Skip to main content
QUICK REVIEW

[Paper Review] FairPy: A Toolkit for Evaluation of Prediction Biases and their Mitigation in Large Language Models

Hrishikesh Viswanath, Tianyi Zhang|arXiv (Cornell University)|Feb 10, 2023
Ethics and Social Impacts of AISocial Sciences6 citations
TL;DR

FairPy is a Python toolkit that decouples bias detection and mitigation techniques for large language models, enabling plug-and-play evaluation of fairness across models like BERT and GPT-2 using standardized metrics. It supports custom model integration, debiasing via retraining and post-processing, and provides empirical results showing reduced gender bias (e.g., WEAT score drop from 1.15 to 0.8 in GPT-2) while highlighting inconsistencies in model compatibility.

ABSTRACT

Recent studies have demonstrated that large pretrained language models (LLMs) such as BERT and GPT-2 exhibit biases in token prediction, often inherited from the data distributions present in their training corpora. In response, a number of mathematical frameworks have been proposed to quantify, identify, and mitigate these the likelihood of biased token predictions. In this paper, we present a comprehensive survey of such techniques tailored towards widely used LLMs such as BERT, GPT-2, etc. We additionally introduce Fairpy, a modular and extensible toolkit that provides plug-and-play interfaces for integrating these mathematical tools, enabling users to evaluate both pretrained and custom language models. Fairpy supports the implementation of existing debiasing algorithms. The toolkit is open-source and publicly available at: \href{https://github.com/HrishikeshVish/Fairpy}{https://github.com/HrishikeshVish/Fairpy}

Motivation & Objective

  • To address the lack of accessible, general-purpose tools for evaluating and mitigating social biases in large language models across diverse models and social groups.
  • To decouple bias detection and mitigation methods from specific models and social contexts, enabling broader reuse and extensibility.
  • To provide a unified, open-source Python interface that supports integration with Hugging Face models and custom models for bias evaluation.
  • To empirically analyze the effectiveness of various bias detection and mitigation techniques across major pre-trained models.
  • To identify compatibility issues in existing metrics—especially those relying on masked templates—when applied to causal (autoregressive) models like GPT-2.

Proposed method

  • The toolkit implements a modular architecture that separates bias detection metrics and mitigation techniques from specific language models, enabling plug-and-play integration.
  • It supports multiple bias detection methods: word embedding similarity (e.g., WEAT), stereotypical prediction scoring (e.g., StereoSet), and probabilistic divergence measures (e.g., Hellinger distance).
  • For mitigation, it implements dropout regularization retraining, self-debiasing via conditional prompting, and null space projection on embeddings.
  • The self-debiasing method uses a conditional template to reduce biased word probabilities via a learned attention-weighted adjustment: $ p_M(w|x) = \alpha(\Delta(w,x,y)) \cdot p_M(w|x) $.
  • The toolkit includes pre-split datasets (e.g., CrowS, StereoSet) to allow per-social-group evaluation, improving runtime and accuracy.
  • It provides a unified interface to handle model-specific embedding layer naming and representation differences, enhancing compatibility across models.
Figure 1: The flow diagram highlights the overall architecture of the model, with the nodes labelled in red denoting the bias detection techniques and the nodes in green highlighting the bias mitigation techniques
Figure 1: The flow diagram highlights the overall architecture of the model, with the nodes labelled in red denoting the bias detection techniques and the nodes in green highlighting the bias mitigation techniques

Experimental results

Research questions

  • RQ1Which bias detection metrics are most effective and generalizable across different pre-trained language models such as BERT and GPT-2?
  • RQ2How do different debiasing techniques—especially retraining with dropout regularization and self-debiasing—impact gender and stereotypical bias in LLMs?
  • RQ3What are the key compatibility challenges when applying template-based bias detection methods (e.g., masked templates) to autoregressive models like GPT-2?
  • RQ4To what extent do existing metrics fail due to model-specific tokenization or embedding layer structures?
  • RQ5How does per-social-group evaluation (e.g., race, gender) improve the precision and efficiency of bias measurement?

Key findings

  • GPT-2 showed a significant reduction in gender bias after dropout regularization retraining, with the WEAT score dropping from 1.15 (biased) to 0.80 (debiased), indicating reduced gender association in word embeddings.
  • Despite reduced WEAT scores, GPT-2’s StereoSet score increased from 47.91 to 58.4, suggesting a higher frequency of stereotypical predictions, highlighting a potential trade-off in mitigation.
  • BERT also showed a decrease in WEAT score from 1.13 to 0.68 after debiasing, indicating reduced gender bias, though F1 score slightly decreased from 65.6 to 64.4.
  • The toolkit successfully enabled per-group evaluation of StereoSet and CrowS datasets, reducing runtime and improving accuracy by splitting data by social category.
  • The toolkit identified model-specific incompatibilities, such as GPT-2 failing to compute StereoSet scores due to tokenization and embedding layer structure differences.
  • Dropout regularization retraining reduced Hellinger distance from 0.14 to 0.35 in GPT-2, indicating increased divergence in prediction distributions, though this may reflect model instability or metric sensitivity.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.