Kolkata ·  
AI engineering
foundations
deep · 6 min

Next-token prediction

An LLM does one thing: predict the next token, add it to the text, and repeat.

updated 23 Sept 2026

People like to say a language model is "just fancy autocomplete". Let's take that seriously for a minute, because it's half right, and the half that's right explains most of how these models behave.

One step

Give a model this text:

The best thing about AI is its ability to

It doesn't answer with a word. It gives a probability to every possible next piece of text. For GPT-2, the top five looked like this:

Next wordProbability
learn4.5%
predict3.5%
make3.2%
understand3.1%
do2.9%

Notice two things. None of them is likely; the favourite is under 5%. And all of them are fine. The model isn't hunting for the right answer. It's ranking reasonable ways to carry on.

Those pieces are tokens, not words. A token is a chunk of text: often a whole word, sometimes part of one, sometimes a space or a comma. Each model has a fixed list of them. GPT-3's list had 50,257, so "a probability for every next piece" meant 50,257 numbers adding up to 100%. How text gets cut up is its own topic, tokenization.

The loop

Now let's make it write more than one token. The network ends with one raw score per token, and softmax turns those into the probabilities in the table. Then we pick one ("learn", say), stick it on the end of the text, and run the whole thing again on the longer text. And again. That's it.

Every new token reads the whole text so far, including what the model just wrote itself. An essay, a JSON object and a block of code all come out of this same step, repeated once per token.

Why pick at all, and not just take the top token? You'd think the top token is safest. But text built that way comes out flat and often repeats itself word for word. Picking a less likely token now and then, at random, reads far more naturally. That's also why the same prompt gives a different answer each time. The model is fixed: same text in, same probabilities out. The randomness is all in the pick, and the rules for it are in sampling.

Why not just count?

This is where "autocomplete" starts to break down. The simplest autocomplete would just count which word usually follows which. Could we do that here, with enough text?

Try it. Take about 40,000 common English words. There are 1.6 billion possible two-word pairs, and 60 trillion three-word sequences. No pile of text in the world covers all of those, and real prompts are hundreds of words long, not three. Plenty of prompts have never been written before, and a count table has nothing to say about them.

So instead of counting, we train a network that has picked up the patterns well enough to give sensible probabilities for text it has never seen.

Learning the same task

Training uses the very same step as practice. Take real text, hide the next token, let the model guess, and compare with what actually came next. Then nudge every parameter a little so the right token gets a bit more likely. Every position in a text is a practice question: guess word 2 from word 1, word 3 from words 1 and 2, and so on.

Do that over an enormous amount of text. For GPT-3, a person reading its training text non-stop would need over 2,600 years. The model gets good at the training text, and it also starts making sensible guesses on text it has never seen. That stage is pretraining.

More falls out than you'd expect

Here's where the autocomplete picture really stops covering it. GPT-3 had 175 billion parameters and was trained on 300 billion tokens. Its makers found you could hand it a task just by writing the task as text to continue. Show a few worked examples, then a new case, and it continues the pattern, which means doing the task. No retraining. With a few examples in the prompt it got 2-digit addition right every time, and 2-digit subtraction 98.9% of the time. Bigger models made better use of the examples.

That's called in-context learning, and it's the idea behind few-shot prompting. Is the model actually learning from your examples, though, or recognising a pattern it already saw in training? The GPT-3 authors chose their words to stay neutral on that, and it's still open.

A chat assistant is the same loop, too. Your conversation is laid out as a script: a user line, an assistant line, another user line, and an empty assistant turn at the end. The model predicts what the assistant says next, one token at a time. A model fresh out of pretraining is good at continuing web pages, which isn't the same as being a helpful assistant. A second round of training, post-training, closes that gap. The loop underneath doesn't change.

What the loop costs

One token at a time means one full pass through the network per token. For GPT-3 that's about 175 billion calculations for every token it writes. A 500-token answer is 500 passes, one after another, and you pay for each token it writes (token pricing). How that splits into reading your prompt and then writing token by token is prefill and decode.

The model also can only see so much text at once, its context window. GPT-3's was 2,048 tokens. (All these sizes are GPT-3's, from 2020. The mechanism is the same today. The numbers aren't.)

And the loop has no blank option. At every step the model has to produce some next token, even when it has nothing solid to go on. That's one root of hallucination.

It also means the prompt is the start of a document, and anything the model writes becomes text it reads next. Getting it to write its working before the answer, on purpose, is chain-of-thought prompting. The probabilities behind each pick are something some APIs let you read back, as logprobs. And whether the job suits a system that guesses this way at all is the question in picking use cases.

Does it only look one token ahead?

So, is it autocomplete? The output side is: one token, then the next. But it's tempting to go further and say the model only "thinks" one token ahead. That part looks wrong.

Anthropic looked inside one of their models while it wrote a rhyming couplet:

He saw a carrot and had to grab it, His hunger was like a starving rabbit

Before it wrote the second line, the model already had "rabbit" in mind as the word to aim for, and then wrote the line to land on it. When the researchers removed "rabbit" from its internal state, it wrote a different line ending in "habit". They had set out to show the model didn't plan ahead, and found that it did.

That's a few case studies, using tools that see only part of what the model computes, so nobody can say yet how much of every answer works like this. But it's enough to retire "just autocomplete". The model writes one token at a time. What goes into each of those tokens can already know where the sentence is going.

Further reading