language model

Watch how AI chooses its next word with real probabilities and temperature

Two runs, same prompt, same settings, and Qwen2.5-0.5B-Instruct split after one word: "The moon" versus "The lunar." That divergence is probability made visible. Watching softmax assign 78% to "moon" while "lunar" waits…

3 min readMachine Learning

The mechanics behind how an AI chooses its next word are often treated as either magic or marketing, but this explainer from Rajucg pulls back the curtain with a clarity that deserves attention. By running Qwen2.5-0.5B-Instruct on the same prompt twice and showing exactly where the paths diverge, they make a complex process feel tangible. This is the kind of hands-on transparency that builds real understanding, especially for anyone who has felt like AI outputs are arbitrary or opaque. It connects directly to the broader work we've seen in the community, such as how open source contributions can build your credibility in AI by sharing replicable experiments like this one, and how when AI deciphers a neural network's strategy from raw weights, we gain a deeper appreciation for the underlying logic.

What stands out is how the video grounds every claim in real numbers. After the model outputs "The," it scores all 151,936 vocabulary tokens: "moon" gets 78.04%, "lunar" gets 1.50%. A greedy decoder always picks "moon." Sampling with temperature 1 means "lunar" wins about once in 67 tries, and in the second run it did. That is not a vague "sometimes it's creative" handwave, it is a concrete probability you can verify. The explainer also shows temperature's effect: "moon" drops from 100% certainty at temperature 0.2 to just 6.3% at temperature 2.0. For anyone using AI tools in their workflow, this is the difference between predictable autocomplete and genuine exploration. The same step-by-step logic applies whether you are generating code, drafting copy, or analyzing data, understanding these controls lets you choose the behavior you actually need.

The video also tackles top-k and top-p sampling, including a crucial detail from the Holtzman et al. 2019 paper. At one step, the token "of" has 97.9% probability, so top-p 0.9 keeps only that single token, effectively forcing greedy behavior despite being a "sampling" method. At the model's default top-p of 0.8, "lunar" gets cut entirely. This matters because it shows that default settings can silently suppress diversity, even when users think they are enabling randomness. The lesson is not that one setting is better; it is that you need to know what each knob actually does.

One of the most surprising findings comes at the end: even temperature 0 can produce different outputs on a server. Thinking Machines ran Qwen3-235B 1,000 times and got 80 different answers, traced to batch-size-dependent addition order. That is a concrete, non-obvious consequence that any developer deploying models should know about. It means determinism is never guaranteed unless you control the full execution environment.

The takeaway is straightforward: if you work with AI, you should understand how token selection works at this level. Not because you need to tweak every parameter, but because the difference between a predictable output and a surprising one is not magic, it is a set of choices you can make deliberately. The next time a model gives you an unexpected result, you will know exactly where to look.

From Machine Learning

I made this explainer for my small channel and would like feedback from people learning this, especially if anything is wrong.

It follows one real example the whole way. I gave Qwen2.5-0.5B-Instruct "Write one sentence about the moon." twice with the same settings (temperature 1, no top-k or top-p, different seeds). Both answers start with "The", then split: "The moon, a satellite of the Earth…" vs "The lunar South Equatorial region…".

Read the original at Machine Learning