RedactEval
RedactEval is a Python package designed to evaluate redaction frameworks by comparing original and redacted text against ground-truth entity values that should have been redacted. It is agnostic to redaction-framework output format, enabling users to compare frameworks consistently without complex requirements such as character-span annotations in the input dataset.
Installation
pip install redacteval
Usage
-
Create a
RedactionEvaluatorinstance with the following parameters:original_text_column: the column containing original textentity_columns: canonical ground-truth entity columns (e.g.person,email)entity_aliases: optional aliases per canonical entity (to match tag variants)coverage_threshold: minimum GT-coverage threshold for a valid matchstrict_entity_matching: whether redaction tag type must match entity typesegmenter: optional custom sentence segmenter
-
Evaluate one or more redacted outputs with the
evaluatemethod:
evaluator = RedactionEvaluator(
original_text_column="original_text",
entity_columns=["person", "address", "email", "phone_number"],
entity_aliases={
"person": ["person", "first_name", "last_name", "name"],
"address": ["address", "location", "place"],
"email": ["email", "email_address"],
"phone_number": ["phone_number", "mobile_number"],
},
coverage_threshold=0.8,
strict_entity_matching=True,
)
results_a = evaluator.evaluate(df, redacted_text_column="redacted_framework_a", beta=2)
results_b = evaluator.evaluate(df, redacted_text_column="redacted_framework_b", beta=2)
print(results_a.summary())
warnings = results_a.get_warnings()
-
evaluatereturns anEvaluationResultsobject:summary()gives global and per-entity metrics (precision,recall,fbeta_score,tp,fp,fn)get_warnings()returns row-level warnings (for example sentence-structure mismatches)
-
Prepare the data for evaluation:
- Entity columns can contain a string, a list of strings, or
None. - Example:
emailcan hold["xavier@gmail.com", "amanda_c@hotmail.com"]for a single row.
- Entity columns can contain a string, a list of strings, or
Ground-Truth Name Input Requirement
For person names, provide atomic name elements separately in ground-truth data.
- Recommended:
person = ["Sam", "Wilson"]person = ["Jane", "Mary", "Smith"](first/middle/last separately)
- Avoid providing only one combined full-name string when you want per-token scoring:
person = "Sam Wilson"(this is treated as one occurrence, not two)
Example row:
{
"original_text": "Sam Wilson or Jane Smith can help you with the issue.",
"person": ["Sam", "Wilson", "Jane", "Smith"],
"redacted_framework_a": "<PERSON> or <FIRST_NAME> <LAST_NAME> can help you with the issue.",
}
Notes:
- A combined mask over multiple atomic values (for example
<PERSON>over"Sam Wilson") is considered correct when overlap requirements are met. - Name elements are matched as standalone occurrences in context (so substrings inside larger tokens such as emails are not counted as separate person occurrences).
Demo Data
You can start with bundled sample data:
from redacteval import RedactionEvaluator, load_demo_data, print_report
df = load_demo_data()
evaluator = RedactionEvaluator(
original_text_column="original_text",
entity_columns=["name", "email", "phone_number"],
entity_aliases={
"name": ["name", "person", "first_name", "last_name"],
"email": ["email", "email_address"],
"phone_number": ["phone_number", "mobile_number"],
},
)
results = evaluator.evaluate(df, redacted_text_column="redacted_framework_a")
print_report(results)
A runnable notebook is available at examples/demo.ipynb.
License
This project is licensed under the Apache License 2.0.
See LICENSE for details.
Contributing
Contributions are welcome.
Please read CONTRIBUTING.md before opening a pull request.
Metadata
Release files for redacteval 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| redacteval-0.1.0.tar.gz | 14.9 kB | Without provenance | Details for redacteval-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| redacteval-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for redacteval-0.1.0-py3-none-any.whl |
Total release size: 30.4 kB
Release files / redacteval-0.1.0.tar.gz
| Download URL | redacteval-0.1.0.tar.gz |
|---|---|
| Size | 14.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
41f739061b2ea531f1ab9cf8604dc5ff8361af998b80e32f1bc887d6c88643a2
|
|
BLAKE2b-256 checksum How to use checksums |
48046d5c68d451186c9eef6db8817e82184dbb47585d24ce62946cadc682b609
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.9
|
Release files / redacteval-0.1.0-py3-none-any.whl
| Download URL | redacteval-0.1.0-py3-none-any.whl |
|---|---|
| Size | 15.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
caff1ec52a8a1fea7171068c8ff13b89b29e062563fd2dfb16099714489c8b8d
|
|
BLAKE2b-256 checksum How to use checksums |
daa39461884e334c20cc316381e5b29071a237e2f81b80cb612ba71799c47422
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.9
|
Security for redacteval 0.1.0
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.