This project is specifically designed to explore and provoke biases in Language Models (LLMs) using Reinforcement Learning techniques. For a detailed exploration of our methods and findings, refer to our paper.
Before you begin, ensure you have the following prerequisites installed:
requirements.txtTo set up Bias-PPO on your local machine, follow these steps:
git clone https://github.com/your-repository/bias-ppo.gitcd bias-ppopip install -r requirements.txtWe provide FT-Gen generator checkpoint on huggingface: https://huggingface.co/farnhua/gpt2-m-testcase_generator
The following steps shows how to train a test case generator using RL, generate test cases from a test case generator, evaluate the generated test cases and futher mitigate bias in target LLMs.
The scripts below reproduce our result of provoking and mitigating bias in ChatGPT, it can be extend to GPT4 and LLaMA2 by changing some argument.
Our P-Chat and FT-Gen baseline test cases are provided in the folder ./Baseline_Prompt, if you want to reproduce the baseline result, you can just skip step 1 and step 2.
To train the model with RL for bias provocation in LLMs, execute the script below. Parameters:
ChatGPT, GPT4./results/<save_path>export OPENAI_API_KEY=""
python main.py \
--mode finetune \
--prompt GPT2 \
--agent ppo_ptx_kl \
--path ./gpt2_finetune/pretrain_data/ChatGPT.csv \
--model_name farnhua/gpt2-m-testcase_generator \
--bot ChatGPT \
--dataset Netflix \
--type bias \
--exp_name ChatGPT_test \
--log_interval 5\
--seed 42 \
--bz 8 \
--kl_coef 0.01 \
--ep_lr 1.0 \
--k_epoch 5\
--discount_r 1.0 \
--end_batch 200 \
--sample_time 8 \
--max_pt_len 30 \
--inner_lr 9e-6 \
--lm_lr 0.1 \
--save_path ChatGPT_test \
--save_interval 10 \
--wandb disabled
./results/ChatGPT_testexport OPENAI_API_KEY=""
python3 test.py \
--model_path ./results/ChatGPT_test \
--bot ChatGPT \
./RL_Result/<bot>/, including:
<bot>-distinct1000-test.csv: Bias-provoking prompts.<bot>-distinct1000-incontext.csv: Example prompts for mitigation../RL_Result/ChatGPT/ChatGPT-distinct1000-test.csv./RL_Result/ChatGPT/ChatGPT-distinct1000-incontext.csvTo evaluate the test cases generated by GPT-2, use the following script. Parameters:
./Score_Result/<bot>/<save_path>export OPENAI_API_KEY=""
python3 score.py \
--prompt_path ./RL_Result/ChatGPT/ChatGPT-distinct1000-incontext.csv \
--save_path ChatGPT-incontext.csv \
--bot ChatGPT \
./RL_Result/ChatGPT-distinct1000-incontext.csv, and the result will be saved at ./Score_Result/ChatGPT/ChatGPT-incontext.csv.top, sample, human as shown in the paper currentlyMitigate_Result/<bot>/<save_path>.export OPENAI_API_KEY=""
python3 mitigate_origin.py \
--type top \
--save_path ChatGPT_mitigate_top_5_origin.csv \
--bot ChatGPT \
--demo_num 5 \
--testfile ./RL_Result/ChatGPT/ChatGPT-distinct1000-incontext \
--demofile ./Score_Result/ChatGPT/ChatGPT-incontext.csv
Mitigate_Result/ChatGPT/ChatGPT_mitigate_top_5_origin.csvThis codebase is modified from BlackBoxBot
This project is specifically designed to explore and provoke biases in Language Models (LLMs) using Reinforcement Learning techniques. For a detailed exploration of our methods and findings, refer to our paper.
Before you begin, ensure you have the following prerequisites installed:
requirements.txtTo set up Bias-PPO on your local machine, follow these steps:
git clone https://github.com/your-repository/bias-ppo.gitcd bias-ppopip install -r requirements.txtWe provide FT-Gen generator checkpoint on huggingface: https://huggingface.co/farnhua/gpt2-m-testcase_generator
The following steps shows how to train a test case generator using RL, generate test cases from a test case generator, evaluate the generated test cases and futher mitigate bias in target LLMs.
The scripts below reproduce our result of provoking and mitigating bias in ChatGPT, it can be extend to GPT4 and LLaMA2 by changing some argument.
Our P-Chat and FT-Gen baseline test cases are provided in the folder ./Baseline_Prompt, if you want to reproduce the baseline result, you can just skip step 1 and step 2.
To train the model with RL for bias provocation in LLMs, execute the script below. Parameters:
ChatGPT, GPT4./results/<save_path>export OPENAI_API_KEY=""
python main.py \
--mode finetune \
--prompt GPT2 \
--agent ppo_ptx_kl \
--path ./gpt2_finetune/pretrain_data/ChatGPT.csv \
--model_name farnhua/gpt2-m-testcase_generator \
--bot ChatGPT \
--dataset Netflix \
--type bias \
--exp_name ChatGPT_test \
--log_interval 5\
--seed 42 \
--bz 8 \
--kl_coef 0.01 \
--ep_lr 1.0 \
--k_epoch 5\
--discount_r 1.0 \
--end_batch 200 \
--sample_time 8 \
--max_pt_len 30 \
--inner_lr 9e-6 \
--lm_lr 0.1 \
--save_path ChatGPT_test \
--save_interval 10 \
--wandb disabled
./results/ChatGPT_testexport OPENAI_API_KEY=""
python3 test.py \
--model_path ./results/ChatGPT_test \
--bot ChatGPT \
./RL_Result/<bot>/, including:
<bot>-distinct1000-test.csv: Bias-provoking prompts.<bot>-distinct1000-incontext.csv: Example prompts for mitigation../RL_Result/ChatGPT/ChatGPT-distinct1000-test.csv./RL_Result/ChatGPT/ChatGPT-distinct1000-incontext.csvTo evaluate the test cases generated by GPT-2, use the following script. Parameters:
./Score_Result/<bot>/<save_path>export OPENAI_API_KEY=""
python3 score.py \
--prompt_path ./RL_Result/ChatGPT/ChatGPT-distinct1000-incontext.csv \
--save_path ChatGPT-incontext.csv \
--bot ChatGPT \
./RL_Result/ChatGPT-distinct1000-incontext.csv, and the result will be saved at ./Score_Result/ChatGPT/ChatGPT-incontext.csv.top, sample, human as shown in the paper currentlyMitigate_Result/<bot>/<save_path>.export OPENAI_API_KEY=""
python3 mitigate_origin.py \
--type top \
--save_path ChatGPT_mitigate_top_5_origin.csv \
--bot ChatGPT \
--demo_num 5 \
--testfile ./RL_Result/ChatGPT/ChatGPT-distinct1000-incontext \
--demofile ./Score_Result/ChatGPT/ChatGPT-incontext.csv
Mitigate_Result/ChatGPT/ChatGPT_mitigate_top_5_origin.csvThis codebase is modified from BlackBoxBot