Skip to main content

HONEST: Measuring Hurtful Sentence Completion in Language Models

https://img.shields.io/pypi/v/honest.svg https://img.shields.io/travis/MilaNLProc/honest.svg Documentation Status Medium Blog Post

…

Large language models (LLMs) have revolutionized the field of NLP. However, LLMs capture and proliferate hurtful stereotypes, especially in text generation. We propose HONEST, a score to measure hurtful sentence completions in language models. It uses a systematic template- and lexicon-based bias evaluation methodology in six languages (English, Italian, French, Portuguese, Romanian, and Spanish) for binary gender and in English for LGBTQAI+ individuals.

…

See the papers for additional details:

Nozza D., Bianchi F., and Hovy D. “HONEST: Measuring hurtful sentence completion in language models.” The 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies. Association for Computational Linguistics, 2021. https://aclanthology.org/2021.naacl-main.191

Nozza D., Bianchi F., Lauscher L., and Hovy D. “Measuring Harmful Sentence Completion in Language Models for LGBTQIA+ Individuals.” The Second Workshop on Language Technology for Equality, Diversity and Inclusion at the Annual Meeting of the Association for Computational Linguistics 2022. https://milanlproc.github.io/publication/2022-honest-hurtful-language-model-lgbtqia+/

Tutorials

Name

Link

Compute HONEST score (+Viz) (stable v0.2.0)

Open In Colab

Installing

pip install -U honest

Using

# Load HONEST templates
evaluator = honest.HonestEvaluator(lang)
masked_templates = evaluator.templates(data_set="binary") # or "queer_nonqueer" or "all"

# Load BERT model
tokenizer = AutoTokenizer.from_pretrained(name_model)
model = AutoModelForMaskedLM.from_pretrained(name_model)

# Define nlp_fill pipeline
nlp_fill = pipeline('fill-mask', model=model, tokenizer=tokenizer, top_k=k)

print("FILL EXAMPLE:",nlp_fill('all women likes to [M].'.replace('[M]',tokenizer.mask_token)))

# Fill templates (please check if the filled words contain any special character)
filled_templates = [[fill['token_str'].strip() for fill in nlp_fill(masked_sentence.replace('[M]',tokenizer.mask_token))] for masked_sentence in masked_templates.keys()]

honest_score = evaluator.honest(filled_templates)
print(name_model, k, honest_score)

Citation

Please use the following bibtex entries if you use this score in your project:

@inproceedings{nozza-etal-2021-honest,
title = {"{HONEST}: Measuring Hurtful Sentence Completion in Language Models"},
author = "Nozza, Debora and Bianchi, Federico  and Hovy, Dirk",
booktitle = "Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies",
month = jun,
year = "2021",
address = "Online",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2021.naacl-main.191",
doi = "10.18653/v1/2021.naacl-main.191",
pages = "2398--2406",
}

@inproceedings{nozza-etal-2022-measuring,
    title = {Measuring Harmful Sentence Completion in Language Models for LGBTQIA+ Individuals},
    author = "Nozza, Debora and Bianchi, Federico and Lauscher, Anne and Hovy, Dirk",
    booktitle = "Proceedings of the Second Workshop on Language Technology for Equality, Diversity and Inclusion",
    publisher = "Association for Computational Linguistics",
    year={2022}
}

Development Team

Software Details

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

Note

Remember that this is a research tool :)

History

0.1.0 (2022-01-25)

  • First release on PyPI.

Metadata

Release files for honest 0.2.1

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

Source distribution (sdist)

Source distribution for honest 0.2.1
File Size Uploaded Provenance Actions
honest-0.2.1.tar.gz 8.0 kB Without provenance Details for honest-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for honest 0.2.1
File Interpreter ABI Platform Actions
honest-0.2.1-py2.py3-none-any.whl Python 3, Python 2 none any Details for honest-0.2.1-py2.py3-none-any.whl

Total release size: 14.3 kB

Release files / honest-0.2.1.tar.gz

Download URL honest-0.2.1.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
06cf98505d71b0096ea6f59a8cfd56d8bbe38d6ec139b3d82498f780c03d2a0b
BLAKE2b-256 checksum
How to use checksums
97fae89b13a568899fe4e84a7198510b9a89da73187379dbbed304f0c65ace6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

Release files / honest-0.2.1-py2.py3-none-any.whl

Download URL honest-0.2.1-py2.py3-none-any.whl
Size 6.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
44d934e495f7bdacf3a8e84434f6b17f3eae188dfff2f4f036db8e3930212415
BLAKE2b-256 checksum
How to use checksums
85b04612f975924aa0539c41a09e3ad9fcb42ae17ca143831c64b3e6f9d9d3d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

Security for honest 0.2.1

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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