Text Generation
Transformers
Safetensors
gemma3_text
pii
pii-detection
privacy
redaction
anonymization
ner
token-classification
gdpr
hipaa
multilingual
gemma3
conversational
text-generation-inference
Instructions to use inboxpraveen/Kavach-PII-270M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use inboxpraveen/Kavach-PII-270M with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="inboxpraveen/Kavach-PII-270M") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("inboxpraveen/Kavach-PII-270M") model = AutoModelForCausalLM.from_pretrained("inboxpraveen/Kavach-PII-270M", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use inboxpraveen/Kavach-PII-270M with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "inboxpraveen/Kavach-PII-270M" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "inboxpraveen/Kavach-PII-270M", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/inboxpraveen/Kavach-PII-270M
- SGLang
How to use inboxpraveen/Kavach-PII-270M with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "inboxpraveen/Kavach-PII-270M" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "inboxpraveen/Kavach-PII-270M", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "inboxpraveen/Kavach-PII-270M" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "inboxpraveen/Kavach-PII-270M", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use inboxpraveen/Kavach-PII-270M with Docker Model Runner:
docker model run hf.co/inboxpraveen/Kavach-PII-270M
Upload 22 files
Browse files- README.md +210 -382
- adapter/adapter_config.json +3 -3
- adapter/adapter_model.safetensors +1 -1
- assets/01-headline-comparison.png +0 -0
- assets/full-test-report.md +142 -140
- assets/per-language-results.json +172 -201
- kavach_extract.py +20 -18
- model.safetensors +1 -1
- pii_config.json +12 -3
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 |
-
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
|
| 52 |
|
| 53 |
-
|
| 54 |
|
| 55 |
-
|
| 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 |
-
|
| 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 |
-

|
| 80 |
-
|
| 81 |
-
| Evaluation set | Documents | Kavach v2 | Kavach v3 | Change |
|
| 82 |
|---|---|---|---|---|
|
| 83 |
-
|
|
| 84 |
-
|
|
| 85 |
-
|
|
| 86 |
-
|
|
| 87 |
-
|
|
| 88 |
-
|
|
| 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 |
-
|
| 115 |
|
| 116 |
-
|
| 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","
|
| 152 |
-
"CASE_ID","CREDIT_DEBIT_CARD","DATE_TIME","DEVICE_ID","DISABILITY","DOB","DRIVING_LICENSE","EMAIL",
|
| 153 |
-
"ETHNICITY","GENDER_SEX","GEO_LOCATION","HEALTH_ID","INSURANCE_ID","IP_ADDRESS","LAB_ORDER_ID",
|
| 154 |
-
"MAC_ADDRESS","MEDICAL_RECORD_ID","NATIONAL_ID","ORGANIZATION","
|
| 155 |
-
"
|
| 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=
|
| 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 |
-
|
|
|
|
| 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=
|
| 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,
|
| 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
|
| 269 |
|
| 270 |
-
### Window size
|
| 271 |
|
| 272 |
-
The defaults below are measured, not reasoned about
|
| 273 |
|
| 274 |
-
|
|
|
|
|
|
|
| 275 |
|
| 276 |
| | Precision | Recall | Value F1 |
|
| 277 |
| --- | --- | --- | --- |
|
| 278 |
-
| Whole document, one call | 0.
|
| 279 |
-
| Windowed 250 / 40 | 0.
|
| 280 |
-
| Windowed 180 / 35 | 0.
|
| 281 |
-
| Windowed 150 / 30 | 0.
|
| 282 |
-
| Windowed 120 / 25 | 0.
|
| 283 |
-
| Windowed 100 / 20 | 0.
|
| 284 |
-
| Windowed 50 / 12 | 0.
|
| 285 |
|
| 286 |
-
|
| 287 |
|
| 288 |
-
**On text that runs past a few hundred words, recall falls away.** These are eight documents of
|
| 289 |
|
| 290 |
| Window / overlap | Precision | Recall | Value F1 | Model calls |
|
| 291 |
| --- | --- | --- | --- | --- |
|
| 292 |
-
| 30 / 8 | 0.
|
| 293 |
-
| 50 / 12 | 0.
|
| 294 |
-
| 100 / 20 | 0.
|
| 295 |
-
| 120 / 25 | 0.
|
| 296 |
-
| 150 / 30 | 0.
|
| 297 |
-
| 180 / 35 | 0.
|
| 298 |
-
| 200 / 40 | 0.
|
| 299 |
-
| 250 / 40 | 0.
|
| 300 |
-
| 400 / 80 | 0.
|
| 301 |
|
| 302 |
-
Precision holds up to 400 words; recall
|
| 303 |
|
| 304 |
-
**The default is 120 words with 25 of overlap**, near the top of both tables
|
| 305 |
|
| 306 |
-
|
| 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:
|
| 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.
|
| 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
|
| 328 |
|
| 329 |
-
| Outcome | Share of
|
| 330 |
| --- | --- |
|
| 331 |
-
| Located as a whole word | 98.
|
| 332 |
-
| Located only inside a longer run, flagged `partial` | 0.
|
| 333 |
-
| Not present in the text at all (hallucination) |
|
| 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:
|
| 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.
|
| 368 |
-
precision against 0.
|
| 369 |
tell a date of birth from an appointment date. Too large and recall goes: on 660-word inputs, recall falls from
|
| 370 |
-
0.
|
| 371 |
-
|
| 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
|
| 375 |
-
|
| 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", "
|
| 388 |
-
"CARD_EXPIRY", "CASE_ID", "CREDIT_DEBIT_CARD", "DATE_TIME", "DEVICE_ID", "DISABILITY", "DOB",
|
| 389 |
-
"EMAIL", "EMPLOYEE_ID", "ETHNICITY", "GENDER_SEX", "GEO_LOCATION", "HEALTH_ID", "
|
| 390 |
-
"
|
| 391 |
-
"
|
| 392 |
-
"
|
|
|
|
|
|
|
| 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
|
| 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.
|
| 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=
|
| 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=
|
| 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
|
| 942 |
* Use greedy decoding (`do_sample=False`, or `temperature: 0`). Sampling adds nothing on an extraction task and breaks JSON validity.
|
| 943 |
-
*
|
| 944 |
-
* Retry unparseable outputs once with `repetition_penalty=1.1`. Small models occasionally fall into a repetition loop
|
| 945 |
-
* Normalise case first if your input may contain
|
| 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 |
-

|
| 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 |
-
, `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
|
| 1106 |
-
|
| 1107 |
-
 | -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`
|
| 1140 |
| Dates, ages over 89 | `DOB`, `DATE_TIME`, `AGE` |
|
| 1141 |
| Telephone and fax | `PHONE` |
|
| 1142 |
| Email | `EMAIL` |
|
| 1143 |
-
| Social Security numbers | `
|
| 1144 |
| Medical record numbers | `MEDICAL_RECORD_ID` |
|
| 1145 |
| Health plan beneficiary numbers | `INSURANCE_ID`, `HEALTH_ID` |
|
| 1146 |
-
| Account numbers | `BANK_ACCOUNT`
|
| 1147 |
-
| Certificate and licence numbers | `DRIVING_LICENSE`, `EMPLOYEE_ID` (NPI, DEA, professional
|
| 1148 |
| Vehicle identifiers | `VIN`, `LICENSE_PLATE` |
|
| 1149 |
-
| Device identifiers | `DEVICE_ID`
|
| 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`,
|
| 1154 |
|
| 1155 |
-
Also covered: PCI (`CREDIT_DEBIT_CARD`, `CARD_EXPIRY`, `CARD_CVV`, `
|
| 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%)
|
| 1163 |
| Precision | base weights bf16 throughout, only the adapter was trained |
|
| 1164 |
-
| Data |
|
| 1165 |
-
| Schedule | 3 epochs,
|
| 1166 |
-
| Augmentation | 18 offset-safe corruption operations applied on the fly at p=0.
|
| 1167 |
-
| Hardware | one NVIDIA RTX 5060 Laptop GPU (8 GB),
|
| 1168 |
| Loss | cross-entropy on the assistant JSON only, prompt tokens masked out |
|
| 1169 |
|
| 1170 |
-
Best dev loss 0.
|
| 1171 |
|
| 1172 |
### Dataset
|
| 1173 |
|
| 1174 |
-
|
| 1175 |
|
| 1176 |
| Split | Documents | Values | PII-free |
|
| 1177 |
|---|---|---|---|
|
| 1178 |
-
| train |
|
| 1179 |
-
| dev | 3,
|
| 1180 |
-
| test |
|
| 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 |
-
|
| 1188 |
|
| 1189 |
-
|
| 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 |
-
*
|
| 1198 |
-
*
|
| 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 |
-
*
|
| 1203 |
-
* The
|
| 1204 |
-
* Independent evaluation on third-party corpora remains the obvious next step.
|
| 1205 |
|
| 1206 |
## Limitations
|
| 1207 |
|
| 1208 |
-
* **
|
| 1209 |
-
* **
|
| 1210 |
-
* **
|
| 1211 |
-
* **
|
| 1212 |
-
* **
|
| 1213 |
-
* **
|
| 1214 |
-
* **
|
| 1215 |
-
* **
|
| 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,
|
| 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
|
| 1234 |
-
author
|
| 1235 |
-
year
|
| 1236 |
-
version = {
|
| 1237 |
-
url
|
| 1238 |
-
note
|
| 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 |
+

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+

|
| 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 |
+

|
| 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 |
+

|
| 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 |
+

|
| 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:
|
| 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 |
-
#
|
| 2 |
|
| 3 |
-
docs=
|
| 4 |
|
| 5 |
| metric | P | R | F1 |
|
| 6 |
|---|---|---|---|
|
| 7 |
-
| value level (label, value) |
|
| 8 |
-
| exact span (micro) |
|
| 9 |
-
| partial span (micro) |
|
| 10 |
-
| redaction (char, type-agnostic) |
|
| 11 |
-
| macro F1 value / exact / partial | | |
|
| 12 |
|
| 13 |
-
negative docs:
|
| 14 |
|
| 15 |
## Per label
|
| 16 |
|
| 17 |
| label | values | pred | P value | R value | F1 value | spans | F1 exact | F1 partial |
|
| 18 |
|---|---|---|---|---|---|---|---|---|
|
| 19 |
-
| PERSON |
|
| 20 |
-
|
|
| 21 |
-
|
|
| 22 |
-
|
|
| 23 |
-
|
|
| 24 |
-
|
|
| 25 |
-
|
|
| 26 |
-
|
|
| 27 |
-
|
|
| 28 |
-
|
|
| 29 |
-
|
|
| 30 |
-
|
|
| 31 |
-
|
|
| 32 |
-
|
|
| 33 |
-
|
|
| 34 |
-
|
|
| 35 |
-
| CARD_CVV |
|
| 36 |
-
|
|
| 37 |
-
|
|
| 38 |
-
| USERNAME |
|
| 39 |
-
|
|
| 40 |
-
|
|
| 41 |
-
|
|
| 42 |
-
|
|
| 43 |
-
|
|
| 44 |
-
|
|
| 45 |
-
|
|
| 46 |
-
|
|
| 47 |
-
|
|
| 48 |
-
|
|
| 49 |
-
|
|
| 50 |
-
|
|
| 51 |
-
|
|
| 52 |
-
|
|
| 53 |
-
|
|
| 54 |
-
|
|
| 55 |
-
|
|
| 56 |
-
|
|
| 57 |
-
|
|
| 58 |
-
|
|
| 59 |
-
|
|
| 60 |
-
|
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
## By language
|
| 64 |
|
| 65 |
| value | docs | spans | F1 value | F1 exact | F1 partial | redaction R | neg-doc FP% |
|
| 66 |
|---|---|---|---|---|---|---|---|
|
| 67 |
-
| English |
|
| 68 |
-
|
|
| 69 |
-
|
|
| 70 |
-
|
|
| 71 |
-
| Bengali |
|
| 72 |
-
|
|
| 73 |
-
|
|
| 74 |
-
|
|
| 75 |
-
|
|
| 76 |
-
|
|
| 77 |
-
|
|
| 78 |
-
|
|
| 79 |
-
|
|
| 80 |
-
|
|
| 81 |
-
|
|
| 82 |
-
|
|
| 83 |
-
|
|
| 84 |
-
|
|
| 85 |
-
|
|
| 86 |
-
|
|
| 87 |
-
|
|
| 88 |
-
|
|
| 89 |
-
| Russian |
|
| 90 |
-
|
|
| 91 |
-
|
|
| 92 |
-
|
|
| 93 |
-
|
|
| 94 |
-
|
|
| 95 |
-
|
|
| 96 |
|
| 97 |
## By language_mode
|
| 98 |
|
| 99 |
| value | docs | spans | F1 value | F1 exact | F1 partial | redaction R | neg-doc FP% |
|
| 100 |
|---|---|---|---|---|---|---|---|
|
| 101 |
-
| monolingual |
|
| 102 |
-
| code_switch |
|
| 103 |
-
| romanized |
|
| 104 |
|
| 105 |
## By noise
|
| 106 |
|
| 107 |
| value | docs | spans | F1 value | F1 exact | F1 partial | redaction R | neg-doc FP% |
|
| 108 |
|---|---|---|---|---|---|---|---|
|
| 109 |
-
| clean |
|
| 110 |
-
| asr |
|
| 111 |
-
| dialogue |
|
| 112 |
-
| adversarial |
|
| 113 |
-
| structured |
|
| 114 |
-
| masked |
|
| 115 |
-
| code_logs |
|
| 116 |
-
| ocr | 74 |
|
| 117 |
-
| typos | 73 |
|
| 118 |
-
| typo |
|
| 119 |
-
| asr_digits | 32 |
|
| 120 |
-
| asr_sim | 18 |
|
| 121 |
-
| ocr_real | 10 |
|
| 122 |
-
| real_context | 3 | 12 |
|
| 123 |
|
| 124 |
## By length
|
| 125 |
|
| 126 |
| value | docs | spans | F1 value | F1 exact | F1 partial | redaction R | neg-doc FP% |
|
| 127 |
|---|---|---|---|---|---|---|---|
|
| 128 |
-
| short |
|
| 129 |
-
| medium |
|
| 130 |
-
| long |
|
| 131 |
-
| very_short | 93 |
|
| 132 |
|
| 133 |
## By polarity
|
| 134 |
|
| 135 |
| value | docs | spans | F1 value | F1 exact | F1 partial | redaction R | neg-doc FP% |
|
| 136 |
|---|---|---|---|---|---|---|---|
|
| 137 |
-
| positive |
|
| 138 |
-
| negative |
|
| 139 |
|
| 140 |
## By bucket
|
| 141 |
|
| 142 |
| value | docs | spans | F1 value | F1 exact | F1 partial | redaction R | neg-doc FP% |
|
| 143 |
|---|---|---|---|---|---|---|---|
|
| 144 |
-
| language_coverage |
|
| 145 |
-
| monolingual_pure |
|
| 146 |
-
| uncovered_scenarios |
|
| 147 |
-
| asr_realism |
|
| 148 |
-
|
|
| 149 |
-
|
|
| 150 |
-
|
|
| 151 |
-
|
|
| 152 |
-
|
|
| 153 |
-
|
|
| 154 |
-
|
|
| 155 |
-
|
|
| 156 |
-
|
|
| 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 |
|
| 169 |
-
| latin |
|
| 170 |
-
| native |
|
| 171 |
-
|
|
| 172 |
-
|
|
| 173 |
-
|
|
| 174 |
-
| Telugu |
|
| 175 |
-
| Bengali |
|
| 176 |
-
|
|
| 177 |
-
|
|
| 178 |
-
|
|
| 179 |
-
|
|
| 180 |
-
|
|
| 181 |
-
|
|
| 182 |
-
| Hangul |
|
| 183 |
-
| Cyrillic |
|
| 184 |
-
|
|
| 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 |
-
"
|
| 3 |
-
"docs":
|
| 4 |
-
"f1":
|
| 5 |
"ci": [
|
| 6 |
-
|
| 7 |
-
|
| 8 |
],
|
| 9 |
-
"
|
| 10 |
-
"gliner": 76.6
|
| 11 |
},
|
| 12 |
-
"
|
| 13 |
-
"docs":
|
| 14 |
-
"f1":
|
| 15 |
"ci": [
|
| 16 |
-
|
| 17 |
-
|
| 18 |
],
|
| 19 |
-
"
|
| 20 |
-
"gliner": 72.9
|
| 21 |
},
|
| 22 |
-
"
|
| 23 |
-
"docs":
|
| 24 |
-
"f1":
|
| 25 |
"ci": [
|
| 26 |
-
|
| 27 |
-
|
| 28 |
],
|
| 29 |
-
"
|
| 30 |
-
"gliner": 72.3
|
| 31 |
},
|
| 32 |
-
"
|
| 33 |
-
"docs":
|
| 34 |
-
"f1":
|
| 35 |
"ci": [
|
| 36 |
-
|
| 37 |
-
|
| 38 |
],
|
| 39 |
-
"
|
| 40 |
-
"gliner": 57.3
|
| 41 |
},
|
| 42 |
-
"
|
| 43 |
-
"docs":
|
| 44 |
-
"f1":
|
| 45 |
"ci": [
|
| 46 |
-
|
| 47 |
-
|
| 48 |
],
|
| 49 |
-
"
|
| 50 |
-
"gliner": 73.8
|
| 51 |
},
|
| 52 |
"Japanese": {
|
| 53 |
-
"docs":
|
| 54 |
-
"f1":
|
| 55 |
"ci": [
|
| 56 |
-
|
| 57 |
-
|
| 58 |
],
|
| 59 |
-
"
|
| 60 |
-
"gliner": 47.2
|
| 61 |
},
|
| 62 |
-
"
|
| 63 |
-
"docs":
|
| 64 |
-
"f1":
|
| 65 |
"ci": [
|
| 66 |
-
|
| 67 |
-
|
| 68 |
],
|
| 69 |
-
"
|
| 70 |
-
"gliner": 66.3
|
| 71 |
},
|
| 72 |
-
"
|
| 73 |
-
"docs":
|
| 74 |
-
"f1":
|
| 75 |
"ci": [
|
| 76 |
-
|
| 77 |
-
|
| 78 |
],
|
| 79 |
-
"
|
| 80 |
-
"gliner": 38.1
|
| 81 |
},
|
| 82 |
-
"
|
| 83 |
-
"docs":
|
| 84 |
-
"f1": 92.
|
| 85 |
"ci": [
|
| 86 |
-
|
| 87 |
-
|
| 88 |
],
|
| 89 |
-
"
|
| 90 |
-
"gliner": 64.9
|
| 91 |
},
|
| 92 |
-
"
|
| 93 |
-
"docs":
|
| 94 |
-
"f1":
|
| 95 |
"ci": [
|
| 96 |
-
|
| 97 |
-
|
| 98 |
],
|
| 99 |
-
"
|
| 100 |
-
"gliner": 63.8
|
| 101 |
},
|
| 102 |
-
"
|
| 103 |
-
"docs":
|
| 104 |
-
"f1":
|
| 105 |
"ci": [
|
| 106 |
-
|
| 107 |
-
|
| 108 |
],
|
| 109 |
-
"
|
| 110 |
-
"gliner": 38.1
|
| 111 |
},
|
| 112 |
-
"
|
| 113 |
-
"docs":
|
| 114 |
-
"f1":
|
| 115 |
"ci": [
|
| 116 |
-
|
| 117 |
-
|
| 118 |
],
|
| 119 |
-
"
|
| 120 |
-
"gliner": 57.7
|
| 121 |
},
|
| 122 |
-
"
|
| 123 |
-
"docs":
|
| 124 |
-
"f1":
|
| 125 |
"ci": [
|
| 126 |
-
|
| 127 |
-
|
| 128 |
],
|
| 129 |
-
"
|
| 130 |
-
"gliner": 71.4
|
| 131 |
},
|
| 132 |
-
"
|
| 133 |
-
"docs":
|
| 134 |
-
"f1":
|
| 135 |
"ci": [
|
| 136 |
-
|
| 137 |
-
|
| 138 |
],
|
| 139 |
-
"
|
| 140 |
-
"gliner": 68.0
|
| 141 |
},
|
| 142 |
-
"
|
| 143 |
-
"docs":
|
| 144 |
-
"f1":
|
| 145 |
"ci": [
|
| 146 |
-
|
| 147 |
-
|
| 148 |
],
|
| 149 |
-
"
|
| 150 |
-
"gliner": 42.5
|
| 151 |
},
|
| 152 |
-
"
|
| 153 |
-
"docs":
|
| 154 |
-
"f1":
|
| 155 |
"ci": [
|
| 156 |
-
|
| 157 |
-
|
| 158 |
],
|
| 159 |
-
"
|
| 160 |
-
"gliner": 67.8
|
| 161 |
},
|
| 162 |
-
"
|
| 163 |
-
"docs":
|
| 164 |
-
"f1":
|
| 165 |
"ci": [
|
| 166 |
-
|
| 167 |
-
|
| 168 |
],
|
| 169 |
-
"
|
| 170 |
-
"gliner": 71.8
|
| 171 |
},
|
| 172 |
-
"
|
| 173 |
-
"docs":
|
| 174 |
-
"f1":
|
| 175 |
"ci": [
|
| 176 |
-
|
| 177 |
-
|
| 178 |
],
|
| 179 |
-
"
|
| 180 |
-
"gliner": 73.3
|
| 181 |
},
|
| 182 |
-
"
|
| 183 |
-
"docs":
|
| 184 |
-
"f1":
|
| 185 |
"ci": [
|
| 186 |
-
|
| 187 |
-
|
| 188 |
],
|
| 189 |
-
"
|
| 190 |
-
"gliner": 43.8
|
| 191 |
},
|
| 192 |
-
"
|
| 193 |
-
"docs":
|
| 194 |
-
"f1":
|
| 195 |
"ci": [
|
| 196 |
-
|
| 197 |
-
|
| 198 |
],
|
| 199 |
-
"
|
| 200 |
-
"gliner": 67.6
|
| 201 |
},
|
| 202 |
"Urdu": {
|
| 203 |
-
"docs":
|
| 204 |
-
"f1":
|
| 205 |
"ci": [
|
| 206 |
-
|
| 207 |
-
|
| 208 |
],
|
| 209 |
-
"
|
| 210 |
-
"gliner": 70.4
|
| 211 |
},
|
| 212 |
-
"
|
| 213 |
-
"docs":
|
| 214 |
-
"f1": 90.
|
| 215 |
"ci": [
|
| 216 |
-
|
| 217 |
-
|
| 218 |
],
|
| 219 |
-
"
|
| 220 |
-
"gliner": 38.8
|
| 221 |
},
|
| 222 |
-
"
|
| 223 |
-
"docs":
|
| 224 |
-
"f1":
|
| 225 |
"ci": [
|
| 226 |
-
|
| 227 |
-
|
| 228 |
],
|
| 229 |
-
"
|
| 230 |
-
"gliner": 41.1
|
| 231 |
},
|
| 232 |
-
"
|
| 233 |
-
"docs":
|
| 234 |
-
"f1":
|
| 235 |
"ci": [
|
| 236 |
-
|
| 237 |
-
|
| 238 |
],
|
| 239 |
-
"
|
| 240 |
-
"gliner": 61.1
|
| 241 |
},
|
| 242 |
-
"
|
| 243 |
-
"docs":
|
| 244 |
-
"f1":
|
| 245 |
"ci": [
|
| 246 |
-
|
| 247 |
-
|
| 248 |
],
|
| 249 |
-
"
|
| 250 |
-
"gliner": 37.6
|
| 251 |
},
|
| 252 |
-
"
|
| 253 |
-
"docs":
|
| 254 |
-
"f1":
|
| 255 |
"ci": [
|
| 256 |
-
|
| 257 |
-
|
| 258 |
],
|
| 259 |
-
"
|
| 260 |
-
"gliner": 42.9
|
| 261 |
},
|
| 262 |
-
"
|
| 263 |
-
"docs":
|
| 264 |
-
"f1":
|
| 265 |
"ci": [
|
| 266 |
-
|
| 267 |
-
|
| 268 |
],
|
| 269 |
-
"
|
| 270 |
-
"gliner": 35.8
|
| 271 |
},
|
| 272 |
-
"
|
| 273 |
-
"docs":
|
| 274 |
-
"f1":
|
| 275 |
"ci": [
|
| 276 |
-
|
| 277 |
-
|
| 278 |
],
|
| 279 |
-
"
|
| 280 |
-
"gliner": 42.3
|
| 281 |
},
|
| 282 |
-
"
|
| 283 |
-
"docs":
|
| 284 |
-
"f1":
|
| 285 |
"ci": [
|
| 286 |
-
|
| 287 |
-
|
| 288 |
],
|
| 289 |
-
"
|
| 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:
|
| 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.
|
| 28 |
-
precision against 0.
|
| 29 |
tell a date of birth from an appointment date. Too large and recall goes: on 660-word inputs, recall falls from
|
| 30 |
-
0.
|
| 31 |
-
|
| 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
|
| 35 |
-
|
| 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", "
|
| 48 |
-
"CARD_EXPIRY", "CASE_ID", "CREDIT_DEBIT_CARD", "DATE_TIME", "DEVICE_ID", "DISABILITY", "DOB",
|
| 49 |
-
"EMAIL", "EMPLOYEE_ID", "ETHNICITY", "GENDER_SEX", "GEO_LOCATION", "HEALTH_ID", "
|
| 50 |
-
"
|
| 51 |
-
"
|
| 52 |
-
"
|
|
|
|
|
|
|
| 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
|
| 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.
|
| 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=
|
| 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=
|
| 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:
|
| 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 |
}
|