Downloads · 30 days
18
5% of all-time downloads
sfermion/bert-pii-detector-onnx
bert-pii-detector-onnx is a token classification model from sfermion. Use it when you need labels on individual words, such as names. The card lists the license as apache-2.0.
This model is a BERT-based token classification model fine-tuned for detecting Personally Identifiable Information (PII) in text. The model is provided in ONNX format for efficient inference across different platforms.
Downloads · 30 days
18
5% of all-time downloads
All-time downloads
333
Public
Repo size
436 MB
Likes
0
Public
Click a slice to open those files.
.onnx436 MB · 100%
From the Hugging Face model README
This model is a BERT-based token classification model fine-tuned for detecting Personally Identifiable Information (PII) in text. The model is provided in ONNX format for efficient inference across different platforms.
bert-base-uncased (Google BERT)This model is designed to identify and classify various types of personally identifiable information in text, including but not limited to:
The model can detect 27 different types of PII entities:
The model uses BIO (Begin-Inside-Outside) tagging scheme, where:
B-[ENTITY] marks the beginning of an entityI-[ENTITY] marks the continuation of an entityO marks tokens that are not PIIpip install onnxruntime transformers tokenizers
import onnxruntime as ort
from transformers import AutoTokenizer
import numpy as np
# Load tokenizer
tokenizer = AutoTokenizer.from_pretrained("path/to/model")
# Load ONNX model
session = ort.InferenceSession("onnx/model.onnx")
# Prepare input text
text = "My name is John Smith and my email is [email protected]"
inputs = tokenizer(text, return_tensors="np", padding=True, truncation=True)
# Run inference
outputs = session.run(
None,
{
"input_ids": inputs["input_ids"].astype(np.int64),
"attention_mask": inputs["attention_mask"].astype(np.int64),
"token_type_ids": inputs["token_type_ids"].astype(np.int64)
}
)
# Get predictions
logits = outputs[0]
predictions = np.argmax(logits, axis=-1)
# Map predictions to labels
id2label = {
0: "B-BOD", 1: "B-BUILDING", 2: "B-CITY", 3: "B-COUNTRY",
4: "B-DATE", 5: "B-DRIVERLICENSE", 6: "B-EMAIL", 7: "B-GEOCOORD",
8: "B-GIVENNAME1", 9: "B-GIVENNAME2", 10: "B-IDCARD", 11: "B-IP",
12: "B-LASTNAME1", 13: "B-LASTNAME2", 14: "B-LASTNAME3", 15: "B-PASS",
16: "B-PASSPORT", 17: "B-POSTCODE", 18: "B-SECADDRESS", 19: "B-SEX",
20: "B-SOCIALNUMBER", 21: "B-STATE", 22: "B-STREET", 23: "B-TEL",
24: "B-TIME", 25: "B-TITLE", 26: "B-USERNAME", 27: "I-BOD",
28: "I-BUILDING", 29: "I-CITY", 30: "I-COUNTRY", 31: "I-DATE",
32: "I-DRIVERLICENSE", 33: "I-EMAIL", 34: "I-GEOCOORD", 35: "I-GIVENNAME1",
36: "I-GIVENNAME2", 37: "I-IDCARD", 38: "I-IP", 39: "I-LASTNAME1",
40: "I-LASTNAME2", 41: "I-LASTNAME3", 42: "I-PASS", 43: "I-PASSPORT",
44: "I-POSTCODE", 45: "I-SECADDRESS", 46: "I-SEX", 47: "I-SOCIALNUMBER",
48: "I-STATE", 49: "I-STREET", 50: "I-TEL", 51: "I-TIME",
52: "I-TITLE", 53: "I-USERNAME", 54: "O"
}
# Decode predictions
tokens = tokenizer.convert_ids_to_tokens(inputs["input_ids"][0])
labels = [id2label[pred] for pred in predictions[0]]
for token, label in zip(tokens, labels):
if token not in ["[CLS]", "[SEP]", "[PAD]"]:
print(f"{token}: {label}")
const ort = require('onnxruntime-node');
const { AutoTokenizer } = require('@xenova/transformers');
async function detectPII(text) {
// Load tokenizer
const tokenizer = await AutoTokenizer.from_pretrained('path/to/model');
// Load ONNX model
const session = await ort.InferenceSession.create('onnx/model.onnx');
// Tokenize input
const inputs = await tokenizer(text, {
padding: true,
truncation: true,
return_tensors: 'ortvalue'
});
// Run inference
const outputs = await session.run(inputs);
// Process outputs
const logits = outputs.logits;
// ... process predictions
}
The model was fine-tuned on the ai4privacy/pii-masking-300k dataset:
bert-base-uncased (Google BERT)The model should be evaluated on appropriate PII detection benchmarks using standard NER metrics (F1, Precision, Recall) for each entity type.
This model is designed to help protect privacy by detecting PII in text. However:
This model is compatible with ONNX Runtime and can be deployed on:
.
├── README.md # This file
├── config.json # Model configuration
├── tokenizer_config.json # Tokenizer configuration
├── tokenizer.json # Fast tokenizer
├── vocab.txt # Vocabulary file
├── special_tokens_map.json # Special tokens mapping
└── onnx/
└── model.onnx # ONNX model file
If you use this model in your research or application, please cite:
@misc{bert-pii-onnx,
title={BERT PII Detection Model (ONNX)},
author={Your Name/Organization},
year={2025},
howpublished={\url{https://huggingface.co/your-username/bert-pii-onnx}}
}
This model is based on BERT. Please also cite the original BERT paper:
@article{devlin2018bert,
title={BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding},
author={Devlin, Jacob and Chang, Ming-Wei and Lee, Kenton and Toutanova, Kristina},
journal={arXiv preprint arXiv:1810.04805},
year={2018}
}
For questions, issues, or feedback about this model, please open an issue in the model repository.
This model is built upon BERT (Bidirectional Encoder Representations from Transformers) developed by Google Research:
The model was trained on ai4privacy/pii-masking-300k:
@misc{ai4privacy-pii-dataset,
title={PII Masking 300K Dataset},
author={ai4privacy},
year={2024},
howpublished={\url{https://huggingface.co/datasets/ai4privacy/pii-masking-300k}}
}