pii-filter-small

A small multilingual model that finds personal information in text. It uses exactly the 33 labels of openai/privacy-filter, so code that runs privacy-filter through transformers works with this one, at 141 million instead of 1.4 billion parameters.

On four public test sets it reaches about the same character F1 as privacy-filter with its official decoder (0.809 against 0.811), with less exact span boundaries (span F1 0.538 against 0.601). On a CPU the 268 MB int8 file is about six times faster than privacy-filter through transformers (202 against 1,281 ms per 1,000 characters, measured in separate runs).

I distilled it from openai/privacy-filter. It is not from or affiliated with OpenAI.

Quick start

from transformers import pipeline

ner = pipeline("token-classification", model="LukasKunhardt/pii-filter-small", aggregation_strategy="simple")
text = "Hi, I'm Anna Müller. Call me at +49 151 2345 6789 or write to anna.mueller@example.org."
for e in ner(text):
    print(e["entity_group"], repr(e["word"]), e["start"], e["end"])
private_person ' Anna Müller' 7 19
private_phone ' +49 151 2345 6789' 31 49
private_email ' anna.mueller@example.org' 61 86

The model predicts BIOES tags; since v1.0.4 config.json names the E- and S- classes I- and B-, so pipeline() returns whole entities (the original names are in bioes_id2label). A word can start with a space. read() in the code (GitHub) trims spaces and reads texts over 500 tokens in 512-token windows, as in training and testing. I tested it as the recognizer of the LLM Guard Anonymize scanner (PyTorch and ONNX).

With transformers.js:

import { pipeline } from "@huggingface/transformers";

const ner = await pipeline("token-classification", "LukasKunhardt/pii-filter-small", { dtype: "q8" });
console.log(await ner("Hi, I am Anna Müller. Mail anna.mueller@posteo.de or call +49 30 1234567."));

It returns one entry per token. dtype: "q8" loads onnx/model_quantized.onnx; in my Node test it matched fp32.

onnx/model.onnx (563 MB) is the fp32 export. In onnx/model_quantized.onnx (268 MB) only the embedding table is 8-bit. On 242 development texts they keep the PyTorch label for 100 % and 99.93 % of tokens (onnx/quantization_check.json).

Use with Presidio

presidio/pii_filter_small.yaml makes this model the NER model of Presidio for English, German, French and Spanish (add a lang_code and a small spaCy model for more):

from presidio_analyzer import AnalyzerEngine
from presidio_analyzer.nlp_engine import NlpEngineProvider
from presidio_anonymizer import AnonymizerEngine

nlp = NlpEngineProvider(conf_file="pii_filter_small.yaml").create_engine()
analyzer = AnalyzerEngine(nlp_engine=nlp, supported_languages=["en", "de", "fr", "es"])
text = "Mein Name ist Erika Mustermann, wohnhaft Lindenstraße 5, 10115 Berlin, Telefon 030 1234567."
print(AnonymizerEngine().anonymize(text=text, analyzer_results=analyzer.analyze(text=text, language="de")).text)
# Mein Name ist <PERSON>, <LOCATION>, Telefon <PHONE_NUMBER>

It needs pip install "presidio-analyzer[transformers]" presidio-anonymizer and the spaCy models named in the file. I checked one sentence per language; Presidio's own regex recognizers still run next to the model. Spans can grow by a neighbouring word or the final full stop (here "wohnhaft" went into the address), because Presidio aligns them to spaCy tokens.

What it finds

Eight categories with B-, I-, E- and S- labels, plus O: account_number (bank, card, ID, passport and tax numbers), private_address, private_date, private_email, private_person (also user names), private_phone, private_url (also IP addresses) and secret (passwords, API keys).

Results

Test data: fixed random samples of four public sets, 4,150 documents in 8 languages: ai4privacy/pii-masking-300k validation, and the test splits of Nemotron-PII, Kiji and Gretel finance. Character F1 (set columns) asks for every character whether it is personal, regardless of category. Span F1 needs start, end and category to match.

Model ai4privacy Nemotron Kiji Gretel Mean char F1 Mean span F1
pii-filter-small, PyTorch (seed 43) 0.929 0.817 0.830 0.661 0.809 0.538
pii-filter-small, onnx/model_quantized.onnx 0.924 0.823 0.844 0.649 0.810 0.530
privacy-filter, official opf decoder 0.952 0.823 0.832 0.637 0.811 0.601
privacy-filter through transformers (argmax) 0.868 0.696 0.737 0.606 0.726 0.471

Mean character F1 against model size

privacy-filter loses a lot when read by argmax per token, as I read my model, so I compare with its own package opf (Viterbi decoder). My model is not better than privacy-filter: it wins on Gretel, loses on ai4privacy, and its span boundaries are worse on every set.

