How Language Models Work (in Plain English) › How the Model Makes Predictions
AI Agent HandbookAll chapters 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" 35% likely
- "It's" 20% likely
- "Because" 15% likely
- "Sky" 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.