sixmonth-redact / tests /test_examples.py
joehachem's picture
fix: keep phone brackets, plus signs and urls whole in redact output
151500a verified
Raw History Blame Contribute Delete
950 Bytes
"""Checks that the documented examples behave as described.
python tests/test_examples.py
"""
import os
from transformers import AutoModel
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
model = AutoModel.from_pretrained(ROOT, trust_remote_code=True).eval()
cases = [
("Called Mrs Johnson re: appt on March 3rd. Pt c/o pain #19. Policy no. BC-44817203.",
"Called Mrs [REDACTED] re: appt on [REDACTED]. Pt c/o pain #19. Policy no. [REDACTED]."),
("Call +1 (415) 555-0100 or (617)555-0144. See https://myclinic.example.com/p/8842",
"Call [REDACTED] or [REDACTED]. See [REDACTED]"),
]
for text, want in cases:
got = model.redact(text)
assert got == want, f"\n got: {got}\nwant: {want}"
for keep in ["Amoxicillin 500mg", "#14", "RCT", "tid"]:
assert keep in model.redact("Rx Amoxicillin 500mg tid, #14 RCT."), keep
assert sum(p.numel() for p in model.parameters()) == 5_773_706
print("examples ok")