How LLMs Work: The Intuition
You learned English from patterns, not by memorising every sentence. Large language models learn the same way.
By the end of this lesson you will be able to
- explain in plain words how an LLM learns from text
- describe next-token prediction and why it is the core of ChatGPT
- explain tokens, embeddings, attention and inference with everyday examples
Step 1: How did you learn English?
Parents talked to you. Teachers taught you. You read books, watched TV and practised speaking. But here's the key question: did anyone teach you every possible sentence?
No. You learned patterns. After hearing “I eat rice”, “I eat pizza”, “I eat mango”, you automatically understand “I eat pasta”, even if you've never heard it before.
A Large Language Model (LLM) learns the same way. It doesn't memorise every sentence. It learns patterns in language.
Step 2: How an LLM learns
Imagine a baby AI. At first it knows nothing: you say “Hello” and it replies “?????”. Now feed it millions of books, Wikipedia, websites, research papers, news and code. That's training.
After seeing billions of sentences, it starts noticing patterns: “The sky is” → blue. “Fish can” → swim. “Birds can” → fly. It is discovering statistical relationships, not memorising a dictionary.
Step 3: What happens during training?
Take the sentence “I love eating ice cream.” Hide the next word and ask the model to predict it:
At first
“I love eating ___” → pizza ❌
The correct answer is ice. The model adjusts its internal parameters slightly.
Trillions of times later
“I love eating ___” → ice is now very likely ✅
This repeated predict → check → correct loop is the essence of training.
Step 4: What does the model actually learn?
People ask: “Does ChatGPT memorise books?” No. It learns probabilities and associations:
Step 5: The secret behind ChatGPT
Most people think ChatGPT searches a database. It doesn't. Type “The capital of France is” and the model scores every possible next word:
| Word | Probability |
|---|---|
| Paris | 99.7% |
| London | 0.2% |
| Delhi | 0.05% |
| Tokyo | 0.05% |
It picks Paris, adds it to the text, then predicts the next token again. One token at a time.
Step 6: Tokenisation
LLMs don't read whole sentences, or even whole words. They read tokens. “Artificial Intelligence is amazing.” becomes Artificial Intelligence is amazing .. Longer or rarer words get split: unbelievable → un + believ + able. Every token then gets an ID number, because computers only process numbers:
| Token | ID |
|---|---|
| Artificial | 5821 |
| Intelligence | 1942 |
| is | 35 |
| amazing | 9043 |
Step 7: Embeddings (word meaning)
Which words are similar: dog, cat, car, lion? You'd say dog, cat and lion are related. The computer learns the same thing. Instead of storing words, it stores vectors (lists of numbers):
Dog → [0.31, 0.82, 0.44, …]
Cat → [0.29, 0.80, 0.42, …]
Car → [0.91, 0.05, 0.63, …]
Dog and Cat have close vectors because their meanings are similar. Car is far away.
Step 8: The Transformer, the brain of an LLM
Before 2017, models mostly read left to right. Transformers changed everything by looking at all the words together. Take: “The trophy didn't fit in the suitcase because it was too big.” What is “it”? The trophy. The Transformer uses attention to focus on the most relevant words. See lesson 8 for the details.
Step 9: Attention, the superpower
“Benedict hit the ball because he was angry.” Who was angry? Benedict. Your brain paid attention to the relationship between the words. Transformers do the same mathematically: instead of treating every word equally, they give more importance to the relevant ones.
Step 10: Inference, when you ask a question
When you ask ChatGPT “Explain AI”, the model does not learn anything new. It simply predicts the next token again and again:
One token at a time until the response is complete. That's inference.
The complete LLM pipeline
Think of an LLM as a very experienced librarian who has read millions of books but doesn't memorise every page. They have learned how language is structured. When you ask a question, they don't look it up in a book; they use everything they've learned to predict the most likely next words, one token at a time.
Fun facts
- GPT stands for Generative Pre-trained Transformer.
- “Large” refers to both the enormous training data and the billions (or trillions) of parameters.
- GPT-3 has 175 billion parameters. Newer frontier models are believed to have hundreds of billions to trillions, though exact numbers are often not disclosed.
- An LLM does not think like a human. It performs mathematical operations on vectors and probabilities.
- During inference, an LLM predicts the next token, not the whole sentence at once.
Students often say “ChatGPT knows the answer.” More accurate: “ChatGPT generates the answer by repeatedly predicting the most probable next token, based on the prompt and the patterns it learned in training.”
That's why LLMs can be impressive yet still make mistakes, or hallucinate, when the most probable continuation isn't factually correct.
Key takeaways
- LLMs learn patterns in language, not a list of memorised sentences.
- Training = predict the next word, check, correct, repeated trillions of times.
- Text → tokens → IDs → embeddings → Transformer with attention.
- Answering = predicting one token at a time (inference). No learning happens while you chat.
Check your understanding
1. How does ChatGPT produce an answer?
Generation is repeated next-token prediction, one token at a time.
2. Why are Dog and Cat stored as similar vectors?
Embeddings are learned from how words are used; similar usage means similar vectors.
3. Why can an LLM “hallucinate”?
It generates plausible text, and plausible isn't always correct.