This repository contains the work made for my Master's Thesis on Algorithmic Discrimination in Natural Language Processing. It contains several experiments with the aim to detect biases based on gender, sexual orientation, ethnicity and more, in common algorithmic tecniques used to process natural languages (english and italian, in our case).
datacontains the dataset files:data/bncis the serialized dataset of the British National Corpus, a collection of ~22k sentences in english language.data/WinoGendercontains two.tsvtables from the WinoGender datasets.
libscontains scripts taken from external projects, optionally adapted for the case.resultsis the folder containing the results produced by the experiments. They can be tables (.tsv) os images (.png).savedcontains serialized files of models and other Python objects. If the creation of these objects is too slow, we used the Python library pickle to save a pre-computed version of them.src, finally, is the folder of the source code of the project:src/experimentscontains the main scripts for the experiments.src/modelscontains the classes for ML models.src/parserscontains the scripts used to parse datasets in thedatafolder.src/viewerscontains the scripts and classes used to produce outputs in theresultsfolder.
main.pyis the launching script.settings.pycentralizes some setting parameters for the whole project.
We now describe briefly how the implemented experiments work:
Inspired by the paper "How is BERT surprised? Layerwise detection of linguistic anomalies" by Li et al., this test aims to detect anomalies in opposite-by-gender pairs of sentences. A metric called surprise is used to measure the un-likelyhood of tokens in the BERT encoding.
Every pair of sentences contains an occupation word, such as "teacher", "doctor", "engineer", etc., and a gendered english pronoun (he/she, him/her, his/her). Our thesis is that the Anomaly Model detects a higher surprise when the occupation token is used in a sentence with a pronoun of a gender which is not frequently associated with it in the real world.
This experiments recalls a variety of papers on algorithmic discrimination studying the distribution of word embeddings in the output embedding space. However, in our case, the BERT encoder is used to produce contextual word embeddings.
We tried to define standard embeddings for the occupation words, abstracting them from the context and plotting their coordinates in a reduced 2D or 3D space (via Principal Components Analysis).
{work in progress}
{work in progress}