Team Ai
Modelpublic

gravitee-io/bert-small-pii-detection

sourceHugging Faceapache-2.0updated 5mo agoView on Hugging Face
7likes355kdownloads
Model Card

gravitee-io/bert-small-pii-detection ๐Ÿš€

Token-classification model for PII detection, fine-tuned from prajjwal1/bert-small on `gravitee-io/pii-detection-dataset`.

Label Set

AGE, COORDINATE, CREDIT_CARD, DATE_TIME, EMAIL_ADDRESS, FINANCIAL, HONORIFIC, IBAN_CODE, IMEI,
IP_ADDRESS, LOCATION, MAC_ADDRESS, NRP, ORGANIZATION, PASSWORD, PERSON, PHONE_NUMBER,
TITLE, URL, US_BANK_NUMBER, US_DRIVER_LICENSE, US_ITIN, US_LICENSE_PLATE, US_PASSPORT, US_SSN

How to Use

Quick start (pipeline)

python
from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline

repo = "gravitee-io/bert-small-pii-detection"
tok = AutoTokenizer.from_pretrained(repo)
model = AutoModelForTokenClassification.from_pretrained(repo)

pipe = pipeline("token-classification", model=model, tokenizer=tok, aggregation_strategy="simple")
text = "Contact John Smith at john@example.com"
pipe(text)

ONNX

commandline
pip install transformers onnxruntime huggingface_hub 
python
from huggingface_hub import hf_hub_download
from transformers import AutoTokenizer, AutoConfig
import onnxruntime as ort

model_id = "gravitee-io/bert-small-pii-detection"

tokenizer = AutoTokenizer.from_pretrained(model_id)
id2label = AutoConfig.from_pretrained(model_id).id2label
session = ort.InferenceSession(hf_hub_download(model_id, "model.quant.onnx"))

text = "Contact John Smith at john@example.com"
enc = tokenizer(text, return_tensors="np")
inputs = {"input_ids": enc["input_ids"], "attention_mask": enc["attention_mask"]}
logits = session.run(None, inputs)[0][0]

tokens = tokenizer.convert_ids_to_tokens(enc["input_ids"][0])
labels = [id2label[i] for i in logits.argmax(-1)]

for tok, label in zip(tokens, labels):
  print(f"{tok:<20} {label}")

Intended use

Detect personally identifiable information (PII) spans in english text. Suitable for privacy filtering, redaction pipelines, and data-leak prevention particularly on structured data (JSON, HTML, XML, SQL, Document)

Evaluation

MetricValue
F10.8686
Precision0.8182
Recall0.9256
Eval loss0.0132

Limitations

  • โ€”English-focused; other languages will degrade
  • โ€”Domain drift is real: audit on your own data ---

Benchmarks

External-corpus evaluation (English only), seqeval. Last run: 2026-05-21.

BenchmarkExamplesFP32 micro F1FP32 macro F1INT8 micro F1INT8 macro F1
gretelai/gretel-pii-masking-en-v1:test5,0000.91410.89710.91210.8860
gretelai/synthetic_pii_finance_multilingual:test2,9620.75340.73540.74980.7351
DataikuNLP/kiji-pii-training-data:test1,0330.92590.86850.92650.8725
beki/privy:test28,8430.88090.96940.88000.9680
beki/privy:test-large120,5740.98330.98100.98250.9801

Per-entity breakdown

<details> <summary><code>gretelai/gretel-pii-masking-en-v1:test</code></summary>

EntityFP32 F1FP32 P / RSupportINT8 F1INT8 P / R
AGE0.00000.000 / 0.00000.00000.000 / 0.000
COORDINATE0.89660.876 / 0.918850.89660.876 / 0.918
CREDIT_CARD0.95720.937 / 0.9796630.95240.926 / 0.980
DATE_TIME0.96050.935 / 0.9883,8050.95680.929 / 0.987
EMAIL_ADDRESS0.98540.976 / 0.9951,0480.98540.976 / 0.995
FINANCIAL0.71430.641 / 0.806310.68570.615 / 0.774
IMEI0.00000.000 / 0.00000.00000.000 / 0.000
IP_ADDRESS0.98190.974 / 0.9909610.98290.976 / 0.990
LOCATION0.85490.853 / 0.8571,7600.85610.855 / 0.857
NRP0.00000.000 / 0.00000.00000.000 / 0.000
ORGANIZATION0.71590.611 / 0.8651850.69740.587 / 0.859
PASSWORD0.87120.793 / 0.9661190.86790.788 / 0.966
PERSON0.79730.781 / 0.8143,2090.79480.781 / 0.809
PHONE_NUMBER0.97380.962 / 0.9869040.97010.955 / 0.986
TITLE0.00000.000 / 0.00000.00000.000 / 0.000
URL0.88460.793 / 1.000230.83020.733 / 0.957
US_BANK_NUMBER0.96100.962 / 0.9603980.96110.960 / 0.962
US_DRIVER_LICENSE0.00000.000 / 0.00000.00000.000 / 0.000
US_ITIN0.89360.875 / 0.913230.83330.800 / 0.870
US_LICENSE_PLATE0.91710.873 / 0.9655790.91560.871 / 0.965
US_PASSPORT0.00000.000 / 0.00000.00000.000 / 0.000
US_SSN0.98800.985 / 0.9911,7050.98980.988 / 0.992

