Concepts / Pre-training Language Models

Pre-training Language Models

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

  • Programming

A General Model Meets a Specific Question

Imagine you are building an application that answers legal questions. You have access to a model that has already been trained on a very large body of data. It knows a great deal about language in general, but it was not built with legal questions in mind. You want it to behave well on your task. 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 one 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?

A team has a pre-trained model and a set of labeled question-and-answer pairs for legal questions. Which kind of finetuning is the most natural first choice?

  • Supervised finetuning

  • Self-supervised finetuning

  • Infilling finetuning

Reveal answer
Answer:

Supervised finetuning

Supervised finetuning trains on (input, output) pairs, so labeled question-and-answer pairs match it directly. The other two types are driven by unlabeled text or by text with gaps, which the team does not describe having.

Two Ways to Reuse a Pre-trained Model

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.

Feature extractorpre-trained, reusedPre-trained modelstarting weightsEmbedding vectorsrepresentationsFurther trainingweights updatedNew downstream modeltrainedTask-adjusted modelsame model, new weightsproducesconsumed bytrainedyields
In feature-based transfer, the pre-trained extractor is reused to produce vectors and a new downstream model is trained on them. In finetuning, the pre-trained model itself is trained further.

Notice the difference in what is trained. Feature-based transfer reuses the feature extractor as a source of representations, and the new work happens in the downstream model that consumes them. Finetuning instead trains the pre-trained model further, so the weights that were learned in pre-training are themselves adjusted.

Finetuning as a Continuation of 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.

This is why the term finetuning covers so much ground. The source defines it as any training that happens after pre-training. Because it is defined by position in the sequence rather than by one fixed procedure, it can take several forms.

Generalpre-trainingunlabeled textSelf-supervisedfinetuningtask-related dataSupervised finetuning(input, output) pairsTask-ready modelsame weights, furthertrainedcontinuescontinuesyields
The same model weights carry forward from general pre-training through a self-supervised stage and then a supervised stage. Each stage adjusts the model that the previous stage produced.

The path from a general model to a task-ready model can pass through more than one kind of finetuning. The order matters, and the next sections explain why. Read the diagram as one continuous line of training, not as three separate projects.

Self-Supervised Finetuning: Preparing the Model First

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.

In the real world

The source gives a second case with the same structure. To finetune a model for book summarization in Vietnamese, you can first finetune it on a large collection of Vietnamese text. In both cases, the self-supervised stage prepares the model before the task-specific stage begins.

Supervised Finetuning: Aligning the Model with People

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.

Comparing the Data Each Finetuning Type Uses

The three finetuning types differ mainly in the data they consume. The table below sets them side by side, including the training signal each one relies on.

Finetuning typeData it usesWhere the training signal comes fromMain purpose
Self-supervised finetuningUnlabeled, task-related textThe text itselfMove the model toward a domain before annotated data
Supervised finetuningAnnotated (input, output) pairsThe human-written output paired with each inputAlign the model with human usage and preference
Infilling finetuningText with a part hiddenThe hidden part the model must fill inEdit text or debug code by filling gaps

Data and training signal for each finetuning type, as described in the source.

Infilling Finetuning and Hidden 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. An important point is that you can finetune a model for infilling even if it was originally pre-trained autoregressively. The pre-training objective does not lock the model into one kind of prediction.

Thevisiblereportvisible[gap]hidden, to predictwasvisibleapprovedvisible
A short sentence with one hidden position. The model sees the tokens on both sides of the gap and learns to predict the token that belongs in the gap.
Worked example

Filling a hidden position from context on both sides

The sentence The report [gap] was approved has one hidden position. Which tokens should the infilling model use to predict it?

  1. 1
    Identify the visible context

    The tokens before the gap are The and report. The tokens after the gap are was and approved.

  2. 2
    Use both sides

    A masked model fills the blank using tokens both before and after the gap, so the words on the right, was approved, constrain what can fill the gap.

  3. 3
    Predict the missing token

    A word such as draft or final fits the surrounding context, and the model is trained to produce a token of this kind in the hidden position.

