COMP5046 — Natural Language Processing

Lecture 10: Training — RLHF, Reward Models, Alignment

Why preference learning · reward model · PPO with KL penalty · DPO · alignment risks.

How to use: walk the pipeline once, then close the page and answer each Recall in your own words before reopening.

The gap

Why SFT alone is not enough

RecallName two reasons next-token loss is a poor stand-in for "human-preferred output".

Three stages

The RLHF pipeline

1. SFT prompt → response 2. Reward Model pairs (y_w > y_l) 3. RL fine-tune (PPO) max r − β KL(π‖π_SFT) policy \(\pi_{\text{SFT}}\) reward \(r_\phi\) final \(\pi_\theta\)
Three-stage RLHF: supervised fine-tune → train reward model on preferences → RL fine-tune policy to maximise reward minus KL drift.

RecallList the three stages in order and what artefact each one produces.

Easier for humans

Collecting preference data

RecallWhy ask "A or B?" instead of "write the ideal answer"?

Bradley–Terry

Training the reward model

RecallWhy is the reward model defined only up to a constant?

RL step

PPO fine-tuning with a KL anchor

prompt \(x\) from \(\mathcal{D}\) policy \(\pi_\theta\) samples \(y\) reward \(r_\phi(x,y)\) frozen RM KL penalty vs \(\pi_{\text{SFT}}\) PPO gradient update
PPO loop: sample y from π_θ, score with frozen RM, subtract β·KL against π_SFT, take clipped policy-gradient step.

RecallWhat single term in the PPO objective stops the policy from hacking the reward model?

Skip the RM

Direct Preference Optimisation (DPO)

RecallWhat does DPO replace from the standard RLHF pipeline?

Failure modes

Risks: reward hacking, brittleness, biases

RecallDistinguish reward hacking from sycophancy with a one-line example each.

Lab

Workshop preview & materials

Quick practice

Why is next-token cross-entropy a poor proxy for "human-preferred output"?
It cannot handle long sequences
It only works for classification, not generation
Per-token loss does not measure task success; many tasks have multiple equally good answers
It requires labels in every language
What is the role of the KL penalty in the PPO RLHF objective?
It makes the reward model train faster
It anchors the policy to π_SFT, preventing reward hacking and mode collapse
It replaces the reward model entirely
It enforces sparsity on attention weights
What does DPO eliminate compared to the standard RLHF pipeline?
The explicit reward model and the PPO sampling loop
The need for any preference data
The supervised fine-tuning stage
The KL penalty

Chapter quizzes

Retrieval practice for this lecture.

Open Quiz Hub Chapter flashcards

Problem cards

Problem 1 — Bradley–Terry log-likelihood

Given preference data \(\{(x^{(i)}, y_w^{(i)}, y_l^{(i)})\}_{i=1}^N\), write the RM loss and explain why adding a constant \(c\) to every reward score does not change the gradient.

Hint

Plug \(r' = r + c\) into \(\sigma(r(y_w)-r(y_l))\) and watch the \(c\)s cancel. The likelihood depends only on score differences; the gradient with respect to \(\phi\) is identical.

Problem 2 — Tune β in PPO

You train RLHF and observe: outputs are very high-reward but read like keyword salad. Which direction would you move \(\beta\) (the KL coefficient), and why? What about the opposite failure — outputs look natural but reward barely moves?

Hint

Keyword salad = policy has drifted too far from \(\pi_{\text{SFT}}\) and is hacking the RM → increase \(\beta\). No reward improvement = penalty is too strong and pins the policy to SFT → decrease \(\beta\). Treat \(\beta\) as a fluency / preference-fit trade-off knob.

Problem 3 — Choose RLHF or DPO

You have a curated set of 50k high-quality preference pairs and a single 7B SFT model; no infrastructure for online RL sampling. Which method fits, and what do you give up?

Hint

DPO: no reward model, no PPO sampling — runs as supervised training on the pair data, so it suits your constraints. You give up on-policy exploration (cannot improve from new samples), and you inherit whatever biases exist in the 50k labels; brittleness results (Lee et al., 2024) suggest internal representations may still encode the undesired behaviour even if outputs no longer show it.