FlashChat
Engineering · Trust & Safety · NLP

How we built an abuse detection model for Hinglish and Indian languages

A 4-layer transformer distilled from MuRIL scores every public-room message on FlashChat before it is shown, in about a tenth of a second on an ordinary CPU. This is how we built it: the label taxonomy, the data, the training method, the benchmarks, and the places where it still falls short.

78%of abusive, sexual and threatening lines caught on our held-out set
1.3%of ordinary messages hidden by mistake at the live threshold
7languages and scripts, including romanized Hindi and Dravidian
141 MBONNX model, about 60M parameters, 4 encoder layers
~135 msfor a batch of 8 messages, CPU only
On this page
  1. Summary
  2. The problem
  3. What the model labels
  4. Where it runs
  5. Training data
  6. Training method
  7. How we measure
  8. Results
  9. What did not work
  10. Limitations
  11. Get the model or data
  12. FAQ
  13. References

00Summary

TL;DR

  • We classify each public-room message into one of seven labels. Three of them (abuse, sexual, threat) add up to a block score; above the line the message is folded behind “tap to view”, never refused.
  • A 12-layer MuRIL teacher is fine-tuned on about 220,000 lines from eight permissively licensed public datasets plus an in-house set (a ninth public set is kept for evaluation only), then distilled into a 4-layer student with a vocabulary cut from 197,258 to 40,000 tokens.
  • Only the embedding table is quantized to int8. Quantizing the attention and feed-forward weights doubled false alarms on counter-speech.
  • At a fixed budget of 1% of ordinary messages hidden, the current model (v13) catches 75% of harmful lines, up from 16% five versions earlier. The distilled student matches its 12-layer teacher at that budget.
  • It is weakest on counter-speech that names a group, indirect sexual requests, and romanized Dravidian slurs. We publish those numbers below.

01Why off-the-shelf filters fail in Indian chat

FlashChat is an anonymous chat platform for India. Its public rooms run in English and fourteen Indian languages, and most of what people type is none of those cleanly: it is code-mixed Hinglish in Roman letters, spelled the way it sounds, with the vowels dropped to save keystrokes. The same word appears as nahi, nhi, nai and nahin in one conversation.

We tried the obvious options first and each one failed in a specific way:

  • Word lists catch the bare slur and miss everything else. They also cannot tell a slur from an ordinary word with the same letters, a problem that multiplies across languages: a syllable that is abusive in one language is a food, a place or a name in another.
  • English toxicity models see romanized Hindi as noise. They score pass the salt as safe and a Hinglish threat as safe for the same reason.
  • A large language model per message works, but costs an API call for every line and adds up to a second of latency to every line.

We needed something that understands romanized and code-mixed text, answers in well under 300 ms on an ordinary CPU, fits in a few hundred megabytes of memory, and can be retrained every few days as people invent new spellings.

Design principle: hide, don’t block. A classifier will be wrong some of the time. When it is wrong about an ordinary message, a refusal silences someone for nothing. So a flagged message is still delivered, folded behind a notice anyone can tap to read, and the sender can say it was fine. That choice is what lets us run the model at a threshold aggressive enough to matter.

02What the model labels

The model reads one chat line (up to 64 tokens) and returns a probability for each of seven labels. A single “toxic or not” output was not enough: swearing at nobody in particular is normal chat, a person disclosing self-harm needs help rather than hiding, and an under-18 disclosure changes how every later message to them should be treated.

The seven labels
LabelMeaningCounts toward block score
okOrdinary chat, friendly teasing, rude-looking words used harmlessly, mild name-calling with no slurNo
swearProfanity not aimed at a person or a groupNo
abuseInsults with a slur, hate against a group (including religion, caste, region, gender), harassment aimed at someoneYes
sexualUnwanted sexual messages and requestsYes
threatViolence, doxxing and leak threats, telling someone to dieYes
self_harmThe writer wants to hurt themselvesNo (routed for support)
minorThe writer says they are under 18No (routed to moderators)

