RLHF and Constitutional AI: learning from preferences
The InstructGPT pipeline (supervised tuning, a reward model fitted to preference pairs, then RL held near the start by a KL penalty) and Constitutional AI, which swaps human raters for written principles.
What runs in CodeSplash
- LNG063InstructGPT / RLHF pipeline Explained here
- LNG064Constitutional AI Explained here
You will be able to
- Name the three stages of the RLHF pipeline and what each one trains
- Write the Bradley–Terry loss a reward model is fitted with
- Explain what the KL penalty to a reference model protects against
- Describe how Constitutional AI produces preference labels, and what it shifts responsibility onto
Three stages
ReadRLHFReinforcement learning from human feedback (RLHF)Tuning a model with a reward model fit to people's pairwise preferences, then optimizing against it with RL such as PPO., as in InstructGPT, runs in three stages:
- Supervised fine-tuning on demonstrations of good answers (instruction tuning).
- A reward model fitted to human comparisons: for one prompt, raters say which of two responses is better.
- Reinforcement learning: the language model writes answers, the reward model scores them, and PPO raises the score, while a penalty keeps the model near where it started.
Raters find it easier to compare two answers than to write a perfect one, which is why preferences, not more demonstrations, drive stage 2.
The reward model
ReadA reward modelReward modelA model trained on human preference pairs to score responses; RLHF then trains the policy to raise that score. scores a prompt and response. It is fitted with the Bradley–TerryBradley–Terry modelA model of pairwise judgments: the difference in two items' log-worths sets the log odds that one is preferred to the other. loss on each chosen () and rejected () pair:
Only differences matter, so adding a constant to every score changes nothing. In the reference's example, the chosen response scores higher by a margin that gives a loss of 0.371; a larger margin would push it toward zero.
Stay near the start
ReadThe RL stage maximizes the reward minus a KL penaltyKL penalty to a reference modelA cost for drifting from the starting model's token probabilities, so preference tuning can't trade everything for reward.:
The reward model is an imperfect proxy fitted to limited comparisons. Optimize it without restraint and the policy finds responses the reward model overrates: long, flattering or oddly formatted. The KL term charges for drifting from the supervised model. In the reference's example a policy with KL 0.082 from its reference ends with a penalized utility of 0.752.
DExplorable · Preference optimization: reward models and DPO
How do pairwise preferences turn into a policy, and what does β protect against?
Small β lets the policy move far from the reference; large β keeps it close.
Comparisons simulated from hidden true rewards with a Bradley–Terry model.
Full-batch gradient steps on the DPO loss.
Step size on the implicit reward β(θ − θ_ref), so β doesn't change the speed.
- Reference policy
- DPO policy
- True optimum π_ref·exp(r*/β)
- Reward model + optimum (dots)
- KL from the reference (nats)
- 1.240
- Expected true reward
- 1.802
- Largest response probability
- 0.814
- Final DPO loss
- 0.4230
- Puzzle: Get within 0.1 of the true optimum's expected reward while staying under 1 nat from the reference.
- Puzzle: Make the policy put more than 90% on a single response.
After 500 steps on 100 pairs with β = 0.50, the policy gives “Correct and helpful” 81% and sits 1.24 nats from the reference. Its expected true reward is 1.80, against 0.34 for the reference and 1.71 for the true KL-regularized optimum. In this toy, DPO's policy is exactly what a fitted Bradley–Terry reward model plus the KL-regularized optimum would give.
Constitutional AI
ReadConstitutional AIConstitutional AIPreference tuning where a model critiques and ranks responses against written principles instead of human raters. replaces most human preference labels with a model guided by written principles. The model critiques and revises its own answers against the principles (a supervised stage), then a model judges pairs of answers against them to train the reward model (reinforcement learning from AI feedback).
In the reference's example, two responses scored against three weighted principles get ratings of 0.83 and 0.75, so the first would be "chosen". The choice of principles, their weights and the judging model now carry the values that raters carried before. Audit them, and keep human checks on outcomes.
What runs here
ReadPredict: no penalty
PredictPredict first
You set β = 0 and train for longer. The reward model's scores keep rising. What happens to the quality people would judge?
Reveal
It can fall. With no anchor, the policy drifts to outputs the reward model wasn't trained on and overrates. Rising proxy reward with falling true quality is reward overoptimization.
Common mistakes
ReadCheck: RLHF and Constitutional AI
CheckpointCheck yourself
Put the InstructGPT pipeline in order.
Show the answer
The order:
- Supervised fine-tuning on demonstrations
- Fit a reward model to human preference pairs
- Optimize the policy with PPO against the reward model, with a KL penalty
Each stage starts from the previous one's model; the KL penalty is measured against the supervised model.
Check yourself
A reward model scores the chosen response 2.0 and the rejected one 0.0. What is its Bradley–Terry loss, −log σ(2)? (Three decimals.)
Show the answer
Answer: 0.127
σ(2) = 1 / (1 + e⁻²) ≈ 0.881, and −log 0.881 ≈ 0.127. The loss depends only on the difference of the two scores.
Check yourself
What does the KL penalty in RLHF protect against?
Show the answer
Answer: a
The penalty keeps the policy where the reward model's judgments were learned, so its proxy stays meaningful.
Check yourself
In Constitutional AI, where do most preference labels come from?
Show the answer
Answer: a
That is reinforcement learning from AI feedback. Humans write and revise the principles instead of labeling every pair.
Check yourself
A team replaces human raters with Constitutional AI. What must they now audit most carefully?
Show the answer
Answer: a
The values move from the raters into the constitution and the judge. Human checks on outcomes remain necessary.
Recap
Recap- RLHF: supervised tuning, a Bradley–Terry reward model from preference pairs, then PPO against it.
- The KL penalty to the reference model keeps the policy where the proxy reward is trustworthy.
- Constitutional AI produces preferences from written principles and a judging model; audit both.
- Explained here; Bradley–Terry and PPO run elsewhere in CodeSplash.
Concepts in this lesson