Result

The model predicts a token for the hidden position using context from both directions. This is the behavior infilling finetuning trains for, and it matches the text-editing use case the source describes.

Choosing a Finetuning Type from Your Data

The data a team has determines which finetuning type fits. The flowchart below asks the questions in an order that follows from the descriptions above. Because self-supervised finetuning can come before supervised finetuning, a team with both unlabeled domain text and annotated pairs may use both, in that order.

Labeledinput-output pairs?Supervised finetuningalign with preferencesSelf-supervisedfinetuningcontinued pre-trainingInfilling finetuningediting, code debuggingUnlabeled domaintext?Text with gaps tofill?yesnoyesnoyes
Start with the kind of data you have. Labeled pairs point to supervised finetuning, unlabeled domain text points to self-supervised finetuning, and text with gaps to fill points to infilling finetuning.
MEDIUM

A team is building a tool that edits customer emails by changing one sentence at a time while keeping the rest of the email intact. They have a large set of existing emails but no annotated edits. Which finetuning type fits their data best, and why? Explain your answer using the kind of data each type uses.

Hints
  • Ask whether the team has annotated (input, output) pairs of edits.
  • Consider which type is described as useful for changing a part of a text while keeping the surrounding material.
  • The source notes that infilling finetuning suits text editing.

Mistakes When Choosing a Finetuning Type

Several errors appear often when learners first apply these ideas. Each one comes from treating finetuning as a set of separate choices rather than one training sequence with data-dependent stages.

  • Common mistake

    Treating feature-based transfer and finetuning as the same thing

    What it looks like

    A team reuses a pre-trained extractor to produce embedding vectors and then assumes they have finetuned the model.

    Why it fails

    In feature-based transfer the extractor is reused to produce representations, and the new training happens in a downstream model. Finetuning trains the pre-trained model itself further.

    Do this instead

    Ask which weights change. If the pre-trained model's weights are updated, that is finetuning.

  • Common mistake

    Assuming finetuning must be a single step

    What it looks like

    A team runs one supervised pass and skips any domain-oriented stage, even though plenty of unlabeled domain text is available.

    Why it fails

    Finetuning can happen in several stages, and self-supervised finetuning can come before the expensive annotated stage.

    Do this instead

    Plan the stages in order, starting with the cheapest data that moves the model toward the domain.

  • Common mistake

    Choosing supervised finetuning because it sounds most advanced

    What it looks like

    A team with only unlabeled text chooses supervised finetuning and has no pairs to train on.

    Why it fails

    Supervised finetuning trains on (input, output) pairs. Without those pairs, the type cannot be applied to the data at hand.

    Do this instead

    Start from the data you have, then pick the type that uses it.

  • Common mistake

    Believing an autoregressive pre-training objective rules out infilling

    What it looks like

    A team says their model was pre-trained to predict the next token, so it cannot be finetuned to fill in gaps.

    Why it fails

    The source says you can finetune a model for infilling even if it was originally pre-trained autoregressively.

    Do this instead

    The pre-training objective does not lock the model into one kind of prediction. Infilling finetuning remains an option.

Key Takeaways

  • Finetuning is any training that happens after pre-training, so it is best understood as a later stage of one continuous training sequence rather than a separate process.
  • Feature-based transfer reuses a feature extractor to produce embedding vectors for a downstream model, while finetuning trains the pre-trained model further.
  • Self-supervised finetuning uses task-related unlabeled data and can come before expensive annotated data, while supervised finetuning trains on (input, output) pairs to align the model with human usage and preference.
  • Infilling finetuning trains a masked model to fill in a hidden span using the tokens on both sides, and it can be applied even to a model pre-trained autoregressively.
  • The type to choose depends on the data available: labeled pairs point to supervised finetuning, unlabeled domain text to self-supervised finetuning, and text with gaps to infilling finetuning.

Related concepts

More concepts starting with P