Downloads · 30 days
7
5% of all-time downloads
contriqx-Hub/arabic-pii-guardrail
arabic-pii-guardrail is a text classification model from contriqx-Hub. Use it when you need a label for a piece of text. It is set up for transformers. The card lists the license as apache-2.0.
A fine-tuned XLM-RoBERTa-large model that detects intent to share personally identifiable information (PII), not just its presence. Built with a focus on Arabic (Gulf dialect + MSA) and English, with support for code-…
Downloads · 30 days
7
5% of all-time downloads
All-time downloads
143
Public
Parameters
560M
2.3 GB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors2.2 GB · 99%
From the Hugging Face model README
A fine-tuned XLM-RoBERTa-large model that detects intent to share personally identifiable information (PII), not just its presence. Built with a focus on Arabic (Gulf dialect + MSA) and English, with support for code-switched and Arabizi text.
The model answers: is this person sharing, requesting, or exposing PII? — not simply does this text contain a recognizable PII pattern?
| Entity Type | Description | Example |
|---|---|---|
PHONE | Phone numbers | 05321234567, +966501234567 |
EMAIL | Email addresses | [email protected] |
SOCIAL_MEDIA | Social media handles | @username, Instagram, TikTok, Telegram |
IBAN | Bank account numbers | SA44 2000 0001 2345 6789 1234 |
ADDRESS | Physical addresses | 45 Tahrir St, Cairo |
URL | Personal websites / profiles | mysite.com |
CREDIT_CARD | Credit card numbers | 4532 **** **** 1234 |
CRYPTO_ADDRESS | Cryptocurrency wallet addresses | 0x71C7656EC7ab88b098defB751B7401B5f6d8976F |
OFF_PLATFORM_ATTEMPT | Attempts to move contact off-platform | "let's talk on WhatsApp" |
NAME | Full personal names | محمد العنزي, Sarah Khaled |
"رقمي 0532..." / "my number is 0532...""تكلم مع خالد الشمري، رقمه..." / "ask for Ahmed, call him at...""find me on the gram @handle", spaced digits "0 5 3 2...", Arabizi names"I'll send you my number tomorrow""if we agree I'll share my address""ما أبي بس رقمي هو..." / "I don't want to but here's my number""وش رقمك؟" / "what's your number?""راجع الدكتور محمد العنزي" / "speak to Dr. Mariam Abdullah""your order ORD-784321""احذر من محتالين يتصلون بأرقام مجهولة""Elon Musk announced...", "صرّح محمد بن سلمان بأن...""follower count hit 532,000", "1250 SAR""someone sent me their number, I'm reporting it""my number is 00000000000 lol"Arabic is the primary focus of this model. It handles the full spectrum of how Arabic speakers actually write online — not just formal text.
Dialects covered
والله, بس, خيي, صاحبي, يو, ابعتلياسمي, تواصل مع, يُعرف بـ, يُدعىScript variations
A7med, F6oum, 7amada, Kh@ledArabic-specific intent signals the model recognizes
| Signal | Example |
|---|---|
| First-person name intro | "اسمي محمد العنزي" / "أنا خالد عبدالله" |
| Possessive third-party | "صاحبي / خيي [name] قال تتواصل معه" |
| Honorific + full name | "تكلم مع الدكتور سامي العمر" |
| Contact redirect | "تواصل معي" / "راسلني" / "ابعتلي رسالة" |
| Platform redirect | "على الإنستا / على السناب / في البايو" |
| Reluctant sharing | "ما أبي بس رقمي هو..." |
| Scam warning with real number | "احذر من هذا الرقم 0501234567" → PII = True |
| Scam warning without number | "احذر من محتالين يتصلون" → PII = False |
Note: This model is designed for the second stage of a two-stage pipeline. An upstream system (regex, NER, or a rules engine) first extracts candidate entities from the text. This model then classifies whether the intent behind each extracted entity is PII sharing. The
entityandentity_typearguments must be provided by the upstream stage. Useentity="NONE"when the sharing intent is implicit and no specific entity string is present in the text (e.g. "I'll send you my details later").
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
import torch.nn.functional as F
model_name = ""
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
model.eval()
def classify_pii(context: str, entity: str, entity_type: str) -> dict:
"""
Args:
context: Full message text
entity: The specific entity string (use "NONE" if implicit)
entity_type: One of PHONE | EMAIL | SOCIAL_MEDIA | IBAN | ADDRESS |
URL | CREDIT_CARD | CRYPTO_ADDRESS | OFF_PLATFORM_ATTEMPT | NAME
Returns:
dict with is_pii (bool), label (str), confidence (float)
"""
text = f"{context} </s> {entity} | {entity_type}"
inputs = tokenizer(
text,
max_length=256,
padding="max_length",
truncation=True,
return_tensors="pt"
)
with torch.no_grad():
outputs = model(**inputs)
probs = F.softmax(outputs.logits, dim=-1)
pred = torch.argmax(probs, dim=-1).item()
confidence = probs[0][pred].item()
return {
"is_pii": pred == 1,
"label": "PII" if pred == 1 else "NOT_PII",
"confidence": round(confidence, 4)
}
# True cases
# NONE entity — implicit sharing intent, no entity string present
classify_pii("I'll send you my details later, just DM me", "NONE", "PHONE")
# → {'is_pii': True, 'label': 'PII', 'confidence': 0.9134}
# When you know the entity type context (more reliable)
classify_pii("سأبعثلك رقمي بكرة", "NONE", "PHONE")
# → {'is_pii': True, 'label': 'PII', 'confidence': 0.8287}
# When entity type is also unknown (use with caution — out of training distribution)
classify_pii("سأبعثلك رقمي بكرة", "NONE", "NONE")
# → {'is_pii': True, 'label': 'PII', 'confidence': 0.7803}
classify_pii("check my bio, everything is there", "NONE", "SOCIAL_MEDIA")
# → {'is_pii': True, 'label': 'PII', 'confidence': 0.9056}
# NONE entity — vague mention, no actual sharing intent
classify_pii("I wish I had someone's number to call right now", "NONE", "PHONE")
# → {'is_pii': False, 'label': 'NOT_PII', 'confidence': 0.8821}
classify_pii("اسمي محمد العنزي وأبي أتواصل معاك", "محمد العنزي", "NAME")
# → {'is_pii': True, 'label': 'PII', 'confidence': 0.9814}
classify_pii("my number is 0532 1234567, call me anytime", "0532 1234567", "PHONE")
# → {'is_pii': True, 'label': 'PII', 'confidence': 0.9923}
classify_pii("find me on the gram @secret_handle", "@secret_handle", "SOCIAL_MEDIA")
# → {'is_pii': True, 'label': 'PII', 'confidence': 0.9761}
# False cases
classify_pii("your order ORD-784321 has been shipped", "ORD-784321", "PHONE")
# → {'is_pii': False, 'label': 'NOT_PII', 'confidence': 0.9502}
classify_pii("Elon Musk announced new features today", "Elon Musk", "NAME")
# → {'is_pii': False, 'label': 'NOT_PII', 'confidence': 0.9388}
FacebookAI/xlm-roberta-large — 550M parameters, multilingual transformer.
NAME entity type (Arabic Gulf + MSA + English + Mixed)| Parameter | Value |
|---|---|
| Loss function | Focal Loss (γ=2, inverse class frequency weights) |
| Learning rate | 1.5e-5 |
| Batch size | 64 (effective, with gradient accumulation) |
| Epochs | 15 |
| Precision | bf16 mixed precision |
| Max sequence length | 256 |
The model expects a specific input format that combines context, entity, and entity type:
{context} </s> {entity} | {entity_type}
Evaluated on a curated benchmark of 2,094 samples across 14 slices covering core capability, adversarial cases, regression tests, and cross-entity confusion.
| Metric | Score |
|---|---|
| Macro F1 | 0.865 |
| Accuracy | 0.866 |
| AUC-ROC | 0.951 |
| FNR (miss rate) | 3.1% |
| FPR (false alarm rate) | 28.8% |
| Entity Type | F1 |
|---|---|
NAME | 0.918 |
OFF_PLATFORM_ATTEMPT | 0.886 |
PHONE | 0.845 |
IBAN | 0.860 |
CREDIT_CARD | 0.852 |
URL | 0.827 |
SOCIAL_MEDIA | 0.820 |
EMAIL | 0.767 |
ADDRESS | 0.710 |
| Language | F1 |
|---|---|
| Arabic | 0.847 |
| English | 0.844 |
| Mixed / Code-switched | 0.782 |
| Slice | F1 | Note |
|---|---|---|
names_core | 0.970 | Name intent detection |
phone_regression | 0.938 | Phone detection unchanged |
evasion_coded | 1.000 | Obfuscated / coded PII |
false_negative_traps | 1.000 | Subtle sharing intent |
false_positive_traps | 0.415 | Known limitation — see below |
context_flip_pairs | 0.637 | Same entity, context flips label |
The model currently leans toward false positives. With an overall FPR of 28.8%, it occasionally flags non-PII content as PII — particularly when a recognizable entity (phone number, email, name) appears in a clearly non-sharing context (news mentions, statistics, celebrity references). This is a precision-recall tradeoff: the model is tuned to almost never miss a genuine PII sharing event (FNR = 3.1%), at the cost of some over-triggering.
Specific known gaps:
These limitations will be addressed in the next release through targeted hard-negative training data and threshold calibration.