liveBook · Manning

Evaluation dataset

As explained in Build a Text-to-Image Generator (from Scratch)

A validation set is a held-out dataset split used to assess model performance during training and select configurations or checkpoints.

A validation set is held-out data used to assess a model during training. Its loss provides a signal about generalization and overfitting without updating the model’s weights. section 13.4.2

A validation loop supports training decisions in two ways:

  • Evaluate the model on validation batches and average their loss. section 13.4.2
  • Track whether validation loss improves; stop after three consecutive epochs without improvement, and retain the best weights. section 13.4.2
def val_epoch(model,dataloader,loss_fn):    #1
    model.eval()
    val_loss=0
    with torch.inference_mode():
        for batch, (X, y) in enumerate(dataloader):    #2
            X, y = X.to(device), y.to(device)
            pred_logits = model(X)
            loss = loss_fn(pred_logits, y)    
            val_loss += loss.item()
    return val_loss/len(dataloader)    #3

The evaluation function switches the model to evaluation mode, disables gradient tracking, and accumulates loss across validation batches. section 13.4.2

How Build a Text-to-Image Generator (from Scratch) covers it

How deep it goes
Implements batch evaluation, average-loss tracking, and early stopping, but does not detail validation-set construction.
Examples
Evaluates a fine-tuned ResNet50 classifier on validation data and stops after three unimproved epochs.
What it assumes
Assumes training and validation dataloaders, a loss function, and a model that can be evaluated.
What you can do after
Operate an early-stopping loop using validation loss and a patience of three epochs.
How it connects
Connects validation loss with overfitting, training loss, and early stopping.

Also explained in

Compare how 27 books explain evaluation dataset →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Text-to-Image Generator (from Scratch). The section links point to the parts of the book it draws on.