How Language Models Work (in Plain English) › How the Model Makes Predictions

Michael BrenndoerferJune 5, 20252 min read
AI Agent HandbookAll chapters
Part 2 of 15Language Models - The Brain of the Agent
Chapter 4How Language Models Work (in Plain English) › How the Model Makes Predictions
Reading section 5 of 12 · How the Model Makes Predictions · 2 minSection 5 of 12 · 2 min

Book contents

Section 5 of 12 · 2 min read

How Language Models Work (in Plain English) › How the Model Makes PredictionsOne section · Sections in this chapter5 / 12 ↓

Once trained, here's what happens when you give the model some text:

You provide a prompt (the starting text):

"Explain why the sky is blue in simple terms:"

The model processes it:

Internally, the model converts your prompt into tokens and runs them through its neural network (a complex mathematical structure with billions of parameters). Think of it as a very sophisticated pattern-matching machine.

The model predicts the next token:

Based on everything it learned during training, the model calculates probabilities for what token should come next. It might determine:

  • "The" →\to 35% likely
  • "It's" →\to 20% likely
  • "Because" →\to 15% likely
  • "Sky" →\to 10% likely
  • ... and thousands of other possibilities with lower probabilities

The model picks a token:

Usually, it selects a high-probability token (though not always the absolute highest; a bit of randomness keeps responses interesting). Let's say it picks "The."

The model repeats:

Now the prompt is "Explain why the sky is blue in simple terms: The" and the model predicts the next token again. Maybe it picks "sky." Then "appears." Then "blue." And so on, building up a complete response one token at a time:

"The sky appears blue because of a process called Rayleigh scattering..."

The model keeps generating tokens until it decides it's done (often by predicting a special "end" token) or hits a length limit.