Skip to main content

No project description provided

Project description

FairGrad: Fairness Aware Gradient Descent

Documentation Status PyPI version GitHub Actions (Tests)

FairGrad, is an easy to use general purpose approach to enforce fairness for gradient descent based methods.

Getting started:

You can get fairgrad from pypi, which means it can be easily installed via pip:

pip install fairgrad

Documentation

The documenation can be found at read the docs

Example usage

To use fairgrad simply replace your pytorch cross entropy loss with fairgrad cross entropy loss. Alongside, regular pytorch cross entropy arguments, it expects following extra arguments.

y_train (np.asarray[int], Tensor, optional): All train example's corresponding label
s_train (np.asarray[int], Tensor, optional): All train example's corresponding sensitive attribute. This means if there
        are 2 sensitive attributes, with each of them being binary. For instance gender - (male and female) and
        age (above 45, below 45). Total unique sentive attributes are 4.
fairness_measure (string): Currently we support "equal_odds", "equal_opportunity", "accuracy_parity", and 
                           "demographic_parity". Note that demographic parity is only supported for binary case.
epsilon (float, optional): The slack which is allowed for the final fairness level.
fairness_rate (float, optional): Parameter which intertwines current fairness weights with sum of previous fairness rates.
# Note this is short snippet. One still needs to models and iterators.
# Full worked out example is available here - @TODO

from fairgrad.torch import CrossEntropyLoss

# define cross entropy loss 
criterion = CrossEntropyLoss(fairness_related_meta_data=fairness_related_meta_data)

# Train loop

for inputs, labels, protected_attributes in train_iterator:
    model.train()
    optimizer.zero_grad()
    output = model(inputs)
    loss = criterion(output, labels, protected_attributes, mode='train')
    loss.backward()
    optimizer.step()

We highly recommend to standardize features by removing the mean and scaling to unit variance. This can be done using standard scalar module in sklearn.

Citation

@article{maheshwari2022fairgrad,
  title={FairGrad: Fairness Aware Gradient Descent},
  author={Maheshwari, Gaurav and Perrot, Micha{\"e}l},
  journal={arXiv preprint arXiv:2206.10923},
  year={2022}
}

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

fairgrad-0.1.9.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

fairgrad-0.1.9-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file fairgrad-0.1.9.tar.gz.

File metadata

  • Download URL: fairgrad-0.1.9.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.8.12 Linux/5.15.0-47-generic

File hashes

Hashes for fairgrad-0.1.9.tar.gz
Algorithm Hash digest
SHA256 e845a7a7fce2000adcf1268baee75827b62869169365f2ed9d07f8f3a07cb072
MD5 1f90980abc133d912f7cfd4d668e864b
BLAKE2b-256 d910d257f33b650d5f6480131946f05bc33e621dcadd209c6db43147cbab9326

See more details on using hashes here.

File details

Details for the file fairgrad-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: fairgrad-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.8.12 Linux/5.15.0-47-generic

File hashes

Hashes for fairgrad-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 5809da0cecad9303021d5456516a225a612c9991981203a657bac216fd2d533f
MD5 ed644a79debf7a2a26f4944cdaaec9d6
BLAKE2b-256 3f8a0172fa779fa22f208d30dae367b773cf87fde0db1e7723cfcf40fdc87b80

See more details on using hashes here.

Supported by

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