Concepts / Fine-Tuning and Evaluating the Model

Fine-Tuning and Evaluating the Model

Initial accuracy is measured separately on the training, validation, and test datasets, giving a baseline before fine-tuning changes the weights.

  • Programming

Why Measure Before Training

Before you fine-tune a model, it helps to know how well it already performs on the data you care about. That baseline gives you something to compare against once training has run. Without a starting measurement, a later improvement or regression has no reference point, so you cannot tell whether the training changed anything meaningful.

In this article we measure a classifier's accuracy on three separate datasets: the training split, the validation split, and the test split. We then look closely at what the resulting numbers tell us at this early stage, while the model has not yet been fine-tuned and its LoRA matrix B still holds its starting values.

What Each Accuracy Number Counts

Accuracy is the share of predictions the model gets right. For a classifier, each example in a dataset has a true label, and the model produces a predicted label. Accuracy counts how many of those predictions match the true labels and reports that count as a fraction of all the predictions made.

Rule

We compute accuracy three times, once for each split, because each split answers a different question. The training split is the data the model learns from, so its accuracy tells you how well the model fits the examples it has seen. The validation split is held apart from the main learning signal and is used to check how the model behaves on data it was not trained on. The test split is kept for the final check. Comparing the three numbers shows whether performance is similar across the splits or whether one split stands out.

Worked example

Turning Counts into Accuracy Percentages

Suppose a training split contains 80 examples and the model predicts 37 of them correctly. What is the training accuracy, and how does it compare with a validation split of 40 examples where 18 predictions are correct?

  1. 1
    Count the correct predictions and the total for the training split

    The model got 37 of 80 examples right, so the correct count is 37 and the total is 80.

  2. 2
    Divide correct by total

    $\frac{37}{80} = 0.4625$, which is 46.25% when written as a percentage.

  3. 3
    Repeat the same calculation for the validation split

    $\frac{18}{40} = 0.45$, which is 45.00% accuracy on the validation split.

  4. 4
    Compare the two values

    The two numbers are close to one another, which tells you the model performs about the same on both splits.

Result

Training accuracy is 46.25% and validation accuracy is 45.00%. These counts are illustrative and were chosen only to show the arithmetic.

Predicting the Starting Numbers

Before you look at any output, make a prediction. The model has not been fine-tuned yet, and LoRA matrix B has been initialized with zeros. Think about whether you expect the three accuracy values to be close to one another, and whether you expect them to match the values from chapter 6.

What do you think happens?

With matrix B set to zeros and no training done yet, what do you expect the training, validation, and test accuracies to be, and do they match chapter 6?

Reveal answer
Answer:

The initial values are 46.25% for training, 45.00% for validation, and 48.75% for test. They are close to one another and they match the values from chapter 6.

Because matrix B starts at zero, the product of A and B is a zero matrix. Adding a zero matrix to the original weights leaves them unchanged, so the model behaves exactly as it did in chapter 6, and the same accuracies are reproduced.

python
Notes on the code
  • calc_accuracy_loader is the single helper function that performs each measurement.
  • Each call receives a data loader, the model, the device it runs on, and a num_batches argument that limits how many batches are used.
  • The same model is passed in every call, so any difference between the numbers comes from the data split.

The call pattern above is an illustration of the helper's arguments as described in the course, not a copy of the official listing. Notice what the three calls share: the model and device are identical, and only the loader changes. Keep one question in mind as you read on: what would have to change for the printed numbers to differ from what we expect?

How the Three Splits Relate

The three datasets play different roles, and each accuracy value tells you something different about the model on its own split. The training split reflects what the model has been fitted to. The validation split reflects behavior on examples held apart from the main learning signal. The test split is reserved for the final check and should not guide decisions made during development.

Training split46.25% accuracyValidation split45.00% accuracyTest split48.75% accuracy
How do the three separate datasets relate to one another, and what does each accuracy value measure on its own split?

The diagram shows the flow in plain terms. Each loader feeds the same model, the model's predictions are scored, and the three results are printed separately. Because the same model is used for all three, a difference between the numbers reflects the data each split contains rather than a different model. Here the three values are close, so the model performs about the same on each split.

Why Zero-Initialized B Leaves the Weights Alone

