Search

Search papers and lessons

Self-Instruct: Aligning Language Models with Self-Generated Instructions

Yizhong Wang, Yeganeh Kordi, Swaroop Mishra et al. · 2022

Self-Instruct has GPT-3 write its own tasks, inputs and answers, filters the weak ones, and fine-tunes on the rest, lifting GPT-3 by 33.1 ROUGE-L points with almost no human labels.

On this page

  • Colour = topic mix
  • Calculus
  • Discrete math
  • Neural network basics
  • Linear algebra
  • Probability
  • Post-training
  • ReadReady to readNot yet

TL;DR

Instruction-tuned models follow requests well, but their training data is written by people, which is slow and tends to cover popular tasks. Self-Instruct cuts that cost: start from 175 hand-written tasks, have the model invent new tasks with example inputs and answers, throw away the weak or repeated ones, and fine-tune the same model on what is left. Applied to GPT-3, the loop produced 52,445 instructions, and tuning on them raised GPT-3 by 33.1 ROUGE-L points on a benchmark of unseen tasks, to within 0.9 points of InstructGPT-001, a model trained on private user data and human labels.

Builds on: Instruction Tuning, GPT-3, In-Context Learning · Leads to: the open synthetic instruction datasets that followed it; the paper's reference list cites Stanford Alpaca, one of them.

Why it mattered

Before this paper, the usual way to teach a model to follow instructions was to collect instructions and good answers from people. That worked, and the labeling cost was the bottleneck. Self-Instruct showed that a base model can produce most of such a training set itself, so instruction data could be built without a large labeling budget. The paper's starting model, GPT-3, was not trained to follow instructions at all, so the gain came from the data and the tuning recipe, not from a stronger starting model.

The idea spread because the data was open. The authors released about 52K generated instructions and a set of manually written novel tasks, so other groups had a public dataset to build on. The paper's Broader Impact section makes this point directly: the industrial models' datasets are not released, so academia has little way to study how they were built.

The problem

Instruction tuning takes a pretrained Language Model and fine-tunes it on pairs of an instruction and a desired response. A pretrained model alone is poor at this. The paper finds that vanilla GPT-3 "basically cannot follow human instructions at all": it produces irrelevant, repetitive text and does not know when to stop.

Writing good pairs is hard for two reasons. First, creativity: a person has to think of tasks that are new and useful. Second, expertise: a person has to write a correct answer to each one. Public instruction collections such as PromptSource and Super-NaturalInstructions helped, but the authors note that most of the NLP tasks in such collections were proposed for research purposes and skew toward classification. The open question was how to get tasks that are broad and not limited to what researchers had already thought to write down.

The paper's answer is to let the model propose the tasks, and to use a small human seed set to keep the proposals on track.

How it works

Here is the loop, step by step, using the paper's names. The numbers in the text are the paper's. The toy numbers are invented to show the mechanics.

flowchart LR
    A[Task pool: 175 seed tasks] --> B[Sample 8 instructions: 6 seed, 2 generated]
    B --> C[Prompt GPT-3 to write a new instruction]
    C --> D{Classification task?}
    D -->|yes| E[Output-first: write labels, then inputs]
    D -->|no| F[Input-first: write input, then output]
    E --> G[Filter: heuristics and ROUGE-L below 0.7]
    F --> G
    G --> H[Add to task pool]
    H --> A
    G --> I[Fine-tune GPT-3 on the kept pairs]
  1. Start with a pool of seed tasks. The pool holds 175 tasks, each with one instruction and one example instance (an input and its output). The authors wrote these themselves for the project. Toy version: the pool has 175 entries.

  2. Sample eight instructions as examples. For each new generation, the code picks 8 instructions from the pool and puts them in the prompt as in-context examples. Six come from the human-written seeds and two from earlier generated tasks, so the model sees the original style and some of its own output. Toy version: the pool has grown to 178 entries, and the prompt shows 6 seed tasks and 2 generated ones.

  3. Ask the model for a new instruction. The prompt shows the eight examples and asks for another task. The model writes one, and generation stops at a stop sequence or a length limit. This is where "self" comes from: the same GPT-3 that will later be tuned writes the tasks. The paper uses temperature 0.7 and top-p 0.5 for this step to keep some variety.

  4. Decide whether the task is a classification task. A classification task has a small, fixed set of possible outputs, such as "positive or negative". The model answers this question with a few-shot prompt built from 12 classification and 19 non-classification seed tasks. The answer decides how instances are generated in the next step. Toy version: "Is the sentiment of this review positive or negative?" is classification; "Write a haiku about rain" is not.

  5. Generate instances. For a non-classification task, the model writes an input first and then the output for that input (input-first). For a classification task, it writes a label first and then an input that matches that label (output-first). The reason for the split: input-first generation on classification tasks tended to produce inputs biased toward one label, for example grammatical sentences for a grammar-error task. Output-first forces coverage of every label.

  6. Filter the output. Three kinds of check run before a task joins the pool. A new instruction is kept only if its ROUGE-L overlap with every existing instruction is below 0.7; ROUGE-L is a text-overlap score based on the longest shared word sequence, so 0.7 means "not nearly a copy". Instructions containing words a language model cannot process well, such as "image", "picture" or "graph", are dropped. Instances are dropped if they are identical to another, if two share an input but disagree on the output, or if the instruction is too long or too short or the output just repeats the input.

  7. Add the survivors and repeat. The kept tasks join the pool, and the loop returns to step 2. The paper ran it until it had about 52,000 instructions. It then fine-tuned GPT-3 on the 82,439 instances, using each instruction with its input as the prompt and the output as the target.

