A token classification (NER) model for
Personally Identifiable Information (PII) detection, fine-tuned on a combination of
ai4privacy/pii-masking-200k and
nvidia/Nemotron-PII datasets.
1from transformers import AutoModelForTokenClassification, AutoTokenizer
2import torch
3
4model_name = "seongyeon1/pii-deberta-v3-base-multi"
5tokenizer = AutoTokenizer.from_pretrained(model_name)
6model = AutoModelForTokenClassification.from_pretrained(model_name)
7
8text = "My name is John Smith and my email is john@example.com"
9inputs = tokenizer(text, return_tensors="pt", return_offsets_mapping=True)
10offset_mapping = inputs.pop("offset_mapping")
11
12with torch.no_grad():
13 outputs = model(**inputs)
14 predictions = torch.argmax(outputs.logits, dim=-1)[0]
15
16for idx, (pred, (start, end)) in enumerate(zip(predictions, offset_mapping[0])):
17 label = model.config.id2label[pred.item()]
18 if label != "O" and start != 0 and end != 0:
19 print(f"{text[start:end]} -> {label}")
54+ entity types from source datasets are merged into 7 standard Kaggle PII types: