inboxpraveen commited on
Commit
a7a942f
·
verified ·
1 Parent(s): e0044a5

Upload 22 files

Browse files
README.md CHANGED
@@ -1,6 +1,7 @@
1
  ---
2
  license: gemma
3
  base_model: google/gemma-3-270m-it
 
4
  library_name: transformers
5
  pipeline_tag: text-generation
6
  tags:
@@ -44,116 +45,47 @@ language:
44
  - pl
45
  ---
46
 
47
- # Kavach PII 270M
48
 
49
- A 270M parameter model that finds personal data in 29 languages. This is version 3. On a held-out test set of 4,577 documents it scores 92.0 value-F1, where GLiNER-PII scores 59.3 and Microsoft Presidio scores 29.5, measured with the same script against the same gold annotations. On 480 documents built entirely by code in eight real-world formats, which share nothing with the training data generator, it scores 90.4.
 
 
50
 
51
- *Kavach* (कवच) is Sanskrit for "armour". The model reads a document and returns the personal data it contains as a JSON list. It runs on a laptop GPU or on CPU, and it was built for the inputs real pipelines actually receive: call-centre ASR transcripts, scanned OCR output, bank statements and CSV exports, forms, chat, code, logs, and deliberately obfuscated text.
52
 
53
- ![Comparison against v2, GLiNER, Presidio and regex baselines](assets/01-headline-comparison.png)
54
 
55
- | | Kavach v3 | Kavach v2 | GLiNER-PII multi-v1 | Presidio | Regex + checksum |
56
- |---|---|---|---|---|---|
57
- | **Value F1** | **92.0** | 79.0 | 59.3 | 29.5 | 30.3 |
58
- | Precision | **92.0** | 86.8 | 67.1 | 30.3 | 66.0 |
59
- | Recall | **92.1** | 72.5 | 53.1 | 28.7 | 19.6 |
60
- | Exact span F1 | **92.5** | 80.1 | 57.8 | 29.5 | 29.1 |
61
- | Redaction recall | **96.0** | 82.2 | 61.1 | 48.9 | 23.9 |
62
- | **False positives on PII-free documents** | 12.5% | **2.0%** | 77.7% | 83.4% | 23.9% |
63
-
64
- Test set: 4,577 held-out documents with 28,672 labelled values, 440 of them free of personal data. It is 3,347 documents from the v2 test set with repaired labels, plus 1,230 new held-out documents. The v2 column is v2's own predictions, re-scored on this gold, not a number copied from the old card. Label sets of the other systems were mapped to ours on a best-effort basis; see [Fair comparison notes](#fair-comparison-notes).
65
-
66
- The last row is the one place where v3 is worse than v2, and it matters for redaction pipelines. Presidio flags something in 83% of documents that contain no personal data and GLiNER in 78%. v2 did so in 2.0%, and v3 does so in 12.5%. Most of v3's cases (35 of the 55 documents) are nothing but a date or a reference number in a document about nobody: an expiry date on a product notice, an order reference in a shipping log. A date or a case number is personal data only when it belongs to someone's record, and v3 learnt to tag them eagerly from dense bank statements and forms. If over-masking such documents is a problem for you, drop the result when the only labels found are dates and case numbers:
67
-
68
- ```python
69
- if {s["label"] for s in result["spans"]} <= {"DATE_TIME", "CASE_ID"}:
70
- result["spans"] = []
71
- ```
72
 
73
- On the test set that brings the rate from 12.5% to 4.5%, at a cost of 0.5 F1, because some real records contain nothing else (an appointment reminder with a booking reference, for example).
74
-
75
- ## What's new in v3
76
-
77
- v3 is the same model size, the same base model and the same training recipe as v2; only the augmentation rate changed. What changed is the data: every label in the old corpus was re-checked, 23,434 new training documents were added, and the label set was simplified from 52 labels to 43. The table below scores both models on the same documents against the same gold at every step, so each step isolates one change.
78
-
79
- ![v3 against v2 on every evaluation set](assets/02-v2-vs-v3.png)
80
-
81
- | Evaluation set | Documents | Kavach v2 | Kavach v3 | Change |
82
  |---|---|---|---|---|
