liveBook · Manning

Next-token prediction

As explained in How Large Language Models Work

An autoregressive generation strategy that predicts each successive word or token from the preceding context.

Next-token prediction generates text one word or token at a time, using the preceding context to choose what should come next. During training, repeated predictions refine associations between context and likely continuations. This can produce useful, human-like language without guaranteeing truth, logic, or understanding. section 4.2.1

Figure 4.6 An LLM sees this sentence nine times, each time learning from the prediction of a single word at the end of each of the nine sequences.
figure

Shows how one sentence becomes multiple training examples, each ending where the model predicts a single word. section 4.2.1

The strategy works by:

  • Using keywords and phrases in the preceding text to narrow the plausible next words. section 4.2.1
  • Applying extensive association calculations refined through billions of training updates. section 4.2.1
  • Producing fluent continuations even when a prompt contains a false premise, because the model is not trained directly for accuracy or contradiction. section 4.2.1
  • Working best when a request resembles material in the training data, while degrading as the task becomes more unique. section 4.3
Figure 4.7 Context can help you make decent predictions about the next word. As you move from left to right, additional text that might occur in a sentence is added. The images in the thought bubble for each sentence show how the added context eliminates predictions.
figure

Illustrates how adding context eliminates candidate continuations and makes the next prediction more constrained. section 4.2.1

A useful pattern with a dangerous edge

A request to calculate pi in Python resembles abundant training material, so the model can return correct-looking code. A request to translate that function into the esoteric language Modula-3 requires more extrapolation. The same predictive mechanism can also confidently explain an absurd claim about spaghetti because the question’s wording activates familiar material-property language. section 4.2.1 section 4.3

Listing 4.1 ChatGPT calculating pi in Python
def calculate_pi(terms):
    pi = 0
    for i in range(terms):
        term = ((-1) ** i) / (2 * i + 1)
        pi += term
    pi *= 4
    return pi

print(calculate_pi(1000000))  #1

Provides a concrete Python artifact produced for a familiar programming task. section 4.3

How How Large Language Models Work covers it

How deep it goes
Explains context-based association and training use, but stops short of mathematical or architectural internals.
Examples
Uses context-elimination figures, an absurd spaghetti explanation, and Python and Modula-3 programs calculating pi.
What you can do after
Evaluate generated responses more cautiously, verify factual claims, and avoid relying on predictions for novel tasks.
How it connects
Connects next-token prediction to reward functions, loss, keyword search, citations, factual accuracy, and novel tasks.

Also explained in

Compare how 9 books explain next-token prediction →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of How Large Language Models Work. The section links point to the parts of the book it draws on.