Concepts / Supervised Finetuning in Practice

Supervised Finetuning in Practice

Finetuning is any training that happens after pre-training, so it can take several forms rather than one fixed procedure.

  • Programming

Why a General Model Needs More Training

Imagine you are building an application that answers legal questions. You have access to a model that was already trained on a very large body of data, and you want it to behave well on your task. The model knows a great deal about language in general, but it was not built with legal questions in mind. What should you do with it?

This is the situation that the different types of finetuning are meant to address. Each type answers a slightly different version of the same question: what kind of data do you have, and what do you need the model to do with it? Before comparing the types, it helps to be clear about where they all begin, which is with transfer learning.

What do you think happens?

Suppose your legal application has a collection of (question, answer) pairs written by lawyers. Which finetuning type fits this data best?

  • Self-supervised finetuning on unlabeled legal text

  • Supervised finetuning on (input, output) pairs

  • Infilling finetuning on text with gaps

Reveal answer
Answer:

Supervised finetuning on (input, output) pairs

Supervised finetuning trains on (input, output) pairs to align the model with human usage and preference. Question-and-answer pairs are exactly that kind of data, so this is the type the data supports most directly.

Finetuning Continues Pre-training

Pre-training usually relies on self-supervision, which lets a model learn from a large amount of unlabeled data. For language models, that data is typically just sequences of text that need no annotations. Finetuning then adjusts the pre-trained model so it fits a specific task. Seen this way, finetuning is part of the same training process, extended into a later stage rather than a separate procedure.

Because finetuning can happen in several stages, the path from a general model to a task-ready model can pass through more than one kind of finetuning. A common path places a self-supervised stage first and a supervised stage after it. The order matters, and the rest of this article explains why.

Pre-trainingself-supervised onunlabeled textSelf-supervisedfinetuningtask-related data,continued pre-trainingSupervised finetuning(input, output) pairsTask-ready modelaligned with human usagethenthenproduces
How does one training run flow from pre-training into finetuning, and where do the data and the training objective change along that sequence?

Read the timeline from left to right. The training objective and the data both change at the boundaries. Pre-training works from large amounts of unlabeled text. The self-supervised finetuning stage keeps learning from unlabeled sequences, but those sequences now come from the domain you care about. The supervised stage switches to annotated (input, output) pairs. Each stage starts from the weights left by the previous one, which is why finetuning is best understood as a continuation rather than a fresh start.

Feature-Based Transfer Versus Finetuning

Transfer learning means taking a model trained for one purpose and using it for a different task. Finetuning is one way to do this, but it is not the only way. A second approach is feature-based transfer. In this approach, a model is trained to extract features from the data, usually in the form of embedding vectors. Those vectors are then passed to another model that does the actual task.

The key contrast is between reusing an output and reusing a model. In feature-based transfer, the feature extractor produces representations and the downstream model consumes them. The source describes this pattern as very common in computer vision, where models trained on the ImageNet dataset were widely used to extract image features for tasks such as object detection and image segmentation.

Pre-trained featureextractorproduces embedding vectorsPre-trained modelweights from pre-trainingEmbedding vectorsreused as input featuresFurther trainingthe model itself is trainedmoreDownstream modelconsumes the vectorsAdapted modelsame model, updated for thetaskoutputsfeedscontinuesyields
Which parts of the pre-trained network are reused as they are, and which parts receive further training in each approach?

Self-Supervised Finetuning as a Preparation Stage

Self-supervised finetuning means finetuning a model with self-supervision, using task-related data. It is also called continued pre-training. It is useful because it can happen before finetuning with expensive task-specific data. The idea is to first move the model toward the domain you care about, using data that is plentiful and inexpensive, and only then spend the cost of annotated examples.

Worked example

Preparing a model for Vietnamese book summarization

You want a model to summarize books written in Vietnamese. Annotated summaries are expensive to produce, but large collections of Vietnamese text are easy to gather. How should the stages be ordered?

  1. 1
    Identify the cheap data

    A large collection of Vietnamese text needs no annotations. It is task-related because it is in the language and domain of the target task.

  2. 2
    Run the self-supervised stage first

    Finetune the model on this text. The model moves toward Vietnamese and away from being only a general language model.

  3. 3
    Add the task-specific stage

    Only after that spend the cost of annotated examples for the summarization task itself.

Result

The self-supervised stage prepares the model before the task-specific stage, so the expensive annotated data is used on a model that already fits the domain.

Supervised Finetuning on Input-Output Pairs

Supervised finetuning uses high-quality annotated data to refine the model. During supervised finetuning, the model is trained on (input, output) pairs. The input can be an instruction and the output can be a response. The purpose of this stage is to align the model with human usage and preference.

The reason this stage matters is that a model trained on very large amounts of data learns a rich understanding of the world, but that knowledge may be difficult for users to draw out for their tasks. The way the model behaves may also differ from what people prefer. Supervised finetuning addresses this gap by showing the model examples of the kind of input and response that people want.

Worked example

Building supervised pairs for the legal application

Your legal application needs the model to answer questions the way a careful lawyer would. What does a supervised training example look like?

  1. 1
    Choose the input

    The input is a legal question a user might ask, such as a question about a tenant's notice period.

  2. 2
    Choose the output

    The output is a response written the way you want the model to respond, clear and careful in tone.

  3. 3
    Assemble the pairs

    Each training example is one (input, output) pair. A large set of such pairs teaches the model the input-to-response behavior you want.

