Macalinao StudioLearnAll enriched lessons ↗
High school path · 7 sectionsSwitch to college ↗

High school / LONGER LESSON dpo

DPO: learn directly from paired preferences

Calculate a reference-relative preference margin, follow a DPO gradient, and evaluate what an offline preference objective can and cannot establish.

Preparation: probability ratios, logarithms and the RLHF lesson.

Plan 25–40 minutes with the activities; this is a study estimate, not a timed requirement. Both paths have complete narration. Your notes and progress are kept separately for each level.

Section 01 / 07

Keep the comparison, change the training route

High-school path. Calculate a reference-relative preference margin, follow a DPO gradient, and evaluate what an offline preference objective can and cannot establish. Preparation: probability ratios, logarithms and the RLHF lesson. Move between Signal Room, Workbench and Field Notes without losing your section. Pause before each worked solution.

Direct preference optimization, or D P O, learns from a prompt with a chosen answer and a rejected answer. In standard DPO training, the policy and a fixed reference score these recorded responses. A preference loss directly updates the policy. There is no separately trained reward network or online reinforcement-learning rollout loop inside this standard optimization step. Someone still has to obtain the answers and preference labels. DPO does not make that collection free, and it does not turn a preference into a fact. It provides a simpler route from the recorded comparison to a policy update.

Worked example. For one prompt, record a supported answer as chosen and a fabricated answer as rejected. Score each under the current policy and reference. Their relative changes determine the DPO margin. No new answer needs to be sampled during this one recorded-pair loss calculation.

Recorded prompt + chosen + rejected + fixed reference → preference loss

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. Does “no online sampling in the standard DPO update” mean that preference data never required generated answers?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

No. Answers may have been generated during data collection. The statement describes the optimization step using recorded pairs, not the entire data-production pipeline.

Section 02 / 07

Score the whole response under the same prompt

An autoregressive model assigns a response probability by multiplying its next-token probabilities, each conditioned on the prompt and previous response tokens. Log probabilities turn that product into a sum. For standard DPO, compare response sequence log probabilities under the policy and reference, with consistent tokenization and boundaries. Do not casually replace a sum with a per-token average: that changes the objective. Our experiment replaces open-ended language with exactly two possible complete responses. Its probabilities are normalized and easy to inspect, but they are not arbitrary raw scores for real sentences.

Worked example. A response with two conditional target probabilities one half and one quarter has probability one eighth. Its log probability is about minus 2.079. Summing log one half and log one quarter gives the same result. Averaging those logs instead gives a different number.

log π(y|x) = Σ_t log π(y_t|x,y_<t)

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. Why must the policy and reference score the same prompt and response tokens?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

Otherwise the ratio mixes a model change with a change in the event being scored. Consistent boundaries, tokenization and conditioning make the comparison interpretable.

Section 03 / 07

The reference changes what a win means

DPO asks how much the policy favors the chosen response relative to the rejected response, compared with how the reference favored them. A chosen answer can already be more probable in absolute terms yet still have a negative reference-relative margin. This is why looking only at the policy’s chosen probability misses the objective. In the two-answer experiment, set the reference chosen probability and the policy log odds independently. Watch the reference-relative margin move. The label says which answer was chosen; the reference tells us the starting balance against which the update is judged.

Worked example. Suppose the policy gives chosen probability 0.6 and the reference gives 0.8. The policy odds are 1.5; the reference odds are four. The unscaled margin is log of 1.5 divided by four, about minus 0.981. Chosen is still more likely than rejected under the policy, but its relative advantage shrank.

m = log(π_c/π_ref,c) − log(π_r/π_ref,r)

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. If policy and reference are identical, what is the unscaled margin?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

Zero. Each policy-to-reference ratio is one, each log ratio is zero, and their difference is zero. The preference label still supplies a learning signal.

Section 04 / 07

Turn the margin into a preference loss

Multiply the reference-relative margin by a positive coefficient beta, then pass it through a sigmoid. This gives the pairwise preference probability implied by this model. The loss for the chosen label is its negative logarithm. A zero margin yields probability one half and loss about 0.693. A positive margin lowers this loss; a negative margin raises it. The implied preference probability is not the probability of generating the chosen response. Our Workbench displays both so that you can see they answer different questions.

