Ask a freshly pretrained language model to “Explain the moon landing to a 6 year old in a few sentences”, and you may get back… more questions: “Explain the theory of gravity to a 6 year old. Explain the theory of relativity to a 6 year old…”. The model is not broken. It was trained to continue text, and on the internet a line like this is often followed by similar lines, for example in a list of homework prompts.
This gap between predicting the next token and doing what the user wants is what alignment tries to close. This reading covers why the gap exists, how in-context learning partly works around it, and how instruction tuning trains models to follow instructions directly, along with its limitations.
1Why alignment?
A pretrained language model learns one thing: given the text so far, predict the next token. Give it a prompt, and it produces a completion that is a likely continuation. A likely continuation is not the same as a helpful answer:
- Given “Translate English to French: cheese”, a perfectly reasonable continuation is “is tasty”: the model simply keeps writing the sentence.
- Given a question, the model may produce more questions, a forum discussion, or an off-topic story, because all of these appear after questions in its training text.
Alignment means making a model's behavior match what people intend. A common summary of the goal is that a model should be helpful (does what the user asked), honest (does not make things up), and harmless (avoids harmful outputs).
2A first workaround: in-context learning
Large language models such as GPT-3 showed a surprising ability: if the prompt contains a task description and a few examples of the task, the model continues the pattern. This is in-context learning (ICL), also called few-shot prompting. No parameters are updated; the “learning” happens entirely inside the prompt.
ICL works, but it has clear limitations:
- Examples every time. The examples must be included in every prompt, using up context length and computation.
- The model does not change. Nothing is learned permanently; a new prompt starts from scratch.
- Sensitivity. Results can change with which examples are chosen and in what order.
- Scale. Smaller models are much worse at in-context learning.
And users do not want to write examples; they want to just ask. Could we instead train the model so that it follows instructions directly?
3Instruction tuning
The idea of instruction tuning: LLMs already have a lot of knowledge from pretraining, but they do not reliably produce the outputs we want. So we finetune them on examples of instructions paired with good responses. The data comes from two main sources:
- Converting existing NLP datasets. A sentiment dataset, a translation dataset, a question answering dataset, and so on, are rewritten into an (instruction, input, output) format using templates.
- Collecting human-written examples. People write prompts that users might ask, together with high-quality answers.
Training is ordinary language modeling on these examples: the instruction and input are given as context, and the model learns to generate the output token by token. One common detail: the loss is usually computed only on the response tokens. The model should learn to answer instructions, not to generate them.
4Scaling up instruction tuning
The training recipe has two stages:
- Pretrain on lots of text with language modeling: learn general knowledge and language.
- Finetune on many tasks, each phrased as instructions: learn to follow instructions.
The key finding is that the number and variety of tasks matters. A model instruction-tuned on many different tasks learns the general skill of “read an instruction, do what it says”, and this skill transfers to tasks it has never seen. To test this, researchers hold out entire task types (e.g., all natural language inference tasks) during finetuning and evaluate on them afterwards with zero-shot instructions.
| Work | Scale of instruction data | Main finding |
|---|---|---|
| FLAN (Wei et al., 2021) | 62 datasets in 12 task clusters | Instruction tuning improves zero-shot performance on held-out task types |
| Super-NaturalInstructions (Wang et al., 2022) | 1,616 tasks with expert-written instructions | Models generalize to unseen tasks given only their instructions |
| Flan-PaLM / Flan-T5 (Chung et al., 2022) | 1,836 tasks, including chain-of-thought data | Scaling the number of tasks and model size both help |
Sentence: The reporter and the chef will discuss their favorite dishes.
Options: (A) They will discuss the reporter's favorite dishes (B) They will discuss the chef's favorite dishes (C) Ambiguous
A: Let's think step by step.
5Limitations of instruction tuning
- Expensive data. High-quality responses written by people cost a lot of time and money, especially for long or expert answers.
- No single right answer. For open-ended requests (“write me a story about a dog and her pet grasshopper”) there are countless good responses. Training the model to reproduce one particular reference story is a strange objective.
- All token mistakes count the same. The language modeling loss penalizes every wrong token in the same way, but some mistakes are much worse than others.
Even after instruction tuning, there is a mismatch between the language modeling objective (“predict the reference tokens”) and what we actually want (“produce responses people prefer”). This motivates methods that learn from human preferences: instead of writing the perfect answer, people compare model outputs and say which one is better, and the model is trained to produce the preferred kind of output.
6Summary
- Pretrained LMs continue text; they do not necessarily do what the user asks. Alignment aims for helpful, honest, and harmless behavior.
- In-context learning puts task examples in the prompt; it needs examples every time and does not change the model.
- Instruction tuning finetunes the model on (instruction, input, output) examples, usually with the loss on the response only.
- Training on many diverse tasks teaches a general instruction-following skill that transfers to unseen tasks.
- Instruction tuning is limited by data cost, open-ended tasks without a single answer, and a token-level loss that treats all mistakes equally.
7Practice
Exercise 1: write an instruction example
Convert this example from a natural language inference dataset into (instruction, input, output) form. Premise: “A man is playing a guitar on stage.” Hypothesis: “A man is performing music.” Label: entailment.
Exercise 2: loss masking
A training sequence has 40 instruction tokens and 10 response tokens. With the loss computed on the response only, how many token predictions contribute to the loss? Why might this be preferred over all 50?
Exercise 3: held-out evaluation
You instruction-tune a model on sentiment analysis, translation, and summarization, and then evaluate it on sentiment analysis with new examples. Does this show generalization to unseen tasks? How would you design a better test?
Quick quiz
8Further reading
- Wei et al. (2021). Finetuned Language Models Are Zero-Shot Learners. (FLAN: instruction tuning and generalization to unseen tasks.)
- Chung et al. (2022). Scaling Instruction-Finetuned Language Models. (Flan-PaLM and Flan-T5.)
- Wang et al. (2022). Super-NaturalInstructions: Generalization via Declarative Instructions on 1600+ NLP Tasks. EMNLP.
- Ouyang et al. (2022). Training Language Models to Follow Instructions with Human Feedback. (InstructGPT; source of the moon-landing example.)
- Brown et al. (2020). Language Models are Few-Shot Learners. (GPT-3 and in-context learning.)