Result

The model learns the expected behavior from examples of the desired input and response, which is the purpose of supervised finetuning.

Infilling Finetuning and Masked Spans

Language models can be autoregressive or masked. An autoregressive model predicts the next token in a sequence, using the previous tokens as its context. A masked model fills in the blank, using the tokens both before and after the gap. Finetuning can target either behavior. With supervised finetuning, you can train a model to predict the next token or to fill in the blank.

Finetuning a model to fill in the blank is called infilling finetuning. The source says it is especially useful for tasks such as text editing and code debugging, since both involve changing a part of a text while keeping the surrounding material. In each case the model sees the text on both sides of the part being changed, and must produce the missing span.

Comparing the Three Finetuning Types

The three types differ mainly in the kind of data they use. Supervised finetuning uses explicit (input, output) pairs. Self-supervised finetuning uses task-related sequences of text that need no annotations. Infilling finetuning uses text in which a span is masked, so the model must fill the gap from the surrounding tokens.

(input, output) pairsexplicit annotated examplesTask-related textsequences needing noannotationsText with a maskedspantokens before and after thegapInstruction andresponsealigns with humanpreferenceContinuedpre-trainingoften before annotated dataText editing and codedebuggingreplace a part, keep theresttrains ontrains ontrains on
How do the training examples differ across the three finetuning types: which have explicit labels, which use text without annotations, and which mask a span to be filled in?
Finetuning typeData it usesTypical purpose
SupervisedExplicit (input, output) pairsAlign the model with human usage and preference
Self-supervised (continued pre-training)Task-related text with no annotationsMove the model toward a domain before annotated data
InfillingText with a masked span and its surrounding tokensFill in or change a part while keeping the rest, such as text editing or code debugging

The three finetuning types and the data each one uses

Choosing a Finetuning Type from Your Data

The choice starts with the data you have, not with the type you like best. Ask whether you have explicit (input, output) pairs, whether you have plentiful task-related text without annotations, or whether your task is to change a part of a text while keeping the rest. The flowchart below follows that reasoning.

Labeled (input,output) pairs?Supervised finetuningalign with human usageInfilling finetuningtext editing, codedebuggingText with gaps tofill?Self-supervisedfinetuningtask-related unlabeled textyesnoyesno
Given what kind of data an application has, which finetuning type should be selected?

The flowchart is a starting point, not a rule that forbids combining stages. The source's own example chains them: a self-supervised stage on a large body of Vietnamese text can come before the task-specific stage. When cheap task-related data is plentiful and annotated data is scarce, it is reasonable to begin with self-supervised finetuning and reserve annotated examples for the later supervised stage.

Mistakes When Selecting a Finetuning Type

  • Common mistake

    Treating feature-based transfer and finetuning as the same thing

    What it looks like

    Taking embedding vectors from a pre-trained model and training a small classifier on them, then calling this finetuning.

    Why it fails

    In feature-based transfer, the extractor's output is reused and another model consumes it. Finetuning trains the pre-trained model further.

    Do this instead

    Ask whether the pre-trained model itself receives further training. If it does, you are finetuning.

  • Common mistake

    Spending annotation budget before preparing the model

    What it looks like

    Writing expensive annotated summaries for a Vietnamese summarization task before any domain adaptation.

    Why it fails

    Self-supervised finetuning can happen before expensive task-specific data, and it uses plentiful, inexpensive text to move the model toward the domain.

    Do this instead

    When cheap task-related text is available, consider a self-supervised stage first, then spend annotations on the supervised stage.

  • Common mistake

    Assuming an autoregressive pre-training objective rules out infilling

    What it looks like

    Deciding not to use infilling for a code debugging tool because the base model was pre-trained to predict the next token.

    Why it fails

    The pre-training objective does not lock the model into one kind of prediction. Infilling finetuning can be applied to an autoregressively pre-trained model.

    Do this instead

    Choose the finetuning type from the task and the data, then train the model for that behavior.

  • Common mistake

    Using self-supervised finetuning when you actually have labeled (input, output) pairs and need the model to match a specific response style

Matching Your Data to a Finetuning Type

MEDIUM

A team has three datasets. Dataset A contains customer questions paired with approved replies. Dataset B contains thousands of unlabeled support-desk transcripts from the same product domain. Dataset C contains product descriptions where some words have been removed and the model must restore them. For each dataset, name the finetuning type that fits, and explain which stage should come first if the team wants to use all three datasets.

Hints
  • Look for explicit (input, output) pairs first. Dataset A is the clearest case.
  • Self-supervised finetuning uses task-related data that needs no annotations, which describes Dataset B.
  • A masked span with the surrounding text on both sides points to infilling finetuning.
  • Consider the source's point that self-supervised finetuning can come before expensive annotated data.

Key Takeaways

  • Finetuning is any training that happens after pre-training, so it extends the same training process into a later stage rather than starting a separate one.
  • Feature-based transfer reuses the outputs of a feature extractor, while finetuning trains the pre-trained model itself further.
  • Supervised finetuning uses (input, output) pairs to align a model with human usage and preference, self-supervised finetuning uses task-related unlabeled text and can come first, and infilling finetuning trains the model to fill a masked span.
  • Choose the finetuning type from the data you have: labeled pairs point to supervised finetuning, plentiful task-related text points to self-supervised finetuning, and text with gaps points to infilling finetuning.

Related concepts

More concepts starting with S