Post-training
Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8
51 cards
Introduction
- In what two ways are pretrained-only LLMs insufficiently helpful?They aren’t good at following instructions (asked how to steal from a store, a base model may just generate a related question), and they aren’t always good at complex problem solving that needs long chains of reasoning.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, Introduction, p. 209
- Why are pretrained-only LLMs also potentially harmful?Pretraining doesn’t make them safe: they can attack users, suggest harmful actions, or give dangerously false answers (e.g. medical).
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, Introduction, p. 209
- What is the underlying reason LLMs are too harmful and insufficiently helpful after pretraining?The pretraining objective (predicting words in text) is misaligned with the human need for models to be helpful and non-harmful.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, Introduction, p. 209
- What are the three stages of post-training?(1) Instruction tuning (SFT): fine-tuning on instructions and responses. (2) Preference alignment (e.g. RLHF, DPO): using a model of human preferences to fine-tune the model. (3) RL with verifiable rewards (RLVR): training on tasks with clear right answers, like math or programming, to solve multi-step problems.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, Introduction, pp. 209–210
- What is a base model?A model that has been pretrained but hasn’t yet gone through any post-training steps.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, Introduction, p. 210
8.1 Instruction tuning
- What is instruction tuning, and what does the model learn beyond the training tasks?Fine-tuning a base LLM on a corpus of instructions and responses for many tasks (translation, meal planning…). Beyond those tasks it learns to follow instructions in general, a form of meta-learning.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.1, p. 210
- What objective and which tokens are used in instruction tuning?The same language-modeling cross-entropy objective as pretraining, but trained only on the response: the instruction is the conditioning context, and the model predicts the response tokens one by one.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.1, p. 210
- Why is instruction tuning called supervised fine-tuning, though it uses next-token prediction?Unlike pretraining text, each instruction comes with a supervised target: a correct answer or response.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.1, p. 210
- What is fine-tuning in general?Taking a fully pretrained model and running additional training passes with cross-entropy loss on new data, adapting all or only some of the parameters.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.1, p. 210
- How much data does instruction tuning need compared to pretraining?Much less: several epochs over instruction datasets of at most millions of examples rather than trillions of tokens, so it costs a small fraction of pretraining.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.1, p. 211
- What kinds of content can instructions contain?Anything: code to write, questions to answer, translations, writing tasks, shopping lists; with parts like length restrictions, personas to assume, and demonstrations.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.1, p. 211
- What instruction-tuning datasets exist?Aya (multilingual, many tasks, partly written by volunteer fluent speakers of many languages), Super-NaturalInstructions, Flan 2022, OPT-IML, Alpaca.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.1, p. 211
- Why use existing NLP datasets to create instruction data, and how?Writing high-quality instructions by hand is slow and costly. Fields of existing datasets (e.g. SQuAD QA, NLI premise/hypothesis/label, sentiment text/label) are extracted as key/value pairs and inserted into instruction templates, often paraphrased by LLMs for diversity.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.1, pp. 211–212
- Give an example of an instruction template built from an NLI dataset.“Suppose {{premise}} Can we infer that {{hypothesis}}? Yes, no, or maybe?”, with the dataset’s label as the target response.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.1, p. 212
- What is the most common way to generate instruction-tuning data today?Having language models write it, based on various datasets.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.1, p. 212
- How can instruction data make models safer, and how much is needed?Take harmful questions, have an LLM paraphrase them and write safe refusals, review them manually, and add them to the instruction data. Even a few hundred safety instructions mixed into a large dataset substantially reduce harmfulness.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.1, pp. 212–213
- How can annotation guidelines written for crowdworkers be reused?As prompts to an LLM to generate instruction-tuning examples for that task.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.1, p. 213
- How are instruction-tuned models evaluated, and why with task clusters?Since the goal is following instructions in general, they are tested on held-out tasks (leave-one-out). Many datasets are near-duplicates of a task, so datasets are grouped into clusters by task similarity and a whole cluster (e.g. all sentiment datasets) is withheld.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.1, p. 213
8.2 Parameter-efficient fine-tuning
- Besides instruction tuning, when might we fine-tune a pretrained model?To adapt it to a new task, domain (legal, medical) or language/variety whose data wasn’t sufficiently represented in pretraining.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.2, p. 213
- Why is it hard to fine-tune all the parameters of very large LMs?Every batch must backpropagate through enormous numbers of parameters in many huge layers, which is very expensive in compute, memory and time; many labs can’t do it.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.2, p. 214
- What is parameter-efficient fine-tuning (PEFT)?Fine-tuning that freezes most parameters and updates only a small chosen subset.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.2, p. 214
- What is the intuition of LoRA?Low-Rank Adaptation: freeze the dense weight matrices (e.g. \(W^Q, W^K, W^V, W^O\)) and instead learn a low-rank update with far fewer parameters.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.2, p. 214
- How does LoRA update a frozen matrix \(W\) of shape \([k \times d]\)?It learns \(A\) \([k \times r]\) and \(B\) \([r \times d]\) with \(r \ll \min(d, k)\), replacing \(W + \Delta W\) by \(W + AB\). The forward pass becomes \(h = xW + xAB\).
With small r, A and B have far fewer parameters than W. - Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.2, p. 214
- What are the advantages of LoRA?Much lower hardware requirements (no gradients for most parameters); no extra inference time, since \(AB\) has the shape of \(W\) and can be added into it; and modules for different domains can be swapped in and out by adding or subtracting them.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.2, pp. 214–215
- To which matrices was LoRA originally applied?Only the attention matrices: \(W^Q, W^K, W^V, W^O\). Many variants exist.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.2, p. 215
8.3 Learning from preferences
- What problems can remain after instruction tuning that preference learning addresses?Hallucinations, unsafe or harmful outputs, and responses that are technically correct but not as helpful as they could be; it targets qualities like honesty, helpfulness and harmlessness.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.3, pp. 215–216
- Why are preference judgments easier to obtain than instructions?They don’t require knowing how to do something, only an opinion about the result. People can express preferences about outputs even with no expertise in producing them.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.3, p. 216
- What forms do preference judgments take?Picking the better of a pair, selecting one from a set, ranking a set of possibilities, or accepting/rejecting an option in isolation.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.3, p. 216
- What does LLM preference data consist of, and how is a preference written?A prompt \(x\) with several outputs \(o\) sampled from an LLM, and judgments such as \((o_i \succ o_j \mid x)\): \(o_i\) is preferred to \(o_j\) given \(x\).
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.3, p. 216
- How many preference pairs does a ranking of \(N\) outputs give, and how many does choosing one best of \(N\) give?A full ranking of \(N\) outputs gives \(\binom{N}{2}\) pairs (e.g. 6 for 4 outputs); selecting the single best gives \(N - 1\) pairs.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.3, p. 216
- What are the three sources of preference data for LLM alignment?Human annotator judgments, implicit preferences extracted from online resources, and fully synthetic preferences from LLMs acting as annotators.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.3, p. 216
- How can social media provide implicit preference data?On sites like Reddit or StackExchange, a post serves as the prompt and the responses as sampled outputs; accumulated user votes rank the responses, which can be turned into preference pairs.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.3, p. 217
- How are synthetic preference datasets like UltraFeedback created?Outputs for each prompt are generated by a diverse set of LLMs, and a strong LLM (e.g. GPT-4) ranks them.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.3, p. 217
- What are aspect-based scalar judgments, and what is their advantage?Annotators (human or LLM) rate each output on a Likert scale along dimensions like helpfulness, honesty, correctness, complexity and verbosity. Pairs can be derived per dimension or from averages, avoiding costly pairwise comparisons.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.3, p. 217
- What is the Bradley-Terry model of preferences?Each item has a hidden scalar score; the probability that \(o_i\) is preferred to \(o_j\) is the sigmoid of the score difference: \(P(o_i \succ o_j \mid x) = \sigma(z_i - z_j)\).
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.3, p. 218
- Why is the Bradley-Terry formulation convenient?Tiny score differences give probabilities near 0.5 (weak or no preference), larger differences quickly approach 0 or 1, and the sigmoid’s derivative allows learning with a binary cross-entropy loss. The score difference is interpreted as the log odds of the preference.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.3, p. 218
- How is a reward model trained from preference data?Learn \(r(x, o)\) that gives the scores in Bradley-Terry, minimizing \(-\log\sigma(r(x, o_w) - r(x, o_l))\) over pairs of preferred (winner) and dispreferred (loser) outputs, averaged over the preference dataset.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.3, p. 219
- How is a reward model typically built?Initialize it from a pretrained LLM, remove the language modeling head, and replace it with a single dense linear layer that outputs a scalar; train with the Bradley-Terry loss.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.3, p. 219
- Besides alignment, what are reward models used for?Best-of-N sampling (picking the preferred response among several sampled ones) and selecting data for instruction tuning.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.3, p. 219
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/