research24 min studyLesson 636 in Engineering

Derive the reference-relative classification margin

Connect the finite KL optimum to a Bradley–Terry likelihood, keeping prompt normalization, beta convention, and sequence log-probability semantics explicit.

On this page

What you’ll understand

  • Derive reward differences from policy-to-reference log ratios.
  • Write the original sigmoid DPO loss and identify its assumptions.
  • Distinguish sequence-sum log probabilities from changed length-normalized objectives.

Direct Preference Optimization rewrites a preference likelihood in terms of policy and reference probabilities. The derivation cancels a prompt-specific normalizer when comparing two responses to the same prompt. It does not cancel arbitrary formatting errors, identify true utility, or guarantee a neural optimizer finds a globally desirable policy. Start with the explicit finite-support assumptions, derive the reference-relative margin, and then verify that the implementation computes the same sequence probabilities and coefficient convention as the equation being claimed.

Invert the finite optimum within one prompt

Use the previous finite response domain with positive normalized reference q, finite rewards, and β>0. The KL-regularized optimum satisfies p*(y)=q(y)exp(r(y)/β)/Z. Taking logs and rearranging expresses reward as β log(p*/q)+β log Z. The normalizer depends on the prompt but not which response is compared within that prompt. Therefore it disappears from a within-prompt reward difference. Comparing unrelated prompts does not generally cancel their different constants, so raw implicit-reward levels should not be interpreted as a universal cross-prompt utility scale.

The change of variables can also associate a positive normalized candidate policy with an implicit reward β log(pθ/q), choosing a particular representative of the additive-equivalence class. That is a mathematical parameterization, not evidence that the policy recovered the reward process behind real annotations. A restricted neural family, finite data, inconsistent preferences, and optimization error all limit that inference. Preserve the reference identity and supported domain. If a comparison response has zero reference probability, its log ratio is not a finite quantity covered by this derivation; arbitrary clipping creates an additional approximation or changed objective.

r(x,y)=βlog⁡p∗(y∣x)q(y∣x)+βlog⁡Z(x)r(x,y)=\beta\log\frac{p^*(y\mid x)}{q(y\mid x)}+\beta\log Z(x)
This inversion assumes the finite positive-reference optimum, finite rewards, and β>0 under the penalty-multiplier convention. Z(x)>0 is finite and shared only by responses to the same prompt. All log ratios are dimensionless and use natural logs.↔ Scroll wide equations horizontally.

Substitute the reward difference into the comparison likelihood

Assume the unit-temperature Bradley–Terry link for preference labels. Substitute the reward difference to obtain a logistic probability whose margin is β times the chosen response's policy/reference log ratio minus the rejected response's corresponding ratio. The negative log probability of the observed winner is the original sigmoid DPO loss. The reference terms matter: the objective compares relative changes from the reference, not simply whether the policy assigns the winner more absolute probability than the loser. A reference-free variant or alternative preference loss defines a different stated problem.

Keep β's convention explicit. Here it is the positive KL penalty multiplier in the underlying reward objective and also multiplies the log-ratio difference in the DPO margin. If the annotation link has a separate positive temperature τ, the substituted margin scales by β/τ instead. Software or papers using reciprocal-temperature notation need conversion. At a fixed observed log-ratio gap, changing β changes the local classification margin, but the fitted implicit reward also changes during training; that local calculation alone is not a monotonic guarantee about the final model's measured KL or behavior.

ℓDPO=−log⁡σ ⁣(β[log⁡pθ(yw∣x)q(yw∣x)−log⁡pθ(yl∣x)q(yl∣x)])\ell_{\mathrm{DPO}}=-\log\sigma\!\left(\beta\left[\log\frac{p_\theta(y_w\mid x)}{q(y_w\mid x)}-\log\frac{p_\theta(y_l\mid x)}{q(y_l\mid x)}\right]\right)
For one winner/loser pair under a unit-temperature Bradley–Terry model, all four probabilities are positive and β>0. Natural logs give loss in nats. The finite derivation is conditional on the stated reference and model assumptions; fitting this empirical loss does not certify universal preference satisfaction.↔ Scroll wide equations horizontally.

