Skip to content

From text predictor to assistant: instruction and preference tuning

A pretrained model continues text; an assistant follows instructions and prefers helpful, harmless answers. Survey the steps that get there, FLAN and T0, RLHF, Constitutional AI, DPO and ORPO, and what each optimizes.

Advanced ~16 min9 steps

What runs in CodeSplash

You will be able to

  • Explain what instruction tuning on many tasks changes, and why template wording matters
  • Lay out the RLHF pipeline: supervised tuning, a reward model, then a KL-penalized policy update
  • Compare DPO and ORPO with RLHF in what they need and what they optimize
  • Say what preference tuning does and doesn't guarantee about a model's answers

Read first

01

Tasks as instructions

Read

A pretrained model asked "Translate to French: good morning" may continue with more English. Instruction tuningInstruction tuningFine-tune a language model on many tasks written as instructions with answers, so it follows new instructions. fine-tunes it on many tasks, each written as an instruction and an answer. FLAN used dozens of task clusters and showed that the tuned model follows instructions for task types it never saw.

The training mix is a choice: the reference program weights three task losses into one objective of 1.06. Large, common tasks can crowd out rare ones, so mixtures are capped or balanced.

02

Wording matters: T0

Read

T0 trained on many tasks, each with several hand-written prompt templates, and found that more prompt variety helped models handle new phrasings. It also measured how much results swing between templates for the same task.

In the reference program, three templates give the right answer probabilities that lead to a mean loss of 0.550, but the losses span 0.693 from best to worst template. The same sensitivity applies to CodeSplash's Label with AI: try a few wordings of your instructions and labels, and check each against known labels.

03

RLHF: learn what people prefer

Read

RLHFReinforcement learning from human feedback (RLHF)Tuning a model with a reward model fit to people's pairwise preferences, then optimizing against it with RL such as PPO., as in InstructGPT, has three steps. Tune the model on demonstrations. Collect pairs of answers that people ranked, and fit a reward modelReward modelA model trained on human preference pairs to score responses; RLHF then trains the policy to raise that score. with a Bradley–TerryBradley–Terry modelA model of pairwise judgments: the difference in two items' log-worths sets the log odds that one is preferred to the other. loss: the preferred answer should score higher. Then update the model to raise reward, minus a KL penaltyKL penalty to a reference modelA cost for drifting from the starting model's token probabilities, so preference tuning can't trade everything for reward. that keeps it close to the tuned starting point.

In the reference program the reward model's pairwise loss is 0.371; the policy's KL divergence from the reference is 0.0823, and reward minus the penalty gives 0.752. Without the penalty, the policy drifts toward whatever fools the reward model.

DExplorable · Preference optimization: reward models and DPO

How do pairwise preferences turn into a policy, and what does β protect against?

0.50

Small β lets the policy move far from the reference; large β keeps it close.

100

Comparisons simulated from hidden true rewards with a Bradley–Terry model.

500

Full-batch gradient steps on the DPO loss.

0.50

Step size on the implicit reward β(θ − θ_ref), so β doesn't change the speed.

Correct and helpful0.81Correct but curt0.12Polite but vague0.05Confident and wrong0.01Off topic0.00Refuses0.00
  • Reference policy
  • DPO policy
  • True optimum π_ref·exp(r*/β)
  • Reward model + optimum (dots)
KL from the reference (nats)
1.240
Expected true reward
1.802
Largest response probability
0.814
Final DPO loss
0.4230
  • Puzzle: Get within 0.1 of the true optimum's expected reward while staying under 1 nat from the reference.
  • Puzzle: Make the policy put more than 90% on a single response.
After 500 steps on 100 pairs with β = 0.50, the policy gives “Correct and helpful” 81% and sits 1.24 nats from the reference. Its expected true reward is 1.80, against 0.34 for the reference and 1.71 for the true KL-regularized optimum. In this toy, DPO's policy is exactly what a fitted Bradley–Terry reward model plus the KL-regularized optimum would give.

After 500 steps on 100 pairs with β = 0.50, the policy gives “Correct and helpful” 81% and sits 1.24 nats from the reference. Its expected true reward is 1.80, against 0.34 for the reference and 1.71 for the true KL-regularized optimum. In this toy, DPO's policy is exactly what a fitted Bradley–Terry reward model plus the KL-regularized optimum would give.

04

Feedback from principles: Constitutional AI

Read

Constitutional AIConstitutional AIPreference tuning where a model critiques and ranks responses against written principles instead of human raters. replaces most human harm labels with AI feedback guided by a short written list of principles. The model critiques and revises its own answers against the principles, and an AI rater compares answers to produce preference pairs for training.

The reference program weights three principles to rate two responses: 0.83 and 0.75. The principles become an explicit, inspectable part of training, and the rater's own biases become part of the data.

05

Without a reward model: DPO and ORPO

Read

DPODirect preference optimization (DPO)Preference tuning without a separate reward model: a loss on preferred versus rejected answers, held near a frozen reference. skips the reward model and the reinforcement learning loop. It raises the log-probability of the preferred answer relative to a frozen reference model, and lowers the rejected one's, in one classification-style loss:

L=−log⁡σ ⁣(β[(log⁡πw−log⁡πwref)−(log⁡πl−log⁡πlref)])\mathcal{L} = -\log\sigma\!\Big(\beta\big[(\log\pi_w - \log\pi^{\mathrm{ref}}_w) - (\log\pi_l - \log\pi^{\mathrm{ref}}_l)\big]\Big)

With β = 0.2 the reference program's loss is 0.616. ORPOORPOOne-stage preference tuning: the usual likelihood loss on the chosen answer plus a log-odds-ratio penalty against the rejected one. drops the reference model too: it adds an odds-ratio preference term to the ordinary supervised loss, giving 0.536 in the reference program.

