4.4.2 · D4Alignment, Prompting & RAG

Exercises — Reward modeling

2,724 words12 min readBack to topic

This page is a self-test ladder for reward modeling. Work each problem before opening its solution. The rungs climb from "do you recognize the pieces?" up to "can you build the whole thing?".

Everything you need was built in the parent note. Keep these symbols in mind:

The picture below (Figure 1) is the only geometry you need — glance at it before starting.

Figure — Reward modeling

Level 1 — Recognition

Recall Solution 1.1

Answer: (b). We maximize the likelihood of the human's observed choice, whose probability is . Maximizing a probability = minimizing its negative (natural) log, giving .

  • (a) is MSE regression — wrong tool (see the L1 mistake below).
  • (c) is the probability itself, not a loss (we want something to minimize, and this grows as we get better).
  • (d) throws away the sign of , so it can't tell "right order" from "wrong order".
Recall Solution 1.2

, so . Meaning: the model has no opinion — it thinks the two answers are equally good, a coin flip. This is the exact centre of the curve in Figure 1.


Level 2 — Application

Recall Solution 2.1

Step — form the difference (WHY: only enters the loss). . Step — sigmoid. . Step — negative log (natural). . On Figure 1: sits well to the right, near the top, loss small — the model already ranks the winner clearly higher, so there's little to fix.

Recall Solution 2.2

. . . Comment: same magnitude of gap but the sign flipped, and the loss jumped from to . On Figure 1, is to the left of centre where is small — the model disagrees with the human and is punished hard.

Recall Solution 2.3

(a) Shift. New scores: . The loss only sees the difference: So , identical to 2.1. The cancels: the reward model is shift-invariant. (b) Scale. Doubling gives , so . Then different from 2.1. Punchline: the loss is invariant to shifting both rewards but not to scaling them, because scaling stretches the difference (here ) and is not scale-free in its argument. So absolute values are meaningless, but the spread of rewards genuinely matters for training.


Level 3 — Analysis

Recall Solution 3.1

Derivation (WHY each step). Two facts about the sigmoid we'll use:

  1. — the standard sigmoid derivative.
  2. Therefore , using the identity . Now apply the chain rule. Since , we have . Then So the asserted formula follows directly from the sigmoid derivative + chain rule. (i) : . (ii) : . Interpretation: when the model is already confidently correct, the update is tiny () — "nothing to fix". When it is confidently wrong, the update is near-maximal () — a big shove to swap the order. The loss is self-correcting: effort flows to the examples that are actually wrong.
Recall Solution 3.2

Notation reminder. (read " choose ") counts how many unordered ways you can pick items out of ; its formula is . Here we pick responses out of to compare. Why all pairs, not just adjacent: one expensive human ranking yields 10 training signals instead of 4, and comparing far-apart ranks (rank 1 vs rank 5) gives a large clean margin, so the RM doesn't overfit to a single noisy neighbour comparison. This is InstructGPT's trick.

Recall Solution 3.3

Average loss is for both — identical by that metric. But Model A nails 3 pairs (loss ) and catastrophically fails one (, i.e. it confidently ranks the wrong answer higher). Model B is mildly unsure everywhere (, just below a coin flip). Trust Model B more for safe deployment: it never confidently inverts a preference. Model A has a "confidently wrong" hole — exactly the kind of region a policy will find and exploit during RL. Average loss hides this because it can't see the distribution of errors.


Level 4 — Synthesis

Recall Solution 4.1

Objective per answer = reward . Assume is near the reference so its KL .

  • : .
  • : . At : scores , so the objective prefers — the KL leash defeats the hack. Threshold: indifference when . For the leash is too loose and the policy chases the hacked answer ; for it stays with . This is why exists and why it must be tuned — see KL divergence and PPO.
Recall Solution 4.2

Match the two shapes. Both are — the only thing that changes between them is what we plug in as the "score".

  • In the RM loss the score is the network output .
  • In DPO the score is the same Bradley–Terry "score" role, just written differently — call it to keep the parallel explicit. It is not a new concept; it is what replaces inside the identical loss template: Substitute: is exactly the argument of in the DPO loss above. So DPO is Bradley–Terry with the score baked into the policy's log-ratio — same statistical model, different parameterization of the score.

Level 5 — Mastery

Recall Solution 5.1

True-preference peak — set its derivative to zero: . Peak true value: . Measured reward at that same : , and it keeps climbing for (e.g. ) even while has already fallen below its peak. Lesson: past the two curves diverge — the RM's measured reward rises while true preference drops (Goodhart's law). Stop early (around ) and use the KL leash; "maximize the proxy forever" destroys the thing you actually cared about. See Figure 2 below.

Figure — Reward modeling
Recall Solution 5.2
  1. Collect preferences. For each prompt, sample answers, have humans rank them → pairs per prompt (efficient labeling). Guard: annotator disagreement → use comparisons, not absolute scores.
  2. Train the reward model with the pairwise loss (Bradley-Terry model, fit like Logistic regression). Guard: confidently-wrong pockets → track pairwise accuracy, not just mean loss (Ex 3.3).
  3. Normalize rewards per prompt before RL. Concretely: mean-center (subtract the batch mean so the average reward is ) and whiten (also divide by the batch standard deviation so the spread is , i.e. ). Guard: shift nonsense (Ex 2.3a) and unstable step sizes from an arbitrary reward scale (Ex 2.3b).
  4. Optimize the policy against with PPO + a KL penalty (Ex 4.1), or skip 2–4 and use DPO directly (Ex 4.2). Guard: reward hacking → tune , early-stop at the Goodhart peak (Ex 5.1).
  5. Deploy with the aligned policy; the input side is shaped by Prompting and, for factual grounding, RAG. Guard: distribution shift at deploy → keep monitoring and re-collect preferences.
Recall Solution 5.3

Per-pair losses (natural log):

  • : , loss .
  • : , loss .
  • : , loss . Mean . The negative- pair dominates — consistent with the self-correcting behaviour of Level 3.

Recall One-line summary of the whole ladder

Everything above is one formula seen from five heights: — recognize it (L1), plug numbers in (L2), read its gradient and error tails (L3), connect it to PPO/DPO (L4), and respect its Goodhart ceiling (L5).