Check on step 6: a candidate "List three fruits" would be dropped if the pool already held "Name three fruits", because the two overlap heavily. "Write a limerick about a cat" would pass if no existing instruction overlaps with it by 0.7 or more.

The math

Step 1 in symbols. Each task tt has an instruction ItI_t and nt≥1n_t \geq 1 input-output instances {(Xt,i,Yt,i)}i=1nt\{(X_{t,i}, Y_{t,i})\}_{i=1}^{n_t}. The goal of the model MM is that M(It,Xt,i)=Yt,iM(I_t, X_{t,i}) = Y_{t,i} for every instance. The instruction and the input do not have a strict boundary: "write an essay about school safety" can be one instruction, or the instruction "write an essay about the following topic" plus the input "school safety". The paper allows an empty input, so Xt,iX_{t,i} can be empty.

Step 3 in symbols. The generator is the same language model that will be tuned. Writing pθp_\theta for its next-token probabilities, each generated sequence is drawn one token at a time, yk∼pθ(⋅∣prompt,y1,…,yk−1)y_k \sim p_\theta(\cdot \mid \text{prompt}, y_1, \ldots, y_{k-1}). This is ordinary autoregressive sampling.

Step 6 in symbols. Let SS be the current pool of instructions and InewI_{\text{new}} a candidate. The candidate is accepted only if

max⁡I∈S  ROUGE-L(Inew,I)<0.7\max_{I \in S} \; \text{ROUGE-L}(I_{\text{new}}, I) \lt 0.7

The maximum runs over the whole pool, so one close match is enough to reject a candidate.

Step 7 in symbols. The tuning loss is the standard next-token cross-entropy, computed on the output only. Write the prompt as xx (instruction plus input, in one of several templates) and the target as y=(y1,…,yT)y = (y_1, \ldots, y_T). The loss is

L(θ)=−∑k=1Tlog⁡pθ(yk∣x,y1,…,yk−1)\mathcal{L}(\theta) = - \sum_{k=1}^{T} \log p_\theta(y_k \mid x, y_1, \ldots, y_{k-1})

The paper sets the prompt loss weight to 0, so prompt tokens do not contribute to the loss. The model is trained to produce the output, not to reproduce the instruction.

Worked check with made-up probabilities: if the three output tokens get probabilities 0.5, 0.8 and 0.9, then L=−(log⁡0.5+log⁡0.8+log⁡0.9)≈0.693+0.223+0.105=1.021\mathcal{L} = -(\log 0.5 + \log 0.8 + \log 0.9) \approx 0.693 + 0.223 + 0.105 = 1.021. Training pushes each probability toward 1, which drives the sum toward 0.

Results

The paper evaluates on three things: a public benchmark of unseen tasks, a new set of user-style instructions judged by humans, and the effect of data size and quality.

Super-NaturalInstructions, zero-shot. The evaluation set has 119 unseen tasks with 100 instances each, scored with ROUGE-L (Table 3 of the paper):