The reason the initial numbers match chapter 6 lies in how LoRA matrix B starts out. Initializing B with zeros makes the product of matrices A and B a zero matrix. Adding a zero matrix to the original weights does not change those weights. So at the moment of initialization, the LoRA addition has no effect on the model's behavior.

Matrix B set tozerosProduct ABzero matrixAdd to originalweightsadds nothingOriginal weightsunchangedAccuracy matcheschapter 646.25%, 45.00%, 48.75%multiplied with Azero matrix addedno changesame model behavior
How does setting B to zero make the effective weight update zero, so the model's outputs and accuracy match the original model before any training?

Read the chain from top to bottom. Each link depends on the one before it. The explanation for the matching numbers rests on a single link: the zero starting value of B. If that link were broken, the rest of the chain would no longer guarantee the same results.

Common Misreadings of the Initial Results

  • Common mistake

    Treating the matching values as a bug

    What it looks like

    A learner sees that the printed initial accuracies equal the chapter 6 numbers and assumes the code is repeating an old result by mistake.

    Why it fails

    With B initialized to zero, the weights are unchanged, so a match is the expected outcome rather than an error.

    Do this instead

    Confirm that B is zero at initialization. If it is, a match is what you should see.

  • Common mistake

    Expecting the three accuracy values to be identical

    What it looks like

    A learner expects training, validation, and test accuracy to be the same number because it is the same model.

    Why it fails

    Each accuracy is computed on a different split. The same model can score differently on different data.

    Do this instead

    Expect the values to be close, and treat any large gap as information about the splits rather than the model alone.

  • Common mistake

    Assuming accuracy equals correctness of the whole model

    What it looks like

    A learner reads 46.25% as the model being wrong about half of everything it has seen, without checking the denominator.

    Why it fails

    Accuracy is the share of predictions that are correct for one dataset, measured with the counts from that dataset.

    Do this instead

    Always check which split the number came from and how many predictions were counted.

  • Common mistake

    Using the test split to make decisions during development, which undermines the purpose of keeping it for the final check

Diagnosing a Mismatch in the Printed Results

Suppose the printed initial values differ from the chapter 6 values. The chain from the previous section tells you where to look. Matrix B is the first link, because a nonzero B makes AB nonzero, which changes the weights and removes the guarantee that the numbers match. The diagram below turns that reasoning into an order of checks.

Printed accuracydiffers fromchapter 6Is matrix B allzeros?Weights alreadychangedAB is nonzeroCheck the AB productand weight mergeCheck the data splitfor each loaderstart herenoyesif weights are unchanged
If the printed initial train, validation, or test accuracy differs from the earlier chapter's values, which step in the chain should I check first?

In words: first check the initialization of B. If B is not zero, the weights have already changed, and that alone explains the mismatch. If B is zero, the next place to look is the AB product and the step that merges it into the weights, since those are the links that should leave the weights unchanged. Only after the weights are confirmed should you look at the data split, because the same model is used for all three measurements and the splits are the remaining source of difference.

Checking Your Understanding

EASY

A colleague reruns the initial evaluation and gets training 46.25%, validation 45.00%, and test 48.75%, identical to chapter 6. Without any training having happened, explain why this is the expected result and not a sign of a bug.

Hints
  • Start from what matrix B contains at initialization.
  • Follow the product AB and what it does when added to the original weights.
MEDIUM

Suppose the printed training accuracy is 52.00% while the chapter 6 value is 46.25%, and B was confirmed to be all zeros. Name the next two links in the chain you would check, in order, and say why each one is relevant.

Hints
  • Consider which steps could change the weights even when B is zero.
  • Consider what differs between the three measurements besides the model.

Key Takeaways

  • Accuracy is the share of predictions a model gets right on a given dataset, and it is measured separately on the training, validation, and test splits to form a baseline before fine-tuning.
  • The initial values of 46.25% for training, 45.00% for validation, and 48.75% for test were produced before any weights changed, and they are expected to match chapter 6.
  • Initializing LoRA matrix B with zeros makes the product AB a zero matrix, and adding a zero matrix leaves the original weights unchanged, so the model behaves as it did before.
  • If the printed initial results differ from chapter 6, check the initialization of B first, then the AB product and weight merge, and then the data split.

Related concepts

More concepts starting with F