Skip to main content

T_xt Sensitivity logo

Sensitivity testing (fairness & robustness) for text machine learning models

PyPI Python_version Build_passing License Docs_passing Code style: black


Extension of text_explainability

Uses the generic architecture of text_explainability to also include tests of robustness (how generalizable the model is in production, e.g. ability to handle input characters, stability when adding typos, or the effect of adding random unrelated data) and fairness (if equal individuals are treated equally by the model, e.g. subgroup fairness on sex and nationality).

© Marcel Robeer, 2021

Quick tour

Robustness: test whether your model is able to handle different data types...

from text_sensitivity import RandomAscii, RandomEmojis, combine_generators

# Generate 10 strings with random ASCII characters
RandomAscii().generate_list(n=10)

# Generate 5 strings with random ASCII characters and emojis
combine_generators(RandomAscii(), RandomEmojis()).generate_list(n=5)

... whether your model performs equally for different entities ...

from text_sensitivity import RandomAddress, RandomEmail

# Random address of your current locale (default = 'nl')
RandomAddress(sep=', ').generate_list(n=5)

# Random e-mail addresses in Spanish ('es') and Portuguese ('pt'), and include from which country the e-mail is
RandomEmail(languages=['es', 'pt']).generate_list(n=10, attributes=True)

... and if it is robust under simple perturbations.

from text_sensitivity import compare_accuracy
from text_sensitivity.perturbation import to_upper, add_typos

# Is model accuracy equal when we change all sentences to uppercase?
compare_accuracy(env, model, to_upper)

# Is model accracy equal when we add typos in words?
compare_accuracy(env, model, add_typos)

Fairness: see if performance is equal among subgroups.

from text_sensitivity import RandomName

# Generate random Dutch ('nl') and Russian ('ru') names, both 'male' and 'female' (+ return attributes)
RandomName(languages=['nl', 'ru'], sex=['male', 'female']).generate_list(n=10, attributes=True)

Installation

Method Instructions
pip Install from PyPI via pip3 install text_sensitivity.
Local Clone this repository and install via pip3 install -e . or locally run python3 setup.py install.

Documentation

Full documentation of the latest version is provided at https://marcelrobeer.github.io/text_sensitivity/.

Example usage

See example_usage.md to see an example of how the package can be used, or run the lines in example_usage.py to do explore it interactively.

Releases

text_explainability is officially released through PyPI.

See CHANGELOG.md for a full overview of the changes for each version.

Citation

@misc{text_sensitivity,
  title = {Python package text\_sensitivity},
  author = {Marcel Robeer and Elize Herrewijnen},
  howpublished = {\url{https://git.science.uu.nl/m.j.robeer/text_sensitivity}},
  year = {2021}
}

Maintenance

Contributors

Todo

Tasks yet to be done:

  • Word-level perturbations
  • Add fairness-specific metrics:
    • Subgroup fairness
    • Counterfactual fairness
  • Add expected behavior
    • Robustness: equal to prior prediction, or in some cases might expect that it deviates
    • Fairness: may deviate from original prediction
  • Tests
    • Add tests for perturbations
    • Add tests for sensitivity testing schemes
  • Add visualization ability

Credits

Metadata

Release files for text-sensitivity 0.2.0

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

Source distribution (sdist)

Source distribution for text-sensitivity 0.2.0
File Size Uploaded
text_sensitivity-0.2.0.tar.gz 37.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for text-sensitivity 0.2.0
File Interpreter ABI Platform
text_sensitivity-0.2.0-py3.9.egg Legacy Egg format - - Details
text_sensitivity-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 2.3 MB

Release files / text_sensitivity-0.2.0.tar.gz

Download URL text_sensitivity-0.2.0.tar.gz
Size 37.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8589346a36a1cb3d742c5cbacbb9acebb512fa26a37fe723b147c93d25b6dcbf
BLAKE2b-256 checksum
How to use checksums
ca4930b359de96d9c958125b0fe1bd1a2aaabb530bdbc2fb8ee0b9e27067b774
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.3.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.6

Release files / text_sensitivity-0.2.0-py3.9.egg

Download URL text_sensitivity-0.2.0-py3.9.egg
Size 1.1 MB
Tags Egg
SHA-256 checksum
How to use checksums
ab21052dbd7f1ad71a9947371130f7a7f18529943bcee37e619f61b2f4aafbf4
BLAKE2b-256 checksum
How to use checksums
31cdc1e34ff899286db1b2deb304ac080f759ba9d945a566c72249ff0c871127
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.3.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.6

Release files / text_sensitivity-0.2.0-py3-none-any.whl

Download URL text_sensitivity-0.2.0-py3-none-any.whl
Size 1.1 MB
Tags Python 3
SHA-256 checksum
How to use checksums
ae0375d6b1983bc1d952eee29f59a1c9371209d5789445d9b48b96a6424c9596
BLAKE2b-256 checksum
How to use checksums
18100590c219918a1a481605f9ed236d409d122dbbae5c01d121081b417d7494
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.3.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.6

Release history Release notifications | RSS feed

0.3.6

2 release files

0.3.5

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.6

3 release files

0.2.5

3 release files

0.2.4

3 release files

0.2.3

3 release files

0.2.2

2 release files

0.2.1

3 release files

This release

0.2.0 This release

3 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

3 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

3 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

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