Concepts / Preparing a Dataset for Instruction Fine-Tuning

Preparing a Dataset for Instruction Fine-Tuning

Once a model has been instruction fine-tuned, the natural next question is whether it actually got better.

  • Programming

Asking Whether the Model Actually Improved

Once a model has been instruction fine-tuned, the natural next question is whether it actually got better. This article is about the stage where that question gets answered. Before any training happens, the instruction data has to be ready, and after training, the fine-tuned model's responses have to be judged. The two tasks named in this article, preparing a dataset and organizing instruction data in training batches, both concern the instruction data used in fine-tuning. The judging step, automated evaluation, comes at the very end of the overall process.

What do you think happens?

Suppose you take three answers from the fine-tuned model, read them carefully, and decide the model is doing well. What can you safely conclude?

  • The model performs well across all of its questions

  • You have a rough feeling for performance, and nothing more

  • The model will perform well on the next thousand questions

Reveal answer
Answer:

You have a rough feeling for performance, and nothing more

Three answers cannot show how often the model fails, which kinds of questions it struggles with, or whether a change you made helped or hurt. Reading three responses gives a impression, not a measurement.

Why Reading Samples by Hand Breaks Down

The early approach to checking a fine-tuned model was to take a handful of examples from the test set, look at what the model wrote in response, and judge the quality by eye. In the material this article draws on, that approach was limited to three examples.

The problem is not only that three examples are few. Three answers cannot tell you how often the model fails, which kinds of questions it struggles with, or whether a change you made last week helped or hurt. The method also does not scale. Reading hundreds or thousands of responses by hand is slow, tiring, and hard to repeat consistently from one review to the next. A judgment that depends on how tired the reader is at the time is not a dependable way to compare two versions of a model.

Key point

Reading a few sample responses by hand gives only a rough idea of performance. It does not scale to larger numbers of responses, and it cannot by itself show failure rates or whether one version is better than another.

Handing the Scoring Job to a Second LLM

The solution the source develops is to let another, larger LLM do the scoring. In automated evaluation, the fine-tuned model writes responses to the test set questions, and a second model reads each response and assigns it a score. The second model does not need to be trained for this job in the course of the evaluation. It is an already trained model that is used only to read responses and score them.

The second model is described as larger, and that choice matters for the design. The evaluator needs to be at least as capable as the thing it is judging. If the judge is weaker than the model it scores, its scores would not carry much meaning. This is why the source moves from a small local model to a larger one when it discusses the options later on.

Test set questionsFine-tuned modelModel responsesEvaluator LLMlarger, scores theresponsesScoresasked ofwritesread byproduces
How a response travels from the fine-tuned model to the evaluator and then to a score. The steps are the same whichever evaluator you choose; only the evaluator box changes.

Compare this with manual sampling. Manual sampling has a person in the loop for every response, which is why it stalls at a few examples. In the automated version, the person designs the test set and reads the resulting scores, while the evaluator reads the responses. The same flow can be repeated on a larger set of responses without the reader being the bottleneck.

Where Evaluation Fits in the Three Stages

Instruction fine-tuning is organized as a three-stage process. The first stage prepares the dataset. The second stage fine-tunes the LLM. The third stage evaluates it. Automated evaluation belongs to the third stage. The source lays out nine numbered steps for the full process and shows which stage each one falls under, but the individual preparation steps are outside the scope of this article.

Prepare the datasetFine-tune the LLMEvaluate the modelautomated evaluationready datafine-tuned model
The three stages in order. Dataset preparation comes first, training comes second, and automated evaluation is the final stage.

The source states the purpose of the third stage directly. Once the fine-tuned model has produced its responses, the goal is to quantify its performance by scoring those responses for the test set. This means the evaluator is not an extra add-on bolted onto the end of the work. It is the last step in the same pipeline that began with preparing the data.

Choosing Where the Evaluator Runs

The source develops the evaluator in two forms. The first version uses an existing instruction-fine-tuned 8-billion-parameter Llama 3 model developed by Meta AI. The second option uses a larger proprietary model. Each form has a different place where the evaluator runs and a different path the data takes.

Preparing a Dataset Versus Organizing Batches

Preparing a dataset sits inside supervised instruction fine-tuning. Supervised instruction fine-tuning is a process that trains a model using instruction data, and before that training can happen, the data has to be ready. Organizing instruction data in training batches is a related but separate task. It concerns how instruction data is arranged for training. Both tasks concern the same instruction data, but they are not the same job.