Compute the declared sequence probability

For an autoregressive response, the conditional log probability is the sum of its token log probabilities given the prompt and earlier response tokens, under a consistent termination convention. The prompt supplies context but its own likelihood is not added to a completion-only score. Mask padding, align shifted targets, and handle EOS consistently on policy and reference paths. Dividing each sequence sum by its own token count is generally not the same conditional sequence probability and can change pair ordering. If length normalization is desired, name and validate that changed objective rather than claim the original derivation is untouched.

Pinned TRL 0.23.1 distinguishes several loss variants and computes completion log-probability sums for its ordinary sigmoid path; other options can alter this behavior. Inspect the exact configuration and implementation instead of applying every current feature to the original paper. The network lab demonstrates the logistic margin only: for each separate view, Reset, set both w=1 and x to 1 or 1.5, predict z=wx−0.5, then inspect. Outputs are approximately 0.6225 and 0.7311 for margins 0.5 and 1. It has no reference model, tokenization, preference dataset, or optimizer and cannot demonstrate DPO training success.

Compute a reference-relative DPO example

For one fictional prompt, chosen and rejected sequence log probabilities under the policy are−4 and−6; under the reference both are−5. Let β=0.5 and use the unit-temperature link. These responses are part of a larger finite domain with the remaining positive probability mass assigned to other responses.

  1. The chosen policy/reference log ratio is−4−(−5)=1. The rejected ratio is−6−(−5)=−1, so their difference is 2.

  2. The DPO margin is 0.5×2=1, giving modeled winner probability sigmoid(1)≈0.73106.

  3. The observed-winner loss is−log sigmoid(1)=log(1+e⁻¹)≈0.31326 nats. The shared prompt normalizer cancels in the difference; this computation assumes matching sequence and mask semantics.

The result

The reference-relative margin is 1 and the example loss is about 0.31326 nats. These numbers evaluate one modeled preference observation, not a behavioral guarantee.

Explore the model

Interactive lab

Interactive lab · network

Inspect the logistic part of a preference loss

For each view: Reset, set both w=1 and x, predict z=wx−0.5, then inspect. Compare x=1 with x=1.5: margins 0.5 and 1 give outputs about 0.6225 and 0.7311. This fixed-bias unit does not compute model log probabilities, fit DPO, or estimate a KL budget.

Inspect the logistic part of a preference lossOne inspectable sigmoid unit, σ(wx − 0.5). Playback traces the computation graph. There is no training, attention mechanism or hidden deep network. Current readings: Product · wx: 1.2; Logit · wx − 0.5: 0.7; Sigmoid output: 0.6682. All parameters are adjustable with the labeled controls below.One input. One weight. One sigmoid.x1.20× w1.20+ b0.70σ0.668output0.668w = 1.00b = −0.50σ(z) = 1 / (1 + exp(−z))
Computation graphSignal trace
Product · wx
1.2
Logit · wx − 0.5
0.7
Sigmoid output
0.6682
t = 0 s

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 forThe sigmoid is only one part of the objective. Reference identity, sequence sums, masks, support, and coefficient convention determine the actual margin.

Check your understanding

Why does β log Z(x) disappear from the DPO pair margin?

Try it yourself

A pair has policy/reference log ratios 0.6 for the chosen response and−0.4 for the rejected response. With β=0.5 and the unit-temperature link, compute the margin and loss.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Subtract the ratios, multiply by β, then use log(1+exp(−margin)).

Compare with the solution

The gap is 1, the margin 0.5, and loss log(1+e⁻⁰·⁵)≈0.47408 nats. The modeled winner probability is about 0.62246. These values assume positive matching sequence probabilities and the stated β convention.

Take it with you

  • DPO’s normalizer cancellation is within a shared prompt and stated support.
  • The original loss uses reference-relative sequence log probabilities and an explicit β convention.
  • Length normalization, masks, and implementation variants can change the claimed objective.

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.