DExplorable · Preference optimization: reward models and DPO

How do pairwise preferences turn into a policy, and what does β protect against?

0.50

Small β lets the policy move far from the reference; large β keeps it close.

100

Comparisons simulated from hidden true rewards with a Bradley–Terry model.

500

Full-batch gradient steps on the DPO loss.

0.50

Step size on the implicit reward β(θ − θ_ref), so β doesn't change the speed.

Correct and helpful0.81Correct but curt0.12Polite but vague0.05Confident and wrong0.01Off topic0.00Refuses0.00
  • Reference policy
  • DPO policy
  • True optimum π_ref·exp(r*/β)
  • Reward model + optimum (dots)
KL from the reference (nats)
1.240
Expected true reward
1.802
Largest response probability
0.814
Final DPO loss
0.4230
  • Puzzle: Get within 0.1 of the true optimum's expected reward while staying under 1 nat from the reference.
  • Puzzle: Make the policy put more than 90% on a single response.
After 500 steps on 100 pairs with β = 0.50, the policy gives “Correct and helpful” 81% and sits 1.24 nats from the reference. Its expected true reward is 1.80, against 0.34 for the reference and 1.71 for the true KL-regularized optimum. In this toy, DPO's policy is exactly what a fitted Bradley–Terry reward model plus the KL-regularized optimum would give.

After 500 steps on 100 pairs with β = 0.50, the policy gives “Correct and helpful” 81% and sits 1.24 nats from the reference. Its expected true reward is 1.80, against 0.34 for the reference and 1.71 for the true KL-regularized optimum. In this toy, DPO's policy is exactly what a fitted Bradley–Terry reward model plus the KL-regularized optimum would give.

06

What preference tuning promises

Predict

Predict first

After preference tuning, raters prefer a model's answers. What has improved?

Its answers are now more often trueIts answers now look more like what raters preferred, which is often but not always more trueNothing changes
Reveal

Its answers look more like what raters preferred. Raters reward clarity, confidence and length as well as correctness, so a tuned model can sound more convincing without being more accurate. Measure correctness separately.

07

Where it stands in CodeSplash

Read
EntryIn CodeSplash
FLAN, T0 (LNG061, LNG062)Explained here
RLHF, Constitutional AI (LNG063, LNG064)Explained here; the pairwise idea runs as Paired comparisons
DPO (LNG065)Runs as a notebook (its reference program)
ORPO (LNG066)Explained here

The Training, adaptation and compression track goes deeper into each of these methods.

08

Check: instruction and preference tuning

Checkpoint

Check yourself

What was FLAN's main finding?

Show the answer

Answer: a

Breadth of instruction-formatted tasks, not any single task, produced the zero-shot gains.

Check yourself

Why do instruction-tuning mixtures cap the share of very large tasks?

Show the answer

Answer: b

The mixture weights decide which skills the tuned model learns most; uncapped, data size alone would decide.

Check yourself

T0 trained each task with several prompt templates. What did that buy?

Show the answer

Answer: b

Seeing many phrasings during training made the model less dependent on one exact wording.

Check yourself

You label texts with an AI model and two wordings of the instruction give accuracy 81% and 68% on known labels. What should you report?

Show the answer

Answer: b

Prompt sensitivity is real and measurable. Report it, and choose the wording on data separate from the final check.

Check yourself

Put the classic RLHF pipeline in order.

  1. 1Collect ranked pairs of answers and fit a reward model
  2. 2Tune the pretrained model on demonstrations
  3. 3Update the model to raise reward, with a KL penalty to the tuned model

Show the answer

The order:

  1. Tune the pretrained model on demonstrations
  2. Collect ranked pairs of answers and fit a reward model
  3. Update the model to raise reward, with a KL penalty to the tuned model

Supervised tuning, then a reward model from preference pairs, then a penalized reinforcement-learning update.

Check yourself

What does the KL penalty in RLHF protect against?

Show the answer

Answer: b

The reward model is only an approximation of preferences. Staying close to the reference model limits how far the policy can game it.

Check yourself

What replaces most human harm labels in Constitutional AI?

Show the answer

Answer: b

The model critiques and revises answers against principles, and an AI rater produces the preference pairs.

Check yourself

What risk comes with using an AI rater to make preference data?

Show the answer

Answer: b

AI feedback scales, but it inherits the rater model's judgments. Spot-check with people.

Check yourself

What does DPO need that ORPO doesn't?

Show the answer

Answer: a

DPO's loss uses log-ratios to a reference policy; ORPO folds preference into the supervised loss with odds ratios and needs no reference.

Check yourself

What does DPO's β control?

Show the answer

Answer: b

β plays the role of RLHF's KL penalty strength, scaling the log-ratio margin inside the sigmoid.

Check yourself

How does ORPO combine supervised tuning and preference tuning?

Show the answer

Answer: b

One stage, no reference model: the odds-ratio term pushes the preferred answer's odds above the rejected one's.

Check yourself

ORPO's preference term compares what between the chosen and rejected answers?

Show the answer

Answer: b

The log odds ratio inside a sigmoid gives a pairwise loss without a reference model.

09

Recap

Recap
  • Instruction tuning on many tasks (FLAN, T0) teaches instruction following; template wording still moves results.
  • RLHF: demonstrations, a Bradley–Terry reward model, then a KL-penalized policy update. Constitutional AI swaps in principle-guided AI feedback.
  • DPO needs a reference model but no reward model; ORPO needs neither.
  • Preference tuning makes answers look preferred, not necessarily true.

Concepts in this lesson