Next-token prediction is the task of guessing what comes next in a sequence, given everything before it. Shown “The cat sat on the”, a model outputs a probability for every token in its vocabulary, with “mat” and “floor” near the top. It is the objective that GPT-style large language models are pre-trained on, and the loop they run to generate text.
As a training objective
Text supplies its own answers: every position in a document is a free example of “given this, what came next?” That makes next-token prediction a form of self-supervised learning that can use enormous amounts of unlabeled text. The model is scored with cross-entropy loss, the negative log of the probability it gave the actual next token, and a causal mask makes sure it can’t peek ahead. The formal name for this setup is causal language modeling.
The idea predates transformers. Bengio and colleagues trained a neural network to predict the next word in 2003, learning word embeddings along the way. GPT-3 showed that scaling the same objective up to a 175-billion-parameter model produced a system that could perform many tasks from a few examples in its prompt.
As a way to generate
At inference time, the model predicts a distribution, one token is chosen from it, the token is appended to the input, and the process repeats. How that token is chosen is up to the decoding strategy, from always taking the most likely token to sampling with a temperature. This one-at-a-time loop is why output streams word by word and why longer answers take longer.
The catch
The objective rewards plausible continuations, not true ones. A model trained only to predict the next token will confidently continue a false premise, which is one root of hallucination and why further training such as instruction tuning and RLHF follows pre-training.