Deep Learning Beginner–Intermediate ⏱ 40 min next-token predictionembeddingsmeaningvectorsLLMprobabilitytemperaturefoundationssoftmax

The Prediction Game: How Tokens Learn to Mean Something

Published 2026-07-18 — Dr Neal Aggarwal
📖 Chapter Two of a ground-up account of how large language models work. In Chapter One we watched raw text from the internet get broken into tokens — the machine's self-made alphabet. But we left those tokens as what they really are at that stage: bare ID numbers, as meaningless as seat numbers at a stadium. This chapter is about the two ideas that breathe life into them.

The Prediction Game: How Tokens Learn to Mean Something

At the close of the last chapter we had reduced a page of writing to a row of integers — token IDs, the grain into which language had been ground so a machine could swallow it. And I was careful to insist on something that should still be nagging at you: those integers mean nothing. Token 5,317 is not "closer" to token 5,318 than to token 90,001. The numbers are arbitrary labels, handed out in the order the tokenizer happened to build its vocabulary. If the model is ever going to seem to understand anything, that understanding cannot come from the numbers themselves. It has to be built.

This chapter is about how it gets built, and the answer comes in two movements that feel, at first, unrelated. The first is a goal — a single, almost comically modest task that the entire apparatus is trained to perform. The second is a transformation — the first thing the machine does to a token, which quietly turns a meaningless ID into something with the beginnings of meaning. By the end you will see that these two are not separate at all: the goal is what creates the meaning, as a kind of side effect, and that fact is the strangest and most important idea in the whole subject.

Let us take the goal first, because it is so small that its power is easy to miss.

Part I — The whole game is "what comes next?"

Here is the entire objective a large language model is trained to accomplish. Ready?

Given a sequence of tokens, predict the next one.

That is it. That is the whole game. Not "understand the passage," not "answer the question," not "reason about the world" — just: here are some tokens, guess what token comes after them. A model that has read "the patient was prescribed a course of" is asked, simply, to fill in the blank. Antibiotics? Steroids? Physiotherapy? It must produce its best guess, and it is scored on nothing more than whether it matched the token that actually came next in some real piece of text.

The first time you hear this, it is genuinely deflating. All of it — the essays, the code, the eerie fluency, the appearance of thought — trained on a task you would set a parrot? It sounds like a category error, as though someone claimed that memorising a phone book could teach you to hold a conversation.

And then, if you sit with it, the deflation inverts into something closer to awe. Because think, really think, about what it would take to be good at this game. To reliably predict the next token in any text drawn from the whole internet, you cannot get by on surface tricks. Consider what predicting the blank actually demands across different sentences:

“The capital of Kenya is ___”  →  requires a fact
“2, 4, 6, 8, ___”  →  requires a pattern
“She lied to him, so he no longer ___”  →  requires a theory of people
“def add(a, b): return a ___”  →  requires the logic of code
“The murderer, it turned out, was the ___”  →  requires holding a whole story in mind

To fill in the last blank correctly for a detective novel, the model would have to have tracked the plot, the clues, the misdirections — everything. The task is a keyhole, and behind the keyhole is a door that opens onto the whole of what the text was about. This is the pivotal realization of the entire field, and I want to state it as plainly as I can.

💡 The back-door of prediction. To predict the next token well, across all text, a system is forced to internalise whatever it takes to make that prediction — facts, grammar, patterns, cause and effect, the way people and stories behave. Understanding is not a separate goal bolted on top of prediction. It is the cheapest way to get good at prediction. We never asked the model to understand. We asked it to guess well, and understanding turned out to be the price of guessing well.

A machine that could truly predict the next word of an arbitrary text would, somewhere inside itself, have to understand that text — and that back-door is the entire trick.

Everything downstream in this book — every capability, every failure — is a consequence of pushing a system relentlessly toward that one keyhole and seeing what it grows in order to fit through.

Part II — The model never gives an answer. It gives a weather forecast.

There is a subtlety here that trips up almost everyone, and getting it right now will save you endless confusion later. When we say the model "predicts the next token," it is easy to picture it confidently declaring a single winner. That is not what happens, and the difference matters enormously.

The model does not output a token. It outputs a probability for every token in the vocabulary at once — all hundred thousand of them from Chapter One. Given "the patient was prescribed a course of", its actual output is something like: antibiotics 41%, steroids 12%, treatment 9%, physiotherapy 4%, and a long, long tail of ever-smaller probabilities trailing off through every other token it knows, including the absurd ones. It is not an answer. It is a forecast — a full distribution of confidence spread across every possible next word.

PREDICTION IS A FORECAST, NOT AN ANSWER the tokens so far “…prescribed a course of” the model one forward pass P(next token) — the whole vocabulary, ranked antibiotics · 0.41 steroids · 0.12 treatment · 0.09 physiotherapy · 0.04 tablets · 0.02 … a very long tail of ever-tinier probabilities draw ONE token weighted by probability append the drawn token to the context, and run the whole thing again — forever “Generating text” is this loop. A thousand-word reply is a thousand forecasts, each conditioned on the last.
Figure 1. The generation loop. The model produces a distribution; a single token is drawn from it; that token is appended and the process repeats. Notice that the model does not plan a sentence — it commits to one token at a time, each choice reshaping the forecast for the next.

