4.4.4 · D1Alignment, Prompting & RAG

Foundations — Direct Preference Optimization (DPO)

2,545 words12 min readBack to topic

This page assumes you have seen none of the notation in the Direct Preference Optimization (DPO) parent note. We build every piece from the ground up: what it means in plain words, the picture it stands for, and why DPO can't work without it. Read top to bottom — each symbol is earned before it is used.


0. What is a language model, as a probability machine?

Before any Greek letters, fix the mental picture.

Figure — Direct Preference Optimization (DPO)

Look at the figure: the same prompt "The capital of France is" gives a tall bar to "Paris" (high probability) and a tiny bar to "banana" (low probability). A language model is nothing more than this bar-height assignment, done over every possible continuation.

We need this picture because everything in DPO is about nudging these bar heights — up for good answers, down for bad ones.


1. The symbols for prompt and responses:

The picture: for one prompt , a human was shown two answers side by side and pointed at one. That pointing is written , read " is preferred over ."

DPO needs pairs, not single answers, because its whole trick works by comparing two responses to the same (you will see why in Section 7).


2. Conditional probability notation:

The vertical bar is the single most-used symbol in the parent note. It looks scary; it means one plain thing.

The picture: cover up the right side of the bar with your hand — you've fixed the prompt to "The capital of France is". Now the left side () ranges over all possible answers, and gives each a bar height (Section 0's figure). Change and you get a different set of bar heights.

We use the Greek letter (pi) purely by tradition — in this field stands for policy, a model that produces actions (here, text). It has nothing to do with .


3. The two models: and

DPO always juggles two copies of the model.

Figure — Direct Preference Optimization (DPO)

The picture: two identical twins at the start. One (the reference) is turned to stone — it will never move. The other (the policy) is free to shift its bar heights during training. DPO always asks "how far has the moving twin drifted from the frozen twin?"

Why keep a frozen copy at all? Because if we only pushed absolute probabilities up, the model would collapse onto a few generic high-probability sentences (word soup that's technically likely). Measuring relative to keeps the model's overall style sane. This is also the reason appears as a subscript only on the trainable one.


4. The log-ratio:

This fraction-inside-a-log is the heart of DPO. Build it in two moves.

Move A — the ratio. compares the two twins on the same response :

  • ratio : the trained model made more likely than the frozen one did.
  • ratio : no change.
  • ratio : the trained model made less likely.

So the ratio is a pure "how much did we move this answer?" dial, immune to how likely the answer already was.

Move B — the log. We take the [natural] logarithm of that ratio.

Figure — Direct Preference Optimization (DPO)

Look at the figure: the horizontal axis is the ratio, the curve is . It crosses zero exactly where the ratio is (the frozen twin), dives to as the answer is suppressed, rises slowly as it's boosted.


5. Turning the log-ratio into a reward: and

The picture: the log-ratio measures drift; is the exchange rate turning "amount of drift" into "amount of reward." Doubling doubles the reward you get for the same drift — so the model can reach a target reward with less drift. That is why large = tighter leash (a common trap the parent note steel-mans).

Why call it "implicit"? Because classic RLHF - Reinforcement Learning from Human Feedback trains a whole separate network for reward. DPO discovers that the policy itself, compared to its frozen twin, already encodes a reward — no extra network needed. See Reward Modeling for the thing DPO replaces.


6. The sigmoid : squashing a score into a probability

We now have, per response, a reward number that can be any size (positive or negative). To talk about "probability that the winner beats the loser," we must squash a number into . That's the sigmoid's job.

Figure — Direct Preference Optimization (DPO)

Look at the S-shaped curve:

  • (a coin flip — no evidence either way).
  • large positive ("almost certainly the winner").
  • large negative ("almost certainly not").

Why this function and not, say, clipping at 0 and 1? Because is smooth everywhere, so we can take its derivative and do gradient descent, and it never actually reaches or , so the loss (Section 8) never blows up to infinity. Full detail lives in Sigmoid and Logistic Loss.


7. The Bradley–Terry model: comparing two rewards

The picture: line up the two rewards. Only the gap between them matters — if the winner's reward is well above the loser's, the difference is a big positive number and says "≈ 1, yes the human preferred correctly."


8. The loss and the expectation

Reading it right to left:

  1. = "by how much does the model reward the winner over the loser?" (Section 5, 7).
  2. = turn that gap into "probability the model agrees with the human" (Section 6).
  3. = a well-behaved way to score that probability (big penalty as it ).
  4. minus sign + = we minimise the average, and minimising is the same as maximising the probability of getting every human preference right.

The picture: it's exactly a yes/no classifier — "did the model rank this pair the way the human did?" That's why the parent note calls DPO "alignment as a classification loss," sidestepping the RL machinery of PPO - Proximal Policy Optimization.


Prerequisite map

Probability of text given a prompt

Conditional bar notation pi of y given x

Two twins policy and frozen reference

Ratio then log-ratio of the twins

Scale by beta gives implicit reward

Bradley-Terry difference of rewards

Sigmoid squashes score to probability

DPO loss a classification problem

Direct Preference Optimization

Each arrow is "you must understand the left box before the right one makes sense." Notice the sigmoid () joins in only at the Bradley–Terry step — it is the translator, not a foundation stone.


Equipment checklist

Say each answer aloud before revealing.

What does the bar in mean?
"Given" — score assuming the prompt is fixed to .
Why is a product over tokens?
A response is a chain of tokens produced one at a time; multiplying their per-token probabilities gives the whole-response probability.
What is ?
The tunable weights of the model we train; changing changes the bar heights.
Which model is frozen, or ?
, the reference, is frozen; moves.
What quiet assumption lets us write ?
Both and are strictly positive, so the ratio and its log are well-defined.
Why take the log of the ratio instead of the raw ratio?
To centre "no change" at , make up/down symmetric, and turn the product of token-probabilities into a numerically safe sum.
What does the implicit reward equal?
.
Does bigger let the model drift more or less?
Less — bigger = tighter leash.
What does the sigmoid output for input ?
, a coin flip.
What is and why must DPO use pairs?
is the uncomputable normaliser depending only on ; taking a difference of rewards for the same cancels it, which requires two responses.
What kind of problem does the final DPO loss resemble?
A binary classification loss — "did the model rank the pair like the human?"

When all feel automatic, open Direct Preference Optimization (DPO) and the derivation will read like plain English.