Training Loops and Model Evaluation
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'.
A General Model Still Needs a Job
By the time you reach this point in building a language model, a great deal of groundwork is already in place. The architecture has been written, a pretrained model has been produced, and pretrained weights from an external source have been loaded into that architecture. Yet a general-purpose language model is not aimed at any particular job. It has learned broadly, but nothing in it yet says, for example, that your task is sorting text messages into spam and not spam.
The step that points the model at a job is fine-tuning: continuing to train the model on a dataset that represents the specific task you care about. The running task in this material is classifying text messages as 'spam' or 'not spam'. Keep that single task in mind as you read. At each step, ask two questions: what should the model output for a given message, and how would anyone know whether it got the answer right?
Tracing a Model Through the Third Stage
Building a working LLM application is easier to follow as a sequence of stages. The first stage covers constructing the model. The second covers a general pretrained model and its later adaptation toward assistant-style use. The third stage is where a pretrained model is adapted into a classifier. This article concentrates on that third stage.
- 1Start with a pretrained model whose weights have already been loaded into the architecture.
- 2Add a labeled dataset that says which class each example belongs to, for instance a message marked spam or not spam.
- 3Fine-tune the model on that labeled data, so it learns to associate each message with its label.
- 4The output of this stage is a classifier, which is a claim that still needs to be checked.
What Fine-Tuning for Classification Does
Fine-tuning a pretrained LLM adapts it to a specific task. For classification, the training data consists of examples that carry class labels such as 'spam' or 'not spam'.
Imagine a small collection of text messages. A person has marked each one as spam or not spam. Fine-tuning for classification means training the pretrained model on these pairs of message and label. Once trained, when the model reads a new message it produces the label it has learned to associate with messages like it.
Training works as a loop over the labeled examples. In each pass, the model reads a message and produces a prediction. That prediction is compared with the true label, and the mismatch is used to adjust the model's weights. The cycle then repeats across the examples. Each repetition nudges the weights and the predictions, which is why one pass through the data is rarely the end of training. The diagram below shows a single pass and how the cycle returns to the start.
Classification Versus Instruction Fine-Tuning
The source names two main ways of fine-tuning an LLM, labeled step 8 and step 9. They begin from different kinds of data, and that difference determines which one applies. Fine-tuning for classification uses a dataset in which each example already carries a class label. Fine-tuning to follow instructions uses an instruction dataset, in which the model is shown a request and the response it should give.
| Aspect | Fine-tuning for classification | Fine-tuning to follow instructions |
|---|---|---|
| Training data | Examples that each carry a class label | An instruction dataset of requests and responses |
| Expected output | A class label such as spam or not spam | A response to the request |
| Goal | A classifier that labels new data | A model that follows instructions |
Two distinct categories of fine-tuning, distinguished by their training data
What Evaluation Checks
Once fine-tuning finishes, the model is supposed to be a classifier, but that is a claim that needs checking. Evaluating the accuracy of a fine-tuned LLM classifier means measuring how often its predicted labels match the true labels on examples it did not learn from. The question is simple to state: when the classifier is given messages whose labels are known, how often does its predicted label match the true label?
In its simplest form, accuracy is the share of examples the classifier labels correctly. A classifier that gets most spam messages and most legitimate messages right has high accuracy. A classifier that often confuses the two groups has low accuracy. The number is only as trustworthy as the examples used to compute it, so the choice of evaluation messages matters as much as the calculation itself.
Scoring a Ten-Message Evaluation Set
Computing accuracy on held-out messages
A fine-tuned spam classifier is evaluated on 10 held-out messages whose true labels are known. The classifier predicts the correct label for 8 of them and the wrong label for 2. What is its accuracy?
- 1Count the examples
The evaluation set has 10 messages. None of them were used to train the model, so they measure behavior on unseen data.
- 2Count the matches
Compare each predicted label with its true label. 8 predictions match the true label, so 8 examples are labeled correctly.
- 3Take the share
Accuracy is the share of examples labeled correctly. 8 correct out of 10 examples is 8 divided by 10, which is 0.8.
The classifier has an accuracy of 80 percent on this evaluation set. The 2 mistakes are worth examining, because a different set of 10 messages could give a different number.
Mistakes When Reading an Accuracy Score
Common mistake Scoring the classifier on messages it was trained on
What it looks likeA model is trained on 500 labeled messages, then scored on those same 500 messages and reports high accuracy.
Why it failsEvaluation is defined as measuring predictions on examples the model did not learn from. Messages seen during training do not show how the classifier handles new messages.
Do this insteadHold back labeled examples before fine-tuning and use only those held-out examples for the accuracy measurement.
Common mistake Treating a single accuracy number as fully trustworthy
What it looks likeA classifier scores 90 percent on a small set that contains only obvious spam, then is trusted for all messages.
Why it failsThe source notes that the number is only as trustworthy as the examples used to compute it. A set that does not reflect the real mix of messages can hide weaknesses.
Do this insteadChoose evaluation messages that represent both spam and legitimate messages, and read the score together with the examples it was computed from.
Common mistake Assuming fine-tuning automatically produces a working classifier
Why it failsThe source says the classifier is a claim that needs checking. Finishing training does not by itself prove the model labels messages correctly.
Labeling a New, Unseen Message
What do you think happens?
A brand-new message arrives that was not in the training or evaluation data. What do you think the fine-tuned classifier does with it?
Reveal answer
The message is passed to the model, and the model returns one of the labels it was trained on, such as spam or not spam.
Using the classifier on new data does not retrain it. The model only reads the message and reports a label.
- 1The new message is passed to the fine-tuned model as input.
- 2The model reads the message and produces a label from the set it was trained on.
- 3The label is returned as the classification of that message.
- 4No training happens at this step, so the weights stay the same.
Reasoning About a Classifier's Output
A spam classifier scores very high accuracy on the messages it was fine-tuned on. Explain why that result alone does not tell you how it will label a new message, and describe what evaluation set you would use instead.
Hints
- Ask which examples the model learned from and which examples it did not.
- Accuracy is defined on examples the model did not learn from.
- A good evaluation set contains labeled messages that were held back and that reflect both spam and not spam.
Summary of the Evaluation Workflow
- 1Fine-tuning adapts a pretrained LLM to a specific task. For classification, the training data is made of examples that carry class labels such as spam or not spam.
- 2Classification fine-tuning and instruction fine-tuning differ mainly in their data: labeled examples versus requests paired with responses.
- 3Evaluating a fine-tuned classifier measures how often its predicted labels match the true labels on held-out examples it did not learn from.
- 4Accuracy is the share of examples labeled correctly, and it is only as trustworthy as the evaluation examples behind it.
- 5Using the classifier on a new message passes it in and returns one of the trained labels, without retraining the model.
At a glance
- Fine-tuning points a general pretrained LLM at a specific job, such as classifying messages as spam or not spam.
- The training data decides the category: labeled examples for classification, requests paired with responses for instruction following.
- Accuracy measures how often predicted labels match true labels on held-out examples the model did not learn from.
- A score is only as trustworthy as the evaluation set behind it, so choose that set with care.
- New messages are labeled by passing them to the classifier, which returns a trained label without retraining.