AI State of the Art
SOTA/Alignement : instruction, RLHF, DPO et apprentissage par renforcement/24 min
Section 110

Instruction Tuning: FLAN, Alpaca, OpenHermes, Orca

Listen as a podcast →

The Problem: Your Model Completes Text, It Doesn't Follow Instructions

Take a raw LLaMA model, fresh out of pre-training. It's an excellent text completer: it has read the entire internet and knows how to predict the next word with impressive accuracy. But tell it "Translate this into English" and it will... sometimes continue your sentence as if writing an article, sometimes rephrase your instruction, sometimes give a correct answer by chance. It's random, because it has never learned to follow instructions.

Instruction tuning (also called SFT, for Supervised Fine-Tuning) fixes this. You show the model thousands of instruction-response pairs until it retains the rule: "when someone asks me a question, I answer, I do not continue the sentence." It is the step that turns a completer into an assistant.

One clarification about where this page sits in the module: instruction tuning describes what you teach the model, not how you teach it. The two combine freely, you can do instruction tuning with LoRA, with QLoRA, or with full fine-tuning, depending on the memory you have.

Three-panel diagram. A, Pretrain-finetune (BERT, T5): a pretrained language model is finetuned on task A then used for inference on task A; two notes say this typically requires many task-specific examples and yields one specialized model per task. B, Prompting (GPT-3): a pretrained language model goes straight to inference on task A, with a note that performance improves via few-shot prompting or prompt engineering. C, Instruction tuning (FLAN): a pretrained language model is instruction-tuned on many tasks B, C, D and more, then does inference on task A, with a note that the model learns to perform many tasks via natural language instructions and generalizes to an unseen task.
The three ways to get a model that does what you ask. In A, you finetune one model per task. In B, you leave the model alone and craft the prompt. In C, instruction tuning: you train once on a large mixture of tasks phrased in natural language, and the model can then handle a task it never saw during training.Source : FLAN paper by Wei et al. (2021), figure 2, via ar5iv
The Complete Chain of a Modern Model
  1. Pre-training on a massive corpus: internet, books, code. The model learns the language.
  2. Instruction tuning on instruction-response pairs. The model learns the role of assistant.
  3. Alignment on human preferences, via RLHF (Reinforcement Learning from Human Feedback) or DPO (Direct Preference Optimization). The model learns to choose between two equally correct answers.

The difference between steps 2 and 3 is worth stating plainly. At step 2, you show the model one good answer and ask it to imitate it. At step 3, you show it two answers and say which one a human preferred. The first teaches a format, the second a judgement.

The Pioneers: FLAN (2021)

Google launched the movement with FLAN (Finetuned Language Net). The idea was simple: fine-tune a model on more than sixty datasets of natural language processing (NLP) all rewritten as instructions in ordinary language, then see what it can do on tasks it has never seen.

That last point is what counts. The aim is not to improve the model on the training tasks (that would be unremarkable) but on tasks absent from training. This is called zero-shot: no examples given, only the instruction.

Finetuned Language Models Are Zero-Shot Learners (Wei et al., 2021)

The result stated in the paper's abstract, and checkable: FLAN, at 137 billion parameters, beats a 175-billion-parameter GPT-3 in zero-shot on 20 of the 25 datasets tested zero-shot, and beats it by a large margin on several of them even when GPT-3 is allowed examples.

Two-part figure. At the top, under the title Finetune on many tasks (instruction-tuning), two training examples: a commonsense reasoning example with an instruction, options and a target, and an English to Spanish translation example; below them, pills list other task families such as sentiment analysis and coreference resolution. An arrow leads to a box labelled Inference on unseen task type containing a natural language inference example with premise, hypothesis and options, plus the FLAN response. At the bottom, a bar chart compares performance on unseen task types between GPT-3 175B zero shot, GPT-3 175B few-shot and FLAN 137B zero-shot across three task families: natural language inference, reading comprehension and closed-book QA.
The FLAN recipe in one picture. At the top, training runs over dozens of task families rewritten as instructions; one whole family is held out, here natural language inference, and the model is tested on it with no examples at all. At the bottom, the result: a 137B FLAN in zero-shot beats a 175B GPT-3, even when GPT-3 is allowed examples.Source : FLAN paper by Wei et al. (2021), figure 1, via ar5iv

Then came FLAN-T5 and FLAN-PaLM, trained on more than 1,800 tasks, with several different phrasings for each. The principle: the more varied the instructions seen during training, the better the model adapts to a new one. Like a student who has worked through very different kinds of exercise and can improvise on exam day.

In parallel, the T0 project, run by the open BigScience consortium, did the same thing collaboratively: the instruction phrasings were written by researchers around the world rather than one team.

The Open-Source Revolution: Alpaca and Self-Instruct (2023)

