text-classification ยท text ยท WASM ยท ~65 MB
A distilled BERT fine-tuned on movie reviews, it scores any text as POSITIVE or NEGATIVE with a confidence. Type below and watch the verdict update live โ then look inside to see exactly which words pushed it each way. Nothing leaves your device.
| Model | Xenova/distilbert-base-uncased-finetuned-sst-2-english |
|---|---|
| Task / pipeline | text-classification |
| Labels | POSITIVE / NEGATIVE (binary; softmax over 2 logits) |
| Architecture | DistilBERT (6-layer) fine-tuned on SST-2 (Stanford Sentiment Treebank) |
| Quantization | q8 (8-bit) ONNX |
| Backend | WebAssembly (runs anywhere; no WebGPU needed) |
| Download | ~65 MB, cached after first load |
| License | Apache-2.0 |
| Web APIs | WebAssembly, Web Workers โ all Baseline widely available |
Type anything. The verdict re-scores automatically (debounced) a moment after you stop typing. The dual meter shows the full probability split between the two classes.
This is occlusion attribution: we re-run the model with each word removed and see how much the POSITIVE score shifts (measured in log-odds, because the model is so confident that raw percentages barely budge). Remove a word that was pushing "positive" and the score drops โ so that word gets a green weight. Remove a negative word and the score rises โ red. No gradients, no hand-waving: just the model's own predictions, N+1 of them.
Sentiment is the entry point to understanding text at scale โ and doing it in the browser means you can react to how a user feels as they type, without a round-trip and without their words ever leaving the device. That unlocks fast, private, always-available text intelligence.
Type text, get POSITIVE/NEGATIVE + confidence, updating live as you type.
Paste a batch of reviews and auto-triage them into positive / negative buckets.
"Flip the sentiment" explorer โ find the words to change to swap the verdict.
See also the MiniLM multi-model demo, which ranks search hits with embeddings and then labels each hit's tone with this model.
Classification is one call; topk returns both class scores:
import { pipeline } from "@huggingface/transformers";
const classify = await pipeline(
"text-classification",
"Xenova/distilbert-base-uncased-finetuned-sst-2-english",
); // downloads + caches ~65 MB once
const out = await classify("best coffee all year", { topk: 2 });
// โ [{ label: "POSITIVE", score: 0.9998 }, { label: "NEGATIVE", score: 0.0002 }]
"See inside" re-uses that same call: it classifies the full text plus one copy per word with that word deleted (batched in a single pass), then subtracts the POSITIVE log-odds to attribute the shift to each word. All of it runs in a Web Worker so typing never janks.