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 context_cued.py with huggingface_hub
Browse files547 unmodified lines548549550547 unmodified linesreturn uniqCONTEXT_TYPES = set(_CUES) # the 12 Group-A types this tier owns547 unmodified lines548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659547 unmodified linesreturn uniqCONTEXT_TYPES = set(_CUES) # the 12 Group-A types this tier owns# =========================================================================== ## P2 — Group-B cue-gated capture (financial.amount / identity.date_of_birth /# contact.phone / contact.postal_code). High-precision: BOTH a cue AND a# value-shape must hold, so the precision-trap docs gain no new false positives.# These ADD spans, authoritative for their type. Distinct from the Group-A ID# tier above (those have no shape; these are shape + cue).# --------------------------------------------------------------------------- ## Shapes (reuse the shipped SNAP shapes so boundaries match the rest of the decode)._GB_PHONE = re.compile(r"(?<!\d)(?:\+?\d{1,3}[ \-.]?)?(?:\(\d{2,4}\)[ \-.]?)?\d{2,4}[ \-.]?\d{3}[ \-.]?\d{3,4}(?!\d)")_GB_DATE = re.compile(r"\b(?:\d{1,2}[\/.\-]\d{1,2}[\/.\-]\d{2,4}"r"|\d{4}[\/.\-]\d{1,2}[\/.\-]\d{1,2}"r"|(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[a-z]*\.?\s+\d{1,2},?\s+\d{4}"r"|\d{1,2}\.?\s+(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|"r"janv|f[ée]vr|mars|avr|mai|juin|juil|ao[ûu]t|sept|oct|nov|d[ée]c|"r"ene|abr|ago|dic|gen|mag|giu|lug|set|ott)[a-zéûô]*\.?\s+\d{4}"r"|\d{1,2}\s*(?:de\s+)?(?:[A-Za-zÀ-ÿ]{3,12})\s*(?:de\s+)?\d{4})\b")_GB_AMOUNT = re.compile(r"(?:[$€£¥₹₩]\s?\d[\d.,]*(?:\s?[KMB])?"r"|\b(?:USD|EUR|GBP|JPY|CHF|CAD|AUD|INR|KRW)\s?\d[\d.,]*(?:\s?[KMB])?\b"r"|\b\d[\d.,]*\s?(?:USD|EUR|GBP|JPY|CHF|INR|KRW|dollars|euros|pounds|yen)\b"r"|\b\d[\d.,]*\s?[$€£¥₹₩])")_GB_POSTAL = re.compile(r"\b(?:\d{5}(?:-\d{4})?|[A-Z]{1,2}\d[A-Z\d]?\s?\d[A-Z]{2}|\d{4}\s?[A-Z]{2}|\d{4})\b")# Cues (multilingual). Amount: also fires on a bare currency symbol adjacent to a# number even WITHOUT a word cue (the symbol IS the cue). Phone reuses tel/mobile/..._GB_CUES = {"financial.amount": re.compile(r"(?i)\b(?:amount|total|salary|balance|fee|price|sum|due|cost|charge|payment|"r"betrag|gehalt|saldo|geb[üu]hr|preis|summe|montant|salaire|solde|frais|prix|"r"importe|salario|saldo|precio|importo|stipendio|prezzo|valor|sal[áa]rio|"r"金额|金額|급여|잔액|사용료|сумма|оклад|баланс|المبلغ|الراتب|"r"kwota|wynagrodzenie|bel[oø]p|bel[ée]ag|summa|sum[ma]|m[ćc]e)\b"),"identity.date_of_birth": re.compile(r"(?i)(?:\bDOB\b|\bD\.?O\.?B\.?|date\s*of\s*birth|born(?:\s*on)?|"r"geburtsdatum|geb\.?\s*am|geboren|date\s*de\s*naissance|n[ée]\s*le|"r"fecha\s*de\s*nacimiento|nacid[oa]\s*el|data\s*di\s*nascita|nat[oa]\s*il|"r"data\s*de\s*nascimento|geboortedatum|data\s*urodzenia|"r"生年月日|生日|出生日期|생년월일|дата\s*рождения|تاريخ\s*الميلاد|"r"ng[àa]y\s*sinh|วันเกิด|f[öo]delsedatum|syntym[äa]aika)"),"contact.phone": re.compile(r"(?i)\b(?:tel|telephone|t[ée]l[ée]phone|phone|mobile|mob|cell|cellphone|"r"call|fax|whatsapp|handy|telefon|tel[ée]fono|telefono|telefoon|"r"電話|手机|手機|전화|휴대폰|телефон|موبايل|هاتف|"r"telefon|puhelin|tlf|s[đd]t|เบอร์โทร|m[óo]vil|celular|n[úu]mero)\b"),"contact.postal_code": re.compile(r"(?i)\b(?:zip|zip\s*code|postal\s*code|postcode|post\s*code|plz|postleitzahl|"r"code\s*postal|c[óo]digo\s*postal|cap|codice\s*postale|c[ée]p|postcode|"r"kod\s*pocztowy|邮编|邮政编码|郵便番号|우편번호|почтовый\s*индекс|"r"الرمز\s*البريدي|postnummer|postinumero|m[ãa]\s*b[uư]u)\b"),}# Amount also fires on bare currency symbol -> number (symbol is the cue)._GB_BARE_AMOUNT = re.compile(r"(?:[$€£¥₹₩]\s?\d[\d.,]*(?:\s?[KMB])?|\b\d[\d.,]*\s?[$€£¥₹₩])")# precision: a value must sit within this many chars AFTER the cue (cue->value gate)._GB_WINDOW = 24_GB_SHAPES = {"financial.amount": _GB_AMOUNT,"identity.date_of_birth": _GB_DATE,"contact.phone": _GB_PHONE,"contact.postal_code": _GB_POSTAL,}def group_b_cue_spans(text: str) -> list[dict]:"""Cue+shape gated Group-B spans. A span is emitted only when a value of theright SHAPE appears within _GB_WINDOW chars after a type cue (or, for amounts,when a bare currency symbol abuts the number). High precision by construction:no cue -> no span, so the precision traps stay clean."""out = []claimed = [False] * len(text)cand = [] # (start, end, type, specificity)for typ, cue_rx in _GB_CUES.items():shape = _GB_SHAPES[typ]for cm in cue_rx.finditer(text):window = text[cm.end():cm.end() + _GB_WINDOW]vm = shape.search(window)if not vm:continue# value must START within the window (not be far downstream prose)vs = cm.end() + vm.start()ve = cm.end() + vm.end()# require only separators/space between cue and valuegap = text[cm.end():vs]if not re.fullmatch(r"[\s:#=.\-/() :№\"']{0,24}", gap):continuecand.append((vs, ve, typ, cm.end() - cm.start() + 100))# bare currency-symbol amounts (symbol is the cue)for vm in _GB_BARE_AMOUNT.finditer(text):cand.append((vm.start(), vm.end(), "financial.amount", 50))cand.sort(key=lambda c: (-c[3], -(c[1] - c[0])))for vs, ve, typ, _spec in cand:if vs < 0 or ve > len(text) or any(claimed[vs:ve]):continueif len(text[vs:ve].strip()) < 3:continuefor i in range(vs, ve):claimed[i] = Trueout.append({"start": vs, "end": ve, "type": typ, "text": text[vs:ve]})out.sort(key=lambda d: (d["start"], d["end"]))return out
context_cued.py+109