83
- | v2 test documents, original v2 gold | 3,347 | **89.1** | 84.7 | -4.4 |
84
- | same documents, repaired gold, only values the old gold also had | 3,347 | 90.6 | **92.2** | +1.6 |
85
- | same documents, repaired v3 gold | 3,347 | 84.3 | **91.4** | +7.1 |
86
- | new v3 test documents only | 1,230 | 72.7 | **92.8** | +20.1 |
87
- | full v3 test | 4,577 | 79.1 | **92.1** | +13.0 |
88
- | hard cases, second-reader checked gold | 435 | 50.4 | **83.7** | +33.3 |
89
- | production probe, built by code | 480 | 72.3 | **90.4** | +18.1 |
90
- | simulated ASR rewrites | 289 | 87.0 | **89.5** | +2.5 |
91
- | real render-to-Tesseract OCR | 250 | 80.4 | **84.5** | +4.1 |
92
- | PII embedded in real Wikipedia text | 300 | 79.4 | **83.9** | +4.5 |
93
-
94
- Reading it from the top:
95
-
96
- * **v2's card reported 88.4 on its own test set, and that gold was missing roughly one value in ten.** Re-annotating the 65,000 v2 documents found the gaps, mostly names in form fields and signature lines, repeated and partial mentions, and organisation names. Against the repaired gold, v2 scores 84.3 on its own test documents and v3 scores 91.4.
97
- * **The first row is the one to read carefully.** On the original v2 gold, v3 scores lower than v2. Its recall there is higher than v2's (90.8 against 88.7), but its precision is 79.4, because it finds 3,181 values the old gold does not contain. 1,982 of them (62%) are in the repaired gold with the same label, and most of the rest are values whose rules changed in v3 (see [Migrating from v2](#migrating-from-v2)).
98
- * **The second row is the like-for-like number.** It keeps only the values the old gold also had, so neither model is rewarded or penalised for the new rules. v3 is 1.6 points ahead there.
99
- * **The new test documents** come from the same generator as 17,942 of v3's training documents, a style v2 never saw, so part of the 20-point gap there is familiarity. The production probe is the check against that: it was built by code, not by a language model, and v3 leads by 18 points on it.
100
- * **The hard cases** are the error types v2 was worst at, written deliberately (see [Hard cases](#hard-cases)).
101
-
102
- What went into the new training data:
103
-
104
- | | Documents |
105
- |---|---|
106
- | Dense records with 15 to 40 values: bank statements, CSV exports, logs, KYC forms, claims | 5,795 |
107
- | Long documents of 200 to 500 words: email threads, transcripts, reports | 3,104 |
108
- | Rare labels in natural context | 2,223 |
109
- | Weak languages: Indic scripts, romanised and code-mixed text | 3,028 |
110
- | Hard negatives: few or no values among non-personal look-alikes | 2,354 |
111
- | Noisy values: typos, OCR confusions, look-alike letters, zero-width characters | 1,438 |
112
- | Hard cases, one per error type v2 made most often (see below) | 5,492 |
113
 
114
- See [Dataset](#dataset) for how the labels were checked.
115
 
116
- ## Migrating from v2
117
-
118
- v3 is a drop-in replacement with one breaking change: **the label list is shorter**. v3 was trained with 43 labels, and the label list is part of the prompt, so code that still sends the v2 list of 52 is sending a prompt the model never saw. Replace `LABELS` with the list in the Quick start below. Nothing else in the prompt changed.
119
-
120
- Eleven v2 labels were folded into broader ones, and two new ones (`BANK_CODE`, `PAYMENT_ID`) take their place. Most of the folded labels were identifier types that cannot be told apart without a cue word: a bare 12-digit number can be an Aadhaar, a tax ID or an account number, v2 lost points guessing between them, and a redaction pipeline treats them all the same way. `SIGNATURE` was usually the same string as the person's name, which value-only output cannot separate, and `POSTAL_CODE` was v2's weakest label at 33.8 F1.
121
-
122
- | v2 label | v3 label |
123
- |---|---|
124
- | `SSN_US`, `AADHAAR_IN`, `PAN_IN`, `TAX_ID` | `NATIONAL_ID` |
125
- | `IBAN` | `BANK_ACCOUNT` |
126
- | `SWIFT_BIC`, `ROUTING_CODE` | `BANK_CODE` |
127
- | `UPI_VPA`, `WALLET_ID` | `PAYMENT_ID` |
128
- | `POSTAL_CODE` | `ADDRESS` (a standalone postcode is still tagged) |
129
- | `SIGNATURE` | `PERSON` |
130
-
131
- What gets tagged also changed in a few places, so a v3 output is not always a relabelled v2 output:
132
-
133
- * **Specific dates only.** `DATE_TIME` needs a day of the month, a year or a clock time. "Yesterday", "last Tuesday" and "March" on their own are no longer tagged, and neither are log timestamps, build dates, public-event dates or business hours.
134
- * **Places are not addresses.** A city, state or country on its own is not an `ADDRESS`, and neither is an organisation's public address in a letterhead or footer.
135
- * **Public contacts are not personal data.** Toll-free helplines and generic mailboxes (`support@`, `info@`, `noreply@`) are not tagged. A named person's direct line and email still are.
136
- * **Realistic values inside code, logs and JSON are tagged**, because customer data pasted into a stack trace is still customer data. Obvious placeholders (`test@example.com`, `555-0100`, `John Doe`, `123-45-6789`) are not.
137
- * **Honorifics and cue words stay outside the value**, in every script: `Mr Rao`, `Rao sir`, `Yamada-san` and `गवळी सर` all tag the name alone, and `MRN 77123` tags `77123`.
138
-
139
- If you ran v2 with `max_new_tokens=768`, raise it to 1024. v3 was trained on dense records (bank statements, CSV exports, KYC forms) whose answer can run past 768 tokens.
140
 
141
  ## Quick start
142
 
143
  ```python
144
- import json
145
  from transformers import AutoTokenizer, AutoModelForCausalLM
146
 
147
- MODEL = "inboxpraveen/Kavach-PII-270M"
148
  tok = AutoTokenizer.from_pretrained(MODEL)
149
  model = AutoModelForCausalLM.from_pretrained(MODEL, dtype="bfloat16").to("cuda").eval()
150
 
151
- LABELS = ["ADDRESS","AGE","API_KEY_TOKEN","BANK_ACCOUNT","BANK_CODE","BIOMETRIC_DESCRIPTOR","CARD_CVV","CARD_EXPIRY",
152
- "CASE_ID","CREDIT_DEBIT_CARD","DATE_TIME","DEVICE_ID","DISABILITY","DOB","DRIVING_LICENSE","EMAIL","EMPLOYEE_ID",
153
- "ETHNICITY","GENDER_SEX","GEO_LOCATION","HEALTH_ID","INSURANCE_ID","IP_ADDRESS","LAB_ORDER_ID","LICENSE_PLATE",
154
- "MAC_ADDRESS","MEDICAL_RECORD_ID","NATIONAL_ID","ORGANIZATION","PASSPORT","PASSWORD_SECRET","PAYMENT_ID","PERSON",
155
- "PHONE","POLITICAL_BELIEF","PRESCRIPTION_ID","RELIGION","STUDENT_ID","TRANSACTION_ID","URL_PERSONAL","USERNAME","VIN",
156
- "VOTER_ID"]
157
 
158
  INSTRUCTION = (
159
  "Extract all personal data (PII/PHI/PCI) from the text.\n"
@@ -168,21 +100,15 @@ def extract(text):
168
  msgs = [{"role": "user", "content": f"{INSTRUCTION}\n\nText:\n<<<\n{text}\n>>>"}]
169
  prompt = tok.apply_chat_template(msgs, tokenize=False, add_generation_prompt=True)
170
  ids = tok(prompt, return_tensors="pt", add_special_tokens=False).to(model.device)
171
- out = model.generate(**ids, max_new_tokens=1024, do_sample=False)
172
  raw = tok.decode(out[0][ids["input_ids"].shape[1]:], skip_special_tokens=True)
173
  return json.loads(raw[raw.find("["): raw.rfind("]") + 1])
174
 
175
- print(extract("Hi, this is Derek Okafor from Meridian Bank, my number is +1-617-555-0142."))
 
176
  # [{"label": "PERSON", "text": "Derek Okafor"},
177
  # {"label": "ORGANIZATION", "text": "Meridian Bank"},
178
  # {"label": "PHONE", "text": "+1-617-555-0142"}]
179
-
180
- print(extract("Please call our helpline 1800-266-1234 or write to support@meridianbank.com. "
181
- "Your case CK-80691 is with Priya Nair, priya.nair@gmail.com."))
182
- # [{"label": "CASE_ID", "text": "CK-80691"},
183
- # {"label": "PERSON", "text": "Priya Nair"},
184
- # {"label": "EMAIL", "text": "priya.nair@gmail.com"}]
185
- # The helpline and the support mailbox are public contacts, not personal data.
186
  ```
187
 
188
  ## Serving
@@ -194,7 +120,7 @@ All three servers below expose an OpenAI-compatible `/v1/chat/completions` endpo
194
  ```bash
195
  pip install vllm
196
 
197
- vllm serve inboxpraveen/Kavach-PII-270M \
198
  --dtype bfloat16 \
199
  --max-model-len 4096 \
200
  --port 8000
@@ -205,7 +131,7 @@ To serve the LoRA adapter on top of the stock base model instead of the merged w
205
  ```bash
206
  vllm serve google/gemma-3-270m-it \
207
  --enable-lora \
208
- --lora-modules kavach=inboxpraveen/Kavach-PII-270M/adapter \
209
  --dtype bfloat16 --max-model-len 4096 --port 8000
210
  ```
211
 
@@ -215,7 +141,7 @@ vllm serve google/gemma-3-270m-it \
215
  pip install "sglang[all]"
216
 
217
  python -m sglang.launch_server \
218
- --model-path inboxpraveen/Kavach-PII-270M \
219
  --dtype bfloat16 \
220
  --context-length 4096 \
221
  --port 30000
@@ -231,19 +157,19 @@ client = OpenAI(base_url="http://127.0.0.1:8000/v1", api_key="EMPTY") # 30000
231
 
232
  def extract(text):
233
  r = client.chat.completions.create(
234
- model="inboxpraveen/Kavach-PII-270M",
235
  messages=[{"role": "user", "content": f"{INSTRUCTION}\n\nText:\n<<<\n{text}\n>>>"}],
236
- temperature=0, max_tokens=1024,
237
  )
238
  raw = r.choices[0].message.content
239
  return json.loads(raw[raw.find("["): raw.rfind("]") + 1])
240
  ```
241
 
242
- Batching is worth setting up. Documents are independent, most answers are short (the median test answer is 88 tokens), and both servers handle concurrent requests well. The accuracy figures in this card were produced with the `transformers` path and with llama.cpp; vLLM and SGLang use the same weights and the same greedy decoding, so results should match, but they were not separately benchmarked.
243
 
244
  ### llama.cpp, Ollama, LM Studio
245
 
246
- See [Kavach-PII-270M-GGUF](https://huggingface.co/inboxpraveen/Kavach-PII-270M-GGUF) for quantised builds down to 169 MB.
247
 
248
  ## Long inputs, transcripts and character offsets
249
 
@@ -265,45 +191,47 @@ print(result["unlocatable"]) # values the model invented; sh
265
  print(result["warnings"]) # empty list means a clean run
266
  ```
267
 
268
- It is written to survive real input: `None`, bytes, a number, an empty string, a model call that raises, and output that is not valid JSON are all handled and reported in `result["warnings"]` rather than raised. Running the file directly (`python kavach_extract.py`) runs its self-test, which needs no GPU and no model. Both back-ends are tested end to end on v3: `transformers` locally and `openai_generate` against a live `llama-server`.
269
 
270
- ### Window size
271
 
272
- The defaults below are measured, not reasoned about. v3 saw longer documents in training than v2 did (a median of 49 words against 39, and 3,265 training documents over 200 words), and it shows: window size matters less than it did for v2, but past a certain length it still matters.
273
 
274
- **On a coherent document, window size barely matters.** These are 92 real test documents of 180 to 385 words, scored against their own gold:
 
 
275
 
276
  | | Precision | Recall | Value F1 |
277
  | --- | --- | --- | --- |
278
- | Whole document, one call | 0.893 | 0.895 | 0.894 |
279
- | Windowed 250 / 40 | 0.875 | 0.911 | 0.893 |
280
- | Windowed 180 / 35 | 0.873 | 0.923 | **0.897** |
281
- | Windowed 150 / 30 | 0.874 | 0.920 | 0.896 |
282
- | Windowed 120 / 25 | 0.869 | 0.926 | 0.896 |
283
- | Windowed 100 / 20 | 0.866 | 0.920 | 0.892 |
284
- | Windowed 50 / 12 | 0.858 | 0.926 | 0.891 |
285
 
286
- Every setting lands between 0.891 and 0.897. Smaller windows trade a little precision for recall, because the model needs the surrounding sentence to tell a date of birth from an appointment date, or a patient from a clinician, and a small window takes some of that away. At 50 words v2 lost 13 points of precision; v3 loses 3.5.
287
 
288
- **On text that runs past a few hundred words, recall falls away.** These are eight documents of 670 to 760 words, each built by stitching unrelated test documents together, which is the harder case:
289
 
290
  | Window / overlap | Precision | Recall | Value F1 | Model calls |
291
  | --- | --- | --- | --- | --- |
292
- | 30 / 8 | 0.866 | 0.886 | 0.876 | 261 |
293
- | 50 / 12 | 0.893 | 0.896 | 0.894 | 150 |
294
- | 100 / 20 | 0.906 | 0.915 | **0.911** | 73 |
295
- | 120 / 25 | 0.902 | 0.906 | 0.904 | 61 |
296
- | 150 / 30 | 0.895 | 0.904 | 0.899 | 49 |
297
- | 180 / 35 | 0.897 | 0.869 | 0.883 | 42 |
298
- | 200 / 40 | 0.883 | 0.842 | 0.862 | 38 |
299
- | 250 / 40 | 0.877 | 0.773 | 0.822 | 32 |
300
- | 400 / 80 | 0.879 | 0.642 | 0.742 | 19 |
301
 
302
- Precision holds up to 400 words; recall does not. A single answer stops short of listing everything in a long, dense input, so one 400-word window finds only 64% of the values. Sending each source document on its own scores 0.901, which is the ceiling any windowing scheme is working towards; the rows from 100 to 150 words reach it or come within 0.002 (the small excess above it is noise on eight documents). v3 degrades more gently than v2 (0.742 against 0.635 at 400 words), but the shape is the same.
303
 
304
- **The default is 120 words with 25 of overlap**, near the top of both tables; 100 to 150 behaves about the same. Do not go past about 180 words, where recall starts to fall. Keep the overlap at 20 or more, or a long address can straddle an edge and be seen whole by neither window. If your input is always coherent prose rather than concatenated records, the choice barely matters.
305
 
306
- These runs used the F16 GGUF build through `llama-server`. On the coherent set, the `transformers` path gave the same scores to within 0.002.
307
 
308
  A document shorter than the window is sent in one call untouched, so ordinary short inputs never pay the windowing cost at all.
309
 
@@ -311,7 +239,7 @@ One note on throughput: `extract_pii` batches the windows of a single document t
311
 
312
  ### Speech-to-text input
313
 
314
- Transcripts work as they come out of the recogniser. Bracketed timestamps (`[00:01:02]`), SRT ranges (`00:00:03,500 --> 00:00:07,120`), WebVTT cues and plain `Speaker 1:` turns pass through untouched, and the timestamps survive redaction. This is not special-case code: 1,068 training documents contain bracketed timestamps and only one of them tags any, so the model learned to ignore them. Measured on v3 with the 30 longest timestamped test documents: none of their 419 timestamps was tagged as personal data, all 419 survived redaction intact, and every returned offset indexed the original string exactly. Where the transcript has line breaks, window edges prefer to land on one, so a speaker turn stays whole; a transcript that arrives as one unbroken line is cut on word boundaries instead.
315
 
316
  ```
317
  [00:00:03] Speaker 1: Hello, this is [PERSON] from [ORGANIZATION].
@@ -320,19 +248,17 @@ Transcripts work as they come out of the recogniser. Bracketed timestamps (`[00:
320
 
321
  ### Locating values correctly
322
 
323
- Matching is stricter than a plain substring search, which matters more than it sounds. A naive `re.escape` locator places values inside longer words: `Raj` lands in the middle of `Rajesh`, `2024` inside `20245`, and redaction then emits `[PERSON]esh`. `extract_pii` requires a whole-word match, with the boundary rule switched off for Chinese, Japanese, Thai, Khmer, Burmese and Korean, where words are not space-separated or particles attach directly to the noun. Indic and Arabic combining marks count as part of the word, which is the bug that a plain `\b` has against Devanagari.
324
 
325
  Where a value occurs nowhere as a whole word, usually because the recogniser ran two words together, the span is still produced and flagged `"partial": True`, on the grounds that a mask starting mid-word beats leaving a real address in the clear. Drop those spans if you would rather under-mask.
326
 
327
- On the 4,577-document test set:
328
 
329
- | Outcome | Share of 28,712 predicted values |
330
  | --- | --- |
331
- | Located as a whole word | 98.79% |
332
- | Located only inside a longer run, flagged `partial` | 0.41% |
333
- | Not present in the text at all (hallucination) | 0.79% |
334
-
335
- On the same test set, 1.8% of v2's predicted values could not be found in the text.
336
 
337
  <details>
338
  <summary>Full source of <code>kavach_extract.py</code></summary>
@@ -357,22 +283,22 @@ What it handles
357
  WebVTT cues and plain 'Speaker 1:' turns. Where the transcript has line breaks, windows prefer to cut on
358
  one, so a speaker turn or a subtitle cue stays whole; a transcript that arrives as a single unbroken line
359
  is simply cut on word boundaries. Timestamps are never treated as personal data, because the model was
360
- trained that way: 1,068 training documents contain bracketed timestamps and only one tags them.
361
  * Values repeated across the document. A name found once is masked at every occurrence.
362
  * Bad input: None, bytes, numbers, empty or whitespace-only strings, and model calls that fail or return
363
  something that is not JSON. Nothing raises; problems are reported in result["warnings"].
364
 
365
  Window defaults are measured, not guessed, and they are a compromise between two opposite failures.
366
 
367
- Too small and precision goes: on 92 real test documents of 180-385 words, a 50-word window scores 0.858
368
- precision against 0.893 for the same documents sent whole, because the model needs the surrounding sentence to
369
  tell a date of birth from an appointment date. Too large and recall goes: on 660-word inputs, recall falls from
370
- 0.92 at a 100-word window to 0.64 at 400, because a single answer stops short of listing everything in a long,
371
- dense input.
372
 
373
  120 words with 25 of overlap is near the top of both curves; 100 to 150 behaves about the same. Do not drop
374
- below about 60, and do not go past about 180. Keep the overlap at 20 or more, or a long address can straddle an
375
- edge and be seen whole by neither window. A document shorter than the window is sent in one call untouched.
376
  """
377
 
378
  from __future__ import annotations
@@ -384,12 +310,14 @@ import unicodedata
384
  __all__ = ["extract_pii", "redact", "LABELS", "INSTRUCTION", "build_prompt"]
385
 
386
  LABELS = [
387
- "ADDRESS", "AGE", "API_KEY_TOKEN", "BANK_ACCOUNT", "BANK_CODE", "BIOMETRIC_DESCRIPTOR", "CARD_CVV",
388
- "CARD_EXPIRY", "CASE_ID", "CREDIT_DEBIT_CARD", "DATE_TIME", "DEVICE_ID", "DISABILITY", "DOB", "DRIVING_LICENSE",
389
- "EMAIL", "EMPLOYEE_ID", "ETHNICITY", "GENDER_SEX", "GEO_LOCATION", "HEALTH_ID", "INSURANCE_ID", "IP_ADDRESS",
390
- "LAB_ORDER_ID", "LICENSE_PLATE", "MAC_ADDRESS", "MEDICAL_RECORD_ID", "NATIONAL_ID", "ORGANIZATION", "PASSPORT",
391
- "PASSWORD_SECRET", "PAYMENT_ID", "PERSON", "PHONE", "POLITICAL_BELIEF", "PRESCRIPTION_ID", "RELIGION",
392
- "STUDENT_ID", "TRANSACTION_ID", "URL_PERSONAL", "USERNAME", "VIN", "VOTER_ID",
 
 
393
  ]
394
 
395
  INSTRUCTION = (
@@ -638,7 +566,7 @@ def extract_pii(
638
  with 20-30 of overlap all behave about the same, and both smaller and larger settings are worse, for
639
  different reasons. Text shorter than one window is sent in a single call.
640
  labels
641
- Restrict to a subset of the 43 labels, for example {"PERSON", "PHONE"}. Default: all.
642
  lenient
643
  Also match values case-insensitively when locating them. Slightly higher recall, slightly higher risk
644
  of matching the wrong occurrence.
@@ -654,7 +582,7 @@ def extract_pii(
654
  dict with keys
655
  spans list of {"start", "end", "label", "text"}, sorted, non-overlapping, offsets into the
656
  original string you passed in. A span also carries "partial": True when the value only
657
- occurred inside a longer run of text, which is rare (0.4% of predictions on the test set)
658
  and usually means speech-to-text ran two words together. Drop those if you would rather
659
  under-mask than mask across a word edge.
660
  entities list of unique {"label", "text"} in order of first appearance
@@ -770,7 +698,7 @@ def redact(text, spans, mask="[{label}]") -> str:
770
  # --------------------------------------------------------------------------------------------------
771
  # generate() adapters. Pick one.
772
 
773
- def transformers_generate(model, tokenizer, max_new_tokens=1024, batch_size=8):
774
  """generate() backed by a local transformers model."""
775
  import torch
776
 
@@ -794,8 +722,8 @@ def transformers_generate(model, tokenizer, max_new_tokens=1024, batch_size=8):
794
  return run
795
 
796
 
797
- def openai_generate(base_url="http://127.0.0.1:8000/v1", model="inboxpraveen/Kavach-PII-270M",
798
- api_key="EMPTY", max_tokens=1024, workers=4):
799
  """generate() backed by any OpenAI-compatible server: vLLM, SGLang or llama-server."""
800
  from concurrent.futures import ThreadPoolExecutor
801
  from openai import OpenAI
@@ -938,196 +866,110 @@ if __name__ == "__main__":
938
 
939
  ## Prompt guidance
940
 
941
- * Use the instruction above verbatim, with the 43-label list. The model was trained on exactly this text, and paraphrasing it costs accuracy.
942
  * Use greedy decoding (`do_sample=False`, or `temperature: 0`). Sampling adds nothing on an extraction task and breaks JSON validity.
943
- * Allow 1024 new tokens, or `48 + 1.6 * input_tokens` capped at 1024. Most answers are short (the median test answer is 88 tokens), but a dense bank statement or CSV export can need more than 800: 19 of the 480 production-probe answers are longer than 768 tokens.
944
- * Retry unparseable outputs once with `repetition_penalty=1.1`. Small models occasionally fall into a repetition loop. On v3's evaluation sets, re-decoding only the failures recovered 102 of 108. Do not apply the penalty to every request: on v2 that lowered F1 by 1.4 points.
945
- * Normalise case first if your input may contain random mixed capitalisation (`jOhN sMiTh`). It still costs 8.5 F1 and makes the model flag far more documents that contain no personal data. See [Limitations](#limitations).
946
- * Send one document per call, and window anything long. `kavach_extract.py` above does the windowing for you.
947
 
948
  ## Results
949
 
950
- ### Hard cases
951
-
952
- v2's errors fell into nine recurring types. For each, v3's training set has hundreds of documents built around it, and a separate gold set of 435 documents (15 per language, about 16 values each) measures it. The gold documents were written by different writers from the training documents, drew their values from separate pools, and were each re-read by a second LLM reader, grouped differently from the writers, who confirmed 99.8% of the 6,837 labels. Each document also carries planted non-personal look-alikes: helplines, head-office addresses, SKUs, version strings and public dates.
953
-
954
- ![Hard cases by failure type](assets/06-hard-cases.png)
955
-
956
- | Failure type | Docs | Gold values | Kavach v3 | Kavach v2 | GLiNER | Presidio |
957
- |---|---|---|---|---|---|---|
958
- | Which identifier is which (several IDs, told apart by cue words) | 45 | 771 | **90.0** | 48.7 | 43.0 | 15.8 |
959
- | Partial and masked values (`card ending 4532`, `XXXX-XX-1234`) | 46 | 591 | **89.0** | 59.4 | 40.9 | 13.8 |
960
- | Organisations and public contacts (tag the firm, not its helpline) | 43 | 565 | **87.2** | 54.5 | 44.2 | 25.3 |
961
- | Technical text (logs, stack traces, JSON, SQL, configs) | 44 | 600 | **86.9** | 65.2 | 48.4 | 27.4 |
962
- | Dense structured records (6 to 12 transaction lines) | 43 | 1,533 | **85.9** | 34.1 | 36.6 | 30.4 |
963
- | Sensitive attributes and dates | 45 | 716 | **82.7** | 51.5 | 50.5 | 14.2 |
964
- | Words glued to values (case endings, particles, postpositions) | 46 | 631 | **78.5** | 51.6 | 34.9 | 16.4 |
965
- | Spoken values in transcripts (numbers read aloud, with corrections) | 47 | 704 | **75.9** | 49.3 | 38.1 | 10.9 |
966
- | Name variants (a full name, then a nickname or surname alone) | 47 | 737 | **75.3** | 58.5 | 45.3 | 21.3 |
967
-
968
- | | Kavach v3 | Kavach v2 | GLiNER | Presidio | Regex + checksum |
969
- |---|---|---|---|---|---|
970
- | **Value F1, all 435 documents** | **83.5** | 50.2 | 41.5 | 20.0 | 18.6 |
971
- | Redaction recall | **91.0** | 59.8 | 42.1 | 36.8 | 21.0 |
972
- | **Planted look-alikes tagged (of 2,213)** | **164** | 290 | 477 | 681 | 344 |
973
- | Predicted values not in the text | **2.7%** | 7.1% | n/a | n/a | n/a |
974
-
975
- Dense records went from v2's worst case (34.1) to 85.9. Name variants and spoken values are now the weakest, both in the mid-70s. One caveat belongs next to these numbers: the gold was written by the same kind of process that wrote the hard-case training documents, with different writers and value pools. The production probe below is the independent check.
976
-
977
- ### Production probe
978
-
979
- 480 documents in eight real-world formats, 60 per format, in English, Hindi, Tamil, Arabic, Spanish and German. No language model wrote any of it. A script builds each document and records every personal value it inserts, so the gold is complete by construction, and each document also carries planted look-alikes that must not be tagged: helplines, head-office addresses, app versions, opening hours.
980
-
981
- | Format | Gold values | Kavach v3 | Kavach v2 | GLiNER | Presidio |
982
- |---|---|---|---|---|---|
983
- | Insurance claim form | 797 | **99.1** | 84.6 | 74.5 | 42.1 |
984
- | KYC form | 660 | **98.6** | 84.2 | 94.4 | 27.6 |
985
- | Email thread | 660 | **97.6** | 92.4 | 71.5 | 42.1 |
986
- | Discharge summary | 660 | **95.8** | 69.0 | 58.2 | 42.5 |
987
- | Call transcript | 420 | 93.1 | **98.1** | 61.0 | 38.3 |
988
- | Access log | 1,248 | **88.0** | 66.4 | 79.3 | 27.3 |
989
- | CSV export | 2,465 | **86.7** | 63.2 | 57.2 | 39.3 |
990
- | Bank statement | 1,014 | **82.6** | 58.2 | 15.5 | 29.7 |
991
- | **All formats** | 7,924 | **90.4** | 72.2 | 62.7 | 35.6 |
992
-
993
- v3 tagged none of the 180 planted look-alikes; v2 tagged 48, GLiNER 178 and Presidio all 180. Redaction recall is 96.3.
994
-
995
- Two things in this table need explaining. The bank statement and CSV scores are held down by the probe's own gold: the script that built it predates v3's labelling rules and does not record transaction dates on a statement or customer IDs in a CSV export, both of which v3 tags as personal (a transaction date on someone's statement is part of their record). Those two account for 912 of v3's 1,081 unmatched predictions. The gold was fixed before v3 was trained and has not been changed. The call transcript row is a real regression: when a customer reads out an 8-digit account number straight after their phone number, v3 labels it `PHONE` in 13 of the 60 transcripts. The value is still found and masked; only its type is wrong.
996
-
997
  ### By input condition
998
 
999
- ![Value-F1 by input condition: v3 against v2, GLiNER and Presidio](assets/03-conditions-radar.png)
1000
 
1001
- | Condition | Test docs | Kavach v3 | Kavach v2 | GLiNER | Presidio |
1002
- |---|---|---|---|---|---|
1003
- | Masked or partial values | 161 | **95.6** | 86.9 | 55.7 | 16.3 |
1004
- | Structured forms | 238 | **94.0** | 85.0 | 70.4 | 30.2 |
1005
- | Dialogue transcripts | 265 | **93.8** | 90.1 | 60.1 | 22.2 |
1006
- | Clean text | 1,374 | **93.2** | 85.8 | 61.9 | 26.6 |
1007
- | OCR output | 74 | **93.0** | 83.5 | 71.9 | 31.9 |
1008
- | Code and logs | 115 | **91.5** | 81.1 | 51.4 | 24.7 |
1009
- | ASR transcripts | 688 | **86.9** | 79.8 | 49.6 | 17.3 |
1010
- | Adversarial formatting | 245 | **85.4** | 79.5 | 55.6 | 16.7 |
 
 
1011
 
1012
- These are the 3,347 test documents that carry a condition tag (the documents inherited from v2's test set); the 1,230 new test documents are not tagged by condition. v3 is ahead of v2 in all eight conditions. The largest gains are on code and logs (+10.4), OCR output (+9.5), structured forms (+9.0) and masked values (+8.7); the smallest is on dialogue transcripts (+3.7), where v2 was already strong. The weakest condition for v3 (adversarial formatting, 85.4) is above the strongest condition for GLiNER (OCR, 71.9).
1013
 
1014
  ### By language
1015
 
1016
- Every language group has at least 85 held-out test documents, so each figure carries a 95% confidence interval between 2 and 8 points wide. v3 is ahead of v2 in all 29, and ahead of GLiNER in all 29.
1017
 
1018
- ![Per-language comparison](assets/04-languages.png)
1019
 
1020
- | Language | Test docs | Kavach v3 F1 | 95% CI | Kavach v2 | GLiNER |
1021
  |---|---|---|---|---|---|
1022
- | Dutch | 90 | **96.4** | 94.3 to 98.3 | 84.7 | 76.6 |
1023
- | Multilingual mix (3 or more) | 120 | **96.0** | 94.8 to 97.1 | 86.3 | 72.9 |
1024
- | Romanized Indian language | 118 | **94.9** | 93.1 to 96.6 | 87.3 | 72.3 |
1025
- | Simplified Chinese | 100 | **94.6** | 92.7 to 96.2 | 84.0 | 57.3 |
1026
- | Indonesian | 96 | **93.8** | 91.7 to 95.7 | 82.2 | 73.8 |
1027
- | Japanese | 91 | **93.6** | 91.4 to 95.7 | 86.5 | 47.2 |
1028
- | Turkish | 96 | **93.1** | 91.2 to 94.9 | 83.4 | 66.3 |
1029
- | Hindi | 141 | **92.9** | 90.8 to 94.8 | 81.0 | 38.1 |
1030
- | English | 1,238 | **92.8** | 91.9 to 93.6 | 81.4 | 64.9 |
1031
- | Russian | 96 | **92.3** | 89.9 to 94.8 | 80.8 | 63.8 |
1032
- | Telugu | 174 | **92.3** | 90.7 to 93.8 | 70.9 | 38.1 |
1033
- | Korean | 106 | **92.2** | 90.1 to 94.3 | 81.1 | 57.7 |
1034
- | Arabic | 173 | **91.7** | 89.7 to 93.6 | 75.5 | 71.4 |
1035
- | Vietnamese | 97 | **91.7** | 89.1 to 93.9 | 80.1 | 68.0 |
1036
- | Punjabi | 118 | **91.6** | 89.4 to 93.7 | 78.5 | 42.5 |
1037
- | Portuguese | 95 | **91.5** | 88.8 to 93.6 | 80.7 | 67.8 |
1038
- | Spanish | 125 | **91.4** | 89.3 to 93.3 | 81.6 | 71.8 |
1039
- | Polish | 98 | **91.3** | 88.8 to 93.8 | 82.1 | 73.3 |
1040
- | Kannada | 156 | **91.2** | 89.1 to 93.1 | 72.7 | 43.8 |
1041
- | German | 107 | **91.1** | 88.5 to 93.4 | 82.8 | 67.6 |
1042
- | Urdu | 107 | **90.7** | 88.3 to 93.1 | 77.2 | 70.4 |
1043
- | Marathi | 118 | **90.6** | 88.2 to 92.9 | 77.9 | 38.8 |
1044
- | Malayalam | 156 | **90.6** | 88.5 to 92.4 | 70.3 | 41.1 |
1045
- | French | 98 | **90.5** | 87.6 to 93.1 | 77.9 | 61.1 |
1046
- | Chinese | 85 | **90.2** | 85.5 to 93.8 | 81.8 | 37.6 |
1047
- | Bengali | 169 | **90.1** | 88.0 to 92.1 | 72.3 | 42.9 |
1048
- | Tamil | 194 | **89.9** | 87.6 to 91.7 | 71.7 | 35.8 |
1049
- | Gujarati | 112 | **89.9** | 87.3 to 92.5 | 76.8 | 42.3 |
1050
- | Italian | 103 | **87.4** | 84.1 to 90.6 | 77.5 | 67.9 |
1051
-
1052
- Languages are covered in native script, romanised form, and code-switched with English. The largest gains are in the Dravidian and Indo-Aryan languages that were v2's weakest: Kannada went from 72.7 to 91.2, Malayalam from 70.3 to 90.6, Telugu from 70.9 to 92.3. The spread across all 29 languages is now under 10 points, against 17 for v2.
1053
 
1054
  ### By label
1055
 
1056
- 43 labels are supported. The table lists those with at least 50 test instances.
1057
 
1058
- ![Per-label comparison](assets/05-labels.png)
1059
 
1060
- | Label | Test instances | Kavach v3 F1 | Kavach v2 F1 | GLiNER F1 |
1061
- |---|---|---|---|---|
1062
- | `PERSON` | 5,371 | **94.3** | 88.1 | 40.4 |
1063
- | `PHONE` | 3,678 | **95.4** | 91.7 | 75.3 |
1064
- | `ORGANIZATION` | 2,732 | **87.5** | 78.6 | 66.0 |
1065
- | `EMAIL` | 2,652 | **96.6** | 92.2 | 87.0 |
1066
- | `DOB` | 2,616 | **97.2** | 92.0 | 87.6 |
1067
- | `CASE_ID` | 2,031 | **88.3** | 52.4 | 23.9 |
1068
- | `DATE_TIME` | 2,014 | **84.6** | 15.6 | 54.7 |
1069
- | `ADDRESS` | 1,587 | **87.2** | 76.7 | 44.4 |
1070
- | `NATIONAL_ID` | 995 | **93.0** | 77.0 | 50.8 |
1071
- | `CREDIT_DEBIT_CARD` | 494 | **93.7** | 76.1 | 57.7 |
1072
- | `BANK_ACCOUNT` | 406 | **94.1** | 77.8 | 59.6 |
1073
- | `EMPLOYEE_ID` | 374 | **89.0** | 72.5 | 33.0 |
1074
- | `INSURANCE_ID` | 329 | **91.4** | 75.4 | 56.1 |
1075
- | `BANK_CODE` | 317 | **94.5** | 58.4 | 29.2 |
1076
- | `TRANSACTION_ID` | 310 | **86.0** | 47.3 | 42.8 |
1077
- | `CARD_EXPIRY` | 245 | **99.6** | 77.9 | 63.1 |
1078
- | `CARD_CVV` | 232 | **96.1** | 79.5 | 62.6 |
1079
- | `MEDICAL_RECORD_ID` | 204 | **85.9** | 71.3 | 45.0 |
1080
- | `AGE` | 200 | **95.2** | 44.0 | 71.2 |
1081
- | `USERNAME` | 179 | **88.0** | 75.2 | 53.1 |
1082
- | `LAB_ORDER_ID` | 173 | **92.1** | 71.7 | 65.8 |
1083
- | `PRESCRIPTION_ID` | 166 | **92.6** | 79.0 | 55.5 |
1084
- | `LICENSE_PLATE` | 158 | **89.4** | 63.0 | 40.3 |
1085
- | `PASSPORT` | 147 | **92.6** | 86.6 | 60.4 |
1086
- | `STUDENT_ID` | 132 | **89.8** | 79.1 | 62.5 |
1087
- | `DRIVING_LICENSE` | 116 | **83.6** | 71.9 | 34.9 |
1088
- | `GENDER_SEX` | 99 | **92.2** | 7.5 | 47.6 |
1089
- | `DEVICE_ID` | 80 | **84.8** | 69.0 | 37.6 |
1090
- | `HEALTH_ID` | 75 | **87.8** | 61.7 | 27.7 |
1091
- | `PASSWORD_SECRET` | 63 | **69.4** | 40.0 | 25.3 |
1092
- | `API_KEY_TOKEN` | 54 | **76.6** | 43.0 | 29.5 |
1093
- | `PAYMENT_ID` | 54 | **75.8** | 67.4 | 31.8 |
1094
-
1095
- Every label improved. The very low v2 figures for `DATE_TIME` and `GENDER_SEX` are mostly rule changes rather than v2 getting worse: v2 tagged vague dates such as "yesterday" and "Friday", which v3's gold does not count, and v2's training data rarely tagged gender at all.
1096
-
1097
- Labels with fewer than 50 test instances, whose figures are indicative only: `IP_ADDRESS` 92.2 (47), `VIN` 89.4 (47), `URL_PERSONAL` 86.0 (46), `RELIGION` 87.1 (42), `VOTER_ID` 88.2 (37), `DISABILITY` 62.2 (36), `BIOMETRIC_DESCRIPTOR` 79.3 (32), `ETHNICITY` 74.1 (29), `POLITICAL_BELIEF` 81.4 (29), `MAC_ADDRESS` 89.4 (23), `GEO_LOCATION` 92.3 (19).
1098
-
1099
- Full label set, 43 in total:
1100
-
1101
- `ADDRESS` `AGE` `API_KEY_TOKEN` `BANK_ACCOUNT` `BANK_CODE` `BIOMETRIC_DESCRIPTOR` `CARD_CVV` `CARD_EXPIRY` `CASE_ID` `CREDIT_DEBIT_CARD` `DATE_TIME` `DEVICE_ID` `DISABILITY` `DOB` `DRIVING_LICENSE` `EMAIL` `EMPLOYEE_ID` `ETHNICITY` `GENDER_SEX` `GEO_LOCATION` `HEALTH_ID` `INSURANCE_ID` `IP_ADDRESS` `LAB_ORDER_ID` `LICENSE_PLATE` `MAC_ADDRESS` `MEDICAL_RECORD_ID` `NATIONAL_ID` `ORGANIZATION` `PASSPORT` `PASSWORD_SECRET` `PAYMENT_ID` `PERSON` `PHONE` `POLITICAL_BELIEF` `PRESCRIPTION_ID` `RELIGION` `STUDENT_ID` `TRANSACTION_ID` `URL_PERSONAL` `USERNAME` `VIN` `VOTER_ID`
1102
 
1103
  ### Robustness
1104
 
1105
- Eighteen offset-safe corruptions applied to 300 held-out dev documents, each measured against the model's own clean baseline of 92.8.
1106
-
1107
- ![Robustness under corruption](assets/07-robustness.png)
1108
-
1109
- | Corruption | v3 change | v2 change |
1110
- |---|---|---|
1111
- | Random mixed capitalisation | -8.5 | -15.6 |
1112
- | All uppercase | -3.8 | -4.7 |
1113
- | Keyboard typos | -3.1 | -8.5 |
1114
- | Punctuation stripped | -1.8 | -3.2 |
1115
- | All lowercase | -1.4 | -3.3 |
1116
- | Whitespace noise | -1.3 | -0.6 |
1117
- | Zero-width characters injected | -1.0 | -1.0 |
1118
- | Homoglyph substitution | -0.9 | -1.1 |
1119
- | Words dropped | -0.8 | -1.2 |
1120
- | Values spaced out (`9 8 7 6`) | -0.6 | -1.3 |
1121
- | Full-width characters | -0.6 | -1.9 |
1122
- | JSON escaping | -0.5 | -0.4 |
1123
- | Prefix and suffix noise | -0.5 | -0.5 |
1124
- | Digits written as words | -0.4 | -1.1 |
1125
- | Mojibake | 0.0 | 0.0 |
1126
- | Separator changes | 0.0 | -0.3 |
1127
- | Markdown wrapping | +0.6 | -2.3 |
1128
- | HTML wrapping | +0.9 | +1.3 |
1129
-
1130
- Fourteen of the eighteen cost under 1.5 F1. Random capitalisation is still the worst case, but v3 loses about half what v2 did, and keyboard typos went from -8.5 to -3.1. The v2 column is from the v2 card, measured the same way on 300 of v2's own dev documents, so compare the size of each drop rather than the absolute scores.
1131
 
1132
  ## Compliance coverage
1133
 
@@ -1136,91 +978,77 @@ Mapped against the 18 HIPAA Safe Harbor identifiers, 16 of 18 have trained suppo
1136
  | HIPAA identifier | Label |
1137
  |---|---|
1138
  | Names | `PERSON` |
1139
- | Geography smaller than a state | `ADDRESS` (including standalone postcodes) |
1140
  | Dates, ages over 89 | `DOB`, `DATE_TIME`, `AGE` |
1141
  | Telephone and fax | `PHONE` |
1142
  | Email | `EMAIL` |
1143
- | Social Security numbers | `NATIONAL_ID` |
1144
  | Medical record numbers | `MEDICAL_RECORD_ID` |
1145
  | Health plan beneficiary numbers | `INSURANCE_ID`, `HEALTH_ID` |
1146
- | Account numbers | `BANK_ACCOUNT`, `CREDIT_DEBIT_CARD`, `PAYMENT_ID` |
1147
- | Certificate and licence numbers | `DRIVING_LICENSE`, `EMPLOYEE_ID` (NPI, DEA, professional registrations) |
1148
  | Vehicle identifiers | `VIN`, `LICENSE_PLATE` |
1149
- | Device identifiers | `DEVICE_ID`, `MAC_ADDRESS` |
1150
  | Web URLs | `URL_PERSONAL` |
1151
  | IP addresses | `IP_ADDRESS` |
1152
  | Biometric identifiers | `BIOMETRIC_DESCRIPTOR` |
1153
- | Any other unique identifying number | `CASE_ID`, `STUDENT_ID`, `TRANSACTION_ID`, and the rest of the ID family |
1154
 
1155
- Also covered: PCI (`CREDIT_DEBIT_CARD`, `CARD_EXPIRY`, `CARD_CVV`, `BANK_ACCOUNT` including IBAN, `BANK_CODE` for SWIFT/BIC, IFSC, ABA routing and sort codes), national identifiers of any country under `NATIONAL_ID` (SSN, Aadhaar, PAN, NIN, NRIC, CPF, DNI, Emirates ID, codice fiscale, Steuer-ID and others), UPI IDs and wallets under `PAYMENT_ID`, and US healthcare administration (NPI and DEA under `EMPLOYEE_ID`, Medicare MBI and Medicaid IDs under `HEALTH_ID`). GDPR special categories are covered by `RELIGION`, `ETHNICITY`, `POLITICAL_BELIEF`, `DISABILITY`, `GENDER_SEX` and `BIOMETRIC_DESCRIPTOR`, though test support for them is thin (see [Limitations](#limitations)).
1156
 
1157
  ## Training
1158
 
1159
  | | |
1160
  |---|---|
1161
  | Base model | `google/gemma-3-270m-it`, 268M parameters |
1162
- | Method | LoRA, r=64, alpha=128, dropout 0.05, on all attention and MLP projections (15.2M trainable, 5.4%), unchanged from v2 |
1163
  | Precision | base weights bf16 throughout, only the adapter was trained |
1164
- | Data | 81,337 training documents, 46.4M tokens (6 documents longer than 3,072 tokens left out) |
1165
- | Schedule | 3 epochs, 15,819 steps, lr 2e-4 with linear decay and 3% warmup, effective batch 16 |
1166
- | Augmentation | 18 offset-safe corruption operations applied on the fly at p=0.5 (v2: 0.35) |
1167
- | Hardware | one NVIDIA RTX 5060 Laptop GPU (8 GB), 6.2 hours, 2.61 GB peak |
1168
  | Loss | cross-entropy on the assistant JSON only, prompt tokens masked out |
1169
 
1170
- Best dev loss 0.0281, measured on 1,000 documents of the v3 dev set. It is not comparable with v2's 0.0397, which was measured on a different dev set with a different label list.
1171
 
1172
  ### Dataset
1173
 
1174
- About 91,700 documents and 593,000 labelled values across all splits, entirely synthetic. No real personal data was used.
1175
 
1176
  | Split | Documents | Values | PII-free |
1177
  |---|---|---|---|
1178
- | train | 81,343 | 523,028 | 7,506 |
1179
- | dev | 3,964 | 21,520 | 393 |
1180
- | test | 4,577 | 28,672 | 440 |
1181
- | hard cases (gold) | 435 | 6,862 | 29 |
1182
- | production probe (built by code) | 480 | 7,924 | 0 |
1183
- | simulated ASR / real OCR / real-text injection | 289 / 250 / 300 | 1,409 / 1,349 / 2,030 | 0 / 0 / 68 |
1184
-
1185
- The training set is the 57,909 v2 training documents, relabelled, plus 23,434 new ones. It spans 29 languages, 23 domains (contact centre, healthcare, pharmacy and labs, insurance, banking, government, telecom, e-commerce, education and HR, legal, IT helpdesk, logistics, real estate, automotive, travel and others), hard negatives and prompt-injection wrappers, and 12 input conditions. It keeps v2's real noise round trips (browser render into Tesseract OCR, an ASR simulator few-shot prompted on real Whisper output), PII embedded in real Wikipedia passages, and 600 hand-built negatives covering already-redacted text, blank forms, placeholder rows and medical billing code lists.
1186
 
1187
- **How the labels were checked.** The weakness v3 set out to fix was label quality as much as coverage, so most of the work went here:
1188
 
1189
- * **Re-annotation.** Every existing document, 65,000 of them, went back through LLM annotators that proposed additions, removals, relabels and boundary fixes against the existing gold. A stronger model, reasoning before it answered, verified every removal and relabel, and every boundary change that lengthened a value. Evaluation sets were audited twice more by independent models. A document-by-document review of a 500-document sample found the old gold had been missing roughly one value in ten.
1190
- * **Written rules, applied by code.** Honorifics and cue words outside the value in every script, sentence punctuation, time particles in Korean, Kannada and Tamil, place names that are not addresses, vague dates, fully masked values and placeholder values. Each rule logs every change it makes, and each was checked on a sample before it was applied to every split.
1191
- * **Measured per language.** 4,400 training documents (150 per language, 200 for English) were audited by a model that had not audited the training set before, with every correction verified: precision 98.9, recall 98.4, and no language below 97.9 precision or 97.1 recall. 870 training documents (30 per language, 7,665 labels) were then read one at a time by LLM reviewers working from the written annotation rules (not by people): precision 97.8, recall 97.1. The error types found there (missed name variants, boundaries, values that are not personal) were then fixed across the whole corpus by rule.
1192
- * **Hard-case documents were filtered, not trusted.** The 4,022 hard-case documents from a local generator passed a gate that removes placeholders, sequential and repeated-digit identifiers, copied example values, near duplicates and anything sharing an identifier with an evaluation split. Documents an automated auditor flagged as possibly missing values were set aside rather than trained on, because no automated judge could tell a real omission from a false alarm reliably. The same kind of document-by-document review, 20 documents per language, then excluded 10 languages that fell below 97 precision or 95 recall from that batch.
1193
- * **No leakage.** Splits are grouped by synthetic identity, so no generated person appears on both sides of a split. 564 test and 288 dev documents that shared an identifier with a training document were moved into training, exact duplicates were removed, and no training text appears in any evaluation split. Documents derived from a training document move with their source, so a rewrite of a training document can never appear in test.
1194
 
1195
  ## Fair comparison notes
1196
 
1197
- * The cross-system tables were scored by the same script (`pii_eval.py`), on the same documents, against the same gold. Values are compared after whitespace normalisation; case matters.
1198
- * The v2-versus-v3 table was scored with `eval_v3.py`, the script that produced the v2 baselines before v3 was trained. It also normalises case. On the same data the two scripts agree to within 0.2 points.
1199
- * v2, GLiNER, Presidio and the regex baseline emit v2 label names. Their predictions were mapped to the v3 labels with the table in [Migrating from v2](#migrating-from-v2), so none of them is penalised for naming.
1200
- * GLiNER-PII (`urchade/gliner_multi_pii-v1`) was queried with natural-language label names mapped to our labels, threshold 0.4, 1,500-character chunks.
1201
  * Presidio used the default `AnalyzerEngine` with spaCy `en_core_web_lg`, threshold 0.35. Its recognisers are English-first, which is part of why it scores poorly on the multilingual portion. It is included because it is the most widely deployed open-source baseline, not because the comparison is favourable.
1202
- * GLiNER and Presidio can only lose recall on label types they do not model. Unmappable types were dropped from their predictions rather than counted as errors.
1203
- * The test gold came from the same pipeline that produced the training data. That is the honest caveat on every number here: it is our own test set. The hard-case gold shares its generation process with the hard-case training documents, although the writers and value pools differ. The production probe is the one set that shares nothing with the training pipeline: code built it, no language model touched it, and its gold is complete by construction. The real-text injection slice reuses passages whose base text also appears in training, so treat it as a robustness check rather than an independent test.
1204
- * Independent evaluation on third-party corpora remains the obvious next step.
1205
 
1206
  ## Limitations
1207
 
1208
- * **False positives on documents with no personal data** rose from 2.0% in v2 to 12.5%, mostly dates and reference numbers in documents about nobody. The two-line filter under the headline table brings it to 4.5% for 0.5 F1.
1209
- * **Name variants and spoken values are the weakest cases.** A person named in full and later by nickname or surname alone scores 75.3 on the hard-case gold, and numbers read aloud with corrections score 75.9. Words glued to values (case endings, particles) are next at 78.5.
1210
- * **Indic scripts trail on the hard cases.** On the hard-case gold, Urdu (74.6), Kannada (75.1), Punjabi (76.1) and Marathi (76.2) are the lowest languages, against 90 and above for English, Dutch and Chinese. Each language has only 15 hard-case documents, so treat these as directional.
1211
- * **Identifier typing still has a ceiling.** A bare number without a cue word cannot always be typed. In call transcripts, an 8-digit account number read out right after a phone number is labelled `PHONE` in 13 of the 60 production-probe transcripts. For redaction what matters is that the value is found, and redaction recall is 96.0 on the test set.
1212
- * **Random capitalisation is still the worst corruption.** Mixed random caps cost 8.5 F1 (v2: 15.6), and among the 23 PII-free documents in the robustness sample, the number flagged rose from 2 to 10. All-uppercase text costs 3.8 and keyboard typos 3.1. Normalise case before calling the model if your inputs may contain it.
1213
- * **Weak labels.** `DISABILITY` (62.2), `PASSWORD_SECRET` (69.4), `ETHNICITY` (74.1), `PAYMENT_ID` (75.8) and `API_KEY_TOKEN` (76.6) are the soft spots, and most special-category labels have fewer than 50 test instances each.
1214
- * **`SIGNATURE` no longer exists.** A signature line is tagged `PERSON`, like any other name.
1215
- * **Do not add a regex union.** Tested on v2: combining the model with checksum and regex recognisers lowered F1 from 88.4 to 86.6 and raised the false-positive rate from 0.4% to 9.0%.
1216
- * **Synthetic training data.** Style is bounded by the generators that produced it. Real noise round trips, augmentation, real-text injection and the code-built probe reduce that fingerprint but do not remove it.
1217
  * **Not a compliance guarantee.** This is a detection aid. Regulated workflows still need human review.
1218
 
1219
  ## Other formats
1220
 
1221
- * Quantised GGUF builds for llama.cpp, Ollama and LM Studio: [Kavach-PII-270M-GGUF](https://huggingface.co/inboxpraveen/Kavach-PII-270M-GGUF)
1222
- * LoRA adapter only, 61 MB, applies to `google/gemma-3-270m-it`: the `adapter/` folder in this repository.
1223
- * v2 (52 labels) remains available in this repository's commit history.
1224
 
1225
  ## Licence
1226
 
@@ -1230,11 +1058,11 @@ Built with Gemma. This model is a fine-tune of `google/gemma-3-270m-it` and is g
1230
 
1231
  ```bibtex
1232
  @software{kavach_pii_270m,
1233
- title = {Kavach PII 270M: multilingual personal data extraction with post-hoc span recovery},
1234
- author = {Praveen Kumar},
1235
- year = {2026},
1236
- version = {3},
1237
- url = {https://huggingface.co/inboxpraveen/Kavach-PII-270M},
1238
- note = {Fine-tune of google/gemma-3-270m-it}
1239
  }
1240
  ```
 
1
  ---
2
  license: gemma
3
  base_model: google/gemma-3-270m-it
4
+ new_version: inboxpraveen/Kavach-PII-270M
5
  library_name: transformers
6
  pipeline_tag: text-generation
7
  tags:
 
45
  - pl
46
  ---
47
 
48
+ # Kavach PII 270M (v2)
49
 
50
+ > **This is version 2 (released 2026-09-23), kept so results and pipelines built on it stay reproducible.** The current version is v3 at [inboxpraveen/Kavach-PII-270M](https://huggingface.co/inboxpraveen/Kavach-PII-270M). Re-scored on v3's repaired test set (4,577 documents, same scorer), v3 reaches 92.0 value-F1 against 79.0 for v2; the 88.4 below was measured against the original v2 gold, which missed roughly one value in ten. On that same set v2 still flags fewer PII-free documents (2.0% against 12.5%). v3 uses a shorter 43-label list, so the prompts are not interchangeable.
51
+ >
52
+ > Weights, charts and figures on this page are unchanged from the original v2 upload. Two notes: `generation_config.json` sets `do_sample: true` as originally shipped, so always decode greedily (`do_sample=False` or `temperature=0`, as every example below does); and [`kavach_extract.py`](kavach_extract.py), missing from the original upload, is now included in its v2 form.
53
 
54
+ A 270M parameter model that finds personal data in 29 languages. It scores 88.4 value-F1 on a held-out test set where GLiNER-PII scores 56.4 and Microsoft Presidio scores 22.2, measured with the same script on the same gold annotations.
55
 
56
+ *Kavach* (कवच) is Sanskrit for "armour". The model reads a document and returns the personal data it contains as a JSON list. It runs on a laptop GPU or on CPU, and it was built for the inputs real pipelines actually receive: call-centre ASR transcripts, scanned OCR output, structured forms, chat, code, logs, and deliberately obfuscated text.
57
 
58
+ ![Comparison against GLiNER, Presidio and regex baselines](assets/01-headline-comparison.png)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
+ | | Kavach PII 270M | GLiNER-PII multi-v1 | Presidio | Regex + checksum |
 
 
 
 
 
 
 
 
61
  |---|---|---|---|---|
62
+ | **Value F1** | **88.4** | 56.4 | 22.2 | 20.5 |
63
+ | Precision | 88.9 | 56.9 | 21.0 | 51.1 |
64
+ | Recall | 87.9 | 55.9 | 23.4 | 12.8 |
65
+ | Exact span F1 | 89.1 | 55.4 | 22.3 | 20.0 |
66
+ | Redaction recall | 93.0 | 66.2 | 43.2 | 15.6 |
67
+ | **False positives on PII-free documents** | **0.4%** | 80.2% | 85.3% | 28.8% |
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
+ The last row decides whether a redaction pipeline is usable in practice. Presidio flags something in 85% of documents that contain no personal data at all. Kavach does so in 0.4%.
70
 
71
+ Test set: 3,372 held-out documents, 13,646 gold values. Presidio and GLiNER label sets were mapped to ours on a best-effort basis. See [Fair comparison notes](#fair-comparison-notes).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
  ## Quick start
74
 
75
  ```python
76
+ import json, re
77
  from transformers import AutoTokenizer, AutoModelForCausalLM
78
 
79
+ MODEL = "inboxpraveen/Kavach-PII-270M-v2"
80
  tok = AutoTokenizer.from_pretrained(MODEL)
81
  model = AutoModelForCausalLM.from_pretrained(MODEL, dtype="bfloat16").to("cuda").eval()
82
 
83
+ LABELS = ["AADHAAR_IN","ADDRESS","AGE","API_KEY_TOKEN","BANK_ACCOUNT","BIOMETRIC_DESCRIPTOR","CARD_CVV",
84
+ "CARD_EXPIRY","CASE_ID","CREDIT_DEBIT_CARD","DATE_TIME","DEVICE_ID","DISABILITY","DOB","DRIVING_LICENSE","EMAIL",
85
+ "EMPLOYEE_ID","ETHNICITY","GENDER_SEX","GEO_LOCATION","HEALTH_ID","IBAN","INSURANCE_ID","IP_ADDRESS","LAB_ORDER_ID",
86
+ "LICENSE_PLATE","MAC_ADDRESS","MEDICAL_RECORD_ID","NATIONAL_ID","ORGANIZATION","PAN_IN","PASSPORT","PASSWORD_SECRET",
87
+ "PERSON","PHONE","POLITICAL_BELIEF","POSTAL_CODE","PRESCRIPTION_ID","RELIGION","ROUTING_CODE","SIGNATURE","SSN_US",
88
+ "STUDENT_ID","SWIFT_BIC","TAX_ID","TRANSACTION_ID","UPI_VPA","URL_PERSONAL","USERNAME","VIN","VOTER_ID","WALLET_ID"]
89
 
90
  INSTRUCTION = (
91
  "Extract all personal data (PII/PHI/PCI) from the text.\n"
 
100
  msgs = [{"role": "user", "content": f"{INSTRUCTION}\n\nText:\n<<<\n{text}\n>>>"}]
101
  prompt = tok.apply_chat_template(msgs, tokenize=False, add_generation_prompt=True)
102
  ids = tok(prompt, return_tensors="pt", add_special_tokens=False).to(model.device)
103
+ out = model.generate(**ids, max_new_tokens=768, do_sample=False)
104
  raw = tok.decode(out[0][ids["input_ids"].shape[1]:], skip_special_tokens=True)
105
  return json.loads(raw[raw.find("["): raw.rfind("]") + 1])
106
 
107
+ text = "Hi, this is Derek Okafor from Meridian Bank, my number is +1-617-555-0142."
108
+ print(extract(text))
109
  # [{"label": "PERSON", "text": "Derek Okafor"},
110
  # {"label": "ORGANIZATION", "text": "Meridian Bank"},
111
  # {"label": "PHONE", "text": "+1-617-555-0142"}]
 
 
 
 
 
 
 
112
  ```
113
 
114
  ## Serving
 
120
  ```bash
121
  pip install vllm
122
 
123
+ vllm serve inboxpraveen/Kavach-PII-270M-v2 \
124
  --dtype bfloat16 \
125
  --max-model-len 4096 \
126
  --port 8000
 
131
  ```bash
132
  vllm serve google/gemma-3-270m-it \
133
  --enable-lora \
134
+ --lora-modules kavach=inboxpraveen/Kavach-PII-270M-v2/adapter \
135
  --dtype bfloat16 --max-model-len 4096 --port 8000
136
  ```
137
 
 
141
  pip install "sglang[all]"
142
 
143
  python -m sglang.launch_server \
144
+ --model-path inboxpraveen/Kavach-PII-270M-v2 \
145
  --dtype bfloat16 \
146
  --context-length 4096 \
147
  --port 30000
 
157
 
158
  def extract(text):
159
  r = client.chat.completions.create(
160
+ model="inboxpraveen/Kavach-PII-270M-v2",
161
  messages=[{"role": "user", "content": f"{INSTRUCTION}\n\nText:\n<<<\n{text}\n>>>"}],
162
+ temperature=0, max_tokens=768,
163
  )
164
  raw = r.choices[0].message.content
165
  return json.loads(raw[raw.find("["): raw.rfind("]") + 1])
166
  ```
167
 
168
+ Batching is worth setting up. Documents are independent, output is short (roughly 100 tokens), and both servers handle concurrent requests well. The accuracy figures in this card were produced with the `transformers` path and with llama.cpp; vLLM and SGLang use the same weights and the same greedy decoding, so results should match, but they were not separately benchmarked.
169
 
170
  ### llama.cpp, Ollama, LM Studio
171
 
172
+ See [Kavach-PII-270M-v2-GGUF](https://huggingface.co/inboxpraveen/Kavach-PII-270M-v2-GGUF) for quantised builds down to 169 MB.
173
 
174
  ## Long inputs, transcripts and character offsets
175
 
 
191
  print(result["warnings"]) # empty list means a clean run
192
  ```
193
 
194
+ It is written to survive real input: `None`, bytes, a number, an empty string, a model call that raises, and output that is not valid JSON are all handled and reported in `result["warnings"]` rather than raised. Running the file directly (`python kavach_extract.py`) runs its self-test, which needs no GPU and no model. Both back-ends are tested end to end: `transformers` locally and `openai_generate` against a live `llama-server`.
195
 
196
+ ### Window size matters more than you would expect
197
 
198
+ The defaults below are measured, not reasoned about, because the obvious reasoning points the wrong way in both directions.
199
 
200
+ The model was trained on short documents: the median training document is 39 words. That does not mean you should feed it 39 words at a time. Two things are going on at once, and they pull opposite ways.
201
+
202
+ **On a coherent document, window size barely matters, but going small hurts.** These are 92 real test documents of 180 to 385 words, scored against their own gold:
203
 
204
  | | Precision | Recall | Value F1 |
205
  | --- | --- | --- | --- |
206
+ | Whole document, one call | 0.861 | 0.829 | 0.845 |
207
+ | Windowed 250 / 40 | 0.885 | 0.823 | 0.853 |
208
+ | Windowed 180 / 35 | 0.855 | 0.840 | 0.847 |
209
+ | Windowed 150 / 30 | 0.854 | 0.859 | **0.857** |
210
+ | Windowed 120 / 25 | 0.824 | 0.872 | 0.847 |
211
+ | Windowed 100 / 20 | 0.817 | 0.850 | 0.833 |
212
+ | Windowed 50 / 12 | 0.727 | 0.836 | 0.778 |
213
 
214
+ Everything from 120 words upward, including sending the document whole, lands between 0.845 and 0.857. Below that it falls away fast: cutting a coherent document into 50-word pieces costs 13 points of precision, because the model needs the surrounding sentence to tell a date of birth from an appointment date, or a patient from a clinician, and a small window takes that away.
215
 
216
+ **On text that runs past a few hundred words, recall falls away.** These are eight documents of about 660 words each, built by stitching unrelated documents together, which is the harder case because the model was never trained on concatenated documents:
217
 
218
  | Window / overlap | Precision | Recall | Value F1 | Model calls |
219
  | --- | --- | --- | --- | --- |
220
+ | 30 / 8 | 0.737 | 0.851 | 0.789 | 245 |
221
+ | 50 / 12 | 0.833 | 0.863 | 0.848 | 141 |
222
+ | 100 / 20 | 0.862 | 0.856 | 0.859 | 68 |
223
+ | 120 / 25 | 0.861 | 0.848 | **0.855** | 57 |
224
+ | 150 / 30 | 0.850 | 0.732 | 0.787 | 47 |
225
+ | 180 / 35 | 0.851 | 0.822 | 0.836 | 39 |
226
+ | 200 / 40 | 0.851 | 0.781 | 0.815 | 36 |
227
+ | 250 / 40 | 0.863 | 0.716 | 0.783 | 31 |
228
+ | 400 / 80 | 0.849 | 0.508 | 0.635 | 17 |
229
 
230
+ Precision holds up to 400 words; recall halves. The model emits about as many entities as a short document contains and then stops, so a single call carrying 400 words of dense personal data simply does not list it all. Sending each source document on its own scores 0.876, which is the ceiling any windowing scheme is working towards.
231
 
232
+ **The default is 120 words with 25 of overlap**, because it is the only setting that is near the top of both tables at once. On coherent documents everything from 120 to 250 sits in a one-point band, 0.847 to 0.857, so the choice barely matters there; 150 is nominally the best of them. On concatenated text the spread is much wider and 120 is clearly better than 150. The second table is eight documents and its middle rows are noisy, which is why the default sits at the low end of the plateau rather than on the single best cell.
233
 
234
+ Two things not to do: do not drop below about 80 words, where precision goes, and do not go past 250, where recall goes. Keep the overlap at 20 or more, or a long address can straddle an edge and be seen whole by neither window. If your input is always coherent prose rather than concatenated records, 150 or 180 is a reasonable change.
235
 
236
  A document shorter than the window is sent in one call untouched, so ordinary short inputs never pay the windowing cost at all.
237
 
 
239
 
240
  ### Speech-to-text input
241
 
242
+ Transcripts work as they come out of the recogniser. Bracketed timestamps (`[00:01:02]`), SRT ranges (`00:00:03,500 --> 00:00:07,120`), WebVTT cues and plain `Speaker 1:` turns pass through untouched, and the timestamps survive redaction. This is not special-case code: 630 training documents contain bracketed timestamps and not one of them is tagged, so the model learned to ignore them. Measured on the 30 longest timestamped test documents, zero timestamps were tagged as personal data and all 243 of them survived redaction intact. Where the transcript has line breaks, window edges prefer to land on one, so a speaker turn stays whole; a transcript that arrives as one unbroken line is cut on word boundaries instead.
243
 
244
  ```
245
  [00:00:03] Speaker 1: Hello, this is [PERSON] from [ORGANIZATION].
 
248
 
249
  ### Locating values correctly
250
 
251
+ Matching is stricter than a plain substring search, which matters more than it sounds. On the test set, a naive `re.escape` locator places 127 spans (0.94%) inside longer words: `Raj` lands in the middle of `Rajesh`, `2024` inside `20245`, and redaction then emits `[PERSON]esh`. `extract_pii` requires a whole-word match, with the boundary rule switched off for Chinese, Japanese, Thai, Khmer, Burmese and Korean, where words are not space-separated or particles attach directly to the noun. Indic and Arabic combining marks count as part of the word, which is the bug that a plain `\b` has against Devanagari.
252
 
253
  Where a value occurs nowhere as a whole word, usually because the recogniser ran two words together, the span is still produced and flagged `"partial": True`, on the grounds that a mask starting mid-word beats leaving a real address in the clear. Drop those spans if you would rather under-mask.
254
 
255
+ On the 3,372-document test set:
256
 
257
+ | Outcome | Share of 13,488 predicted values |
258
  | --- | --- |
259
+ | Located as a whole word | 98.07% |
260
+ | Located only inside a longer run, flagged `partial` | 0.57% |
261
+ | Not present in the text at all (hallucination) | 1.36% |
 
 
262
 
263
  <details>
264
  <summary>Full source of <code>kavach_extract.py</code></summary>
 
283
  WebVTT cues and plain 'Speaker 1:' turns. Where the transcript has line breaks, windows prefer to cut on
284
  one, so a speaker turn or a subtitle cue stays whole; a transcript that arrives as a single unbroken line
285
  is simply cut on word boundaries. Timestamps are never treated as personal data, because the model was
286
+ trained that way: 630 training documents contain bracketed timestamps and not one is tagged.
287
  * Values repeated across the document. A name found once is masked at every occurrence.
288
  * Bad input: None, bytes, numbers, empty or whitespace-only strings, and model calls that fail or return
289
  something that is not JSON. Nothing raises; problems are reported in result["warnings"].
290
 
291
  Window defaults are measured, not guessed, and they are a compromise between two opposite failures.
292
 
293
+ Too small and precision goes: on 92 real test documents of 180-385 words, a 50-word window scores 0.727
294
+ precision against 0.861 for the same documents sent whole, because the model needs the surrounding sentence to
295
  tell a date of birth from an appointment date. Too large and recall goes: on 660-word inputs, recall falls from
296
+ 0.86 at a 100-word window to 0.51 at 400, because the model emits about as many entities as the short documents
297
+ it was trained on and then stops.
298
 
299
  120 words with 25 of overlap is near the top of both curves; 100 to 150 behaves about the same. Do not drop
300
+ below about 80, and do not go past 250. Keep the overlap at 20 or more, or a long address can straddle an edge
301
+ and be seen whole by neither window. A document shorter than the window is sent in one call untouched.
302
  """
303
 
304
  from __future__ import annotations
 
310
  __all__ = ["extract_pii", "redact", "LABELS", "INSTRUCTION", "build_prompt"]
311
 
312
  LABELS = [
313
+ "AADHAAR_IN", "ADDRESS", "AGE", "API_KEY_TOKEN", "BANK_ACCOUNT", "BIOMETRIC_DESCRIPTOR", "CARD_CVV",
314
+ "CARD_EXPIRY", "CASE_ID", "CREDIT_DEBIT_CARD", "DATE_TIME", "DEVICE_ID", "DISABILITY", "DOB",
315
+ "DRIVING_LICENSE", "EMAIL", "EMPLOYEE_ID", "ETHNICITY", "GENDER_SEX", "GEO_LOCATION", "HEALTH_ID", "IBAN",
316
+ "INSURANCE_ID", "IP_ADDRESS", "LAB_ORDER_ID", "LICENSE_PLATE", "MAC_ADDRESS", "MEDICAL_RECORD_ID",
317
+ "NATIONAL_ID", "ORGANIZATION", "PAN_IN", "PASSPORT", "PASSWORD_SECRET", "PERSON", "PHONE",
318
+ "POLITICAL_BELIEF", "POSTAL_CODE", "PRESCRIPTION_ID", "RELIGION", "ROUTING_CODE", "SIGNATURE", "SSN_US",
319
+ "STUDENT_ID", "SWIFT_BIC", "TAX_ID", "TRANSACTION_ID", "UPI_VPA", "URL_PERSONAL", "USERNAME", "VIN",
320
+ "VOTER_ID", "WALLET_ID",
321
  ]
322
 
323
  INSTRUCTION = (
 
566
  with 20-30 of overlap all behave about the same, and both smaller and larger settings are worse, for
567
  different reasons. Text shorter than one window is sent in a single call.
568
  labels
569
+ Restrict to a subset of the 52 labels, for example {"PERSON", "PHONE"}. Default: all.
570
  lenient
571
  Also match values case-insensitively when locating them. Slightly higher recall, slightly higher risk
572
  of matching the wrong occurrence.
 
582
  dict with keys
583
  spans list of {"start", "end", "label", "text"}, sorted, non-overlapping, offsets into the
584
  original string you passed in. A span also carries "partial": True when the value only
585
+ occurred inside a longer run of text, which is rare (0.6% of predictions on the test set)
586
  and usually means speech-to-text ran two words together. Drop those if you would rather
587
  under-mask than mask across a word edge.
588
  entities list of unique {"label", "text"} in order of first appearance
 
698
  # --------------------------------------------------------------------------------------------------
699
  # generate() adapters. Pick one.
700
 
701
+ def transformers_generate(model, tokenizer, max_new_tokens=768, batch_size=8):
702
  """generate() backed by a local transformers model."""
703
  import torch
704
 
 
722
  return run
723
 
724
 
725
+ def openai_generate(base_url="http://127.0.0.1:8000/v1", model="inboxpraveen/Kavach-PII-270M-v2",
726
+ api_key="EMPTY", max_tokens=768, workers=4):
727
  """generate() backed by any OpenAI-compatible server: vLLM, SGLang or llama-server."""
728
  from concurrent.futures import ThreadPoolExecutor
729
  from openai import OpenAI
 
866
 
867
  ## Prompt guidance
868
 
869
+ * Use the instruction above verbatim. The model was trained on exactly this text, and paraphrasing it costs accuracy.
870
  * Use greedy decoding (`do_sample=False`, or `temperature: 0`). Sampling adds nothing on an extraction task and breaks JSON validity.
871
+ * `max_new_tokens` of roughly `48 + 1.6 * input_tokens` is enough. Output is short.
872
+ * Retry unparseable outputs once with `repetition_penalty=1.1`. Small models occasionally fall into a repetition loop on rare scripts. Re-decoding only the failures recovered 45 out of 45 in testing and raised F1 by 1.0 point. Applying a repetition penalty to every request lowered F1 by 1.4 points, so apply it only on retry.
873
+ * Normalise case first if your input may contain mixed random capitalisation. See [Limitations](#limitations).
874
+ * Send one document per call, and window anything long. The model was not trained on concatenated documents, and a single call carrying far more text than it saw in training loses recall badly. `kavach_extract.py` above does the windowing for you.
875
 
876
  ## Results
877
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
878
  ### By input condition
879
 
880
+ ![Value-F1 by input condition](assets/02-conditions-radar.png)
881
 
882
+ | Condition | Test docs | Kavach | GLiNER | Presidio |
883
+ |---|---|---|---|---|
884
+ | Dialogue transcripts | 266 | **93.1** | 57.8 | 20.9 |
885
+ | Masked or partial values | 162 | **90.6** | 54.3 | 16.4 |
886
+ | Structured forms | 239 | **90.4** | 66.9 | 28.3 |
887
+ | OCR output | 74 | **90.4** | 70.1 | 30.9 |
888
+ | Clean text | 1,382 | **90.3** | 59.2 | 25.7 |
889
+ | Code and logs | 118 | **87.5** | 50.7 | 24.0 |
890
+ | ASR transcripts | 695 | **83.3** | 49.0 | 17.0 |
891
+ | Adversarial formatting | 247 | **82.5** | 52.8 | 16.1 |
892
+
893
+ The weakest condition for Kavach (adversarial formatting, 82.5) is above the strongest condition for GLiNER (OCR, 70.1).
894
 
895
+ Additional held-out slices: simulated ASR rewrites 88.9, real render-to-Tesseract OCR 81.4, and PII embedded in long real Wikipedia passages 82.4 with 0.0% false positives on the PII-free portions.
896
 
897
  ### By language
898
 
899
+ Each of the 29 language groups has at least 80 held-out test documents, so each figure carries a confidence interval of roughly 5 points rather than the 20 to 45 points you get from a 15-document sample. Kavach leads in all 29.
900
 
901
+ ![Per-language comparison](assets/03-languages.png)
902
 
903
+ | Language | Test docs | Kavach F1 | 95% CI | GLiNER | Gain |
904
  |---|---|---|---|---|---|
905
+ | Dutch | 81 | **94.3** | 91.6 to 97.0 | 74.7 | +19.6 |
906
+ | Russian | 81 | **93.9** | 91.2 to 96.1 | 59.2 | +34.7 |
907
+ | Simplified Chinese | 81 | **93.6** | 90.8 to 95.9 | 52.7 | +40.9 |
908
+ | German | 82 | **92.9** | 90.1 to 95.1 | 66.0 | +26.9 |
909
+ | Turkish | 83 | **92.6** | 89.7 to 95.2 | 68.2 | +24.4 |
910
+ | Romanized Indian language | 85 | **92.2** | 89.3 to 95.3 | 72.2 | +20.0 |
911
+ | Multilingual mix (3 or more) | 80 | **92.0** | 88.6 to 95.0 | 71.5 | +20.5 |
912
+ | Japanese | 85 | **91.8** | 88.5 to 94.7 | 37.3 | +54.5 |
913
+ | Korean | 80 | **91.4** | 87.8 to 94.5 | 47.0 | +44.4 |
914
+ | Vietnamese | 84 | **90.7** | 87.8 to 93.5 | 64.8 | +26.0 |
915
+ | Spanish | 116 | **90.4** | 87.1 to 92.8 | 68.4 | +22.0 |
916
+ | Polish | 82 | **90.0** | 86.0 to 93.1 | 69.2 | +20.8 |
917
+ | English | 994 | **89.3** | 88.2 to 90.4 | 58.8 | +30.5 |
918
+ | Indonesian | 83 | **89.2** | 85.4 to 92.6 | 69.0 | +20.2 |
919
+ | Punjabi | 83 | **88.4** | 84.9 to 91.6 | 32.9 | +55.5 |
920
+ | Urdu | 80 | **87.6** | 83.4 to 91.2 | 69.2 | +18.4 |
921
+ | French | 83 | **87.1** | 83.2 to 90.9 | 58.3 | +28.8 |
922
+ | Portuguese | 83 | **86.3** | 81.3 to 91.8 | 64.5 | +21.8 |
923
+ | Chinese | 84 | **85.9** | 79.5 to 91.0 | 29.6 | +56.3 |
924
+ | Marathi | 81 | **85.6** | 81.8 to 89.3 | 35.0 | +50.6 |
925
+ | Italian | 83 | **85.1** | 79.6 to 90.8 | 67.8 | +17.3 |
926
+ | Gujarati | 82 | **85.0** | 81.6 to 89.0 | 40.6 | +44.4 |
927
+ | Hindi | 105 | **84.8** | 80.8 to 88.5 | 39.0 | +45.8 |
928
+ | Malayalam | 83 | **83.5** | 77.8 to 88.6 | 31.3 | +52.2 |
929
+ | Tamil | 97 | **83.1** | 78.6 to 87.2 | 32.5 | +50.6 |
930
+ | Bengali | 87 | **82.2** | 77.5 to 87.1 | 39.6 | +42.6 |
931
+ | Arabic | 82 | **81.3** | 74.9 to 87.5 | 55.2 | +26.1 |
932
+ | Telugu | 82 | **80.6** | 73.6 to 86.8 | 25.4 | +55.2 |
933
+ | Kannada | 80 | **74.6** | 69.7 to 79.0 | 35.2 | +39.4 |
934
+
935
+ Languages are covered in native script, romanised form, and code-switched with English.
936
 
937
  ### By label
938
 
939
+ 52 labels are supported. The table lists those with at least 50 test instances.
940
 
941
+ ![Per-label comparison](assets/04-labels.png)
942
 
943
+ | Label | Test instances | Kavach F1 | GLiNER F1 |
944
+ |---|---|---|---|
945
+ | `PERSON` | 2853 | **93.8** | 43.1 |
946
+ | `ORGANIZATION` | 1972 | **87.1** | 69.5 |
947
+ | `PHONE` | 1899 | **93.2** | 76.2 |
948
+ | `DOB` | 1106 | **92.2** | 83.8 |
949
+ | `EMAIL` | 1092 | **94.4** | 81.9 |
950
+ | `ADDRESS` | 1067 | **81.4** | 54.6 |
951
+ | `CASE_ID` | 669 | **82.5** | 37.3 |
952
+ | `EMPLOYEE_ID` | 212 | **86.5** | 28.6 |
953
+ | `INSURANCE_ID` | 208 | **84.7** | 58.8 |
954
+ | `BANK_ACCOUNT` | 183 | **86.9** | 54.8 |
955
+ | `NATIONAL_ID` | 183 | **75.2** | 32.4 |
956
+ | `CREDIT_DEBIT_CARD` | 174 | **90.6** | 62.1 |
957
+ | `TAX_ID` | 151 | **70.8** | 47.6 |
958
+ | `MEDICAL_RECORD_ID` | 135 | **86.3** | 45.3 |
959
+ | `DATE_TIME` | 134 | **58.9** | not modelled |
960
+ | `TRANSACTION_ID` | 122 | **78.1** | not modelled |
961
+
962
+ Full label set, 52 in total:
963
+
964
+ `AADHAAR_IN` `ADDRESS` `AGE` `API_KEY_TOKEN` `BANK_ACCOUNT` `BIOMETRIC_DESCRIPTOR` `CARD_CVV` `CARD_EXPIRY` `CASE_ID` `CREDIT_DEBIT_CARD` `DATE_TIME` `DEVICE_ID` `DISABILITY` `DOB` `DRIVING_LICENSE` `EMAIL` `EMPLOYEE_ID` `ETHNICITY` `GENDER_SEX` `GEO_LOCATION` `HEALTH_ID` `IBAN` `INSURANCE_ID` `IP_ADDRESS` `LAB_ORDER_ID` `LICENSE_PLATE` `MAC_ADDRESS` `MEDICAL_RECORD_ID` `NATIONAL_ID` `ORGANIZATION` `PAN_IN` `PASSPORT` `PASSWORD_SECRET` `PERSON` `PHONE` `POLITICAL_BELIEF` `POSTAL_CODE` `PRESCRIPTION_ID` `RELIGION` `ROUTING_CODE` `SIGNATURE` `SSN_US` `STUDENT_ID` `SWIFT_BIC` `TAX_ID` `TRANSACTION_ID` `UPI_VPA` `URL_PERSONAL` `USERNAME` `VIN` `VOTER_ID` `WALLET_ID`
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
965
 
966
  ### Robustness
967
 
968
+ Eighteen offset-safe corruptions applied to held-out documents, measured against the model's own clean baseline.
969
+
970
+ ![Robustness under corruption](assets/05-robustness.png)
971
+
972
+ Twelve of the eighteen cost under 1.5 F1, including zero-width character injection, homoglyph substitution, full-width characters, HTML and markdown wrapping, JSON escaping, whitespace noise, and separator changes. The exceptions are covered under [Limitations](#limitations).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
973
 
974
  ## Compliance coverage
975
 
 
978
  | HIPAA identifier | Label |
979
  |---|---|
980
  | Names | `PERSON` |
981
+ | Geography smaller than a state | `ADDRESS`, `POSTAL_CODE` |
982
  | Dates, ages over 89 | `DOB`, `DATE_TIME`, `AGE` |
983
  | Telephone and fax | `PHONE` |
984
  | Email | `EMAIL` |
985
+ | Social Security numbers | `SSN_US` |
986
  | Medical record numbers | `MEDICAL_RECORD_ID` |
987
  | Health plan beneficiary numbers | `INSURANCE_ID`, `HEALTH_ID` |
988
+ | Account numbers | `BANK_ACCOUNT` |
989
+ | Certificate and licence numbers | `DRIVING_LICENSE`, `EMPLOYEE_ID` (NPI, DEA, professional licences) |
990
  | Vehicle identifiers | `VIN`, `LICENSE_PLATE` |
991
+ | Device identifiers | `DEVICE_ID` |
992
  | Web URLs | `URL_PERSONAL` |
993
  | IP addresses | `IP_ADDRESS` |
994
  | Biometric identifiers | `BIOMETRIC_DESCRIPTOR` |
995
+ | Any other unique identifying number | `CASE_ID`, `STUDENT_ID`, and the rest of the ID family |
996
 
997
+ Also covered: PCI (`CREDIT_DEBIT_CARD`, `CARD_EXPIRY`, `CARD_CVV`, `IBAN`, `SWIFT_BIC`, `ROUTING_CODE`), India (`AADHAAR_IN`, `PAN_IN`, `UPI_VPA`, `VOTER_ID`), and US healthcare administration (NPI, DEA, Medicare MBI, and state professional licences, trained under `EMPLOYEE_ID` and `HEALTH_ID`).
998
 
999
  ## Training
1000
 
1001
  | | |
1002
  |---|---|
1003
  | Base model | `google/gemma-3-270m-it`, 268M parameters |
1004
+ | Method | LoRA, r=64, alpha=128, dropout 0.05, on all attention and MLP projections (15.2M trainable, 5.4%) |
1005
  | Precision | base weights bf16 throughout, only the adapter was trained |
1006
+ | Data | 58,596 training documents, 29.9M tokens |
1007
+ | Schedule | 3 epochs, 11,202 steps, lr 2e-4 with linear decay and 3% warmup, effective batch 16 |
1008
+ | Augmentation | 18 offset-safe corruption operations applied on the fly at p=0.35 |
1009
+ | Hardware | one NVIDIA RTX 5060 Laptop GPU (8 GB), 4 hours, 5.75 GB peak |
1010
  | Loss | cross-entropy on the assistant JSON only, prompt tokens masked out |
1011
 
1012
+ Best dev loss 0.0397, against 0.0478 for the previous version.
1013
 
1014
  ### Dataset
1015
 
1016
+ 65,307 documents and 238,254 labelled values, entirely synthetic. No real personal data was used.
1017
 
1018
  | Split | Documents | Values | PII-free |
1019
  |---|---|---|---|
1020
+ | train | 58,596 | 211,589 | 11,164 |
1021
+ | dev | 3,339 | 13,019 | 743 |
1022
+ | test | 3,372 | 13,646 | 736 |
 
 
 
 
 
1023
 
1024
+ The corpus spans 29 languages, 23 domains (contact centre, healthcare, pharmacy and labs, insurance, banking, government, telecom, e-commerce, education and HR, legal, IT helpdesk, logistics, real estate, automotive, and others) and 12 input conditions. It includes real noise round trips (browser render into Tesseract OCR, and an ASR simulator few-shot prompted on real Whisper output), PII embedded in real Wikipedia passages, and 600 hand-built negatives covering already-redacted text, blank forms, placeholder rows, and medical billing code lists.
1025
 
1026
+ Splits are grouped by synthetic identity, so no generated person appears on both sides of a split, and they are verified free of exact-text overlap. Documents derived from a training document move with their source, so a rewrite of a training document can never appear in test.
 
 
 
 
1027
 
1028
  ## Fair comparison notes
1029
 
1030
+ * All systems were scored by the same script, on the same 3,372 documents, against the same gold annotations.
1031
+ * GLiNER-PII (`urchade/gliner_multi_pii-v1`) was queried with natural-language label names mapped to the 52 labels, threshold 0.4, 1,500-character chunks.
 
 
1032
  * Presidio used the default `AnalyzerEngine` with spaCy `en_core_web_lg`, threshold 0.35. Its recognisers are English-first, which is part of why it scores poorly on the multilingual portion. It is included because it is the most widely deployed open-source baseline, not because the comparison is favourable.
1033
+ * Both systems can only lose recall on label types they do not model. Their label sets were mapped on a best-effort basis, and unmappable types were dropped from their predictions rather than counted as errors.
1034
+ * The gold annotations came from the same pipeline that produced the training data. That is the honest caveat on every number here: it is our own test set. Independent evaluation on third-party corpora is the obvious next step.
 
1035
 
1036
  ## Limitations
1037
 
1038
+ * **Identifier typing has a ceiling.** A bare alphanumeric string with no nearby cue word cannot be classified as `TAX_ID` rather than `NATIONAL_ID` by any model. Only 15% of such confusions had a disambiguating cue within 40 characters. For redaction, what matters is that the value is found, and redaction recall stays at 93.0 even where type accuracy drops. Consider reporting family-level accuracy alongside exact accuracy.
1039
+ * **Random capitalisation is the worst failure mode.** Mixed random caps cost 15.6 F1 and raise the false-positive rate on clean documents to 20%. The cause was found (the uppercase augmentation was missing from the training mix entirely, and case-chaos was weighted at 4%), the mix was rebalanced, and the model retrained. Uppercase robustness improved by 3.5 points but case-chaos improved by only 1.2. Normalise case before calling the model if your inputs may contain it.
1040
+ * **Keyboard typos** cost 8.5 F1.
1041
+ * **`SIGNATURE` against `PERSON`.** When a signature is the same string as a person's name in the same document, value-only output cannot separate them. This affects roughly 15% of `SIGNATURE` instances.
1042
+ * **Weak labels.** `POSTAL_CODE` (33.8), `PAN_IN` (41.3), `AADHAAR_IN` (45.1) and `DATE_TIME` (58.9) are the soft spots. `DATE_TIME` is inherently contextual, since a date is only personal data when tied to a person.
1043
+ * **Thin labels.** `ETHNICITY`, `AGE`, `GENDER_SEX`, `DISABILITY`, `POLITICAL_BELIEF` and `BIOMETRIC_DESCRIPTOR` have fewer than 10 test instances each. Treat their per-label numbers as indicative only.
1044
+ * **Do not add a regex union.** This was tested. Combining the model with checksum and regex recognisers lowered F1 from 88.4 to 86.6 and raised the false-positive rate from 0.4% to 9.0%.
1045
+ * **Synthetic training data.** Style is bounded by the generator that produced it. Real noise round trips, augmentation and real-text injection reduce that fingerprint but do not remove it.
 
1046
  * **Not a compliance guarantee.** This is a detection aid. Regulated workflows still need human review.
1047
 
1048
  ## Other formats
1049
 
1050
+ * Quantised GGUF builds for llama.cpp, Ollama and LM Studio: [Kavach-PII-270M-v2-GGUF](https://huggingface.co/inboxpraveen/Kavach-PII-270M-v2-GGUF)
1051
+ * LoRA adapter only, 90 MB, applies to `google/gemma-3-270m-it`: the `adapter/` folder in this repository.
 
1052
 
1053
  ## Licence
1054
 
 
1058
 
1059
  ```bibtex
1060
  @software{kavach_pii_270m,
1061
+ title = {Kavach PII 270M: multilingual personal data extraction with post-hoc span recovery},
1062
+ author = {Praveen Kumar},
1063
+ year = {2026},
1064
+ version = {2},
1065
+ url = {https://huggingface.co/inboxpraveen/Kavach-PII-270M-v2},
1066
+ note = {Fine-tune of google/gemma-3-270m-it}
1067
  }
1068
  ```
adapter/adapter_config.json CHANGED
@@ -32,13 +32,13 @@
32
  "rank_pattern": {},
33
  "revision": null,
34
  "target_modules": [
 
 
35
  "q_proj",
36
  "up_proj",
37
  "v_proj",
38
  "gate_proj",
39
- "o_proj",
40
- "down_proj",
41
- "k_proj"
42
  ],
43
  "target_parameters": null,
44
  "task_type": "CAUSAL_LM",
 
32
  "rank_pattern": {},
33
  "revision": null,
34
  "target_modules": [
35
+ "k_proj",
36
+ "down_proj",
37
  "q_proj",
38
  "up_proj",
39
  "v_proj",
40
  "gate_proj",
41
+ "o_proj"
 
 
42
  ],
43
  "target_parameters": null,
44
  "task_type": "CAUSAL_LM",
adapter/adapter_model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:a998536db33826fca014c3274bfcbc718b155ad57c3f7ba82d8c7397a7857966
3
  size 60785144
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d5ec24bfdcc5dde0967b687711cf1a9656757e4b1ff59ba15832e9f7f42b38d2
3
  size 60785144
assets/01-headline-comparison.png CHANGED
assets/full-test-report.md CHANGED
@@ -1,185 +1,187 @@
1
- # kavach_v3_test.jsonl (values)
2
 
3
- docs=4,577 gold_spans=31,375 pred_spans=31,125 · gold_values=28,670 pred_values=28,710 · unlocatable predicted values: 248 ( 0.9%) · unparseable outputs: 2 docs
4
 
5
  | metric | P | R | F1 |
6
  |---|---|---|---|
7
- | value level (label, value) | 92.0 | 92.1 | ** 92.0** |
8
- | exact span (micro) | 92.9 | 92.1 | ** 92.5** |
9
- | partial span (micro) | 95.2 | 94.4 | ** 94.8** |
10
- | redaction (char, type-agnostic) | 96.8 | 96.0 | ** 96.4** |
11
- | macro F1 value / exact / partial | | | 88.0 / 88.3 / 90.4 |
12
 
13
- negative docs: 440, false-positive rate 12.5% · positive docs fully covered: 75.4%
14
 
15
  ## Per label
16
 
17
  | label | values | pred | P value | R value | F1 value | spans | F1 exact | F1 partial |
18
  |---|---|---|---|---|---|---|---|---|
19
- | PERSON | 5371 | 5331 | 94.6 | 93.9 | 94.3 | 6961 | 94.6 | 96.5 |
20
- | PHONE | 3678 | 3657 | 95.7 | 95.2 | 95.4 | 3891 | 95.5 | 97.5 |
21
- | ORGANIZATION | 2732 | 2705 | 87.9 | 87.0 | 87.5 | 2950 | 88.5 | 93.4 |
22
- | EMAIL | 2652 | 2655 | 96.6 | 96.7 | 96.6 | 2782 | 97.7 | 98.3 |
23
- | DOB | 2616 | 2616 | 97.2 | 97.2 | 97.2 | 2680 | 97.3 | 98.8 |
24
- | CASE_ID | 2031 | 2170 | 85.5 | 91.3 | 88.3 | 2156 | 88.5 | 89.5 |
25
- | DATE_TIME | 2014 | 2091 | 83.0 | 86.2 | 84.6 | 2064 | 84.8 | 90.2 |
26
- | ADDRESS | 1587 | 1567 | 87.7 | 86.6 | 87.2 | 1616 | 87.8 | 94.5 |
27
- | NATIONAL_ID | 995 | 981 | 93.7 | 92.4 | 93.0 | 1050 | 93.6 | 94.3 |
28
- | CREDIT_DEBIT_CARD | 494 | 505 | 92.7 | 94.7 | 93.7 | 516 | 93.3 | 94.5 |
29
- | BANK_ACCOUNT | 406 | 412 | 93.4 | 94.8 | 94.1 | 433 | 94.1 | 95.3 |
30
- | EMPLOYEE_ID | 374 | 381 | 88.2 | 89.8 | 89.0 | 395 | 89.2 | 90.0 |
31
- | INSURANCE_ID | 329 | 321 | 92.5 | 90.3 | 91.4 | 345 | 91.6 | 92.5 |
32
- | BANK_CODE | 317 | 314 | 94.9 | 94.0 | 94.5 | 327 | 95.4 | 96.3 |
33
- | TRANSACTION_ID | 310 | 281 | 90.4 | 81.9 | 86.0 | 324 | 86.7 | 87.0 |
34
- | CARD_EXPIRY | 245 | 245 | 99.6 | 99.6 | 99.6 | 247 | 99.4 | 99.4 |
35
- | CARD_CVV | 232 | 232 | 96.1 | 96.1 | 96.1 | 240 | 95.2 | 96.0 |
36
- | MEDICAL_RECORD_ID | 204 | 213 | 84.0 | 87.7 | 85.9 | 210 | 85.7 | 88.1 |
37
- | AGE | 200 | 197 | 95.9 | 94.5 | 95.2 | 207 | 95.6 | 95.6 |
38
- | USERNAME | 179 | 189 | 85.7 | 90.5 | 88.0 | 185 | 86.4 | 87.5 |
39
- | LAB_ORDER_ID | 173 | 168 | 93.5 | 90.8 | 92.1 | 186 | 92.9 | 93.4 |
40
- | PRESCRIPTION_ID | 166 | 160 | 94.4 | 91.0 | 92.6 | 176 | 93.1 | 95.4 |
41
- | LICENSE_PLATE | 158 | 153 | 90.8 | 88.0 | 89.4 | 168 | 89.4 | 90.0 |
42
- | PASSPORT | 147 | 151 | 91.4 | 93.9 | 92.6 | 156 | 93.0 | 94.3 |
43
- | STUDENT_ID | 132 | 122 | 93.4 | 86.4 | 89.8 | 141 | 90.8 | 90.8 |
44
- | DRIVING_LICENSE | 116 | 116 | 83.6 | 83.6 | 83.6 | 125 | 84.1 | 84.1 |
45
- | GENDER_SEX | 99 | 94 | 94.7 | 89.9 | 92.2 | 111 | 91.5 | 92.5 |
46
- | DEVICE_ID | 80 | 78 | 85.9 | 83.8 | 84.8 | 81 | 84.3 | 84.3 |
47
- | HEALTH_ID | 75 | 64 | 95.3 | 81.3 | 87.8 | 77 | 87.5 | 87.5 |
48
- | PASSWORD_SECRET | 63 | 61 | 70.5 | 68.3 | 69.4 | 65 | 66.7 | 71.3 |
49
- | API_KEY_TOKEN | 54 | 53 | 77.4 | 75.9 | 76.6 | 56 | 76.4 | 78.2 |
50
- | PAYMENT_ID | 54 | 41 | 87.8 | 66.7 | 75.8 | 54 | 77.9 | 82.1 |
51
- | VIN | 47 | 47 | 89.4 | 89.4 | 89.4 | 49 | 87.8 | 87.8 |
52
- | URL_PERSONAL | 46 | 47 | 85.1 | 87.0 | 86.0 | 49 | 86.9 | 86.9 |
53
- | IP_ADDRESS | 47 | 55 | 85.5 | 100.0 | 92.2 | 47 | 93.1 | 93.1 |
54
- | RELIGION | 42 | 43 | 86.0 | 88.1 | 87.1 | 43 | 88.4 | 95.3 |
55
- | VOTER_ID | 37 | 31 | 96.8 | 81.1 | 88.2 | 37 | 88.2 | 88.2 |
56
- | DISABILITY | 36 | 38 | 60.5 | 63.9 | 62.2 | 36 | 63.0 | 79.5 |
57
- | BIOMETRIC_DESCRIPTOR | 32 | 26 | 88.5 | 71.9 | 79.3 | 37 | 76.9 | 76.9 |
58
- | POLITICAL_BELIEF | 29 | 30 | 80.0 | 82.8 | 81.4 | 30 | 82.0 | 85.2 |
59
- | ETHNICITY | 29 | 25 | 80.0 | 69.0 | 74.1 | 30 | 79.2 | 83.0 |
60
- | MAC_ADDRESS | 23 | 24 | 87.5 | 91.3 | 89.4 | 23 | 89.4 | 93.6 |
61
- | GEO_LOCATION | 19 | 20 | 90.0 | 94.7 | 92.3 | 19 | 92.3 | 97.4 |
 
 
 
 
 
 
 
 
 
62
 
63
  ## By language
64
 
65
  | value | docs | spans | F1 value | F1 exact | F1 partial | redaction R | neg-doc FP% |
66
  |---|---|---|---|---|---|---|---|
67
- | English | 1238 | 8370 | 92.8 | 92.9 | 95.2 | 96.4 | 8.4 |
68
- | Tamil | 194 | 1708 | 89.9 | 90.0 | 92.6 | 95.1 | 17.6 |
69
- | Telugu | 174 | 1618 | 92.3 | 93.1 | 95.4 | 95.5 | 22.2 |
70
- | Arabic | 173 | 1350 | 91.7 | 92.2 | 95.4 | 96.0 | 38.5 |
71
- | Bengali | 169 | 1362 | 90.0 | 90.9 | 93.5 | 94.4 | 0.0 |
72
- | Kannada | 156 | 1315 | 91.2 | 91.8 | 94.3 | 93.9 | 40.0 |
73
- | Malayalam | 156 | 1292 | 90.6 | 91.8 | 94.2 | 95.1 | 30.0 |
74
- | Hindi | 141 | 790 | 92.9 | 93.7 | 95.9 | 96.8 | 14.3 |
75
- | Spanish | 125 | 735 | 91.3 | 91.8 | 94.0 | 93.5 | 15.4 |
76
- | mixed | 120 | 988 | 96.0 | 96.1 | 97.1 | 97.5 | 50.0 |
77
- | Marathi | 118 | 784 | 90.6 | 91.5 | 94.9 | 94.8 | 9.1 |
78
- | Punjabi | 118 | 728 | 91.6 | 92.5 | 94.2 | 94.9 | 40.0 |
79
- | Romanized Indian language | 118 | 745 | 94.9 | 95.5 | 96.6 | 98.6 | 0.0 |
80
- | Gujarati | 112 | 638 | 89.9 | 90.6 | 93.1 | 94.5 | 25.0 |
81
- | German | 107 | 633 | 90.9 | 91.4 | 94.0 | 94.3 | 6.2 |
82
- | Urdu | 107 | 628 | 90.7 | 91.6 | 93.4 | 95.8 | 0.0 |
83
- | Korean | 106 | 791 | 92.2 | 93.2 | 96.1 | 96.7 | 20.0 |
84
- | Italian | 103 | 557 | 87.2 | 87.8 | 93.0 | 95.8 | 12.5 |
85
- | Simplified Chinese | 100 | 680 | 94.6 | 94.7 | 96.9 | 98.8 | 0.0 |
86
- | French | 98 | 468 | 90.4 | 90.4 | 91.9 | 96.6 | 0.0 |
87
- | Polish | 98 | 627 | 91.3 | 91.6 | 93.6 | 96.0 | 14.3 |
88
- | Vietnamese | 97 | 593 | 91.7 | 92.1 | 94.1 | 97.4 | 20.0 |
89
- | Russian | 96 | 645 | 92.3 | 92.8 | 95.1 | 97.0 | 0.0 |
90
- | Turkish | 96 | 660 | 93.1 | 92.9 | 95.0 | 98.0 | 12.5 |
91
- | Indonesian | 96 | 598 | 93.8 | 94.0 | 96.0 | 96.6 | 0.0 |
92
- | Portuguese | 95 | 507 | 91.3 | 91.8 | 94.2 | 96.5 | 16.7 |
93
- | Japanese | 91 | 540 | 93.6 | 94.8 | 95.5 | 95.5 | 9.1 |
94
- | Dutch | 90 | 548 | 96.4 | 96.7 | 97.2 | 98.1 | 11.1 |
95
- | Chinese | 85 | 477 | 90.2 | 90.5 | 94.6 | 97.7 | 13.3 |
96
 
97
  ## By language_mode
98
 
99
  | value | docs | spans | F1 value | F1 exact | F1 partial | redaction R | neg-doc FP% |
100
  |---|---|---|---|---|---|---|---|
101
- | monolingual | 2623 | 12914 | 92.4 | 92.7 | 95.1 | 96.6 | 10.6 |
102
- | code_switch | 510 | 2507 | 87.0 | 88.4 | 92.7 | 93.8 | 13.4 |
103
- | romanized | 214 | 970 | 89.5 | 89.9 | 93.4 | 95.2 | 25.0 |
104
 
105
  ## By noise
106
 
107
  | value | docs | spans | F1 value | F1 exact | F1 partial | redaction R | neg-doc FP% |
108
  |---|---|---|---|---|---|---|---|
109
- | clean | 1374 | 6384 | 93.2 | 93.5 | 95.2 | 97.7 | 15.0 |
110
- | asr | 688 | 3653 | 86.9 | 88.0 | 93.4 | 94.2 | 7.8 |
111
- | dialogue | 265 | 1802 | 93.8 | 94.0 | 95.6 | 96.0 | 0.0 |
112
- | adversarial | 245 | 1095 | 85.4 | 86.3 | 93.1 | 95.6 | 4.3 |
113
- | structured | 238 | 1108 | 94.0 | 94.3 | 95.2 | 97.4 | 37.5 |
114
- | masked | 161 | 613 | 95.6 | 96.0 | 97.3 | 97.1 | 22.2 |
115
- | code_logs | 115 | 407 | 91.5 | 90.9 | 91.2 | 93.8 | 5.6 |
116
- | ocr | 74 | 441 | 93.0 | 93.5 | 95.5 | 96.9 | 0.0 |
117
- | typos | 73 | 331 | 91.8 | 92.2 | 94.6 | 96.2 | 25.0 |
118
- | typo | 51 | 221 | 97.3 | 97.3 | 98.2 | 99.9 | 0.0 |
119
- | asr_digits | 32 | 193 | 87.8 | 87.6 | 94.5 | 94.2 | 0.0 |
120
- | asr_sim | 18 | 82 | 95.7 | 95.7 | 95.7 | 95.2 | - |
121
- | ocr_real | 10 | 49 | 80.0 | 80.4 | 88.2 | 83.5 | - |
122
- | real_context | 3 | 12 | 74.1 | 76.9 | 76.9 | 88.5 | - |
123
 
124
  ## By length
125
 
126
  | value | docs | spans | F1 value | F1 exact | F1 partial | redaction R | neg-doc FP% |
127
  |---|---|---|---|---|---|---|---|
128
- | short | 1685 | 6985 | 93.0 | 93.4 | 95.5 | 97.1 | 13.4 |
129
- | medium | 1369 | 7482 | 91.3 | 91.9 | 95.0 | 96.2 | 9.9 |
130
- | long | 200 | 1726 | 84.7 | 86.3 | 90.3 | 92.0 | 0.0 |
131
- | very_short | 93 | 198 | 88.2 | 88.2 | 90.7 | 98.0 | 26.3 |
132
 
133
  ## By polarity
134
 
135
  | value | docs | spans | F1 value | F1 exact | F1 partial | redaction R | neg-doc FP% |
136
  |---|---|---|---|---|---|---|---|
137
- | positive | 3663 | 29763 | 92.8 | 93.2 | 95.5 | 96.4 | - |
138
- | negative | 914 | 1612 | 78.6 | 80.1 | 83.3 | 87.1 | 12.5 |
139
 
140
  ## By bucket
141
 
142
  | value | docs | spans | F1 value | F1 exact | F1 partial | redaction R | neg-doc FP% |
143
  |---|---|---|---|---|---|---|---|
144
- | language_coverage | 877 | 4937 | 95.1 | 95.4 | 96.9 | 98.2 | 3.6 |
145
- | monolingual_pure | 824 | 3262 | 89.5 | 89.9 | 93.0 | 95.0 | 21.9 |
146
- | uncovered_scenarios | 468 | 1943 | 93.9 | 94.2 | 95.6 | 97.3 | 12.8 |
147
- | asr_realism | 417 | 2431 | 85.9 | 87.4 | 93.3 | 94.1 | 12.1 |
148
- | B4 | 286 | 2284 | 91.7 | 92.3 | 95.2 | 94.9 | - |
149
- | B1 | 256 | 5498 | 94.6 | 94.9 | 96.0 | 96.9 | - |
150
- | adversarial_format | 222 | 998 | 84.5 | 85.4 | 92.8 | 95.3 | 5.0 |
151
- | B2 | 204 | 3841 | 92.5 | 93.3 | 95.2 | 95.3 | - |
152
- | B5 | 198 | 609 | 84.6 | 84.6 | 87.1 | 91.9 | 14.5 |
153
- | compliance_identifiers | 154 | 906 | 95.9 | 96.1 | 96.6 | 99.0 | 0.0 |
154
- | B3 | 148 | 1411 | 91.1 | 91.3 | 92.7 | 95.8 | - |
155
- | B6 | 138 | 1341 | 93.5 | 93.6 | 95.5 | 97.6 | - |
156
- | code_and_logs | 115 | 407 | 91.5 | 90.9 | 91.2 | 93.8 | 5.6 |
157
- | targeted_rare_labels | 111 | 531 | 93.1 | 93.6 | 94.6 | 95.4 | 0.0 |
158
- | targeted_sensitive_attributes | 47 | 159 | 88.3 | 89.0 | 92.1 | 94.8 | 12.5 |
159
- | targeted_long_documents | 39 | 412 | 86.4 | 87.5 | 89.5 | 93.4 | - |
160
- | targeted_hard_negatives | 38 | 76 | 73.4 | 74.2 | 83.0 | 84.2 | 16.7 |
161
- | targeted_org_agent_readback | 32 | 317 | 95.9 | 96.5 | 97.8 | 97.3 | 0.0 |
162
- | inject | 3 | 12 | 74.1 | 76.9 | 76.9 | 88.5 | - |
163
 
164
  ## By script
165
 
166
  | value | docs | spans | F1 value | F1 exact | F1 partial | redaction R | neg-doc FP% |
167
  |---|---|---|---|---|---|---|---|
168
- | Latin | 1983 | 12921 | 91.4 | 91.8 | 94.4 | 95.9 | 12.0 |
169
- | latin | 635 | 3633 | 95.6 | 95.7 | 96.8 | 98.4 | 2.8 |
170
- | native | 396 | 2210 | 94.6 | 95.0 | 96.9 | 98.1 | 3.6 |
171
- | Arabic | 224 | 1694 | 91.3 | 91.9 | 94.7 | 96.1 | 31.2 |
172
- | Devanagari | 186 | 1237 | 92.0 | 92.8 | 95.5 | 95.7 | 11.8 |
173
- | Tamil | 161 | 1557 | 90.2 | 90.3 | 92.9 | 95.0 | 30.0 |
174
- | Telugu | 158 | 1574 | 93.0 | 93.7 | 95.7 | 95.8 | 25.0 |
175
- | Bengali | 149 | 1262 | 90.5 | 91.3 | 93.7 | 95.2 | 0.0 |
176
- | Kannada | 126 | 1194 | 92.2 | 92.8 | 94.2 | 94.1 | 33.3 |
177
- | Malayalam | 118 | 1085 | 90.5 | 91.8 | 93.9 | 94.5 | 16.7 |
178
- | Mixed | 102 | 447 | 89.3 | 89.9 | 94.2 | 95.7 | 7.1 |
179
- | Gurmukhi | 88 | 576 | 91.0 | 92.1 | 93.1 | 94.1 | 40.0 |
180
- | Han | 85 | 622 | 90.7 | 91.3 | 95.3 | 96.9 | 10.0 |
181
- | Gujarati | 79 | 472 | 90.1 | 90.8 | 93.2 | 93.2 | 20.0 |
182
- | Hangul | 48 | 485 | 90.0 | 91.4 | 95.4 | 96.5 | 100.0 |
183
- | Cyrillic | 27 | 261 | 87.8 | 88.5 | 91.3 | 94.8 | 0.0 |
184
- | Japanese | 7 | 118 | 92.8 | 93.5 | 93.5 | 96.1 | - |
185
- | Hiragana | 5 | 27 | 87.5 | 90.6 | 94.3 | 87.6 | - |
 
1
+ # test.jsonl (values)
2
 
3
+ docs=3,372 gold_spans=14,591 pred_spans=14,191 · gold_values=13,646 pred_values=13,488 · unlocatable predicted values: 194 ( 1.4%) · unparseable outputs: 2 docs
4
 
5
  | metric | P | R | F1 |
6
  |---|---|---|---|
7
+ | value level (label, value) | 88.9 | 87.9 | ** 88.4** |
8
+ | exact span (micro) | 90.4 | 87.9 | ** 89.1** |
9
+ | partial span (micro) | 93.5 | 91.0 | ** 92.2** |
10
+ | redaction (char, type-agnostic) | 95.5 | 93.0 | ** 94.3** |
11
+ | macro F1 value / exact / partial | | | 75.0 / 75.4 / 80.6 |
12
 
13
+ negative docs: 736, false-positive rate 0.4% · positive docs fully covered: 73.8%
14
 
15
  ## Per label
16
 
17
  | label | values | pred | P value | R value | F1 value | spans | F1 exact | F1 partial |
18
  |---|---|---|---|---|---|---|---|---|
19
+ | PERSON | 2853 | 2832 | 94.2 | 93.5 | 93.8 | 3196 | 94.0 | 96.1 |
20
+ | ORGANIZATION | 1972 | 1980 | 86.9 | 87.3 | 87.1 | 2159 | 88.8 | 93.3 |
21
+ | PHONE | 1899 | 1898 | 93.2 | 93.2 | 93.2 | 2019 | 93.4 | 95.7 |
22
+ | DOB | 1106 | 1120 | 91.6 | 92.8 | 92.2 | 1132 | 92.5 | 94.3 |
23
+ | EMAIL | 1092 | 1087 | 94.7 | 94.2 | 94.4 | 1133 | 96.0 | 96.4 |
24
+ | ADDRESS | 1067 | 1050 | 82.1 | 80.8 | 81.4 | 1083 | 82.7 | 93.3 |
25
+ | CASE_ID | 669 | 638 | 84.5 | 80.6 | 82.5 | 734 | 83.0 | 84.6 |
26
+ | EMPLOYEE_ID | 212 | 218 | 85.3 | 87.7 | 86.5 | 235 | 88.2 | 89.5 |
27
+ | INSURANCE_ID | 208 | 210 | 84.3 | 85.1 | 84.7 | 221 | 85.1 | 86.9 |
28
+ | BANK_ACCOUNT | 183 | 192 | 84.9 | 89.1 | 86.9 | 189 | 87.1 | 90.2 |
29
+ | NATIONAL_ID | 183 | 208 | 70.7 | 80.3 | 75.2 | 187 | 74.2 | 75.2 |
30
+ | CREDIT_DEBIT_CARD | 174 | 177 | 89.8 | 91.4 | 90.6 | 183 | 91.1 | 92.7 |
31
+ | TAX_ID | 151 | 157 | 69.4 | 72.2 | 70.8 | 155 | 69.6 | 72.2 |
32
+ | MEDICAL_RECORD_ID | 135 | 150 | 82.0 | 91.1 | 86.3 | 138 | 86.6 | 88.0 |
33
+ | DATE_TIME | 134 | 107 | 66.4 | 53.0 | 58.9 | 134 | 60.2 | 75.4 |
34
+ | TRANSACTION_ID | 122 | 111 | 82.0 | 74.6 | 78.1 | 138 | 78.2 | 81.2 |
35
+ | CARD_CVV | 122 | 123 | 95.1 | 95.9 | 95.5 | 129 | 94.6 | 94.6 |
36
+ | PASSPORT | 117 | 123 | 91.1 | 95.7 | 93.3 | 126 | 94.2 | 96.5 |
37
+ | CARD_EXPIRY | 121 | 120 | 94.2 | 93.4 | 93.8 | 121 | 93.8 | 95.4 |
38
+ | USERNAME | 117 | 110 | 85.5 | 80.3 | 82.8 | 120 | 82.8 | 88.1 |
39
+ | PRESCRIPTION_ID | 114 | 101 | 95.0 | 84.2 | 89.3 | 123 | 89.7 | 90.5 |
40
+ | LAB_ORDER_ID | 97 | 96 | 88.5 | 87.6 | 88.1 | 108 | 88.8 | 89.7 |
41
+ | DRIVING_LICENSE | 82 | 86 | 76.7 | 80.5 | 78.6 | 89 | 78.3 | 81.5 |
42
+ | STUDENT_ID | 74 | 71 | 88.7 | 85.1 | 86.9 | 82 | 88.2 | 89.4 |
43
+ | LICENSE_PLATE | 69 | 67 | 80.6 | 78.3 | 79.4 | 75 | 81.1 | 81.1 |
44
+ | AADHAAR_IN | 54 | 17 | 94.1 | 29.6 | 45.1 | 61 | 46.3 | 46.3 |
45
+ | DEVICE_ID | 54 | 45 | 95.6 | 79.6 | 86.9 | 55 | 87.1 | 87.1 |
46
+ | HEALTH_ID | 48 | 41 | 95.1 | 81.2 | 87.6 | 49 | 86.7 | 86.7 |
47
+ | POSTAL_CODE | 41 | 36 | 36.1 | 31.7 | 33.8 | 50 | 30.2 | 32.6 |
48
+ | PAN_IN | 43 | 20 | 65.0 | 30.2 | 41.3 | 43 | 40.0 | 40.0 |
49
+ | IP_ADDRESS | 39 | 39 | 97.4 | 97.4 | 97.4 | 40 | 95.1 | 95.1 |
50
+ | SIGNATURE | 39 | 20 | 70.0 | 35.9 | 47.5 | 27 | 59.6 | 85.1 |
51
+ | RELIGION | 24 | 20 | 75.0 | 62.5 | 68.2 | 24 | 69.8 | 69.8 |
52
+ | PASSWORD_SECRET | 21 | 14 | 85.7 | 57.1 | 68.6 | 21 | 68.6 | 74.3 |
53
+ | MAC_ADDRESS | 20 | 20 | 95.0 | 95.0 | 95.0 | 21 | 95.2 | 95.2 |
54
+ | WALLET_ID | 19 | 17 | 100.0 | 89.5 | 94.4 | 19 | 94.4 | 94.4 |
55
+ | URL_PERSONAL | 18 | 12 | 91.7 | 61.1 | 73.3 | 18 | 73.3 | 73.3 |
56
+ | VOTER_ID | 17 | 16 | 100.0 | 94.1 | 97.0 | 17 | 97.0 | 97.0 |
57
+ | IBAN | 16 | 17 | 76.5 | 81.2 | 78.8 | 16 | 78.8 | 84.8 |
58
+ | SWIFT_BIC | 15 | 16 | 68.8 | 73.3 | 71.0 | 16 | 68.8 | 87.5 |
59
+ | UPI_VPA | 15 | 15 | 80.0 | 80.0 | 80.0 | 15 | 82.8 | 89.7 |
60
+ | ROUTING_CODE | 14 | 24 | 58.3 | 100.0 | 73.7 | 14 | 73.7 | 73.7 |
61
+ | API_KEY_TOKEN | 13 | 9 | 88.9 | 61.5 | 72.7 | 13 | 72.7 | 72.7 |
62
+ | VIN | 10 | 11 | 81.8 | 90.0 | 85.7 | 10 | 85.7 | 85.7 |
63
+ | DISABILITY | 8 | 9 | 33.3 | 37.5 | 35.3 | 8 | 35.3 | 94.1 |
64
+ | GENDER_SEX | 8 | 4 | 50.0 | 25.0 | 33.3 | 8 | 36.4 | 36.4 |
65
+ | ETHNICITY | 8 | 6 | 33.3 | 25.0 | 28.6 | 8 | 28.6 | 57.1 |
66
+ | POLITICAL_BELIEF | 8 | 9 | 44.4 | 50.0 | 47.1 | 8 | 47.1 | 94.1 |
67
+ | AGE | 8 | 9 | 55.6 | 62.5 | 58.8 | 8 | 58.8 | 58.8 |
68
+ | SSN_US | 6 | 6 | 66.7 | 66.7 | 66.7 | 6 | 66.7 | 66.7 |
69
+ | BIOMETRIC_DESCRIPTOR | 4 | 4 | 100.0 | 100.0 | 100.0 | 4 | 100.0 | 100.0 |
70
+ | GEO_LOCATION | 3 | 0 | 0.0 | 0.0 | 0.0 | 3 | 0.0 | 0.0 |
71
 
72
  ## By language
73
 
74
  | value | docs | spans | F1 value | F1 exact | F1 partial | redaction R | neg-doc FP% |
75
  |---|---|---|---|---|---|---|---|
76
+ | English | 994 | 4274 | 89.3 | 89.6 | 92.8 | 93.0 | 0.0 |
77
+ | Spanish | 116 | 511 | 90.4 | 91.7 | 94.1 | 94.0 | 0.0 |
78
+ | Hindi | 105 | 411 | 84.8 | 86.7 | 92.0 | 92.3 | 0.0 |
79
+ | Tamil | 97 | 343 | 83.1 | 84.6 | 89.5 | 91.9 | 0.0 |
80
+ | Bengali | 87 | 368 | 82.2 | 84.3 | 86.9 | 81.0 | 0.0 |
81
+ | Japanese | 85 | 386 | 91.8 | 92.4 | 95.0 | 96.4 | 0.0 |
82
+ | Romanized Indian language | 85 | 389 | 92.2 | 92.3 | 93.3 | 99.2 | 0.0 |
83
+ | Chinese | 84 | 385 | 85.9 | 86.1 | 92.4 | 92.6 | 0.0 |
84
+ | Vietnamese | 84 | 417 | 90.7 | 91.6 | 93.1 | 94.2 | 0.0 |
85
+ | French | 83 | 287 | 87.1 | 87.9 | 90.8 | 93.4 | 0.0 |
86
+ | Italian | 83 | 334 | 85.1 | 84.9 | 93.0 | 92.8 | 0.0 |
87
+ | Malayalam | 83 | 357 | 83.5 | 86.2 | 90.5 | 86.9 | 0.0 |
88
+ | Punjabi | 83 | 340 | 88.4 | 89.1 | 91.8 | 95.9 | 0.0 |
89
+ | Turkish | 83 | 406 | 92.6 | 93.0 | 95.3 | 95.8 | 0.0 |
90
+ | Indonesian | 83 | 359 | 89.2 | 90.3 | 91.7 | 97.3 | 0.0 |
91
+ | Portuguese | 83 | 326 | 86.3 | 86.5 | 90.2 | 96.0 | 0.0 |
92
+ | German | 82 | 365 | 92.9 | 93.6 | 94.7 | 96.3 | 0.0 |
93
+ | Polish | 82 | 353 | 90.0 | 90.6 | 92.3 | 96.1 | 0.0 |
94
+ | Telugu | 82 | 311 | 80.6 | 83.3 | 87.6 | 84.3 | 5.0 |
95
+ | Gujarati | 82 | 340 | 85.0 | 84.7 | 88.6 | 93.7 | 0.0 |
96
+ | Arabic | 82 | 318 | 81.3 | 82.7 | 88.8 | 88.2 | 0.0 |
97
+ | Marathi | 81 | 316 | 85.6 | 87.3 | 91.2 | 90.9 | 0.0 |
98
+ | Russian | 81 | 406 | 93.9 | 94.1 | 95.4 | 96.6 | 0.0 |
99
+ | Dutch | 81 | 374 | 94.3 | 94.6 | 96.2 | 95.4 | 0.0 |
100
+ | Simplified Chinese | 81 | 396 | 93.6 | 94.1 | 96.4 | 96.9 | 0.0 |
101
+ | Kannada | 80 | 337 | 74.6 | 74.6 | 79.0 | 83.3 | 11.8 |
102
+ | Urdu | 80 | 368 | 87.6 | 89.1 | 91.6 | 95.1 | 0.0 |
103
+ | Korean | 80 | 372 | 91.4 | 92.1 | 95.1 | 96.9 | 0.0 |
104
+ | mixed | 80 | 442 | 92.0 | 92.8 | 93.2 | 95.2 | 0.0 |
105
 
106
  ## By language_mode
107
 
108
  | value | docs | spans | F1 value | F1 exact | F1 partial | redaction R | neg-doc FP% |
109
  |---|---|---|---|---|---|---|---|
110
+ | monolingual | 2638 | 11468 | 89.6 | 90.2 | 92.8 | 93.8 | 0.0 |
111
+ | code_switch | 518 | 2266 | 81.3 | 83.3 | 88.9 | 89.4 | 0.8 |
112
+ | romanized | 216 | 857 | 89.8 | 90.6 | 92.8 | 92.7 | 4.9 |
113
 
114
  ## By noise
115
 
116
  | value | docs | spans | F1 value | F1 exact | F1 partial | redaction R | neg-doc FP% |
117
  |---|---|---|---|---|---|---|---|
118
+ | clean | 1382 | 5612 | 90.3 | 91.1 | 93.2 | 94.5 | 0.9 |
119
+ | asr | 695 | 3338 | 83.3 | 84.4 | 90.0 | 89.3 | 0.0 |
120
+ | dialogue | 266 | 1619 | 93.1 | 93.3 | 94.0 | 94.8 | 0.0 |
121
+ | adversarial | 247 | 977 | 82.5 | 83.5 | 92.4 | 93.9 | 0.0 |
122
+ | structured | 239 | 971 | 90.4 | 90.9 | 92.3 | 95.7 | 0.0 |
123
+ | masked | 162 | 570 | 90.6 | 91.0 | 93.4 | 97.0 | 0.0 |
124
+ | code_logs | 118 | 363 | 87.5 | 88.0 | 88.0 | 88.9 | 0.0 |
125
+ | ocr | 74 | 348 | 90.4 | 90.8 | 92.2 | 95.7 | 0.0 |
126
+ | typos | 73 | 282 | 90.7 | 91.8 | 92.8 | 93.5 | 0.0 |
127
+ | typo | 53 | 221 | 97.1 | 97.1 | 98.0 | 99.9 | 0.0 |
128
+ | asr_digits | 32 | 152 | 82.2 | 83.2 | 88.9 | 95.4 | 0.0 |
129
+ | asr_sim | 18 | 78 | 83.7 | 83.7 | 85.0 | 96.2 | - |
130
+ | ocr_real | 10 | 48 | 73.9 | 75.3 | 81.7 | 78.2 | - |
131
+ | real_context | 3 | 12 | 69.6 | 69.6 | 78.3 | 93.1 | - |
132
 
133
  ## By length
134
 
135
  | value | docs | spans | F1 value | F1 exact | F1 partial | redaction R | neg-doc FP% |
136
  |---|---|---|---|---|---|---|---|
137
+ | short | 1694 | 6491 | 89.7 | 90.2 | 92.8 | 95.3 | 0.0 |
138
+ | medium | 1382 | 6526 | 88.0 | 89.1 | 92.5 | 92.7 | 0.0 |
139
+ | long | 203 | 1383 | 82.6 | 84.4 | 88.7 | 86.1 | 2.0 |
140
+ | very_short | 93 | 191 | 88.5 | 88.5 | 91.7 | 99.2 | 8.0 |
141
 
142
  ## By polarity
143
 
144
  | value | docs | spans | F1 value | F1 exact | F1 partial | redaction R | neg-doc FP% |
145
  |---|---|---|---|---|---|---|---|
146
+ | positive | 2636 | 14591 | 88.4 | 89.2 | 92.3 | 93.0 | - |
147
+ | negative | 736 | 0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.4 |
148
 
149
  ## By bucket
150
 
151
  | value | docs | spans | F1 value | F1 exact | F1 partial | redaction R | neg-doc FP% |
152
  |---|---|---|---|---|---|---|---|
153
+ | language_coverage | 881 | 4424 | 92.7 | 93.2 | 94.9 | 96.7 | 0.0 |
154
+ | monolingual_pure | 831 | 2987 | 87.4 | 88.3 | 91.0 | 91.9 | 1.1 |
155
+ | uncovered_scenarios | 469 | 1721 | 90.7 | 91.0 | 93.2 | 93.4 | 0.0 |
156
+ | asr_realism | 421 | 2257 | 82.1 | 83.4 | 89.7 | 89.0 | 0.0 |
157
+ | adversarial_format | 224 | 881 | 81.6 | 82.6 | 92.2 | 93.6 | 0.0 |
158
+ | compliance_identifiers | 156 | 760 | 93.1 | 93.8 | 95.4 | 96.9 | 0.0 |
159
+ | code_and_logs | 118 | 363 | 87.5 | 88.0 | 88.0 | 88.9 | 0.0 |
160
+ | targeted_rare_labels | 112 | 469 | 83.1 | 84.5 | 86.2 | 95.3 | 0.0 |
161
+ | targeted_sensitive_attributes | 47 | 148 | 79.0 | 80.7 | 87.6 | 90.7 | 0.0 |
162
+ | targeted_long_documents | 40 | 262 | 81.3 | 81.7 | 83.2 | 85.0 | 8.3 |
163
+ | targeted_hard_negatives | 38 | 0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
164
+ | targeted_org_agent_readback | 32 | 307 | 95.1 | 95.3 | 96.7 | 95.3 | 0.0 |
165
+ | inject | 3 | 12 | 69.6 | 69.6 | 78.3 | 93.1 | - |
 
 
 
 
 
 
166
 
167
  ## By script
168
 
169
  | value | docs | spans | F1 value | F1 exact | F1 partial | redaction R | neg-doc FP% |
170
  |---|---|---|---|---|---|---|---|
171
+ | Latin | 1522 | 6184 | 88.4 | 88.9 | 92.3 | 92.6 | 0.5 |
172
+ | latin | 639 | 3154 | 92.3 | 93.0 | 94.4 | 96.7 | 0.0 |
173
+ | native | 398 | 2030 | 93.3 | 93.8 | 95.8 | 96.8 | 0.0 |
174
+ | Devanagari | 111 | 403 | 85.0 | 87.1 | 91.2 | 92.7 | 0.0 |
175
+ | Arabic | 105 | 421 | 81.0 | 82.5 | 87.5 | 89.4 | 0.0 |
176
+ | Mixed | 104 | 398 | 84.7 | 85.9 | 90.5 | 92.9 | 0.0 |
177
+ | Telugu | 66 | 278 | 80.7 | 83.6 | 88.1 | 85.0 | 6.2 |
178
+ | Bengali | 65 | 257 | 80.9 | 83.0 | 85.9 | 83.5 | 0.0 |
179
+ | Tamil | 64 | 233 | 79.4 | 81.5 | 88.3 | 91.9 | 0.0 |
180
+ | Han | 64 | 311 | 80.3 | 81.2 | 90.1 | 91.2 | 0.0 |
181
+ | Gurmukhi | 53 | 198 | 86.2 | 87.4 | 89.4 | 94.6 | 0.0 |
182
+ | Kannada | 50 | 225 | 69.1 | 68.3 | 72.2 | 78.0 | 0.0 |
183
+ | Gujarati | 48 | 191 | 81.2 | 81.2 | 87.2 | 90.2 | 0.0 |
184
+ | Malayalam | 45 | 167 | 76.6 | 78.6 | 85.0 | 79.7 | 0.0 |
185
+ | Hangul | 21 | 77 | 82.1 | 82.6 | 87.7 | 92.5 | 0.0 |
186
+ | Cyrillic | 12 | 41 | 91.4 | 91.4 | 91.4 | 93.8 | 0.0 |
187
+ | Hiragana | 5 | 23 | 87.2 | 88.9 | 93.3 | 89.9 | 0.0 |
 
assets/per-language-results.json CHANGED
@@ -1,292 +1,263 @@
1
  {
2
- "Dutch": {
3
- "docs": 90,
4
- "f1": 96.4,
5
  "ci": [
6
- 94.3,
7
- 98.3
8
  ],
9
- "v2": 84.7,
10
- "gliner": 76.6
11
  },
12
- "Multilingual mix": {
13
- "docs": 120,
14
- "f1": 96.0,
15
  "ci": [
16
- 94.8,
17
- 97.1
18
  ],
19
- "v2": 86.3,
20
- "gliner": 72.9
21
  },
22
- "Romanized Indian language": {
23
- "docs": 118,
24
- "f1": 94.9,
25
  "ci": [
26
- 93.1,
27
- 96.6
28
  ],
29
- "v2": 87.3,
30
- "gliner": 72.3
31
  },
32
- "Simplified Chinese": {
33
- "docs": 100,
34
- "f1": 94.6,
35
  "ci": [
36
- 92.7,
37
- 96.2
38
  ],
39
- "v2": 84.0,
40
- "gliner": 57.3
41
  },
42
- "Indonesian": {
43
- "docs": 96,
44
- "f1": 93.8,
45
  "ci": [
46
- 91.7,
47
- 95.7
48
  ],
49
- "v2": 82.2,
50
- "gliner": 73.8
51
  },
52
  "Japanese": {
53
- "docs": 91,
54
- "f1": 93.6,
55
  "ci": [
56
- 91.4,
57
- 95.7
58
  ],
59
- "v2": 86.5,
60
- "gliner": 47.2
61
  },
62
- "Turkish": {
63
- "docs": 96,
64
- "f1": 93.1,
65
  "ci": [
66
- 91.2,
67
- 94.9
68
  ],
69
- "v2": 83.4,
70
- "gliner": 66.3
71
  },
72
- "Hindi": {
73
- "docs": 141,
74
- "f1": 92.9,
75
  "ci": [
76
- 90.8,
77
- 94.8
78
  ],
79
- "v2": 81.0,
80
- "gliner": 38.1
81
  },
82
- "English": {
83
- "docs": 1238,
84
- "f1": 92.8,
85
  "ci": [
86
- 91.9,
87
- 93.6
88
  ],
89
- "v2": 81.4,
90
- "gliner": 64.9
91
  },
92
- "Russian": {
93
- "docs": 96,
94
- "f1": 92.3,
95
  "ci": [
96
- 89.9,
97
- 94.8
98
  ],
99
- "v2": 80.8,
100
- "gliner": 63.8
101
  },
102
- "Telugu": {
103
- "docs": 174,
104
- "f1": 92.3,
105
  "ci": [
106
- 90.7,
107
- 93.8
108
  ],
109
- "v2": 70.9,
110
- "gliner": 38.1
111
  },
112
- "Korean": {
113
- "docs": 106,
114
- "f1": 92.2,
115
  "ci": [
116
- 90.1,
117
- 94.3
118
  ],
119
- "v2": 81.1,
120
- "gliner": 57.7
121
  },
122
- "Arabic": {
123
- "docs": 173,
124
- "f1": 91.7,
125
  "ci": [
126
- 89.7,
127
- 93.6
128
  ],
129
- "v2": 75.5,
130
- "gliner": 71.4
131
  },
132
- "Vietnamese": {
133
- "docs": 97,
134
- "f1": 91.7,
135
  "ci": [
136
- 89.1,
137
- 93.9
138
  ],
139
- "v2": 80.1,
140
- "gliner": 68.0
141
  },
142
- "Punjabi": {
143
- "docs": 118,
144
- "f1": 91.6,
145
  "ci": [
146
- 89.4,
147
- 93.7
148
  ],
149
- "v2": 78.5,
150
- "gliner": 42.5
151
  },
152
- "Portuguese": {
153
- "docs": 95,
154
- "f1": 91.5,
155
  "ci": [
156
- 88.8,
157
- 93.6
158
  ],
159
- "v2": 80.7,
160
- "gliner": 67.8
161
  },
162
- "Spanish": {
163
- "docs": 125,
164
- "f1": 91.4,
165
  "ci": [
166
- 89.3,
167
- 93.3
168
  ],
169
- "v2": 81.6,
170
- "gliner": 71.8
171
  },
172
- "Polish": {
173
- "docs": 98,
174
- "f1": 91.3,
175
  "ci": [
176
- 88.8,
177
- 93.8
178
  ],
179
- "v2": 82.1,
180
- "gliner": 73.3
181
  },
182
- "Kannada": {
183
- "docs": 156,
184
- "f1": 91.2,
185
  "ci": [
186
- 89.1,
187
- 93.1
188
  ],
189
- "v2": 72.7,
190
- "gliner": 43.8
191
  },
192
- "German": {
193
- "docs": 107,
194
- "f1": 91.1,
195
  "ci": [
196
- 88.5,
197
- 93.4
198
  ],
199
- "v2": 82.8,
200
- "gliner": 67.6
201
  },
202
  "Urdu": {
203
- "docs": 107,
204
- "f1": 90.7,
205
  "ci": [
206
- 88.3,
207
- 93.1
208
  ],
209
- "v2": 77.2,
210
- "gliner": 70.4
211
  },
212
- "Marathi": {
213
- "docs": 118,
214
- "f1": 90.6,
215
  "ci": [
216
- 88.2,
217
- 92.9
218
  ],
219
- "v2": 77.9,
220
- "gliner": 38.8
221
  },
222
- "Malayalam": {
223
- "docs": 156,
224
- "f1": 90.6,
225
  "ci": [
226
- 88.5,
227
- 92.4
228
  ],
229
- "v2": 70.3,
230
- "gliner": 41.1
231
  },
232
- "French": {
233
- "docs": 98,
234
- "f1": 90.5,
235
  "ci": [
236
- 87.6,
237
- 93.1
238
  ],
239
- "v2": 77.9,
240
- "gliner": 61.1
241
  },
242
- "Chinese": {
243
- "docs": 85,
244
- "f1": 90.2,
245
  "ci": [
246
- 85.5,
247
- 93.8
248
  ],
249
- "v2": 81.8,
250
- "gliner": 37.6
251
  },
252
- "Bengali": {
253
- "docs": 169,
254
- "f1": 90.1,
255
  "ci": [
256
- 88.0,
257
- 92.1
258
  ],
259
- "v2": 72.3,
260
- "gliner": 42.9
261
  },
262
- "Tamil": {
263
- "docs": 194,
264
- "f1": 89.9,
265
  "ci": [
266
- 87.6,
267
- 91.7
268
  ],
269
- "v2": 71.7,
270
- "gliner": 35.8
271
  },
272
- "Gujarati": {
273
- "docs": 112,
274
- "f1": 89.9,
275
  "ci": [
276
- 87.3,
277
- 92.5
278
  ],
279
- "v2": 76.8,
280
- "gliner": 42.3
281
  },
282
- "Italian": {
283
- "docs": 103,
284
- "f1": 87.4,
285
  "ci": [
286
- 84.1,
287
- 90.6
288
  ],
289
- "v2": 77.5,
290
- "gliner": 67.9
291
  }
292
  }
 
1
  {
2
+ "English": {
3
+ "docs": 994,
4
+ "f1": 89.3,
5
  "ci": [
6
+ 88.2,
7
+ 90.4
8
  ],
9
+ "gliner": 58.8
 
10
  },
11
+ "Spanish": {
12
+ "docs": 116,
13
+ "f1": 90.4,
14
  "ci": [
15
+ 87.1,
16
+ 92.8
17
  ],
18
+ "gliner": 68.4
 
19
  },
20
+ "Kannada": {
21
+ "docs": 80,
22
+ "f1": 74.6,
23
  "ci": [
24
+ 69.7,
25
+ 79.0
26
  ],
27
+ "gliner": 35.2
 
28
  },
29
+ "Tamil": {
30
+ "docs": 97,
31
+ "f1": 83.1,
32
  "ci": [
33
+ 78.6,
34
+ 87.2
35
  ],
36
+ "gliner": 32.5
 
37
  },
38
+ "Chinese": {
39
+ "docs": 84,
40
+ "f1": 85.9,
41
  "ci": [
42
+ 79.5,
43
+ 91.0
44
  ],
45
+ "gliner": 29.6
 
46
  },
47
  "Japanese": {
48
+ "docs": 85,
49
+ "f1": 91.8,
50
  "ci": [
51
+ 88.5,
52
+ 94.7
53
  ],
54
+ "gliner": 37.3
 
55
  },
56
+ "Marathi": {
57
+ "docs": 81,
58
+ "f1": 85.6,
59
  "ci": [
60
+ 81.8,
61
+ 89.3
62
  ],
63
+ "gliner": 35.0
 
64
  },
65
+ "French": {
66
+ "docs": 83,
67
+ "f1": 87.1,
68
  "ci": [
69
+ 83.2,
70
+ 90.9
71
  ],
72
+ "gliner": 58.3
 
73
  },
74
+ "German": {
75
+ "docs": 82,
76
+ "f1": 92.9,
77
  "ci": [
78
+ 90.1,
79
+ 95.1
80
  ],
81
+ "gliner": 66.0
 
82
  },
83
+ "Italian": {
84
+ "docs": 83,
85
+ "f1": 85.1,
86
  "ci": [
87
+ 79.6,
88
+ 90.8
89
  ],
90
+ "gliner": 67.8
 
91
  },
92
+ "Russian": {
93
+ "docs": 81,
94
+ "f1": 93.9,
95
  "ci": [
96
+ 91.2,
97
+ 96.1
98
  ],
99
+ "gliner": 59.2
 
100
  },
101
+ "Polish": {
102
+ "docs": 82,
103
+ "f1": 90.0,
104
  "ci": [
105
+ 86.0,
106
+ 93.1
107
  ],
108
+ "gliner": 69.2
 
109
  },
110
+ "Telugu": {
111
+ "docs": 82,
112
+ "f1": 80.6,
113
  "ci": [
114
+ 73.6,
115
+ 86.8
116
  ],
117
+ "gliner": 25.4
 
118
  },
119
+ "Hindi": {
120
+ "docs": 105,
121
+ "f1": 84.8,
122
  "ci": [
123
+ 80.8,
124
+ 88.5
125
  ],
126
+ "gliner": 39.0
 
127
  },
128
+ "Gujarati": {
129
+ "docs": 82,
130
+ "f1": 85.0,
131
  "ci": [
132
+ 81.6,
133
+ 89.0
134
  ],
135
+ "gliner": 40.6
 
136
  },
137
+ "Malayalam": {
138
+ "docs": 83,
139
+ "f1": 83.5,
140
  "ci": [
141
+ 77.8,
142
+ 88.6
143
  ],
144
+ "gliner": 31.3
 
145
  },
146
+ "Punjabi": {
147
+ "docs": 83,
148
+ "f1": 88.4,
149
  "ci": [
150
+ 84.9,
151
+ 91.6
152
  ],
153
+ "gliner": 32.9
 
154
  },
155
+ "Arabic": {
156
+ "docs": 82,
157
+ "f1": 81.3,
158
  "ci": [
159
+ 74.9,
160
+ 87.5
161
  ],
162
+ "gliner": 55.2
 
163
  },
164
+ "Dutch": {
165
+ "docs": 81,
166
+ "f1": 94.3,
167
  "ci": [
168
+ 91.6,
169
+ 97.0
170
  ],
171
+ "gliner": 74.7
 
172
  },
173
+ "Bengali": {
174
+ "docs": 87,
175
+ "f1": 82.2,
176
  "ci": [
177
+ 77.5,
178
+ 87.1
179
  ],
180
+ "gliner": 39.6
 
181
  },
182
  "Urdu": {
183
+ "docs": 80,
184
+ "f1": 87.6,
185
  "ci": [
186
+ 83.4,
187
+ 91.2
188
  ],
189
+ "gliner": 69.2
 
190
  },
191
+ "Vietnamese": {
192
+ "docs": 84,
193
+ "f1": 90.7,
194
  "ci": [
195
+ 87.8,
196
+ 93.5
197
  ],
198
+ "gliner": 64.8
 
199
  },
200
+ "Turkish": {
201
+ "docs": 83,
202
+ "f1": 92.6,
203
  "ci": [
204
+ 89.7,
205
+ 95.2
206
  ],
207
+ "gliner": 68.2
 
208
  },
209
+ "Indonesian": {
210
+ "docs": 83,
211
+ "f1": 89.2,
212
  "ci": [
213
+ 85.4,
214
+ 92.6
215
  ],
216
+ "gliner": 69.0
 
217
  },
218
+ "Portuguese": {
219
+ "docs": 83,
220
+ "f1": 86.3,
221
  "ci": [
222
+ 81.3,
223
+ 91.8
224
  ],
225
+ "gliner": 64.5
 
226
  },
227
+ "Korean": {
228
+ "docs": 80,
229
+ "f1": 91.4,
230
  "ci": [
231
+ 87.8,
232
+ 94.5
233
  ],
234
+ "gliner": 47.0
 
235
  },
236
+ "mixed": {
237
+ "docs": 80,
238
+ "f1": 92.0,
239
  "ci": [
240
+ 88.6,
241
+ 95.0
242
  ],
243
+ "gliner": 71.5
 
244
  },
245
+ "Simplified Chinese": {
246
+ "docs": 81,
247
+ "f1": 93.6,
248
  "ci": [
249
+ 90.8,
250
+ 95.9
251
  ],
252
+ "gliner": 52.7
 
253
  },
254
+ "Romanized Indian language": {
255
+ "docs": 85,
256
+ "f1": 92.2,
257
  "ci": [
258
+ 89.3,
259
+ 95.3
260
  ],
261
+ "gliner": 72.2
 
262
  }
263
  }
kavach_extract.py CHANGED
@@ -17,22 +17,22 @@ What it handles
17
  WebVTT cues and plain 'Speaker 1:' turns. Where the transcript has line breaks, windows prefer to cut on
18
  one, so a speaker turn or a subtitle cue stays whole; a transcript that arrives as a single unbroken line
19
  is simply cut on word boundaries. Timestamps are never treated as personal data, because the model was
20
- trained that way: 1,068 training documents contain bracketed timestamps and only one tags them.
21
  * Values repeated across the document. A name found once is masked at every occurrence.
22
  * Bad input: None, bytes, numbers, empty or whitespace-only strings, and model calls that fail or return
23
  something that is not JSON. Nothing raises; problems are reported in result["warnings"].
24
 
25
  Window defaults are measured, not guessed, and they are a compromise between two opposite failures.
26
 
27
- Too small and precision goes: on 92 real test documents of 180-385 words, a 50-word window scores 0.858
28
- precision against 0.893 for the same documents sent whole, because the model needs the surrounding sentence to
29
  tell a date of birth from an appointment date. Too large and recall goes: on 660-word inputs, recall falls from
30
- 0.92 at a 100-word window to 0.64 at 400, because a single answer stops short of listing everything in a long,
31
- dense input.
32
 
33
  120 words with 25 of overlap is near the top of both curves; 100 to 150 behaves about the same. Do not drop
34
- below about 60, and do not go past about 180. Keep the overlap at 20 or more, or a long address can straddle an
35
- edge and be seen whole by neither window. A document shorter than the window is sent in one call untouched.
36
  """
37
 
38
  from __future__ import annotations
@@ -44,12 +44,14 @@ import unicodedata
44
  __all__ = ["extract_pii", "redact", "LABELS", "INSTRUCTION", "build_prompt"]
45
 
46
  LABELS = [
47
- "ADDRESS", "AGE", "API_KEY_TOKEN", "BANK_ACCOUNT", "BANK_CODE", "BIOMETRIC_DESCRIPTOR", "CARD_CVV",
48
- "CARD_EXPIRY", "CASE_ID", "CREDIT_DEBIT_CARD", "DATE_TIME", "DEVICE_ID", "DISABILITY", "DOB", "DRIVING_LICENSE",
49
- "EMAIL", "EMPLOYEE_ID", "ETHNICITY", "GENDER_SEX", "GEO_LOCATION", "HEALTH_ID", "INSURANCE_ID", "IP_ADDRESS",
50
- "LAB_ORDER_ID", "LICENSE_PLATE", "MAC_ADDRESS", "MEDICAL_RECORD_ID", "NATIONAL_ID", "ORGANIZATION", "PASSPORT",
51
- "PASSWORD_SECRET", "PAYMENT_ID", "PERSON", "PHONE", "POLITICAL_BELIEF", "PRESCRIPTION_ID", "RELIGION",
52
- "STUDENT_ID", "TRANSACTION_ID", "URL_PERSONAL", "USERNAME", "VIN", "VOTER_ID",
 
 
53
  ]
54
 
55
  INSTRUCTION = (
@@ -298,7 +300,7 @@ def extract_pii(
298
  with 20-30 of overlap all behave about the same, and both smaller and larger settings are worse, for
299
  different reasons. Text shorter than one window is sent in a single call.
300
  labels
301
- Restrict to a subset of the 43 labels, for example {"PERSON", "PHONE"}. Default: all.
302
  lenient
303
  Also match values case-insensitively when locating them. Slightly higher recall, slightly higher risk
304
  of matching the wrong occurrence.
@@ -314,7 +316,7 @@ def extract_pii(
314
  dict with keys
315
  spans list of {"start", "end", "label", "text"}, sorted, non-overlapping, offsets into the
316
  original string you passed in. A span also carries "partial": True when the value only
317
- occurred inside a longer run of text, which is rare (0.4% of predictions on the test set)
318
  and usually means speech-to-text ran two words together. Drop those if you would rather
319
  under-mask than mask across a word edge.
320
  entities list of unique {"label", "text"} in order of first appearance
@@ -430,7 +432,7 @@ def redact(text, spans, mask="[{label}]") -> str:
430
  # --------------------------------------------------------------------------------------------------
431
  # generate() adapters. Pick one.
432
 
433
- def transformers_generate(model, tokenizer, max_new_tokens=1024, batch_size=8):
434
  """generate() backed by a local transformers model."""
435
  import torch
436
 
@@ -454,8 +456,8 @@ def transformers_generate(model, tokenizer, max_new_tokens=1024, batch_size=8):
454
  return run
455
 
456
 
457
- def openai_generate(base_url="http://127.0.0.1:8000/v1", model="inboxpraveen/Kavach-PII-270M",
458
- api_key="EMPTY", max_tokens=1024, workers=4):
459
  """generate() backed by any OpenAI-compatible server: vLLM, SGLang or llama-server."""
460
  from concurrent.futures import ThreadPoolExecutor
461
  from openai import OpenAI
 
17
  WebVTT cues and plain 'Speaker 1:' turns. Where the transcript has line breaks, windows prefer to cut on
18
  one, so a speaker turn or a subtitle cue stays whole; a transcript that arrives as a single unbroken line
19
  is simply cut on word boundaries. Timestamps are never treated as personal data, because the model was
20
+ trained that way: 630 training documents contain bracketed timestamps and not one is tagged.
21
  * Values repeated across the document. A name found once is masked at every occurrence.
22
  * Bad input: None, bytes, numbers, empty or whitespace-only strings, and model calls that fail or return
23
  something that is not JSON. Nothing raises; problems are reported in result["warnings"].
24
 
25
  Window defaults are measured, not guessed, and they are a compromise between two opposite failures.
26
 
27
+ Too small and precision goes: on 92 real test documents of 180-385 words, a 50-word window scores 0.727
28
+ precision against 0.861 for the same documents sent whole, because the model needs the surrounding sentence to
29
  tell a date of birth from an appointment date. Too large and recall goes: on 660-word inputs, recall falls from
30
+ 0.86 at a 100-word window to 0.51 at 400, because the model emits about as many entities as the short documents
31
+ it was trained on and then stops.
32
 
33
  120 words with 25 of overlap is near the top of both curves; 100 to 150 behaves about the same. Do not drop
34
+ below about 80, and do not go past 250. Keep the overlap at 20 or more, or a long address can straddle an edge
35
+ and be seen whole by neither window. A document shorter than the window is sent in one call untouched.
36
  """
37
 
38
  from __future__ import annotations
 
44
  __all__ = ["extract_pii", "redact", "LABELS", "INSTRUCTION", "build_prompt"]
45
 
46
  LABELS = [
47
+ "AADHAAR_IN", "ADDRESS", "AGE", "API_KEY_TOKEN", "BANK_ACCOUNT", "BIOMETRIC_DESCRIPTOR", "CARD_CVV",
48
+ "CARD_EXPIRY", "CASE_ID", "CREDIT_DEBIT_CARD", "DATE_TIME", "DEVICE_ID", "DISABILITY", "DOB",
49
+ "DRIVING_LICENSE", "EMAIL", "EMPLOYEE_ID", "ETHNICITY", "GENDER_SEX", "GEO_LOCATION", "HEALTH_ID", "IBAN",
50
+ "INSURANCE_ID", "IP_ADDRESS", "LAB_ORDER_ID", "LICENSE_PLATE", "MAC_ADDRESS", "MEDICAL_RECORD_ID",
51
+ "NATIONAL_ID", "ORGANIZATION", "PAN_IN", "PASSPORT", "PASSWORD_SECRET", "PERSON", "PHONE",
52
+ "POLITICAL_BELIEF", "POSTAL_CODE", "PRESCRIPTION_ID", "RELIGION", "ROUTING_CODE", "SIGNATURE", "SSN_US",
53
+ "STUDENT_ID", "SWIFT_BIC", "TAX_ID", "TRANSACTION_ID", "UPI_VPA", "URL_PERSONAL", "USERNAME", "VIN",
54
+ "VOTER_ID", "WALLET_ID",
55
  ]
56
 
57
  INSTRUCTION = (
 
300
  with 20-30 of overlap all behave about the same, and both smaller and larger settings are worse, for
301
  different reasons. Text shorter than one window is sent in a single call.
302
  labels
303
+ Restrict to a subset of the 52 labels, for example {"PERSON", "PHONE"}. Default: all.
304
  lenient
305
  Also match values case-insensitively when locating them. Slightly higher recall, slightly higher risk
306
  of matching the wrong occurrence.
 
316
  dict with keys
317
  spans list of {"start", "end", "label", "text"}, sorted, non-overlapping, offsets into the
318
  original string you passed in. A span also carries "partial": True when the value only
319
+ occurred inside a longer run of text, which is rare (0.6% of predictions on the test set)
320
  and usually means speech-to-text ran two words together. Drop those if you would rather
321
  under-mask than mask across a word edge.
322
  entities list of unique {"label", "text"} in order of first appearance
 
432
  # --------------------------------------------------------------------------------------------------
433
  # generate() adapters. Pick one.
434
 
435
+ def transformers_generate(model, tokenizer, max_new_tokens=768, batch_size=8):
436
  """generate() backed by a local transformers model."""
437
  import torch
438
 
 
456
  return run
457
 
458
 
459
+ def openai_generate(base_url="http://127.0.0.1:8000/v1", model="inboxpraveen/Kavach-PII-270M-v2",
460
+ api_key="EMPTY", max_tokens=768, workers=4):
461
  """generate() backed by any OpenAI-compatible server: vLLM, SGLang or llama-server."""
462
  from concurrent.futures import ThreadPoolExecutor
463
  from openai import OpenAI
model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:89f8bff488301a5ca8bf3bed7638421297041df7df75a6013eac3ab2def64703
3
  size 536223056
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f023ed8ce3da48e0c285220d2be600648059130d45328bd34819a3ecff2bdee6
3
  size 536223056
pii_config.json CHANGED
@@ -11,11 +11,11 @@
11
  },
12
  "bits4": false,
13
  "labels": [
 
14
  "ADDRESS",
15
  "AGE",
16
  "API_KEY_TOKEN",
17
  "BANK_ACCOUNT",
18
- "BANK_CODE",
19
  "BIOMETRIC_DESCRIPTOR",
20
  "CARD_CVV",
21
  "CARD_EXPIRY",
@@ -32,6 +32,7 @@
32
  "GENDER_SEX",
33
  "GEO_LOCATION",
34
  "HEALTH_ID",
 
35
  "INSURANCE_ID",
36
  "IP_ADDRESS",
37
  "LAB_ORDER_ID",
@@ -40,19 +41,27 @@
40
  "MEDICAL_RECORD_ID",
41
  "NATIONAL_ID",
42
  "ORGANIZATION",
 
43
  "PASSPORT",
44
  "PASSWORD_SECRET",
45
- "PAYMENT_ID",
46
  "PERSON",
47
  "PHONE",
48
  "POLITICAL_BELIEF",
 
49
  "PRESCRIPTION_ID",
50
  "RELIGION",
 
 
 
51
  "STUDENT_ID",
 
 
52
  "TRANSACTION_ID",
 
53
  "URL_PERSONAL",
54
  "USERNAME",
55
  "VIN",
56
- "VOTER_ID"
 
57
  ]
58
  }
 
11
  },
12
  "bits4": false,
13
  "labels": [
14
+ "AADHAAR_IN",
15
  "ADDRESS",
16
  "AGE",
17
  "API_KEY_TOKEN",
18
  "BANK_ACCOUNT",
 
19
  "BIOMETRIC_DESCRIPTOR",
20
  "CARD_CVV",
21
  "CARD_EXPIRY",
 
32
  "GENDER_SEX",
33
  "GEO_LOCATION",
34
  "HEALTH_ID",
35
+ "IBAN",
36
  "INSURANCE_ID",
37
  "IP_ADDRESS",
38
  "LAB_ORDER_ID",
 
41
  "MEDICAL_RECORD_ID",
42
  "NATIONAL_ID",
43
  "ORGANIZATION",
44
+ "PAN_IN",
45
  "PASSPORT",
46
  "PASSWORD_SECRET",
 
47
  "PERSON",
48
  "PHONE",
49
  "POLITICAL_BELIEF",
50
+ "POSTAL_CODE",
51
  "PRESCRIPTION_ID",
52
  "RELIGION",
53
+ "ROUTING_CODE",
54
+ "SIGNATURE",
55
+ "SSN_US",
56
  "STUDENT_ID",
57
+ "SWIFT_BIC",
58
+ "TAX_ID",
59
  "TRANSACTION_ID",
60
+ "UPI_VPA",
61
  "URL_PERSONAL",
62
  "USERNAME",
63
  "VIN",
64
+ "VOTER_ID",
65
+ "WALLET_ID"
66
  ]
67
  }