Repository navigation
feat(pii_remover): default NER to IndicBERTv2 Naamapadam model - #170
Open
AkhileshNegi wants to merge 1 commit into
Open
AkhileshNegi wants to merge 1 commit into
AkhileshNegi wants to merge 1 commit into
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 |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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