mama-deid: medical de-identification that keeps the clinical context

A 350M-parameter multilingual encoder that removes what identifies a patient from medical text and keeps what a clinician or a researcher needs. Names, contacts, addresses, ID numbers, dates of birth, home towns, employers, URLs and nationality or religion are masked. Conditions, treatments, tests, care places, clinical dates, durations and ages stay, labelled, so they can be highlighted or extracted.

in:   Hi, it's Marta Lindqvist, my neurologist Dr. Okonkwo at St Brennan's put me on pyridostigmine
      60 mg for MG last March. You can reach me on 07931 482 506.
out:  Hi, it's [PERSON], my neurologist [CLINICIAN] at St Brennan's put me on pyridostigmine 60 mg
      for MG last March. You can reach me on [CONTACT].

General PII detectors treat a diagnosis or a drug as personal data and remove it, which leaves medical text unusable. mama-deid is trained on the opposite policy: the person goes, the medicine stays. It reads patient chat messages, short answers to app questions, uploaded documents (letters, reports, prescriptions, OCR output), transcribed voice notes and longer posts, in 22 languages and their scripts. It runs on a laptop CPU, and patient text never leaves your infrastructure.

Labels

Masked Kept
PERSON patients, relatives, any non-clinical person CLINICAL_STATE: diagnoses, symptoms, findings, lab values
CLINICIAN doctors, nurses, therapists, pharmacists CLINICAL_INTERVENTION: drugs, doses, procedures, tests, visits
ADDRESS street addresses, postal codes, coordinates CARE_INSTITUTION: hospitals, clinics, wards, pharmacies
CONTACT phones, emails, social handles CARE_LOCALITY: the town where care happens, a care place's own address
ID record, insurance, national, card, account, plate, device and login numbers CLINICAL_DATE: dates and times of clinical events
DOB dates of birth CLINICAL_DURATION: how long something lasted
RESIDENCE_LOCALITY the town a person lives in, comes from or travelled to AGE
ORG employers, schools, named private insurers RESIDENCE_COUNTRY
URL web addresses
NRP nationality, ethnicity, religion, politics, sexual orientation, gender identity

