FairPy: A toolkit for evaluation of social biases and their mitigation in large language models

Hrishikesh Viswanath, Tianyi ZhangarXiv 2023 · DOI · OpenReview

TL;DR

Large language models (LLMs) inherit societal biases from their training data, impacting their reliability. This paper introduces FairPy, an open-source Python toolkit that unifies a wide range of bias detection and mitigation techniques for LLMs, offering plug-and-play interfaces for both pre-trained and custom models. FairPy aims to democratize bias evaluation and mitigation for NLP practitioners.

What Problem Does This Paper Address?

Large language models (LLMs) like BERT and GPT-2 have become incredibly powerful for understanding and generating text. However, they are trained on massive datasets scraped from the internet, which unfortunately contain societal biases related to race, gender, and other demographics. These biases can manifest as preferential token generation, leading to unfair or discriminatory outputs, and ultimately limiting the trustworthiness and adoption of NLP systems in real-world applications. While researchers have developed various mathematical frameworks to quantify, identify, and mitigate these biases, these methods are often theoretical, not readily accessible, or difficult to integrate into existing development pipelines. This creates a significant barrier for NLP practitioners who want to ensure their models are fair.

Methods

FairPy addresses this by providing a modular and extensible toolkit with plug-and-play interfaces. It consolidates a wide array of bias detection and mitigation techniques, making them accessible and integrable with popular open-source LLMs (like BERT, GPT-2, etc.) as well as user-defined models. The toolkit is structured into two main packages: bias detection and bias mitigation.

Bias Detection: The paper categorizes bias detection metrics into two groups:

  1. Internal Representation/Encoding Biases: These metrics assess biases within the model's learned embeddings, looking for statistical regularities that reflect societal biases.
  2. Behavioral Biases: These metrics infer bias by evaluating the model's output in response to controlled input perturbations.

Bias Mitigation: Similarly, mitigation methods are grouped into:

  1. Retraining/Adaptation: This involves retraining the model on balanced or curated datasets, or adapting it through techniques like reinforcement or transfer learning.
  2. Post-hoc Interventions: These methods modify learned token embeddings or internal representations to reduce biased associations after the model has been trained.

FairPy offers interfaces for integrating existing debiasing algorithms and supports a range of popular LLMs through the HuggingFace library.

Datasets

The paper mentions the use of curated datasets and templated corpora for bias evaluation. Specific datasets highlighted include:

  • WinoBias: Used for demonstrating biases in contextualized scenarios.
  • CrowS-pairs: Used for measuring WEAT scores, split into groups for faster computation.
  • Yelp, Reddit, and Wikipedia English: Used for Counter Factual Data Augmentation (CDA) in retraining.

The toolkit also supports user-defined datasets.

Key Insights and Ideas

  • Unified Toolkit for Accessibility: The core idea is to bridge the gap between theoretical bias research and practical NLP development by providing a single, accessible toolkit.
  • Modularity and Extensibility: FairPy's design allows for easy integration of new models and metrics, promoting broader applicability across diverse LLMs.
  • Decoupling Bias Metrics: The toolkit aims to decouple bias detection metrics from specific model architectures and contexts, making them more generalizable.
  • Addressing Template Limitations: The authors acknowledge that existing evaluation templates can be restrictive, especially for different model types (e.g., causal vs. masked LLMs), and propose future work on more adaptable template structures.
  • Empirical Inconsistencies: The empirical analysis reveals that some bias metrics struggle with models that split words into sub-tokens (e.g., OpenAI-GPT), and that model architecture variations can make applying certain debiasing techniques (like Null Space Projection) challenging.

Key Results

The paper presents empirical results for GPT-2 and BERT after debiasing using Dropout Regularization.

  • GPT-2: Showed reductions in Hellinger Distance (0.35 to 0.14) and WEAT Score (1.15 to 0.8), and improvements in StereoSet (47.91 to 58.4) and Log Probability (56.87 to 63.81) after debiasing.
  • BERT: Also demonstrated a reduction in WEAT Score (1.13 to 0.68) and improvements in StereoSet (56.3 to 59.71) and Log Probability (57.25 to 54.58) after debiasing.

These results indicate that debiasing techniques can indeed reduce certain types of biases, though the paper notes that the WEAT score reduction contradicts some previous findings.

Limitations and Future Work

Limitations: * Metric Applicability: Some metrics are not universally applicable to all LLM architectures, particularly those that tokenize words into sub-word units. * Model Architecture Variations: Differences in how models structure and name their final embedding layers can complicate the application of certain debiasing techniques. * Dataset Splitting: While the toolkit allows for splitting datasets by semantic categories for more granular analysis, this was not a standard practice in previous works. * Untested Methods: The toolkit currently supports CDA for multi-class settings, but this specific application has not yet been tested.

Future Work: * Cascading and Hybrid Metrics: Incorporating methods that apply multiple metrics concurrently or in sequence. * Web Interface: Developing a user-friendly web interface to allow users to easily upload models and retrieve statistics. * More Comprehensive Support: Including a wider range of bias detection and mitigation methods, especially those with compatibility issues or limited availability. * Adaptable Template Structures: Developing more flexible template structures for bias evaluation that can be unified across different language model types.

Summary updated

BibTeX
@misc{viswanath2023fairpy,
  author = {Hrishikesh Viswanath and Tianyi Zhang},
  title = {{FairPy: A toolkit for evaluation of social biases and their mitigation in large language models}},
  year = {2023},
  eprint = {2302.05508},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2302.05508},
}
Figure