This repository is the code base for the paper: Instructed to Bias: Instruction-Tuned Language Models Exhibit Emergent Cognitive Bias (TACL).
- Python version >= 3.11
View requirments.txt file for more information.
git clone https://github.com/itay1itzhak/InstructedToBias.git
cd InstructedToBias
pip install requirements.txt -r
Use the following script generate data for the three biases - the decoy effect, certainty effect and belief bias*. You can also unzip the Data.zip file to get the generated data.
* Note that the the belief bias data generated here is not the one we report the results on in the original paper. This data is a recreation of the data created by Dasgupta et al. (2022) which we used for the results in our paper.
BIAS_NAME = {'decoy','certainty','false_belief'}.
python Data_generation/generate_samples.py --bias_name $BIAS_NAME
Now you can use a model to make prediction in the generated data. We support the models used in the original paper from the GPT3/3.5/4, the T5/Flan-T5, and the Mistral-7B models families. Additional models can be easily supported by adding a new predictor file for your model that inherits from the Predictor class (see 'Predict/t5_predict.py' for example).
We'll use T5-Small and Flan-T5-Small as an example.
$MODELS = 't5-v1_1-small,flan-t5-small'
In order to predict using OpenAI API models, make sure to create an .env file in the main dir with your OpenAI key in the following format -
OPENAI_API_KEY=YOUR_KEY
python run_predict.py --bias_name $BIAS_NAME --all_models $MODELS
Run the analysis script to create a .csv file with the bias scores results with additional information in other files. The results will be saved in The respected predictions dirs.
* Note that for the decoy analysis, you'll need to set BIAS_NAME=decoy_expensive
or BIAS_NAME=decoy_cheaper
for the respected biases analysis.
python run_analysis.py --bias_name $BIAS_NAME --all_models $MODELS
Use the with_format_few_shot
or with_task_few_shot
when predicting and running analysis with few-shot examples.
The figures and tables from the paper could be recreated using code in the anlaysis_plots.ipynb Jupyter notebook.
Instructed to Bias is MIT-licensed.