Skip to main content

Text Sensitivity logo

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

PyPI Downloads Python_version Lint, Security & Tests License Documentation Status Code style: black DOI


Extension of text_explainability

Uses the generic architecture of text_explainability to also include tests of safety (how safe it the model in production, i.e. types of inputs it can handle), robustness (how generalizable the model is in production, e.g. 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

Safety: test if 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)

Robustness: if 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 accuracy 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

See the installation instructions for an extended installation guide.

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://text-sensitivity.readthedocs.io/.

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_sensitivity 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},
  howpublished = {\url{https://github.com/MarcelRobeer/text_sensitivity}},
  doi = {10.5281/zenodo.14192941},
  year = {2021}
}

Maintenance

Contributors

Todo

Tasks yet to be done:

  • Word-level perturbations
  • Add fairness-specific metrics:
    • 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.3.6

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.3.6
File Size Uploaded Provenance
text_sensitivity-0.3.6.tar.gz 336.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for text-sensitivity 0.3.6
File Interpreter ABI Platform
text_sensitivity-0.3.6-py3-none-any.whl Python 3 none any Details

Total release size: 393.2 kB

Release files / text_sensitivity-0.3.6.tar.gz

Download URL text_sensitivity-0.3.6.tar.gz
Size 336.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d2a65b9f17302bbb731372d228c608aded6fd4efb7a13721de35c0f3ce177955
BLAKE2b-256 checksum
How to use checksums
edca07a135d642f8a5289c25f00c8eb189a92ead88cb812fe65d58c4d8f39135
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.11

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

Download URL text_sensitivity-0.3.6-py3-none-any.whl
Size 56.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0216dbe03bf448881752c40385af1fcbe0b78664ae9df7c2574e886a4498e6a4
BLAKE2b-256 checksum
How to use checksums
3a50f845f529f06bf48a87bc2c2f54777f583470ad4b32080e014cbdbba65138
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.11

Security for text-sensitivity 0.3.6

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.

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