Post-training
Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8
12 cards in “8.4 Alignment via preference-based learning” · whole deck
8.4 Alignment via preference-based learning
- How do the elements of reinforcement learning map onto LLM alignment?
RL LLM alignment action choice of the next token state context: tokens generated so far policy \(\pi\) the language model reward score from a reward model learned from preferences - Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.4, pp. 219–220
- What objective does preference-based RL alignment optimize, in its simplest form?Find the policy that maximizes expected reward of its own outputs: \(\pi^* = \arg\max_{\pi_\theta}\mathbb{E}_{x \sim D,\, o \sim \pi_\theta(o \mid x)}[r(x, o)]\).
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.4, p. 220
- What are two key differences between traditional RL and RL for LLM alignment?(1) The reward comes not from the environment (win or lose) but from a learned reward model, a noisy surrogate for the true reward. (2) Learning starts not from a random policy but from a strong pretrained, instruction-tuned model that should only be nudged toward preferred behavior.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.4, p. 220
- Why is a KL-divergence penalty added to the alignment objective?Optimizing only for reward on a small amount of preference data would make the model forget what it learned in pretraining. The penalty \(\beta D_{KL}[\pi_\theta \,\|\, \pi_{ref}]\) keeps the trained policy close to the reference (starting) model.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.4, p. 221
- Write the KL-constrained alignment objective.\(\pi^* = \arg\max_{\pi_\theta}\mathbb{E}\big[r(x, o) - \beta\log\frac{\pi_\theta(o \mid x)}{\pi_{ref}(o \mid x)}\big]\), where \(\beta\) controls the strength of the penalty.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.4, p. 221
- What does KL divergence measure?A distance between two probability distributions; for LLM policies, the log of the ratio of the trained policy’s probability to the reference policy’s.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.4, p. 221
- What are the two approaches to aligning LLMs with this objective?Train an explicit reward model and optimize the policy with RL (e.g. PPO), or rearrange the closed-form solution to fine-tune directly from preference data (DPO).
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.4, p. 221
- What is Direct Preference Optimization (DPO)?A method (Rafailov et al., 2023) that optimizes an LLM directly on preference data with gradient descent, without learning an explicit reward model or sampling from the model being trained.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.4, p. 222
- What is the key insight of DPO?Rewrite the closed-form optimum of the KL-constrained objective so the reward is expressed through policies: \(r(x, o) = \beta\log\frac{\pi(o \mid x)}{\pi_{ref}(o \mid x)} + \beta\log Z(x)\). In the Bradley-Terry difference of two rewards, the intractable partition function \(Z(x)\) cancels.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.4, p. 222
- Write the DPO loss for one preference pair.\(L_{DPO} = -\log\sigma\Big(\beta\log\frac{\pi_\theta(o_w \mid x)}{\pi_{ref}(o_w \mid x)} - \beta\log\frac{\pi_\theta(o_l \mid x)}{\pi_{ref}(o_l \mid x)}\Big)\)
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.4, p. 222
- What does the DPO update do, intuitively?It increases the likelihood of preferred outputs and decreases that of dispreferred ones, relative to the reference model, while the KL term (via \(\beta\), typically 0.01–0.1) keeps it from straying too far.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.4, pp. 222–223
- What are the advantages of DPO over PPO?No explicit reward model to train; it learns directly from the preference dataset without expensive online sampling from the policy; and it keeps only 2 LLMs in memory during training instead of 4.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.4, p. 223
Source
- Daniel Jurafsky and James H. Martin. Speech and Language Processing. 3rd edition (draft). https://web.stanford.edu/~jurafsky/slp3/