Part XVII — LLM Post-Training: SFT, DPO, GRPO & Reasoning / Test-Time Compute · Chapter 3

RLHF: Bradley-Terry reward modeling

Hook

Every reward in this part so far was a known number, handed to the learner directly. A language model has no such thing — nobody can write down "this sentence is worth 7.3 points." What people can do easily is compare two answers and say which one they like better.

Intuition

Three candidate responses, no numeric reward for any of them — only three comparisons: "B beats A," "B beats C," "C beats A." Step through fitting a reward score to each response from nothing but those three judgments, watching the scores separate as the fit proceeds.

Formalize

The Bradley-Terry model turns a pile of pairwise comparisons into a reward score per item: the probability that ii beats jj is a sigmoid of the difference in their scores,

P(ij)=σ(rirj)P(i \succ j) = \sigma(r_i - r_j)
  • P(ij)P(i \succ j) — the probability that response ii beats response jj in a head-to-head comparison.
  • ii, jj — the two candidate responses being compared.
  • rir_i, rjr_j — the fitted reward scores for responses ii and jj.
  1. Fitting r is ordinary logistic regression

    Fitting rr from observed comparisons is exactly Part II's logistic regression, with each comparison contributing one cross-entropy term.

  2. The fitted score stands in for the reward

    Once a reward model is fit this way, it can score a response the same way any other trained reward function would — and that score is what stands in for the reward Chapter 4's policy gradient needs but nobody could hand it directly.

Play

The policy starts uniform, with no idea any response is better than any other. After training on the fitted reward model — not on any ground truth, since none exists here — it clearly favors the response humans actually preferred, using the exact same update rule from Chapter 4.

Worked example

With AA fixed at reward 00 as a reference point (Bradley-Terry scores are only meaningful relative to each other, exactly like softmax logits):

  1. First fitting step

    All three scores start at 00, so every comparison's predicted probability is σ(0)=0.5\sigma(0)=0.5 — completely uncertain. Each comparison pushes the winner's gradient down by (1p)(1-p) and the loser's up by (1p)(1-p), i.e. by 0.50.5 each:

    • BB beats AA: pushes BB by 0.5-0.5
    • BB beats CC: pushes BB by another 0.5-0.5 (total 1.0-1.0), pushes CC by +0.5+0.5
    • CC beats AA: pushes CC by 0.5-0.5 (net 00 for CC, since its two pushes cancel)

    Descending: rB00.5(1.0)=0.5r_B \leftarrow 0 - 0.5(-1.0) = 0.5; rC00.5(0)=0r_C \leftarrow 0 - 0.5(0) = 0BB wins two comparisons and its score rises, while CC's one win and one loss (against parties still at 00) exactly cancel.

  2. After three fitting steps

    Repeating the same gradient step, using the updated rewards each time:

    • After step 2 (starting from rB=0.5,rC=0r_B=0.5, r_C=0): rB0.8775r_B\to0.8775, rC0.061r_C\to0.061
    • After step 3 (starting from those): rB1.18r_B\to1.18, rC0.15r_C\to0.15

    rA=0r_A=0 throughout (fixed as the reference) — the fitted scores recover the true order the comparisons implied (BB beat both, CC split, AA lost both), entirely from three yes/no judgments.

  3. Training the policy on that fitted reward

    Feeding these three scores through Chapter 4's exact policy-gradient update, one response at a time, moves the policy from uniform to favoring BB with about 46%46\% of the probability mass — the response people actually preferred.

Checkpoint

Fit the reward model until response B's reward passes 1.0.

Step forward to try it
Summary
P(ij)=σ(rirj)P(i \succ j) = \sigma(r_i - r_j)

RLHF — short for Reinforcement Learning from Human Feedback — is two ideas already in this course, run back to back: fit a reward model from preference data using ordinary logistic regression, then run policy gradient against that fitted reward exactly as if it had been the real thing all along. Nothing about the second step needed to know the reward was learned rather than given — which is exactly what makes this technique general enough to align a model with a preference nobody could ever have written down as a formula. This closes the reinforcement-learning arc built from three completely different pieces: bandits, values, and policies. The capstone puts all three to work solving one small maze.