02 — Probability

The dials inside the model.

Same prompt, different settings, different answers. Drag temperature, top-K and top-P. Watch the candidate next-token bars rescale live. Click "set deterministic" to see what GenAI becomes when you remove the probability — and why that's not the win it looks like.

Illustrative data. These distributions are representative of how a small model like GPT-2 ranks its next-token candidates — one dominant token when the answer is obvious, a flat spread when it isn't. The re-weighting maths (temperature, top-K, top-P) below is the real thing, run live in your browser. Want the real model too? Hit Run GPT-2 live.

downloads ~45 MB once, then cached in your browser
Pick a prompt — the model will guess the next word
loading prompts…
The prompt · the model predicts the next token
Temperature 1.00
Low = play it safe, pick the favourite. High = take chances, spread the bets. The model's "creativity" knob.
top-K 20
Only ever consider the K most-likely words. Everything past rank K is thrown out before the model chooses.
top-P (nucleus) 1.00
Keep the smallest set of words whose chances add up to P, then drop the long tail. A smarter cut-off than a fixed K.
force temperature → 0: always pick the single most-likely word

Candidate next tokens — live probability

green = the model's top pick · faded = filtered out
pick a prompt above…
What am I actually dragging? (temperature, top-K, top-P)

The model never "decides". It draws.

For every next word, the model produces a probability distribution over its whole vocabulary — thousands of candidates, each with a chance. The bars above are the top twenty. The model then samples from that distribution: it rolls a weighted die. The dials change the shape of the die before it's rolled.

Temperature — the creativity knob.

Internally each candidate has a raw score (a logit). Temperature divides those scores before they're turned back into probabilities. Below 1, the gap between favourite and the rest grows — the model plays safe. Above 1, the gap shrinks — long-shot words get a real chance. At exactly 0, only the single favourite survives.

top-K and top-P — the cut-offs.

top-K says "only ever look at the K most-likely words." top-P (also called nucleus sampling) is cleverer: keep adding candidates from the top until their combined chance reaches P, then stop. Both exist to chop off the weird long tail — the thousands of words with a tiny but non-zero chance that occasionally produce nonsense.

Why this matters for your work.

The exact same prompt can give a different answer every time, by design. When a colleague says "the AI told me X," remember: X was one draw from a die whose shape someone else configured. Run it again and you might get Y. The output is not a fact the model looked up — it is a sample it generated.

So what is "deterministic"?

Click set deterministic and you pin temperature to zero. Now the favourite always wins; the randomness is gone. The answer is repeatable — but you have also thrown away the one thing that made it generative. That is the 98/2 Principle: the boring 98% of software is deterministic and predictable; the AI lives in the risky, probabilistic 2% at the edge. Turn the 2% off and you are back in the 98%.

Under the hood — see the full transformer (Poloclub)

The bars above are the model's output — the next-token probability distribution, the very last step. To see the mechanism that produces them — how your tokens flow through the embedding, the attention layers, and the stacked blocks before they collapse into that distribution — explore Poloclub's interactive Transformer Explainer, embedded live below. open in a new tab ↗

expanding… loading the Transformer Explainer