Mood Racer
Your words are fuel! A real AI reads what you type and decides: happy or grumpy? Happy sentences make your car zoom, grumpy ones make it crawl. Can you beat Grumpy Gus to the finish?
Word X-ray
Which words pushed the mood?
What's happening inside
Sentences that fooled it
- None yet. Try sarcasm!
How it works
Chop
Your sentence is cut into word pieces (“unhappy” becomes “un” + “##happy”) and each piece becomes a number.
Read together
Six layers of attention let every word look at every other word, so “not” can change what “bad” means.
Two scores
At the end it gives two scores, happy and grumpy, and turns them into chances that add up to 100%.
X-ray
To see which words mattered, we score the sentence again with each word taken out, all at once, and compare.
What just happened?
- The mood reader learned from thousands of movie reviews that people had already marked as happy or grumpy.
- It never understood your feelings. It learned which words and patterns usually go with happy or grumpy reviews.
- That's why sarcasm fools it: “Oh great, a flat tyre” is full of happy-sounding words but means the opposite.
- It can only answer happy or grumpy. Even a boring sentence like “The table is brown” gets pushed to one side (it says almost 0% happy!).
- The X-ray shows which words it leaned on. Sometimes it's surprising, and that's a clue about what it really learned.
For grown-ups: what's really going on
Model: Xenova/distilbert-base-uncased-finetuned-sst-2-english, an ONNX export of the Hugging Face distilbert-base-uncased-finetuned-sst-2-english checkpoint, loaded 8-bit quantised (q8, ~68 MB) with Transformers.js 3.8 on WebAssembly. DistilBERT is a 6-layer, 768-d, 12-head transformer encoder (~66 M parameters) distilled from BERT-base; a linear head on the [CLS] token outputs 2 logits (NEGATIVE, POSITIVE). It reports ~91% accuracy on the SST-2 dev set (binary sentiment of movie-review sentences).
- Pre/post-processing: lower-cased WordPiece tokenisation (30,522-token vocabulary),
[CLS] … [SEP], truncation at 512 tokens. We call the tokenizer and model directly (not the pipeline) to get raw logits, and showP(positive) = softmax(z)[1] = σ(zpos − zneg). - Quantisation side effects: the q8 file uses dynamic int8 quantisation, where activation scales are computed per call, so the same sentence can score slightly differently alone vs inside the padded X-ray batch. Fine for a game; for production, compare against fp32 on your own data.
- Scheduling: inference is debounced by 250 ms and serialised (never two runs at once; only the latest text is scored). A short sentence typically scores in roughly 10–50 ms on a laptop CPU.
- Word X-ray = occlusion / leave-one-out: for a sentence of n words we build n variants with one word deleted and score them in a single padded batch. Importance of word i is the change in log-odds
Δi = m(x) − m(x∖i)withm = zpos − zneg; we use log-odds rather than probabilities because p saturates (in “I am not happy with this terrible movie” only “not” moves p at all, since p ≈ 0.000 either way). A dashed box marks a word whose removal moves p across 0.5. Cost is n + 1 forward passes (we cap at 40 words). It ignores interactions: in “not bad”, deleting either word changes the meaning, so effects are not additive. Gradient-based methods (Integrated Gradients) or SHAP are more principled alternatives. - Race: target speed
v* = 4 + 26·pm/s, approached with a 0.7 s time constant; if no new words arrive for 4 s, a “fuel” multiplier decays to 0.35 so the race can't be won by pasting one sentence. Grumpy Gus drives at 17.5 m/s on the 1000 m track, so you need an average P(positive) of a bit over 0.5 from the start. - Known failure modes (all measured with this exact q8 model): negation (“This is not the worst day.” → about 20–30% positive here, while the full-precision original says 89%: 8-bit quantisation flipped a borderline case); sarcasm (“Oh fantastic, it is raining on my birthday.” → 99.98% positive); no neutral class (“The table is brown.” → 0.1% positive); domain shift (it was trained on movie reviews, not chat messages); and over-confidence in general (probabilities near 0 or 1 are not calibrated).
- Bias: the model card documents that otherwise identical sentences mentioning different countries or groups get noticeably different scores. Treat sentiment scores as a weak signal, never as a judgement about people, and audit on your own data before using one.
- Privacy: everything runs in the page; your text is never sent anywhere. Only the model files are downloaded from the Hugging Face hub and cached by the browser.
Further reading: Sanh et al., “DistilBERT” (2019) · Socher et al., Stanford Sentiment Treebank (2013) · model card (with bias notes).