Token Classification
Transformers
Safetensors
lfm2
liquid
lfm2.5
bidirectional
masked-lm
encoder
pii
ner
privacy
multilingual
custom_code
Run this model with HF Jobs
Run LiquidAI/LFM2.5-Encoder-350M-PII-Detector on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/LiquidAI/LFM2.5-Encoder-350M-PII-Detector. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/LiquidAI/LFM2.5-Encoder-350M-PII-Detector on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use LiquidAI/LFM2.5-Encoder-350M-PII-Detector with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use LiquidAI/LFM2.5-Encoder-350M-PII-Detector with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("token-classification", model="LiquidAI/LFM2.5-Encoder-350M-PII-Detector", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForTokenClassification tokenizer = AutoTokenizer.from_pretrained("LiquidAI/LFM2.5-Encoder-350M-PII-Detector", trust_remote_code=True) model = AutoModelForTokenClassification.from_pretrained("LiquidAI/LFM2.5-Encoder-350M-PII-Detector", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload README.md with huggingface_hub
Browse files1234567891011121314151617183 unmodified lines222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158---license: otherlanguage: [en, de, fr, es, it, nl, pt, pl, ru, zh, ja, ko, ar, hi, id, vi, th, sv, fi, da, el, ro, hu, cs, sk, bg, lt, lv, et, ga, mt]pipeline_tag: token-classificationtags: [pii, ner, privacy, multilingual, token-classification]---# LiquidAI/pii-detect (v8)Multilingual PII detection β a full fine-tune of the bidirectional **LFM2.5-350M** MLMencoder with a token-classification head. **40 PII types** (identity, contact, financial,credential, online, device, location, healthcare, org, legal, special-category) across**33 languages**. Ships with an inference-time **hybrid regex decode**(`pii_hybrid_decode.py`) that fixes byte-BPE boundary fragmentation on format-bound types(roughly doubles exact-match F1).## Usage```python3 unmodified linesspec = importlib.util.spec_from_file_location("hd", hf_hub_download("LiquidAI/pii-detect","pii_hybrid_decode.py"))hd = importlib.util.module_from_spec(spec); spec.loader.exec_module(hd)tok = AutoTokenizer.from_pretrained("LiquidAI/pii-detect", trust_remote_code=True)model = AutoModelForTokenClassification.from_pretrained("LiquidAI/pii-detect", trust_remote_code=True).eval()print(hd.predict("Email laura@charite.de or call +49 30 4505 1234.", tok, model)) # recommended```> **Decode update (same v8 weights β two inference tiers added, no retrain).**> (1) **Context-cued ID tier**: captures the value after an ID field-label ("Passport No:", "Policy #",> "MRN:" β¦ 33 languages) β fixes the structure-less IDs the model can't learn (recall ~0 β 0.6β0.75).> (2) **Group-B cue tier**: cue+shape-gated amount/date/phone/postal (e.g. `amount recall 0.16 β 0.77`).> Net on the internal eval (realistic, partial / exact): **F1 0.641 β 0.727 / 0.429 β 0.500, recall> 0.516 β 0.641, precision up to 0.840** β with **person_name unchanged** and no new precision-trap> failures. Both tiers are cue/shape-gated for precision; `contact.address` is intentionally left to the> model (it was the precision-costly type in calibration). Public/ShieldFlow are ~unchanged (these cues> fire on labelled IDs/amounts, which are dense in real documents).## Evaluation (type-level micro-F1; one shared harness)v4 is the previous release. We report the **best decode** per benchmark. NOTE: nemotron &ai4privacy are *contaminated* β their public leaders trained in-distribution on those exactcorpora (specialist ceilings β0.918 / 0.946); shown for completeness.### Public benchmarks (partial)| benchmark | v4 (prev) | **v8** | leader ||---|---|---|---|| Nemotron (contaminated) | 0.613 | **0.799** | v8 (+0.19) || AI4Privacy (contaminated) | 0.394 | **0.673** | v8 (+0.28) || Gretel (clean) | 0.809 | **0.833** | v8 || TAB (clean, legal) | **0.819** | 0.751 | v4 || SPY (clean) | **0.405** | 0.346 | v4 || MAPA (clean, EU legal) | **0.488** | 0.408 | v4 |### Internal eval (held-out, 40-type / 33-lang / 6,094 docs; realistic subset, partial / exact)| model | hybrid decode ||---|---|| v4 | (0.59, 0.367) || **v8** | **(0.641, 0.429)** |The hybrid decode roughly **doubles exact-match F1** by fixing sub-token boundaryfragmentation on emails, IBANs, phones, dates, SSNs, MACs, credit cards, etc.### ShieldFlow proxy gate (native taxonomy, partial F1; base / xlong)| | v4 | **v8** | q4 incumbent ||---|---|---|---|| proxy_traffic_holdout | 0.786 | **0.829** (P0.84/R0.81) | 0.878 || proxy_traffic_holdout_xlong | 0.780 | 0.759 | 0.884 |## Honest summaryv8 is the strongest model on the **product-critical signals** (the held-out internal evaland the ShieldFlow gate) and on Gretel + the two contaminated sets, with a large capabilityjump over v4 (40 types vs 32 β it can now detect amount, JWT, crypto wallets, IMEI, etc.,which v4 could not). It is **behind v4 on three clean academic sets** (SPY, TAB, MAPA) by0.04β0.08 β a recall/precision trade-off from the broader schema; SPY's national_id formatin particular is a recall artifact we deliberately did not overfit to. **No singlecheckpoint is best on every benchmark.** Earlier checkpoints v6/v7 trade differently (v7leads TAB at 0.786); available on request.> **Decode upgrade (same weights):** the hybrid decode now adds Latin word-boundary snapping (fixes leading sub-token drops like `Ibuprofen`β`profen`) and precision guards (SWIFT/BIC requires a digit or cue; drops <3-char fragments). Net vs the prior decode: internal exact-F1 0.361β**0.429**, ShieldFlow proxy 0.812β**0.829**, all public sets flat-to-up, zero regressions.## Candidate model comparison β all benchmarksEvery candidate checkpoint from development, across all benchmarks, **best decode permodel** (token classifier or +hybrid regex layer). v8 (published) uses the upgraded decode(boundary-snap + precision guards). *Nemotron/AI4Privacy are contaminated β public leaderstrained in-distribution on those corpora (specialist ceilings β0.918/0.946). Internal =held-out 40-type/33-language eval (partial-F1, realistic subset). ShieldFlow = product proxygate (base split). Internal exact-F1 = strict-boundary match.*| Benchmark | v4 | v6 | v7 | **v8 (current)** ||---|---|---|---|---|| SPY | **0.426** | 0.373 | 0.378 | 0.355 || TAB | **0.819** | 0.679 | 0.786 | 0.751 || Gretel | 0.816 | **0.839** | 0.822 | 0.833 || MAPA | 0.488 | **0.492** | 0.421 | 0.408 || Nemotron* | 0.696 | **0.802** | 0.790 | **0.802** || AI4Privacy* | 0.429 | **0.677** | 0.624 | 0.673 || Internal | 0.590 | 0.584 | 0.596 | **0.727** || ShieldFlow | 0.798 | 0.803 | 0.810 | **0.829** || Internal exact-F1 | 0.367 | 0.330 | 0.353 | **0.500** |No single checkpoint dominates every benchmark β this is a genuine multi-objective frontier:**v8** leads the product-critical signals (Internal, ShieldFlow) and exact-boundary F1;**v4** still leads several clean academic sets (SPY, TAB, MAPA); **v6** leads Gretel/AI4Privacy.v8 is published as the best balance for real-world deployment (it also covers 40 PII types vsv4's 32). (A recall-focused retrain, v9, was evaluated but **not published** β it failed to improve the targeted alphanumeric-ID recall and regressed person_name/internal; it did set a new ShieldFlow-proxy best of 0.856. v8 remains current.)### vs. external models (same current eval sets)All scored in our harness on the **current** eval sets (best decode per model). *Nemotron &AI4Privacy are contaminated for the vendors that lead them (Piiranha trained on AI4Privacy;OpenMed on Nemotron). LFM demo (q4) uses ShieldFlow's native taxonomy, so it is compared onlyon the ShieldFlow gate (its home turf), not on our 40-type schema.*| Model | Internal | SPY | TAB | Gretel | MAPA | Nemotron* | AI4Privacy* | ShieldFlow ||---|---|---|---|---|---|---|---|---|| **v8 (ours, published)** | 0.727 | 0.355 | 0.751 | 0.833 | 0.408 | 0.802 | 0.673 | 0.829 || **Ours β best candidate (v4βv8)** | 0.727 | 0.426 | 0.819 | 0.839 | 0.492 | 0.802 | 0.677 | 0.829 || GLiNER multi-pii | 0.736 | 0.213 | 0.447 | 0.728 | 0.489 | 0.713 | 0.492 | β || Piiranha | 0.490 | 0.248 | 0.262 | 0.552 | 0.262 | 0.672 | 0.949 | β || OpenMed-Nemotron | 0.508 | 0.244 | 0.672 | 0.774 | 0.113 | 0.923 | 0.419 | β || OpenAI privacy-filter | 0.473 | 0.275 | 0.543 | 0.458 | 0.249 | 0.583 | 0.380 | β || regex baseline | 0.342 | 0.370 | 0.000 | 0.340 | 0.000 | 0.347 | 0.214 | β || LFM demo (q4) | β | β | β | β | β | β | β | 0.878 |**Reading it:** our best candidate **leads all four clean public benchmarks** (SPY, TAB, Gretel,MAPA); the published **v8 leads TAB & Gretel** outright vs every external model and is the clear**#2 generalist on the held-out internal eval** (0.641) behind **GLiNER (0.736)** β ahead of everyother production model (OpenMed 0.508, Piiranha 0.490, OpenAI-PF 0.473). On the two *contaminated*sets and the **ShieldFlow** gate, v8 is #2 behind the in-distribution specialist / incumbent.## Development notes β recall-lever explorationSeveral retrains probed the remaining recall gaps. None beat the published model, but theymap the tradeoff precisely (kept here for transparency):- **v9** (brute-force ID-frequency data): IDs stayed ~0 recall β structure-less alphanumeric IDsaren't learnable from more data β and person_name regressed.- **v10** (mild class-weighting + Group-B data diversity): lifted under-detected-type recall a lot(MAPA 0.53, TAB 0.83, date_of_birth/phone/address recall up sharply) **but crashed person_name to 0.26**.- **v11** (same data, class-weighting OFF): person_name partly recovered, but the recall gains vanished.**Conclusion:** a global class-weight trades rare-type recall directly against the dominantperson_name β not a net win. The shipped improvement is instead the **inference-side context-cuedID layer**, which fixes the zero-recall IDs without that tradeoff. Closing the remaining Group-Brecall gap needs per-type calibration, not another retrain.## Schema & training40 canonical `domain.type` labels, BIOES (161 classes). Trained on multilingual syntheticdata (gemma-generated, exact char-span labels, PII-vs-NER decoy regime) + the publicbenchmarks' own **test-disjoint** train splits. Saturates <1 epoch.12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152533 unmodified lines57585960616263---license: otherlanguage: [en, de, fr, es, pt, it, pl, ru, zh, ja, ko, ar, hi, id, vi, th]pipeline_tag: token-classificationtags: [pii, ner, privacy, multilingual, token-classification]---# LiquidAI/pii-detect (v14)Multilingual PII detection β a full fine-tune of the bidirectional **LFM2.5-350M** MLMencoder with a token-classification head, covering **40 PII types** across **16 languages**(en, de, fr, es, pt, it, pl, ru, zh, ja, ko, ar, hi, id, vi, th). Ships with aninference-time **hybrid regex decode** (`pii_hybrid_decode.py`) that adds validator-gatedformats (email/IBAN/credit-card/IP/JWT/β¦) and cue-gated IDs on top of the model, fixingbyte-BPE boundary fragmentation.**v14** is trained on a persona-driven, gemma-generated synthetic corpus (coherentlocale-personas Γ scenarios Γ cue/inline/structured embedding, LLM-judge-filtered,contamination-cleaned against all eval sets).## Benchmarks (18-locale-filtered, partial-F1, hybrid decode)Comparison vs the prior release (v8) and external models (SauerkrautLM-LFM2.5-GLiNER, theLFM ShieldFlow demo q4). All on identical, contamination-cleaned, 16-language splits.| Benchmark | **v14** | v8 (prev) | GLiNER | LFM-demo-q4 ||---|---|---|---|---|| SPY | **0.388** | 0.351 | 0.280 | 0.192 || Gretel | **0.765** | 0.758 | 0.663 | 0.804 || TAB | **0.789** | 0.749 | 0.685 | 0.490 || ai4privacy | **0.557** | 0.643 | 0.488 | 0.500 || Nemotron | **0.782** | 0.773 | 0.639 | 0.656 || MAPA | **0.157** | 0.486 | 0.416 | 0.250 || Internal (40-type) | **0.628** | 0.616 | 0.479 | 0.466 || ShieldFlow proxy | **0.838** | 0.847 | 0.646 | 0.839 || ShieldFlow proxy-xl | **0.841** | 0.797 | 0.658 | 0.842 |### Honest notes- **v14 beats both external models** (GLiNER, LFM-demo) on the general/multilingualbenchmarks (TAB, Nemotron, Internal, SPY, Gretel) and **matches the LFM-demo on its ownShieldFlow distribution**, where it is the in-distribution incumbent.- **Two regressions vs v8** to be transparent about: **MAPA** (v14 0.157 vs v8 0.486) β abenchmark-convention conflict (MAPA labels citation dates as `date_of_birth`, whichconflicts with TAB where dates are not PII; v14 follows the standard convention) β and**ai4privacy** (v14 0.557 vs v8 0.643; note ai4privacy is in the backbone's pretraining).- **Detection-tier** (does it find the PII span, ignoring fine type β the metric thatmatters for redaction) is markedly higher than exact-type across the board (β0.77β0.85internal/general), i.e. the strict per-type F1 understates real detection.## Usage```python3 unmodified linesspec = importlib.util.spec_from_file_location("hd", hf_hub_download("LiquidAI/pii-detect","pii_hybrid_decode.py"))hd = importlib.util.module_from_spec(spec); spec.loader.exec_module(hd)tok = AutoTokenizer.from_pretrained("LiquidAI/pii-detect", trust_remote_code=True)m = AutoModelForTokenClassification.from_pretrained("LiquidAI/pii-detect", trust_remote_code=True).eval()spans = hd.predict("Email Dr. Laura Schmidt at laura@charite.de about Marco Bianchi.", tok, m)# -> [{'type':'identity.person_name','text':'Laura Schmidt',...}, {'type':'contact.email',...}, ...]```
README.md+45-140