Reinforcement Learning from Human Feedback (RLHF)
WHAT is RLHF?
The big idea: preferences are cheaper and more reliable than absolute scores. A human is bad at saying "this answer is a 7.3/10" but good at saying "answer A is better than answer B."
WHY not just do more supervised learning?

Stage 1 — Supervised Fine-Tuning (SFT)
WHAT: Fine-tune the base LM on a dataset of (prompt, ideal human answer) pairs with ordinary cross-entropy.
WHY: The base model predicts internet text, not helpful assistant replies. SFT gives a sane starting policy that already talks like an assistant, so RL has a decent place to start (RL from scratch on language would be hopeless).
Stage 2 — The Reward Model (derived from scratch)
WHAT: Given a prompt and two responses (winner) and (loser), a labeler picks the better one. We want a scalar model such that better answers get higher reward.
HOW do we turn "A beats B" into a loss? We use the Bradley–Terry model of pairwise comparisons. Suppose each response has a latent "quality" . Bradley–Terry says the probability a human prefers over is a logistic function of the reward difference:
Why this form? Divide top and bottom by ... let's instead factor to reveal the sigmoid. Divide numerator and denominator by :
Why this step? It shows the model only cares about the difference of rewards — exactly what a comparison gives us. The absolute scale is unidentified (adding a constant to all rewards changes nothing), which is fine.
Now maximize the likelihood of the observed human choices → minimize negative log-likelihood:
The RM is usually the SFT model with the final token-prediction head replaced by a single scalar head on the last token.
Stage 3 — RL optimization with PPO
WHAT: Treat the LM as a policy . Sample a response, score it with the RM, and update to increase expected reward.
The naive objective:
WHY this is dangerous: The RM is only accurate near data it saw. If we push hard on pure reward, the policy finds adversarial gibberish that fools the RM (reward hacking). So we add a leash back to the SFT policy.
WHY the KL term (derivation of intuition): We want high reward but stay close to a trusted model. Rewrite the per-token reward as . If drifts far from , the log-ratio blows up and eats the reward. This keeps generations fluent and prevents mode collapse.
HOW does PPO update the policy? PPO maximizes reward while limiting how far each update moves the policy, using the clipped surrogate objective. With ratio and advantage :
Why clip? A single big update on a noisy reward can destroy the policy. Clipping removes the incentive to move beyond , giving small, safe steps.
Worked Example 1 — Reward-model loss numerically
Suppose for one comparison and .
- Step: difference . Why? RM only sees the gap.
- Step: . Why? Probability we predicted the winner correctly.
- Step: loss . Why? Low loss because the model already ranked the winner higher; gradient will still gently widen the gap.
If instead the model was wrong (): , loss — much bigger, pushing a strong correction. This is exactly what we want.
Worked Example 2 — The KL leash in action
Say for a token the SFT model gives probability to a word and the current policy gives .
- Log-ratio .
- With , penalty subtracted from the reward.
- Why this step? The policy got 4× more confident than the trusted model on this token; the penalty says "only do that if the reward gain clearly beats ."
Common mistakes
Recall Feynman: explain it to a 12-year-old
Imagine teaching a puppy tricks. You can't explain in English what "good behavior" means, but you can point at two tricks and say "that one was better." You give a treat-predicting judge (the reward model) lots of these comparisons until it learns to guess which trick you'd like. Then you let the puppy try things, the judge hands out pretend-treats, and the puppy learns to do more of what earns treats. But you keep the puppy on a leash (KL penalty) so it doesn't run off doing weird stuff just to trick the judge. That leashed treat-training is RLHF.
Active-recall flashcards
#flashcards/ai-ml
What are the 3 stages of RLHF, in order?
Why use pairwise comparisons instead of absolute quality scores?
Write the reward-model loss and its origin.
Why does the RM only depend on the difference of rewards?
What is the full RLHF RL objective?
Why include the KL penalty?
What is reward hacking (Goodhart) in RLHF?
What does PPO's clipping accomplish?
Does RLHF add new knowledge?
What architecture is the reward model usually?
Connections
- Supervised Fine-Tuning (SFT) — provides the starting policy and reference model.
- Proximal Policy Optimization (PPO) — the RL algorithm doing the update.
- KL Divergence — the leash keeping the policy near SFT.
- Bradley-Terry Model — statistical basis of the reward loss.
- Direct Preference Optimization (DPO) — RLHF without an explicit RM/RL loop.
- Reward Hacking and Goodhart's Law — the failure RLHF must guard against.
- Constitutional AI / RLAIF — replacing human labels with AI feedback.
- Prompting and Retrieval-Augmented Generation (RAG) — alternative/complementary alignment levers.
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
Dekho, RLHF ka core problem yeh hai: "helpful, harmless aur honest bano" — iske liye koi seedha formula nahi likh sakte. To hum kya karte hain? Humans ko do jawab dikhate hain aur poochte hain "in dono me kaunsa better hai?" Absolute rating (jaise 7/10) dena insaan ke liye mushkil hai, par comparison ("A behtar hai B se") dena easy aur reliable hai. Yehi trick hai.
Pipeline teen steps ka hai. Pehle SFT: base model ko human-written accha jawab dikha kar fine tune karo, taaki woh assistant ki tarah baat kare. Phir Reward Model: preference comparisons se ek chhota model train karo jo bata de ki human kis jawab ko pasand karega. Iski loss Bradley-Terry se aati hai — — matlab model sirf winner aur loser ke reward ke difference ki parwah karta hai. Teesra, PPO: language model ko policy maan kar RL se train karo, reward model score badhane ke liye.
Sabse important cheez hai KL penalty (the leash). Agar tum sirf reward maximize karoge, model "reward hacking" kar dega — aisa bakwaas output banayega jo reward model ko chakma de de, par actually ghatiya ho. Isliye KL term policy ko SFT model ke paas rok kar rakhta hai. Ek baat yaad rakho: RLHF naya gyaan nahi sikhata, woh sirf pehle se maujood behaviors ko re-prioritize karta hai — accha wala upar, bura wala neeche. Yeh matter isliye karta hai kyunki yehi technique ChatGPT jaise models ko "aligned" aur useful banati hai.