The block score is P(abuse) + P(sexual) + P(threat). Summing the three harmful classes, rather than taking the arg-max, means a line the model cannot place between “abuse” and “sexual” is still scored as harmful. One threshold on that sum is the only knob we turn in production.

Labelling rules matter as much as the architecture. A few we had to write down explicitly: a slur repeated while quoting or reporting it is still abuse; counter-speech that does not repeat the slur is fine; a put-down of a religion, its people or its customs is abuse even without a slur; a stereotype joke about caste, region or gender with no slur stays ok; English “you idiot” is ok.

03Where it runs

The model runs as its own small service on a separate machine inside our private network. The chat server sends public-room lines to it in batches and waits at most 300 ms.

Message path for a public-room line

Every step fails open: if the model is slow or unreachable, the message is delivered as normal.

Step 1
Message sent

A user posts a line in a public room. Our own daily room prompts are never scored.

Step 2
Word filter

Disallowed words are starred out for readers at the room’s level. The model still reads the line as typed.

Step 3
Text model

Batches of up to 8 lines, one batch in flight, 300 ms budget. Returns 7 probabilities per line.

Score < 0.856Delivered normally.
Score ≥ 0.856Delivered folded: “may be offensive, tap to view”. Sender can mark it fine.
Threat or under-18 ≥ 0.5Also placed first in the moderator review queue.
Timeout or errorDelivered normally; the late score is kept for review.
Folded lines, lines a reader chose to open, and lines a sender disputed are exported for review and become labelled training data for the next version.

Keeping the model in its own process was a lesson learned the hard way. ONNX Runtime’s session.run is synchronous on its calling thread; an early version ran next to our photo classifier and a burst of long batches froze photo checks for minutes. The text model now has its own service, its own memory limit and its own token, and the chat server talks to it over the private network only.

04Training data

The training set mixes three sources: public datasets with permissive licences, an in-house labelled set, and lines generated from the in-house set by rule-based augmentation. We list every public dataset by name. We do not publish or describe the in-house set beyond its size; see access if you need it.

Public datasets

Public datasets used (all permissively licensed)
DatasetLanguagesLicenceHow we use it
TextDetox Multilingual Toxicity1English, Hindi, HinglishOpenRAIL++Training: toxic → abuse, clean → ok
PRISM Hinglish Hate Speech2English, Hindi, Hinglish (29.5k)MITTraining
DynaHate3English (41,144)CC BY 4.0Training: adversarial lines written to fool models; 31 cases that overlap HateCheck removed
Measuring Hate Speech4English (17,956 kept)CC BY 4.0Training: hate score > 0.5 → abuse; supportive talk about a group → ok; the ambiguous middle dropped
DravidianLangTech Offensive5Tamil (37,901), Malayalam (16,559), Kannada (5,281)CC BY 4.0Training: targeted → abuse, untargeted → swear
Telugu Hate Speech6Telugu (35,142)CC BY 4.0Training
Hinglish Everyday Conversations 1M7HinglishMITShort everyday lines as ok; unlabelled text for distillation
SODA8EnglishCC BY 4.0Everyday dialogue as ok; unlabelled text for distillation
HateCheck + HateCheck Hindi9English, Hindi (7,293 cases)CC BY 4.0Evaluation only, never trained on

We left out datasets whose licence forbids commercial use (for example CC BY-NC sets) and datasets published without any licence file, even where they would have helped.

Cleaning the public data

Public toxicity sets are mostly long social-media comments, which look nothing like chat. Before training:

  1. Length filter. Lines over 200 characters are dropped.
  2. Conflict removal. 1,316 texts that two sources labelled in opposite ways were dropped entirely.
  3. Slice capping. Each source × language × label slice is capped at 2,500 lines so no single dataset dominates. The 281,046 public rows (87,666 toxic) become 120,329.
  4. Short-line rule. One- and two-word toxic lines are dropped unless they are known slurs (124 of 565 kept), because a lone “no” marked toxic in context teaches the model to hide “no”.
  5. Sexual-word rule. No public set has a sexual label, so their sexual lines arrive as “clean”. 452 such lines were dropped rather than taught as ok.
  6. Transliteration. 22,890 Devanagari Hindi lines were added again in Roman letters, which is how people actually type Hindi on a phone.

