Tarnkappe: fast PII detection for German and English

Find and mask personal data in German and English text for GDPR (DSGVO) work, on a plain CPU in about 1.5 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].

Many open PII models focus on English. Tarnkappe is trained and tested on German too, including German company forms (GmbH, e.V., AG), German phone numbers, postcodes and IBANs.

It detects persons (split into first and last name), organisations, places, streets, postcodes, email addresses, phone numbers, IBANs, card numbers and IP addresses.

  • Small: a 2.5M-parameter BiGRU tagger, 5 MB as int8 ONNX, plus 25 MB of word vectors. 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

Hand-labelled real web pages (pages profile). The largest test so far is 45 snippets from five people's scans, never used for tuning: 141 organisations and 60 persons.

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

These pages are mostly business profiles and press releases. On a smaller test of political news and blogs, organisations found was 71%.

Public benchmarks (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.5%
Persons in tweets (Broad Twitter Corpus test) 82.2%
Persons in social-media text (WNUT 2017 test) 83.9%
All PII in Microsoft Presidio sentences (templates unseen in training) 97.5% (96.3% of detections real)
European phone numbers, 40 countries (held-out synthetic test) 99.2%
Companies in English Wikipedia excerpts, companies unseen in training 82.6%

Speed: 1.5 ms median per short text, about 600 texts per second on one CPU core, about 270 MB of memory.

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)
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
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), German and English 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 and German only.
  • Small brand names with no context are sometimes missed or taken for persons.
  • Weaker on informal text: about 82–84% 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

Dataset used to train ndrcsr/tarnkappe

Space using ndrcsr/tarnkappe 1

Collection including ndrcsr/tarnkappe