โ† All models

text-classification ยท text ยท WASM ยท ~65 MB

DistilBERT SST-2 โ€” read the sentiment as you type

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.

At a glance

ModelXenova/distilbert-base-uncased-finetuned-sst-2-english
Task / pipelinetext-classification
LabelsPOSITIVE / NEGATIVE (binary; softmax over 2 logits)
ArchitectureDistilBERT (6-layer) fine-tuned on SST-2 (Stanford Sentiment Treebank)
Quantizationq8 (8-bit) ONNX
BackendWebAssembly (runs anywhere; no WebGPU needed)
Download~65 MB, cached after first load
LicenseApache-2.0
Web APIsWebAssembly, Web Workers โ€” all Baseline widely available

Run it

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.

See inside โ€” which words moved the needle

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.

Why it matters

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.

Use cases

Basics

Type text, get POSITIVE/NEGATIVE + confidence, updating live as you type.

Practical

Paste a batch of reviews and auto-triage them into positive / negative buckets.

Wild

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

How the API works

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.

References