Skip to content
Technology, explained from the insideAI · Software · Digital payments
TayoTechTalk.

How AI Works

How Large Language Models Predict the Next Token

By Temitayo Solomon Gbadebo · November 2, 2026

You ask an AI assistant to explain something, and a paragraph appears almost immediately. It can feel as if the assistant found a finished answer somewhere and pasted it into the conversation.

A useful way to understand a typical text-generating large language model is to slow that process down. The model works out possible next pieces of text, one piece is selected, and the process continues using the growing response. Those pieces are called tokens.

That simple loop can produce an explanation, a story or a software function. Let’s walk through it without assuming you already know machine learning.

Start with an unfinished sentence

Imagine the sentence: “Please save the document before you close the…”

You might suggest “window,” “application” or “laptop.” “Banana” would be a strange continuation. You are using the surrounding words and your experience to judge what fits.

A language model calculates scores for possible continuations using patterns represented in its trained parameters. The scores can be converted into probabilities. These probabilities describe how the model distributes its next-token predictions; they are not a certificate that the resulting statement is true. Google’s introduction to language models explains this connection between context, tokens and probability.

A token is not always a whole word

Before the model processes your message, a tokenizer converts the text into a sequence of token identifiers. A token may correspond to a whole word, part of a word, punctuation or another text fragment. The exact divisions depend on the tokenizer.

For illustration, a tokenizer could split a longer word into two or more pieces. Another tokenizer might keep that word together. Do not assume that a five-word sentence must use exactly five tokens, or that the same sentence has the same token count in every model.

The identifiers are numbers that let the system look up numerical representations of the tokens. They are labels, not rankings: token number 8,000 is not “more meaningful” than token number 80. Hugging Face’s tokenizer guide explains how word, character and subword approaches differ.

Context helps the model narrow the possibilities

Consider these two prompts:

  • “The customer opened an account at the bank…”
  • “The canoe stopped beside the river bank…”

The shared word “bank” has different meanings. The surrounding text provides clues about which continuation makes sense. A useful model needs to work with those relationships, rather than treating each word as an isolated label.

Many widely used text-generating models use a Transformer architecture. Its attention mechanisms help combine information from different token positions. The original Transformer paper describes attention-based processing; modern systems use several architectural variations. You do not need to calculate attention scores to understand the practical point: changing the context can change the next-token prediction.

For example, “Explain this to a ten-year-old” and “Explain this to an experienced database engineer” should lead to different vocabulary and detail, even when the topic is the same.

One prediction becomes the next piece of context

Let’s invent a tiny example. These figures are illustrative, not measurements from a real model.

After “Please save the document before you close the,” suppose the candidate distribution is:

  • “window”: 50%
  • “application”: 30%
  • “laptop”: 15%
  • All other options together: 5%

If “application” is selected, the growing sentence now ends with that word. The next step might produce a full stop. After that, the system might generate another sentence or stop. For readability, this example treats each candidate word as one token; real token boundaries can differ.

This repeating process is called autoregressive generation. A causal language model uses preceding tokens rather than looking at future tokens that have not yet been generated. See Hugging Face’s causal language modeling guide for the underlying task.

Why the same question can get different answers

The model supplies predictions, while a decoding strategy determines how a token is selected. One approach chooses the highest-probability option at each step. Another samples from a probability distribution, allowing more than one plausible continuation.

Sampling settings can change how concentrated those choices are. This helps explain why two responses can say roughly the same thing using different sentences. It also explains why generating again can sometimes change more than the wording. Hugging Face documents these alternatives in its generation strategies guide.

For a birthday message, variation can be useful. For extracting invoice totals, unexpected variation is less welcome. A lower-variation setting can make a workflow more consistent, but consistency alone does not establish accuracy. A system can repeat the same mistake.

Training and answering are different activities

During training, a model’s parameters are adjusted using examples and a learning objective. In next-token training, text provides both the context and the token that should follow it. The model learns across many such examples.

During ordinary inference, those learned parameters are used to process the current input and generate output. The model does not need to retrain itself for every question. Adding a detail to a conversation gives it more context for that interaction; that is different from updating its underlying trained parameters.

If you are following the earlier articles on this site, gradient descent helps explain the parameter-adjustment side. This article focuses on what happens when the trained model produces text.

Fluent answers still need checking

Models can generate incorrect details, including plausible-looking names, dates and references. Google’s Transformer introduction identifies hallucinations and bias among the practical limitations of LLMs.

Think about asking for the opening hours of a small shop. A neatly written answer could sound reasonable while being completely wrong. The writing quality gives you very little evidence about whether the shop actually closes at that time.

For important facts, check the original source. For calculations, verify the arithmetic. For generated code, run meaningful tests and review the behavior. Treat a confident explanation as something to examine, especially when the cost of being wrong is high.

A small exercise

Try completing “The customer could not pay because…” in three settings: a supermarket checkout, an online subscription and a rural shop with poor connectivity. Notice how each setting changes your likely continuation.

Then ask an AI assistant to complete those prompts. You will not see its internal probability distribution, but you can observe how context changes the response. That is the central idea to remember: a text-generating model repeatedly predicts a continuation from the information available to it. Understanding that process helps you ask clearer questions and judge the answers more carefully.