Homeglossary

Next-token prediction

Next-token prediction is a machine learning method that generates text or code by estimating the most likely next token from prior context. It is the core mechanism behind many large language models, which repeat this prediction one token at a time to produce an answer. A token can be a whole word, part of a word, punctuation mark, or programming symbol, so prediction is more precise than simply guessing the next word.

Build reviewable AI-generated apps with Emergent.

What is next-token prediction?

Next-token prediction is a machine learning method that generates text or code by estimating the most likely next token from the context that came before it. Large language models repeat this process one token at a time, adding each selected token back into the sequence to create an answer, code snippet, or structured output. It is not simply next-word prediction because a token may be a word, part of a word, punctuation mark, space, or programming symbol.

How LLMs generate the next token

During training, the model learns from existing sequences where the next token is already known. During generation, it applies those learned patterns to a new prompt.

  1. Text or code is split into tokens.
  2. A transformer processes those tokens and weighs their relationships in the available context.
  3. The model assigns probability scores to possible next tokens in its vocabulary.
  4. A decoding method selects one token, either the highest-scoring option or a controlled alternative.
  5. The selected token is appended to the context, and the loop repeats until the response ends.

Tokens, words, and code: what the model actually predicts

Token boundaries affect prompt length, output limits, and generated code. A short-looking input can contain several tokens, especially when it includes uncommon words or syntax.

UnitExampleWhy it matters
Word"testing"A familiar reading unit, but not always one model unit.
Token"test" + "ing", or "."Models predict these smaller pieces. See the token glossary for more detail.
Code syntax"{", "()", indentationSmall mistakes can make otherwise plausible code fail.

Why next-token prediction is useful in software development

It can speed up drafting and iteration when the model receives clear context and constraints.

  • Complete repeated code patterns and boilerplate.
  • Draft UI copy, API documentation, and error explanations.
  • Suggest test cases from expected application behavior.
  • Produce structured formats such as JSON, when a schema is supplied.
  • Help developers explore alternatives before reviewing the final implementation.

Limits of next-token prediction and how to reduce errors

Fluent output is not proof that an answer, dependency, or code path is correct. Next-token prediction also does not forecast cryptocurrency prices or future events with reliable certainty.

  • Models can invent facts, citations, functions, or package behavior.
  • Older training information may conflict with current documentation.
  • Ambiguous prompts can omit requirements, security rules, or edge cases.
  • Retrieve authoritative sources, request citations, and validate structured output against schemas.
  • Run tests, inspect code diffs, and keep a human accountable for release decisions.

Next-token prediction in AI app building with Emergent

In an agentic development workflow, natural-language instructions provide the context that guides generated code and revisions. Emergent applies this capability to app design and development, while testing, integration checks, and human review help verify results before deployment. For teams evaluating coding tools, its guide to the best AI coding assistant options offers useful context. Build reviewable AI-generated apps with Emergent.

Start Building
on Emergent today
Start Building