</details>

<details> <summary><code>gretelai/syntheticpiifinance_multilingual:test</code></summary>

EntityFP32 F1FP32 P / RSupportINT8 F1INT8 P / R
AGE0.00000.000 / 0.00000.00000.000 / 0.000
COORDINATE0.60000.483 / 0.792530.60870.494 / 0.792
CREDIT_CARD0.58740.467 / 0.792530.61430.494 / 0.811
DATE_TIME0.74100.667 / 0.8334,2940.74060.667 / 0.833
EMAIL_ADDRESS0.79710.746 / 0.8565760.79810.741 / 0.865
FINANCIAL0.70480.632 / 0.7962940.69670.624 / 0.789
IBAN_CODE0.85140.778 / 0.940670.85710.787 / 0.940
IP_ADDRESS0.78540.796 / 0.7751110.78920.786 / 0.793
LOCATION0.75540.684 / 0.8441,9380.75060.677 / 0.842
NRP0.00000.000 / 0.00000.00000.000 / 0.000
ORGANIZATION0.69750.612 / 0.8112,7020.68760.602 / 0.802
PASSWORD0.63920.508 / 0.861360.59410.462 / 0.833
PERSON0.81250.778 / 0.8513,2950.80850.771 / 0.850
PHONE_NUMBER0.86480.791 / 0.9534060.86510.790 / 0.956
TITLE0.00000.000 / 0.00000.00000.000 / 0.000
URL0.00000.000 / 0.00000.00000.000 / 0.000
US_BANK_NUMBER0.60380.511 / 0.738650.59760.495 / 0.754
US_DRIVER_LICENSE0.77310.697 / 0.868530.77970.708 / 0.868
US_ITIN0.00000.000 / 0.00000.00000.000 / 0.000
US_LICENSE_PLATE0.00000.000 / 0.00000.00000.000 / 0.000
US_PASSPORT0.74190.708 / 0.780590.76800.727 / 0.814
US_SSN0.81120.773 / 0.853680.80560.763 / 0.853

</details>

<details> <summary><code>DataikuNLP/kiji-pii-training-data:test</code></summary>

EntityFP32 F1FP32 P / RSupportINT8 F1INT8 P / R
AGE0.86820.789 / 0.9661160.87940.801 / 0.974
CREDIT_CARD0.94310.892 / 1.000580.95870.921 / 1.000
DATE_TIME0.82760.742 / 0.9361410.83540.754 / 0.936
EMAIL_ADDRESS0.99420.989 / 1.0002580.99420.989 / 1.000
IBAN_CODE0.96550.942 / 0.990990.97030.951 / 0.990
LOCATION0.91150.878 / 0.9483,6300.91160.881 / 0.945
ORGANIZATION0.74390.716 / 0.7742740.74350.712 / 0.777
PASSWORD0.87320.845 / 0.9031030.90050.880 / 0.922
PERSON0.96850.956 / 0.9811,9870.96650.952 / 0.981
PHONE_NUMBER0.96760.968 / 0.9682470.96760.968 / 0.968
TITLE0.00000.000 / 0.00030.00000.000 / 0.000
URL0.94740.936 / 0.9591690.94190.926 / 0.959
US_DRIVER_LICENSE0.93230.900 / 0.9671210.95580.930 / 0.983
US_ITIN0.94740.947 / 0.947950.94740.947 / 0.947
US_LICENSE_PLATE0.96690.959 / 0.9751200.95080.935 / 0.967
US_PASSPORT0.97870.966 / 0.9911160.97460.958 / 0.991
US_SSN0.92910.892 / 0.9691960.93370.900 / 0.969

</details>

<details> <summary><code>beki/privy:test</code></summary>

