text-classification ยท text ยท WASM ยท ~110 MB
A BERT fine-tuned on the Jigsaw toxic-comment data. It reads any text and emits six
independent toxicity signals โ toxic, severe toxic,
obscene, threat, insult, identity hate โ each a
0โ100% probability. This is defensive content-safety tooling: set a threshold, and triage what to
flag. Every score is computed on your device; no comment is ever sent to a server.
| Model | Xenova/toxic-bert (ONNX of unitary/toxic-bert) |
|---|---|
| Task / pipeline | text-classification ยท multi-label (per-label sigmoid, not softmax) |
| Labels | toxic ยท severe_toxic ยท obscene ยท threat ยท insult ยท identity_hate |
| Architecture | BERT-base (12-layer) fine-tuned on the Jigsaw Toxic Comment Classification corpus |
| Quantization | q8 (8-bit) ONNX |
| Backend | WebAssembly (runs anywhere; no WebGPU needed) |
| Download | ~110 MB, cached after first load |
| License | Apache-2.0 |
| Web APIs | WebAssembly, Web Workers โ all Baseline widely available |
Type or paste a comment; it re-scores automatically a moment after you stop typing. The moderation threshold decides the verdict: if any label lands at or above it, the comment is flagged for review โ otherwise it's allowed. The samples below are deliberately hostile so you can see the classifier separate them from the benign one.
A sentiment model picks one winner with a softmax (the scores sum to 100%). Toxicity is
multi-label: the model's final layer produces six raw logits, and
each passes through its own sigmoid independently. So a single comment can
be 0.99 toxic and 0.95 insult at once โ the columns below don't
add up to anything in particular, and that's the point. The table shows each label's raw logit next
to its sigmoid probability, so you can see exactly how the threshold turns numbers into a decision.
| Label | logit | sigmoid | vs threshold |
|---|
A softmax over these would force one
winner and hide the fact that this text is several kinds of bad at once. Independent sigmoids keep
every signal legible โ the moderation queue can route a threat differently from an
obscene.
Moderation is a scale problem: no team can read every comment, DM, or review. A fast, private, offline toxicity score is a first line of defence โ it runs the instant someone hits submit, without the text ever leaving the tab, and hands a human queue only what actually needs eyes.
Score a single comment and read all six independent toxicity labels.
A moderation queue: paste many comments, set a threshold, auto-sort into flag / allow.
Edge cases โ sarcasm, reclaimed slurs, quoted abuse โ where the classifier's calibration shows its limits.
A toxicity gate in front of a sentiment model: only clean comments pass through to analysis.
The convenience path is one call; because the model is multi-label, ask for every label with topk: null:
import { pipeline } from "@huggingface/transformers";
const classify = await pipeline("text-classification", "Xenova/toxic-bert");
const out = await classify("you are worthless", { topk: null });
// โ [{ label: "toxic", score: 0.98 }, { label: "insult", score: 0.64 }, โฆ] (independent sigmoids)
This page goes one level deeper for "See inside": instead of the pipeline it runs the
tokenizer then the model() in a single forward pass, reads the raw
six-value logits tensor, and applies the sigmoid itself โ so it can show both the logit
and the probability, and apply your threshold. Same weights, same result. All of it runs in
a Web Worker so typing never janks.