Preparing Instruction Datasets
Stage 1 produces the dataset. Nothing can be trained until this stage is complete.
Why a Language Model Needs Instruction Training
Suppose you hand a language model a request such as 'Convert 45 kilometers to meters.' You want the model to respond with the answer, not with some loosely related continuation of the text. Instruction fine-tuning is the process built for exactly this purpose. Its aim is to strengthen an LLM's ability to follow an instruction and produce the response that a person actually wants.
What do you think happens?
What would a model need in order to learn to answer instructions instead of continuing text? Where would its examples of good responses come from, and how would you know whether its answers had improved?
Reveal answer
It needs examples of instructions paired with good responses, and a way to judge its answers after training.
The source frames the rest of the process around those two questions: where the examples come from, and how improvement is checked. The process is organized to answer them in order, from dataset to training to evaluation.
What Instruction Fine-Tuning Changes
The goal is not just any output. The desired response is the specific answer a careful person would give to that instruction. Instruction fine-tuning is the work of making a model's outputs look more like these targeted answers. Compared with a model that only continues text, a fine-tuned model is pushed toward responding to the instruction itself.
The before side of the diagram describes the behavior instruction fine-tuning is meant to move away from. The after side describes the behavior it is meant to produce: a response that fulfills the instruction.
Examples of Desired Responses
Fine-tuning needs examples of the behavior you want. Each example pairs an instruction with a response that fulfills it. The source offers three illustrative pairs that show the range of tasks such data can cover.
| Task type | Instruction | Desired response |
|---|---|---|
| Unit conversion | Convert 45 kilometers to meters. | The answer to the conversion, not loosely related text |
| Synonym request | Provide a synonym for bright. | A word such as radiant |
| Sentence rewrite | Rewrite a sentence without passive voice. | The artist composed the song. |
Three instruction-response pairs from the source, showing the range of tasks covered
The Three Stages and Their Nine Steps
The process is organized into three stages, carried out as nine steps in order. Stage 1 prepares the dataset that will be used for training. Stage 2 sets up a model and fine-tunes it on that dataset. Stage 3 evaluates the fine-tuned model. Read the structure as one line of work split into three blocks: the first turns raw material into a usable dataset, the second changes the model using that dataset, and the third asks whether the change was worthwhile.
Stage 1: Preparing the Dataset
The first stage begins with the data. Its job is to obtain the instruction dataset, look at it, and arrange it so that a training process can consume it. Within this stage the work proceeds through three steps. Taken together, they download, format, batch, and load the instruction-response pairs.
The dataset used in this process contains 1,100 instruction-response pairs of the kind shown above. The source notes that this dataset was created for the course text itself, and that readers who want other publicly available instruction datasets can find alternatives in appendix B of the course text.
Stage 1 produces the dataset. Nothing can be trained until this stage is complete.
Stage 2: Loading and Fine-Tuning the Model
The second stage takes the prepared dataset and applies it to a model. Two actions define it. First, a pretrained LLM is loaded. Second, that model is instruction fine-tuned on the prepared dataset. Stage 2 cannot begin until stage 1 has produced the dataset, which is why the three stages are presented in order.
Step 4 loads the pretrained LLM and establishes the starting model. Step 5 instruction fine-tunes that model, adjusting it using the instruction-response pairs. Step 6 inspects the loss, which lets you check how training is progressing as the adjustment runs. Stage 2 is the point where the data from stage 1 actually changes the model's behavior.
Stage 3: Evaluating the Fine-Tuned Model
Once the model has been fine-tuned, the question becomes whether it is actually better at following instructions. Stage 3 answers that question through three steps. Step 7 extracts responses: the fine-tuned model is run to produce its answers. Step 8 is qualitative evaluation, which means reading and judging those answers. Step 9 scores the responses, turning the judgment into a score.
The order inside stage 3 matters. Evaluation looks at responses the model has actually produced, so it depends on stage 2 having finished. Qualitative reading comes before scoring, so the numbers are attached to answers someone has already examined.
Tracing One Instruction Through the Pipeline
To see how the stages connect, follow a single instruction, 'Provide a synonym for bright,' through the process. The walkthrough below is an original illustration built from the same pattern as the source's examples. It is not a result the source reports.
Following 'Provide a synonym for bright' Through the Pipeline
Trace what happens to one instruction-response pair from raw data to a scored response, and what each stage contributes.
- 1Stage 1 entry
The pair pairs the instruction 'Provide a synonym for bright' with a desired response such as 'radiant'. Stage 1 obtains, formats, batches, and loads this pair with the rest of the dataset so training can consume it.
- 2Stage 2 training
A pretrained LLM is loaded in step 4. In step 5 it is instruction fine-tuned on the prepared pairs, which includes this one, so the model is adjusted toward answering synonym requests with a targeted word. Step 6 lets you watch the loss while this adjustment runs.
- 3Stage 3 evaluation
In step 7 the fine-tuned model is run on the synonym instruction to produce its answer. In step 8 someone reads that answer and judges whether it fulfills the request. In step 9 the judgment becomes a score.
Each stage contributes something the next one needs: stage 1 supplies the examples, stage 2 changes the model using them, and stage 3 checks whether the change shows up in an actual answer.
Why Stage Order Cannot Be Swapped
What do you think happens?
If you tried to evaluate responses before any fine-tuning took place, what would you be evaluating?
Reveal answer
You would be evaluating a model that has not been instruction fine-tuned on the prepared dataset, so the evaluation would not measure the effect of fine-tuning.
Stage 3 examines responses the model has actually produced after stage 2, so the evaluation depends on fine-tuning having happened first.
Common Misreadings of the Pipeline
Common mistake Treating the nine steps as unordered tasks
What it looks likeScoring responses before anyone has read them
Why it failsQualitative reading comes before scoring so that the numbers are attached to answers someone has already examined.
Do this insteadKeep steps 8 and 9 in that order, after the model has produced responses in step 7.
Common mistake Believing the dataset is the same thing as the trained model
Why it failsStage 1 only prepares instruction-response pairs. The model changes in stage 2, when a pretrained LLM is fine-tuned on that dataset.
Do this insteadTrack the dataset and the model as separate artifacts that stage 2 connects.
Common mistake Assuming any output counts as a desired response
Why it failsThe desired response is the specific answer a careful person would give to the instruction.
Do this insteadJudge training data by whether each response actually fulfills its instruction.
Common mistake Skipping evaluation because training ran without errors
Trace Your Own Instruction
Choose a new instruction, such as 'Convert 10 kilometers to meters,' and write a desired response for it. Then trace that pair through the pipeline: name what stage 1 does with it, what stage 2 changes, and how stage 3 would check the result. Finally, explain why the evaluation could not happen before stage 2 finished.
Hints
- Start from the instruction-response pair, since that is what stage 1 prepares.
- Stage 2 changes the model, so think about what the model learns from the prepared pairs.
- Stage 3 needs responses the model has actually produced after training.
Key Takeaways
- Instruction fine-tuning aims to improve an LLM's ability to follow instructions and produce the response a person actually wants.
- The process has three stages carried out as nine ordered steps: dataset preparation, model setup and fine-tuning, and evaluation.
- Stage 1 prepares instruction-response pairs, stage 2 loads a pretrained LLM and fine-tunes it, and stage 3 extracts, qualitatively reads, and scores the responses.
- Each stage depends on the one before it, so the order of the three stages matters.