Skip to content

LivNLP/Evaluating_RAG_on_Social_Bias

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Evaluating the Effect of Retrieval Augmentation on Social Biases

This repository contains the code and data for the paper:

Evaluating the Effect of Retrieval Augmentation on Social Biases

We study how Retrieval-Augmented Generation (RAG) affects social biases in Large Language Models (LLMs) across multiple bias types (gender, age, race, religion) and languages (English, Chinese, Japanese), using the BBQ benchmark.


Running the Code

This guide explains how to prepare the datasets and reproduce the experimental results in the paper.

1. Download and Prepare the Dataset

  1. Download the Dataset
    Obtain the dataset files from the dataset folder (or the provided release link).

  2. Extract the Dataset
    Unzip the downloaded files and move all contents into the code directory, while preserving the original folder structure.

After this step, you should see directories such as addressed_dataset/ and addressed_corpus/ under the project root.


2. Document Retrieval for RAG (Required)

Before running any RAG-based evaluation, you must first retrieve documents for each bias subtype.

This is done using context_rag.py.

Purpose of context_rag.py

  • Builds a retrieval index over bias-controlled corpora:
    • bias (stereotypical)
    • anti (anti-stereotypical)
    • full (mixed)
  • Retrieves documents for each BBQ question
  • Saves retrieved documents for later reuse in evaluation
  • Default retrieval setting: Top-10 documents

Example Usage

python context_rag.py \
  --question_path addressed_dataset/Gender.jsonl \
  --retrieved_info_path retrieved_info/gender \
  --corpus bias \
  --retriever VectorIndexRetriever \
  --top_k 10

After running this script, the retrieved documents will be saved as:

retrieved_info/<bias_type>/<corpus>_corpus.jsonl

⚠️ This step is mandatory. main.py assumes retrieved documents already exist.


3. Reproducing Experimental Results

After document retrieval is completed, you can reproduce the experimental results reported in the paper by running main.py.

Purpose of main.py

  • Loads BBQ questions from addressed_dataset
  • Loads retrieved documents from retrieved_info
  • Runs LLM inference with or without RAG
  • Computes evaluation metrics on BBQ:
    • Accuracy
    • Diff-Bias scores for ambiguous and disambiguated contexts

Example Command

python main.py \
  --question_path addressed_dataset/Gender.jsonl \
  --retrieved_info_path retrieved_info/gender/retrieved_ten \
  --model_name gpt-3.5-turbo \
  --corpus bias \

  --if_retrieve True

Citation

@article{zhang2025evaluating,
  title={Evaluating the Effect of Retrieval Augmentation on Social Biases},
  author={Zhang, Tianhui and Zhou, Yi and Bollegala, Danushka},
  journal={arXiv preprint arXiv:2502.17611},
  year={2025}
}

About

A meta-evaluation on the relationship between the different components in a RAG system and the social biases presented in the generated text across three languages.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors