Language models, retrieval, prompting, and language adaptation · Instruction, preference, and parameter-efficient adaptation · LNG066 · Training method
Odds Ratio Preference Optimization (ORPO)
Combines supervised likelihood training with an odds-ratio preference penalty in one reference-free adaptation objective.
In CodeSplash
Documented in the Academy only. There's no Set up button.
- Availability
- Explained here
- Code example
- Component demo, not a trained model
- Who ran it
- CodeSplash's own run
- CodeSplash's run
- The reference's example ran in Python and R here, and they agree.
- The reference's record
- Python: The chapter's authors report running it; there is no record for this entry alone. R: Reviewed but not run: R wasn't available to the reference's authors.
Purpose
Combines supervised likelihood training with an odds-ratio preference penalty in one reference-free adaptation objective. It differs from DPO by not requiring a separate frozen reference policy in its defining formulation.
Question / objective
Can supervised likelihood and odds-ratio preferences be optimized in one reference-free stage?
Architecture / computational structure
One trainable policy provides chosen/rejected sequence probabilities; a supervised term and odds-ratio term share weights. There is no mandatory separate reference model in the defining objective; loss weight and normalization are hyperparameters.
Assumptions
Treating a raw product of many token probabilities as a numerically ordinary probability can underflow and alter behavior; use log-space implementations.
Formula / computational definition
L=L_SFT+lambda L_OR, where L_OR=-log sigma(log odds(y_w|x)-log odds(y_l|x)) and odds(p)=p/(1-p). The paper uses sequence-probability definitions that must be followed consistently, including length normalization.
Parameters and notation
Learned parameters: identified in the architecture subsection. Hyperparameters, design and inference choices: Preference weight lambda, chosen-response likelihood term, sequence normalization, learning rate, pair quality, and parameter-efficient versus full updates.
Fitting, fine-tuning, and adaptation
Train full weights or supported adapters on preference pairs with exact sequence normalization and response masks. Validate supervised loss and preference quality jointly, tune lambda on held-out data, and inspect response length and general-task retention. Reference-free training still requires careful overfitting control.
How to use and calibrate
Track chosen-response loss, preference accuracy, general task retention, response length, and independent human preference or factuality measures. Use development data for settings and an independent test set for the final estimate. Report uncertainty across examples or seeds when the evaluation design supports it; model scores and self-assessments are not automatically calibrated probabilities of correctness.
Example application
Adapt an assistant from paired preferred/rejected replies under a single-stage objective.
Interpretation / pitfalls
Watch out
Reference-free does not mean unconstrained or guaranteed to retain base capabilities. The code below isolates one stated component; successful execution does not validate model quality or reproduce the cited experiment.
Python and R code examples
Full implementation route: Use the authors' implementation or a documented ORPO trainer compatible with the selected version. R bridges Python via reticulate. The native example illustrates the odds-ratio term on two explicit toy probabilities, not a complete token-level implementation.
Example scope: ORPO odds-ratio component on explicit normalized toy sequence probabilities.
Dependencies: Python 3 standard library; base R; shared setup above. No model downloads or external services.
Validation: Python component executed in the combined example script; R counterpart supplied but not runtime-tested here. All numbers are synthetic.
Python and R
The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.
Component demo, not a trained model — ORPO odds-ratio component on explicit normalized toy sequence probabilities.
Shared setup for this chapter
import math
def softmax(xs):
m = max(xs)
es = [math.exp(x-m) for x in xs]
return [e/sum(es) for e in es]
def dot(a, b):
return sum(x*y for x, y in zip(a, b))
def matvec(matrix, vector):
return [dot(row, vector) for row in matrix]
def meanvec(rows):
return [sum(row[j] for row in rows)/len(rows) for j in range(len(rows[0]))]
def sigmoid(x):
return 1/(1+math.exp(-x))
def nll(probabilities):
return -sum(math.log(p) for p in probabilities)
p_chosen,p_rejected,weight = 0.6,0.3,0.1
log_odds_margin = math.log(p_chosen/(1-p_chosen))-math.log(p_rejected/(1-p_rejected))
preference_loss = -math.log(sigmoid(log_odds_margin))
print(-math.log(p_chosen)+weight*preference_loss)
Component demo, not a trained model — ORPO odds-ratio component on explicit normalized toy sequence probabilities.
Shared setup for this chapter
softmax <- function(x) {
shifted <- exp(x-max(x))
shifted/sum(shifted)
}
p_chosen <- 0.6; p_rejected <- 0.3; weight <- 0.1
log_odds_margin <- qlogis(p_chosen)-qlogis(p_rejected)
preference_loss <- -log(plogis(log_odds_margin))
print(-log(p_chosen)+weight*preference_loss)
Sources
- Source 1arxiv.org
From the CodeSplash reference, entry LNG066.