Skip to content

Tools to study biases in natural language generation

Notifications You must be signed in to change notification settings

mohitsudhakar/nlg-bias

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nlg-bias

Emily Sheng, Kai-Wei Chang, Premkumar Natarajan, Nanyun Peng (EMNLP 2019).

Data

regard/ contains samples annotated with regard, and sentiment/ contains samples annotated with sentiment.

The train_other.tsv files include samples with the "other" label. We use train.tsv to train the original models described in the paper, but also include the more robust models trained with train_other.tsv in this repo.

In the TSV files, the first column is the annotation (-1 for negative, 0 for neutral, 1 for positive, 2 for other), and the second column is the sample.

For more details on annotation guidelines and process, please look through the paper.

Models

  • Download the regard2 model here (3.12 GB) into models/.
  • Download the sentiment2 model here (3.12 GB) into models/.
  • Download the regard1 model here (3.12 GB) into models/.
  • Download the sentiment1 model here (3.12 GB) into models/.

There are four types of models: regard1, regard2, sentiment1, and sentiment2. All are ensemble models that take the majority label of three model runs. regard1 and sentiment1 are trained on the respective train.tsv files (as described in the paper). regard2 and sentiment2 are trained on the respective train_other.tsv files. We recommend using regard2 and sentiment2, as they appear to be more quantitatively and qualitatively robust.

model_type dev acc. test acc.
regard1 0.85 0.77
regard2 0.92 0.80
sentiment1 0.77 0.77
sentiment2 0.87 0.77

Code

Setup

To create a clean environment and install necessary dependencies:

conda create -n biases python=3.7

conda activate biases

conda install pip

conda install pytorch=1.2.0 -c pytorch

pip install -r requirements.txt

Run models

If we have a file of samples, e.g., small_gpt2_generated_samples.tsv, and a corresponding file where the demographic groups have been masked, small_gpt2_generated_samples.tsv.XYZ, we can run eval.py:

python scripts/eval.py --sample_file data/generated_samples/sample.tsv --model_type regard2

This will use the regard2 model to label all samples in sample.tsv and subsequently evaluate the amount of biases towards different demographics groups.

About

Tools to study biases in natural language generation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 93.6%
  • Shell 6.4%