{"id":13565930,"url":"https://github.com/aida-ugent/fairret","last_synced_at":"2025-09-10T05:14:31.465Z","repository":{"id":220196245,"uuid":"750984966","full_name":"aida-ugent/fairret","owner":"aida-ugent","description":"A fairness library in PyTorch.","archived":false,"fork":false,"pushed_at":"2024-07-23T17:00:24.000Z","size":458,"stargazers_count":26,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-08T05:50:33.886Z","etag":null,"topics":["ai","artificial-intelligence","bias","deep-learning","fairness","fairness-ai","fairness-ml","machine-learning","python","pytorch"],"latest_commit_sha":null,"homepage":"https://aida-ugent.github.io/fairret/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aida-ugent.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-31T17:55:41.000Z","updated_at":"2024-07-23T17:00:27.000Z","dependencies_parsed_at":"2024-07-23T18:55:47.315Z","dependency_job_id":null,"html_url":"https://github.com/aida-ugent/fairret","commit_stats":null,"previous_names":["aida-ugent/fairret"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aida-ugent%2Ffairret","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aida-ugent%2Ffairret/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aida-ugent%2Ffairret/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aida-ugent%2Ffairret/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aida-ugent","download_url":"https://codeload.github.com/aida-ugent/fairret/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230261048,"owners_count":18198656,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","artificial-intelligence","bias","deep-learning","fairness","fairness-ai","fairness-ml","machine-learning","python","pytorch"],"created_at":"2024-08-01T13:01:58.119Z","updated_at":"2024-12-20T04:07:26.206Z","avatar_url":"https://github.com/aida-ugent.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# fairret - a fairness library in PyTorch\n\n[![Licence](https://img.shields.io/github/license/aida-ugent/fairret)](https://github.com/aida-ugent/fairret/blob/main/LICENSE)\n[![PyPI - Version](https://img.shields.io/pypi/v/fairret)](https://pypi.org/project/fairret/)\n![Static Badge](https://img.shields.io/badge/PyTorch-ee4c2c)\n[![Static Badge](https://img.shields.io/badge/Original%20Paper-00a0ff)](https://openreview.net/pdf?id=NnyD0Rjx2B)\n\u003cimg src=\"./docs/source/_static/fairret.png\" height=\"300\" align=\"right\"\u003e\n\nThe goal of fairret is to serve as an open-source library for measuring and pursuing statistical fairness in PyTorch models. \n\nThe library is designed to be \n1. *flexible* in how fairness is defined and pursued.\n2. *easy* to integrate into existing PyTorch pipelines.\n3. *clear* in what its tools can and cannot do.\n\nCentral to the library is the paradigm of the _fairness regularization term_ (fairrets) that quantify unfairness as differentiable PyTorch loss functions. \n\nThese can be minimized jointly with other losses, like the binary cross-entropy error, by just adding them together!\n\n## Quickstart\n\nIt suffices to simply choose a _statistic_ that should be equalized across groups and a _fairret_ that quantifies the gap. \n\nThe model can then be trained as follows:\n\n```python\nimport torch.nn.functional as F\nfrom fairret.statistic import PositiveRate\nfrom fairret.loss import NormLoss\n\nstatistic = PositiveRate()\nnorm_fairret = NormLoss(statistic)\n\ndef train(model, optimizer, train_loader):\n     for feat, sens, target in train_loader:\n            optimizer.zero_grad()\n            \n            logit = model(feat)\n            bce_loss = F.binary_cross_entropy_with_logits(logit, target)\n            fairret_loss = norm_fairret(logit, sens)\n            loss = bce_loss + fairret_loss\n            loss.backward()\n            \n            optimizer.step()\n```\n\nNo special data structure is required for the sensitive features. If the training batch contains $N$ elements, then `sens` should be a tensor of floats with shape $(N, d_s)$, with $d_s$ the number of sensitive features. **Like any categorical feature, it is expected that categorical sensitive features are one-hot encoded.**\n\nA notebook with a full example pipeline is provided here: [Simple Pipeline.ipynb](/examples/Simple Pipeline.ipynb).\n\nWe also host [documentation](https://aida-ugent.github.io/fairret/).\n\n## Installation\nThe fairret library can be installed via PyPi:\n\n```\npip install fairret\n```\n\nA minimal list of dependencies is provided in [pyproject.toml](https://github.com/aida-ugent/fairret/blob/main/pyproject.toml). \n\nIf the library is installed locally, the required packages can be installed via `pip install .`\n\n## Warning: AI fairness != fairness\nThere are many ways in which technical approaches to AI fairness, such as this library, are simplistic and limited in actually achieving fairness in real-world decision processes.\n\nMore information on these limitations can be found [here](https://dl.acm.org/doi/full/10.1145/3624700) or [here](https://ojs.aaai.org/index.php/AAAI/article/view/26798).\n\n## Future plans\nThe library maintains a core focus on only fairrets for now, yet we plan to add more fairness tools that align with the design principles in the future. These may involve breaking changes. At the same time, we'll keep reviewing the role of this library within the wider ecosystem of fairness toolkits. \n\nWant to help? Please don't hesitate to open an issue, draft a pull request, or shoot an email to [maarten.buyl@ugent.be](mailto:maarten.buyl@ugent.be).\n\n## Citation\nThis framework will be presented as a paper at ICLR 2024. If you found this library useful in your work, please consider citing it as follows:\n\n```bibtex\n@inproceedings{buyl2024fairret,\n    title={fairret: a Framework for Differentiable Fairness Regularization Terms},\n    author={Buyl, Maarten and Defrance, Marybeth and De Bie, Tijl},\n    booktitle={International Conference on Learning Representations},\n    year={2024}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faida-ugent%2Ffairret","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faida-ugent%2Ffairret","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faida-ugent%2Ffairret/lists"}