Skip to content
ImagineWorld

Preparing Fine-Tuning Datasets

node_idnode-book_llm-systems-engineering_module-27-preparing-fine-tuning-datasets
node_typechapter-node
schema_profileworld.chapter_node.v1
statusactive
entropyhigh
manifoldworld
domainimagineworld.net
authorityinforms
layercorpus
chapter_num27
chapter_titlePreparing Fine-Tuning Datasets
governed_byCORPUS
constitutional_citationCONSTITUTION
local graph

Module 27 — Preparing Fine-Tuning Datasets

Section titled “Module 27 — Preparing Fine-Tuning Datasets”

The preparation of data used in fine-tuning demands care that looks quite different from the pipelines used to assemble pretraining corpora. A fine-tuning dataset is a compact set of carefully constructed examples whose every row shapes how the model will respond. Small errors in formatting or labeling propagate rapidly through learned behavior because the training signal is concentrated. This module examines what distinguishes fine-tuning data from pretraining data and how to construct sets of examples that reliably induce the target behavior. It also considers the boundary between a dataset that is rich enough to generalize and one that is narrow enough to cause regression on capabilities the base model already possessed.

How Fine-Tuning Data Differs from Pretraining Data

Section titled “How Fine-Tuning Data Differs from Pretraining Data”

Pretraining corpora are measured in trillions of tokens, assembled from broad web crawls and reference collections whose primary virtue is scale. Fine-tuning data operates on a different principle. Its purpose is behavioral shaping, which means that each example contributes a meaningful fraction of the signal reaching the model’s weights.

This change in purpose reshapes every step of the data pipeline. Deduplication, which in pretraining is about removing near-duplicate web pages to reduce wasted compute, becomes in fine-tuning a concern about overrepresented patterns that could cause the model to parrot specific phrasings. Filtering, once driven by heuristic quality signals applied across massive corpora, becomes a matter of careful human judgment applied example by example. The quality of instruction examples correlate more strongly with downstream evaluation performance than the raw count of examples, which reinforces the view that fine-tuning rewards precision over volume.

flowchart TB
    subgraph P[Pretraining pipeline]
        direction TB
        P1["Source collection<br/>Broad web crawls, references"] --> P2["Deduplication<br/>Drop near-duplicate pages"] --> P3["Heuristic filtering<br/>Automated quality signals"] --> P4["Pretraining corpus<br/>Scale drives the signal"]
    end
    subgraph F[Fine-tuning pipeline]
        direction TB
        F1["Source curation<br/>Hand-picked instruction examples"] --> F2["Deduplication<br/>Guard against parroted phrasings"] --> F3["Example-by-example review<br/>Human judgment per item"] --> F4["Fine-tuning dataset<br/>Each example shapes weights"]
    end

Figure 5-2. Pretraining and Fine-Tuning Data Pipelines Compared

The dominant unit of fine-tuning data is the prompt-response pair. A prompt encodes what the user wants, and the response encodes how the model should reply. Mishra et al. (2022) framed this format as a way to teach models to generalize across tasks by reading task descriptions expressed in natural language. When the pretrained model sees thousands of these pairs during fine-tuning, it learns to treat the prompt as a conditional input and to produce text that resembles the response distribution.

Good instruction data has properties that practitioners learn to recognize through inspection. The prompt should be unambiguous, containing enough context for the desired response to be well-defined. The response should be accurate at the level of facts it contains and appropriate in length relative to the question. Its style should match the behavior the model is meant to exhibit at inference time. Wei et al. (2022) showed that instruction-tuned models generalize to tasks whose instructions they have never seen before, and the effect depends on the diversity of instruction phrasings present during training.

Formatting decisions (Module 19) propagate directly into deployed behavior. If a dataset encodes every response with a polite preamble such as “Certainly, here is the information you requested,” the fine-tuned model will produce that preamble at inference time even when it is unhelpful. If chain-of-thought reasoning is embedded inside responses using a particular delimiter, the model will reproduce that delimiter. Longpre et al. (2023) documented how variations in the template used to wrap instructions in the Flan Collection produced measurable differences in downstream evaluation, underscoring that the visible surface of each example becomes part of the learned behavior. For multi-turn chat models, the chat template separating system messages from user and assistant messages is itself a piece of format that must be applied consistently during training so that the model produces the correct boundary tokens during generation.

