10. RLHF & Alignment
Making models helpful, harmless, and honest
A language model trained purely on next-token prediction learns an extraordinary amount about the world. It can write code, explain scientific concepts, and carry on a conversation. But it doesn't automatically learn to be useful. Without extra work, a pre-trained model might produce confident-sounding misinformation, generate harmful content, or give technically correct but deeply unhelpful answers. Pre-training optimizes for predicting the next token in a corpus — not for being a good assistant.
This is the alignment problem in miniature: how do you take a capable model and steer it toward behavior that's actually helpful, honest, and safe? The dominant answer today is Reinforcement Learning from Human Feedback — RLHF.
Why Pre-Training Isn't Enough
The pre-training corpus is a mix of everything: great writing, terrible writing, misinformation, propaganda, forum arguments, and academic papers. A model trained on all of this learns to mimic the distribution. Ask it a question and it will generate text that looks like how people answer questions on the internet — which isn't always what you want.
More subtly, a raw pre-trained model doesn't really understand that it's supposed to be helping you. It's pattern-matching. If your prompt looks like the start of a debate, it'll generate the debate. If it looks like a creative writing piece, you'll get prose. Getting reliable, task-focused behavior out of a base model requires careful prompting and a fair amount of luck.
Step 1: Supervised Fine-Tuning
The first step is straightforward: collect a dataset of high-quality prompt-response pairs, written or curated by human contractors, and fine-tune the pre-trained model on them. This is called Supervised Fine-Tuning (SFT).
SFT teaches the model what "good" looks like in terms of format and tone. It learns to:
- Acknowledge when it doesn't know something
- Follow instructions before elaborating
- Structure answers with appropriate length and detail
- Avoid obviously harmful content
SFT alone produces a noticeable improvement over the base model. But it's limited by data. You can only write so many examples, and the model will still find ways to behave unexpectedly on prompts outside your training distribution. You need something more dynamic.
Step 2: The Reward Model
Here's the core insight behind RLHF: instead of telling the model what good looks like with fixed examples, train a separate model to evaluate output quality — and then use that evaluator to guide the main model's learning.
This separate model is the reward model (RM). To train it, you collect a large set of human preference rankings. Show human raters two (or more) completions for the same prompt, and ask: which is better? This is easier and faster than writing ideal completions from scratch, and it captures more nuanced human judgment.
The reward model learns to predict which response a human would prefer. Given a prompt and a completion, it outputs a scalar score. A response that's helpful, accurate, and well-structured gets a high score. A response that's evasive, wrong, or rambling gets a low score.
Step 3: PPO — The RL Loop
Now you have a reward signal. Time to use it.
Proximal Policy Optimization (PPO) is the reinforcement learning algorithm used to fine-tune the language model using the reward model's scores. The LLM is the "policy" — it takes a prompt as input and outputs a completion. The reward model acts as the environment, scoring that completion.
- Sample a prompt from the training distribution
- The LLM (policy) generates a completion
- The reward model scores the completion
- PPO computes a gradient update that makes high-scoring completions more likely
- Repeat thousands of times across millions of prompt-completion pairs
The full pipeline looks like this:
KL Divergence: Don't Drift Too Far
Left unconstrained, PPO will find shortcuts. The model might learn to produce responses that score high on the reward model without actually being good — a phenomenon called reward hacking. It might discover that the reward model can be fooled by verbose, confident-sounding text, or that certain phrases reliably boost scores.
The fix is a KL divergence penalty. During PPO training, you add a term to the loss that penalizes the model for moving too far from the SFT baseline. If the current policy's output distribution diverges significantly from the SFT model's distribution, the penalty kicks in and pulls it back.
This creates a trade-off: the model wants to maximize reward, but it can't stray too far from what it learned during SFT. The coefficient on the KL penalty is a key hyperparameter — too small and you get reward hacking, too large and the RL step barely does anything.
DPO: Skipping the Reward Model Entirely
RLHF with PPO is powerful but complex. You need to train two large models (the reward model and the policy), run expensive RL loops, and carefully tune the KL penalty. Direct Preference Optimization (DPO), introduced in 2023, offers a cleaner alternative.
DPO's key insight: the reward model in RLHF is implicitly representing what the optimal policy looks like. If you assume a particular mathematical relationship between the reward and the policy, you can re-derive the training objective in terms of the policy directly — no separate reward model needed.
In practice, DPO is simpler to implement and often matches or exceeds PPO-trained models on benchmarks. It's become the dominant approach for fine-tuning open-weight models.
The Alignment Tax
There's a persistent concern about aligned models: do they become worse at things in the process of becoming safer and more helpful? The answer is a qualified yes — at least on certain benchmarks.
Raw capability benchmarks sometimes show a small drop after alignment training. An aligned model might be slightly more likely to say "I'm not sure" when a raw model would have guessed (correctly). It might refuse edge-case questions that the raw model would have answered.
But this is largely a measurement artifact. The benchmarks were designed to test raw capability, not usefulness. In practice, aligned models are dramatically more valuable: they follow instructions reliably, handle edge cases gracefully, and don't produce outputs you have to sanitize before showing to users.
Try It: Preference Ranker
Preference Ranker
Read both completions and choose which you prefer. See how a reward model would score them and what the training signal would look like.
Wrapping Up the Series
This article marks the end of the LLM series. We've traveled from the raw mechanics of how tokens are represented, through the transformer architecture that processes them, up through training at scale, the tricks that make inference fast, the ways models generate text — and now to the techniques that make all of that capability actually useful.
The field is moving fast. RLHF and DPO are not the final word on alignment — they're today's best practical tools, and they have known limitations. Models can still be jailbroken, reward models can still be hacked, and the relationship between benchmark performance and real-world usefulness remains murky.
But the core ideas here — learning from human preferences, using reward signals to steer behavior, constraining optimization to avoid drift — are likely to remain central regardless of what comes next. Understanding them gives you a foundation to evaluate whatever new technique lands next month claiming to have solved alignment once and for all.
- Pre-training gives fluency and knowledge; alignment gives the model values and intent
- SFT teaches format and behavior via curated examples; it's the starting point for alignment
- Reward models learn to predict human preferences from pairwise comparisons
- PPO uses reward model scores as a training signal; KL penalty prevents reward hacking
- DPO skips the reward model and directly optimizes on preference pairs — simpler and often as effective
- The alignment tax is real but small; aligned models are far more useful in practice despite minor benchmark regressions