Preference optimization and alignment
Derive a pairwise preference objective relative to a reference policy and evaluate what preference labels can establish.
On this page
The question for today
What you’ll understand
- Distinguish supervised demonstrations, reward modeling, and direct preference optimization.
- Calculate a DPO pair loss from policy-to-reference probability ratios.
- Identify preference-data bias and evaluate behavior beyond training-pair agreement.
A pretrained next-token objective does not fully specify how an assistant should respond to a user's instruction. Preference training adds judgments about desirable responses, such as usefulness, clarity, or adherence to a policy. Those judgments are data with a collection process and a population, not an objective definition of all good behavior. The engineering task is to state what was preferred, optimize a controlled objective, and test whether the resulting policy behaves well on held-out interactions and important failure cases.
Different supervision stages answer different questions
Supervised fine-tuning learns from example responses to prompts. A preference dataset instead presents alternatives and records which response a labeler favors under a rubric. One RLHF approach fits a reward model to those comparisons, then optimizes a policy while penalizing departure from a reference. InstructGPT provides an influential example of demonstrations followed by human preference feedback. Its empirical improvements are evidence for a particular training and evaluation setup, not proof that every preference-trained policy is truthful or universally aligned.
Write the annotation instructions and record ambiguous or disputed comparisons. Preferences can reflect conflicting judgments about style, length, facts, or values. If longer answers are often preferred, a model may learn verbosity instead of stronger reasoning. Collect representative prompts, separate related prompts across splits, and inspect annotator disagreement. Label model-selected or rule-selected pairs with their provenance rather than calling them independent human judgments.
DPO compares relative sequence likelihoods
Direct Preference Optimization derives a pairwise classification objective from a regularized preference formulation. For each prompt, compare the policy's likelihood ratio to a fixed reference for the preferred response and for the rejected response. The loss encourages a higher relative score for the preferred response. This can avoid fitting and then sampling against a separate reward model during the DPO update, but it still requires appropriate preference data, optimization, and evaluation. It is not merely supervised training on the preferred text alone.
Use sums of token log probabilities for sequence scores, with consistent tokenization, prompt masking, and end-token treatment. Padding must not contribute to the score. Standard DPO uses sequence log likelihoods; replacing them with length-normalized scores changes the objective and should be named explicitly. Beta appears both in the derivation's regularization tradeoff and in the scaled pair logit. Its practical effect depends on optimization and data, so do not infer a universal update size from its numerical value alone.
Evaluate the policy, including its tradeoffs
Held-out pair accuracy measures whether the model orders similar response pairs as desired. It does not fully test interactive task success, truthfulness, robustness, or the appropriateness of refusal. Evaluate factual and procedural correctness with independent criteria, and compare responses with length and formatting controlled where relevant. Include distribution shifts, conflicting instructions, and cases requiring uncertainty. A policy can improve preference scores by sounding confident while becoming less honest about missing evidence.
Track capability regressions as well as preferred behavior. Evaluate the base or supervised reference under the same prompts and decoding settings, report important slices, and document data filtering. Preserve the training recipe, reference checkpoint, preference dataset identity, and scoring convention. Human feedback and automated judges can both carry systematic bias. Treat alignment as measured behavioral requirements with stated limits, rather than a binary property bestowed by one loss.
Work it through
Calculate one preference-pair loss
For one prompt, the reference assigns probability 0.2 to the preferred response and 0.4 to the rejected response. The current policy assigns 0.4 and 0.2 respectively. Use β=0.5 and natural logarithms; other responses hold the remaining probability mass.
The preferred policy-to-reference ratio is 0.4/0.2 = 2. The rejected ratio is 0.2/0.4 = 0.5. Their log-ratio difference is ln(2) − ln(0.5) = ln(4).
Multiply by β=0.5 to get ln(2). Applying sigmoid gives 2/(1+2) = 2/3 as the pairwise model probability under this loss.
The loss is −ln(2/3), approximately 0.4055. If policy and reference were identical, both ratios would be one and the loss would be ln(2), approximately 0.6931.
This policy already favors the preferred response relative to its reference, yielding a lower pair loss. One pair says nothing about overall factual accuracy or the preference dataset's representativeness.
The living notebook
Explore the model
Interactive lab · network
Inspect a logistic comparison
The lab computes σ(wx−0.5) from one input and one weight. Its sigmoid shape is the same mathematical link used in a pairwise loss, but the fixed bias and controls do not calculate DPO sequence ratios, train a policy, or represent a full language model.
- Product · wx
- 1.2
- Logit · wx − 0.5
- 0.7
- Sigmoid output
- 0.6682
One inspectable sigmoid unit, σ(wx − 0.5). Playback traces the computation graph. There is no training, attention mechanism or hidden deep network. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forA smooth pairwise probability can encode a preference comparison without making that comparison objectively correct.
Pause & reason
Check your understanding
Your turn
Try it yourself
Policy and reference give identical probabilities to both responses in a pair. What are the DPO pair logit, implied pair probability, and loss for any positive β?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Each policy-to-reference ratio is one, so begin with its logarithm.
Compare with the solution
Both log ratios are zero, so the scaled difference is zero for any positive β. Sigmoid(0)=0.5 and the loss is −ln(0.5)=ln(2), approximately 0.6931. The current policy has not yet shifted the pair's relative preference away from the reference under this objective.
Keep the idea
Take it with you
- Preference labels encode a rubric and population, not an infallible reward oracle.
- DPO compares reference-relative sequence likelihoods for preferred and rejected responses.
- Measure correctness, robustness, and regressions independently of preference-pair fit.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.