Macalinao StudioLearnAll enriched lessons ↗
College path · 7 sectionsSwitch to high school ↗

College / 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

College 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.

The original derivation connects a KL-regularized reward objective to a policy parameterization of reward under a Bradley–Terry preference model. This is a mathematical relationship under stated assumptions, not a guarantee that finite-data neural training reproduces a perfect RLHF optimum. Standard offline DPO is the subject here; variants may change the loss, weighting, reference or data refresh. Keep those differences visible when comparing implementations.

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.

Prompt tokens provide conditioning but are not part of the conditional response log-probability sum. Include the intended response boundary or end token consistently. In a real vocabulary, the chosen and rejected sequences are only two among many possibilities and their probabilities usually do not sum to one. Our binary restriction makes them exhaustive by definition, so log odds simplify the margin. That simplification must not be silently applied to real sequence scoring.

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.

The unscaled margin is log policy-chosen over reference-chosen minus log policy-rejected over reference-rejected. In the binary fixture this equals policy log odds minus reference log odds. At the reference, the margin is zero regardless of how unequal the two reference probabilities are. The fixed reference must assign positive probability to both observed responses for finite ratios; our control range guarantees that support.

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.

Writing z as beta times the margin, the stable loss is softplus of minus z. In the binary fixture the policy logit u is its log odds, so the derivative with respect to u is beta times sigmoid of z minus one. The reference is fixed during differentiation. For real models the chain rule acts through the chosen and rejected sequence log probabilities and their shared network parameters.

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.

At zero margin the derivative is minus beta divided by two, so a fixed learning rate gives a larger initial logit step for larger beta in this fixture. At positive margins the sigmoid saturates, altering the gradient. A single separable pair has an infimum of zero loss as the chosen log odds grow without bound; the fixture has no finite minimizer for that isolated pair. Real shared parameters, conflicting examples, regularization and stopping rules change the situation.

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.

Standard sequence-sum scoring interacts with length and token-level likelihoods; changing to length-normalized scores defines a modified objective and needs separate justification. Label noise and preference heterogeneity challenge the assumed scalar ranking. Train/test splits should group prompts and related source material, not merely split individual pairs. A low loss on observed pairs does not establish ranking quality for unseen candidates or robustness to distribution shift.

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.

Compare candidates from compatible starting checkpoints with documented data budgets, optimization choices and decoding settings. Measure task success, factual support, refusal appropriateness and regression alongside preference win rate; report sampling uncertainty. A simpler optimizer may reduce engineering complexity without guaranteeing better capability or lower total data cost. The exact Workbench arithmetic validates the displayed objective, not a trained model or a universal ranking between algorithms.

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. At policy equal to reference, what is standard chosen-pair DPO loss? Option 1: Zero. Option 2: Log two. Option 3: Beta.

Pause and choose an answer before continuing.

Reveal worked solution

Option 2 is correct. The reference-relative margin is zero, giving implied preference probability one half.

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 college path?

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