CPU time on 50 Nemotron documents with 3 threads, in ms per 1,000 characters: int8 202, onnx/model.onnx 231, PyTorch 225, privacy-filter through transformers 1,281 and through opf 16,894 (ONNX times from a later run; chart). RESULTS.md has all tables.

PII Masking Benchmark

I ran the official evaluation of PIIMB with default settings: character masking regardless of category, mean F2 over six tasks. F2 per task: ai4privacy-en 0.902, ai4privacy-multi 0.845, gretel 0.903, mapa-eur-lex 0.290, nemotron-pii 0.616, privy 0.499. Among the 37 entries in its public results my model would rank 23rd. These are the numbers with the v1.0.4 labels; with the v1.0.3 labels the mean was 0.674. I changed the label names after I had seen that number, by a rule written before the new run.

Model Parameters Mean F2
OpenMed/privacy-filter-multilingual-v2 (best entry) 1.4 B 0.836
OpenMed/OpenMed-PII-SuperClinical-Small-44M-v1 (best of similar size) 141 M 0.816
pii-filter-small 141 M 0.676
openai/privacy-filter 1.4 B 0.662

How I tested

Test samples, label mapping and a gate were fixed in writing before training (rules/). In v1.0 one gate condition failed: the int8 file lost 0.018 mean character F1 against PyTorch, more than the allowed 0.01. This version's int8 file loses nothing there (0.810 against 0.809) and 0.008 mean span F1. I chose it on development texts by a rule written beforehand and measured it once on the test samples.

I opened the test samples once for my models, after choosing seed and checkpoint on development texts. privacy-filter was measured twice: through transformers before training, through opf afterwards. Gold spans without a match in my mapping are ignored (7,345 of 29,203).

Limits

  • Per-language tests cover nine languages, all on synthetic data. Real data and the other training languages, such as Arabic, Japanese and Chinese, are untested.
  • On clinical notes it left personal information in most documents (RESULTS.md).
  • In my tries, long numbers with spaces, such as IBANs, were sometimes split into parts of different categories.
  • This is not a medical device. Removing identifiers is not anonymisation under the GDPR: the remaining text can still identify a person.

Training data

  1. DeepSeek V4.1 Flash (open weights, MIT) wrote 24,000 documents in 22 languages, such as e-mails, invoices and chats, with invented people and values. About 15 % were asked to contain no personal information.
  2. I dropped 124 texts that shared a 10-word sequence with a test document, leaving 23,876.
  3. openai/privacy-filter labelled every text (spans and per-character category probabilities), read through transformers with argmax; I found the gap to opf only after training.
  4. 1,150 texts (5 %) became my development set.

Training

  • Base model: jhu-clsp/mmBERT-small (MIT).
  • Loss: cross-entropy on the teacher's BIOES spans plus KL divergence to its category probabilities.
  • 3 epochs, learning rate 5e-5, batch 16, windows of 512 tokens, about 21 minutes per seed on one NVIDIA A10G.
  • Seeds 42, 43 and 44 (test mean 0.809 character F1); I shipped seed 43, best on development character F1 (0.904).
  • The texts cost about 3 US dollars.

Licenses

The model is MIT, like mmBERT-small and DeepSeek V4.1 Flash; openai/privacy-filter is Apache 2.0. Nemotron-PII is CC BY 4.0, Gretel and Kiji are Apache 2.0. ai4privacy/pii-masking-300k (academic licence) and PIIMB (CC BY-NC 4.0) I used only for testing.

Versions

  • v1.0.5: presidio/pii_filter_small.yaml and a Presidio example. Model files unchanged.
  • v1.0.4: config.json names the E- and S- classes I- and B-, so pipeline(aggregation_strategy="simple") returns whole entities. Weights and ONNX files unchanged; PIIMB mean F2 0.674 → 0.676.
  • v1.0.3: new files onnx/model.onnx and onnx/model_quantized.onnx (mean character F1 0.810); onnx/model_int8.onnx (0.791) removed.

Citation

@misc{kunhardt2026piifiltersmall,
  author = {Lukas Kunhardt},
  title  = {pii-filter-small: a small multilingual PII detector with the labels of openai/privacy-filter},
  year   = {2026},
  url    = {https://huggingface.co/LukasKunhardt/pii-filter-small}
}

Contact: Lukas Kunhardt, ORCID 0000-0001-5135-6427, lukasvonkunhardt.com.

Downloads last month
112
Safetensors
Model size
0.1B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for LukasKunhardt/pii-filter-small

Quantized
(327)
this model

Datasets used to train LukasKunhardt/pii-filter-small