ModelParametersROUGE-L
T5-LM11B25.7
GPT-3175B6.8
T011B33.1
GPT-3 + T0 training175B37.9
GPT-3 Self-Instruct (this paper)175B39.9
InstructGPT-001175B40.8
T-k-Instruct11B46.0
GPT-3 + SuperNI training175B49.5
GPT-3 Self-Instruct + SuperNI training175B51.6

The headline gain is 39.9 - 6.8 = 33.1 points. The paper calls this "+33.1%", but it is an absolute gain in ROUGE-L points, not a percentage change; the ratio 39.9 / 6.8 is about 5.9. The gap to InstructGPT-001 is 40.8 - 39.9 = 0.9 points. On top of the SuperNI training set, Self-Instruct data adds 51.6 - 49.5 = 2.1 points, which the authors read as evidence that the two kinds of data are complementary.

User-oriented instructions, human judged. The authors wrote 252 instructions for new uses (email, social media, programming and so on), one instance each. Two authors rated each output on four levels: A (valid and satisfying), B (acceptable with minor errors), C (relevant but with significant errors), D (irrelevant or invalid). GPT-3 Self-Instruct outperforms GPT-3 tuned on T0 or SuperNI data by a large margin. Counting B as valid, it is about 5% behind InstructGPT-001.

Data size and quality. Performance rises as the generated data grows, but the gain flattens after about 16K instructions. On SuperNI the gain flattens much earlier, at a few hundred instructions, which the authors attribute to the generated tasks being unlike typical NLP benchmarks. Regenerating the outputs with InstructGPT-003 and tuning on that version improved the model by 10% in human evaluation.

Data quality. On 200 sampled instructions (one instance each), an expert reviewer found 92% valid tasks, 79% appropriate inputs, 58% correct outputs, and 54% with all three fields valid. The data is noisy. The authors argue that even flawed examples are usually in the right format and still teach the model what a response should look like.

Limits. The paper names three. Tail phenomena: gains concentrate on tasks that are common in pretraining, so unusual or creative instructions may still fail. Dependence on large models: the method may work best for big models, which is a barrier for groups without large compute. Reinforced biases: the loop can amplify social biases, and it had trouble producing balanced labels, which reflected the model's own priors. The whole generation cost about 600 dollars in API fees, and the paper's experiments use one model (GPT-3 "davinci"), so the claim is about that setup.

Reading guide

Check yourself

QuestionThe seed pool has 175 tasks. What role do the seeds play, and why does their coverage matter?Show answer

The seeds are the only human input. The model copies their style and coverage: the paper observes that putting coding tasks in the prompt makes it more likely to generate coding tasks, so the diversity and quality of the seeds limit what the loop can produce.

QuestionIn Table 1, 82,439 instances come from 52,445 instructions. Roughly how many instances per instruction is that?Show answer

82,439 / 52,445 is about 1.57, so roughly 1.6 instances per instruction. Most tasks have a single example pair or a small handful.

QuestionWhy does the method use output-first generation for classification tasks instead of input-first?Show answer

Input-first generation on classification tasks tends to produce inputs biased toward one label. For grammar error detection, the model usually writes grammatical sentences. Output-first generation picks a label first and then writes an input that matches it, so every label is represented.

QuestionA candidate instruction has a ROUGE-L overlap of 0.75 with one existing instruction and 0.30 with all the others. Is it kept?Show answer

No. The rule is that the maximum overlap with any existing instruction must be below 0.7. One match of 0.75 is above the threshold, so a single close match is enough to reject the candidate, even though the other overlaps are low.

QuestionVanilla GPT-3 scores 6.8 on SuperNI and the tuned model scores 39.9. A colleague says this is a 487 percent improvement. Is that the paper's claim, and how should the result be stated?Show answer

Not quite. The 487 percent figure is the relative gain, (39.9 - 6.8) / 6.8 = 4.87, so the gain is 4.87 times the baseline score. The paper's Table 3 caption writes its gain as "+33.1%", but that is an absolute gain of 33.1 ROUGE-L points, and stating it that way is clearer. The ratio of the two scores, 39.9 / 6.8, is about 5.9.

Sources

  • Wang et al., Self-Instruct: Aligning Language Models with Self-Generated Instructions — arXiv:2212.10560
  • Ouyang et al., Training language models to follow instructions with human feedback — arXiv:2203.02155
  • Brown et al., Language models are few-shot learners — arXiv:2005.14165

Read the full paper

Yizhong Wang, Yeganeh Kordi, Swaroop Mishra et al., 2022. arXiv:2212.10560