generating-synthetic-surrogates
Skill này làm gì
Skill này thay định danh bệnh nhân trong văn bản lâm sàng bằng các giá trị giả chân thực, đúng loại, chẳng hạn một tên giả thay cho tên thật. Văn bản vẫn dễ đọc và các công cụ khác vẫn phân tích được. Dành cho các nhóm cần văn bản tự nhiên, an toàn.
Khi nào nên dùng
- ✓Khi các ghi chú đã khử nhận dạng cần vẫn tự nhiên và dễ đọc thay vì đầy dấu che.
- ✓Khi văn bản huấn luyện hoặc demo cần danh tính giả nhất quán xuyên suốt một tài liệu.
- ✓Khi bạn muốn một định dạng thay thế tùy chỉnh, như mẫu số hồ sơ bệnh án riêng của bạn.
Liên kết skill
https://github.com/maziyarpanahi/openmed/blob/master/skills/generating-synthetic-surrogates/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Hãy khử nhận dạng ghi chú này bằng cách thay tên và số hồ sơ bằng giá trị giả chân thực, nhất quán trong toàn bộ tài liệu.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent phát hiện định danh, tạo một giá trị giả phù hợp cho từng loại, giữ giá trị giả của mỗi người nhất quán trong ghi chú, rồi trả về văn bản dễ đọc.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Generating synthetic surrogates
method="replace" swaps each detected identifier for a realistic, type-matched
fake — John Doe becomes Mark Lee, a phone becomes a plausible phone, a date
becomes a plausible date. Unlike opaque [REDACTED]/[NAME] masks, surrogate
text reads naturally and stays parseable by downstream NLP, while still
containing no real PHI. OpenMed generates surrogates on-device via Faker-backed
providers keyed to each canonical label.
When to use this skill
Use surrogates when the de-identified text must remain readable or machine-
parseable: training data for clinical NLP, demos, QA, or notes a human still
needs to skim. If you only need the identifiers gone and don't care about
readability, plain method="mask" is simpler and more obviously redacted.
Quick start
import openmed
note = (
"Patient John Doe (MRN 1234567) saw Dr. John Doe's colleague on 2024-03-02. "
"Reach John Doe at 617-555-0142."
)
result = openmed.deidentify(
note,
method="replace",
consistent=True, # every "John Doe" -> the SAME surrogate within this call
seed=42, # reproducible across runs
locale="en_US", # shapes the fakes; defaults from lang via LANG_TO_LOCALE
)
print(result.deidentified_text)
# Patient Mark Lee (MRN 8830127) saw Dr. Mark Lee's colleague on 2024-07-18. ...
consistent=True is what makes the output coherent: the three mentions of
"John Doe" collapse to one fake identity instead of three different ones, so the
note still makes sense. seed= makes that mapping reproducible run to run.
Surrogates vs opaque redaction
method="mask" ([NAME]) |
method="replace" (surrogate) |
|
|---|---|---|
| Readability | low — placeholders | high — reads like a real note |
| Downstream NLP | tokenizers see [NAME] everywhere |
natural distribution preserved |
| Co-reference | lost (all [NAME]) |
preserved with consistent=True |
| Obvious it's de-identified | yes | no (must be tracked out-of-band) |
| Reversible | with keep_mapping=True |
with keep_mapping=True |
Custom providers and label generators
When a built-in surrogate doesn't match your house format (e.g. your MRNs are
H + 7 digits), register a generator or a Faker provider.
from openmed import (
register_label_generator, register_clinical_provider,
Anonymizer, AnonymizerConfig,
)
# Override the surrogate for one canonical label. Signature: (faker, original, *, locale)
def hospital_mrn(faker, original, *, locale):
return f"H{faker.numerify('#######')}"
register_label_generator("ID_NUM", hospital_mrn) # global, all new Anonymizers
# Add a whole custom Faker provider (e.g. proprietary identifier formats):
register_clinical_provider(MyClinicalProvider) # a faker BaseProvider subclass
# Per-instance control (preferred for isolation): pass providers via config,
# and pull a single surrogate directly when you need one.
anon = Anonymizer(AnonymizerConfig(
lang="en", consistent=True, seed=7, custom_providers=[MyClinicalProvider],
))
fake = anon.surrogate("1234567", "ID_NUM")
Use register_label_generator(canonical_label, fn) to swap one label's
surrogate; register_clinical_provider(provider) to add providers globally; or
AnonymizerConfig.custom_providers for per-run scoping. Validate any custom
label against openmed.CANONICAL_LABELS.
Workflow
- Choose
method="replace"(or a profile likegdpr_pseudonymization/canada_pipedathat replaces by default — seeconfiguring-privacy-policies). - Enable consistency with
consistent=Trueand aseed=so repeated mentions resolve to one identity and the result is reproducible. - Set
locale=so surrogates look native (pt_BR,de_DE, …); it defaults fromlangviaLANG_TO_LOCALE(deidentifying-multilingual-text). - Register custom generators for any house-specific formats (MRN, account, address) before the run.
- If reversibility is needed, add
keep_mapping=Trueand storeresult.mappingas a secret, separate from the output. - Verify no surrogate collides with a real value and residual risk is low
(
auditing-deidentification-runs).
Hand-off to / from OpenMed
- Core de-id:
deidentifying-clinical-text—method, thresholds,keep_mapping, policies. - Policies that replace:
configuring-privacy-policies(gdpr_pseudonymization,canada_pipeda). - **Multilingual surrogat
Câu hỏi thường gặp
Các giá trị giả có thể tái tạo không?
Có. Dùng một seed cố định sẽ làm đầu ra có thể tái tạo qua các lần chạy.
Cùng một người có nhận được cùng tên giả không?
Khi bật chế độ nhất quán, mỗi định danh được ánh xạ tới cùng một giá trị giả trong một tài liệu.
Che có tốt hơn trong một số trường hợp không?
Có. Nếu tính dễ đọc không quan trọng, che đơn giản dễ hơn và được đánh dấu rõ là đã che.
Chi tiết
Mô tả gốc của tác giả
Replace detected PHI with realistic, type-matched fake values in OpenMed so clinical notes stay readable and parseable instead of full of [REDACTED] markers. Use when the user wants surrogate names, MRNs, addresses, or dates rather than opaque masks, needs consistent fake identities across a document, must keep notes natural for downstream NLP, or wants to register a custom surrogate generator or provider. Covers deidentify(method=\"replace\", consistent=True, seed=..., locale=...), register_label_generator, register_clinical_provider, and Anonymizer/AnonymizerConfig. Pairs with OpenMed deiden
repo: maziyarpanahi/openmed
Độ phổ biến
- Sao GitHub
- 5.8k
- Vị trí xếp hạng
- #14707
- Giấy phép
- Apache-2.0
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
annotating-variants
5.8kGiúp agent dự đoán tác động của biến thể di truyền, đổi tên HGVS sang vị trí bộ gen và gắn tần suất quần thể bằng công cụ chú giải miễn phí.
ask-openmed
5.8kGiúp agent chọn đúng quy trình OpenMed cho yêu cầu về văn bản lâm sàng, luôn kiểm tra quyền riêng tư trước khi có thể có dữ liệu bệnh nhân.
assembling-fhir-bundles
5.8kGói nhiều bản ghi y tế FHIR thành một Bundle giao dịch để gửi tới EHR, với các tham chiếu nội bộ được liên kết đúng.
auditing-deid-leakage
5.8kQuét văn bản lâm sàng đã khử nhận dạng để tìm định danh còn sót như SSN, số thẻ, email và ngày tháng, và chặn phát hành nếu còn sót.
Skill tương tự
reverse-engineer-anything
422kGiúp agent của bạn xem bên trong các app và package đã phát hành để giải thích tính năng, so sánh phiên bản hoặc hướng dẫn dựng lại bằng công cụ REA.
1password
394kGiúp agent của bạn cài đặt CLI của 1Password, đăng nhập, và đọc hoặc đưa thông tin bí mật vào mà không in giá trị ra cuộc trò chuyện.
healthcheck
394kGiúp agent của bạn rà soát bảo mật máy tính hoặc máy chủ đang chạy OpenClaw, như SSH, tường lửa, cập nhật và sao lưu, rồi đề xuất cách sửa an toàn.