In-house data and augmentation

The in-house set has about 11,200 hand-labelled lines for the current version, written and reviewed by our team against the labelling rules above, with deliberate coverage of what public data lacks: sexual requests, threats, self-harm, under-18 disclosures, and hard negatives such as everyday words with a second meaning. 1,089 of them are held out and never trained on.

From the training part we generate 60,503 variants in code, imitating how people dodge filters: Hinglish spelling variants (hai → h, kya → kia), leetspeak (a→4, o→0), Cyrillic look-alike letters, slurs with letters spaced or symbols inserted, emoji tails, and lines wrapped in room calls like “… anyone here?”. Age introductions are generated from templates, half under 18 and half over, so the model learns the difference between “17 f” and “27 f”.

Final training mix, v13 teacher (220,334 lines)
LabelLinesShareShare bar
ok129,13758.6%
abuse55,26225.1%
sexual15,6727.1%
threat9,6994.4%
self_harm5,1002.3%
minor2,8561.3%
swear2,6081.2%

Rare classes have a floor of 600 training lines, and hand-labelled lines are repeated as spelling variants so a few thousand carefully labelled examples are not drowned by a hundred thousand public ones.

05Training method

Teacher: fine-tuned MuRIL

The starting point is MuRIL10, Google’s BERT-base model pre-trained on 17 Indian languages including their transliterated forms, which is exactly the property English models lack. We start from IIT Kharagpur CNERG’s checkpoint11 that already fine-tuned MuRIL on abusive speech in eight Indian languages, replace its head with our seven-way classifier, and fine-tune. Each new version continues from the previous version’s teacher rather than from scratch.

Teacher fine-tuning setup
ArchitectureBERT-base: 12 layers, hidden 768, 12 heads, ~237M parameters (most in a 197,258-token embedding table)
Max sequence length64 tokens (chat lines are short; also halves inference time)
OptimiserAdamW, learning rate 2e-5, batch size 32
Epochs3 to 5; the checkpoint is chosen by validation macro-F1 together with block recall, not by loss
HardwareOne cloud GPU; about 20 minutes per epoch
Data splitIn-house lines: train / threshold-tuning / held-out. The held-out set is frozen across versions so every model is compared on the same lines

We pick the checkpoint by recall on the harmful classes as well as macro-F1 because the two disagree: in one run the epoch with the best F1 caught fewer harmful lines than an earlier epoch with a slightly lower F1, and missed harm is what we are trying to reduce.

Student: distillation to 4 layers

The teacher is too slow and too large to run on every message. We distil it into a student with the same width but a third of the depth:

Teacher → student → served model

Teacher
layers
12
vocab
197,258
params
~237M
format
PyTorch fp32
distil on 140k+ lines
Student
layers
4
vocab
40,000
params
~60M
epochs
5 distillation
ONNX, int8 embeddings
Served
file
141 MB
runtime
ONNX Runtime
memory
~260 MB resident
speed
~135 ms / 8 lines
The student is initialised from teacher layers 0, 4, 7 and 11, so it starts with representations spread across the teacher’s depth instead of only its bottom layers.
  • Vocabulary pruning. MuRIL’s 197k-token vocabulary is 64% of its parameters. We keep the 40,000 tokens our corpus actually uses and check on a 5,000-line sample that the student produces exactly as many unknown tokens as the teacher (336 in both).
  • Layer selection. Student layers are copied from teacher layers 0, 4, 7 and 11.
  • Soft-label distillation. The student learns the teacher’s full probability distribution on 140,000 unlabelled lines (everyday Hinglish and English chat, plus public lines left over after capping) as well as the labelled set. The teacher’s uncertainty on ambiguous lines is information a hard label throws away.
  • Polish pass. A final pass over the hand-labelled lines (118,606 with variants) pulls the student back toward our own labelling rules.

