Concepts / Fine-Tuning to Follow Instructions

Fine-Tuning to Follow Instructions

Fine-tuning adapts a pretrained LLM to a specific task; for classification, the training data consists of examples that carry class labels such as 'spam' or 'not spam'.

  • Programming

Aiming a General Model at a Job

Imagine you have built a language model and loaded pretrained weights into its architecture. You now have a model that has learned a great deal about language in general, but it is not yet aimed at any particular job. Ask it about a text message and it has no built-in commitment to answering 'spam' or 'not spam'. Something has to point it at the work you care about.

That pointing step is fine-tuning: continuing to train the model on a dataset that represents the specific task. Throughout this article we will keep one running task in mind, classifying text messages as 'spam' or 'not spam'. At every step, ask two questions: what should the model output for a given message, and how would anyone know whether it got the answer right?

Where Fine-Tuning Sits in the Build

Building a working LLM application is easier to follow as a sequence of stages. The first stage constructs the model. The second produces a general pretrained model and later adapts it toward assistant-style use. The third stage is where a pretrained model is adapted into a classifier. This article concentrates on that third stage.

The third stage starts from a pretrained model whose weights have already been loaded. It adds a labeled dataset, which says which class each example belongs to, and fines-tunes the model on that data. The output of this stage is a classifier. The path that matters runs from loaded weights and a labeled dataset, through fine-tuning for classification, and out to the classifier.

Pretrained LLMweights already loadedLabeled messageseach message has a classFine-tune forclassificationtrain on message and labelpairsClassifierreturns a trained labelstarting weightstraining dataproduces
What steps happen in order, from the pretrained model through labeled training examples to a trained classifier?

Labeled Messages as Training Data

Picture a small collection of text messages. A person has read each one and marked it as spam or not spam. Fine-tuning for classification means training the pretrained model on pairs of message and label. Each training example is a message paired with its class label, so the model sees what a spam message looks like and what a legitimate message looks like, side by side with the answer it should produce.

Worked example

Building a tiny labeled set

You want to fine-tune a model on three messages. Write out the training examples so each one pairs the message with its class label.

  1. 1
    Choose the message

    Message one is 'Win a free prize, click now'. A person marks it as spam.

  2. 2
    Pair it with its label

    The training example is the pair ('Win a free prize, click now', spam).

  3. 3
    Repeat for each message

    Message two, 'Lunch at noon tomorrow?', is marked not spam, giving ('Lunch at noon tomorrow?', not spam). Message three, 'Your account is locked, send your password', is marked spam.

  4. 4
    Read the finished set

    The dataset is now a list of message and label pairs. Nothing in a pair asks the model to write a reply; it only says which class the message belongs to.

Result

Three labeled training examples: two spam, one not spam, each carrying the class the model should learn to produce.

Two Kinds of Fine-Tuning Compared

The source names two main ways of fine-tuning an LLM, usually labeled step 8 and step 9. They start from different kinds of data, and that difference is what decides which one applies. Fine-tuning for classification uses a dataset in which each example already carries a class label, such as 'spam' or 'not spam'. Fine-tuning to follow instructions uses an instruction dataset, in which the model is shown a request and the response it should give.

Message paired withclass labeltraining dataRequest paired withresponsetraining dataReturns a label suchas spamoutputProduces a responseto a requestoutputAssign each messageto a classgoalFollow instructionsgoal
How do the training data, the output produced, and the goal differ between the two kinds of fine-tuning?

A useful test is to look at the dataset first. If every example carries a class label, you are doing classification fine-tuning and the model's job is to pick a label. If every example is a request paired with a desired response, you are doing instruction fine-tuning and the model's job is to answer. The same pretrained model could be pointed either way; the data is what sets the direction.

Which Output Position Gets Read

When the model processes a message, it produces an output for each position in that message. A classifier needs one decision, not one per position, so a single output position is chosen and mapped to the class labels. In the common arrangement this is the output at the last token position, which is read and turned into 'spam' or 'not spam'. The other positions are processed along the way but are not the ones whose output is used for the label.

Token 1processed, not readToken 2processed, not readToken 3processed, not readLast tokenoutput read for the label
When the model processes a message, which output position is used to decide the label?

