hiteshwadhwani commited on
Commit
80a7e2f
·
verified ·
1 Parent(s): 532f888

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +198 -0
README.md ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ - hi
5
+ license: apache-2.0
6
+ tags:
7
+ - token-classification
8
+ - ner
9
+ - pii
10
+ - indian-languages
11
+ - hindi
12
+ - devanagari
13
+ - hinglish
14
+ - privacy
15
+ datasets:
16
+ - custom
17
+ base_model: ai4bharat/IndicBERTv2-MLM-only
18
+ pipeline_tag: token-classification
19
+ metrics:
20
+ - f1
21
+ - precision
22
+ - recall
23
+ model-index:
24
+ - name: pii-model-indicv2
25
+ results:
26
+ - task:
27
+ type: token-classification
28
+ name: Named Entity Recognition
29
+ metrics:
30
+ - name: F1
31
+ type: f1
32
+ value: 0.9497
33
+ - name: Precision
34
+ type: precision
35
+ value: 0.9464
36
+ - name: Recall
37
+ type: recall
38
+ value: 0.9530
39
+ ---
40
+
41
+ # PII Detection Model — IndicBERTv2
42
+
43
+ A token classification model for detecting and redacting **Personally Identifiable Information (PII)** in English, Hindi, Hinglish, and Devanagari text.
44
+
45
+ Built on [ai4bharat/IndicBERTv2-MLM-only](https://huggingface.co/ai4bharat/IndicBERTv2-MLM-only) — a 278M parameter BERT model pretrained on 20.9B tokens across 24 Indian languages.
46
+
47
+ ## Supported Languages
48
+ - **English** — names, addresses, phone numbers, SSN, etc.
49
+ - **Hindi (Devanagari)** — राजेश कुमार, मुंबई, बीस हज़ार रुपये, पंद्रह मार्च
50
+ - **Hinglish** — "Mera naam Rajesh hai aur main Mumbai mein rehta hoon"
51
+ - **Mixed Devanagari + English** — "मेरा phone number 9876543210 है"
52
+
53
+ ## Entity Types (31)
54
+
55
+ | Entity | Description | Example |
56
+ |--------|-------------|---------|
57
+ | FIRSTNAME | First name | Rajesh, राजेश, John |
58
+ | LASTNAME | Last name | Kumar, कुमार, Smith |
59
+ | MIDDLENAME | Middle name | Kumar |
60
+ | PREFIX | Title/prefix | Mr, श्री, Dr, श्रीमती |
61
+ | GENDER | Gender | male, female |
62
+ | SEX | Sex | M, F |
63
+ | AGE | Age | 35 |
64
+ | DOB | Date of birth | 15/03/1990 |
65
+ | DATE | General date | पंद्रह मार्च, March fifteenth |
66
+ | EMAIL | Email address | priya@gmail.com |
67
+ | PHONENUMBER | Phone number | +91 98765 43210 |
68
+ | CITY | City | Mumbai, मुंबई, Boston |
69
+ | STATE | State | Maharashtra, महाराष्ट्र |
70
+ | COUNTY | County | Cook County |
71
+ | ZIPCODE | ZIP/PIN code | 400001, 02101 |
72
+ | STREET | Street name | MG Road, Oak Avenue |
73
+ | BUILDINGNUMBER | Building number | 42 |
74
+ | SECONDARYADDRESS | Apt/Suite | Flat 301 |
75
+ | COMPANYNAME | Company | Infosys, टाटा कंसल्टेंसी |
76
+ | ACCOUNTNUMBER | Account number | 9876543210 |
77
+ | ACCOUNTNAME | Account name | Tata Consultancy |
78
+ | CREDITCARDNUMBER | Credit card | 4111-1111-1111-1111 |
79
+ | CREDITCARDCVV | CVV | 123 |
80
+ | CREDITCARDISSUER | Card issuer | Visa, HDFC |
81
+ | SSN | SSN/PAN/Aadhaar | 123-45-6789, ABCDE1234F |
82
+ | IBAN | IBAN | IN89UTIB00001234567890 |
83
+ | PIN | ATM/Security PIN | 4098 |
84
+ | PASSWORD | Password | S3cur3P@ss! |
85
+ | USERNAME | Username | mdavis |
86
+ | URL | URL | www.example.com |
87
+ | AMOUNT | Money amount | 50000, बीस हज़ार रुपये |
88
+
89
+ ## Usage
90
+
91
+ ```python
92
+ from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
93
+
94
+ model = AutoModelForTokenClassification.from_pretrained("hiteshwadhwani/pii-model-indicv2")
95
+ tokenizer = AutoTokenizer.from_pretrained("hiteshwadhwani/pii-model-indicv2")
96
+
97
+ ner = pipeline("ner", model=model, tokenizer=tokenizer, aggregation_strategy="first")
98
+
99
+ # English
100
+ results = ner("Mr John Smith lives at 456 Oak Avenue Boston")
101
+
102
+ # Hinglish
103
+ results = ner("Mera naam Rajesh Kumar hai aur main Mumbai mein rehta hoon")
104
+
105
+ # Hindi (Devanagari)
106
+ results = ner("मेरा नाम राजेश कुमार है और मैं मुंबई में रहता हूं")
107
+
108
+ # Hindi amounts and dates in words
109
+ results = ner("आपके क्रेडिट कार्ड के बीस हज़ार रूपये शुल्क लंबित हैं, जो पंद्रह मार्च को देना था।")
110
+
111
+ for entity in results:
112
+ if entity["entity_group"] != "O":
113
+ print(f"{entity['word']} → {entity['entity_group']} ({entity['score']:.2f})")
114
+ ```
115
+
116
+ ### Redaction Example
117
+
118
+ ```python
119
+ def redact_pii(text, ner_pipeline, threshold=0.5):
120
+ results = ner_pipeline(text)
121
+ entities = [r for r in results if r["score"] >= threshold and r["entity_group"] != "O"]
122
+ entities.sort(key=lambda x: x["start"])
123
+
124
+ merged = []
125
+ for ent in entities:
126
+ label = ent["entity_group"]
127
+ if merged and merged[-1]["label"] == label and ent["start"] <= merged[-1]["end"] + 1:
128
+ merged[-1]["end"] = max(merged[-1]["end"], ent["end"])
129
+ else:
130
+ merged.append({"label": label, "start": ent["start"], "end": ent["end"]})
131
+
132
+ redacted = text
133
+ for span in reversed(merged):
134
+ redacted = redacted[:span["start"]] + f"[{span['label']}]" + redacted[span["end"]:]
135
+ return redacted
136
+
137
+ print(redact_pii("Shri Rajesh Kumar lives at 42 MG Road Bengaluru Karnataka", ner))
138
+ # [PREFIX] [FIRSTNAME] [LASTNAME] lives at [BUILDINGNUMBER] [STREET] [CITY] [STATE]
139
+
140
+ print(redact_pii("आपके बीस हज़ार रूपये शुल्क लंबित हैं, जो पंद्रह मार्च को देना था।", ner))
141
+ # आपके [AMOUNT] शुल्क लंबित हैं, जो [DATE] को देना था।
142
+ ```
143
+
144
+ ## Evaluation Results
145
+
146
+ | Metric | Score |
147
+ |--------|-------|
148
+ | **Overall F1** | **0.9497** |
149
+ | Precision | 0.9464 |
150
+ | Recall | 0.9530 |
151
+
152
+ ### Per-Entity F1
153
+
154
+ | Entity | F1 | Entity | F1 |
155
+ |--------|-----|--------|-----|
156
+ | FIRSTNAME | 0.99 | LASTNAME | 0.99 |
157
+ | CITY | 0.99 | STATE | 0.99 |
158
+ | PHONENUMBER | 0.98 | EMAIL | 0.93 |
159
+ | DOB | 0.96 | DATE | 0.95 |
160
+ | COMPANYNAME | 0.97 | PREFIX | 0.98 |
161
+ | CREDITCARDNUMBER | 0.95 | CREDITCARDISSUER | 0.95 |
162
+ | URL | 0.99 | USERNAME | 0.99 |
163
+ | MIDDLENAME | 1.00 | ACCOUNTNUMBER | 0.91 |
164
+ | PASSWORD | 0.91 | ZIPCODE | 0.95 |
165
+ | AMOUNT | 0.86 | STREET | 0.91 |
166
+
167
+ ## Why IndicBERTv2?
168
+
169
+ | | indic-bert (v1) | IndicBERTv2 (this model) |
170
+ |---|---|---|
171
+ | Parameters | 32M | **278M** |
172
+ | Architecture | ALBERT (shared layers) | **BERT (unique layers)** |
173
+ | Languages | 12 | **24** |
174
+ | Training corpus | ~9B tokens | **20.9B tokens** |
175
+ | Devanagari names | Partial subword issues | **Clean detection** |
176
+ | Hindi amounts (बीस हज़ार) | Not detected | **Detected** |
177
+ | Hindi dates (पंद्रह मार्च) | Not detected | **Detected** |
178
+ | Unusual names (Viteshwar) | Broken subword alignment | **Clean detection** |
179
+
180
+ ## Training Details
181
+
182
+ - **Base model**: ai4bharat/IndicBERTv2-MLM-only (278M params, 24 languages)
183
+ - **Task**: Token Classification (NER with BIO tagging)
184
+ - **Epochs**: 10
185
+ - **Learning rate**: 2e-5
186
+ - **Batch size**: 16
187
+ - **Optimizer**: AdamW
188
+
189
+ ## Limitations
190
+
191
+ - SEX entity has low F1 — overlaps with GENDER
192
+ - SECONDARYADDRESS detection is weak
193
+ - Latency is higher than v1 (~25-40ms vs ~8ms) due to larger model size
194
+ - Best suited for Indian and US PII patterns
195
+
196
+ ## License
197
+
198
+ Apache 2.0