Quantization: only the embeddings

Standard dynamic int8 quantization of every matrix multiply shrinks the model further, and on aggregate metrics it looks almost free: 91% of block decisions stay the same. On HateCheck’s non-hateful cases it was not free at all. False alarms on counter-speech and identity mentions went from 6% to 22–25%, even with the last layer kept in float.

Quantizing only the embedding lookup (op_types_to_quantize=['Gather']) keeps most of the size saving, because the embedding table is the largest tensor, and matches the float model on every test set. The served model is 141 MB.

Choosing the threshold

Training picks thresholds that maximise F2 on the validation split (recall weighted twice as heavily as precision). Production uses a different rule: we fix how many ordinary messages we are willing to fold, read the operating curve, and pick the threshold there. The live threshold of 0.856 sits where the curve flattens; lowering it to 0.485 would catch 4 more points of harmful lines while doubling the ordinary chat folded and adding 12 points of false alarms on counter-speech.

06How we measure

Aggregate accuracy is meaningless when 90% of chat is fine. We report two numbers side by side: the share of harmful lines caught (recall on abuse, sexual and threat) and the share of ordinary lines hidden (false-positive rate). Every model is evaluated on three sets it never saw in training:

Evaluation sets
SetSizeWhat it tells us
In-house held-out1,049Real-world style chat lines with our labels, frozen across versions. The headline numbers come from here.
Unseen everyday chat2,924Ordinary Hinglish and English conversation from sources never used in training. Measures false alarms on normal talk.
HateCheck (EN + HI)7,293Functional tests: negation, counter-speech, reclaimed slurs, identity mentions. Measures whether the model understands hate or just keywords.

When we compare versions we use equal-cost comparison: for each model, find the threshold at which it hides exactly 1%, 2% or 5% of ordinary held-out lines, then compare how many harmful lines each catches at that cost. Comparing models at the same nominal threshold is misleading, because two versions can put the same message at very different scores.

07Results

Six versions, one held-out set

Harmful lines caught at a 1% false-alarm budget

Each model at the threshold where it hides 1% of ordinary held-out lines.

Recall at 1% false-positive rate by model version v8 16%, v10 43%, v11 45%, v12 65%, v13 75%. v816% v1043% v1145% v1265% v13 (live)75%
Gridlines at 0, 25, 50, 75 and 100%. The jump from v11 to v12 came from targeted in-house lines for sexual requests and threats, a teacher picked by recall, and embedding-only quantization.
Harmful lines caught at equal cost (in-house held-out)
Model1% hidden2% hidden5% hidden
v816%39%60%
v1043%50%62%
v1145%54%67%
v12 (4-layer)65%76%82%
v12 teacher (12-layer)61%75%86%
v13 (4-layer, live)75%82%87%

The distilled 4-layer student matches or beats its 12-layer teacher at the 1% and 2% budgets, where we operate; the teacher only pulls ahead at 5%, a budget we would never run in production. That result convinced us not to serve a larger model: the limit is the data, not the model size.

The operating curve

Catch rate against ordinary messages hidden

Each point is one threshold, from 0.2 (right) to 0.983 (left). Up and to the left is better.

v13 (live)v12
Operating curves of v13 and v12 v13 sits above and to the left of v12 at every threshold. At the live threshold 0.856, v13 catches 78% of harmful lines while hiding 1.3% of ordinary ones; v12 at the same threshold catches 76% while hiding 2.1%. 90%85%80%75%70%65%60% 0%1%2%3%4%5% ordinary held-out messages hidden harmful lines caught live: 0.856 v13 v12
The y-axis starts at 60% to separate the curves. Hover or tap a point for its threshold. Full numbers are in the table below.
v13 at selected thresholds
ThresholdHarmful caughtHeld-out ordinary hiddenUnseen chat hiddenHateCheck harmless flaggedHateCheck hateful caught
0.98364%0.7%0.3%4%19%
0.92775%1.1%0.8%17%43%
0.856 (live)78%1.3%1.3%25%53%
0.780%1.6%2.1%32%62%
0.48582%2.1%2.5%37%68%
0.285%3.1%3.7%45%75%

