1from transformers import pipeline
2
3# Load the PII detection pipeline
4ner = pipeline("ner", model="OpenMed/OpenMed-PII-Arabic-SnowflakeMed-Large-568M-v1", aggregation_strategy="simple")
5
6text = """
7المريض خالد العتيبي (تاريخ الميلاد: 15/03/1985، رقم الهوية: 9876543210) تم فحصه اليوم.
8التواصل: khaled.otaibi@email.sa، الهاتف: +966 50 123 4567.
9العنوان: شارع العليا 42، الرياض 11432.
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-Arabic-SnowflakeMed-Large-568M-v1"
5model = AutoModelForTokenClassification.from_pretrained(model_name)
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7
8texts = [
9 "المريض خالد العتيبي (تاريخ الميلاد: 15/03/1985، رقم الهوية: 9876543210) تم فحصه اليوم.",
10 "التواصل: khaled.otaibi@email.sa، الهاتف: +966 50 123 4567.",
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)
-
AI4Privacy PII Masking 200K: Multilingual base dataset (200K records across 8 languages)
-
NVIDIA Nemotron-PII: Seed dataset for synthetic data generation
-
Synthetic Arabic Data: ~25K high-quality samples generated with locale-specific formatting (National ID format, +966 phones, Arabic names, SAR/ر.س currency)
-
Format: BIO-tagged token classification
-
Labels: 76 BIO tags (54 entity types)
1@misc{openmed-pii-2026,
2 title = {OpenMed-PII-Arabic-SnowflakeMed-Large-568M-v1: Arabic PII Detection Model},
3 author = {OpenMed Science},
4 year = {2026},
5 publisher = {Hugging Face},
6 url = {https://huggingface.co/OpenMed/OpenMed-PII-Arabic-SnowflakeMed-Large-568M-v1}
7}