Skip to main content

pic2   pic5   pic1   pic8

pic6   pic7   pic3   pic4

AI systems can create, propagate, support, and automate bias in decision-making processes. To mitigate biased decisions, we both need to understand the origin of the bias and define what it means for an algorithm to make fair decisions. By Locating Unfairness through Canonical Inverse Design (LUCID), we generate a canonical set that shows the desired inputs for a model given a preferred output. The canonical set reveals the model’s internal logic and exposes potential unethical biases by repeatedly interrogating the decision-making process.

LUCID-GAN extends on LUCID by generating canonical inputs via a conditional generative model instead of gradient-based inverse design. LUCID-GAN generates canonical inputs conditional on the predictions of the model under fairness evaluation. LUCID-GAN has several benefits, including that it applies to non-differentiable models, ensures that a canonical set consists of realistic inputs, and allows us to assess indirect discrimination and explicitly check for intersectional unfairness.

Read our paper on LUCID and LUCID-GAN for more details, or check out the documentation.

We encourage everyone to contribute to this project by submitting an issue or a pull request!

Installation

Install canonical_sets from PyPi.

pip install canonical_sets

For development install, see contribute. You can also check the documentation.

Usage

LUCID

LUCID can be used for the gradient-based inverse design to generate canonical sets, and is available for both PyTorch and Tensorflow models. It only requires a model, a preferred output, and an example input (which is often a part of the training data). The results are stored in a pd.DataFrame, and can be accessed by calling results. It’s fully customizable, but can also be used out-of-the-box for a wide range of applications by using its default settings:

import pandas as pd

from canonical_sets.data import Adult
from canonical_sets.models import ClassifierTF
from canonical_sets import LUCID

adult = Adult()

model = ClassifierTF(2)
outputs = pd.DataFrame([[0, 1]], columns=["<=50K", ">50K"])
example_data = adult.train_data

lucid = LUCID(model, outputs, example_data)
lucid.results.head()

LUCID-GAN

LUCIDGAN generates canonical sets by using conditional generative models (GANs). This approach has several benefits, including that it applies to non–differentiable models, ensures that a canonical set consists of realistic inputs, and allows us to assess indirect discrimination and explicitly check for intersectional unfairness. LUCID-GAN only requires the input and predictions of a black-box model. It’s fully customizable, but can also be used out-of-the-box for a wide range of applications by using its default settings:

import pandas as pd

from canonical_sets.data import Adult
from canonical_sets.models import ClassifierTF
from canonical_sets import LUCIDGAN

model = ClassifierTF(2)
adult = Adult()

# we need original data as LUCID-GAN does some preprocessing
test_data = adult.inverse_preprocess(adult.test_data)

# we only require the predictions for the positive class
preds = model.predict(adult.test_data.to_numpy())[:, 1]

data = pd.concat([test_data, pd.DataFrame(preds, columns=["preds"])], axis=1)

lucidgan = LUCIDGAN(epochs=5)
lucidgan.fit(data, conditional=["preds"])

samples = lucidgan.sample(100, conditional=pd.DataFrame({"preds": [1]}))
samples.head()

For detailed examples see examples and for the source code see canonical_sets. For LUCID, we advice to start with either the tensorflow or pytorch example, and then the advanced example. For LUCIDGAN, you can replicate the experiments from the paper with the GAN_adult and GAN_compas examples. You can also check the documentation for more details. If you have any remaining questions, feel free to submit an issue or PR!

Output-based group metrics

Most group fairness notions focus on the equality of outcome by computing statistical parity metrics on a model’s output. The two most prominent examples of these statistical output-based metrics are Demographic Parity (DP) and Equality Of Opportunity (EOP). In DP, we compare the Positivity Rate (PR) of the subpopulations under fairness evaluation, and in EOP, we compare the True Positive Rate (TPR). The choice between DP and EOP depends on the underlying assumptions and worldview of the evaluator. The Metrics class allows you to compute these metrics for binary classification tasks given the predictions and ground truth:

from canonical_sets.data import Adult
from canonical_sets.models import ClassifierTF
from canonical_sets.group import Metrics

model = ClassifierTF(2)
adult = Adult()

preds = model.predict(adult.test_data.to_numpy()).argmax(axis=1)
targets = adult.test_labels[">50K"]

metrics = Metrics(preds, targets)
metrics.metrics

Data

canonical_sets contains some functionality to easily access commonly used data sets in the fairness literature:

from canonical_sets import Adult, Compas

adult = Adult()
adult.train_data.head()

compas = Compas()
compas.train_data.head()

The default settings can be customized to change the pre-processing, splitting, etc. See examples for details. You can also check the documentation.

Community

If you are interested in cross-disciplinary research related to machine learning, feel free to:

Disclaimer

The package and the code is provided “as-is” and there is NO WARRANTY of any kind. Use it only if the content and output files make sense to you.

Acknowledgements

This project benefited from financial support from Innoviris.

LUCIDGAN is based on the CTGAN class from the ctgan package. It has been extended to fix several bugs (see my PR on the CTGAN GitHub page) and to allow for the extension of the conditional vector. A part of the code and comments is identical to the original CTGAN class.

Citation

@inproceedings{mazijn_lucid_2023,
  title={{LUCID: Exposing Algorithmic Bias through Inverse Design}},
  author={Mazijn, Carmen and Prunkl, Carina and Algaba, Andres and Danckaert, Jan and Ginis, Vincent},
  booktitle={Thirty-Seventh AAAI Conference on Artificial Intelligence (accepted)},
  year={2023},
}

@article{algaba_lucidgan_2022,
  title={{LUCID-GAN: Conditional Generative Models to Locate Unfairness}},
  author={Algaba, Andres and Mazijn, Carmen and Prunkl, Carina and Danckaert, Jan and Ginis, Vincent},
  year={2022},
  journal={Working paper}
}

Metadata

Release files for canonical-sets 0.0.3

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

Source distribution (sdist)

Source distribution for canonical-sets 0.0.3
File Size Uploaded
canonical_sets-0.0.3.tar.gz 23.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for canonical-sets 0.0.3
File Interpreter ABI Platform
canonical_sets-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 51.3 kB

Release files / canonical_sets-0.0.3.tar.gz

Download URL canonical_sets-0.0.3.tar.gz
Size 23.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a913fcf3d58c21a0d82d2ade83b3bb71558f379a93e4c376da62da8d9988f2b7
BLAKE2b-256 checksum
How to use checksums
f15a91ebea3c83997e237791d3903539a66c6392bce747dfc748c03b25439959
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.14 CPython/3.9.13 Windows/10

Release files / canonical_sets-0.0.3-py3-none-any.whl

Download URL canonical_sets-0.0.3-py3-none-any.whl
Size 27.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
833d682fab4ee37d6ebd20710b615235cc86f39b5943b7d1e63ce3a8960b191c
BLAKE2b-256 checksum
How to use checksums
74244da3a2056a1ff75b76ad730fb35f0f2ee62a810bd8a4fa76409bcc95f080
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.14 CPython/3.9.13 Windows/10

Release history Release notifications | RSS feed

This release

0.0.3 This release

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