Model Performance Evaluation
Settings are adjusted, and the model is compared against the validation set to see which choices work best.
Why One Accuracy Number Is Not Enough
Once a spam classifier has been fine-tuned, the natural next question is whether it works. A single accuracy number is tempting to report, but a fine-tuned model is judged on several datasets, and each one answers a slightly different question. Reporting one number hides which question was answered, so the evaluation is split across datasets that play different roles.
Keep this idea in mind as you read: the same model can look different depending on which data you measure it on. The rest of this article shows why that is expected, how to read the differences, and how the finished model is then used to classify a new message.
Three Datasets, Three Questions
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, so it is the data that choices were compared against. The test set is held back so that it can serve as a fresh check on the finished model. Each dataset therefore answers a different question about the same model.
The three sets are not interchangeable. A high score on the training set alone tells you the model has fitted its learning examples, not that it handles new messages. A score on the validation set is shaped by the decisions made while looking at it. Only the test set gives a check that was never part of those decisions, which is why it is held back.
Following the Data Through Development
Development is an iterative process. Settings are adjusted, and the model is compared against the validation set to see which choices work best. The timeline below shows when each dataset enters the work. The training set is the material the model learns from, the validation set is consulted repeatedly while choices are compared, and the test set is reserved for the end.
Because decisions are repeatedly shaped to the validation data, 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 described as a more neutral estimate of how the model will behave on messages it has never seen.
Reading the Gap Between Training and Test Accuracy
Overfitting is indicated when training accuracy is significantly higher than test accuracy. The word significantly matters: a small difference between the two is not evidence of overfitting on its own.
In the reported results, training and test accuracy sit close together. The source describes them as almost identical, and the slight gap between them, 1.54 points, suggests minimal overfitting of the training data. The pattern to investigate is different: a large difference, such as a training score in the high nineties with a test score far below it.
Judging a training and test gap
A training accuracy and a test accuracy are compared to decide whether the model is overfitting. The example below uses generated numbers to practice the reasoning; they are not from the source.
- 1Identify the two values
Suppose training accuracy is 98.0 percent and test accuracy is 96.5 percent.
- 2Measure the gap
The difference is 1.5 points, which is close to the slight gap the source reads as minimal overfitting.
- 3Judge significance
A gap this small is not evidence of overfitting, so there is no strong reason to change the model on this basis alone.
- 4Contrast with a large gap
If the same training score were 98.0 percent but the test score were 70.0 percent, the 28-point gap would be the pattern to investigate.
A 1.5-point gap is treated as small enough to ignore, while a 28-point gap would signal possible overfitting and call for investigation.
| Pattern | What it looks like | How to read it |
|---|---|---|
| Small gap | Training and test accuracy almost identical | Minimal overfitting, as in the reported 1.54-point gap |
| Large gap | Training accuracy far above test accuracy | Signals overfitting; investigate before trusting the model |
| Test above training | Test score higher than training score | Not described by the overfitting definition; read it as a result to interpret, not as a failure |
Reading the training and test relationship
Why Validation Often Beats Test
What do you think happens?
Must validation accuracy always be higher than test accuracy for a finished model?
Reveal answer
No, it is only a tendency
Validation accuracy is typically somewhat higher than test accuracy because tuning targets the validation set. The source says this is a tendency and not a guaranteed ordering, so a run where validation scores lower than test is possible.
The expected pattern comes from how development works. Choices are compared against the validation set, so they are gradually shaped to it, and the validation score benefits from that shaping. The test set receives no such benefit, so its score tends to sit a little lower.
The ordering is still only a tendency. The reported results follow the expectation, with validation above test. But 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 not automatically a failure; it simply means the tuning effect was weaker in that run. Treat 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 want, the source notes it is common and could potentially be reduced by changing the model's settings. Two hyperparameters are named: 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 source only says it can potentially reduce the gap.
Tracing a 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. The diagram below follows one message through those stages in order, including the truncation check on sequences longer than the supported context length.
Notice that the classifier's output is a name, not a number. The integer label produced by the model is a stepping stone, and the function's last job is to map that label back to a readable class. Because the answer passes through several stages, a wrong result can come from more than one place: the text might be prepared differently from training, the truncation might cut off content that mattered, or the model might predict the wrong integer.
The evaluation in this article sits inside the larger workflow. Classification fine-tuning is organized in three stages: preparing the dataset, setting up the model, and fine-tuning the model and then using it. Final evaluation and classification of new messages both belong to that last stage, so the process does not end when training stops. Step 9 is the evaluation, and step 10 is the use of the finished model on new messages. If a final accuracy looks wrong, you can trace back through the steps that produced it.
Common Misreadings of Evaluation Results
Common mistake Treating validation above test as a required ordering
What it looks likeA run where validation accuracy comes out lower than test accuracy is reported as a broken evaluation.
Why it failsThe source describes validation being higher than test as a tendency, not a guaranteed ordering. Development decisions shape the validation score, but the ordering depends on what happened in that run.
Do this insteadRead the ordering as evidence to interpret. A reversed result means the tuning effect was weaker in that run, not that the evaluation failed.
Common mistake Calling any nonzero gap between training and test accuracy overfitting
What it looks likeA 1.54-point gap between training and test accuracy is labeled as overfitting and the model is discarded.
Why it failsOverfitting is indicated when training accuracy is significantly higher than test accuracy. The source reads a slight gap as suggesting minimal overfitting.
Do this insteadJudge whether the gap is significant. Investigate large gaps, and do not overreact to small ones.
Common mistake Using the test set to make development decisions
What it looks likeSettings are adjusted again and again until the test score improves.
Why it failsThe test set is held back so it can serve as a fresh check on the finished model. Once it is used for decisions, its score is no longer a neutral estimate.
Do this insteadMake choices against the validation set and reserve the test set for the final check.
Common mistake Assuming a wrong classification has only one possible cause
What it looks likeA message is misclassified and the model is blamed without checking the rest of the pipeline.
Why it failsThe answer passes through tokenization, truncation, the model's integer prediction, and the mapping to a class name. Each stage can introduce a mismatch.
Do this insteadTrace back through the stages to find where the mismatch began before changing the model.
Checking Your Reading of the Pipeline
Without looking back, put these stages in the order a new message passes through them when calling the classifier: the model predicts an integer label; the text is turned into token IDs; the integer is mapped to a class name; the length is checked against the supported context length. Then explain which stage a wrong answer would most likely come from if the message was cut short.
Hints
- Start from the raw text and think about what the model needs before it can predict anything.
- The integer label is an intermediate result; the class name is the final output.
- A cut-short message points to the truncation step, which happens before the model sees the input.
A colleague reports that validation accuracy is 0.4 points lower than test accuracy and concludes the evaluation is wrong. Explain, using the tendency described in the source, why this conclusion is not justified on its own.
Hints
- Recall whether the source describes validation above test as a rule or a tendency.
- Think about how development decisions shape the validation score.
Key Takeaways
- A fine-tuned model is measured on separate datasets because each answers a different question: the training set shows fit to learned examples, the validation set guides development choices, and the test set gives a held-back check on the finished model.
- A gap between training and test accuracy signals overfitting only when training accuracy is significantly higher; a small gap, such as the reported 1.54 points, suggests minimal overfitting and can be ignored.
- 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, so a reversed result should be interpreted rather than treated as a failure.
- The
classify_reviewfunction turns a new message into token IDs, predicts an integer label, and maps that label to a class name; tracing these stages helps locate where a wrong answer began.