Skip to main content

Extension of text_explainability for sensitivity testing (robustness, fairness)

Project description

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 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

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},
  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

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

text_sensitivity-0.2.4.tar.gz (38.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

text_sensitivity-0.2.4-py3.9.egg (81.8 kB view details)

Uploaded Egg

text_sensitivity-0.2.4-py3-none-any.whl (41.6 kB view details)

Uploaded Python 3

File details

Details for the file text_sensitivity-0.2.4.tar.gz.

File metadata

  • Download URL: text_sensitivity-0.2.4.tar.gz
  • Upload date:
  • Size: 38.9 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for text_sensitivity-0.2.4.tar.gz
Algorithm Hash digest
SHA256 fb794ad1ec3b588cb5d5eaeb7dcb435309041157d6eeb39ca300a7de4a5ea9f5
MD5 fb078f5a9131f45eb22886e574004b05
BLAKE2b-256 16248e58c8f8bc5106a6289cc49cdf2617ea405d2d2378c56260b91b5a40314a

See more details on using hashes here.

File details

Details for the file text_sensitivity-0.2.4-py3.9.egg.

File metadata

  • Download URL: text_sensitivity-0.2.4-py3.9.egg
  • Upload date:
  • Size: 81.8 kB
  • Tags: Egg
  • Uploaded using 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

File hashes

Hashes for text_sensitivity-0.2.4-py3.9.egg
Algorithm Hash digest
SHA256 985f894c8be7b8c1ab74916b1eaebe171b03ba57701e19e7efe5c284ab20f721
MD5 d1163727da7a9460ccaf7940548bc58e
BLAKE2b-256 dd15b1a4d2d2dd7a699970969e5c659f800d59b400a0c60ee01186ba0e9db748

See more details on using hashes here.

File details

Details for the file text_sensitivity-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: text_sensitivity-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 41.6 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for text_sensitivity-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 aabf75d447e611aa924fdabef499b83e510112a8488c7122b05a02a2fec6e493
MD5 2b33761b331f5a4f66a666a2b82bb055
BLAKE2b-256 913bc5ad9a69baf7928694e61059cab1dfcbc2fb147f051c0e1118831c0ca7c3

See more details on using hashes here.

Supported by

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