The NLP Bias Identification Toolkit
Project description
biaslyze - The NLP Bias Identification Toolkit
Bias is often subtle and difficult to detect in NLP models, as the protected attributes are less obvious and can take many forms in language (e.g. proxies, double meanings, ambiguities etc.). Therefore, technical bias testing is a key step in avoiding algorithmically mediated discrimination. However, it is currently conducted too rarely due to the effort involved, missing resources or lack of awareness for the problem.
Biaslyze helps to get started with the analysis of bias within NLP models and offers a concrete entry point for further impact assessments and mitigation measures. Especially for teams with limited resources, our toolbox offers a low-effort approach to bias testing in NLP use cases.
Installation
Installation can be done using pypi:
pip install biaslyze
Then you need to download the required spacy models:
python -m spacy download en_core_web_sm
Quickstart
from biaslyze.bias_detectors import CounterfactualBiasDetector
bias_detector = CounterfactualBiasDetector()
# detect bias in the model based on the given texts
# here, clf is a scikit-learn text classification pipeline trained for a binary classification task
detection_res = bias_detector.process(
texts=texts,
predict_func=clf.predict_proba
)
# see a summary of the detection
detection_res.report()
# visualize the counterfactual scores
detection_res.visualize_counterfactual_scores(concept="religion", top_n=10)
Example output:
You can see a more detailed example in the tutorial.
Development setup
- First you need to install poetry to manage your python environment: https://python-poetry.org/docs/#installation
- Run
make install
to install the dependencies and get the spacy basemodels. - Now you can use
biaslyze
in your jupyter notebooks.
Adding concepts and keywords
You can add concepts and new keywords for existing concepts by editing concepts.py.
Preview/build the documentation with mkdocs
To preview the documentation run make doc-preview
. This will launch a preview of the documentation on http://127.0.0.1:8000/
.
To build the documentation html run make doc
.
Run the automated tests
make test
Style guide
We are using isort and black: make style
For linting we are running ruff: make lint
Contributing
Follow the google style guide for python: https://google.github.io/styleguide/pyguide.html
This project uses black, isort and ruff to enforce style. Apply it by running make style
and make lint
.
Acknowledgements
- Funded from March 2023 until August 2023 by
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for biaslyze-0.0.6a0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65a4b270904db99cb3348174af375e7c858427a95263af7d10656d2c93869a20 |
|
MD5 | 17581ea6fae5ed603aa9da2bc10435dd |
|
BLAKE2b-256 | a75b730a41e5860bd87558d82cd4b670a99884b1d61c7d708600c5bcea4e9f26 |