How Large Language Models predict the next token.
|
You've used this before. But what's happening under the hood?
These are all different products, built on the same idea
ChatGPT
OpenAI
Claude
Anthropic
Gemini
Llama
Meta
Mistral
Mistral AI
Falcon
TII
Same prompt
"Explain quantum physics simply"
ChatGPT
Think of particles as tiny dice that...
Claude
Imagine the universe at its smallest scale...
Gemini
Quantum physics is like a game where...
Large
billions of parameters
Language
trained on text
Model
makes predictions
How does it actually work?
How does it understand?Where does it learn?Why is it so good?You type:
Your prompt
"The capital of France is ___"
The model's job: predict what comes next
Text is split into tokens
"The capital of France is"
· = a space that is part of the token. IDs are illustrative; each tokenizer has its own numbering.
"unbelievable"→unbelievable
Tokens = the currency of LLMs
Short prompt
"Hi there"
Long prompt
"Write a detailed essay about..."
With AI APIs you pay per token: for the tokens you send+the tokens that come back (prices differ by model)
Rule of thumb: 1 token ≈ ¾ of an English word | a 1-page email ≈ 500 tokens
GPS locates a place
(40.7, -74.0)
= New York
Embedding locates meaning
[0.82, -0.45, ...]
= "King" (royalty, male, power)
Every token gets its own unique embedding vector:
Notice: "France" has large numbers (lots of meaning) — "of" has tiny numbers (little meaning)
The model learned this from data alone — no one programmed it
Attention: each token looks at every other token to understand context
"France" and "capital" attend strongly to each other
Thick lines = strong attention. "France" and "capital" are strongly connected.
bank looks at river
bank = riverbank
bank looks at approved + loan
bank = a money business
Same word, different neighbours, different meaning
Tokens flow through billions of neural network parameters
...through many layers of math that extract meaning and patterns
Parameters
Billions
Early layers
Grammar
Middle layers
Meaning
Later layers
Reasoning
Big models: billions of parameters|Each parameter = one tiny number, adjusted during training
The network scores every possible next token
"The capital of France is ___" → every token in the vocabulary gets a score
Illustrative numbers. A clear question gives one tall bar; an open one spreads the chances out.
Autoregressive generation: output becomes the next input
That streaming effect you see in ChatGPT? This is why.
Iteration 1 / 5
Input
Output
Generated so far:
The capital of France is ▌
Temperature — the creativity dial
Always picks "Paris" — deterministic
Training: reading the internet to learn patterns
Learning to predict the next token, over and over, on massive data
Billions of parameters
adjusted over weeks or months
on thousands of chips
Big models are trained on trillions of tokens of text
Human Scale
Even reading a book every day, a person would need thousands of lifetimes to read that much
Training Cost
Thousands of powerful chips running for weeks or months, which costs a lot of money and electricity
Training = predicting the next word, trillions of times
Wrong prediction → adjust parameters!
Grammar, facts, reasoning — all learned from next-word prediction
The model has a fixed-size context window
It can only see a limited number of tokens at once
Measured in
tokens
not words or pages
Everything counts
in + out
your messages and its replies
Size
varies
by model; check the docs
LLMs have NO memory between conversations
Chat 1
"My name is Alex"
"Nice to meet you, Alex!"
Chat 2 (new session)
"What's my name?"
"I don't know your name."
FORGOTTEN
Each conversation starts completely fresh — no persistent memory
The complete journey from question to answer
Think of it as "autocomplete on steroids"
I'm going to the...
3 boring suggestions. That's it.
Explain quantum physics like I'm 5
Full coherent paragraphs, on any topic
Same principle. Vastly more training text. Vastly bigger model.
Know the capabilities AND the limits
CAN
CAN'T
Now you know what powers ChatGPT, Claude, Gemini, and Llama!