Review sentiment analysis

Classify a restaurant review as positive or negative, without sending a single character to a server.

Referencedistilbert-base-uncased-finetuned-sst-2-english
Footprint68 MB
Pipelinetext-classification
RuntimeWebGPU / WASM

Local runtime test

Checking cache
Data inputReview text
ProbabilitiesAwaiting input

No run yet

Implementation

The same pipeline can be called from either Python or JavaScript.

inference_pipeline.py
from transformers import pipeline

classifier = pipeline(
    "text-classification",
    model="distilbert-base-uncased-finetuned-sst-2-english",
)
result = classifier("Best carbonara I've had outside Rome.")
print(result)
# [{'label': 'POSITIVE', 'score': 0.9998}]

What this does

Paste a restaurant review and this page classifies it as positive or negative. The model download and every inference run happen inside your browser tab. No text you type is ever sent to a server, and the demo keeps working even if you go offline once the model has loaded.

The model

This demo runs distilbert-base-uncased-finetuned-sst-2-english, a distilled version of BERT fine-tuned on the Stanford Sentiment Treebank (SST-2). DistilBERT keeps roughly 97% of BERT’s language understanding while being about 40% smaller and 60% faster, which makes it practical to download and run directly in a browser tab. The build used here is the Xenova/distilbert-base-uncased-finetuned-sst-2-english ONNX export, whose weights file is around 67 MB — the button quotes ~68 MB because the tokenizer travels with it — prepared for the transformers.js runtime.

How it works

  1. The page loads transformers.js, a JavaScript port of the Hugging Face transformers library that runs models with ONNX Runtime Web.
  2. On first use, the browser downloads the quantized model weights and caches them, so later visits skip the download entirely.
  3. Your review text is tokenized and run through the model locally, using WebGPU when it’s available and falling back to WebAssembly otherwise.
  4. The model outputs a label (POSITIVE or NEGATIVE) with a confidence score, which the page renders immediately.

Under the hood, DistilBERT is the model doing the classifying, fine-tuned on SST-2. Your text is first tokenized into subword ids, which are fed through the transformer encoder to produce contextual representations of the whole sequence. A small classification head on top of that encoder reduces those representations to two logits, one per class, and a softmax turns those logits into the positive/negative probabilities shown as the confidence score. Because the model was fine-tuned only on English movie reviews, it is English-only and can be confidently wrong outside that domain: a review in another language, or from a very different context such as legal or medical text, may still get a high-confidence label that is simply incorrect.

Limitations

This model knows two labels — positive and negative — and only the movie-review English it was fine-tuned on. Neutral, mixed, sarcastic or non-English text still gets one of the two labels, often with high confidence. Long or domain-specific prose, such as legal or medical writing, is outside what it learned.