benchmark-pii-recall
它能做什么
这项技能衡量 PII 检测模型在合成测试文本中找出个人标识符的能力,重点是召回率,即尽量少漏掉标识符。适合在发布前比较模型或设置的团队。
适用场景
- ✓当你在选择 PII 模型、阈值或量化版本之前进行比较的时候。
- ✓当发布需要为直接标识符设定最低召回率规则的时候。
- ✓当你希望有一项可重复进行、且不保存任何原始标识符的检查的时候。
技能链接
https://github.com/maziyarpanahi/openmed/blob/master/skills/benchmark-pii-recall/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请在合成测试文本上比较这两个 PII 模型,并告诉我哪一个达到了 99% 的召回率下限。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会构建带有精确标识符位置的合成测试文档,运行模型,将检测到的片段与之对照打分,并只报告数量,不保存标识符文本。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Benchmark PII recall
Measure PII recall before optimizing F1, size, or latency. A missed direct identifier is a privacy failure even when aggregate F1 improves.
Procedure
- Build synthetic fixtures with exact offsets and canonical PII labels.
- Include direct identifiers, boundary cases, languages/scripts, and the target device or quantization.
- Run
extract_piiat the candidate threshold. - Normalize prediction labels and score each document separately.
- Aggregate counts only; do not persist raw text or identifier surfaces.
- Fail the release when the recall floor or zero-critical-leak requirement is not met.
Runnable synthetic benchmark
Install the model runtime first with python -m pip install "openmed[hf]".
from openmed import extract_pii
from openmed.core.labels import normalize_label
from openmed.eval import compute_character_recall, compute_exact_span_f1
MODEL = "OpenMed/OpenMed-PII-SuperClinical-Small-44M-v1"
RECALL_FLOOR = 0.99
FIXTURES = [
{
"text": (
"Call the synthetic clinic at 212-555-0198 or email "
"demo.patient@example.test."
),
"spans": [
("PHONE", "212-555-0198"),
("EMAIL", "demo.patient@example.test"),
],
},
{
"text": (
"The synthetic callback number is 415-555-0136 and the contact "
"address is sample.user@example.test."
),
"spans": [
("PHONE", "415-555-0136"),
("EMAIL", "sample.user@example.test"),
],
},
]
true_positives = false_positives = false_negatives = 0
covered_graphemes = total_graphemes = 0
for fixture in FIXTURES:
text = fixture["text"]
gold = []
for label, surface in fixture["spans"]:
start = text.index(surface)
gold.append(
{"start": start, "end": start + len(surface), "label": label}
)
result = extract_pii(
text,
model_name=MODEL,
confidence_threshold=0.5,
lang="en",
)
predicted = [
{
"start": entity.start,
"end": entity.end,
"label": normalize_label(entity.label),
}
for entity in result.entities
if entity.start is not None and entity.end is not None
]
exact = compute_exact_span_f1(gold, predicted, source_text=text)
recall = compute_character_recall(gold, predicted, source_text=text)
true_positives += exact.true_positives
false_positives += exact.false_positives
false_negatives += exact.false_negatives
covered_graphemes += int(recall.numerator)
total_graphemes += int(recall.denominator)
exact_recall = true_positives / max(true_positives + false_negatives, 1)
grapheme_recall = covered_graphemes / max(total_graphemes, 1)
print(
{
"documents": len(FIXTURES),
"exact_span_recall": exact_recall,
"grapheme_recall": grapheme_recall,
"false_positives": false_positives,
"false_negatives": false_negatives,
}
)
assert grapheme_recall >= RECALL_FLOOR, "PII recall floor not met"
Release gates
- Require zero misses for critical direct identifiers even if aggregate recall passes.
- Report per-label, language, script, section, and device slices.
- Compare quantized and full-precision outputs; reject recall regressions.
- Add hard negatives so over-redaction does not hide behind high recall.
- Store fixture hashes, model identity, threshold, and aggregate counts only.
- Keep DUA-gated corpora outside the repository and load them only from the user's approved location.
Repository example
Read the policy and release-evidence walkthrough for PHI-free leakage metrics and audit evidence.
常见问题
为什么重点关注召回率?
因为漏掉一个直接标识符就是一次隐私失败,即使整体准确率看起来很高。
它使用真实的患者数据吗?
不使用。基准测试使用带有精确标签位置的合成样本。
它能让发布失败吗?
能。如果未达到召回率下限或零严重泄露规则,它会判定发布失败。
详情
作者的原始描述
Benchmark an OpenMed PII model with synthetic gold spans and report label-aware exact-span and grapheme recall without emitting identifier surfaces. Use when an agent must compare a model, threshold, backend, or quantized artifact and enforce a recall floor before release.
repo: maziyarpanahi/openmed
热度
- GitHub 星标
- 5.8k
- 排名
- #14675
- 许可证
- Apache-2.0
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
annotating-variants
5.8k帮你的智能体预测基因变异的作用,把 HGVS 名称转换为基因组位置,并使用免费的公共注释工具添加人群频率。
ask-openmed
5.8k帮你的智能体为临床文本请求选择合适的 OpenMed 工作流程,并在可能涉及患者数据时,先进行隐私检查。
assembling-fhir-bundles
5.8k把多份 FHIR 健康记录打包成一个事务 Bundle,可直接发送给 EHR 系统,并正确链接其中的内部引用。
auditing-deid-leakage
5.8k扫描已去标识化的临床文本,查找残留的标识符,例如社会安全号、银行卡号、电子邮件地址和日期,若仍有残留则阻止发布。