Single instruction example

SegmentContentLoss
System message“You are a helpful assistant.”Masked — context only, no gradient
User prompt“Translate ‘hello’ to French.”Masked — conditional input, no gradient
Assistant response“Bonjour.”Loss applied — tokens contribute, gradients flow
Boundary tokensChat template separators applied identically at training and inference—

Figure 5-3. Loss Masking and Boundary Tokens in an Instruction Example

Sourcing and Constructing Fine-Tuning Examples

Section titled “Sourcing and Constructing Fine-Tuning Examples”

Several paths exist for assembling instruction data, and each carries its own quality trade-offs. Human-authored examples, written by domain experts or trained annotators, produce the highest-fidelity data because each response reflects a considered judgment about what the model should say. Ouyang et al. (2022) described how OpenAI’s early instruction-tuning work for InstructGPT relied heavily on labelers who wrote prompts and demonstrations according to detailed guidelines, and the resulting dataset produced substantial improvements in helpfulness ratings. The cost of this approach is real. Labeler throughput is limited by human reading speed, and quality varies across annotators in ways that require ongoing calibration.

Model-generated data (Module 15) offers a way to expand coverage at lower cost. Wang et al. (2022) introduced Self-Instruct, a pipeline in which a capable language model is prompted to generate new instructions from a seed set of human examples, after which the model’s outputs are filtered by simple heuristics. Taori et al. (2023) applied a similar idea in the Alpaca project, using the outputs of a larger proprietary model to fine-tune a smaller open one. Honovich et al. (2023) demonstrated in their Unnatural Instructions work that synthetic instruction data could rival human-written data on several benchmarks when generated with sufficient care.

Synthetic data introduces a distinct failure mode. The generating model’s biases become embedded in the dataset, and its mistakes may pass heuristic filters while still degrading downstream performance. Human review of a sampled subset is typically needed to catch systematic errors before they are amplified during training.

Structured resources that already exist in the world provide a third source. Datasets originally assembled for classification or summarization tasks can be converted into instruction format by wrapping the original input with a task description and treating the label as the response. Chung et al.

(2024) showed in the scaled Flan work that combining many such converted datasets with chain-of-thought examples produced strong generalization across unseen tasks. The main caveat is that converted data often has a narrower surface form than naturally occurring prompts, and so models fine-tuned exclusively on such data may struggle with the informal phrasings that appear in real usage.

The question of how much fine-tuning data is enough has no single answer, because the right number depends on how far the target behavior sits from the model’s pretrained tendencies. Domain adaptation toward specialized vocabularies or reasoning patterns typically requires larger sets, with published recipes spanning from tens of thousands to a few hundred thousand examples depending on the breadth of the domain. Chung et al. (2024) observed that instruction-tuned model quality continued to improve as the number of tasks covered in the training mixture grew into the thousands, suggesting that diversity of instruction types matters increasingly once a quality floor has been met.

Coverage is the counterpart to size. A dataset that contains many examples of a single response pattern teaches the model that pattern well and provides little signal about other desired behaviors. Dong et al. (2024) surveyed instruction-tuning research and highlighted the recurring finding that narrow fine-tuning datasets cause capability regression, meaning that the model loses some of the general competence it acquired during pretraining as its weights drift toward the narrow distribution against which it is being optimized.

Practitioners manage this risk in two principal ways. Mixing a replay sample of general instruction data into the domain-specific set helps preserve broad capability across the training run. Monitoring evaluation scores on held-out general benchmarks during training reveals regression early enough to adjust the training recipe. Capping the number of epochs over the fine-tuning set is a related precaution, since Zhou et al. (2023) observed that memorization of individual examples becomes a problem well before the loss curve flattens completely. Decisions about data composition are iterative in practice, with each training run informing changes to the mix that will be used on the next attempt.