XP: 0
🎓 Bonus · Module 15 · How Models Really Learn

How Models Really Learn

You built a model in the simulator — but where does a real LLM get its knowledge, and how does it learn to be a helpful assistant instead of a rambling text-predictor? The answer is three stages: Pretraining → Fine-tuning → RLHF. This is the part everyone's curious about.
The three stages

From blank network to ChatGPT — in 3 steps

Back in Module 3 you learned how a network learns: backpropagation nudges the weights to lower the error ("turning the knobs"). That's the engine. But a real chatbot goes through three separate training stages, each using that same engine for a different goal.

Stage 1

📖 Pretraining

Read a huge chunk of the internet and just predict the next word, billions of times. This is where knowledge comes from.
→ a "smart but wild" text predictor
Stage 2

🎯 Fine-tuning

Show it thousands of example conversations (question → good answer) so it learns the format of being a helpful assistant.
→ answers questions instead of rambling
Stage 3

👍 RLHF

Humans rank its answers; the model learns to prefer the ones people like — helpful, honest, harmless.
→ polished, aligned, safe
Layman example — raising an expert

Pretraining = a kid reading every book in the library (soaks up knowledge, but blurts random things). Fine-tuning = apprenticeship, watching pros answer questions the right way (learns the job). RLHF = a mentor giving thumbs-up/down until their judgment is polished (learns good taste). Same brain — three phases of growing up.

Stage 1

📖 Pretraining — where knowledge comes from

This is the giant, expensive stage. The model reads a massive slice of the internet — books, articles, code, forums — and does exactly one thing: predict the next word (Module 5!). No labels, no humans grading it. The text itself is the answer key: hide the next word, guess it, check, adjust the weights, repeat trillions of times.

Why this creates knowledge

To predict "The capital of France is ___", the model must learn that it's Paris. To finish "Water boils at ___ degrees", it must learn physics. Predicting the next word forces it to absorb facts, grammar, reasoning, and style — all just to guess better. Knowledge is a side-effect of getting good at the guessing game. This is called self-supervised learning (the data labels itself).

The catch: after pretraining, the model is brilliant but wild. Ask it a question and it might just continue with more questions — because on the internet, questions are often followed by more questions. It predicts text; it doesn't yet know it's supposed to help.

🎮 Game 1

Be the pretraining loop

Predict the next word to "train" the model. Each correct guess teaches it a fact — watch its knowledge bar fill. This is the whole of pretraining, just tiny.

Predict the next word (self-supervised)
The text is its own answer key — no human needed.
📚 knowledge absorbed
Stage 2

🎯 Fine-tuning — teaching it the job

Now we tame the wild genius. We show it thousands of example conversations written by humans: a question, and an ideal answer. It keeps doing next-word prediction — but now on demonstrations of being helpful. It learns the format: "when I see a question, I give a direct, useful answer" (not more questions).

This is called Supervised Fine-Tuning (SFT) — "supervised" because humans supplied the correct answers. It's a small, cheap stage compared to pretraining (thousands of examples, not trillions of words), but it completely changes the model's behavior.

Same knowledge, new manners

Fine-tuning doesn't add much new knowledge — the facts came from pretraining. It teaches behavior: how to respond, what tone, when to refuse. Think of it as etiquette school for a genius who never learned how to hold a conversation.

🎮 Game 2

Watch fine-tuning flip the behavior

Same question, same knowledge — but see how the model responds before fine-tuning (wild text-predictor) vs after (helpful assistant). Click to fine-tune each example.

Before → After fine-tuning
Click "Fine-tune" to teach it the assistant format.
Stage 3

👍 RLHF — learning what people actually prefer

The final polish, and the "secret sauce" behind ChatGPT feeling so good. RLHF = Reinforcement Learning from Human Feedback. Fine-tuning taught the model to answer; RLHF teaches it to answer the way people prefer.

1️⃣

Collect human preferences

The model writes 2+ answers to a prompt. Humans pick which is better. Do this thousands of times.
2️⃣

Train a "reward model"

A second AI learns to predict which answers humans will like — it becomes an automatic judge that scores any answer.
3️⃣

Reinforce the good answers

The model generates answers, the reward model scores them, and (via backprop) the model is nudged to produce higher-scoring ones. It learns good taste.
Layman example — a chef and a food critic

The model is a chef cooking dishes. Instead of a human tasting every plate forever (too slow), we train a food critic (reward model) who learned everyone's tastes. Now the chef cooks, the critic scores instantly, and the chef adjusts recipes to score higher — improving fast, without a human at every meal.

Why this matters (and its limits)

RLHF is what makes models helpful, honest, and harmless — it's where "don't produce harmful content" and "admit when unsure" get reinforced. But it's imperfect: the model learns what human raters preferred, which can bake in their biases, or make it "people-pleasing" (agreeing to sound nice). It's alignment, not perfection.

🎮 Game 3

Be the human feedback

You're the human rater. For each prompt, pick the better answer. Your choices train the "reward model" — and you'll watch the assistant's quality climb as it learns your preferences.

Pick the better answer (👍 = reward)
Your preferences become the model's reward signal.
👆 Pick the answer a human would prefer.
assistant quality
50%
Zoom out

The whole pipeline, start to finish

Here's how the three stages connect into the model you talk to every day:

📖

Pretraining — trillions of words

Predict-the-next-word on the internet → raw knowledge & language. Months, millions of $, huge GPU clusters.
🎯

Fine-tuning (SFT) — thousands of examples

Human-written Q→A demos → learns the assistant format. Cheaper, changes behavior not knowledge.
👍

RLHF — human preferences

Rank answers → reward model → reinforce the good ones. The final polish; helpful, honest, harmless.
🤖

= The assistant you chat with

ChatGPT, Claude, Gemini — all built by this exact 3-stage recipe.
🎯 Check your understanding

Quick challenge

1. Where does a model get its knowledge?
2. Why is pretraining called self-supervised?
3. What does fine-tuning (SFT) mainly change?
4. In RLHF, what does the reward model do?
5. All three stages ultimately rely on which engine from Module 3?
Takeaway

What you learned

Every modern chatbot is built in three stages, all powered by backpropagation (Module 3): 📖 Pretraining — predict-the-next-word on trillions of words → this is where knowledge comes from (self-supervised: the text labels itself). 🎯 Fine-tuning (SFT) — thousands of human Q→A demos → learns the behavior of a helpful assistant instead of a wild text-predictor. 👍 RLHF — humans rank answers, a reward model learns their taste, and the model is reinforced toward answers people prefer → helpful, honest, harmless. Same knowledge from stage 1; stages 2 & 3 shape how it's delivered.

🎉 That's the complete picture — you now understand not just how an LLM is built, but how it's trained to be an assistant. This was the last big gap. You've gone from a single pixel to understanding (and building) the whole modern AI pipeline.

🚀 Ready for the next level? → Applied AI

You've mastered the concepts. Now build it all for real, in code. The Applied AI course is the hands-on sequel: train a GPT from scratch in PyTorch, fine-tune with LoRA, and wire up RAG with a vector database — every module pairs real, copyable code with interactive explainers.

⚙️ Continue to the Applied AI course →