Chuyển đến nội dung
Skillpedia
Lập trình chung5.8k · #14677

bridging-presidio-and-spacy

Skill này làm gì

Skill này liên kết các công cụ văn bản lâm sàng của OpenMed với Presidio, spaCy và LangChain, là các công cụ phổ biến để phát hiện dữ liệu cá nhân và ứng dụng ngôn ngữ. Dành cho lập trình viên đã chạy một trong các công cụ đó và muốn đưa OpenMed vào trong.

Khi nào nên dùng

  • ✓Khi bạn đã chạy Microsoft Presidio và muốn thêm phát hiện PII lâm sàng của OpenMed vào đó.
  • ✓Khi pipeline spaCy của bạn nên tạo ra các đoạn dữ liệu cá nhân của OpenMed.
  • ✓Khi bạn xây chuỗi LangChain và muốn loại bỏ thông tin bệnh nhân trước khi văn bản đến mô hình ngôn ngữ.

Liên kết skill

https://github.com/maziyarpanahi/openmed/blob/master/skills/bridging-presidio-and-spacy/SKILL.md

Sao 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

Hãy dùng skill này để giúp tôi: https://github.com/maziyarpanahi/openmed/blob/master/skills/bridging-presidio-and-spacy/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Tôi đang dùng Microsoft Presidio. Hãy thêm phát hiện PII lâm sàng của OpenMed vào pipeline Presidio của tôi.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent chỉ cài phần mở rộng cần thiết cho công cụ đã chọn, rồi dùng bộ chuyển đổi tương ứng để đổi qua lại giữa kết quả OpenMed và định dạng của công 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.

Bridging Presidio, spaCy & LangChain

OpenMed interoperates with the dominant PII/NLP ecosystems through a single, lazy adapter registry: openmed.interop. Adapters live behind explicit imports, so importing openmed never drags in Presidio, spaCy, or LangChain — each is an optional extra you install only when you need that bridge.

When to use

Reach for a bridge when:

  • you already run Microsoft Presidio and want OpenMed's clinical PII recall on top (or to feed OpenMed spans back into Presidio's anonymizer);
  • you have a spaCy pipeline and want OpenMed PII spans on the Doc;
  • you build LangChain chains and want to redact PHI before text reaches an LLM (the on-device guardrail in front of a cloud model);
  • you need OpenMed's de-identification reachable from an existing framework instead of rewriting the pipeline around openmed.deidentify.

The lazy adapter registry (verified)

import openmed.interop as interop

interop.available_adapters()
# ('cda', 'hl7v2', 'langchain', 'presidio', 'spacy')

spec = interop.adapter_spec("presidio")
# AdapterSpec(name='presidio', module='openmed.interop.presidio',
#             extra='presidio', description='Presidio RecognizerResult adapter')

mod = interop.get_adapter("presidio")        # imports openmed.interop.presidio
# Attribute access also works lazily:
openmed.interop.presidio                      # same module, imported on first touch

available_adapters() and adapter_spec() never import the adapter module, so they are safe to call for discovery even without the extra installed. get_adapter(name) (and attribute access) triggers the import — and the adapter's own optional dependency.

Install only the extra you need:

pip install "openmed[presidio]"     # Presidio RecognizerResult adapter
pip install "openmed[spacy]"        # spaCy openmed_deid component
pip install "openmed[langchain]"    # LangChain redaction runnable
# cda and hl7v2 adapters ship in core (no extra) — see their own skills

Presidio bridge (verified callables)

Module openmed.interop.presidio converts between Presidio RecognizerResults and OpenMed canonical PIIEntitys, and merges both detectors through OpenMed's semantic-unit merger.

from openmed.interop.presidio import (
    to_canonical,        # RecognizerResult(s) -> [PIIEntity]
    from_canonical,      # [PIIEntity] -> [RecognizerResult]  (needs presidio extra)
    merge_with_openmed,  # combine OpenMed + Presidio spans, resolve overlaps
    PresidioAdapterConfig,
)
import openmed

text = "Dr. Smith called patient at 617-555-0123 on 2024-03-02."

# Presidio gives you RecognizerResults; OpenMed gives PIIEntities.
openmed_spans = openmed.extract_pii(text).entities
presidio_results = analyzer.analyze(text=text, language="en")   # your Presidio analyzer

merged = merge_with_openmed(
    openmed_spans, presidio_results, text=text,
    config=PresidioAdapterConfig(preserve_presidio_labels=True),
)
# -> de-duplicated [PIIEntity]; overlaps resolved by score, length, OpenMed-origin

Why merge instead of union: merge_with_openmed runs both detectors' spans through merge_entities_with_semantic_units, so overlapping/adjacent detections collapse into one correct span (e.g. PHONE from Presidio vs a partial OpenMed hit) rather than producing double redactions. Label mapping is built in (Presidio PHONE_NUMBER ↔ OpenMed PHONE, US_SSN ↔ SSN, etc.).

To push OpenMed spans into Presidio's anonymizer, convert back:

results = from_canonical(openmed_spans)        # [RecognizerResult]
anonymized = anonymizer.anonymize(text=text, analyzer_results=results)

spaCy bridge (verified factory)

Module openmed.interop.spacy_component registers a spaCy pipeline factory named openmed_deid. Add it to a pipeline and OpenMed PII spans land on the Doc.

import spacy
import openmed.interop.spacy_component   # registers the @Language.factory

nlp = spacy.blank("en")
nlp.add_pipe("openmed_deid", config={
    "confidence_threshold": 0.5,
    "lang": "en",
    "target": "openmed_pii",     # doc.spans key
    "merge_ents": False,         # set True to also write doc.ents
    "alignment_mode": "expand",  # char->token alignment: strict|contract|expand
})

doc = nlp("Patient John Doe, MRN 12345, seen today.")
for span in doc.spans["openmed_pii"]:
    print(span.label_, span.text)
# raw char-offset spans also available on doc._.openmed_pii

`merge

Câu hỏi thường gặp

Cài OpenMed có tải cả ba công cụ không?

Không. Mỗi cầu nối là một phần mở rộng tùy chọn, nên bạn chỉ cài cái cần dùng.

Các đoạn của OpenMed có thể đưa ngược vào Presidio không?

Có. Skill có hướng dẫn chuyển kết quả qua lại với định dạng của Presidio.

LangChain có được bao quát không?

Có. Nó bao quát việc che văn bản trước khi nó đến mô hình ngôn ngữ.

Chi tiết

Mô tả gốc của tác giả

Combine OpenMed clinical NLP with Microsoft Presidio, spaCy, or LangChain through OpenMed's built-in interop adapter registry (openmed.interop). Covers the lazy adapter registry (available_adapters, get_adapter, adapter_spec), the presidio/spacy/langchain pip extras, and the verified callables — Presidio to_canonical/from_canonical/merge_with_openmed, the spaCy openmed_deid pipeline factory, and the LangChain create_redaction_runnable. Use when the user wants to add Presidio recognizers, embed OpenMed PII detection in a spaCy pipeline, or use OpenMed de-identification as a LangChain runnable.

repo: maziyarpanahi/openmed

Độ phổ biến

Sao GitHub
5.8k
Vị trí xếp hạng
#14677
Giấy phép
Apache-2.0
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự