4.4.1 · D2Alignment, Prompting & RAG

Visual walkthrough — Reinforcement Learning from Human Feedback (RLHF)

2,075 words9 min readBack to topic

We will build, in order:

  • what a preference even is (a pointing finger),
  • what a reward number is (a height),
  • why we compare differences and not absolutes,
  • how the sigmoid turns a difference into a probability,
  • how maximum likelihood turns that probability into a loss,
  • and the degenerate cases (tie, already-correct, confidently-wrong).

Prerequisites we lean on: Bradley-Terry Model, Supervised Fine-Tuning (SFT) (the model whose head we reuse), and later KL Divergence / Proximal Policy Optimization (PPO) for stage 3.


Step 1 — The only raw material: a human points

WHAT. A labeler sees a prompt and two candidate answers. They pick one as better. That's it. No numbers, no scores — just a finger pointing.

We name the two answers by their fate:

  • — the winner (the one pointed at),
  • — the loser (the other one).

The symbol means "is preferred to". So the whole datum is the sentence given .

WHY start here. Humans are unreliable at "rate this 7.3/10" but reliable at "this one is better." We refuse to invent numbers we don't have. Our entire machine must be buildable from pointing alone.

PICTURE. Two answer cards; a hand points at the left one. There is no number anywhere yet — that is the whole point of Step 1.


Step 2 — Invent a height called "reward"

WHAT. We imagine every answer has a hidden number — a "quality height" — and we build a model that reads a prompt+answer and outputs that single number.

Reading the symbols:

  • — the reward (a scalar, one number),
  • — the model's tunable weights (the knobs we will turn),
  • — the inputs it looks at: the prompt and one answer.

So = "how high this answer stands, according to a model with knobs ."

WHY invent a height at all. A pointing finger compares two things but gives us no function we can optimize a language model against later. We need a machine that outputs a score for any single answer, so stage 3 can score answers it has never seen. The height is that bridge.

PICTURE. The two cards from Step 1, now placed at two heights on a vertical axis labeled . Winner sits higher — but notice the axis has no fixed zero yet; we could slide both cards up together and nothing about "which is higher" would change. Remember that; it matters in Step 5.


Step 3 — Only the difference of heights is meaningful

WHAT. We compute one number: the gap between the winner's height and the loser's.

  • → the model already ranks the winner higher (good).
  • → the model thinks they're equal (undecided).
  • → the model ranks the loser higher (wrong — must be corrected).

WHY the difference and not the two heights separately. The human never told us an absolute height — only "left is above right." So the only thing our data can pin down is the gap . Sliding both heights up by the same amount leaves untouched, and our human would report the exact same preference. Everything downstream must depend on alone.

PICTURE. A vertical bracket measuring the gap between the two card heights. A ghosted "slid up" copy of both cards shows the gap is identical — proving the absolute zero is invisible to the data.


Step 4 — Turn the gap into a probability with the sigmoid

WHAT. We need to convert the gap (any real number, to ) into a probability (between and ) that the human prefers . The tool that does exactly this squashing is the sigmoid:

Reading each piece:

  • — the reward gap from Step 3, the input,
  • — a positive number; big when is very negative, tiny when is very positive,
  • — forced into , so it reads as a probability.

WHY the sigmoid and not, say, clipping or a straight line? Three demands must all hold:

  1. output must live in (it's a probability),
  2. bigger gap → higher probability (monotone),
  3. depend on only (Step 3's rule).

The Bradley-Terry Model gives this shape for free. It posits . Divide top and bottom by : The exponentials cancel into a pure function of the difference — nature handing us Step 3's requirement automatically.

PICTURE. The S-curve. Mark three points: maps to (a coin flip — model is undecided), large positive hugs (sure the winner wins), large negative hugs . The horizontal axis is ; the vertical axis is .


Step 5 — Maximum likelihood: reward being right, punish being wrong

WHAT. We have one knob-setting that produces a probability of the human choice we actually observed. Good knobs make close to . We turn "make big" into "make a loss small" by taking the negative logarithm:

Reading it:

  • near near → loss near (we predicted the human well: barely nudge),
  • near → loss (we predicted the wrong answer: huge push).

WHY the log, and why negative. We want to reward the model for assigning high probability to the choice the human made. Probability multiplies across independent examples; turns products into sums (stable to optimize). The minus sign flips "maximize probability" into "minimize loss," so gradient descent can chew on it. This is maximum likelihood — nothing arbitrary, just "make the observed data most probable."

PICTURE. Plot against . It is near-zero on the right (model already correct), rises gently through where , and shoots up on the left (model confidently wrong). The steepness on the left is the correction force.

Averaging this single-example loss over the whole dataset gives the parent's final result:


Step 6 — The degenerate cases (never leave the reader guessing)

WHAT. We check the three boundary situations the S-curve of Step 4 quietly covers.

Case A — a tie (). The model scores both equally. Then and . This is the baseline loss: exactly what a coin-flip guesser pays. Any real learning drives loss below .

Case B — already correct (). , . Small loss, small gradient — the model is only gently pushed to widen an already-correct gap. (This is Worked Example 1 in the parent.)

Case C — confidently wrong (). , . Loss is larger than Case B — a strong corrective shove, exactly where we want the learning to concentrate.

WHY show all three. A reader must never hit a scenario the picture didn't cover: what if scores tie? what if the model's already right? what if it's badly wrong? Each maps to a specific height on the Step-5 loss curve, and each produces a sensible, self-correcting force.

PICTURE. The Step-5 loss curve again, now with three dots — green (Case B, right), gray (Case A, tie) and red (Case C, wrong) — each labeled with its pair, so the whole behavior is one glance.


The one-picture summary

human points at winner

reward heights r_w and r_l

gap Delta = r_w minus r_l

sigmoid gives probability

minus log gives loss

average over dataset = L_RM

Recall Feynman: retell the walkthrough in plain words

All we ever get from a person is a finger pointing at the better of two answers. So we make up a "height" number for each answer using a model with knobs. We can't trust the actual height — only which is higher — so we look at the gap between them. A gap can be any size, but we want a probability that the person prefers the winner, so we bend the gap through an S-curve (the sigmoid): big positive gap → nearly certain, zero gap → coin flip, big negative gap → nearly certainly wrong. Then we say "make the answer the human actually picked as probable as possible," which — after taking the negative log so small is good and big is bad — becomes our loss. A tie costs ; being right costs almost nothing; being confidently wrong costs a lot. Turn the knobs to shrink that cost across every comparison, and the model learns to rank answers the way people do. That trained ranker is the reward model that stage 3's PPO later optimizes against — on a KL leash.

Recall Self-test

Why does the loss depend only on the reward difference? ::: Because the human only told us "winner > loser" — the absolute zero of reward is unobservable, so adding a constant to every reward leaves , the probability, and the loss unchanged. What is the loss when the model scores both answers equally? ::: , the coin-flip baseline. Which tool converts the unbounded gap into a probability, and why that one? ::: The sigmoid — it is monotone, lands in , and is exactly what Bradley–Terry produces after cancelling the exponentials, giving dependence on alone.