EntityFP32 F1FP32 P / RSupportINT8 F1INT8 P / R
AGE0.96590.934 / 1.0007640.96100.926 / 0.999
COORDINATE0.00000.000 / 0.00000.00000.000 / 0.000
CREDIT_CARD1.00001.000 / 1.0007571.00001.000 / 1.000
DATE_TIME0.99750.995 / 1.0005,2890.99750.995 / 0.999
EMAIL_ADDRESS0.00000.000 / 0.00000.00000.000 / 0.000
FINANCIAL0.95840.924 / 0.9962,2430.95410.916 / 0.996
HONORIFIC0.99700.994 / 1.0002,3450.99720.995 / 1.000
IBAN_CODE0.00000.000 / 0.00000.00000.000 / 0.000
IMEI1.00001.000 / 1.0007690.99940.999 / 1.000
IP_ADDRESS0.00000.000 / 0.00000.00000.000 / 0.000
LOCATION0.88510.968 / 0.81512,9300.88500.968 / 0.815
MAC_ADDRESS0.99860.997 / 1.0007350.99590.992 / 1.000
NRP0.99580.992 / 0.9993,8290.99560.992 / 0.999
ORGANIZATION0.98200.977 / 0.9871,4930.98070.974 / 0.987
PASSWORD0.93480.881 / 0.9967200.93860.886 / 0.997
PERSON0.98970.988 / 0.9917,9860.98780.986 / 0.990
PHONE_NUMBER0.00000.000 / 0.00000.00000.000 / 0.000
TITLE0.96610.942 / 0.9927320.96550.939 / 0.993
URL0.00000.000 / 0.00000.00000.000 / 0.000
US_BANK_NUMBER0.99510.990 / 1.0007170.99580.992 / 1.000
US_DRIVER_LICENSE0.93030.890 / 0.9747810.92250.875 / 0.976
US_ITIN0.98110.965 / 0.9977540.98240.968 / 0.997
US_LICENSE_PLATE0.93900.895 / 0.9877880.93340.885 / 0.987
US_PASSPORT0.93340.893 / 0.9777530.93200.894 / 0.973
US_SSN0.00000.000 / 0.00000.00000.000 / 0.000

</details>

<details> <summary><code>beki/privy:test-large</code></summary>

EntityFP32 F1FP32 P / RSupportINT8 F1INT8 P / R
AGE0.94470.895 / 1.0003,0920.94410.895 / 0.999
COORDINATE0.99940.999 / 1.0009,5430.99960.999 / 1.000
CREDIT_CARD0.99680.997 / 0.9963,1510.99700.997 / 0.997
DATE_TIME0.99250.986 / 1.00022,1360.99230.985 / 0.999
EMAIL_ADDRESS0.99920.999 / 1.0003,1420.99870.998 / 1.000
FINANCIAL0.94810.907 / 0.9939,3600.94330.898 / 0.993
HONORIFIC0.99820.997 / 1.0009,5840.99820.997 / 1.000
IBAN_CODE0.99820.996 / 1.0003,0990.99820.996 / 1.000
IMEI0.99981.000 / 1.0003,1160.99970.999 / 1.000
IP_ADDRESS0.99720.994 / 1.0003,1850.99700.995 / 0.999
LOCATION0.97640.964 / 0.99043,9320.97610.963 / 0.989
MAC_ADDRESS0.99570.992 / 1.0003,1370.99510.991 / 1.000
NRP0.99480.991 / 0.99915,9430.99480.991 / 0.998
ORGANIZATION0.97940.970 / 0.9896,1650.97620.963 / 0.989
PASSWORD0.96560.936 / 0.9973,0820.95990.925 / 0.997
PERSON0.98870.987 / 0.99032,3800.98780.985 / 0.990
PHONE_NUMBER0.99790.996 / 1.0003,0990.99740.995 / 1.000
TITLE0.97440.954 / 0.9953,1920.96960.945 / 0.996
URL0.99850.997 / 1.0006,2370.99850.997 / 1.000
US_BANK_NUMBER0.99480.991 / 0.9993,0910.99370.989 / 0.998
US_DRIVER_LICENSE0.92380.874 / 0.9793,0410.92080.869 / 0.979
US_ITIN0.98210.966 / 0.9992,9950.98290.967 / 0.999
US_LICENSE_PLATE0.94580.902 / 0.9943,0490.94140.894 / 0.994
US_PASSPORT0.93440.889 / 0.9853,0440.94050.901 / 0.983
US_SSN0.99820.996 / 1.0002,9800.99900.998 / 1.000

</details>

Citation

Data citation are present in the dataset card used for this model. If you use the model, please consider citing the papers:

@misc{bhargava2021generalization,
      title={Generalization in NLI: Ways (Not) To Go Beyond Simple Heuristics}, 
      author={Prajjwal Bhargava and Aleksandr Drozd and Anna Rogers},
      year={2021},
      eprint={2110.01518},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}

@article{DBLP:journals/corr/abs-1908-08962,
  author    = {Iulia Turc and
               Ming{-}Wei Chang and
               Kenton Lee and
               Kristina Toutanova},
  title     = {Well-Read Students Learn Better: The Impact of Student Initialization
               on Knowledge Distillation},
  journal   = {CoRR},
  volume    = {abs/1908.08962},
  year      = {2019},
  url       = {http://arxiv.org/abs/1908.08962},
  eprinttype = {arXiv},
  eprint    = {1908.08962},
  timestamp = {Thu, 29 Aug 2019 16:32:34 +0200},
  biburl    = {https://dblp.org/rec/journals/corr/abs-1908-08962.bib},
  bibsource = {dblp computer science bibliography, https://dblp.org}
}