Topic 1 of 5 · 4 min read
Generating one token at a time
Goal: Trace the generation loop for a short reply and explain why the model cannot go back and revise tokens it already wrote.
A language model writes by repeating one small step: it scores every possible next token, picks one, adds it to the text, and goes again.
Check yourself · 1 of 3
Which description matches how a language model generates a reply?
Why it matters
Chat tools such as ChatGPT, Claude, Gemini and Copilot feel like they think a whole answer and then type it out. They do not. Knowing the real loop explains why long answers drift, why a model cannot take back a sentence, and why the first few words of a reply matter so much.
How the loop works
A token is a chunk of text, often a word or part of a word. (If this is new, read the tokens skill first.) Each turn of the loop has four steps:
- Read. The model takes everything so far: your prompt plus any tokens it has already written.
- Score. It gives a probability to every token in its vocabulary. "The capital of France is" might give "Paris" a very high score and "Lyon" a tiny one.
- Pick. One token is chosen. A setting called temperature controls how much chance is allowed. Low temperature almost always takes the top token. Higher temperature sometimes takes a lower one.
- Append and repeat. The chosen token joins the text, and the loop starts again with the longer text. It stops when the model picks a special end-of-reply token or hits a length limit.
Here is the loop for the prompt "The capital of France is":
| Step | Text so far | Token picked |
|---|---|---|
| 1 | The capital of France is | Paris |
| 2 | The capital of France is Paris | . |
| 3 | The capital of France is Paris. | (end) |
No going back
Once a token is picked, it is part of the text. The model has no eraser. Its next step must continue from what is already there, even if that token was a poor choice. A human writer drafts, crosses out and rewrites. A model, on its own, only moves forward. Newer "reasoning" modes write extra thinking text first, but that is still one token at a time, and it works because the thinking text becomes part of the input.
Before and after
Before: "Is it safe to take ibuprofen with my blood pressure pill?" The model starts with "Yes, it is generally fine..." and now every following token has to support that opening.
After: "First list the facts that matter for this question, then give a yes or no at the end." The model writes the facts first. The answer comes last, so it can use them.
What goes wrong
- Early commitment. A wrong first word, such as "Yes" or "No", pulls the rest of the reply toward it.
- Drift in long answers. Each token depends on all the earlier ones, including the model's own mistakes.
- Asking the model to "go back". In a chat, it cannot edit its earlier text. It writes a new reply that may or may not fix the problem.
Examples
Tracing a short reply
Prompt: "Name a primary colour."
- Step 1: scores might be Red 40%, Blue 35%, Yellow 20%, other 5%. The model picks Blue.
- Step 2: the text is now "Blue". The next scores favour a full stop or "is". It picks a full stop.
- Step 3: the text is "Blue." and the model picks the end token.
Run it again and a higher temperature might pick Red at step 1. The rest of the reply then follows from Red.
Move the verdict to the end
Before: Should we migrate to the new supplier? Answer yes or no, then explain.
After: Compare the two suppliers on price, delivery time and reliability. Then give your recommendation in one sentence.
In the first version the model commits to yes or no before it has written any reasoning. In the second, the reasoning is already on the page when it reaches the recommendation.
Key points
- A model produces text by looping: score every possible next token, pick one, append it, repeat.
- The loop stops when the model picks an end-of-reply token or reaches a length limit.
- Temperature controls how much a lower-scored token can be chosen instead of the top one.
- A token that has been written stays in the text, so the model cannot revise it, only continue from it.
- Asking for the facts first and the verdict last gives the model something to build on before it commits.
Common mistakes
- Believing the model drafts a full answer in private and then types it out.
- Asking for the verdict in the first word and the reasoning afterwards.
- Expecting the model to quietly fix an earlier sentence while it keeps writing.
- Treating the probabilities as a list of answers the model has already checked.
Check yourself · 2 of 3
A model has written "The meeting is on Tuesday" but the correct day is Thursday. What can it do on its own, in the same reply?
Check yourself · 3 of 3
You ask: "Is this contract clause risky? Start with Yes or No, then explain." Why is that wording a weak choice?
Practice items, not counted towards your mastery.
Start here
- 3Blue1Brown: Large Language Models explained briefly (opens in a new tab)VideoFree
A short illustrated lesson (video and text) showing a model assigning a probability to every possible next word, then picking one.
- 3Blue1Brown: Transformers, the tech behind LLMs (opens in a new tab)VideoFree
A longer illustrated lesson on how a chat model turns text into a probability list for the next token and samples from it, again and again.
- LLM Visualization (Brendan Bycroft) (opens in a new tab)ToolFree
An interactive 3D model that shows a small GPT turning tokens into next-token probabilities.
More for this topic
- The Illustrated GPT-2 (Jay Alammar) (opens in a new tab)ArticleFree
Picture-based explanation of how a GPT model produces one token and feeds it back in.