Concepts / Loading Pretrained Models

Loading Pretrained Models

The input stays the same across the two stages while the expected output changes. This is why a model trained to continue text can be redirected toward classification without changing how it reads text.

  • Programming

A Model That Only Continues Text

Suppose you want a language model to decide whether an incoming email is spam. The obvious question is where the model should start. Should you build a new model from nothing and teach it to recognize spam directly, or should you begin with a model that already knows how to work with language? The source you are studying describes the second route, and this article explains why it works and what loading a pretrained model actually does.

The core difficulty is that a model which was only pretrained has learned one habit very well: it continues text, one token at a time. Its natural behavior is to predict what comes next in a passage. A spam classifier needs something different, namely a single answer chosen from a fixed set of categories. Before reading on, try to decide what a pretrained-only model would output if you handed it an email.

What do you think happens?

If you give a model that was only pretrained an email, what does it naturally produce?

  • A single class label such as spam or not spam

  • The next token of the text, one token at a time

  • A numeric accuracy score for the email

Reveal answer
Answer:

The next token of the text, one token at a time

A pretrained model has learned to continue text by predicting what comes next. It has not yet been trained to return one answer from a fixed set of categories, which is what a classifier needs.

What Changes Between Pretraining and Classification

The difference between the two stages lies in the expected output. During pretraining, the model is trained to predict the next token over its vocabulary. During classification fine-tuning, the model is trained to output a correct class label. The fine-tuning stage does not reinvent how the model reads its input. It changes the target the model is pushed toward.

Token IDs intext converted to IDsToken IDs intext converted to IDsNext tokenone token over thevocabularyClass labelone correct label from afixed set
What does the model output in each stage, and what stays the same? The input form is shared, while the expected output differs.

Read the two columns together. The left column shows the habit the pretrained model already has. The right column shows the answer the classifier must give. The input column is identical in both, which is the point the next section develops.

Keeping the Input Form the Same

The input to the model during classification fine-tuning is text that has been converted into token IDs. This is the same kind of input the model received during pretraining. Because the form already matches, fine-tuning does not require a new input format. What it adds is a different expected output: a class label rather than the next token.

Key point

The input stays the same across the two stages while the expected output changes. This is why a model trained to continue text can be redirected toward classification without changing how it reads text.

Tracing One Email Through the Classifier

Follow a single example from start to finish. The email text is first converted into token IDs. Those IDs are passed into the model. Instead of producing a continuation, the model is expected to produce one class label from its fixed set of categories. The diagram below lays out this path for the spam case.

Email textincoming messageToken IDstext converted to IDsLoaded base modelpretrained GPT-2 mediumPredicted label: spamone label from a fixed settokenizepassed inoutput
What happens to one input text, step by step, as it passes through the model until it becomes a predicted class label?
Worked example

Classifying a single incoming email

An email arrives and must be sorted as spam or not spam by a classifier built on a pretrained model.

  1. 1
    Start with the text

    The incoming email is raw text. Nothing has been classified yet.

  2. 2
    Convert to token IDs

    The text is converted into token IDs, the same form the model saw during pretraining.

  3. 3
    Pass into the loaded model

    The token IDs enter the base model that was loaded before fine-tuning began.

  4. 4
    Expect one class label

    The model is trained to produce one correct class label from a fixed set, not the next token of the email.

Result

The email receives one predicted class label, such as spam.

Loading the Base Model Before Fine-Tuning

Classification fine-tuning does not begin from nothing. Before fine-tuning an LLM, the pretrained model is loaded as a base model. The base model is the starting point, and the fine-tuning process then adapts it toward the classification goal. Loading is therefore the first step in the sequence, coming before any input is passed in and before any class label is expected as output.

The key idea is the order of operations. The model is loaded first, and fine-tuning is applied to that already-loaded model. Loading is not the fine-tuning itself. It is the step that gives fine-tuning something to work on.

The GPT-2 Medium Starting Point

The model loaded in this workflow is a pretrained GPT-2 medium model with 355 million parameters. Instruction fine-tuning is the process of adapting a model so that it responds to specific instructions or tasks, and it needs a starting model before that adaptation can begin. In this part of the workflow, the starting model is the pretrained GPT-2 medium model, loaded to serve as the starting point for instruction fine-tuning.

Pretrained GPT-2medium355 million parameters, notyet adaptedLoaded as base modelstarting point forfine-tuningFine-tuning appliedadapted toward the taskloadfine-tune
What is the state of the model at each stage, and what moves it from one stage to the next?

Follow the state across these two stages. At the first stage, the pretrained GPT-2 medium model is loaded. Its state at that moment is the pretrained one: it has 355 million parameters and has not yet been adapted to any instruction. At the second stage, instruction fine-tuning begins from that loaded model. The state carried forward is the same starting point, and the fine-tuning process is what changes the model from there.

Mistakes About What Loading Provides

  • Common mistake

    Treating loading as fine-tuning

    What it looks like

    Believing that once the GPT-2 medium model is loaded, it already classifies emails.

    Why it fails

    Loading supplies the starting point. Instruction fine-tuning is the separate step that follows from it.

    Do this instead

    Loading gives fine-tuning something to work on; the adaptation itself is a later stage.

  • Common mistake

    Assuming the starting model is untrained

    What it looks like

    Thinking the loaded base model is a blank network that knows nothing about language.

    Why it fails

    The starting model is a pretrained model. Fine-tuning begins from a pretrained model rather than from scratch.

    Do this instead

    Treat the loaded model as already pretrained, and expect fine-tuning to adapt it rather than teach it language from zero.

  • Common mistake

    Reading the parameter count as a statement about behavior

    What it looks like

    Concluding that because the model has 355 million parameters, it will perform classification well.

    Why it fails

    The source gives the parameter count as a fact about the model's size. It does not say anything about how the model behaves on a task.

    Do this instead

    Read 355 million as a description of size only, and understand that behavior on a task depends on the fine-tuning that follows.

Checking Your Understanding

MEDIUM

A colleague says that since the base model was pretrained, it should already return a spam or not spam label for any email. Explain what is wrong with this claim, using the difference between the next-token habit and the class label output.

Hints
  • Ask what a pretrained-only model is trained to output.
  • Compare the expected output in pretraining with the expected output in classification fine-tuning.

Key Takeaways

  • Classification fine-tuning trains the model to output one correct class label, while pretraining trains it to predict the next token.
  • The input form stays the same across both stages: text converted into token IDs, so fine-tuning needs no new input format.
  • The pretrained model is loaded as a base model first, and fine-tuning then adapts that already-loaded model; loading is not the fine-tuning itself.
  • The workflow starts from a pretrained GPT-2 medium model with 355 million parameters, which is a statement about size, not about behavior.

Related concepts

More concepts starting with L