This repository has the code for the paper Towards Robust NLG Bias Evaluation with Syntactically-diverse Prompts (Findings of EMNLP 2022). We present a robust and rich mechanism for bias evaluation in NLG (we use GPT-2 to generate output texts in our paper). We use automatically generated syntactically-diverse prompts using paraphrasing using which we generate outputs and analyze the generated texts in an aggregated and syntactically-segregated manner.
conda create -n robust_nlg_bias python
conda activate robust_nlg_bias
conda install pip
pip install -r requirements.txt
- Create a file for the fixed handcrafted prompts as in
data/prompts/fixed-prompts.txt
- Use this file to get paraphrases for 100 different syntactic structures using AESOP directly. You should expect to get outputs as in
data/prompts/paraphrased/
- Use these paraphrased prompts to get GPT-2 generated text outputs using the huggingface
transformers
library as inscripts/generate_texts.py
. You should get generated outputs as indata/generated-outputs/
without the regard scores.
-
Clone the regard classifier repository
-
Follow the instructions to use
run_classifier.py
to get the regard scores for all generated prompts. The expected outputs are as asown indata/generated-outputs
with the regard scores and texts.
- Run
scripts/aggregated_analysis.py
andscripts/segregated_analysis.py
(adapted from regard repository) to get the distribution curves, mean, std deviation, KL divergence, regard gaps, and other statistical analysis of the regard scores distributed across various seeds, demographic groups and syntactic structures. - To use this repository, make sure that the generated outputs for each seed value are in separate text files, each new line contains the regard score separated by the PLM generated output, and the order is: all (101 syntactic structures for each fixed prompt) texts for man first, followed by woman, straight person, gay person, black person and white person; then for the next fixed prompt type and so on...
- Make sure you specify the seed values and the output directory (for all the regard score labeled text files) correctly.
- Run the following commands to use our repository:
python scripts/aggregated_analysis.py --seeds="21,12,3,30,9,18,36,45,54,27" --dir_name=data/generated-outputs/
python scripts/segregated_analysis.py --seeds="21,12,3,30,9,18,36,45,54,27" --dir_name=data/generated-outputs/
To appear in Findings of EMNLP 2022. Please cite our work if you decide to use it for your project.