One token at a time
When you ask an LLM a question, it does not write the whole answer in one flash. It writes the first word, then the second, then the third. Each new word is a guess based on the words that came before it.
This is called autoregressive generation. The model looks at everything it has written so far, including your prompt, and picks the next token that seems most likely.
Key idea: an LLM answers questions by repeatedly asking itself, “What word probably comes next?”
Because it works one token at a time, the model can write long answers. But it also means mistakes can creep in. If it picks a wrong word early, the rest of the answer may try to cover up that mistake rather than fix it.
The power of the prompt
The words you give the model are called the prompt. The prompt is the model’s starting point. A clear prompt usually gets a better answer than a vague one.
For example, “Explain photosynthesis” is okay. “Explain photosynthesis like I am in fifth grade, in three sentences” is much better. The model uses your instructions to steer its next-token guesses.
See it generate
Choose a prompt and watch a simulated LLM write an answer one token at a time. The token counter shows how many tokens have been generated.
Prompt matters
The same topic can get very different answers depending on how you ask. Pick a style below and see how the response changes.
Simple
“Explain gravity in one sentence.”
Detailed
“Explain gravity to a curious 10th grader.”
Creative
“Tell a short story about gravity.”
Sampling with temperature
LLMs do not pick the next word at random. They use a temperature setting to control how creative or careful the output is. This Python function shows the same idea with a tiny vocabulary.
Check yourself
Why might an LLM give a different answer to the same question if you ask it twice? Think about the role of probability and the prompt.
Sample answer: The model picks the most likely token at each step, but sometimes several tokens are almost equally likely. A small random choice can change the whole answer.
Quick quiz
1. How does an LLM write an answer?
2. What is a prompt?
3. Why can the same question get different answers?
Keep learning about AI
You know how an LLM answers one token at a time. Next, see how LLMs become agents that can take actions, not just write text.
Part of the “Are LLMs smarter than a 5th grader?” tutorial series.