Tarnkappe: fast PII detection for German, English, French and Spanish

Find and mask personal data in German, English, French and Spanish text for GDPR (DSGVO, RGPD) work, on a plain CPU in about 1.2 ms per text.

GitHub Code: Apache 2.0 Weights: CC BY-SA 4.0

Before After
Hallo, ich bin Laura Becker von der Nordwind GmbH in Hamburg. Erreichbar unter 0171 3920045 oder laura.becker@nordwind.de. Hallo, ich bin [FIRST_NAME] [LAST_NAME] von der [ORGANIZATION] in [LOCATION]. Erreichbar unter [PHONE] oder [EMAIL].
Laura Becker works at Nordwind GmbH in Hamburg. Call her on +49 30 1234567 or mail laura.becker@nordwind.de. [FIRST_NAME] [LAST_NAME] works at [ORGANIZATION] in [LOCATION]. Call her on [PHONE] or mail [EMAIL].
Directrice de la publication : Marie Dupont, Lumière Éditions SARL, 12 rue des Lilas, 69003 Lyon. Directrice de la publication : [FIRST_NAME] [LAST_NAME], [ORGANIZATION], [STREET], [ZIP] [LOCATION].

Many open PII models focus on English. Tarnkappe is trained and tested on German, French and Spanish too, for Germany, Austria, Switzerland, France, Belgium and Spain: company forms (GmbH, e.V., SARL, Sàrl, SRL, ASBL, S.L.), phone numbers, postcodes, IBANs and national ID numbers.

It detects persons (split into first and last name), organisations, places, streets, postcodes, email addresses, phone numbers, IBANs, card numbers, IP addresses and national ID numbers (Spanish DNI/NIE, French NIR, Belgian national register number, Swiss AHV, each checksum-verified).

  • Small: a 2.8M-parameter BiGRU tagger, 6 MB as int8 ONNX, plus 52 MB of word vectors for four languages, about 200 MB of memory in all. No GPU, no PyTorch at runtime.
  • Hybrid: the tagger handles names, organisations and places. Patterns, checksums and Google's libphonenumber handle structured data.
  • Built for scanned web pages: a second check filters company detections, and names are shared across all pages of one person's scan.
  • Open: code Apache 2.0, weights CC BY-SA 4.0, trained only on openly licensed data.

Made by BetterPrivacy, which uses it to find where a person's data is exposed on the web. Code, training scripts and full results: github.com/ncserny/betterprivacy-tarnkappe

Quick start

pip install "git+https://github.com/ncserny/betterprivacy-tarnkappe" huggingface_hub
from huggingface_hub import snapshot_download
from tarnkappe import Detector

det = Detector(snapshot_download("ndrcsr/tarnkappe"))   # the package also ships these files; this loads them from the Hub

text = "Laura Becker works at Nordwind GmbH in Hamburg. Call her on +49 30 1234567 or mail laura.becker@nordwind.de."
for e in det.detect(text):
    print(e["type"], e["text"])
# FIRST_NAME Laura / LAST_NAME Becker / ORGANIZATION Nordwind GmbH / LOCATION Hamburg
# PHONE +49 30 1234567 / EMAIL laura.becker@nordwind.de

print(det.redact(text))
# [FIRST_NAME] [LAST_NAME] works at [ORGANIZATION] in [LOCATION]. Call her on [PHONE] or mail [EMAIL].

For web pages, use det.detect(text, profile="pages"). For many pages about one person, use detect_scan (see the GitHub README); it shares company names across pages.

Results

v0.8.2, 60 real French, Swiss, Belgian and Spanish pages (legal notices, team pages, directory profiles, press and news; 888 items; never used for training):

Found Release bar
All items 97.2% (v0.7: 89.6%)
Persons 100% 95%
Organisations 93.1% 80%
Places / streets / postcodes 98.3% / 98.4% / 94.9% 85% / 90% / 90%
Phones / e-mail 98.4% / 100% 95% / 99%
Detections that are real PII 86.0% (v0.7: 68.7%) 85%

These labels were made with AI assistance and a rule-by-rule check; some French/Spanish rules were written after reading the same pages. Treat it as a first real test.

v0.7, hand-labelled English and German web pages (pages profile, 45 snippets from five people's scans, never used for tuning: 141 organisations, 60 persons). Not yet re-run with v0.8.

Found Detections correct Release bar
Persons 100% 92.1% 95% found, 85% correct
Organisations 87.9% 89.9% 80% found, 85% correct

Public benchmarks, v0.8.2 (share of items found, any overlap counts):

Test Found
Persons in English web text (UNER EWT test) 96.2%
Persons in German Wikipedia/news (GermEval 2014 test) 96.0%
Persons in tweets (Broad Twitter Corpus test) 86.3%
Persons in social-media text (WNUT 2017 test) 88.6%
All PII in Microsoft Presidio sentences (templates unseen in training) 96.8% (95.1% of detections real; v0.7: 97.4%)
Organisations in the same Presidio sentences 98.5% (v0.7: 97.0%)
Persons in WikiNER French / Spanish test (strict F1) 0.86 / 0.86

v0.8.0 and v0.8.1 were weaker than v0.7 on English organisations (Presidio 92.6%) and German news. v0.8.2 is retrained and beats v0.7 on both: strict F1 0.668 on English web text (v0.7: 0.646), 0.715 on GermEval (0.687) and 0.733 on German PUD (0.694). The English/German v0.7 model stays available as revision v0.7.2 of this repository, and v0.8.1 as revision v0.8.1.

Speed: about 1.2 ms median per short text, about 700 texts per second on one CPU core, about 200 MB of memory with package v0.8.1 or later: less than the two-language v0.7 needed (310 MB), although it now knows four languages.

All numbers, test conditions and what is and is not a clean test are in RESULTS.md.

Files

File What
tagger.int8.onnx Quantised tagger, used by default (5 MB)
tagger.onnx Float32 tagger (10 MB)
vectors.npz Frozen input word vectors (from spaCy's en_core_web_md, de_core_news_md, fr_core_news_md, es_core_news_md)
orgcheck.onnx, org_lexicon.json Second check on company detections
institutions.txt Well-known organisations without a legal form (parties, media, public bodies), used on web pages; read by the package from its own copy
thresholds.json, profiles.json Decision thresholds and the pages profile
first_names.txt First names for splitting a person into first and last name
metrics.json Test scores of the float32 tagger

Training data and licence

Trained on openly licensed data only: UNER English EWT (CC BY-SA 4.0), GermEval 2014, WNUT 2017 and the Broad Twitter Corpus (CC BY 4.0), WikiNER and MultiCoNER v2 French and Spanish (CC BY 4.0), German, English, French and Spanish Wikipedia paragraphs labelled by GLiNER2-PII (text CC BY-SA 4.0), company names from CC0 sources, Presidio Research templates (MIT) and generated sentences. No real personal data was collected for training. Hand-labelled real pages are used for testing only.

The weights are licensed CC BY-SA 4.0 because the training data includes CC BY-SA text: if you publish a modified version, keep the licence and the credits in NOTICE. The code is Apache 2.0 on GitHub.

Limits

  • English, German, French and Spanish only. Dutch and Italian are not trained.
  • Small brand names with no context are sometimes missed or taken for persons.
  • Weaker on informal text: about 83–85% of persons are found in tweets and social-media posts.
  • It will miss things. Use it to reduce personal data, not as a guarantee of anonymisation or legal compliance.
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Datasets used to train ndrcsr/tarnkappe

Space using ndrcsr/tarnkappe 1

Collection including ndrcsr/tarnkappe