By category

Recall per harmful category, v13 vs v12, at equal cost
BudgetModelAbuseSexualThreat
1% hiddenv1268%53%84%
1% hiddenv1377%70%79%
2% hiddenv1277%70%84%
2% hiddenv1383%79%87%

Sexual requests gained the most (53% → 70% at 1%), from in-house lines covering indirect requests. Threat recall dipped at the 1% budget, but the held-out set has only 38 threat lines, so a 5-point change is two lines; we treat it as a warning to watch, not a regression.

By language

On the test split of the full training mixture (public and in-house sources, 8,547 harmful lines), at the low training threshold of 0.05 where both models run in a high-recall mode:

Block recall and precision by language, at threshold 0.05
LanguageHarmful linesTeacher recallStudent recallStudent precision
English3,26690.2%88.8%70.0%
Hinglish (Roman)1,40782.2%80.9%66.1%
Hindi (Devanagari)1,19783.4%83.5%66.9%
Tamil94879.9%80.0%60.9%
Kannada62884.7%82.8%69.0%
Malayalam56288.6%82.9%69.4%
Telugu53986.8%84.4%77.8%
All8,54786.1%84.7%68.2%

Distillation costs about 1.4 points of recall overall, and most of that is in Malayalam (5.7 points). Hindi and Tamil lose nothing.

Production

Serving profile
HardwareA small CPU-only machine in our private network, shared with the photo checks
Latency~135 ms per batch of 8 lines in the model; ~190 ms round trip from the chat server
Budget300 ms, then the message is delivered and the score stored when it arrives
Memory~260 MB resident for the worker process
Cost per messageNo external API call; the model runs on our own machine

08What did not work

Most experiments made things worse. These are the ones worth knowing about before you try them:

QuantizationFull int8 quantization

91% decision agreement hid a fourfold rise in false alarms on counter-speech. Measure on functional tests, not only on aggregate agreement.

DistillationMatching hidden states

Adding a loss that copies the teacher’s [CLS] vector at each kept layer caught fewer harmful lines than plain soft-label distillation at every threshold.

Model sizeServing the 12-layer teacher

Several times slower per line and no better at a 1% budget (61% vs 65%). We did not deploy it.

EnsemblesTeacher + student together

Averaging or OR-ing the two raised catch rate by a few points but doubled false alarms on counter-speech. Not worth the cost.

DataMore generated lines

Two later runs added thousands of generated lines. Both lost to v13: identity groups named in harmful examples, without harmless twins naming the same groups, taught the model that any mention of a group is abuse.

ThresholdsScoring every version at 0.6

Each training run crushes scores differently; one version’s natural threshold was 0.05. Compare versions only at equal cost.

09Limitations and responsible use

  • Counter-speech and identity mentions. At the live threshold, 25% of HateCheck’s non-hateful cases are flagged. Sentences such as “I don’t hate them” or “I love being part of this community” that name a group are the most common false alarm. This is why the model folds instead of blocking.
  • Indirect sexual requests that use no explicit word are still the weakest harmful category.
  • Romanized Dravidian, Marathi and Bengali slurs. The 12-layer teacher recognises most of them; the 4-layer student loses many in distillation.
  • Small categories. Threat, self-harm and under-18 recall rest on a few dozen held-out examples each, so their numbers move by several points between versions.
  • Labels encode our policy. What counts as “abuse” here reflects FlashChat’s community rules for anonymous public rooms. Other platforms will draw lines differently, and should evaluate on their own data before relying on this model.
  • Not for punishment on its own. No account is penalised on the model’s score alone. Moderation actions are taken by people.

