4.4.1 · D4Alignment, Prompting & RAG

Exercises — Reinforcement Learning from Human Feedback (RLHF)

2,104 words10 min readBack to topic

Before we start, the two workhorse numbers of this whole page, drawn once so no symbol is used blind:

Figure — Reinforcement Learning from Human Feedback (RLHF)

Level 1 — Recognition

L1.1

Name the three stages of RLHF in order, and name the single tool used inside each stage.

Recall Solution
  1. Supervised Fine-Tuning (SFT) — ordinary cross-entropy on (prompt, ideal answer) pairs.
  2. Reward Model — trained with the Bradley-Terry Model pairwise loss.
  3. RL optimizationProximal Policy Optimization (PPO) with a KL Divergence penalty.

Mnemonic: "SFT Ranks, PPO Pulls (on a KL leash)."

L1.2

In the reward-model loss which response is and which is ? What does output here?

Recall Solution

is the winner (the response the human preferred); is the loser. The output is the model's predicted probability that the human prefers the winner — a number in . We take of it so that a confident correct prediction (near ) gives near-zero loss.

L1.3

True/False: "The reward model outputs an absolute quality score on a fixed 0–10 scale."

Recall Solution

False. Bradley–Terry only fixes reward differences. Adding the same constant to every reward leaves the loss unchanged, so the zero-point is arbitrary. Only comparisons carry meaning.


Level 2 — Application

L2.1

For one comparison the reward model outputs and . Compute the gap , the predicted probability , and the loss.

Recall Solution
  • Gap: . Why the gap? The RM only sees the difference of rewards.
  • Probability: .
  • Loss: .

Low loss — the model already ranks the winner above the loser, so only a gentle nudge is needed.

L2.2

The model got it wrong: it scored , . Recompute the loss and compare to L2.1.

Recall Solution
  • Gap: .
  • Probability: .
  • Loss: .

The loss jumped from to — an 8.4× larger penalty. A wrong ranking is punished hard, exactly what we want.

L2.3

A token gets probability under and under . With , compute the per-token KL penalty subtracted from the reward.

Recall Solution
  • Log-ratio: .
  • Penalty: .

The policy is more confident than the trusted model here, so the reward gain from this token must beat or the leash pulls it back.


Level 3 — Analysis

L3.1

Show algebraically that adding a constant to every reward leaves unchanged. What does this prove about the reward scale?

Recall Solution

Replace for all . Inside the loss we only ever use the gap: The cancels, so and the loss are identical. Conclusion: the RM's absolute zero-point is unidentified — only differences are learnable. This is why we never treat a raw reward number as an "absolute grade".

L3.2

Explain, using the objective, why removing the KL term invites reward hacking (Reward Hacking and Goodhart's Law).

Recall Solution

The full objective is With the policy maximizes alone. But is a proxy, accurate only near the data it saw. The optimizer will happily wander into weird off-distribution outputs where is mistakenly high — gibberish that fools the RM. The KL term charges per unit of drift from the trusted , so straying far costs reward and is only worth it if the reward gain is real. This is KL Divergence acting as a leash.

L3.3

Derive the sigmoid form of Bradley–Terry: starting from show it equals .

Recall Solution

Divide numerator and denominator by : What this reveals: the model depends only on the difference — precisely the information a pairwise comparison provides. Everything shared cancels.


Level 4 — Synthesis

L4.1

One PPO step. Old policy prob of a token , new policy prob , advantage , clip . Compute the ratio , the clipped ratio, and the PPO term .

Recall Solution
  • Ratio: .
  • Clip range: , so clipped .
  • Two candidates: ; clipped .
  • PPO term: .

Because and overshot , Proximal Policy Optimization (PPO) caps the gain at — the model gets no extra reward for pushing past the clip, killing the incentive to take a reckless step.

L4.2

Same numbers but a bad action: with . Compute the PPO term and explain why clipping does not protect here.

Recall Solution
  • Candidates: ; clipped .
  • PPO term: .

With a negative advantage the picks the more negative (unclipped) value, so the full penalty applies. This is deliberate: PPO always keeps the more pessimistic estimate, so a genuinely bad action is never let off the hook by clipping.

L4.3

Combine reward and leash for one full token. RM reward ; gives the token prob , gives ; . Compute the KL-adjusted reward . Is this token still worth it?

Recall Solution
  • Log-ratio: .
  • Penalty: .
  • Adjusted reward: .

Still positive, so the reward gain () clearly beats the leash cost () — the update is justified. Had been, say, , we'd get and the leash would win.


Level 5 — Mastery

L5.1

Your RLHF model's average reward keeps rising over training, but human raters say the outputs are getting worse (repetitive, sycophantic). Diagnose the failure by name, identify which knob is mis-set, and state the fix.

Recall Solution
  • Diagnosis: Reward Hacking and Goodhart's Law. The measured proxy (RM reward) improves while the true target (human judgment) degrades — the classic Goodhart split.
  • Knob: (the KL coefficient) is too small, so the leash to is too loose and the policy drifts into off-distribution outputs the RM mis-scores.
  • Fixes: raise ; refresh the RM with fresh comparisons on the current policy's outputs (the region it now visits); add early stopping on a held-out human eval. Optionally switch to Direct Preference Optimization (DPO) which folds the KL constraint into a single supervised loss, or use Constitutional AI / RLAIF to scale comparison labels.

L5.2

A colleague proposes skipping the reward model entirely and optimizing preferences directly. Name the method, and state in one sentence how it removes the separate RM + PPO loop.

Recall Solution
  • Method: Direct Preference Optimization (DPO).
  • How: DPO algebraically shows the optimal RLHF policy is a closed-form function of the reward, so it re-parametrizes the reward through the policy itself and trains directly on the preference pairs with a single classification-style loss — no explicit reward model and no PPO sampling loop.

L5.3 (design)

You have a budget for either (a) more SFT demonstrations or (b) more preference comparisons. The model already talks fluently like an assistant but frequently picks the less helpful of two plausible answers. Which do you buy, and why — grounded in what each stage can and cannot do?

Recall Solution

Buy (b) preference comparisons. Reasoning tied to each stage's job:

  • SFT can only imitate answers we wrote; the model is already fluent, so more demonstrations mostly repeat what it can do.
  • The failure — choosing the worse of two plausible answers — is a ranking problem over the model's own outputs, exactly what preference data + the reward model fix. Comparisons give feedback on outputs we never wrote, covering the space the model actually explores.
  • So more comparisons sharpen the reward model and, through PPO, steer the policy toward the better answer among plausible ones.

Recall One-glance answer key

L2.1 loss ::: L2.2 loss ::: L2.3 penalty L4.1 PPO term ::: L4.2 PPO term ::: L4.3 adjusted reward