Next-token prediction
Also known as: next-word prediction
How a language model writes - it guesses the single most fitting next piece of text, adds it, and repeats until the answer is done.
Draft - this entry has not been reviewed yet.
Formal
The task at the heart of a large language model - from all tokens so far, work out how likely each possible next token is; during inference one is picked, added to the text, and the step repeats.
In plain English
Like finishing a well-known saying - hear “the early bird…” and “catches the worm” comes to mind - done over and over, one word at a time, until a whole answer stands.
In practice
A medical secretary at a hospital watches a chat assistant's draft letter appear word by word; when she stops it halfway, half a sentence is left, because each token is chosen only after all the ones before it.
Why it matters
The model aims for text that fits, not text that is checked, and each answer takes one step per token - which explains both how smooth it sounds and what it costs in money and time.
Technical deep dive
Formally, an autoregressive language model factorises the probability of a sequence as a product of conditionals, p(x1, ..., xn) = p(x1) · p(x2 | x1) · ... · p(xn | x1, ..., xn−1). At each position the network outputs a vector of logits, one per vocabulary entry (tens to hundreds of thousands of them), and a softmax turns these into a probability distribution over the next token. Training minimises the average negative log-likelihood of the actual next token, the cross-entropy loss; perplexity, the exponential of that loss, is the standard intrinsic metric.
Training is massively parallel because of teacher forcing and the causal mask. The whole ground-truth sequence is fed in at once, and the attention mask prevents position t from seeing positions after t, so one forward pass yields a loss term at every position simultaneously. Generation cannot be parallelised this way: each new token depends on the previous one, so producing n tokens requires n sequential forward passes. A KV cache avoids recomputing attention keys and values for earlier positions, making each step cost roughly proportional to the current length rather than recomputing the whole prefix, but the sequential dependency remains the main source of latency.
Several techniques attack that cost without changing the objective. Speculative decoding (Leviathan et al., 2023; Chen et al., 2023) lets a small draft model propose several tokens that the large model verifies in a single pass, accepting them with a rule that preserves the large model's output distribution exactly. Multi-token prediction heads (Gloeckle et al., 2024) train the model to predict several future tokens at once, which can be used for faster decoding. Diffusion-style language models replace left-to-right generation altogether but remain a minority approach.
The objective explains several documented quirks. Because each step conditions only on what came before, an early error is never revised, only continued; the model can talk itself into a wrong answer, which chain-of-thought and reasoning training partly exploit and partly counter. The "reversal curse" (Berglund et al., 2023) showed that models trained on "A is B" often fail to answer "B is A", a consequence of learning conditional continuations rather than symmetric facts. Next-token prediction is also why a model's confidence is not calibrated truth: a high-probability token is one that fits the pattern, which is the direct link to hallucination. Selecting the actual token from the distribution is a separate step, sampling, controlled by temperature, top-p and related settings.
What to learn first
Everything this builds on, foundations first.
Relationships
Sources & further reading
Reference works
- Radford et al. (2019), Language Models are Unsupervised Multitask Learners
Textbooks
- Jurafsky & Martin, Speech and Language Processing
Where this data comes from
This entry was drafted by an AI from the sources above and has not yet been checked by a person. Treat it as a starting point, and check anything important against the sources.
See the review queueSuggest a correction on GitHubThis term as JSON
Check yourself
Loading…