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.
This guide explains how to prepare the datasets and reproduce the experimental results in the paper.
-
Download the Dataset
Obtain the dataset files from thedatasetfolder (or the provided release link). -
Extract the Dataset
Unzip the downloaded files and move all contents into thecodedirectory, while preserving the original folder structure.
After this step, you should see directories such as addressed_dataset/ and addressed_corpus/ under the project root.
Before running any RAG-based evaluation, you must first retrieve documents for each bias subtype.
This is done using 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
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
After document retrieval is completed, you can reproduce the experimental results reported in the paper by running 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
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@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}
}