Per-Language PII De-identification¶
OpenMed's PII detection and de-identification are multilingual. Built-in language packs live in openmed.core.pii_i18n.SUPPORTED_LANGUAGES. The optional Indic family adds four user-configured routes and can also serve the built-in Assamese, Bengali, Hindi, Marathi, Odia, Tamil, and Telugu codes. Every code documented here wires up:
- a default PII model from
DEFAULT_PII_MODELS, used when you passlang=without an explicitmodel_name=(anenv:OPENMED_INDIC_NER_MODELentry means weights are optional and must be configured by the caller), and - a Faker locale from
LANG_TO_LOCALE(openmed/core/anonymizer/locales.py), used bymethod="replace"to generate locale-aware surrogates.
Pick a language by passing its ISO 639-1 code to extract_pii() or deidentify():
from openmed import deidentify
deidentify("Paciente Pedro Almeida, CPF 123.456.789-09", lang="pt", method="mask")
For the redaction methods (mask, remove, replace, hash, shift_dates), locale resolution, determinism, and cross-document surrogate vaults, see PII Anonymization.
Automatic language and script routing¶
The staged privacy pipeline can choose a document pack automatically while preserving exact language decisions for every script run:
from openmed.core.pipeline import Pipeline
route = Pipeline(lang="auto").stage2_language_script(
"Patient stable. 患者发热。 रोगी स्थिर है।"
)
print(route.lang, route.model_name)
print(route.metadata["runs"])
The core fallback is deterministic and dependency-free. It combines Unicode script runs with each LanguagePack's candidate priority and context hints; for example, adjacent kana selects Japanese for Han runs, while standalone Han prefers Chinese and Marathi lexical markers disambiguate Marathi from the otherwise Hindi-first Devanagari route. Install openmed[lid] to enable the lazy, on-device pycld2 adapter for ambiguous runs. The adapter and its CLD2 implementation are Apache-2.0, import only when routing is first requested, and do not download or bundle model weights.
Language-ID license boundary
This router deliberately excludes CLD3, which is outside this roadmap task's approved dependency scope. Non-commercial language-ID assets remain prohibited; only permissively licensed implementations may be bundled or referenced by the router.
Kept in sync with the code
The table below lists every built-in code in SUPPORTED_LANGUAGES plus the optional INDIC_NER_LANGUAGES, together with its DEFAULT_PII_MODELS entry and LANG_TO_LOCALE mapping. tests/unit/test_docs_language_coherence.py asserts this page matches the constants exactly, so a newly wired language fails the suite until it is documented here.
Built-in and optional languages¶
| Code | Language | Default PII model | Faker locale | Notes |
|---|---|---|---|---|
am | Amharic | OpenMed/privacy-filter-multilingual | am_ET | Ethiopic patterns; en_KE Faker approximation warns once. |
ar | Arabic | OpenMed/OpenMed-PII-Arabic-SnowflakeMed-Large-568M-v1 | ar_EG | Egypt is the most-populous Arabic locale; override per call. |
as | Assamese | OpenMed/privacy-filter-multilingual | as_IN | Bengali Faker backend; curated Assamese names; Aadhaar. |
bn | Bengali | OpenMed/OpenMed-PII-Bengali-mSuperClinical-Large-279M-v1 | bn_BD | Dedicated Bengali PII registry entry. |
da | Danish | OpenMed/privacy-filter-multilingual | da_DK | CPR-aware Nordic language pack. |
cs | Czech | OpenMed/privacy-filter-multilingual | cs_CZ | Rodné číslo checksum-aware surrogates. |
de | German | OpenMed/OpenMed-PII-German-SuperClinical-Small-44M-v1 | de_DE | Steuer-ID surrogates via GermanSteuerIdProvider. |
el | Greek | OpenMed/privacy-filter-multilingual | el_GR | AMKA Luhn-aware surrogates. |
en | English | OpenMed/OpenMed-PII-SuperClinical-Small-44M-v1 | en_US | Default model splits names into first_name/last_name. |
es | Spanish | OpenMed/OpenMed-PII-Spanish-SuperClinical-Small-44M-v1 | es_ES | DNI/NIE checksum-aware surrogates. |
fr | French | OpenMed/OpenMed-PII-French-SuperClinical-Small-44M-v1 | fr_FR | NIR / INSEE; fr_SN, fr_CI, and fr_CM locale overlays. |
gu | Gujarati | env:OPENMED_INDIC_NER_MODEL | gu_IN | Optional Indic NER weights. |
he | Hebrew | OpenMed/privacy-filter-multilingual | he_IL | Served by the multilingual privacy filter. |
hi | Hindi | OpenMed/OpenMed-PII-Hindi-SuperClinical-Large-434M-v1 | hi_IN | Aadhaar (Verhoeff) surrogates. |
id | Indonesian | OpenMed/privacy-filter-multilingual | id_ID | Served by the multilingual privacy filter; NIK-aware. |
it | Italian | OpenMed/OpenMed-PII-Italian-SuperClinical-Small-44M-v1 | it_IT | Codice Fiscale surrogates via it_IT.ssn. |
ja | Japanese | OpenMed/OpenMed-PII-Japanese-BigMed-Large-560M-v1 | ja_JP | Family-name-first PERSON spans. |
kn | Kannada | env:OPENMED_INDIC_NER_MODEL | kn_IN | Optional Indic NER weights; Indian Faker fallback. |
ko | Korean | OpenMed/OpenMed-PII-Korean-NomicMed-Large-395M-v1 | ko_KR | Resident Registration Number (RRN) surrogates. |
ml | Malayalam | env:OPENMED_INDIC_NER_MODEL | ml_IN | Optional Indic NER weights; Indian Faker fallback. |
mr | Marathi | OpenMed/privacy-filter-multilingual | mr_IN | Three-part names; hi_IN Faker approximation warns once. |
nl | Dutch | OpenMed/OpenMed-PII-Dutch-SuperClinical-Large-434M-v1 | nl_NL | BSN (Elfproef) surrogates via nl_NL.ssn. |
no | Norwegian | OpenMed/privacy-filter-multilingual | no_NO | Fødselsnummer double modulus-11 validation. |
or | Odia | OpenMed/privacy-filter-multilingual | or_IN | Native Odia surrogates; Aadhaar and Odisha PIN patterns. |
pa | Punjabi | env:OPENMED_INDIC_NER_MODEL | pa_IN | Optional Indic NER weights; Indian Faker fallback. |
pt | Portuguese | OpenMed/OpenMed-PII-Portuguese-SnowflakeMed-Large-568M-v1 | pt_PT | pt_BR IDs; pt_MZ and pt_AO locale overlays. |
ro | Romanian | OpenMed/privacy-filter-multilingual | ro_RO | Served by the multilingual privacy filter; CNP-aware. |
ru | Russian | OpenMed/privacy-filter-multilingual | ru_RU | Default-model placeholder; SNILS-aware. Dedicated weights are not bundled. |
sv | Swedish | OpenMed/privacy-filter-multilingual | sv_SE | Personnummer Luhn validation and surrogates. |
sw | Swahili | OpenMed/privacy-filter-multilingual | sw | Bilingual patterns with Kenya ID and Maisha-aware surrogates. |
ta | Tamil | OpenMed/OpenMed-PII-Tamil-mSuperClinical-Large-279M-v1 | ta_IN | Dedicated Tamil PII registry entry. |
te | Telugu | OpenMed/OpenMed-PII-Telugu-SuperClinical-Large-434M-v1 | en_IN | No Faker Telugu locale — en_IN approximation (warns once). |
th | Thai | OpenMed/privacy-filter-multilingual | th_TH | Served by the multilingual privacy filter; Thai NID-aware. |
tr | Turkish | OpenMed/OpenMed-PII-Turkish-SuperClinical-Small-44M-v1 | tr_TR | TCKN surrogates. |
xh | isiXhosa | OpenMed/privacy-filter-multilingual | xh_ZA | Nguni patterns; zu_ZA Faker approximation warns once. |
zh | Chinese | OpenMed/OpenMed-PII-Chinese-BigMed-Large-560M-v1 | zh_CN | Dedicated Chinese PII registry entry. |
zu | isiZulu | OpenMed/privacy-filter-multilingual | zu_ZA | Nguni patterns with checksum-valid South African ID support. |
uk | Ukrainian | OpenMed/privacy-filter-multilingual | uk_UA | RNOKPP checksum-aware surrogates. |
Chinese segmentation and Han-script routing use the dedicated zh registry entry. Codes outside this list (for example pl, lv, sk, ms, tl, fi, and ur) are not model-backed PII languages. Several of them still have validator-backed national-ID coverage (openmed.core.pii_i18n.NATIONAL_ID_ONLY_LANGUAGES); see PII Anonymization for the ID providers. Urdu uses the conceptual ur_PK locale for CNIC dispatch and Faker's installed en_PK backend for general surrogate data, with a one-time approximation warning.
The four optional Indic language packs never download a default checkpoint. Set OPENMED_INDIC_NER_MODEL to a user-supplied local path or model repo, or pass an explicit model. When it is unset, registry lookup returns no optional model and the Naamapadam-style suite reports a structured skip reason.
Indian-English and code-mixed clinical notes¶
Latin-script Hinglish routing remains explicit. Set code_mixed=True to add the Roman-Hindi rule bank while keeping the English model route. When token tags are omitted, OpenMed's stdlib-only fallback derives exact offset/label records locally; no model weights or network access are required:
from openmed import deidentify
result = deidentify(
"Patient Ravi ka aadhaar 246778325484 hai.",
lang="en",
code_mixed=True,
)
Callers with a locally hosted token classifier can pass lid_model=. The hook receives the input and offset-only token spans and must return one of hi, en, ne, univ, or other for every span. Explicit token_language_tags= still take precedence. Audit metadata retains offsets, labels, and hashes rather than token surfaces.
For lang="hi" or lang="te", a note containing both Latin and Devanagari (or Latin and Telugu) automatically activates the India clinical route. OpenMed segments the note into offset-preserving script runs, adds bounded context to each run so PERSON and LOCATION spans can cross a script boundary, sends Latin windows to the registered English clinical model, and sends Indic windows to the language's registered Hindi or Telugu model. Caller-supplied model IDs or local model paths are used for every window instead; OpenMed does not select an unregistered third-party model automatically.
The documented first-party fallback is OpenMed/privacy-filter-multilingual. Applications that choose that fallback must supply it explicitly as model_name; the route does not silently switch models after an inference error. Telugu replacement still uses the documented en_IN Faker locale approximation and can emit its existing one-time warning.
Indian-English prescription abbreviations such as Tab., Cap., OD, BD, TDS, HS, and SOS are normalized locally before entity merging. Source text and offsets remain unchanged. All shipped fixtures are synthetic; any restricted clinical corpus or separately trained weights remain user-supplied or out of process.
Assistive output
India clinical NER output assists review and does not make clinical or disclosure decisions.
Hausa (ha) is available through that deterministic pattern-pack path with a native ha_NG surrogate locale. Boko context cues cover dates, ages, Nigerian NINs, and Nigerian/Nigerien phones. Ajami coverage is intentionally limited to numeric patterns—phones, NINs, and dates written with Western or Arabic-Indic digits—and does not claim Ajami lexical recognition or transliteration.
Yoruba (yo) is available through that deterministic pattern-pack path with a native yo_NG surrogate locale. It covers Nigeria NINs and +234 phones with tone-marked, decomposed, or unmarked context cues, and replacement spans expand to whole base-plus-diacritic clusters so dot-below and tone marks cannot be orphaned.
Igbo (ig) is available through that deterministic pattern-pack path with a native ig_NG surrogate locale. It recognizes Nigeria NINs, +234 phones, dates, and ages in Igbo and English-Igbo clinical text, including decomposed or unmarked context cues. Replacement spans expand to whole base-plus-diacritic clusters so dot-below vowels cannot be split or left behind.
Worked examples¶
Each example de-identifies synthetic, non-PHI text with method="mask". The exact placeholder tokens come from the chosen model's own entity labels, so they can vary by model (see choosing a method); the canonical labels below are illustrative.
Amharic — am¶
- Model:
OpenMed/privacy-filter-multilingual· localeam_ET(en_KEis the documented Faker approximation)
Arabic — ar¶
- Model:
OpenMed/OpenMed-PII-Arabic-SnowflakeMed-Large-568M-v1· localear_EG
Assamese — as¶
- Model:
OpenMed/privacy-filter-multilingual· localeas_IN
Bengali — bn¶
- Model:
OpenMed/OpenMed-PII-Bengali-mSuperClinical-Large-279M-v1· localebn_BD
Danish — da¶
- Model:
OpenMed/privacy-filter-multilingual· localeda_DK
Before: Patient Anna Nielsen, CPR 170885-1234
After: Patient [NAME], CPR [ID]
### Czech — `cs`
- Model: `OpenMed/privacy-filter-multilingual` · locale `cs_CZ`
```text
Before: Pacient Jan Novák, rodné číslo 751116/0008
After: Pacient [NAME], rodné číslo [ID]
German — de¶
- Model:
OpenMed/OpenMed-PII-German-SuperClinical-Small-44M-v1· localede_DE
Greek — el¶
- Model:
OpenMed/privacy-filter-multilingual· localeel_GR
English — en¶
- Model:
OpenMed/OpenMed-PII-SuperClinical-Small-44M-v1· localeen_US
Before: Patient John Doe was seen on 03/14/2025; call 555-0142
After: Patient [NAME] was seen on [DATE]; call [PHONE]
Spanish — es¶
- Model:
OpenMed/OpenMed-PII-Spanish-SuperClinical-Small-44M-v1· localees_ES
French — fr¶
- Model:
OpenMed/OpenMed-PII-French-SuperClinical-Small-44M-v1· localefr_FR
Gujarati — gu¶
- Model:
env:OPENMED_INDIC_NER_MODEL· localegu_IN
Kannada — kn¶
- Model:
env:OPENMED_INDIC_NER_MODEL· localekn_IN
Before: ಅರುಣ್ ಬೆಂಗಳೂರಿನಲ್ಲಿ ಕಾವೇರಿ ಆಸ್ಪತ್ರೆಗೆ ಹೋದರು.
After: [PERSON] [LOCATION] [ORGANIZATION] ಹೋದರು.
Malayalam — ml¶
- Model:
env:OPENMED_INDIC_NER_MODEL· localeml_IN
Marathi — mr¶
- Model:
OpenMed/privacy-filter-multilingual· localemr_IN
Before: रुग्णाचे नाव सौ. वैशाली सुरेश देशमुख. जन्मतारीख १४ फेब्रुवारी १९८५.
After: रुग्णाचे नाव [PERSON]. जन्मतारीख [DATE].
Odia — or¶
- Model:
OpenMed/privacy-filter-multilingual· localeor_IN
Punjabi — pa¶
- Model:
env:OPENMED_INDIC_NER_MODEL· localepa_IN
Tamil — ta¶
- Model:
OpenMed/OpenMed-PII-Tamil-mSuperClinical-Large-279M-v1· localeta_IN
Before: அருண் சென்னையில் காவேரி மருத்துவமனை சென்றார்.
After: [PERSON] [LOCATION] [ORGANIZATION] சென்றார்.
Hebrew — he¶
- Model:
OpenMed/privacy-filter-multilingual· localehe_IL
Hindi — hi¶
- Model:
OpenMed/OpenMed-PII-Hindi-SuperClinical-Large-434M-v1· localehi_IN
Indonesian — id¶
- Model:
OpenMed/privacy-filter-multilingual· localeid_ID
Italian — it¶
- Model:
OpenMed/OpenMed-PII-Italian-SuperClinical-Small-44M-v1· localeit_IT
Before: Paziente Marco Rossi, codice fiscale RSSMRC80A01H501U
After: Paziente [NAME], codice fiscale [ID]
Japanese — ja¶
- Model:
OpenMed/OpenMed-PII-Japanese-BigMed-Large-560M-v1· localeja_JP
Korean — ko¶
- Model:
OpenMed/OpenMed-PII-Korean-NomicMed-Large-395M-v1· localeko_KR
Dutch — nl¶
- Model:
OpenMed/OpenMed-PII-Dutch-SuperClinical-Large-434M-v1· localenl_NL
Norwegian — no¶
- Model:
OpenMed/privacy-filter-multilingual· localeno_NO
Portuguese — pt¶
- Model:
OpenMed/OpenMed-PII-Portuguese-SnowflakeMed-Large-568M-v1· localept_PT(passlocale="pt_BR"for Brazilian CPF/CNPJ surrogates)
Romanian — ro¶
- Model:
OpenMed/privacy-filter-multilingual· localero_RO
Russian — ru¶
- Model:
OpenMed/privacy-filter-multilingual· localeru_RU - The multilingual model name is a routing placeholder until dedicated Russian weights ship; deterministic Cyrillic patterns remain available offline.
Swedish — sv¶
- Model:
OpenMed/privacy-filter-multilingual· localesv_SE
Swahili — sw¶
- Model:
OpenMed/privacy-filter-multilingual· localesw
Before: Jina: Amina Hassan. Nambari ya kitambulisho 12345678
After: Jina: [NAME]. Nambari ya kitambulisho [ID]
Telugu — te¶
- Model:
OpenMed/OpenMed-PII-Telugu-SuperClinical-Large-434M-v1· localeen_IN(Faker has no Telugu locale —en_INis a documented approximation)
Thai — th¶
- Model:
OpenMed/privacy-filter-multilingual· localeth_TH
Turkish — tr¶
- Model:
OpenMed/OpenMed-PII-Turkish-SuperClinical-Small-44M-v1· localetr_TR
isiXhosa — xh¶
- Model:
OpenMed/privacy-filter-multilingual· localexh_ZA(zu_ZAis the documented Faker approximation)
Before: Igama lesigulane: Xolani Qwabe. Inombolo yesazisi 7903116001080
After: Igama lesigulane: [NAME]. Inombolo yesazisi [ID]
Chinese — zh¶
- Model:
OpenMed/OpenMed-PII-Chinese-BigMed-Large-560M-v1· localezh_CN
The dedicated registry entry is used by default for Chinese PII detection, while segmentation and exact-offset guarantees remain unchanged.
isiZulu — zu¶
- Model:
OpenMed/privacy-filter-multilingual· localezu_ZA
Before: Igama lesiguli: Nomcebo Dlamini. Inombolo kamazisi 8001015009087
After: Igama lesiguli: [NAME]. Inombolo kamazisi [ID]
### Ukrainian — `uk`
- Model: `OpenMed/privacy-filter-multilingual` · locale `uk_UA`
```text
Before: Пацієнтка Олена Коваль, РНОКПП 2974281300
After: Пацієнтка [NAME], РНОКПП [ID]