Downloads · 30 days
29
6% of all-time downloads
naazimsnh02/qwen3-0.6b-pii-detector
qwen3-0.6b-pii-detector is a machine learning model from naazimsnh02. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as apache-2.0.
This model is a fine-tuned version of Qwen/Qwen3-0.6B for detecting Personally Identifiable Information (PII) and Protected Health Information (PHI) in text using inline tagging format.
Downloads · 30 days
29
6% of all-time downloads
All-time downloads
494
Public
Parameters
596M
1.2 GB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors1.2 GB · 99%
From the Hugging Face model README
This model is a fine-tuned version of Qwen/Qwen3-0.6B for detecting Personally Identifiable Information (PII) and Protected Health Information (PHI) in text using inline tagging format.
[entity]label)[entity]labelpip install transformers torch
from transformers import AutoModelForCausalLM, AutoTokenizer
# Load model and tokenizer
model_name = "naazimsnh02/qwen3-0.6b-pii-detector"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
# Prepare input
text = "My name is John Smith and my SSN is 123-45-6789. Contact me at [email protected]"
messages = [
{
"role": "user",
"content": f"""Analyze the following text and identify all PII (Personally Identifiable Information) and PHI (Protected Health Information) entities.
Text: {text}
Provide the output with inline tags in the format: [entity]label"""
}
]
# Generate
input_ids = tokenizer.apply_chat_template(
messages,
tokenize=True,
add_generation_prompt=True,
return_tensors="pt"
)
outputs = model.generate(
input_ids,
max_new_tokens=512,
temperature=0.1, # Lower for consistent tagging
top_p=0.9,
)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
# Output: My name is [John Smith]name and my SSN is [123-45-6789]ssn. Contact me at [[email protected]]email
For better accuracy, provide domain and locale information:
# Prepare input with context
text = "Patient John Doe, MRN 12345, diagnosed with hypertension."
domain = "healthcare"
doc_type = "medical_record"
locale = "us"
messages = [
{
"role": "user",
"content": f"""Analyze the following {doc_type} from the {domain} domain ({locale.upper()} locale) and identify all PII (Personally Identifiable Information) and PHI (Protected Health Information) entities.
Text: {text}
Provide the output with inline tags in the format: [entity]label"""
}
]
# Generate as above
input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt")
outputs = model.generate(input_ids, max_new_tokens=512, temperature=0.1)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
Use this utility class to extract structured data from the model's tagged output:
import re
from typing import List, Dict
class PIIExtractor:
"""
Utility class to extract PII entities from text tagged by the model.
The model outputs text in the format: [entity]label
Example: "[John Smith]first_name works at [Acme Corp]organization"
"""
def __init__(self):
# Pattern to match [entity]label format
self.pattern = re.compile(r'\[([^\]]+)\](\w+)')
def extract_entities(self, tagged_text: str) -> List[Dict[str, str]]:
"""
Extract all PII entities from tagged text.
Returns:
List of dictionaries with 'text' and 'label' keys
"""
matches = self.pattern.findall(tagged_text)
return [{"text": text, "label": label} for text, label in matches]
def extract_with_positions(self, tagged_text: str) -> List[Dict[str, any]]:
"""Extract entities with their positions in the original text."""
entities = []
offset = 0
for match in self.pattern.finditer(tagged_text):
entity_text = match.group(1)
label = match.group(2)
start = match.start() - offset
end = start + len(entity_text)
entities.append({
"text": entity_text,
"label": label,
"start": start,
"end": end
})
# Update offset (length of tags removed)
offset += len(label) + 2 # +2 for ] and label
return entities
def get_clean_text(self, tagged_text: str) -> str:
"""Remove all tags from text, leaving only the original content."""
# Remove labels and brackets
text = re.sub(r'\](\w+)', '', tagged_text)
text = text.replace('[', '')
return text
def group_by_label(self, tagged_text: str) -> Dict[str, List[str]]:
"""Group extracted entities by their label type."""
entities = self.extract_entities(tagged_text)
grouped = {}
for entity in entities:
label = entity['label']
if label not in grouped:
grouped[label] = []
grouped[label].append(entity['text'])
return grouped
# Example usage
extractor = PIIExtractor()
tagged_output = "[John Smith]first_name lives in [New York]city"
entities = extractor.extract_entities(tagged_output)
print(entities)
# [{'text': 'John Smith', 'label': 'first_name'}, {'text': 'New York', 'label': 'city'}]
clean_text = extractor.get_clean_text(tagged_output)
print(clean_text)
# "John Smith lives in New York"
grouped = extractor.group_by_label(tagged_output)
print(grouped)
# {'first_name': ['John Smith'], 'city': ['New York']}
The model outputs text with inline tags in the format: [entity]label
Example:
Input:
I am applying for student financial aid. My name is Peggy and my SSN is 250-38-8116.
Output:
I am applying for student financial aid. My name is [Peggy]first_name and my SSN is [250-38-8116]ssn.
The model can detect various types of sensitive information including:
first_name, last_name, name, maiden_name, middle_namessn (Social Security Number)date_of_birth, agegender, race_ethnicity, religious_beliefdriver_license, passport, national_idemail, phone_number, fax_numberstreet_address, address, city, state, county, zip_code, countrypo_boxmedical_record_number (mrn), patient_idblood_type, diagnosis, medication, procedurehealth_plan_id, insurance_number, policy_numberhospital_name, doctor_namecredit_card_number, bank_account_numberrouting_number, account_number, ibantax_id, employer_id (ein)salary, incomeorganization, company_name, employerjob_title, employee_idusername, user_idip_address, mac_addressurl, domain_namedevice_id, imeistudent_id, school_name, universitydegree, gpacase_number, court_namelicense_plate, vinAnd 20+ more categories...
Trained on diverse domains including:
This model was trained using:
⚠️ Important: This model is designed to DETECT PII/PHI, not to protect it.
Apache 2.0
If you use this model, please cite:
@misc{qwen3-pii-detector,
author = {Syed Naazim Hussain},
title = {Qwen3 0.6B PII Detector},
year = {2025},
publisher = {HuggingFace},
url = {https://huggingface.co/naazimsnh02/qwen3-0.6b-pii-detector}
}