Git Product home page Git Product logo

mitigating_gender_bias_in_captioning_system's Introduction

Mitigating Gender Bias In Captioning System

This is the pytorch implemention for WWW(The Web Conference)2021 paper “Mitigating Gender Bias In Captioning system” [Link][cite]. Recent studies have shown that captioning datasets, such as the COCO dataset, may contain severe social bias which could potentially lead to unintentional discrimination in learning models. In this work, we specifically focus on the gender bias problem.

Environment

  • pytorch==0.41
  • torchvision==0.2.1
  • python==3.6
  • scikit-image==0.16.2
  • numpy==1.18.1
  • h5py==2.10.0

COCO-GB: Dataset Creation and Analysis

The COCO-GB dataset are created for quantifying gender bias in models. We construct COCO-GB v1 based on a widely used split and create a gender-balanced secret test dataset. COCO-GB v2 is created by reorganizing the train/test split so that the gender-object joint distribution in training set is very different from testing set.

  • Gender-object joint distribution of COCO training dataset

  • Gender-object joint distribution of original COCO test dataset

  • Gender-object joint distribution of COCO-GB v1 secret test dataset

  • Gender-object joint distribution of COCO-GB v2 test dataset

Benchmarking Captioning Models on COCO-GB v1

To reveal the gender bias in existing models, we utilize the gender prediction performance to quantify bias learned by models. Models are trained on Karpathy split, obtain caption quality from original test split, and evaluate gender prediciton performance on the COCO-GB v1 secret test dataset.

Evaluation of Gender Prediction Accuracy

python Benchmarking_existing_models/benchmarking.py 

We saved the caption results of baseline models in folder Benchmarking_existing_models/json_results

Evaluation of Caption Quality

Please download the COCO official Evaluation Tool from https://github.com/tylin/coco-caption

Image Captioning Model with Guided Attention

We propose a novel Guided Attention Image Captioning model (GAIC) to mitigate gender bias by self-supervising on model’s visual attention. GAIC has two complementary streams to encourage the model to explore correct gender features. The training pipeline can seamlessly add extra supervision to accelerate the self-exploration process. Besides, GAIC is model-agnostic and can be easily applied to various captioning models.

Data pipeline

See create_input_files() in utils.py.

This reads the data downloaded and saves the following files –

An HDF5 file containing images for each split in an I, 3, 256, 256 tensor, where I is the number of images in the split. Pixel values are still in the range [0, 255], and are stored as unsigned 8-bit Ints. A JSON file for each split with a list of N_c * I encoded captions, where N_c is the number of captions sampled per image. These captions are in the same order as the images in the HDF5 file. Therefore, the ith caption will correspond to the i // N_cth image. A JSON file for each split with a list of N_c * I caption lengths. The ith value is the length of the ith caption, which corresponds to the i // N_cth image. A JSON file which contains the word_map, the word-to-index dictionary.

Training Baseline Model

python train.py 

We choose Att model as the baseline model. We train baseline for 5 epochs on COCO dataset.

Training GAIC Model

python fine_tune.py 

We Construct GAIC model based on the baseline model. Fine-tune the GAIC model on the fine-tune set for 1 epoch. For training GAICes model, please set the supervised_training = True.

Evaluation of Caption Quality and Gender Accuracy

python eval.py

This code will evaluate the model caption quality on the original test dataset, and evaluate model gender prediction accuracy on COCO-GB v1 or COCO-GB v2.

Show Qualitative Results

python caption.py

This code will show the attention maps for inputting images.

mitigating_gender_bias_in_captioning_system's People

Contributors

captiongenderbias2020 avatar trx14 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mitigating_gender_bias_in_captioning_system's Issues

In create_gender_fine_tuning_input_files function in utils.py, what is n_captions and how can i get them?

Hi, i want to create gender fine tuning input files, but i always failed in utils.py, line 197.

I got WORDMAP files from running Create_Input_Files in create_input_files.py and karpathy_json_path was Benchmarking_existing_models/Ksplit_gender_category.json because i couldn't find the actual dataset(karpathy_json_path='/Users/tangruixiang/Desktop/Fairness_Dataset/code/COCO/Karpathy_split/coco/dataset.json' as you used in create_input_files.py file.)

However, 'Benchmarking_existing_models/Ksplit_gender_category.json' file doesn't have 'n_tokens' and 'g_word_pos' except 'tokens', so i can't create gender fine tuning input files.
It would be really appreciated that if you tell me how to get this dataset.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.