The model scores public rooms only. One-to-one stranger chats are held in memory and dropped when the chat ends, and Saved Chat between FlashBuddies is end-to-end encrypted, so neither passes through it. More on what is and is not stored is on our safety page.

10Get the model or the dataset

We make the model and our evaluation data available to researchers, trust & safety teams and companies working on Indian-language moderation. Tell us who you are and what you need.

Model weights

The 4-layer ONNX model with tokenizer and thresholds, or the 12-layer teacher checkpoint.

Evaluation set

Our frozen held-out set and scoring scripts, to benchmark your own models.

Training data

The in-house labelled set and labelling guidelines, under a written data agreement.

Please include your organisation, the artefact you want, your intended use (research or commercial), and any timeline. We read every request.

11Frequently asked questions

Does FlashChat block messages the model flags?

No. A public-room message that scores above the line is still delivered, folded behind a tap-to-view notice. The sender can mark it as fine. Nothing is refused because of the model, and if the model does not answer within 300 ms the message goes out normally.

Which languages does the model understand?

English, Hindi in Devanagari and in Roman letters, code-mixed Hinglish, and Tamil, Telugu, Kannada and Malayalam, including the romanized spellings people type on phones. Recall is lowest on romanized Dravidian slurs.

Is the model used on private one-to-one chats?

No. It scores messages in public rooms only. One-to-one chats are not stored unless someone reports them, and Saved Chat between FlashBuddies is end-to-end encrypted, so the server cannot read it.

Can I get the model or the dataset?

Yes, on request. Email [email protected] with your organisation, what you want (model, evaluation set or training data) and how you plan to use it. The in-house data is shared only under a written agreement.

12References

  1. TextDetox. Multilingual Toxicity Dataset. huggingface.co/datasets/textdetox/multilingual_toxicity_dataset
  2. PRISM Hinglish Hate Speech. huggingface.co/datasets/pankajbiswas6/prism-hinglish-hate-speech
  3. Vidgen, B., Thrush, T., Waseem, Z., Kiela, D. (2021). Learning from the Worst: Dynamically Generated Datasets to Improve Online Hate Detection. ACL. github.com/bvidgen/Dynamically-Generated-Hate-Speech-Dataset
  4. Kennedy, C. J. et al. (2020). Constructing interval variables via faceted Rasch measurement and multitask deep learning: a hate speech application. huggingface.co/datasets/ucberkeley-dlab/measuring-hate-speech
  5. Chakravarthi, B. R. et al. (2021). Findings of the Shared Task on Offensive Language Identification in Tamil, Malayalam, and Kannada. DravidianLangTech. huggingface.co/datasets/community-datasets/offenseval_dravidian
  6. Telugu Hate Speech. huggingface.co/datasets/mounikaiiith/Telugu-Hatespeech
  7. Hinglish Everyday Conversations 1M. huggingface.co/datasets/Abhishekcr448/Hinglish-Everyday-Conversations-1M
  8. Kim, H. et al. (2023). SODA: Million-scale Dialogue Distillation with Social Commonsense Contextualization. EMNLP. huggingface.co/datasets/allenai/soda
  9. Röttger, P. et al. (2021). HateCheck: Functional Tests for Hate Speech Detection Models. ACL; Röttger, P. et al. (2022). Multilingual HateCheck. WOAH. huggingface.co/datasets/Paul/hatecheck
  10. Khanuja, S. et al. (2021). MuRIL: Multilingual Representations for Indian Languages. arXiv:2103.10730. Apache 2.0.
  11. Das, M., Banerjee, S., Mukherjee, A. (2022). Data Bootstrapping Approaches to Improve Low Resource Abusive Language Detection for Indic Languages. ACM HT. Model: Hate-speech-CNERG/indic-abusive-allInOne-MuRIL (AFL-3.0).
  12. Hinton, G., Vinyals, O., Dean, J. (2015). Distilling the Knowledge in a Neural Network. arXiv:1503.02531.