Worked example. With equal policy and reference probabilities, beta one gives z zero and loss 0.693. If policy chosen probability becomes about 0.731 while reference remains one half, the log-odds margin is one. The implied preference probability becomes about 0.731 and loss about 0.313 in this special beta-one example.

z = βm; L_DPO = −log sigmoid(z) = softplus(−z)

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. At zero margin, does the loss become zero because the models agree?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

No. Agreement with the reference gives an implied preference probability of one half. The chosen label still asks for a relative shift, so the loss is log two, approximately 0.693.

Section 05 / 07

Take a step, then ask what beta really controls

Move the policy logit with one gradient step and compare the new loss. In our isolated pair, the step increases the chosen log odds. Beta affects both the scaled margin and the gradient, so changing it while holding the learning rate fixed changes optimization as well as the interpretation of the objective. Do not memorize the rule “larger beta always moves the trained model farther” or its opposite. In the related fixed-reward RLHF objective, larger beta penalizes divergence more strongly. In finite-data DPO training, the actual trajectory also depends on margins, data and optimization.

Worked example. Start with policy logit zero, reference one half, beta one and learning rate one. The gradient is minus 0.5, so the new logit is 0.5. Chosen probability becomes about 0.622, the margin becomes 0.5 and the loss falls from 0.693 to about 0.474.

u_new = u − ηβ(sigmoid(βm)−1)

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. Does this one pair prove that larger beta will always produce a better model?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

No. It only demonstrates a specific gradient and step under fixed assumptions. Better model quality requires held-out evaluation, and beta’s effect on a complete training run cannot be inferred from one local derivative.

Section 06 / 07

Audit labels, lengths and missing alternatives

An offline preference dataset contains only the responses that were collected. It cannot directly compare an excellent answer that never appears. If chosen answers are usually longer, the model may learn a length association instead of the intended quality distinction. If labels favor confident but unsupported statements, fitting them can amplify that behavior. Inspect close calls, contradictory labels and examples where both candidates are poor. Include the rubric and the source of judgments. Data collected from one policy may cover a different range of answers than a later trained policy produces.

Worked example. Imagine every chosen answer is 300 words and every rejected answer is 30 words. Before celebrating a preference-learning gain, create length-matched comparisons and check factual support. A model that writes longer answers may satisfy the accidental pattern without improving the requested task.

Observed pair accuracy ≠ coverage of all possible responses

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. A test pair is a paraphrase of a training pair from the same source. Is a random pair split enough protection?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

No. Group related prompts and source material before splitting. Otherwise memorized content or near-duplicate comparisons may inflate the apparent generalization result.

Section 07 / 07

Compare learning signals with a fair final test

You now have three ways to describe post-training signals. Instruction tuning imitates target responses. A common RLHF pipeline predicts comparison-based reward and then optimizes a regularized policy objective. Standard DPO directly fits a reference-relative preference loss on recorded pairs. These methods can appear in the same development pipeline, and none replaces independent evaluation. Modern language-model progress includes making useful behavior easier to teach and training systems easier to operate. The practical question remains whether the changed model handles new requests more accurately, helpfully and consistently under a clear rubric.

Worked example. Keep one held-out prompt set and blind the response identities. Compare the starting model, an SFT model and a preference-trained model. Report two-bullet compliance separately from supported facts. If one improves formatting but loses factual support, preserve both findings rather than collapsing them into a promotional score.

Demonstrations, rewards and pairwise objectives require independent evaluation

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. What evidence would justify saying this post-training change helped a summarization product?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

Held-out summaries should improve under a predeclared rubric, with supported claims, adequate coverage and acceptable format. Compare at matched conditions, quantify uncertainty and inspect regressions. Training loss alone is insufficient.

Final checkpoint. What does standard offline DPO use directly? Option 1: Recorded chosen/rejected pairs and a reference. Option 2: A mandatory new reward network. Option 3: Only unlabeled prompts.

Pause and choose an answer before continuing.

Reveal worked solution

Option 1 is correct. The standard pairwise objective updates the policy without a separate reward-model training loop.

LONGER REASONING LESSONS

Reason, verify and learn from attempts

Worked examples, local narration and connected experiments at your level.

Continue the learning path

Sources and scope

Original worked examples and teaching text, grounded in these primary references. Numerical fixtures explain mechanisms; model quality and hardware performance require separate measurements. Both levels share key examples, with different explanations and checkpoints.

Reset this high school path?

This removes only this path’s notes, progress and experiments from this browser.