This forecasting nature explains a fact everyone has noticed: ask the same model the same question twice and you may get two different answers. That is not a bug, and it is not the model "changing its mind." It is because generating text involves drawing from the distribution, and a draw has an element of chance. How much chance is governed by a single dial you have very likely met in an API or a settings panel: temperature. Turn the temperature down toward zero and the model almost always takes its single most probable token — reliable, repetitive, a little robotic. Turn it up and the draw gets more adventurous, reaching further into the tail — creative, surprising, and increasingly liable to wander into nonsense. Temperature is quite literally a knob on how much you let the dice matter.

🎲 Why "it's just autocomplete" is both fair and deeply misleading. The dismissive line contains a true observation — yes, mechanically, the model is completing text one probable token at a time, exactly like the suggestion strip above your phone keyboard. What the line misses is everything about the difference in degree that becomes a difference in kind. Your phone predicts the next word from the last two or three. This machine predicts it from thousands of prior tokens, using a model of the world it had to build in order to predict well. Calling it "just autocomplete" is like calling a surgeon "just someone with a knife." The verb is right; the noun is doing unimaginable work.

So: the goal is prediction, and the output is a forecast we sample from. But we still have not answered the question this chapter opened with. The forecast has to be computed from the input tokens — and the input tokens, remember, are meaningless integers. How does a meaningless integer participate in producing a rich probability distribution? For that, we need the second movement: the transformation that gives a token its first foothold on meaning.

Part III — Giving every token a place in space

Here is the idea, and it is one of the most beautiful in all of machine learning. We are going to stop representing a token as a number, and start representing it as a location.

Picture a vast space — not the three dimensions we live in, but hundreds or thousands of them; hold the intuition even though you cannot picture the dimensions. Every token in the vocabulary is assigned a point in this space, specified by a list of numbers called a vector — its coordinates. The token dog is at one location; cat is at another; lisinopril at another still. This assignment — this big table mapping each of the hundred thousand tokens to its vector — is called the embedding, and the vectors are called embeddings too. It is, quite simply, the first thing that happens to a token once it enters the model: its ID is looked up in this table and swapped for its coordinates.

Now, why on earth would coordinates be better than a number? Because coordinates have neighbours, and neighbours can carry meaning. A single number line can only say "bigger" or "smaller." But a high-dimensional space can arrange its points so that things with similar meaning sit close together, and — this is the astonishing part — so that directions in the space correspond to relationships.

MEANING BECOMES GEOMETRY a flattened 2-D glimpse of a space that really has hundreds of dimensions medications lisinopril aspirin metformin symptoms dyspnoea oedema fatigue procedures angiography echocardiogram dialysis Not only do similar things cluster — the direction from a drug to its class is roughly the same everywhere, so relationships themselves become fixed compass bearings the model can follow.
Figure 2. A cartoon of embedding space (real ones have hundreds of dimensions, which no picture can honestly show). Two properties matter: proximity encodes similarity, so the model can generalise from one drug to a related one it has seen less often; and direction encodes relationship, so the same "compass bearing" that points from a drug to its class points the same way for every drug at once.

The famous demonstration of the direction idea, in ordinary-language embeddings, is almost a magic trick: take the vector for king, subtract the vector for man, add the vector for woman, and you land very near the vector for queen. The "royalty" and the "gender" of a word turn out to be directions you can travel along. In a medical embedding the same structure appears in our own vocabulary: aspirin is to NSAID roughly as lisinopril is to ACE-inhibitor — the "is-a-member-of-this-drug-class" relationship is a consistent bearing in the space. The model was never handed a drug classification. It reconstructed one, as geometry, purely from how these words are used.

💡 An embedding is a fixed address in a space where distance means dissimilarity of meaning. This single move — from arbitrary ID to meaningful coordinate — is what lets a model generalise at all. Having seen "lisinopril lowers blood pressure" a thousand times, it can make a sensible guess about "ramipril" the first time, because the two live in nearly the same neighbourhood. Without embeddings, every token would be an island. With them, meaning has a landscape, and the model can navigate it.

If this idea of meaning-as-geometry feels important, that is because it is: it returns, scaled up from single tokens to whole documents, when we reach the chapter on retrieval — the mechanism behind grounding a model in your own files. The geometry you are meeting here, at the level of one token, is the same geometry that will later let a machine search a library by meaning rather than by keyword. Learn it once, here, and it pays dividends twice.

Part IV — Nobody puts the meaning there

Now for the part that genuinely borders on the uncanny, and that ties this chapter's two movements into a single knot.

Where does the arrangement of Figure 2 come from? Who decided that aspirin and lisinopril should be neighbours, that the drug-class direction should be consistent, that the space should be organised so beautifully? Surely a team of doctors sat down and placed the medical terms by hand?

No. Nobody placed anything. At the very start, before any training, the embedding table is filled with random numbers. Every token is flung to a random point in the space. aspirin and poetry and dialysis are scattered like buckshot, no cluster, no structure, no meaning whatsoever. The map begins as pure noise.

