F air L ib: A Unified Framework for Assessing and Improving Fairness (2022)

Abstract: This paper presents FairLib, an open-source python library for assessing and improving model fairness. It provides a systematic framework for quickly accessing benchmark datasets, reproducing existing debiasing baseline models, developing new methods, evaluating models with different metrics, and visualizing their results. Its modularity and extensibility enable the framework to be used for diverse types of inputs, including natural language, images, and audio. We implement 14 debiasing methods, including pre-processing,at-training-time, and post-processing approaches. The built-in metrics cover the most commonly acknowledged fairness criteria and can be further generalized and customized for fairness evaluation.

## introduction while neural methods have achieved great success, it has been shown that naively-trained models often learn spurious correlations with protected attributes like user demographics or socio-economic factors, leading to allocation harms, stereotyping, and other representation harms @xcite @xcite @xcite . as a result, there is a surge of interest in assessing and improving fairness. various bias evaluation metrics have been introduced in previous studies to gauge different types of biases. one common family of fairness assessment is group fairness which measures performance disparities across demographic groups. different instantiations of group fairness have been proposed, including demographic parity @xcite , where the positive prediction rate should be identical across groups (irrespective of the gold label), or equal opportunity @xcite where all groups should have an equal chance of false negative prediction (equalized odds extends the notion to include equal true positive rates). more recent work addressed disparities within classes and demographic groups @xcite . while these approaches reflect the nature of fairness increasingly faithfully, they have been applied and evaluated inconsistently in previous work, which impedes systematic analysis and comparison of proposed approaches. in terms of bias mitigation, diverse debiasing methods have been proposed, including attraining-time @xcite @xcite , and pre- @xcite and post-processing approaches @xcite . although these methods have been proved effective for bias mitigation, it is challenging to reproduce results and compare methods because of inconsistencies in training strategy and model selection criteria, which demonstrably affect the results. we present fairlib , a well-documented, opensource framework for assessing and improving fairness. fairlib implements a number of common debiasing approaches in a unified framework to facilitate reproducible and consistent evaluation, and provides interfaces for developing new debiasing methods. moreover, a dataset interface supports adoption of both built-in and newly developed methods for new tasks and corpora. for better presentation, fairlib also provides utilities for result summarization and visualization. fairlib is implemented in python using pytorch and is easy to use: it can be run from the command line, or imported as a package into other projects. to demonstrate its utility, we use fairlib to reproduce a battery of debiasing results from the recent nlp literature, and show that improved and systematic hyperparameter tuning leads to demonstrable improvements over the originally reported results. fairlib is released under apache license 2.0 and is available on github. 2 detailed documentation and tutorials are available on fairlib 's website. 3 ## benchmark datasets in addition to evaluating bias wrt. a user group, we require datasets where each input instance is annotated with protected attributes (e.g., gender) and a target class label (e.g., sentiment). however, for a variety of reasons, only a small subset of datasets contains protected attribute labels, and annotating protected labels can be difficult. to standardize fairness studies, fairlib provides apis to access various publicly available fairness benchmark datasets, including: (1) text corpora for occupation classification (bios, de-arteaga et al. (2019) ## bias mitigation this section reviews the three primary types of debiasing methods, followed by section 4.1, a summary of bias mitigation methods implemented in fairlib . pre-processing adjusts the training dataset to be balanced across protected groups before training, such that the input feature space is expected to be uncorrelated with the protected attributes. typical approaches here adopt long-tail learning approaches for debiasing, such as resampling the training set such that the number of instances within each protected group is identical @xcite @xcite . at training time introduces constraints into the optimization process for model training. a popular method is adversarial training, which jointly trains: (i) a discriminator to recover protected attribute values; and (ii) the main model to correctly predict the target classes while at the same time preventing protected attributes from being correctly predicted @xcite @xcite @xcite . post-processing aims to adjust a trained classifier according to protected attributes, such that the final predictions are fair to different protected groups. for example, @xcite iteratively project fixed text representations from a trained model to a null-space of protected attributes. @xcite adjust the predictions for each protected group by searching for the best prior for type main idea metric (m ) independence (ŷ ⊥ g) positive rate of each protected group is the same tp+fp tp+fp+tn+fn (positive rate) (demographic parity; feldman et al. (2015)) separation (ŷ ⊥ g|y) acknowledges correlation between g and y tp tp+fn (recall or tpr) (equalized odds; hardt et al. (2016)) fp fp+tn (fall-out or fpr) sufficiency (y ⊥ g|ŷ) predictions are calibrated for all groups tp tp+fp (precision) (test fairness; chouldechova (2017)) tn tn+fn (npv) ## model comparison typically, debiasing methods suffer from performance-fairness trade-offs, and no single method achieves both the best performance and fairness, making comparison between fairness methods difficult. in this section, we first introduce trade-off plots for model comparison, and then discuss model selection criteria that can be used for reporting numerical results. performance-fairness trade-off is a common way of comparing different debiasing methods without the requirement for model selection. specifically, there is usually a trade-off hyperparameter for each debiasing method, which controls to what extent the model will sacrifice performance for better fairness, such as the number of iterations for null-space projection in inlp, 6 or the strength of the additional contrastive losses in fairscl. figure 1 shows a trade-off plot over different values of the trade-off hyperparameter of fairscl for occupation classification, wherein we evaluate performance with accuracy, and use equal opportunity as the fairness criterion (see section 8.1 for details). 7 instead of trade-offs wrt. different hyperparameter values, it can be more instructive to compute the maximum fairness that can be achieved by different models at a fixed performance level, and vice versa. figure 2 shows an example of comparing the pareto frontiers of inlp with fairscl, where the results are obtained by varying the hyperparameters as illustrated in figure 1 . for a particular method, a pareto optimal point corresponds to a model (i.e., a particular value of the trade-off hy-type model main idea pre-bd @xcite equalize the size of protected groups. cb @xcite down-sample the majority protected group within each class. jb @xcite jointly balance the protected attributes and classes. bteo @xcite balance protected attributes within advantage classes. ## fairlib design and architecture here, we describe the four modules of fairlib , namely data, model, evaluation, and analysis. ## usage in this section, we demonstrate the basic use of fairlib . for further details, see the online interactive demos for examples of adding customized models, datasets, and metrics. the following command shows an example for training and evaluating a standard model: in order to apply built-in debiasing methods, additional options for debiasing can be added to the command-line to realise combinations of methods: ## benchmark experiments to evaluate fairlib , we conduct extensive experiments to compare models implemented in fairlib with their original reported results over two benchmark datasets. in appendix a, we provide more experimental details. ## conclusion in this paper, we present fairlib , a new opensource python library and framework for measuring and improving fairness, which implements a wide range of fairness metrics and 14 debiasing approaches. with better-designed hyperparameter tuning and model selection, the reproduced models in fairlib outperform the results reported in the original work. fairlib also has remarkable flexibility and extensibility, such that new models, debiasing methods, and datasets can be easily developed and evaluated. where the fairness metric is tpr gap (corresponding to equal opportunity fairness); the performance is measured with accuracy score; the best epoch is selected based on dto; and the tuned trade-off hyperparameters are used as the index. n_jobs is an optional argument for multiprocessing, and the resulting dataframe will be saved to the specified directory. assuming bios_gender_results is a python dictionary of retrieved experimental results from the first step, indexed by the corresponding method name, we provide the following function for model comparison: from fairlib.tables_and_figures import final_results_df ↩→ @xmath0:inlp_df, "fairscl":fairscl_df,} @xmath1, @xmath2, @xmath3, @xmath4,) each method has one selected model in the resulting dataframe, which can then be used to create tables. if visualization is desired, users can disable model selection by setting @xmath5, in which case all pareto frontier points will be returned.