1from transformers import pipeline
2
3# Load the PII detection pipeline
4ner = pipeline("ner", model="OpenMed/OpenMed-PII-Hindi-BiomedBERTFull-Base-110M-v1", aggregation_strategy="simple")
5
6text = """
7रोगी राजेश कुमार (जन्म तिथि: 15/03/1985, आधार: 9876 5432 1098) की आज जांच हुई।
8संपर्क: rajesh.kumar@email.in, फ़ोन: +91 98765 43210।
9पता: 123 विकास मार्ग, 110092 नई दिल्ली।
10"""
11
12entities = ner(text)
13for entity in entities:
14 print(f"{entity['entity_group']}: {entity['word']} (score: {entity['score']:.3f})")
1def redact_pii(text, entities, placeholder='[REDACTED]'):
2 """Replace detected PII with placeholders."""
3 # Sort entities by start position (descending) to preserve offsets
4 sorted_entities = sorted(entities, key=lambda x: x['start'], reverse=True)
5 redacted = text
6 for ent in sorted_entities:
7 redacted = redacted[:ent['start']] + f"[{ent['entity_group']}]" + redacted[ent['end']:]
8 return redacted
9
10# Apply de-identification
11redacted_text = redact_pii(text, entities)
12print(redacted_text)
1from transformers import AutoModelForTokenClassification, AutoTokenizer
2import torch
3
4model_name = "OpenMed/OpenMed-PII-Hindi-BiomedBERTFull-Base-110M-v1"
5model = AutoModelForTokenClassification.from_pretrained(model_name)
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7
8texts = [
9 "रोगी राजेश कुमार (जन्म तिथि: 15/03/1985, आधार: 9876 5432 1098) की आज जांच हुई।",
10 "संपर्क: rajesh.kumar@email.in, फ़ोन: +91 98765 43210।",
11]
12
13inputs = tokenizer(texts, return_tensors='pt', padding=True, truncation=True)
14with torch.no_grad():
15 outputs = model(**inputs)
16 predictions = torch.argmax(outputs.logits, dim=-1)
1@misc{openmed-pii-2026,
2 title = {OpenMed-PII-Hindi-BiomedBERTFull-Base-110M-v1: Hindi PII Detection Model},
3 author = {OpenMed Science},
4 year = {2026},
5 publisher = {Hugging Face},
6 url = {https://huggingface.co/OpenMed/OpenMed-PII-Hindi-BiomedBERTFull-Base-110M-v1}
7}