From an example to a next-token prediction
easy 7 minGeneration is a sequence of conditional choices.
Video lesson · Chapter 1 of 4
The parcel dispatch desk
Theory
Read or listen first. About 2 min.
What it is
Generation is a sequence of conditional choices. During training a model learns which continuations reduce prediction error across many prefixes. At inference it runs the learned network on the current prefix, samples or selects a token, appends that token and repeats.
Why it exists
Prediction and verification answer different questions. A model can produce the day of the week that fits a sentence while having no access to the delivery schedule. Decide which answers may be generated from context alone and which must be checked against a record.
Which word follows the delivery notice?
Inside this chapter
Chapter sources- What is an LLM?
- A language model estimates a distribution over the next token from the prefix it has seen. Generating an answer means repeating that operation with an ever longer prefix. A fluent explanation of yesterday’s refund rules can therefore sound convincing even when the policy changed this morning. Supply current evidence when the answer depends on external facts.
At every step the model produces a score for each vocabulary entry, a decoder picks one, and the chosen token is glued onto the prefix before the next step. Nothing in that loop looks anything up: the only facts available are those absorbed during training and those placed in the prompt. That is why a model can describe last year's refund policy with total confidence. You notice the problem when answers are fluent but disagree with the current record, so log which evidence was in the prompt for each answer.
Example. Offer the prefix “The museum opens at” without its timetable. Compare two completions with the actual opening hours and mark the missing evidence.
Another example. A support bot asked about a parcel's delivery date can write a convincing weekday. Unless the carrier's tracking record for that order is in the prompt, that weekday is a plausible continuation, not a lookup.
A fluent guess is not a checked fact
Both completions read naturally. Only the supplied timetable can say which one is right. - Neural Networks Recap
- A layer multiplies its input by learned weights, adds a bias and applies a transformation. During training, a loss measures error and backpropagation assigns gradients to those weights. During ordinary inference the weights stay fixed. Correcting a chatbot in one conversation changes its input context, not its training parameters.
Training and inference run the same arithmetic but differ in what is allowed to change. In training, a loss compares the output with a target, backpropagation works out how much each weight contributed to the error, and an optimiser nudges every weight. In inference the weights are frozen and only the input varies. So when a user corrects a chatbot mid-conversation, the correction lives in the prompt for that session and vanishes when the session ends.
Example. A one-input unit with , and ReLU produces 5 at and 0 at . New inputs change outputs while the weights stay fixed.
One unit, fixed weights, different inputs
Input x w·x + b (w = 2, b = -1) ReLU output 3 5 5 1 1 1 0 -1 0 The weights never change between rows. Only the input does, so only the output does. - The "Next Token" Concept
- Given “the delivery arrived on”, the model scores every possible continuation. Selecting “Tuesday” appends that token and changes the distribution used by the next step. Training can score many positions together with a causal mask. Autoregressive generation still needs the previously selected token before it can extend that particular answer.
During training the model sees whole sentences at once and a causal mask stops each position from peeking at later ones, so it can learn from every position in parallel. Generation cannot do that, because the token at step five does not exist until step four has been chosen. This is why output length drives latency: every new token costs one more pass through the network.
Example. Start with two candidates, “red” and “blue.” After choosing “red,” ask for the next distribution using the entire new prefix, including that choice.
Another example. A coding agent writing a 300-token function performs 300 sequential decoding steps, even though the prompt of several thousand tokens was processed in one parallel pass.
Each choice becomes part of the next question - 1Prefix
The car is - 2Score candidatesred 0.55 · blue 0.45
- 3Choose one
red - 4Append
The car is red - 5Score againnew distribution from the longer prefix
Repeat: back to PrefixIllustrative probabilities. The loop repeats until a stop token or length limit.
- Probability Distributions Visualized
- Logits express relative preference on an unrestricted scale. Softmax converts them into nonnegative probabilities whose sum is one. Adding the same constant to every logit changes none of the probabilities. A token with twice another token’s probability can still lose a random draw.
Logits are raw preferences that can be any real number. Softmax exponentiates each one, which makes them all positive, then divides by the total so they sum to one. Because a common factor cancels top and bottom, only differences between logits matter. The probabilities describe how often each token would be drawn, not how likely the resulting statement is to be true.
Example. For logits [0, 0], each token receives 0.5. Adding 10 to both logits still gives [0.5, 0.5].
Shifting every logit changes nothing
Logits [0, 0] and [10, 10] both give [0.5, 0.5]. Only the gaps between logits matter. - The Chef Analogy
- Imagine a chef choosing an ingredient after tasting the dish so far. Salt changes which ingredient makes sense next. In generation, the prefix is the dish and the selected token changes the next distribution. The analogy stops at factual verification: a model can continue a recipe coherently without having tested the result.
The analogy is useful for one idea: each choice is conditioned on everything before it, and once made it changes what follows. It is misleading if it suggests the model has a goal for the finished dish or tests it. A model can write a coherent recipe it has never cooked, so treat checks against records as part of the application, not part of generation.
Example. Salt the soup before choosing the next ingredient. Compare with appending “Tuesday” before scoring the next word. Neither operation checks the carrier’s timetable.
Where the analogy holds and where it stops
Dish so far
The prefix. Everything already added shapes what comes next.
Next ingredient
The next token, chosen in light of the dish so far.
Salt changes the plan
Appending
Tuesdaychanges the next distribution, just as salt changes the next ingredient.Nobody tastes the result
The model never checks the carrier timetable. Verification is a separate step.
How it works
Step through the idea, or press Play.
Prefix. “Delivery arrives on”
Understand it
Worked example
Which word follows the delivery notice?
- 1
“Delivery arrives on”
The text ends before a weekday. Training examples have shaped likely continuations; no live shipping record has been consulted.
- 2
Mon 2 · Tue 1 · Fri 0
In this three-token example the decoder produces logits. Softmax turns their differences into probabilities of about 0.67, 0.24 and 0.09.
- 3
“Delivery arrives on Monday”
Choosing Monday appends one token. The next prediction uses the extended text. Nothing in that operation verifies a delivery date.
Convert scores to probabilities
Follow the handoffs
From logits to probabilities, by hand
| Token | Logit z | e^z | Probability |
|---|---|---|---|
| Monday | 2 | 7.39 | 0.665 |
| Tuesday | 1 | 2.72 | 0.245 |
| Friday | 0 | 1.00 | 0.090 |
| Sum | 11.11 | 1.000 |
Generate or check a record?
Summary
The whole topic in one minute.
The model scored possible strings. Delivery is an external fact that requires matching the shipment identity to a current record.
Prediction and verification answer different questions. A model can produce the day of the week that fits a sentence while having no access to the delivery schedule. Decide which answers may be generated from context alone and which must be checked against a record.