Kavach: distilled IndicBERT v2, 6 layers, ONNX INT8

Binary offensive-content classifier for Hindi, Marathi and English in Devanagari, romanised (Latin script) and code-mixed text. Built for CPU serving as an input / output guardrail in an LLM gateway.

Research use only. The training data includes sources licensed CC BY-NC-SA 4.0 (L3Cube MahaHate, MeHate), so these weights are non-commercial. Not a production moderation model: see Limitations.

Live demo: https://kavach-d05v.onrender.com

What it is

  • Teacher: ai4bharat/IndicBERTv2-MLM-only fine-tuned with adversarial training (spacing, repeat, transliteration and emoji edits) on 58,457 texts plus 28,629 perturbed copies.
  • Student: the teacher with every other layer removed (12 to 6), trained with knowledge distillation (0.5 CE + 0.5 T^2 KL, T = 2).
  • Vocabulary pruned from 250,000 to the 57,005 token ids seen in training; vocab_map.npy maps every original token id to its new id (unused ids map to [UNK]) and must be applied before the model.
  • Exported to ONNX and quantised with dynamic INT8, per-channel, reduced range (chosen on validation).

Files

File
model.int8.onnx inputs input_ids, attention_mask, token_type_ids (int64, [batch, seq]); output logits [batch, 2], index 1 = offensive
tokenizer.json the original IndicBERT v2 fast tokenizer (unpruned ids)
vocab_map.npy int32 array of length 250,000: original id to pruned id
kavach.json max length 128, temperature 1.1708, block threshold 0.6359 (precision 0.90 on validation)

Usage (no torch needed): tokenise with tokenizers, map ids through vocab_map.npy, run with onnxruntime, softmax, compare P(offensive) with the threshold. Reference implementation: kavach/onnx_model.py in the project repository.

Evaluation (all from the project's result files)

Macro-F1 of this INT8 model, evaluated through the serving code:

Set Macro-F1
In-source test (7,308 texts, 5 sources) 0.862 [0.853, 0.870]
Held-out sources never trained on (HateEval Hindi + Marathi, 3,939) 0.742
HateCheck Hindi functional tests (3,565) 0.490
In-source, Latin script / Devanagari / mixed 0.788 / 0.907 / 0.922
  • Teacher (12 layers, FP32): 0.865 / 0.749 / 0.512. Same student trained on labels only: 0.855 / 0.736 / 0.456.
  • Character-level evasion: 46% of correctly flagged offensive texts are evaded by at least one edit family within three word edits.
  • At the precision-0.90 threshold: precision 0.898, recall 0.857 on in-source test; precision 0.657, recall 0.764 on held-out sources.
  • Size 83.8 MB; 4.2 ms p50 per text, batch 1, 4 threads on an Intel i7-11800H.

Limitations

  • Flags almost all counter-speech (text quoting or criticising hate) and many neutral mentions of identity groups as offensive: 0% correct on HateCheck's counter-speech tests.
  • In-source scores overstate performance on new sources by about 0.12 macro-F1.
  • The label merges hate, offensive, profane and aggressive content as each source defines it.
  • Romanised Marathi is represented by one small dataset; held-out sources are Devanagari only.
  • A threshold tuned on one distribution does not keep its precision on another: re-choose it per deployment.
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for Sharath1036/kavach-indicbert2-6l-int8

Quantized
(6)
this model