The read output is mapped to the labels the classifier was trained on. The label 'spam' and the label 'not spam' are two possible destinations for that one value. This is why a classifier can only return labels it was trained on: the output has been tied to that fixed set of classes during fine-tuning.

Checking Accuracy on Held-Out Messages

Once fine-tuning finishes, the model is supposed to be a classifier, but that is a claim that needs checking. The source treats evaluating the accuracy of a fine-tuned LLM classifier as an important step in its own right. The question evaluation answers is simple: when the classifier is given messages with known labels, how often does its predicted label match the true label?

The key detail is that evaluation uses examples the model did not learn from. Checking the classifier on its own training messages would show whether it memorized them, not whether it handles new ones. So the evaluation set is held out: labeled examples kept aside from training and used only to measure performance.

Rule

In words, accuracy is the share of evaluation examples that the classifier labels correctly. A classifier that gets most spam messages and most legitimate messages right has high accuracy. One that often confuses the two groups has low accuracy.

Labeling a New Message

After fine-tuning and evaluation, the classifier can be used on messages it has never seen. A new message is passed to the model, and the model returns one of the labels it was trained on. The source describes this as using a fine-tuned LLM to classify new data. Nothing about this step retrains the model; it only reads the message and reports a label.

New messagenever seen in trainingFine-tuned modelweights are not changedOutput readlast token positionSpam or not spamreturned labelpassed inprocessedmapped to label
What happens to a new message as it moves through the model to produce a label?

What do you think happens?

Suppose you run the fine-tuned spam classifier on a brand-new message it has never seen. Does the model's training change as a result?

  • Yes, it learns from the new message

  • No, it only reads the message and reports a label

Reveal answer
Answer:

No, it only reads the message and reports a label.

Using a fine-tuned classifier on new data is inference, not training. The model returns one of its trained labels and nothing about its weights is updated.

Reasoning about the returned label means keeping two things in view. First, the label is only as reliable as the accuracy measured on held-out examples. Second, a label is a best judgment among the classes the model knows, so an unusual message still receives one of those labels, even when the model is less sure of it. The label does not come with a guarantee of correctness for that particular message.

Mistakes Beginners Make

  • Common mistake

    Treating any fine-tuned model as a classifier

    What it looks like

    Calling a model fine-tuned on request and response pairs a spam classifier.

    Why it fails

    The training data decides the kind of fine-tuning. Request and response pairs point toward following instructions, not toward choosing a class label.

    Do this instead

    Check the dataset first. Labeled examples such as spam or not spam mean classification fine-tuning.

  • Common mistake

    Measuring accuracy on the training messages

    What it looks like

    Reporting high accuracy after running the classifier on the same messages it was fine-tuned on.

    Why it fails

    The model has already seen those labels, so the score shows memorization rather than performance on unseen messages.

    Do this instead

    Hold out labeled examples that were not used for training and compute accuracy on those.

  • Common mistake

    Assuming new-message labeling retrains the model

    Why it fails

    Reading a new message and returning a label does not change the weights. It is a use of the model, not further training.

    Do this instead

    Treat labeling as reading and reporting. Retraining is a separate step that uses labeled data.

  • Common mistake

    Trusting a single accuracy number without asking what messages produced it

Practice Reasoning About a Classifier

MEDIUM

A spam classifier was fine-tuned on a labeled set of messages. It scored well on the messages used to train it. A colleague says the classifier is ready to use on real email. Using the ideas in this article, explain what evidence is missing and what you would check before agreeing, and then describe what the classifier's returned label for a new message does and does not guarantee.

Hints
  • Ask whether the messages used for the score were ever seen during training.
  • Recall what accuracy measures: the share of evaluation examples labeled correctly.
  • Think about whether returning a label for a new message changes the model.

Key Takeaways

  • Fine-tuning points a pretrained LLM at a specific job by continuing training on a task-specific dataset; for classification, each example pairs a message with a label such as 'spam' or 'not spam'.
  • Classification fine-tuning and instruction fine-tuning differ in their data: labeled examples versus request and response pairs. The data determines which one applies.
  • Accuracy is the share of held-out, labeled examples that the classifier labels correctly, and it is only trustworthy if the evaluation messages were not used for training.
  • Labeling a new message passes it through the fine-tuned model and returns one of the trained labels without retraining the model.

Related concepts

More concepts starting with F