Skip to main content

inFairness is a Python package to train and audit individually fair PyTorch models

Project description

Build Status Python3.8+ License Code style: black

inFairness

inFairness is a PyTorch package that allows training individually fair PyTorch models

Installation

inFairness can be installed using pip:

pip install inFairness

Alternatively, if you wish to install the latest development version, you can install directly by cloning this repository:

git clone <git repo url>
cd inFairness
pip install -e .

Features

inFairness currently supports:

  1. Training of individually fair models : [Docs]
  2. Auditing pre-trained ML models for individual fairness : [Docs]

Coming soon

We plan to extend the package by integrating the following features:

  1. Post-processing for Individual Fairness : [Paper]
  2. Support Individually fair boosting and ranking
  3. Additional individually fair metrics

Contributing

We welcome contributions from the community in any form - whether it is through the contribution of a new fair algorithm, fair metric, a new use-case, or simply reporting an issue or enhancement in the package. To contribute code to the package, please follow the following steps:

  1. Clone this git repository to your local system
  2. Setup your system by installing dependencies as: pip3 install -r requirements.txt and pip3 install -r build_requirements.txt
  3. Add your code contribution to the package. Please refer to the inFairness folder for an overview of the directory structure
  4. Add appropriate unit tests in the tests folder
  5. Once you are ready to commit code, check for the following:
    1. Coding style compliance using: flake8 inFairness/. This command will list all stylistic violations found in the code. Please try to fix as much as you can
    2. Ensure all the test cases pass using: coverage run --source inFairness -m pytest tests/. All unit tests need to pass to be able merge code in the package.
  6. Finally, commit your code and raise a Pull Request.

Tutorials

The examples folder contains tutorials from different fields illustrating how to use the package.

Minimal example

First, you need to import the relevant packages

from inFairness import distances
from inFairness.fairalgo import SenSeI

The inFairness.distances module implements various distance metrics on the input and the output spaces, and the inFairness.fairalgo implements various individually fair learning algorithms with SenSeI being one particular algorithm.

Thereafter, we instantiate and fit the distance metrics on the training data, and

distance_x = distances.SVDSensitiveSubspaceDistance()
distance_y = distances.EuclideanDistance()

distance_x.fit(X_train=data, n_components=50)

# Finally instantiate the fair algorithm
fairalgo = SenSeI(network, distance_x, distance_y, lossfn, rho=1.0, eps=1e-3, lr=0.01, auditor_nsteps=100, auditor_lr=0.1)

Finally, you can train the fairalgo as you would train your standard PyTorch deep neural network:

fairalgo.train()

for epoch in range(EPOCHS):
    for x, y in train_dl:
        optimizer.zero_grad()
        result = fairalgo(x, y)
        result.loss.backward()
        optimizer.step()

Authors

  • Mikhail Yurochkin
  • Mayank Agarwal
  • Aldo Pareja
  • Onkar Bhardwaj

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

inFairness-0.1.0.tar.gz (20.7 kB view details)

Uploaded Source

Built Distribution

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

inFairness-0.1.0-py3-none-any.whl (27.4 kB view details)

Uploaded Python 3

File details

Details for the file inFairness-0.1.0.tar.gz.

File metadata

  • Download URL: inFairness-0.1.0.tar.gz
  • Upload date:
  • Size: 20.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.1

File hashes

Hashes for inFairness-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2df554c2af46d7fd7898aa8aae5801567d7b8bb77765635da8a294e4bcf81d1d
MD5 5c60b4f561afeebc73b616b22b214882
BLAKE2b-256 e36201af3ecca91d6c64e8242966d9d0aa0f12176ec2aed8acfd1c1622295523

See more details on using hashes here.

File details

Details for the file inFairness-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: inFairness-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 27.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.1

File hashes

Hashes for inFairness-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 67e1127bf28dd31491a025c2c81ae25052ba966b3d7beaa6c9c47c1baafe9b4d
MD5 b0a5f730e7fcc504744325a70ad2d457
BLAKE2b-256 2b83b72c0efc22bf546acbfd25ca35e7b26d8c9cf92ac3515d956a090638901c

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