Introduction
"The model predicts the next token" is easy to say and hard to picture. Following a single short prompt through every stage shows what the phrase covers and where a wrong answer can enter.
This example traces the prompt "The capital of Australia is" through an invented small language model. The model, its token splits, and its likelihoods are made up for illustration and weren't measured from any real system.
The Problem
The prompt is five words long:
The capital of Australia is
The task is to follow how the model turns this prompt into a finished reply, and then to run it a second time and see whether the reply comes out the same. The correct completion is Canberra. Sydney is Australia's largest and best-known city, and it's a common wrong answer among people.
Working It Through
Step 1: Split the prompt into tokens
The model can't take in letters or words directly. The prompt is first split into tokens, the pieces of text a model handles as units. In this invented model every word of the prompt is common enough to have a token of its own, so the split is simple.
| Position | Token |
|---|
| 1 | The |
| 2 | capital |
| 3 | of |
| 4 | Australia |
| 5 | is |
Each token is then replaced by its number on the model's fixed list of tokens. From here on the model is working with five numbers.
Step 2: Turn each token into a position
Each token number is swapped for that token's embedding, a list of numbers that works as a position in a space of meaning. Tokens that are used in similar ways get nearby positions (Lee and Trott 2023, "Word vectors"). In this invented model the embedding for "Australia" sits near those for other countries, and also near tokens such as "Sydney," "Canberra," and "Melbourne," which turn up in the same kinds of sentences.
The model's layers then combine the five positions, so that "capital" is read in light of "Australia" and the sentence as a whole points toward a place name. How the layers do that is a subject of its own. What matters here is the result, which is one set of numbers summing up the text so far.
Step 3: Rank the candidates for the next token
From that summary the model produces a likelihood for every token on its list. Most get almost nothing. Here are the top five.
| Rank | Candidate token | Rough likelihood |
|---|
| 1 | Canberra | About half |
| 2 | Sydney | About a quarter |
| 3 | a | About one in ten |
| 4 | the | About one in twenty |
| 5 | located | About one in twenty |
All the other tokens on the list share the small remainder.
"Sydney" is on this list for a reason. Suppose the model's training text mentions Sydney alongside Australia far more often than it mentions Canberra, and that some of that text states the mistake outright. The model's ranking reflects the text it learned from, so a frequent error earns a real share.
Step 4: Sample one token, add it, and repeat
The model now samples, which means it picks one candidate by chance, with likelier candidates more likely to be picked. On this run the draw lands on "Canberra." That token is added to the text.
The text so far is now "The capital of Australia is Canberra," and the whole of it goes back in as input. The model produces a fresh ranking, a token is drawn, and the cycle repeats. Wolfram describes this loop as asking over and over what should come next given the text so far (Wolfram 2023, "It's Just Adding One Word at a Time").
| Text so far ends with | Leading candidates | Token drawn |
|---|
| … is Canberra | a comma, a period, "which" | , |
| … is Canberra, | "a," "which," "not" | a |
| … is Canberra, a | "city," "planned," "small" | planned |
Two more cycles add "city" and a period. On the cycle after that, the model's draw is a special token that means the reply is finished, and generation stops. The first reply reads: "The capital of Australia is Canberra, a planned city."
Step 5: Run it again with a different draw
Start over from Step 3 with the same prompt. The model's ranking is identical, since the input is identical. The draw is a new one. This time it lands on "Sydney," which had about one chance in four.
"Sydney" is added to the text, and the model continues from there. It doesn't go back and reconsider. Its input now ends "is Sydney," and its job is to predict what follows that text.
| Text so far ends with | Leading candidates | Token drawn |
|---|
| … is Sydney | a comma, a period, "which" | , |
| … is Sydney, | "the," "a," "which" | the |
| … is Sydney, the | "largest," "country," "most" | largest |
Two more cycles add "city" and a period, and then the stop token is drawn. The second reply reads: "The capital of Australia is Sydney, the largest city."
The second reply is false, and it's as fluent as the first. Nothing in its wording marks it as the less likely draw.
Key Considerations
The likelihoods in this example are illustrative. A real, large model would probably rank "Canberra" far higher on a question this well covered, and the error would be rare. The pattern becomes common on questions where the training text is thin, mixed, or often wrong.
A common mistake is to think the model looks the answer up. It has no table of capitals to consult. It ranks tokens by how well they continue the text, and "Sydney" can outrank "Canberra" wherever the text the model learned from pairs Sydney with Australia often enough. A correct answer and an incorrect one come out of the same process.
A second point concerns the moment of the error. The second reply went wrong at a single token. Everything after it was a sensible continuation of a false start, and the phrase "the largest city" is even true of Sydney. The model built on its own earlier output as it would on any other text.
Summary
The same prompt, the same model, and the same ranking produced two replies that split at the first generated token.
| First run | Second run |
|---|
| Prompt | The capital of Australia is | The capital of Australia is |
| Token 1 | Canberra | Sydney (the runs split here) |
| Token 2 | , | , |
| Token 3 | a | the |
| Token 4 | planned | largest |
| Tokens 5 and 6 | city . | city . |
| Finished reply | The capital of Australia is Canberra, a planned city. | The capital of Australia is Sydney, the largest city. |
Check: both runs used the ranking from Step 3 unchanged. "Canberra" had about half the likelihood and "Sydney" about a quarter, so across many runs roughly twice as many replies would begin with "Canberra" as with "Sydney." Getting one of each in two runs is an ordinary outcome.
References
- Lee, Timothy B., and Sean Trott. 2023. "Large Language Models, Explained with a Minimum of Math and Jargon." Understanding AI, July 27, 2023.
- Wolfram, Stephen. 2023. "What Is ChatGPT Doing … and Why Does It Work?" Stephen Wolfram Writings, February 14, 2023.