The full policy, with 54 decided edge cases (a practice named after its doctor, a clinician who is a relative, a holiday town against a town visited for treatment, Arabic and Hebrew joined prefixes, Japanese honorifics, a bank's own SWIFT code), is in LABELLING.md.

Quick start

import sys
from huggingface_hub import snapshot_download

path = snapshot_download("mamahealth/mama-deid")
sys.path.insert(0, path)
from model import load, mask_bias, masked_text, predict

tokenizer, model = load(path)
text = "Mein Vater Herbert Kรคssbohrer (geb. 14.06.1948) hat seit 3 Wochen Atemnot."
spans = predict(text, tokenizer, model, mask_bias(path, "tuned"))
print(masked_text(text, spans))
# Mein Vater [PERSON] (geb. [DOB]) hat seit 3 Wochen Atemnot.
print(masked_text(text, spans, highlight=True))
# Mein Vater [PERSON] (geb. [DOB]) hat seit <clinical_duration>3 Wochen</clinical_duration> <clinical_state>Atemnot</clinical_state>.

predict returns every span with its label, kept ones included. Which labels get masked is a post-processing choice in masked_text, so a deployment can mask more (a care town, for a very small cohort) without retraining. mask_bias(path, "tuned") loads the per-label biases chosen on validation; a number instead applies one bias to every masked label, trading leaks for over-masking.

Results

Own validation set

1,714 texts in 22 languages, written by two models that wrote no training data, each from its own prompt: Claude Opus and, since v10, a GPT model, so the scores also measure text in a style the model was not trained on. Messages, answers, documents, conversations and posts, with typos, OCR damage, code-switching and fragments. Identifier spans are the unit: an identifier counts as hidden only when all its characters are masked. The texts by the GPT model are harder for every version of the model.

Micro-F2 Micro-F1 [95% CI] Identifier recall Character precision Clinical spans damaged Messages over-masked
0.940 0.925 [0.915โ€“0.935] 95.1% 92.1% 1.3% 7.4%

By language, for every language with at least 30 validation texts. The language comes from the batch for the twelve single-language batches and from a language detector for the mixed ones. Each language other than English holds 57 to 162 identifiers, so read differences under about 0.05 as noise.

Language Texts Identifiers Identifier recall F2 Clinical damaged
English 378 1,008 0.985 0.981 0.4%
Korean 99 161 0.919 0.912 1.6%
Arabic 85 125 0.952 0.911 3.1%
Hindi 84 162 0.852 0.851 2.7%
Thai 78 127 0.795 0.773 2.7%
Indonesian 70 98 0.959 0.949 0.9%
Japanese 65 102 0.961 0.951 0.7%
Russian 65 118 0.975 0.971 0.6%
Italian 65 130 1.000 0.995 0.0%
Polish 65 125 0.976 0.971 0.8%
Hebrew 63 121 0.835 0.812 2.2%
Portuguese 61 117 0.983 0.978 0.3%
Spanish 58 97 0.948 0.943 0.8%
Vietnamese 56 70 0.957 0.931 3.0%
German 54 89 1.000 0.985 0.9%
Turkish 51 73 0.959 0.938 1.2%
Persian 50 106 0.896 0.853 5.1%
French 39 79 1.000 0.988 1.5%
Dutch 38 82 0.951 0.958 0.3%
Greek 37 57 0.982 0.952 2.4%

English and the European languages are strongest. Thai, Hebrew and Hindi still trail (identifier recall 0.80 to 0.85); Persian is at 0.90. Check the model on your own data before use in those languages.

Held-out test

Written like validation, never used for training, and run once after every choice for this release was made. Two slices are written by a GPT model, a writer whose style no Claude-written training row shares; the newest one is rich in letterheads, postal codes and names in Thai, Hindi, Hebrew, Korean, Arabic and Persian.

Test slice Texts Identifiers Identifier recall F1 F2 Clinical damaged
Claude Opus 550 1,404 95.4% 0.917 0.939 1.8%
GPT model (v10 round) 700 388 96.9% 0.930 0.953 0.7%
GPT model (v11 round) 411 1,313 95.9% 0.906 0.937 3.5%

The test also holds minimal pairs: two texts that differ in a few words so that one label flips. The 400 pairs of the v10 round (eponyms, look-alike drug names, towns visited for care or not, birth against clinical dates, streets named after dates, spoken identifiers, OCR names, clinics named after people) are now easy: every identifier in them is found. The 300 harder pairs of the v11 round flip on context alone, and show where the model still fails:

Pattern (v11 pairs) Identifier recall F1
Postal code or a number with the same digits 0.880 0.871
A clinic's letterhead or the patient's employer 0.881 0.891
The same address as home or as the clinic's 0.901 0.800
An identifier buried at the end of a long document 0.830 0.804
A Thai, Hindi or Hebrew word as a name or as a common word 0.765 0.448
A Korean name with a joined particle 0.582 0.552

Public PII benchmarks

Six public benchmarks, run with one harness for both models: the same 1,000-text samples (127 for TAB), partial-overlap matching, labels mapped onto one coarse type set (public_benchmark.py). LiquidAI's own evaluation code is not public, so these are not their published numbers; on ai4privacy and MAPA the harness reproduces them within 0.03.

Identifier recall and exact-type F1 on six public PII benchmarks, mama-deid against LiquidAI's base model

Identifier recall: the share of names, contacts, addresses, IDs, dates of birth, URLs, nationality and organisations masked, whatever label the model gave them.

Benchmark Domain LiquidAI base mama-deid
SPY legal and medical, English 0.951 0.989
Gretel finance and more, English 0.754 0.975
TAB European court rulings, English 0.584 0.634
ai4privacy multilingual 0.831 0.945
Nemotron-PII many domains, English 0.769 0.948
MAPA EU legal, 6 languages 0.253 0.494

Exact-type F1, counting only the spans mama-deid masks:

Benchmark LiquidAI base mama-deid
SPY 0.671 0.530
Gretel 0.793 0.907
TAB 0.337 0.402
ai4privacy 0.712 0.776
Nemotron-PII 0.647 0.757
MAPA 0.211 0.169

By language, on the two multilingual benchmarks (identifier recall, LiquidAI base โ†’ mama-deid):

English French German Italian Spanish Hindi Portuguese
ai4privacy 0.88 โ†’ 0.95 0.87 โ†’ 0.94 0.81 โ†’ 0.96 0.82 โ†’ 0.93 0.78 โ†’ 0.94 0.71 โ†’ 0.93
MAPA 0.30 โ†’ 0.59 0.18 โ†’ 0.44 0.25 โ†’ 0.40 0.67 โ†’ 0.89 0.27 โ†’ 0.93 0.25 โ†’ 0.48

MAPA's Italian and Spanish samples hold only 9 and 15 identifiers; the other cells hold 46 to 401.

These benchmarks count dates, places, hospitals, organisations of the state and medical terms as personal data; mama-deid keeps them by design, so its precision here understates it. SPY leaves many real e-mails, phones and doctors' names in its texts unlabelled, so correct masks count as errors. mama-deid trained on 852 records of the Nemotron-PII train split; none is in the test sample.

What the clinical tags make possible

Because kept spans come back labelled, not just left alone, code after the model can de-identify further, or differently, without retraining. These are post-processing on top of predict; the first is built in.

  • Date shifting. Move every clinical date of one patient by the same secret offset, drawn once per patient: the real dates disappear, the intervals between events stay exact. This is the standard method for research datasets.
    masked_text(text, spans, days=107)   # or: mask.py ... --shift-days 107
    # in:  Marta Lindqvist was operated on 12 March 2024 at St Brennan's, relapse on 2 May 2024, call 07931 482 506.
    # out: [PERSON] was operated on 27 June 2024 at St Brennan's, relapse on 17 August 2024, call [CONTACT].
    
    Numeric dates keep their order and separator; month names keep their language (English, German, French, Italian, Spanish, Portuguese, Dutch). Relative dates ("last week") and bare years are left as they are; use a new offset per patient, never one for everyone.
  • Generalisation. Keep only the year of a clinical date, write ages above 89 as "90 or older", or replace a care town with its region.
  • Surrogates instead of [PERSON]. Replace each name with a consistent invented one: the text stays readable, and a name the model missed hides among the invented ones.
  • Pseudonyms across a history. [PERSON_1], [PERSON_2], consistent across one patient's messages, keep "my husband [PERSON_2]" readable. Kept with its mapping, this is pseudonymisation, not anonymisation.
  • Risk-based masking. For a rare disease or a small cohort, also mask CARE_LOCALITY, CARE_INSTITUTION or RESIDENCE_COUNTRY: a setting in masked_text, not a new model.
  • Structured extraction. Conditions, treatments, tests, dates and durations come out labelled: timelines, cohort building, pharmacovigilance signals.
  • Faster review. highlight=True (or the demo's colour view) shows a reviewer at a glance what stayed in the text.

How it was built

  1. One policy. LABELLING.md decides every case; new cases are decided there first.
  2. Briefs. A script writes one brief per row: language, writer, register, setting, condition, identifiers.
  3. Writers. Claude Sonnet and Fable and two GPT models (through Codex) write training rows; Claude Opus and a third GPT model write validation and test, and no training data.
  4. Review. A model other than the writer reviews and fixes every batch; Claude Opus reviews all evaluation data.
  5. Checks. check_data.py lints every record and blocks leaks and repeated templates between and within splits.
  6. Training with fresh identifiers every epoch, then selection and bias tuning on validation only.
  7. Error analysis of each version becomes the next targeted data round.

Data

All text is synthetic: no patient data was used at any step.

  • One policy, one checker. Every batch was written and reviewed against LABELLING.md. check_data.py lints every record: placeholder numbers (descending digits, textbook IBANs, fictional phone ranges), honorifics and kinship words on the wrong side of a name, Arabic and Hebrew prefixes outside a span, Turkish suffixes inside one, credentials in clinician spans.
  • Variety by design, not by luck. Each row is written from a brief that fixes its shape, language, writer (patient, caregiver, parent, the app's assistant), age, register (rushed thumb-typing, voice note, formal, angry, low literacyโ€ฆ), care setting (24), the kinds of identifier it carries (26, or none: about a third of rows carry no identifier) and a condition drawn towards the ICD chapters training mentions least. Drug and condition vocabularies cover 47 markets, so each row names its medicines the way that country does.
  • Separate writers, separate splits, two model families. Training data was written by Claude Sonnet and Claude Fable and, in the last round (8,300 records), by two GPT models through Codex; validation and test by Claude Opus and a third GPT model that wrote no training data, from different prompts. Evaluation data written by the GPT model was reviewed by Claude Opus. Writers from a second model family keep the model from learning one writer's style instead of the task. Every batch was reviewed by a model other than its writer, which fixed what it found: 0 to 0.12 identifier errors per record before fixing in the last rounds. For the earlier rounds a third model also measured the remaining error rate on a sample. In the latest rounds every identifier value was generated and checked by script for its format and check digit (IBAN mod-97, Luhn, VIN, codice fiscale, DNI, BSN, PESEL, NIRโ€ฆ).
  • No leaks between splits. Exact, word-shingle and character-shingle checks between train, validation and test, and near-duplicates removed within train.
  • Targeted rounds. Error analysis of each model on the public benchmarks became new data: lists of identifiers, long unbroken documents, flat and unit numbers in addresses, names with letters such as ลŸ, ล‚ or ล‘, formal nationality, pasted chats with speaker names, administrative letters, and rare structured numbers (plates, VINs, card codes, PINs, device serials). A last round came from testing the demo: towns travelled to for care or not, addresses, emails and phones spoken out in words (streets named after dates, "punto โ€ฆ chiocciola"), two-digit dates beside a birth date, and names spelled out with spaces or underscores in OCR and dictation headers. The last round (v10) added breadth rather than patterns: 5,200 rows across all 22 languages (more for the weaker ones), 1,500 structured documents rendered from templates (letters, lab tables, forms, email threads, chat exports, multi-page OCR), 1,000 long, administrative, transcribed and mixed-language rows, and 600 minimal pairs (an eponym against the disease, a trip for treatment against a holiday). The v11 round followed a user test with a referral letter: 800 rows of postal codes in every country's format, 800 letterheads, referral blocks and lab footers (half also carrying the patient's own address), 1,750 rows with people's names in Thai, Hindi, Hebrew, Korean, Arabic and Persian, and 400 minimal pairs. At the same time the policy started to label postal codes (ADDRESS) and a care place's own address (CARE_LOCALITY, kept but taggable), and all splits were relabelled. No benchmark text entered training.
  • Public data. 852 records of NVIDIA's Nemotron-PII (CC BY 4.0), relabelled to this policy.

About 27,100 source records across the three splits; 31,500 training texts after context windows (a third of messages are also seen with the message before them).

Training

Base LFM2.5-Encoder-350M-PII-Detector (revision b8c9cf3)
Head new token-classification head, 73 BIES tags for 18 labels, warm-started from the base model's matching PII tags
Trained every layer but the token embeddings
Optimiser Adafactor, learning rate 3e-5 (head 1e-4), weight decay 0.01
Schedule 6% linear warm-up, linear decay to zero, 2 epochs (18,618 steps); the released model averages the weights of the last 6 checks
Batches up to 1,024 padded tokens, grouped by length; short answers seen 3ร—, documents 2ร—
Augmentation every epoch rewrites identifiers with fresh values per locale (keeping titles, gender and name order), swaps drugs within their ATC class and conditions within their ICD chapter, adds noise to 15% of rows (typing, OCR, names spelled out in capitals with spaces or underscores, numbers in contacts, IDs, addresses and ages written out as words in 19 languages), and leaves 30% unchanged
Selection identifier F2 on one half of validation every 500 steps; patience 12 checks
Mask biases per masked label, tuned on the other half of validation for identifier F2, and not changed afterwards

Decoding

Each window of up to 2,500 characters is cut at line breaks, or at spaces inside a longer line, so no text goes unread. Spans in scripts written with spaces (Latin, Cyrillic, Greek, Arabic, Hebrew, Devanagari and others) are widened to whole words, so a name is never half masked; a numeric date gets one label for all of it, the one with the most probability over its tokens, so 02-10-26 is never split into [DOB]-10-[DOB]; overlapping spans merge; spans of punctuation alone are dropped.

How the numbers were kept honest

Every choice for this release (data, training length, checkpoint, mask biases) was made on the validation split: the checkpoint on one half, the biases on the other. The held-out test and the public benchmarks were run once, after every choice, and changed nothing. Earlier releases did not keep to this: their biases were raised by hand after a public-benchmark run, which made their TAB and MAPA numbers optimistic. Against the previous release (biases set that way), v11 has higher F1 on both test slices written by a GPT model and higher recall on the newest one, lower recall on the Claude-written test (95.4% against 96.5%) and on the legal benchmarks TAB and MAPA, and about the same recall on the medical and multilingual benchmarks.

Limitations

  • Synthetic evaluation. Training and evaluation text is machine-written. Real messages will be harder; measure recall on a sample of your own data before relying on it.
  • Not a certified tool. Review output before sharing data. Do not use it as the only safeguard for regulated releases.
  • Pseudonymised, not anonymised. The default output keeps clinical dates, ages, care places and care towns. That fits a HIPAA limited data set or GDPR pseudonymised data, not HIPAA Safe Harbor (which removes every date element but the year, ages over 89 and towns) and not GDPR anonymous data. For Safe Harbor, generalise dates and ages and mask CARE_LOCALITY in post-processing; in a very small cohort, mask care places too.
  • Short context. Each text is read alone. A one-word answer such as a town name can be ambiguous without the question; pass the question with it when you can.
  • Weaker spots. Names in Thai, Hebrew and Hindi (identifier recall 0.80 to 0.85 on validation), and common words in those scripts sometimes masked as names; Korean names followed by a joined particle (0.58 on the hardest test pairs); an identifier buried at the end of a long document; legal text (TAB, MAPA), which the model was not built for. Drug names that read like people's names are occasionally masked. A care place's own address is kept by default: mask CARE_LOCALITY in post-processing for a small cohort or for HIPAA Safe Harbor.

Licence and attribution

The model is a derivative of LiquidAI's LFM2.5-Encoder-350M-PII-Detector and is released under the LFM Open License v1.0 (see LICENSE and NOTICE): free, including commercial use, for organisations under $10M annual revenue; above that, commercial use needs a licence from Liquid AI. The training data includes NVIDIA Nemotron-PII, CC BY 4.0.

Citation

@misc{mamadeid2026,
  title  = {mama-deid: multilingual medical de-identification that keeps the clinical context},
  author = {Famiglini, Lorenzo and {mama health}},
  year   = {2026},
  url    = {https://huggingface.co/mamahealth/mama-deid}
}
Downloads last month
25
Safetensors
Model size
0.4B params
Tensor type
F32
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for mamahealth/mama-deid

Dataset used to train mamahealth/mama-deid