Next-token prediction is the training objective in which a model learns to maximize the probability it assigns to each token of its training text given all preceding tokens. The objective is self-supervised, requiring no labels beyond the text itself, and it is the signal behind the GPT line and essentially every modern decoder-only language model: training a Transformer on next-token prediction over web-scale text is, in one sentence, the pretraining recipe of the field.1
Generation is the same conditional applied in the other direction: a model trained this way produces text by sampling one token at a time, appending each draw to the context and repeating, which is why the objective and autoregressive decoding are two faces of one factorization.
Role in the network
Next-token prediction is not a layer but an objective, applied at the output head of a decoder-only stack. The final hidden state at each position is projected to logits over the vocabulary, a softmax turns them into a conditional distribution, and the token that actually followed is the label; cross-entropy loss scores the prediction, and backpropagation distributes the gradient through every layer below. Because the target at each position is just the input shifted by one, the supervision is free, which is what makes web-scale text a training set.
Two mechanisms make the objective workable at scale. A causal mask in the attention layers blocks every position's access to future tokens, so no position can read its own label. And teacher forcing scores the whole sequence in one parallel pass: every position is predicted simultaneously, each contributing a term to the loss. At inference the mask stays but the gold prefix disappears: the model conditions on its own earlier outputs instead.
The mathematics
Any joint distribution over a token sequence factorizes by the chain rule of probability, and next-token prediction parameterizes each factor with one network:
$$p(x) = \prod_{t=1}^{T} p_\theta(x_t \mid x_{<t})$$| Symbol | Shape | Meaning |
|---|---|---|
| \(x = (x_1, \dots, x_T)\) | token sequence | a training document or a generated sample |
| \(x_{<t}\) | prefix of length \(t - 1\) | the context visible at position \(t\) under the causal mask |
| \(p_\theta(\cdot \mid x_{<t})\) | \(\mathbb{R}^{V}\) | the model's conditional distribution over a vocabulary of \(V\) tokens |
| \(\theta\) | all model parameters | shared across every position and factor |
The training objective maximizes the log likelihood of the corpus \(\mathcal{D}\), equivalently minimizing
$$\mathcal{L}(\theta) = -\sum_{x \in \mathcal{D}} \sum_{t=1}^{|x|} \log p_\theta(x_t \mid x_{<t})$$a sum of per-token cross-entropy terms over the corpus, all of which teacher forcing evaluates in a single forward pass per sequence. The per-token loss this defines is the quantity tracked in scaling-law curves, which showed test loss falling as a power law in model size, dataset size, and compute,2 and which the Chinchilla analysis used to argue that the large models of its period were undertrained relative to their size.4
Generation inverts the direction: text is produced by iterated softmax draws, \(x_t \sim p_\theta(\cdot \mid x_{<t})\), each sampled token appended to the context. Three knobs shape the draws. Temperature divides the logits by \(T\) before the softmax, sharpening or flattening the distribution. Top-k sampling truncates the distribution to the \(k\) highest-probability tokens, a set \(K\), and renormalizes:6
$$\tilde{p}_i = \frac{p_i}{\sum_{j \in K} p_j} \quad \text{for } i \in K, \qquad \tilde{p}_i = 0 \quad \text{otherwise}$$Top-p, or nucleus, sampling chooses the truncation adaptively: take the smallest set \(U\) whose mass reaches a threshold, \(\sum_{i \in U} p_i \geq p\), then renormalize the same way, \(\tilde{p}_i = p_i \,/\, \sum_{j \in U} p_j\) for \(i \in U\).5 The kept set grows where the model is uncertain and shrinks where it is confident, which is why nucleus sampling displaced fixed-k truncation as the default.
Worked example: a two-token language model
Take a vocabulary of two tokens, {A, B}, and a model whose learned conditionals are:
| Context | \(p(A \mid \cdot)\) | \(p(B \mid \cdot)\) |
|---|---|---|
| start of sequence | 0.6 | 0.4 |
| previous token A | 0.4 | 0.6 |
| previous token B | 0.6 | 0.4 |
The model has learned an alternation tendency: after either token it favors the other. The probability the factorization assigns to the sequence "A B A" is the product of the three conditional factors,
$$p(\text{A B A}) = p(x_1 = A) \times p(x_2 = B \mid x_1 = A) \times p(x_3 = A \mid x_1, x_2) = 0.6 \times 0.6 \times 0.6 = 0.216$$read straight off the table: start favors A at 0.6, A favors B at 0.6, and B favors A at 0.6. Teacher forcing scores all three factors in one pass over the training sequence, each position contributing its own term. The training loss on the sequence averages the per-token surprisals, \(-\ln(0.6) = 0.511\) nats per token (\(0.737\) bits), and the sequence perplexity is \(e^{0.511} = 1.667\), equivalently \(0.216^{-1/3}\): the model is as uncertain as a uniform choice among 1.67 tokens per step, better than the 2.0 of a uniform model on this vocabulary, because it has captured the alternation.
Intuition
The factorization is exact probability, but the objective's force comes from what accurate prediction demands. The standard explanation for the breadth of in-context abilities that emerge at scale is that accurate prediction forces the model to internalize whatever regularities the text reflects, from grammar to factual associations. The information-theoretic reading sharpens the point: log loss is a code length, so a model minimizing next-token loss is learning to compress its corpus, and the regularities that compress text are the regularities of the world that produced it. Shannon had framed English prediction as a game of guessing the next character in 1951, using human players to bound the entropy of printed English;3 the modern objective is the same game played by a network, at a scale Shannon's readers could not have priced.
Variants and extensions
Alternatives occupy niches. Masked language modeling trains bidirectional encoders such as BERT by predicting hidden tokens from both directions at once; denoising objectives power diffusion language models, which refine an entire corrupted sequence in parallel rather than drawing it left to right; and multi-token variants predict several future tokens at once to accelerate inference, a design shipped as an auxiliary training objective in DeepSeek-V3.7 As of 2026, however, every frontier general-purpose language model is trained primarily on next-token prediction.1
Adoption
Next-token prediction is the pretraining objective of the GPT line and essentially every modern decoder-only language model. GPT-3's few-shot results made the objective's scaling case, showing that a model trained on nothing else produced broad task ability at 175 billion parameters.1 The scaling-law and Chinchilla analyses then converted its per-token loss into the planning quantity of the field.24 On the generation side, the sampling knobs the objective implies, temperature, top-k,6 and nucleus truncation,5 are standard controls in every generation interface.
Limitations and critiques
Training and deployment conditions differ: the model is scored on gold prefixes but generates from its own outputs, a mismatch known as exposure bias. Fixes such as scheduled sampling, which gradually swaps gold inputs for the model's own predictions during training, were studied in the recurrent era,9 though at large language model scale the problem largely receded in practice, as discussed at Teacher forcing. The objective also scores tokens, not behavior: nothing in the likelihood rewards helpfulness, honesty, or harmlessness, which is why deployed models add post-training stages such as RLHF and preference optimization on top of the pretrained base. And the deepest critique targets the paradigm itself: Bender, Gebru, McMillan-Major, and Shmitchell's "stochastic parrots" paper argued that ever-larger models trained to mimic text distributions amplify encoded biases while remaining ungrounded in meaning.8
History
Shannon framed English prediction as a next-character guessing game in 1951.3 Bengio et al. gave the objective its modern neural form in 2003, training a feedforward network over fixed windows with a shared embedding,3 and the recurrent and seq2seq eras kept the loss while changing the architecture around it. The GPT series from 2018 paired the objective with the decoder-only Transformer:10 what changed with the GPT series was the architecture and the scale, not the loss.3 GPT-3 in 2020 showed few-shot ability emerging from the same objective at scale,1 and the scaling-law literature made its per-token cross-entropy the field's common measure of progress.24
See also
References
-
Brown, T., et al., "Language Models are Few-Shot Learners," arXiv:2005.14165, May 2020. ↩↩↩↩
-
Kaplan, J., et al., "Scaling Laws for Neural Language Models," arXiv:2001.08361, January 2020. ↩↩↩
-
Shannon, C. E., "Prediction and Entropy of Printed English," Bell System Technical Journal, January 1951; Bengio, Y., et al., "A Neural Probabilistic Language Model," JMLR 3, 2003. ↩↩↩↩
-
Hoffmann, J., et al., "Training Compute-Optimal Large Language Models," arXiv:2203.15556, March 2022. ↩↩↩
-
Holtzman, A., et al., "The Curious Case of Neural Text Degeneration," arXiv:1904.09751, April 2019. ↩↩
-
Fan, A., Lewis, M., and Dauphin, Y., "Hierarchical Neural Story Generation," arXiv:1805.04833, May 2018. ↩↩
-
DeepSeek-AI, "DeepSeek-V3 Technical Report," arXiv:2412.19437, December 2024. ↩
-
Bender, E. M., Gebru, T., McMillan-Major, A., and Shmitchell, S., "On the Dangers of Stochastic Parrots: Can Language Models Be Too Big?," ACM FAccT, March 2021. ↩
-
Bengio, S., et al., "Scheduled Sampling for Sequence Prediction with Recurrent Neural Networks," arXiv:1506.03099, June 2015. ↩
-
Radford, A., et al., "Improving Language Understanding by Generative Pre-Training," OpenAI, June 2018. ↩