Flags offensive text in 12 Indian languages and English (Hindi, Bengali, Marathi, Tamil, Telugu, Kannada,
Malayalam, Gujarati, Punjabi, Odia, Assamese, Urdu, English), in native script, romanized or code-mixed, and says
why: profanity, insult, hate and sexual, plus an overall offensive flag. It is
InDIM-small (32M) fine-tuned for this task: about 6 ms for a short
comment on a CPU (8 threads).
A text can have any number of labels; none means clean. Precision, recall, F1 and PR-AUC of this model on the gold test set (below):
| Label | Yes when the text … | Precision | Recall | F1 | PR-AUC |
|---|---|---|---|---|---|
profanity |
uses a swear word, obscene word or vulgar expression, aimed at someone or not (judged by the words) | 0.95 | 0.53 | 0.68 | 0.87 |
insult |
attacks, demeans or abuses a specific person or group (name-calling, degrading comparisons, threats) | 0.86 | 0.46 | 0.60 | 0.82 |
hate |
attacks a group because of religion, caste, ethnicity, nationality, region, language, gender, sexual orientation or disability | 0.38 | 0.46 | 0.42 | 0.39 |
sexual |
sexually explicit text or a sexual proposition, including porn / escort / sex-chat advertising (judged by what it describes; curse words with a sexual literal meaning are profanity) |
0.90 | 0.82 | 0.86 | 0.92 |
offensive |
any of the four (a separate head; the most reliable single flag) | 0.85 | 0.91 | 0.88 | 0.95 |
The four labels are precise but miss many cases; offensive finds about 91% of offensive texts. Use offensive to
decide whether a text needs attention and the four labels to say why. News about crime, sex education, medicine,
criticism of a policy, and a word that is only mentioned or discussed are meant to be clean.
pip install -r requirements.txt
python example.py
from cbx_profanity import ProfanityClassifier # cbx_profanity.py is in this repository
clf = ProfanityClassifier(".") # folder with the model files; CPU or GPU
r = clf.classify("saala harami, teri aukaat kya hai")
r["offensive"], r["labels"] # flag and the labels at or above their thresholds
r["scores"] # score per label and for `offensive`
clf.classify_document(long_text) # 256-token chunks, highest score per label
python example.py prints (texts invented; the errors are the model's own, see Limitations):
clean - Thanks for sharing the recipe, my mother makes it the same way every Diwali.
clean - शाम को बारिश हो सकती है, छाता साथ रखना।
clean - நாளைக்கு கூட்டம் பத்து மணிக்கு தொடங்கும்.
OFFENSIVE profanity bc aaj traffic bahut kharab hai, ek ghanta phas gaya
OFFENSIVE insult,hate saala harami, teri aukaat kya hai
OFFENSIVE - What a stupid useless idiot, nobody asked for your opinion.
python onnx_example.py runs the same model with ONNX Runtime (onnx/model.onnx, fp32, same decisions as PyTorch on
1,000 of 1,000 gold texts).
"truncated": True).
For long documents use classify_document.Gold test set: 3,980 texts never used in training: about 300 social-media comments per language (none for Gujarati, Punjabi, Odia and Assamese, which have no labelled comment data) and about 107 web passages per Indic language. Each text was labelled by two LLMs independently following a written guide, with a third deciding their disagreements. No person reviewed the gold labels, so they contain errors. Also Hindi HateCheck (Röttger et al. 2022; hateful and non-hateful test cases written by experts).
Every model was fine-tuned with the same data and recipe (plain fine-tuning, learning rate picked on validation, thresholds tuned on validation); mean of 3 training runs unless marked.
| Model | Parameters | profanity | insult | hate | sexual | offensive | Macro F1 | Clean texts flagged ↓ | HateCheck-hi hate F1 / PR-AUC |
|---|---|---|---|---|---|---|---|---|---|
| InDIM-small (this model's base) | 32M | 0.709 | 0.640 | 0.436 | 0.851 | 0.880 | 0.703 | 5.9% | 0.31 / 0.749 |
| mmBERT-small | 140M | 0.751 | 0.676 | 0.460 | 0.851 | 0.887 | 0.725 | 5.3% | 0.36 / 0.742 |
| mmBERT-base (1 run) | 307M | 0.753 | 0.691 | 0.505 | 0.873 | 0.889 | 0.742 | 3.9% | 0.53 / 0.759 |
| IndicBERT v2 | 278M | 0.690 | 0.719 | 0.450 | 0.863 | 0.888 | 0.722 | 4.7% | 0.41 / 0.744 |
"Clean texts flagged": share of the 1,693 gold texts with none of the four labels on which any label fires.
insult and
profanity; it ranks HateCheck cases about as well as mmBERT-base (PR-AUC) but flags fewer of them at its
threshold. Choose it when speed or CPU cost matters more than the last points of recall.CPU latency (Intel i7-10700, 8 threads, one text at a time, PyTorch fp32): 6.2 ms for a 28-token comment, 24 ms for a full 256-token chunk. fp16 is exact; ONNX int8 changed 7% of decisions in our test, so only the fp32 ONNX file is provided.
hate is weak. On the gold set most hate flags are wrong (often strong personal abuse with no identity
target) and it finds less than half of hateful texts; on Hindi HateCheck it finds about a quarter. Do not rely on
it to find hate speech, and check every hate flag.insult recall 0.46): rude but not vulgar words such as "idiot" or "bewakoof"
often score below the threshold.hate) are one reasonable reading, not the only one.Intended use: helping people moderate user-generated content at scale: prioritising, filtering or routing texts for review, and measuring abuse in aggregate. Not intended for automatic penalties against individual users, for law enforcement or surveillance, or for any decision about a person without human review. The model makes mistakes, more in some languages and communities than others. It is provided "as is", without warranties of any kind; Cobuild Tech Private Limited is not liable for its use. You are responsible for checking that it suits your data and for complying with the laws that apply to your use.
InDIM-small (32M) fine-tuned on social-media comments from public datasets and web text in the 13 languages, labelled to the written guide by LLMs (plain fine-tuning, five sigmoid heads, learning rate 4e-4, thresholds per label picked on validation). The source datasets are credited in NOTICE.
If you use this model, please cite InDIM-small (32M).
Apache-2.0 (see LICENSE). Dataset credits and licences: see NOTICE.
Questions: hello@cobuildx.ai.
onnx/model.onnx 126 MBmodel.safetensors 126 MBCobuildX-AI/InDIM-small