Classification Fine-Tuning Workflow
Once a spam classifier has been fine-tuned, the natural next question is whether it works.
Why One Accuracy Number Is Not Enough
Once a spam classifier has been fine-tuned, the natural next question is whether it works. It is tempting to answer with a single accuracy number, but a fine-tuned model is judged on several datasets, and each one answers a slightly different question. Measuring accuracy on only one dataset hides information that the other datasets reveal.
The three datasets involved are the training set, the validation set, and the test set. The training set shows how well the model fits the examples it learned from. The validation set was used while development decisions were being made. The test set is held back so that it can serve as a fresh check on the finished model. Each role is different, and so each accuracy number must be read in light of the role of the data it came from.
Three Datasets, Three Questions
The final evaluation uses one accuracy function applied to three data loaders: the training loader, the validation loader, and the validation-stage loader's counterpart, the test loader. Accuracy is computed for each loader and printed as a percentage with two decimal places. The source notes that this evaluation is run across the entire dataset, which is why no eval_iter limit is defined. Limiting the number of evaluation batches is a different choice, and it is not used in this workflow.
The training set measures fit to examples the model has already seen. The validation set measures performance on data that informed development decisions, so its score can be shaped by those decisions. The test set measures performance on data that played no part in making decisions. Because these three roles differ, the three numbers must be measured separately; blending them into one figure would erase the distinction the workflow is designed to preserve.
Development is an iterative process. Settings are adjusted and the model is compared against the validation set to see which choices work best. Over many rounds those choices are shaped to the validation data, so validation scores can drift upward in a way the untouched test set does not reflect. The test set was not used to make decisions, so its score is a more neutral estimate of how the model will behave on messages it has never seen.
Reading the Train-Test Gap
The gap is a difference between two accuracy values, and it is interpreted through the word significantly. Overfitting is indicated when training accuracy is significantly higher than test accuracy. A slight gap suggests minimal overfitting. The reported results show a gap of 1.54 points, and the source describes the training and test accuracy as almost identical, which is why that gap is treated as small.
The pattern worth investigating is a large difference. The source gives a concrete picture of it: a training score in the high nineties paired with a test score far below it. That shape says the model fits its training examples much better than it handles new ones. The diagram below contrasts that pattern with the nearly identical scores of the reported run.
Why Validation Often Sits Above Test
What do you think happens?
After tuning against the validation set, do you expect its accuracy to be higher or lower than the test accuracy? Commit to an answer before reading on.
Reveal answer
Validation is typically somewhat higher than test, but this is a tendency and not a guaranteed ordering.
Tuning targets the validation set, so its score can drift upward. The test set played no part in decisions, so it gives a more neutral estimate. The ordering can still reverse on a particular run, depending on what happened during development.
The expectation is real, and the reported results match it: validation accuracy is higher than test accuracy. The error comes from treating the expectation as a rule. Whether validation sits above or below test on a given run depends on what happened during development. A validation score that comes out lower than the test score is therefore not automatically a failure; it simply means the tuning effect was weaker in that run. Read the ordering as evidence to interpret, not as a check that must pass.
When the gap between validation and test accuracy is larger than you would like, the source names two hyperparameters that can potentially reduce it: the dropout rate, set through drop_rate, and the weight_decay parameter in the optimizer configuration. Raising the dropout rate or the weight decay is the suggested adjustment. Each change should be re-measured, because the effect is not guaranteed and the new run will produce its own three accuracy values.
Tracing a New Message to a Class Name
After evaluation, the model is put to use. The classify_review function takes a piece of text and returns the name of its class. Its signature shows what it needs: the text, the fine-tuned model, the tokenizer, the device, an optional max_length, and a pad_token_id that defaults to 50256.
The function follows the same preprocessing ideas used for the SpamDataset earlier in the workflow. The text is turned into token IDs, the model then predicts an integer class label, and the function returns the matching class name. Pay attention to the order: raw text comes first, token IDs come second, and a label is produced only after the model has seen those IDs.
The classifier's output is a name, not a number. The integer label is a stepping stone, and the function's last job is to map that label back to a readable class. This layering matters for debugging. A wrong answer can come from several places: the text might be prepared differently from training, the truncation might cut off content that mattered, or the model might predict the wrong integer. Knowing the sequence of stages makes it easier to locate where a mismatch began.
Following One Message Through classify_review
A new message arrives and the caller wants a class name, such as spam or not spam, rather than a raw number.
- 1Receive text
The message is passed in as the text argument, together with the fine-tuned model, the tokenizer, and the device.
- 2Encode
The tokenizer converts the text into token IDs, the
input_idsthe model reads. - 3Limit length
If the sequence is longer than the supported context length, it is truncated before it reaches the model.
- 4Predict
The model predicts an integer class label from the prepared IDs.
- 5Map to name
The function returns the class name that matches the integer label.
The function returns a class name. If that name is wrong, check the steps in reverse order to find where the mismatch began.
Mistakes When Reading Evaluation Results
Common mistake Expecting validation to always beat test
What it looks likeValidation comes out at a slightly lower value than test on one run, and the run is judged a failure.
Why it failsValidation sitting above test is a tendency caused by tuning, not a rule. The ordering depends on what happened during development.
Do this insteadTreat the ordering as evidence to interpret. A reversed ordering means the tuning effect was weaker in that run.
Common mistake Calling any train-test difference overfitting
What it looks likeA gap of 1.54 points is reported as overfitting.
Why it failsOverfitting is signaled by training accuracy being significantly higher than test accuracy. A slight gap suggests minimal overfitting.
Do this insteadJudge the size of the gap, and look for a large difference such as a training score far above a test score.
Common mistake Reporting one accuracy number for the whole model
Why it failsEach dataset answers a different question, so one figure hides the distinction between fit, tuning, and the held-back check.
Common mistake Assuming the model outputs a class name directly
Why it failsThe model predicts an integer label, and the function maps that label to a readable class name as its last step.
Common mistake Using the test set to make development decisions
Why it failsThe test set is held back so that it remains a fresh check. Tuning against it removes its neutrality as an estimate.
Practice Reading Evaluation Results
A fine-tuned classifier reports a training accuracy that is significantly higher than its test accuracy. Another run reports training and test accuracy that are almost identical, with validation slightly below test. For each run, state whether overfitting is indicated, and explain why the validation-below-test ordering does not by itself mean the run has failed. Then name one hyperparameter adjustment the source suggests for a large validation-to-test gap and say what you would re-measure afterward.
Hints
- Overfitting is indicated by a significant difference between training and test accuracy, not by any difference.
- Validation above test is a tendency; the ordering can reverse on a given run.
- The two named hyperparameters are the dropout rate (
drop_rate) andweight_decay.
Key Takeaways
- Accuracy is measured separately on training, validation, and test data because each dataset plays a different role: learning, tuning decisions, and a held-back final check.
- Overfitting is indicated when training accuracy is significantly higher than test accuracy; a slight gap, such as the 1.54-point gap reported here, suggests minimal overfitting.
- Validation accuracy is typically somewhat higher than test accuracy because tuning targets the validation set, but this is a tendency and not a guaranteed ordering; raising dropout or weight decay may narrow the gap and must be re-measured.
- The classifier turns a new message into a class name by tokenizing it into
input_ids, truncating to the supported context length, predicting an integer label, and mapping that label to a readable class name.