Instructions to use Project-Bastion/english-pii-detector with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Project-Bastion/english-pii-detector with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("token-classification", model="Project-Bastion/english-pii-detector")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForTokenClassification tokenizer = AutoTokenizer.from_pretrained("Project-Bastion/english-pii-detector") model = AutoModelForTokenClassification.from_pretrained("Project-Bastion/english-pii-detector", device_map="auto") - Notebooks
- Google Colab
- Kaggle
english-pii-detector
Find personal data in English text and mask it: names, e-mail addresses, phone numbers, street addresses, SSNs, card numbers, passwords, usernames, dates of birth, driver's licence numbers, IP addresses, bank account numbers, ID numbers and API keys / PINs. An 82M-parameter DistilRoBERTa token classifier, Apache-2.0 (piiranha, a widely used open PII model, is CC-BY-NC-ND-4.0). It scores higher than piiranha and gliner_multi_pii on three public PII benchmarks, and it is a third of the size of the multilingual Project-Bastion/multilingual-pii-detector while matching its Nemotron-PII score.
Try it in your browser: a static page that runs the model locally (transformers.js, ONNX int8, about 83 MB, downloaded once). The text you paste never leaves your device.
Results
Micro F1 over characters, on the groups all three models can predict (name, e-mail, phone, address, SSN, card, password, username, date of birth, driver's licence). All models scored with identical code on identical documents; documents are taken in a fixed hash order from each test split.
| Benchmark | english-pii-detector | iiiorg/piiranha-v1-detect-personal-information (247k downloads, CC-BY-NC-ND-4.0) | urchade/gliner_multi_pii-v1 (89k downloads) |
|---|---|---|---|
| nvidia/Nemotron-PII test (1,000 docs) | 0.976 | 0.780 | 0.871 |
| gretelai/gretel-pii-masking-en-v1 test (1,000 docs) | 0.967 | 0.706 | 0.846 |
| gretelai/synthetic_pii_finance_multilingual test, English (1,000 docs) | 0.900 | 0.685 | 0.650 |
F1 per group on nvidia/Nemotron-PII:
| Group | this model | piiranha | gliner_multi_pii |
|---|---|---|---|
| NAME | 0.984 | 0.788 | 0.572 |
| 0.999 | 0.739 | 0.985 | |
| PHONE | 0.956 | 0.764 | 0.945 |
| ADDRESS | 0.890 | 0.840 | 0.833 |
| SSN | 0.981 | 0.800 | 0.989 |
| CARD | 0.913 | 0.931 | 0.945 |
| PASSWORD | 0.980 | 0.455 | 0.779 |
| USERNAME | 0.992 | 0.660 | 0.807 |
| DOB | 1.000 | 0.939 | 0.989 |
Usage
from transformers import pipeline
ner = pipeline("token-classification", model="Project-Bastion/english-pii-detector", aggregation_strategy="simple", stride=64)
def redact(text):
out, pos = "", 0
for e in sorted(ner(text), key=lambda e: e["start"]):
out += text[pos:e["start"]] + f"[{e['entity_group']}]"; pos = e["end"]
return out + text[pos:]
print(redact("Hi, I'm Maria Garcia. Reach me at maria.garcia@example.com or +1 415 555 0132."))
Labels: NAME, EMAIL, PHONE, ADDRESS, SSN, CARD, PASSWORD, USERNAME, DOB, DRIVER, IP, ACCOUNT, ID_NUM, SECRET. Texts longer than 256 tokens are processed in overlapping windows (stride=64).
Files
onnx/model_quantized.onnx (weight-only int8, 83 MB) and onnx/model.onnx (fp32, 326 MB) for onnxruntime. Against PyTorch on 40 checked documents, fp32 gives the same label for every token and int8 for 99.97% of tokens.
Notes on the numbers
This model was trained on the training splits of gretelai/synthetic_pii_finance_multilingual (English), gretelai/gretel-pii-masking-en-v1 and nvidia/Nemotron-PII; the scores are on their test splits. piiranha and gliner_multi_pii were trained on other data, so part of the gap is in-domain training. All three benchmarks are synthetic documents; scores on real-world text can be lower.
Limits
- Check recall on your own text before relying on it for compliance: it is weakest on card numbers and street addresses.
- English only; on short chat-style snippets and IBANs, also try the multilingual model.
License and credits
Apache-2.0. Base model: distilroberta-base (Apache-2.0). Training data: English parts of gretelai/synthetic_pii_finance_multilingual (Apache-2.0), gretelai/gretel-pii-masking-en-v1 (Apache-2.0) and nvidia/Nemotron-PII (CC-BY-4.0, NVIDIA). The test splits of these datasets are used for the scores above.
- Downloads last month
- -
Model tree for Project-Bastion/english-pii-detector
Base model
distilbert/distilroberta-baseSpace using Project-Bastion/english-pii-detector 1
Collection including Project-Bastion/english-pii-detector
Evaluation results
- micro F1 on nvidia/Nemotron-PII test (1000 documents)self-reported0.976
- micro F1 on gretelai/gretel-pii-masking-en-v1 test (1000 documents)self-reported0.967
- micro F1 on gretelai/synthetic_pii_finance_multilingual testself-reported0.900