And then the prediction game begins. The model is shown ocean after ocean of real text and asked, over and over, to predict the next token — and every time it guesses, it is nudged to guess a little better. Crucially, those nudges do not only adjust some separate "prediction machinery." They reach all the way back and move the embedding vectors themselves. If treating aspirin and ibuprofen as neighbours helps the model predict text about pain relief, then the training gently slides their vectors together. If keeping bank-the-river and bank-the-money distinguishable helps, the training pulls on those too. Token by token, nudge by nudge, over billions of predictions, the random scatter organises itself into the landscape of meaning — not because meaning was the goal, but because a meaningful map is what makes the prediction game winnable.

MEANING PRECIPITATES OUT OF PREDICTION before training — random noise no clusters · every token an island billions of predictions after training — organised meaning like clusters with like · relationships aligned
Figure 3. The map is not designed; it is grown. Training on the prediction game reaches back and rearranges the embedding vectors themselves, so that the geometry of meaning condenses out of the single pressure to guess the next token well. We will open up exactly how a guess reaches back and moves a vector in a later chapter on training — for now, the point is simply that meaning is discovered, not installed.

Pause on this, because it is the philosophical heart of the whole enterprise and it is almost never stated plainly. We did not teach the model what words mean. We could not have — nobody has a complete theory of what words mean. Instead we set up a game in which having a good internal model of meaning is rewarded, pointed the machine at a large fraction of everything humans have written, and let meaning precipitate out of the relentless pressure to predict. The understanding these systems have — such as it is — was not authored. It was distilled.

⚕️ A double-edged gift for those of us in medicine. The upside is remarkable: the model builds its own nosology, its own web of how clinical concepts relate, without ever being handed a textbook taxonomy — and that is why it can move so fluently across medicine. But look at the mechanism again. The map is distilled from how words are used in the training text. So if the text of the internet associates certain conditions with certain groups, certain symptoms with certain demographics, or reflects the historical blind spots of the medical literature, those associations do not merely appear in the output — they are baked into the very geometry, as distances and directions. The model's biases are not slogans it repeats. They are the shape of its space. That is a far harder thing to find, and to fix, than a bad sentence.

Part V — The gap a lone vector cannot cross

We have come a long way. Tokens have become points in a meaningful space; the space organised itself through the prediction game; and the game, we argued, is a keyhole onto genuine understanding. It would be easy to feel we are nearly done — that a model is just a big embedding table plus some machinery to read off predictions. But there is a crack in what we have built so far, and finding it precisely is what sets up everything to come.

Here is the crack. The embedding of a token is fixed. bank gets one vector, always the same, no matter where it appears. But consider two sentences:

“He sat on the bank of the river and watched the current.”
“He deposited the cheque at the bank on the corner.”

The word bank means something utterly different in each — a muddy riverside in one, a financial institution in the other. Yet the embedding table, knowing nothing of context, hands over the identical vector for bank both times. A fixed point in space simply cannot be a riverbank here and a savings bank there. The single most important word for the meaning of each sentence arrives at the model wearing the same blank mask.

THE PROBLEM A FIXED VECTOR CANNOT SOLVE “bank” one fixed vector “…the bank of the river…” needs: riverside “…deposited it at the bank…” needs: institution The same mask arrives for two opposite meanings. The only cure: let the token look at its neighbours — “river”, “deposited” — and adjust its own meaning in light of the company it keeps. that adjustment-by-context has a name — and it is the whole of Chapter Three
Figure 4. The limitation that motivates everything next. A static embedding captures a token's meaning in isolation, which is genuinely useful — but language is not made of isolated words. Meaning is contextual. To resolve "bank", the token must be allowed to gather information from the words around it and update itself accordingly. Naming that operation precisely is the doorway out of this chapter.

So we need something more. We need a token, once it has been given its starting vector, to look around — to see that "river" and "current" are nearby in one sentence and "deposited" and "cheque" in the other, and to let that company reshape its own meaning before any prediction is made. We need each token to stop being a fixed point and become a point that adjusts itself in light of its neighbours.

This is not a small tweak. It is the central mechanism of the entire architecture — the thing that separates a modern language model from every earlier attempt, the idea that made all of this work at last. It has a name, and you have heard the name even if you have never been shown what is under it.

It is called attention. It is the reason these models are built the way they are. And building it, from nothing, so that you understand not just what it does but why it was the answer everyone was reaching for — that is Chapter Three.

For now, hold the shape of what we have. A token enters as a meaningless number. It is handed a place in a vast space of meaning — a place that was not designed but grown, distilled out of the single pressure to predict what comes next. And there it sits, rich but static, wearing the same face in every sentence, waiting for permission to turn its head and look at the words around it.

We are about to grant that permission. And when we do, the whole thing comes alive.

— Neal

📖 Next chapter: Attention — how a token learns to look at its neighbours and become a different thing in every sentence. It is the idea at the dead centre of every large language model, and we will build it from first principles, one honest step at a time.
tags: next-token prediction embeddings meaning vectors LLM probability temperature foundations softmax