Downloads · 30 days
68
20% of all-time downloads
YalenLabs/yalen-pii-ner-multilingual
yalen-pii-ner-multilingual is a token classification model from YalenLabs. Use it when you need labels on individual words, such as names. The card lists the license as mit.
Detects 9 classes of personal and financial data (names, organizations, locations, IBAN, card numbers, phone numbers, emails, dates) in French and English text, with a focus on medical documents. Developed by Yalen Labs.
Downloads · 30 days
68
20% of all-time downloads
All-time downloads
335
Public
Parameters
135M
809 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors539 MB · 79%
From the Hugging Face model README
Detects 9 classes of personal and financial data (names, organizations, locations, IBAN, card numbers, phone numbers, emails, dates) in French and English text, with a focus on medical documents. Developed by Yalen Labs.
v2 — retrained after a linguistic bias audit. Version 1 of this model was put through a three-phase bias audit: does it detect a Tunisian, Algerian, Senegalese or Kenyan patient name as well as a French one? The audit found a bias against Kenyan names and, above all, large failures on upper-case and lower-case names and on dates written in words. v2 was retrained from the base model to fix these issues, and meets all the audit's success criteria. Full reports, benchmark and evaluation code: YalenLabs/yalen-pii-ner-bias-audit.
| Patient-name detection (strict recall, bias benchmark) | v1 | v2 |
|---|---|---|
| By cultural group (FR, TN, DZ, SN, KE) | 71–83 % | 99.6–100 % |
| Largest gap vs. French names | −5.8 pts (Kenyan names, bias) | 0.2 pt |
| "Firstname Lastname" | 93–97 % | 100 % |
| "LASTNAME Firstname" (common in medical records) | 30–57 % | 99–100 % |
| "FIRSTNAME LASTNAME" | 24–43 % | 100 % |
| "firstname lastname" | 0–1 % | 90–99 % |
| "Mr/Mrs Lastname" | 92–96 % | 99–100 % |
| Precision on names | 81–84 % | 97–100 % |
| Date of birth | v1 | v2 |
|---|---|---|
| "12/03/1978", ISO | 151 / 168 | 167 / 168 |
| "12.03.1978" | 51 / 151 | 151 / 151 |
| "12 mars 1978", "12 March 1978" | 0 / 173 | 158 / 173 |
No regression on the 9 classes (internal validation, strict F1, v1 → v2): PER 65.3 → 97.2 %, ORG 70.7 → 81.6 %, LOC 81.8 → 90.0 %, MISC 48.7 → 74.5 %, IBAN 81.6 → 100 %, CARD 90.0 → 98.8 %, PHONE 89.7 → 99.2 %, EMAIL 98.9 → 100 %, DATE 68.3 → 100 %. On WikiNER, used to train both versions, they are on par (88.1 % vs 87.6 %).
v1 is still available with revision="v1".
| Entity | Description | Examples |
|---|---|---|
| PER | Person name | Amal Meddeb, MEDDEB Amal, Mme Meddeb, Wanjiku Kamau |
| ORG | Organization | Banque de France |
| LOC | Location | Tunis, Nairobi, avenue Habib Bourguiba |
| MISC | Other named entity | Visa |
| IBAN | Bank account number | TN59 1000 6035 1835 9848 3270 |
| CARD | Credit / debit card | 4532 1234 5678 9012 |
| PHONE | Phone number | +216 71 234 567, +254 712 345 678 |
| Email address | [email protected] | |
| DATE | Date | 12/03/1978, 12.03.1978, 12 mars 1978, March 12, 1978 |
The names in this card are fictitious examples.
from transformers import pipeline
ner = pipeline("token-classification", model="YalenLabs/yalen-pii-ner-multilingual",
aggregation_strategy="simple")
for e in ner("Patiente : MEDDEB Amal, née le 12 mars 1978, tél. +216 22 123 456."):
print(e["entity_group"], e["word"], round(e["score"], 3))
import json, numpy as np, onnxruntime as ort
from huggingface_hub import snapshot_download
from transformers import AutoTokenizer
path = snapshot_download("YalenLabs/yalen-pii-ner-multilingual", allow_patterns=["*.onnx", "*.json", "vocab.txt"])
tok = AutoTokenizer.from_pretrained(path)
sess = ort.InferenceSession(f"{path}/model_quantized.onnx", providers=["CPUExecutionProvider"])
id2label = json.load(open(f"{path}/config.json"))["id2label"]
enc = tok("Patiente : MEDDEB Amal, née le 12 mars 1978.", return_tensors="np")
logits = sess.run(None, {"input_ids": enc["input_ids"], "attention_mask": enc["attention_mask"]})[0][0]
for t, l in zip(tok.convert_ids_to_tokens(enc["input_ids"][0]), logits.argmax(-1)):
if id2label[str(l)] != "O":
print(t, id2label[str(l)])
Retrained from distilbert-base-multilingual-cased, 19 BIO labels (O + 9 × B/I), 3 epochs, lr 5e-5, batch 32, fp16, on one T4 GPU.
| Source | License | Sentences | Purpose |
|---|---|---|---|
| Jean-Baptiste/wikiner_fr | Not stated (derived from Wikipedia) | 60,000 | Names, locations, organizations in general text |
| ai4privacy/open-pii-masking-500k-ai4privacy | CC-BY-4.0 | 30,000 | Names, cities, phones, emails, cards, dates (fr, en) |
| Synthetic, structured | — | 15,000 | IBAN (incl. Tunisian), cards, phones, emails, dates |
| Synthetic, bias-targeted | Name lists from Wikidata (CC0) | 30,000 | Names from 5 groups in 5 formats, doctors' names, dates in words |
The bias-targeted data uses templates and surnames distinct from the audit benchmark, so the benchmark measures generalization. Contains data from ai4privacy/open-pii-masking-500k-ai4privacy, licensed under CC-BY-4.0.
| File | Content |
|---|---|
model.safetensors | PyTorch weights (FP32, 539 MB) |
model_quantized.onnx | ONNX, dynamic INT8 quantization (129 MB), for CPU inference |
config.json, tokenizer*.json, vocab.txt | Configuration and tokenizer |
Privacy compliance (GDPR), redaction of documents before sharing, data loss prevention, healthcare documents. The model produces detections for human-reviewed processes. It is not intended for profiling individuals or automated decisions about them.
MIT.