Skip to main content

fairlib

fairlib is a Python framework for assessing and improving fairness. Built-in algorithms can be applied to text inputs, structured inputs, and image inputs.

The fairlib package includes metrics for fairness evaluation, algorithms for bias mitigation, and functions for analysis.

For those who want to start with fairlib now, you can try our Colab Tutorial, which provides a gentle introduction to the concepts and capabilities. The tutorials and other notebooks offer a deeper introduction. The complete API is also available.

Installation

fairlib currently requires Python3.7+ and Pytorch 1.10 or higher. Dependencies of the core modules are listed in requirements.txt. We strongly recommend using a venv or conda environment for installation.

Standard Installation

If you do not need further modifications, you can install it with:

# Start a new virtual environment:
conda create -n fairlib python=3.7
conda activate fairlib

pip install fairlib

Development Installation

To set up a development environment, run the following commands to clone the repository and install fairlib:

git clone https://github.com/HanXudong/fairlib.git ~/fairlib
cd ~/fairlib
python setup.py develop

Benchmark Datasets

Please refer to data/README.md for a list of fairness benchmark datasets.

Usage

The full description of fairlib usages can be found in fairlib cheat sheet and API reference. Here are the most basic examples.

  • fairlib can be run from the command line:

    python fairlib --exp_id EXP_NAME
    
  • fairlib can be imported as a package

    from fairlib.base_options import options
    from src import networks
    
    config_file = 'opt.yaml'
    # Get options
    state = options.get_state(conf_file=config_file)
    
    # Init the model
    model = networks.get_main_model(state)
    
    # Training with debiasing
    model.train_self()
    

Model Selection and Fairness Evaluation

Besides the classical loss- and performance-based model selection, we provide performance-fairness trade-off based model selection (see the paper below).

Please see this tutorial for an example of loading training history, performing model selections based on different strategies, and creating basic plots. Moreover, interactive plots are also supported, which can be used for analysis.

Known issues and limitations

None are known at this time.

Getting help

If you have any problem with our code or have some suggestions, including the future feature, feel free to contact

or describe it in Issues.

Paper

fairlib: A Unified Framework for Assessing and Improving Classification Fairness

Cite Us

@article{han2022fairlib,
  title={fairlib: A Unified Framework for Assessing and Improving Classification Fairness},
  author={Han, Xudong and Shen, Aili and Li, Yitong and Frermann, Lea and Baldwin, Timothy and Cohn, Trevor},
  journal={arXiv preprint arXiv:2205.01876},
  year={2022}
}

Contributing

We appreciate all contributions. If you are planning to contribute back bug-fixes, please do so without any further discussion. If you plan to contribute new features, utility functions or extensions, please first open an issue and discuss the feature with us.

License

This project is distributed under the terms of the APACHE LICENSE, VERSION 2.0. The license applies to all files in the GitHub repository hosting this file.

Acknowledgments

Metadata

Release files for fairlib 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fairlib 0.1.0
File Size Uploaded
fairlib-0.1.0.tar.gz 69.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fairlib 0.1.0
File Interpreter ABI Platform
fairlib-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 168.1 kB

Release files / fairlib-0.1.0.tar.gz

Download URL fairlib-0.1.0.tar.gz
Size 69.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b1fb77bf985f8af57eac699d283812d06e0bc26397b8ec5ca4964f979165ae21
BLAKE2b-256 checksum
How to use checksums
fcaa0649cbde80a4a08efc87c9775797cf72f0e2434a48177fbfd879dc8e8c21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.7.12

Release files / fairlib-0.1.0-py3-none-any.whl

Download URL fairlib-0.1.0-py3-none-any.whl
Size 98.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2f7ee344e2a777f5533f4880c03b15a40995e7f2947cedaba69add6c7e28dd04
BLAKE2b-256 checksum
How to use checksums
cbcc432571f2d5599db0e626a674753bb545d659962a3cad0ee24b77ba2e19fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.7.12

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page