A native MLX port of
OpenMed/privacy-filter-multilingual
for fast, on-device fine-grained PII detection across 54 categories
and 16 languages on Apple Silicon.
This 8-bit affine-quantized artifact reduces download size and resident memory; for the full-precision sibling see OpenMed/privacy-filter-multilingual-mlx.
Family at a glance. Same architecture and training data, three runtimes:
The model is a token classifier built on the OpenAI Privacy Filter
architecture (openai_privacy_filter). It tags each token with a BIOES
label across 54 PII span classes, then a Viterbi pass over the BIOES
grammar yields clean entity spans. Languages covered: Arabic, Bengali,
Chinese, Dutch, English, French, German, Hindi, Italian, Japanese,
Korean, Portuguese, Spanish, Telugu, Turkish, Vietnamese.
Full label schema (217 BIOES labels)
The output space is O plus B-, I-, E-, S- for each of the 54
span classes (4 × 54 + 1 = 217). The runtime PrivacyFilterMLXPipeline
runs Viterbi over this BIOES grammar, so the consumer sees clean grouped
entities rather than raw token tags. The full id2label mapping is
shipped alongside the weights in this repo.
For per-label accuracy, training recipe, and dataset details, see the
base PyTorch checkpoint.
The MLX runtime uses tiktokeno200k_base directly for tokenization;
the tokenizer.json is kept so consumers can inspect or re-tokenize via
transformers if desired.
OpenMed gives you a single extract_pii() / deidentify() API that
auto-selects MLX on Apple Silicon and PyTorch elsewhere — same code on
every host.
pip install -U "openmed[mlx]"
python
1from openmed import extract_pii, deidentify
23text =(4"Patient Sarah Johnson (DOB 03/15/1985), phone 415-555-0123, email sarah.johnson@example.com."5)67# Extract grouped entity spans (runs on MLX here, PyTorch fallback elsewhere)8result = extract_pii(text, model_name="OpenMed/privacy-filter-multilingual-mlx-8bit")9for ent in result.entities:10print(f"{ent.label:30s}{ent.text!r} conf={ent.confidence:.2f}")1112# De-identify13masked = deidentify(text, method="mask",14 model_name="OpenMed/privacy-filter-multilingual-mlx-8bit")15fake = deidentify(16 text,17 method="replace",18 model_name="OpenMed/privacy-filter-multilingual-mlx-8bit",19 consistent=True,20 seed=42,# deterministic locale-aware Faker surrogates21)
When MLX isn't available (Linux, Windows, Intel Mac, missing mlx package),
this exact same call automatically falls back to the PyTorch checkpoint
OpenMed/privacy-filter-multilingual with a one-time warning. Family-aware fallback: a Multilingual
MLX request never substitutes an unrelated baseline.
Direct MLX usage (lower-level)
python
1from huggingface_hub import snapshot_download
2from openmed.mlx.inference import PrivacyFilterMLXPipeline
34model_path = snapshot_download("OpenMed/privacy-filter-multilingual-mlx-8bit")5pipe = PrivacyFilterMLXPipeline(model_path)67print(pipe("Email me at alice.smith@example.com after 5pm."))8# [{'entity_group': 'EMAIL',9# 'score': 0.92,10# 'word': 'alice.smith@example.com',11# 'start': 12,12# 'end': 35}]
The pipeline returns a list of dicts with entity_group, score, word,
start, and end (character offsets into the input string).
Hardware notes
Designed for Apple Silicon (M-series GPUs); CPU inference works but is slower.
Tested on macOS with mlx>=0.18. The MLX runtime in this repo is
independent of mlx_lm (token classification, not causal LM).
Lower latency / smaller memory than the BF16 sibling.
Credits & Acknowledgements
This artifact wouldn't exist without two open-source releases — sincere
thanks to both teams:
OpenAI for open-sourcing the Privacy Filter
(architecture, modeling code, and opf training/eval CLI). The MLX
port in this repo runs that same architecture under Apple's MLX
framework.