yalen-ai commited on
Commit
1dfa7bb
·
verified ·
1 Parent(s): 403a74c

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +246 -0
README.md ADDED
@@ -0,0 +1,246 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - fr
4
+ - en
5
+ - ar
6
+ - multilingual
7
+ license: mit
8
+ tags:
9
+ - distilbert
10
+ - ner
11
+ - pii
12
+ - privacy
13
+ - gdpr
14
+ - onnx
15
+ - quantized
16
+ - token-classification
17
+ - tunisian
18
+ pipeline_tag: token-classification
19
+ model-index:
20
+ - name: distilbert_pii_ner_yalen
21
+ results:
22
+ - task:
23
+ type: token-classification
24
+ metrics:
25
+ - type: f1
26
+ value: 0.9042
27
+ name: F1 (test set)
28
+ verified: false
29
+ ---
30
+
31
+ # distilbert_pii_ner_yalen — PII & NER Detector (9 classes · ONNX INT8)
32
+
33
+ Fine-tuned and quantized version of [distilbert-base-multilingual-cased](https://huggingface.co/distilbert-base-multilingual-cased) for PII and Named Entity Recognition detection.
34
+
35
+ Developed by [Yalen AI](https://huggingface.co/yalen-ai) as part of the Yalen Sentinel Pulse privacy protection platform.
36
+
37
+ > **Model format**: ONNX INT8 quantized — 74% smaller than the original PyTorch model (139 MB vs 543 MB), with minimal accuracy loss.
38
+
39
+ ---
40
+
41
+ ## Model Description
42
+
43
+ This model detects 9 classes of sensitive personal and financial information using BIO tagging. It supports multilingual input with strong performance on French, English, and Tunisian Arabic-Latin mixed text.
44
+
45
+ ### Detected Entities
46
+
47
+ | Entity | Description | Examples |
48
+ |--------|-------------|---------|
49
+ | PER | Person name | Ahmed Ben Salah, Marie Dupont |
50
+ | ORG | Organization | TechCorp Tunisie, Banque de France |
51
+ | LOC | Location | Tunis, Paris, avenue Habib Bourguiba |
52
+ | MISC | Miscellaneous named entity | Visa, MasterCard |
53
+ | IBAN | International Bank Account Number | TN59 1000 6035 1835 9848 3270, FR76 3000... |
54
+ | CARD | Credit / Debit card number | 4532 1234 5678 9012 |
55
+ | PHONE | Phone number (international formats) | +216 71 234 567, +33 1 23 45 67 89 |
56
+ | EMAIL | Email address | ahmed.bensalah@techcorp.tn |
57
+ | DATE | Date (any format) | 15/03/2025, 14 mars 2025, 12/2028 |
58
+
59
+ ---
60
+
61
+ ## Performance
62
+
63
+ ### Global Scores (epoch 4 / 14,944 steps)
64
+
65
+ | Precision | Recall | F1-Score | Accuracy |
66
+ |-----------|--------|----------|----------|
67
+ | 89.39% | 91.47% | **90.42%** | 98.87% |
68
+
69
+ ### Per-Class F1 (evaluation set)
70
+
71
+ | Entity | F1 |
72
+ |--------|----|
73
+ | PER | 100% |
74
+ | ORG | 88.9% |
75
+ | LOC | 80.0% |
76
+ | IBAN | 100% |
77
+ | CARD | 100% |
78
+ | PHONE | 100% |
79
+ | EMAIL | 100% |
80
+ | DATE | 66.7% |
81
+
82
+ ---
83
+
84
+ ## Training Data
85
+
86
+ | Source | Volume | Classes |
87
+ |--------|--------|---------|
88
+ | [Jean-Baptiste/wikiner_fr](https://huggingface.co/datasets/Jean-Baptiste/wikiner_fr) | 120,682 sentences | PER, ORG, LOC, MISC |
89
+ | [ai4privacy/pii-masking-200k](https://huggingface.co/datasets/ai4privacy/pii-masking-200k) | 82,545 examples | IBAN, CARD, PHONE, EMAIL, DATE |
90
+ | Faker (synthetic) | 40,000 examples (8,000 × 5 classes) | IBAN, CARD, PHONE, EMAIL, DATE |
91
+ | **TOTAL** | **239,099 train · 17,538 val** | **9 classes** |
92
+
93
+ ---
94
+
95
+ ## Quick Start
96
+
97
+ ### With Optimum (recommended for ONNX)
98
+
99
+ ```python
100
+ from optimum.onnxruntime import ORTModelForTokenClassification
101
+ from transformers import AutoTokenizer, pipeline
102
+
103
+ model = ORTModelForTokenClassification.from_pretrained(
104
+ "yalen-ai/distilbert_pii_ner_yalen",
105
+ file_name="model_quantized.onnx"
106
+ )
107
+ tokenizer = AutoTokenizer.from_pretrained("yalen-ai/distilbert_pii_ner_yalen")
108
+
109
+ ner = pipeline("token-classification", model=model, tokenizer=tokenizer, aggregation_strategy="simple")
110
+
111
+ text = "Contact: ahmed.bensalah@techcorp.tn | Tel: +216 71 234 567 | IBAN: TN59 1000 6035 1835 9848 3270"
112
+ results = ner(text)
113
+
114
+ for entity in results:
115
+ print(f"[{entity['entity_group']}] '{entity['word']}' (score: {entity['score']:.3f})")
116
+ ```
117
+
118
+ Output:
119
+ ```
120
+ [EMAIL] 'ahmed.bensalah@techcorp.tn' (score: 0.998)
121
+ [PHONE] '+216 71 234 567' (score: 0.984)
122
+ [IBAN] 'TN59 1000 6035 1835 9848 3270' (score: 0.757)
123
+ ```
124
+
125
+ ### With ONNX Runtime directly
126
+
127
+ ```python
128
+ import onnxruntime as ort
129
+ from transformers import AutoTokenizer
130
+ import numpy as np
131
+ import json
132
+
133
+ # Load tokenizer and label map
134
+ tokenizer = AutoTokenizer.from_pretrained("yalen-ai/distilbert_pii_ner_yalen")
135
+ with open("config.json") as f:
136
+ cfg = json.load(f)
137
+ id2label = cfg["id2label"]
138
+
139
+ # Load ONNX session
140
+ session = ort.InferenceSession("model_quantized.onnx", providers=["CPUExecutionProvider"])
141
+
142
+ def predict(text):
143
+ inputs = tokenizer(text, return_tensors="np", truncation=True, max_length=512)
144
+ outputs = session.run(None, dict(inputs))
145
+ logits = outputs[0][0]
146
+ token_ids = inputs["input_ids"][0]
147
+ tokens = tokenizer.convert_ids_to_tokens(token_ids)
148
+ labels = [id2label[str(np.argmax(l))] for l in logits]
149
+ return [(tok, lbl) for tok, lbl in zip(tokens, labels) if lbl != "O" and not tok.startswith("[")]
150
+
151
+ results = predict("Ahmed Ben Salah travaille chez TechCorp, IBAN: TN59 1000 6035 1835 9848 3270")
152
+ for token, label in results:
153
+ print(f" {token:<30} {label}")
154
+ ```
155
+
156
+ ---
157
+
158
+ ## Installation
159
+
160
+ ```bash
161
+ # For Optimum (ONNX Runtime)
162
+ pip install optimum[onnxruntime] transformers
163
+
164
+ # For direct ONNX Runtime usage
165
+ pip install onnxruntime transformers
166
+ ```
167
+
168
+ ---
169
+
170
+ ## Model Architecture
171
+
172
+ | Parameter | Value |
173
+ |-----------|-------|
174
+ | Base model | distilbert-base-multilingual-cased |
175
+ | Architecture | DistilBertForTokenClassification |
176
+ | Hidden size | 768 |
177
+ | Attention heads | 12 |
178
+ | Hidden layers | 6 |
179
+ | Max tokens | 512 |
180
+ | Vocab size | 119,547 |
181
+ | Labels | 19 (O + 9×BIO) |
182
+ | Format | ONNX INT8 (avx2 quantization) |
183
+
184
+ ### Model Size Comparison
185
+
186
+ | Stage | Format | Size |
187
+ |-------|--------|------|
188
+ | Fine-tuning | PyTorch FP32 | 543 MB |
189
+ | Export | ONNX FP32 | 539 MB |
190
+ | **Quantization** | **ONNX INT8 avx2** | **139 MB** |
191
+
192
+ ---
193
+
194
+ ## Label Map
195
+
196
+ ```json
197
+ {
198
+ "0": "O",
199
+ "1": "B-PER", "2": "I-PER",
200
+ "3": "B-ORG", "4": "I-ORG",
201
+ "5": "B-LOC", "6": "I-LOC",
202
+ "7": "B-MISC", "8": "I-MISC",
203
+ "9": "B-IBAN", "10": "I-IBAN",
204
+ "11": "B-CARD", "12": "I-CARD",
205
+ "13": "B-PHONE", "14": "I-PHONE",
206
+ "15": "B-EMAIL", "16": "I-EMAIL",
207
+ "17": "B-DATE", "18": "I-DATE"
208
+ }
209
+ ```
210
+
211
+ ---
212
+
213
+ ## Intended Use
214
+
215
+ - **Privacy compliance** (GDPR, Tunisian Data Protection Law)
216
+ - **Document redaction** — anonymize sensitive documents before sharing
217
+ - **Data loss prevention (DLP)** — detect accidental PII leaks in logs or messages
218
+ - **Financial document processing** — extract IBAN/card numbers for validation
219
+ - **Healthcare & insurance** — detect names, dates and contact information
220
+ - **Edge deployment** — ONNX INT8 runs efficiently on CPU without GPU
221
+
222
+ ---
223
+
224
+ ## Limitations
225
+
226
+ - Maximum input length: 512 tokens (long documents should be split by sentence or paragraph)
227
+ - DATE detection is the weakest class (F1 ~67%) — dates in full French text ("14 mars 2025") are harder to detect than numeric formats
228
+ - Card number detection works best with standard spacing (`XXXX XXXX XXXX XXXX`)
229
+ - MISC class is inherited from WikiNER and may catch general named entities beyond PII
230
+
231
+ ---
232
+
233
+ ## About Yalen AI
234
+
235
+ Yalen Sentinel Pulse is an AI-powered platform for PII detection and data privacy protection,
236
+ developed by the Yalen AI team. It combines regex patterns, ML models, and NER to
237
+ provide comprehensive sensitive data identification.
238
+
239
+ - Platform: Yalen Sentinel Pulse
240
+ - Contact: [hello@yalen.ai](mailto:hello@yalen.ai)
241
+
242
+ ---
243
+
244
+ ## License
245
+
246
+ MIT — free for commercial and research use.