Skip to main content

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 young developers, students and teams with limited resources, our toolbox offers a low-effort approach to bias testing in NLP use cases.


Installation can be done using pypi:

pip install biaslyze


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(

# see a summary of the detection

# 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:
  • 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

Preview/build the documentation with mkdocs

To preview the documentation run make doc-preview. This will launch a preview of the documentation on 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


Follow the google style guide for python:

This project uses black, isort and ruff to enforce style. Apply it by running make style and make lint.


  • Funded from March 2023 until August 2023 by logos of the "Bundesministerium für Bildung und Forschung", Prodotype Fund and OKFN-Deutschland

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

biaslyze-0.0.5a0.tar.gz (21.2 kB view hashes)

Uploaded Source

Built Distribution

biaslyze-0.0.5a0-py3-none-any.whl (22.0 kB view hashes)

Uploaded Python 3

Supported by

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