text-classification ยท text ยท WASM ยท ~358 MB
Cardiff NLP's RoBERTa-large fine-tuned to detect hate speech aimed at a protected
characteristic. It reads any text and picks one of eight classes โ seven
kinds of targeted hate (gender, race, sexuality,
religion, origin, disability, age) plus
not_hate โ as a single softmax. This is a strictly narrower task than
toxicity or offensiveness: not everything rude is hate. It is an imperfect moderation
signal, not a verdict โ it reads surface words, has no speaker model, and carries its
training biases. Every score is computed on your device; no comment is ever sent to a server.
| Model | onnx-community/twitter-roberta-large-hate-latest-ONNX (ONNX of cardiffnlp/twitter-roberta-large-hate-latest) |
|---|---|
| Task / pipeline | text-classification ยท single-label (softmax over 8 classes) |
| Classes | hate_gender ยท hate_race ยท hate_sexuality ยท hate_religion ยท hate_origin ยท hate_disability ยท hate_age ยท not_hate |
| Architecture | RoBERTa-large (355M params, 24-layer) fine-tuned on the TweetHate benchmark (Cardiff NLP) |
| Quantization | q8 (8-bit) ONNX |
| Backend | WebAssembly (runs anywhere; no WebGPU needed) |
| Download | ~358 MB โ a large model; downloaded once, then cached. Best on a good connection; heavy for low-memory phones. |
| License | MIT |
| Web APIs | WebAssembly, Web Workers โ all Baseline widely available |
Type or paste text; it re-scores automatically a moment after you stop typing. The
hate threshold decides the verdict: if the combined hate probability
(1 โ not_hate) lands at or above it, the text is
flagged and the model names the targeted group โ otherwise
it's allowed. The samples show the difference between
rudeness and hate keyed to a protected characteristic.
The final layer produces eight raw logits, and a single softmax
turns them into competing probabilities that sum to 100%. Seven of those classes
are hate keyed to a protected characteristic; the eighth is not_hate. So the
model does two things at once: it decides whether the text is hateful (1 โ P(not_hate)) and, if so,
which group is targeted โ something a plain toxicity score can't tell you. The table shows
each class's logit beside its softmax probability.
| Class | logit | softmax | role |
|---|
Because the classes compete, a comment
that is nasty but not group-targeted lands on not_hate โ the model is deliberately
conservative about calling something hate. That is a feature for precision and a limitation for
recall: coded or novel hate can slip through.
Hate speech is a distinct, high-stakes category: platforms, regulators, and trust-and-safety teams treat protected-group attacks differently from ordinary rudeness. A model that not only flags hate but names the targeted characteristic lets you route, prioritise, and report it correctly โ and doing it on-device means sensitive text never leaves the tab.
race or religion hit to the specialist queue, not the generic spam bin.
Honesty note: this model reflects its training data (English tweets). It is conservative
โ reliable on explicit, surface-level attacks, but it lets a lot of coded, "polite", or subtle hate
through as not_hate (a recall gap), and it can encode demographic bias. Treat every
score as one signal that routes a human โ never a verdict, and never read not_hate
as proof that text is safe.
Score one comment: hate vs not-hate, and which protected group is targeted.
Moderation triage โ a queue sorted by hate probability, a signal for a reviewer, not a verdict.
Reclaimed language and edge cases where the model false-positives โ and why you can't auto-ban on it.
Hate vs toxicity, head to head: where a targeted-hate signal and a toxicity signal agree and diverge.
The convenience path is one call; ask for every class with topk: null:
import { pipeline } from "@huggingface/transformers";
const classify = await pipeline("text-classification", "onnx-community/twitter-roberta-large-hate-latest-ONNX");
const out = await classify("go back to your own country", { topk: null });
// โ [{ label: "hate_origin", score: 0.94 }, { label: "not_hate", score: 0.03 }, โฆ] (softmax over 8)
For "See inside" this page runs the tokenizer then the model() directly,
reads the raw eight-value logits, and applies the softmax itself โ so it can show both
the logit and the probability, compute the aggregate hate score (1 โ not_hate), and
apply your threshold. All of it runs in a Web Worker so typing never janks.