cbx-indim-profanity-detector-32M

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).

Labels

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.

Quick start

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).

Input

  • One comment, message or passage. The model reads at most 256 tokens; longer text is cut ("truncated": True). For long documents use classify_document.
  • Native script, romanized and code-mixed text are all supported. The model judges the text alone: it does not see the conversation, the image or the video a comment refers to.

Results

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.

  • This repository holds the training run with the best validation score: gold macro F1 0.688 (per label in the Labels table), clean texts flagged 7.7%, HateCheck-hi hate recall 0.26.
  • On this task InDIM-small is about 2 points of macro F1 below the larger models, mostly on 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.

Limitations

  • 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.
  • Mild insults are often missed (insult recall 0.46): rude but not vulgar words such as "idiot" or "bewakoof" often score below the threshold.
  • Gujarati, Punjabi, Odia, Assamese and native-script Urdu have little or no labelled comment data; expect more errors on comments in these languages.
  • Bias. Dialect words, caste and community terms, reclaimed words and counter-speech that quotes abuse can be flagged wrongly; mild words can be missed. Errors are not spread evenly across languages, scripts or communities.
  • Labels are from LLMs, not people, both for training and for the gold set. The guide's choices (for example, that criticism of a political party is not hate) are one reasonable reading, not the only one.
  • Context. The model sees one text. Sarcasm, quotes, in-group banter and comments about images or videos are often misread.

Intended use and disclaimer

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.

Training

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.

Citation

If you use this model, please cite InDIM-small (32M).

Licence

Apache-2.0 (see LICENSE). Dataset credits and licences: see NOTICE.

Questions: hello@cobuildx.ai.

Downloads last month
-
Safetensors
Model size
31.5M params
Tensor type
F32
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for CobuildX-AI/cbx-indim-profanity-detector-32M

Quantized
(4)
this model

Collection including CobuildX-AI/cbx-indim-profanity-detector-32M