A fair PyTorch loss function
The goal of this loss function is to take fairness into account during the training of a PyTorch model. It works by adding a fairness measure to a regular loss value, following this equation:
Installation
pip install fair-loss
Example
import torch
from fair_loss import FairLoss
model = torch.nn.Sequential(torch.nn.Linear(5, 1), torch.nn.ReLU())
data = torch.randint(0, 5, (100, 5), dtype=torch.float, requires_grad=True)
y_true = torch.randint(0, 5, (100, 1), dtype=torch.float)
y_pred = model(data)
# Let's say the sensitive attribute is in the second dimension
dim = 1
criterion = FairLoss(torch.nn.MSELoss(), data[:, dim].detach().unique(), accuracy)
loss = criterion(data[:, dim], y_pred, y_true)
loss.backward()
Documentation
See the documentation.
Metadata
Release files for fair-loss 0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fair_loss-0.5.tar.gz | 29.8 kB | Without provenance | Details for fair_loss-0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fair_loss-0.5-py3-none-any.whl | Python 3 | none | any | Details for fair_loss-0.5-py3-none-any.whl |
Total release size: 46.1 kB
Release files / fair_loss-0.5.tar.gz
| Download URL | fair_loss-0.5.tar.gz |
|---|---|
| Size | 29.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ce14885a0b4ca91d6e9a2bbed38462394761f5c460f4cd2ac4776c1ba25439c4
|
|
BLAKE2b-256 checksum How to use checksums |
e8e633fbaaa2bc3f2d0e86cc7c09edc75083ea987ec0cd2cc2797649e86173c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
|
Release files / fair_loss-0.5-py3-none-any.whl
| Download URL | fair_loss-0.5-py3-none-any.whl |
|---|---|
| Size | 16.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
66046aa130cd303bf84c8d02e2f072f2141783c5039e8b16cbf7f597f2d3fe2b
|
|
BLAKE2b-256 checksum How to use checksums |
ad56e33ac0716abd294f6d586ecd106f026372ce252b709f27621e7c95f8d5af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
|
Security for fair-loss 0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.