Generative AI
Instruction Tuning and Supervised Fine-Tuning
Design supervised fine-tuning data that improves task behavior without encoding brittle templates or hidden contradictions.
By the end you can
- Explain how supervised fine-tuning changes a pretrained language model
- Design prompt-response demonstrations with clear provenance and task coverage
- Identify contamination, duplication, style bias, and conflicting instructions in SFT data
- Evaluate fine-tuned behavior against both target gains and broad regressions
Example
The raters said the imitations were competitive; the benchmarks said otherwise
Fine-tune a small model on ChatGPT's outputs and it starts to sound like ChatGPT. Whether it also works like ChatGPT is a separate question, and it has been measured. Imitation models of 1.5B to 13B parameters were trained on 0.3M to 150M tokens of ChatGPT outputs, then put in front of crowd raters. The raters judged them competitive with ChatGPT itself.
Targeted automatic evaluations did not agree. On tasks not heavily supported in the imitation data, the models closed little to none of the gap from the base LM to ChatGPT. Gudibande and colleagues state the mechanism in one line of their abstract: "We show that these performance discrepancies may slip past human raters because imitation models are adept at mimicking ChatGPT's style but not its factuality." The paper is The False Promise of Imitating Proprietary LLMs, an ICLR 2024 spotlight.
The demonstrations taught the surface of the behavior. The human evaluation could not tell the surface from the task. Both facts were measured, not suspected.
- Style is what a rater can see: crowd comparison rewarded the property the imitation data transferred well — presentation — and was blind to the property it did not.
- Coverage decides the gain: the gap that failed to close was on tasks not heavily supported in the imitation data, so the shape of the demonstration set, not its size, set the ceiling.
- Scale did not rescue it: the finding held across models from 1.5B to 13B parameters trained on anywhere from 0.3M to 150M tokens of outputs.
- Provenance travels with the data: demonstrations copied out of another system carry its selection effects, its stale rules and its boilerplate along with its wording.
- The evaluation was the failure: targeted automatic evaluations found what preference judgments did not, and a team measuring only style similarity would have shipped the result as a success.
SFT moves probability toward demonstrated outputs — about 13,000 of them, in the canonical case
Supervised fine-tuning continues gradient-based training on curated input-output pairs. For a decoder model, the loss often applies to response tokens while the prompt provides conditioning context. The model learns both the task and the dataset's presentation habits. A narrow demonstration set can improve one interface while making responses more repetitive or brittle elsewhere.
The order of magnitude is smaller than most people expect. InstructGPT was built on about thirteen thousand demonstrations. Ouyang and co-authors set the three corpora out in 2022: "The SFT dataset contains about 13k training prompts (from the API and labeler-written), the RM dataset has 33k training prompts (from the API and labeler-written), and the PPO dataset has 31k training prompts (only from the API)."
Those roughly 13,000 demonstrations were written by a hired team of about 40 contractors. What they bought was not marginal. Human raters preferred the 1.3B-parameter InstructGPT's outputs to those of the 175B GPT-3, despite the 100x difference in parameters. Demonstrations are a lever that a hundredfold in scale did not match.
Case
A thousand curated prompts against eighteen hundred tasks
How little can be enough is an empirical question, and two papers answer it from opposite ends. LIMA is a 65-billion-parameter LLaMa fine-tuned with the standard supervised loss on only 1,000 carefully curated prompts and responses, with no reinforcement learning at all. In a controlled human study, its responses were equivalent or strictly preferred to GPT-4 in 43% of cases, to Bard in 58% and to DaVinci003 in 65%. Zhou and co-authors published it in 2023, and the subtitle is the finding: Less Is More for Alignment.
Scale of tasks is a separate axis. Chung and co-authors instruction-finetuned Flan-PaLM 540B on 1.8K tasks and reached 75.2% on five-shot MMLU. One thousand curated examples buy a conversational interface. Eighteen hundred tasks buy breadth. Neither number is the other's substitute, and neither is a target to copy before you know which of the two problems you have.
Visual
An SFT record needs more than prompt and answer
A usable demonstration record carries five layers, and only the middle one is the answer. Task intent records what user need and decision the example represents. Input and context hold the prompt, source material, tool state and relevant constraints. The target response is the desired output with its exact formatting and behavior. Provenance names the author, source, policy version, creation method and review history. Evaluation tags mark domain, difficulty, risk, language and known alternatives. The metadata is what makes later audits and corrections possible. Without it, a dataset can only be regenerated, not repaired.
A public corpus shows what this costs and what it yields. Köpf and co-authors released OpenAssistant Conversations in 2023, and their abstract counts it out: "In an effort to democratize research on large-scale alignment, we release OpenAssistant Conversations, a human-generated, human-annotated assistant-style conversation corpus consisting of 161,443 messages in 35 different languages, annotated with 461,292 quality ratings, resulting in over 10,000 complete and fully annotated conversation trees." It came from over 13,500 volunteers, under a permissive licence.
Note the ratio: 461,292 quality ratings against 161,443 messages. In a corpus built to be audited, the annotation outweighs the content.
- 01
Task intent
What user need and decision the example represents.
- 02
Input and context
Prompt, source material, tool state, and relevant constraints.
- 03
Target response
The desired output with exact formatting and behavior.
- 04
Provenance
Author, source, policy version, creation method, and review history.
- 05
Evaluation tags
Domain, difficulty, risk, language, and known alternatives.
Comparison
Demonstration sources have different failure modes
A healthy mixture uses each source for the behavior it can support.
Expert-written examples are high-control demonstrations created for the intended policy. They come with clear rationale and provenance, they are expensive and slow to scale, they can overrepresent idealized prompts, and they need disagreement and adjudication. InstructGPT's roughly 13,000 SFT prompts, written with labeler demonstrations by about 40 contractors, are what this source looks like at production scale.
Historical interaction logs supply real wording and operational diversity from deployed workflows. They capture authentic user behavior, they contain stale policy and privacy risk, and they reflect prior system selection effects. They require redaction and reconstruction before any of that authenticity is usable.
Synthetic examples are model-generated prompts or answers reviewed before use, and their value has been measured. Self-Instruct bootstrapped GPT-3 from 175 seed instructions into 52K instructions and 82K instances. A candidate was admitted only when its ROUGE-L similarity to every existing instruction was below 0.7. Wang and co-authors report the result in their abstract: "Applying our method to the vanilla GPT3, we demonstrate a 33% absolute improvement over the original model on Super-NaturalInstructions, on par with the performance of InstructGPT-001, which was trained with private user data and human annotations." The remaining distance to that human-annotated baseline was 5% absolute.
So synthetic generation expands rare combinations quickly and cheaply. It needs an explicit near-duplicate filter to stay usable at all. And it can reproduce the generator's blind spots — which is exactly what Gudibande and colleagues measured when imitation of ChatGPT outputs transferred style without factuality. Synthetic data earns a place in the mixture. It should not dominate the evidence base.
Expert-written examples
High-control demonstrations created for the intended policy.
- Clear rationale and provenance
- Expensive and slow to scale
- Can overrepresent idealized prompts
- Need disagreement and adjudication
Historical interaction logs
Real wording and operational diversity from deployed workflows.
- Capture authentic user behavior
- Contain stale policy and privacy risk
- Reflect prior system selection effects
- Require redaction and reconstruction
Synthetic examples
Model-generated prompts or answers reviewed before use.
- Expand rare combinations quickly
- Can reproduce generator blind spots
- Need independent validation
- Should not dominate the evidence base
Key idea
The loss mask is a measured design variable, not a data-loader default
A conversational record can include system instructions, user input, retrieved evidence and assistant output. The loss mask decides which of those the model is trained to produce, so it should match the learning objective. Train accidentally on user or tool text and you teach the model to imitate roles it should only condition on. The right mask depends on the format and the model. Verify it with token-level tests rather than assuming it from a data-loader setting.
Supervising only the response tokens is a convention, and an open empirical question. Shi and co-authors applied the loss to the instruction and prompt as well as the output, and report: "Through experiments across 21 diverse benchmarks, we show that, in many scenarios, IM can effectively improve the LM performance on both NLP tasks (e.g., MMLU, TruthfulQA, and HumanEval) and open-ended generation benchmarks (e.g., MT-Bench and AlpacaEval)." In the most advantageous case they raised AlpacaEval 1.0 performance by over 100%.
The size of the benefit was governed by two properties of the dataset: the instruction-to-output length ratio and the number of training examples. Both are things you can measure in your own corpus before choosing a mask.
A mislabeled loss mask can train the model to reproduce context instead of respond to it — and the correct mask is an experiment, not a setting.
Steps
Build an SFT dataset with release discipline
Treat the dataset as a versioned product artifact. Step 1, define behaviors and exclusions: write what the model should do, refuse, clarify and escalate. Step 2, sample the real distribution, covering ordinary, rare, adversarial and ambiguous requests. Step 3, create and review targets with domain experts, recording acceptable alternatives. Step 4, deduplicate and split so that near-duplicate examples cannot leak into evaluation. Step 5, verify formatting and masks by testing tokenization, role boundaries, truncation and loss application. Step 6, run broad regressions measuring target gains, style drift, multilingual behavior and safety tradeoffs.
Steps 2 and 4 are not aspirational. Ouyang and co-authors documented exactly these controls for InstructGPT: "We heuristically deduplicate prompts by checking for prompts that share a long common prefix, and we limit the number of prompts to 200 per user ID. We also create our train, validation, and test splits based on user ID, so that the validation and test sets contain no data from users whose data is in the training set. To avoid the models learning potentially sensitive customer details, we filter all prompts in the training split for personally identifiable information (PII)." Deduplication, a per-user cap, user-level splitting and PII filtering — written down as part of the dataset description.
The cost of skipping step 4 has been quantified. C4 contained a single 61-word English sentence repeated over 60,000 times. Over 1% of unprompted model output was copied verbatim from training data. Deduplication cut memorized emissions tenfold. On the evaluation side, Lee and co-authors are specific: "We can also reduce train-test overlap, which affects over 4% of the validation set of standard datasets, thus allowing for more accurate evaluation." Over 4% of a validation set is a number large enough to decide a launch.
Step 6 is where fine-tuning stops being a local edit. Qi and co-authors report: "For instance, we jailbreak GPT-3.5 Turbo's safety guardrails by fine-tuning it on only 10 such examples at a cost of less than $0.20 via OpenAI's APIs, making the model responsive to nearly any harmful instructions." Ten examples and twenty cents. The result that matters more for ordinary teams is the second one: fine-tuning on benign, commonly used datasets also degraded safety alignment, with no malicious intent anywhere in the process. A regression suite is what stands between an ordinary SFT run and that outcome.
1. Define behaviors and exclusions
Write what the model should do, refuse, clarify, and escalate.
2. Sample the real distribution
Cover ordinary, rare, adversarial, and ambiguous requests.
3. Create and review targets
Use domain experts and record acceptable alternatives.
4. Deduplicate and split
Prevent near-duplicate examples from leaking into evaluation.
5. Verify formatting and masks
Test tokenization, role boundaries, truncation, and loss application.
6. Run broad regressions
Measure target gains, style drift, multilingual behavior, and safety tradeoffs.
SFT is strongest when the desired behavior can be demonstrated
Supervised examples work well for formats, procedures, tone and task-specific response patterns. Those are the properties that transferred cleanly in every study above, including in the imitation models whose style convinced human raters. They are weaker when the desired behavior depends on unstable facts, or on preferences that are difficult to express as one ideal answer. That is where the same imitation models closed little to none of the gap, and where a benign dataset can quietly move safety behavior.
The next lesson examines preference data and reward models. Those methods compare alternatives instead of requiring a single canonical response. Note that in InstructGPT the reward-model corpus was the larger of the two: 33k training prompts against about 13k demonstrations.
Key takeaways
- SFT increases the probability of demonstrated response patterns under the chosen data and loss mask. InstructGPT's set was about 13k training prompts written by roughly 40 contractors, and the 1.3B tuned model was preferred by human raters to the 175B GPT-3.
- Demonstration quality includes current policy, provenance, coverage, privacy and acceptable alternatives. OpenAssistant Conversations carries 461,292 quality ratings over 161,443 messages in 35 languages, from over 13,500 volunteers.
- Historical logs, expert examples and synthetic data contribute different strengths and risks. Self-Instruct turned 175 seed instructions into 52K instructions and 82K instances for a 33% absolute gain on Super-NaturalInstructions, still 5% absolute short of InstructGPT-001.
- Role formatting, tokenization, truncation and loss masking require token-level tests, and the mask itself is empirical. Supervising instructions as well as outputs across 21 benchmarks raised AlpacaEval 1.0 by over 100% in the most advantageous case, governed by the instruction-to-output length ratio and the number of training examples.
- Near-duplicate examples leak into evaluation and exaggerate generalization. Train-test overlap affects over 4% of the validation sets of standard datasets, and deduplication cut memorized emissions tenfold.
- A successful SFT release must show target gains without unacceptable broad regressions. Crowd raters passed imitation models whose factuality had not improved, and fine-tuning on 10 examples for under $0.20 stripped GPT-3.5 Turbo's guardrails — while benign datasets degraded safety too.