Repository navigation
feat(pii_remover): default NER to IndicBERTv2 Naamapadam model - #170
Conversation
spaCy en_core_web_lg is English-only, so PERSON/LOCATION in Hindi, Marathi, Kannada, Telugu text were never detected and Hinglish was over-redacted. Switch the default engine to transformers with neuronsbyisshu/indicbert-hi-ner-naamapadam (CC0, ~0.3B params). spaCy en_core_web_sm stays for tokenization; nlp_engine_type="spacy" still works as a fallback. Regex recognizers are unchanged. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are limited based on label configuration. 🏷️ Required labels (at least one): 1
Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Comparison on the published 419-sample evaluation setThis is the same dataset behind the numbers on the docs page (Privacy Protection). The current docs figures (acc 0.84 / P 0.92 / R 0.80 / F1 0.86) reproduce exactly with spaCy
Regex entities (phone, email, IP, PAN, Aadhaar, passport, vehicle, voter) are byte-identical between the two runs. Notes on the dataset itself, affecting both models equally:
If this merges, the docs page should be updated to acc 0.89 / P 1.00 / R 0.82 / F1 0.90, response time ~0.04 s. |
Summary
pii_removerruns Presidio with spaCyen_core_web_lgfor NER. That model is English-only, so for Indian NGO traffic PERSON/LOCATION were effectively never detected in Hindi, Marathi, Kannada or Telugu text, and Hinglish was over-redacted (mera naam Rajesh Kumar hai→<PERSON>). Regex recognizers (phone, email, PAN, Aadhaar…) were fine since they are script-agnostic.This PR switches the default NER to
neuronsbyisshu/indicbert-hi-ner-naamapadam(IndicBERTv2 fine-tuned on Hindi Naamapadam, CC0, ~0.3B params, CPU-only) via the existingtransformersengine path. spaCyen_core_web_smstays for tokenization.nlp_engine_type="spacy"still works as a fallback. No new dependency, no API key, public HF repo.Changes:
pii_remover.py:DEFAULT_TRANSFORMERS_MODEL→ IndicBERT model,nlp_engine_typedefault →"transformers".Dockerfile: pre-download the new model instead ofdslim/bert-base-NER-uncased.pii-remover.md,DEVELOPER_GUIDE.md,ARCHITECTURE.md) updated.Evaluation
Row-by-row comparison sheet: https://docs.google.com/spreadsheets/d/1843aBnpVtFJu4SJDNFx3x6w-L445bp7-ucm955WwNQU/edit?usp=sharing (filter column J ≠
tieto see only rows where the models differ).Both runs use the same harness metrics as
app/evaluation/pii/run.py, with all 15 entity types enabled so NER is actually exercised.Dataset 1:
pii_multilang_3300.csv(3300 rows, 550 templates × 6 langs; names/locations in native script for hi/mr/kn/te)Sentence-level F1 (did the validator fire on a PII row):
en_core_web_lgValue recall for NER-dependent types (spaCy → IndicBERT):
Row-level wins (ties excluded): IndicBERT 722, spaCy 167. spaCy's 72 false positives on clean rows are mostly Hinglish junk tagged PERSON (
bhai,kitni hai); 11 of IndicBERT's 13 are real names the dataset marks as non-PII (Bill Gates, John Wick).Dataset 2:
pii_detection_testing_dataset.csv(419 rows, 300 en / 119 hi)Hindi PERSON recall 0.17 → 1.00, LOCATION 0.00 → 1.00.
Regex entities
Identical across both models on every dataset (PHONE/EMAIL/URL/IP/PAN/VOTER 1.00, CREDIT_CARD 0.94, PASSPORT 0.80, VEHICLE_REG 0.70, AADHAAR 0.2–0.4, IBAN 0.23, MEDICAL_LICENSE 0.15). The low ones are Presidio pattern / synthetic-data mismatches (invalid Verhoeff, spaced vehicle plates) and are out of scope here.
Cost
Checklist
app/tests/validators/test_pii_remover.py, 17 passed).Notes
NRPis not a label in this model, so it will not be detected (spaCy only got it for English anyway). Lone Latin-script first names inside Indic text (डॉ Aiswarya) are the weakest case (~0.45 recall).DEFAULT_ENTITY_TYPESstill excludes PERSON/LOCATION/NRP; this PR only changes which model answers when they are requested. Turning them on by default is a separate decision.ai4bharat/IndicNER(trained on all 11 Indic languages, MIT) once gated HF access is granted; same plug-in point, should lift kn/te name recall.en_core_web_lgso the spaCy fallback keeps working; can be dropped later to save ~600 MB.🤖 Generated with Claude Code