AspectPreparing a datasetOrganizing instruction data in training batches
Relationship to fine-tuningA step within supervised instruction fine-tuningA related task that concerns how instruction data is arranged
What it operates onThe instruction data as a wholeThe instruction data, as it is arranged for training
What it establishesThe readiness of the data before trainingThe arrangement of that data into batches used for training
Position in the illustrationComes before batch organizationComes after preparation

Two related tasks that both concern the instruction data used in fine-tuning. The source does not describe the preparation steps or any particular batching method.

Following the Data Through Each State

The easiest way to see how the two tasks relate is to follow the instruction data as it moves through them. The diagram below traces its state at each point. It shows the order given in the source's illustration, with preparation before batch organization, and it does not imply any order beyond that.

Instruction datacollectionPrepared datasetBatched instructiondataprepareorganize into batches
The collection of instruction data as it moves from preparation into batch organization. Each step changes what the data is ready for, not its content.

Read the diagram carefully. The first transition moves the collection from a raw state into a prepared state, which is the readiness that dataset preparation establishes. The second transition takes that prepared data and arranges it for training in batches. Neither transition, as the source describes it, is a training step, and neither is the evaluation stage that comes last.

Worked Trace of a Small Evaluation Run

Worked example

Scoring a test set instead of three sample answers

A developer wants to know whether a fine-tuned model improved. The developer has a test set of 500 questions. Reading three answers by hand would be the old method. Describe how the automated evaluation handles the full set. The numbers here are illustrative and are not from the source.

  1. 1
    Ask the test set questions

    The fine-tuned model writes a response to each of the 500 questions, producing 500 responses.

  2. 2
    Pass each response to the evaluator

    The evaluator, a second LLM such as the local Llama 3 8B model running through Ollama, reads each response.

  3. 3
    Collect the scores

    The evaluator assigns a score to each response, so the developer has a score for every item in the test set rather than three impressions.

  4. 4
    Read the aggregate

    Because every response has a score, the developer can see how often the model does poorly and compare the result with an earlier version, which the three-answer method could not show.

Result

The same flow handles 500 responses as easily as three, and the result is a set of scores that can be compared across versions.

Mistakes Beginners Make With the Evaluation Stage

  • Common mistake

    Treating a few hand-read answers as proof that the model improved

    Why it fails

    Three answers give a rough feeling only. They cannot reveal failure rates or which question types cause trouble.

    Do this instead

    Score the full test set with an evaluator so the results can be counted and compared.

  • Common mistake

    Choosing an evaluator that is weaker than the model it judges

    Why it fails

    The evaluator needs to be at least as capable as the thing it is judging, or its scores carry little meaning.

    Do this instead

    Pick an evaluator with at least the capability the source calls for, and move to a larger model such as GPT-4 through the OpenAI API when the local model is not enough.

  • Common mistake

    Assuming Ollama can also train or fine-tune the model

    Why it fails

    Ollama is a tool for inference and does not support training or fine-tuning.

    Do this instead

    Use Ollama only to run the evaluator, and keep training as a separate stage.

  • Common mistake

    Treating automated evaluation as an optional extra after the pipeline

    Why it fails

    Evaluation is the third stage of the same three-stage process that begins with preparing the dataset.

    Do this instead

    Plan the evaluation stage from the start, since it is the last step in the same pipeline.

  • Common mistake

    Using the words preparing a dataset and organizing batches as if they were the same task

    Why it fails

    Preparation establishes readiness of the instruction data, while batch organization concerns how that data is arranged for training.

    Do this instead

    Keep the two tasks separate in your notes, even though both concern the same instruction data.

Checking Your Understanding of the Pipeline

MEDIUM

A teammate says that automated evaluation is an optional extra that can be added after the fine-tuned model is delivered. Using the three-stage process, explain why this is not how the source frames it, and state where dataset preparation fits.

Hints
  • Look at which stage automated evaluation belongs to in the three-stage process.
  • Think about what the evaluation stage does with the responses the fine-tuned model has produced.
  • Dataset preparation is the first stage, so it comes before fine-tuning and evaluation.

Key Takeaways

  • Reading a few sample responses by hand gives only a rough idea of performance and does not scale, so a larger LLM can take over the scoring job.
  • Instruction fine-tuning has three stages: prepare the dataset, fine-tune the LLM, and evaluate it. Automated evaluation is the final stage of that pipeline.
  • The 8-billion-parameter Llama 3 model can run locally through Ollama as the evaluator, which keeps test set responses on your machine, while GPT-4 through the OpenAI API offers a stronger judge at the cost of sending responses to a web service.
  • Preparing a dataset is a step within supervised instruction fine-tuning, while organizing instruction data in training batches is a related task that concerns how the same data is arranged for training.

Related concepts

More concepts starting with P