4.4.1 · D1Alignment, Prompting & RAG

Foundations — Reinforcement Learning from Human Feedback (RLHF)

1,939 words9 min readBack to topic

This page assumes you have seen nothing. Before RLHF makes sense, we must earn every symbol the parent note throws at you — , , , , , , and the strange word policy. We build them one at a time, each with a picture, in an order where every new symbol only uses ones already defined.


0. What is a "language model" really? — the symbol

We give this whole guessing machine a name: (the Greek letter "pi", here it has nothing to do with — it is just the traditional letter for a policy, defined below).

  • reads: "the probability the model assigns to producing the full answer , given the prompt ." The vertical bar means "given" / "assuming we already saw."
  • = the input text (prompt). = a candidate answer (a whole sentence).
Figure — Reinforcement Learning from Human Feedback (RLHF)

Related: this trained-to-chat model is what Supervised Fine-Tuning (SFT) produces, written .


1. Probability, and why and are special

A probability is a number in the range :

  • means "never,"
  • means "certain,"
  • means "coin-flip."

The model spreads a total of across all possible next words — it is dividing up a full pie. If it hands "the" a slice of , that word gets of its confidence. We will constantly compare two models' slices for the same word, so hold that picture: two pies, same slice, different sizes.


2. The logarithm — turning "how many times bigger" into a plain number

The parent note writes and . Why does a log appear at all?

Two facts we need, both visible in the figure:

  1. turns a ratio into a difference. . This is why comparisons (which are naturally ratios/differences) become clean sums.
  2. punishes small probabilities hard. As a probability slides toward , its dives toward . So is a "surprise meter": tiny probability = huge penalty.
Figure — Reinforcement Learning from Human Feedback (RLHF)

3. The reward — a judge that scores answers

Picture a judge at a talent show holding up a scorecard. But — crucial — this judge was never taught absolute scores. It was only ever shown pairs and told which one won. So only differences between its scores mean anything (see Section 5). This is the Bradley-Terry Model at work.


4. The sigmoid — squashing any number into a probability

The parent note computes . What is this ("sigma")?

Why do we need this exact shape? Because the reward difference can be any real number, but "probability the human prefers the winner" must live in . The sigmoid is the S-curve that bridges those two worlds:

  • (a tie — no preference),
  • big positive (winner clearly preferred),
  • big negative (we got the ranking backwards).
Figure — Reinforcement Learning from Human Feedback (RLHF)

5. Why only differences of reward matter

The Bradley-Terry Model says the probability a human prefers winner over loser is . Because only the difference appears, adding the same constant to every reward changes nothing: So the reward's "zero point" is arbitrary. That is why "the RM outputs an absolute quality" is a listed mistake — it doesn't. It outputs a ruler with no marked origin, only spacing. This limitation is the seed of Goodhart's law.


6. Expectation and KL divergence — the leash

Expectation means "the average value, weighted by how likely each case is." When the parent writes , the means " is sampled from" — i.e. "average this over answers the policy actually produces." It is just a careful word for average.

Now the leash. is the policy we are training ( = "phi" labels its knobs, distinct from the judge's ). We want it to stay near the trusted .

Picture two pies again (Section 1). If the new policy's slices match the trusted model's slices, KL — no leash tension. If the new policy shouts "!" where the trusted model whispered "," the log-ratio shows up as tension pulling it back. Deep dive: KL Divergence.


7. Putting the symbols in order

probability 0 to 1

language model pi of y given x

log turns ratio into difference

policy pi phi that acts

trusted model pi SFT

sigmoid squashes score to probability

reward r theta scores answers

Bradley Terry only differences matter

reward model loss

KL divergence measures drift

full RLHF objective

RLHF: aligned model

Each box uses only boxes that feed into it — that is the whole promise of "every symbol earned before use."


8. One numerical walkthrough, symbol by symbol

Reusing the parent's Worked Example 1 with our fresh definitions, so you feel each symbol fire.

  • , — the judge's two scores (Section 3).
  • — only the difference counts (Section 5).
  • — squash difference into "probability we ranked correctly" (Section 4).
  • loss — the surprise meter; low because we were right (Section 2).

If the judge had it backwards (): , , loss — a big penalty demanding a big correction. Every symbol on this page just did a job.


Equipment checklist

Cover the right side and answer out loud before revealing.

What does mean in plain words?
The probability the model/policy assigns to producing answer when given prompt ; the bar means "given."
Why is called a policy here and not just a model?
Because it must choose actions (pick words to build an answer), and anything that chooses actions is a policy — we will train it like an agent.
What single number does output, and what does mean?
One scalar "goodness" score for the answer; labels all the tunable knobs inside the reward model.
Why can only differences of reward be trusted, never absolute values?
Bradley–Terry uses ; adding a constant to every reward leaves that difference unchanged, so the zero point is arbitrary.
What does the sigmoid do, and why do we need it?
It squashes any real number into , converting a reward difference into a probability of preference.
What is and what does it represent?
— a tie, no preference between the two answers.
Why does appear when we compare two probabilities?
Because : it turns "how many times bigger" into a clean additive difference.
What does do as ?
It blows up toward — a "surprise meter" that punishes confident wrong predictions hard.
What does mean, and what does signify?
Expectation = probability-weighted average; means " is sampled from" the policy .
What does tell you?
The two distributions are identical — the trained policy hasn't drifted from the trusted SFT model at all.
What role does play in the leash?
It sets leash tightness: large keeps the policy close to SFT (safe), small lets it chase reward (risky).