Field note

The weighted die behind every word

Every word a model writes is a sample, not a lookup. I built a small toy to make that visible, and it quietly changed how I read everything a model says.

Most of us talk to a language model every day now, and almost none of us have actually seen the one move it makes. It feels like the model knows the answer and types it out for you. That picture is wrong in a way that matters, so I built a small interactive toy, a next-token sampler you can poke at, mostly to force myself to look at the mechanism instead of the magic.

Here is the move. For the next word, a model assigns a score to every word it could possibly say, tens of thousands of them. A function called softmax squashes those scores into probabilities that add up to one. Then it rolls a weighted die: a word with twice the probability is twice as likely to come up. All of the intelligence lives in the scores. The act of speaking is a roll.

One giant face, or a fair-ish crowd

Look at "The capital of France is" and the distribution is a single skyscraper: "Paris" at ninety-something percent, everything else a sliver. Roll that die a hundred times and you get Paris a hundred times. Now look at "The old lighthouse keeper opened the door and saw" and the bars flatten right out, no clear winner, a long tail of plausible continuations. Same machine, completely different shape. The shape of the distribution is the model quietly telling you how sure it is, if you bother to look at it.

Temperature is a personality knob

The single most useful thing I took from building this is temperature. Just before that softmax step, every score gets divided by one number. Turn it down and the gaps between scores stretch, so the top word runs away with all the probability and the model becomes a careful, repetitive clerk. Turn it up and the gaps compress, unlikely words get a real shot, and the same model turns into a reckless poet. Same prompt, same scores, a wildly different writer. It is also the honest answer to "why did it say something different this time": you re-rolled a weighted die, and the seed was the only thing that changed.

Change one number, the temperature, and the same model swings from a clerk to a poet. The intelligence is in the scores; the personality is in how you roll.

Trimming the weird tail

Two more knobs handle the long tail of nonsense. top-k keeps only the k highest faces and throws the rest off the die. top-p, also called nucleus sampling, keeps the smallest group of faces whose probabilities add up to p, so it trims hard when the model is confident and barely at all when it is unsure. Both exist so a high temperature can add life without occasionally rolling a genuinely broken word. Turn sampling off entirely (greedy, always take the top face) and you get text that is safe, repeatable, and a little lifeless.

An honest toy

The honest caveat is this. The distributions in my version are hand-authored: four little sentences with plausible numbers I wrote by hand. A real model scores tens of thousands of tokens from billions of parameters, not a handful from me, and the grey "rest of the vocabulary" bar stands in for that whole tail. But the mechanism is not faked. Score, soften, trim, roll. That is the actual loop behind every chatbot you have ever used, run once per word, forever.

Trust the shape, not the magic. Once you can see the die, a chatbot stops being a wizard and starts being a process you can reason about.

What it changed

Building it rewired how I read model behavior. A hallucination stops looking like the model "lying" and starts looking like what it is: a confident roll from a distribution that happened to be wrong. "Just make it more accurate" stops being a coherent request once you can see that accuracy and creativity are partly the same dial. And the thing everyone finds spooky, that you can ask the exact same question twice and get two different answers, turns out to have the most boring explanation there is. You rolled the die again.

The toy is live if you want to roll it yourself: drag the temperature, watch the bars breathe, then hit roll and watch a sentence assemble one weighted-die throw at a time. I built it to understand something, and then left it running so you can poke at it too.

Adjacent reading

← Field notes · RSS