Skip to main content

A comprehensive set of fairness metrics, datasets and algorithms to address and mitigate bias in Natural Language Processing.

Project description

Fair Language Processing (FairLangProc)

License: MIT PyPI version Docs Python 3.10 Tests

The Fair Language Processing package is a extensible open-source Python library containing techniques developed by the research community to help detect and mitigate bias in Natural Language Processing throughout the AI application lifecycle.

The FairLangProc package includes:

  1. Data sets to test for biases in NLP models.
  2. Metrics based on different philosophies to quantified said biases.
  3. Algorithms to mitigate biases.

It has been created with the intention of encouraging the use of bias mitigation strategies in the NLP community, and with the hope of democratizing these tools for the ever-increasing set of NLP practitioners. We invite you to use it and improve it.

We have developed the package with extensibility in mind. This library is still in development. We encourage your contributions.

Supported fairness datasets

Data Set Size Reference
BBQ 58,492 Parrish et al., 2021
BEC-Pro 5,400 Bartl et al., 2020
BOLD 23,679 Dhamala et al., 2021
BUG 108,419 Levy et al., 2021
Crow-SPairs 1,508 Nangia et al., 2020
GAP 8,908 Webster et al., 2018
HolisticBias 460,000 Smith et al., 2022
HONEST 420 Nozza et al., 2021
StereoSet 16,995 Nadeem et al., 2020
UnQover 30 Li et al., 2020
WinoBias+ 1,367 Vanmassenhove et al., 2021
WinoBias 3,160 Zhao et al., 2018
WinoGender 720 Rudinger et al., 2018

Supported fairness metrics

Supported bias mitigation algorithms

Setup

Python

To install the latest stable version from PyPI, run:

pip install FairLangProc

Has been tested and ran with both Python 3.13 and Python 3.10. Compatibility with older versions is possible and expected, although we are still testing older configurations. The minimum tested versions of the requirements are:

  • pandas>=2.2.3
  • scikit-learn>=1.6.1
  • torch>=2.6.0
  • transformers>=4.47.1
  • datasets>=3.4.1
  • adapter-transformers>=1.1.0
  • accelerate>=0.26.0
  • pytest>=8.4.1

Manual installation

Clone the latest version of this repository:

git clone https://github.com/arturo-perez-peralta/FairLangProc

Using FairLangProc

The notebooks directory contains a diverse collection of jupyter notebooks that showcase how to use the different processors, metrics and data sets. If you'd like to run the examples requiring , download the data sets now and place them in a folder named Fair-LLM-Benchmarks inside the 'FairLangProc/datsets' path or simply clone the repository from Gallegos et al.

Using the BiasDataLoader

In order to run the BiasDataLoader first you need to download the datasets from the repository from I. Gallegos https://github.com/i-gallegos/Fair-LLM-Benchmark. In order to do this you first need to find the path of the package. This can be done with the following Python command:

python -c "import FairLangProc; print(FairLangProc.__file__)" 

Now you only need to download the datasets:

git clone https://github.com/i-gallegos/Fair-LLM-Benchmark [absolute path to your Python packages folder]/FairLangProc/datasets

Credits

For attribution in academic contexts, please use the bibtex entry below:

@misc{pérezperalta2025fairlangprocpythonpackagefairness,
      title={FairLangProc: A Python package for fairness in NLP}, 
      author={Arturo Pérez-Peralta and Sandra Benítez-Peña and Rosa E. Lillo},
      year={2025},
      eprint={2508.03677},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/2508.03677}, 
}

We thank Víctor Agulló for his inputs on many different questions that arose during the making of the package as well as for his contributions on different parts of the code, specially those related to the BiasDataLoader method.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fairlangproc-0.1.6.tar.gz (42.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fairlangproc-0.1.6-py3-none-any.whl (91.2 kB view details)

Uploaded Python 3

File details

Details for the file fairlangproc-0.1.6.tar.gz.

File metadata

  • Download URL: fairlangproc-0.1.6.tar.gz
  • Upload date:
  • Size: 42.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for fairlangproc-0.1.6.tar.gz
Algorithm Hash digest
SHA256 c5d8543e1c3563a2a361b16776fd909ed92e89dcf577b9fbb731e224431df6ca
MD5 5053e3f5751868706286528c9368d410
BLAKE2b-256 169f5a2c8d10ebf565f65d9ffb8aecdcc24873b32e400ebd7c903091c6a4e214

See more details on using hashes here.

File details

Details for the file fairlangproc-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: fairlangproc-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 91.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for fairlangproc-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 041919e0e05360ea6b01629007aca41d7e4b60e130b583ded7fca88702f5dbc6
MD5 4615232297a2d9e333cc09c16e16755c
BLAKE2b-256 b3885e60d6668caecee335c369e79fbca63fccbeb5fe1ec71a75617c7deb7677

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page