Stanford had a simple idea: have a more powerful model generate the training data. Starting from 175 hand-written examples, they asked text-davinci-003 (OpenAI's GPT-3.5-generation model) to produce 52,000 more, then fine-tuned LLaMA-7B on those.

The cost Stanford reported: under $500 to generate the data and under $100 for the fine-tuning. Under $600 in total, against the millions spent pre-training the base model.

Diagram of how Alpaca was built. On the left, a document labelled 175 Self-Instruct seed tasks and a Text-davinci-003 block converge into an arrow labelled Modified Self-instruct Instruction Generation. That arrow produces a document labelled 52K Instruction-following examples, which is combined with a Meta LLaMA 7B block through an arrow labelled Supervised Finetuning, resulting in an Alpaca 7B block. At the bottom, two boxes give an example seed task, brainstorm a list of possible New Year's resolutions, and an example generated task, brainstorm creative ideas for designing a conference room.
The whole Alpaca chain on one line: 175 hand-written examples go into text-davinci-003, which produces 52,000, and those 52,000 are used to finetune LLaMA-7B. The two boxes at the bottom show the key point, the generated example is not a copy of the seed, it only borrows its shape.Source : Stanford CRFM, Alpaca model announcement

This technique is called Self-Instruct: give a powerful model a few starting examples and it manufactures thousands more. It is data distillation, the large model's know-how passes into the small one through the examples it writes, with no human annotating anything. An experienced teacher writes the exercises that will train the student.

The result set off a wave: Vicuna, WizardLM and dozens of other open models started rivaling commercial assistants, at trivial cost.

OpenHermes: Quality Above All

OpenHermes 2.5 gathers about a million examples, with two deliberate choices:

  • multiple sources (general text, code, mathematics, logical reasoning) rather than one;
  • filtering that removes poorly phrased, inconsistent or repetitive examples.

The lesson: raw volume is not what counts, diversity and cleanliness are. The next section returns to this with numbers.

Data Format: The Conversational Standard

{
  "messages": [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Explain photosynthesis."},
    {"role": "assistant", "content": "Photosynthesis is..."}
  ]
}

This three-role format is what nearly every training library uses. The system role sets general behaviour, user carries the question, assistant the expected answer.

Careful not to conflate two levels. This message structure is a logical representation; to be fed to the model it has to be flattened into plain text, with markers signalling where each turn starts and ends. Those markers differ from model to model: some use special tags like <|im_start|>, others brackets. This is the model's chat template, and it belongs to the model, not to the data format.

Task Diversity: The Real Secret

A good instruction tuning dataset doesn't just contain Q&A. It covers a broad spectrum:

  • Open-ended questions: "Explain...", "Describe...", "Compare..."
  • Structured tasks: "Translate...", "Summarize...", "Extract the entities from..."
  • Reasoning: "Solve this problem...", "Analyze the pros and cons..."
  • Creativity: "Write a poem about...", "Invent a story where..."
  • Code: "Implement...", "Debug this code...", "Optimize this function..."
  • Multi-turn: complete conversations with evolving context

This diversity is crucial. A model trained only on factual Q&A will be bad at creativity. A model trained only on code will be weird in conversation.

Quality Before Volume: The LIMA Lesson

The LIMA paper (Meta, 2023) showed that a model fine-tuned on 1,000 carefully chosen examples rivals models trained on hundreds of thousands of ordinary ones. Its title states the thesis: Less Is More for Alignment.

AlpaGasus pushed the same way, filtering Alpaca's 52,000 examples down to the 9,000 best-rated by a judge model, and getting a better model than the full 52,000 gave.

That is a ratio of 1 to 6, which is not trivial: five examples out of six in a well-known dataset contributed nothing, or hurt. The practical conclusion: spend the annotation budget on sorting, not on volume.

Instruction Tuning Best Practices

1. Respect the Model's Chat Template

Every model expects the exact turn markers it was trained with, and those differ between families. A wrong template produces a model that mixes instructions and answers, the most common and most silent mistake, since training runs to completion without ever flagging anything wrong. Use the template shipped with the model; do not rewrite it.

2. Learn Only on the Answer

The model is trained to predict the next word, and the loss (the measure of its error) is computed over every predicted word. It must be computed only on the words of the answer, masked over those of the instruction.

Why? Because otherwise the model is also being trained to invent questions, which nobody needs, and part of its learning capacity goes there. The detail is technical; the effect on quality is large.

3. Aim for Detailed and Structured Responses

The model imitates the style of the responses it sees. Short, sloppy responses produce a sloppy assistant. Well-structured responses, with clear paragraphs and examples, produce a helpful assistant.

4. Diversify Seriously

Don't fine-tune only on factual questions. Vary the domains, response formats, and difficulty levels. The more varied situations the model sees, the better it generalizes.

The Synthetic Data Trap

Data produced by a powerful model inherits its leanings: its style, its turns of phrase, its refusals. The student model cannot surpass its teacher on those dimensions, since it has never seen anything else.

Worse: train on synthetic data, then use the resulting model to generate new data, and repeat, quality degrades with every round. This is model collapse, and the image is a photocopy of a photocopy: each pass loses some of the original's variety, and nothing ever restores it.

The remedy is simple: always mix human-annotated data into synthetic data.

Key Datasets to Know

DatasetSizeSourceStrengths
OpenHermes 2.5~1MGPT-4 + multiQuality, diversity
Dolly-15K15KHumanFree license
OASST1/2~160KCrowdsourcingMultilingual, multi-turn
UltraChat1.5MGPT-3.5/4Volume
SlimOrca518KOrca filteringFiltered quality

The Impact: The Industry Standard Pipeline

Every serious model today follows the same three-step chain: pre-training, instruction tuning, alignment. Instruction tuning is its decisive moment, the one that separates a model that knows things from a model that can help.

The rest of the module covers the third step: RLHF in practice for the tooling, DPO in practice for the variant without reinforcement learning, and Post-fine-tuning evaluation to check any of it worked.


In short. Instruction tuning turns a text completer into an assistant. Without it, the model is an encyclopedia that cannot hold a conversation. And the field's most solid lesson fits in one sentence: a thousand sorted examples beat a hundred thousand scraped ones.

Check your understanding0 / 4

1. In the three-step chain of a modern model, what distinguishes instruction tuning (step 2) from alignment (step 3)?

2. The LIMA paper fine-tunes a model on just 1,000 carefully chosen examples. What lesson does the page draw from that result and from AlpaGasus?

3. Why does the page recommend always mixing human-annotated data into synthetic data?

4. A team fine-tunes a model using its own turn markers instead of the chat template shipped with the model. What should it expect, according to the page?