liveBook · Manning

Objective function

As explained in Grokking AI Algorithms, Second Edition

Training loss is the loss computed on the examples used to fit a model.

An objective function expresses what a learning system is trying to minimize or maximize. During model training, a loss function turns a prediction’s error into a number: the training loss. Think of it as a score for how far the model’s answer is from the answer available in its training examples. The choice of loss matters because it defines what the model is being trained to improve. section 5.22 section 9.17 section 9.8

A typical learning cycle uses loss like this:

  • Make predictions from a batch of training examples, then compare them with the known answers to obtain a loss value. section 11.32
  • Use backpropagation to calculate weight adjustments, update the weights, and repeat with more batches. section 11.32 section 12.22
  • Watch the trend, not just one score: decreasing training loss suggests improvement on training examples, but does not establish that the model generalizes. section 12.21 section 11.34

Choose a loss that matches the prediction

For a neural network predicting a class, a simple illustration compares a prediction of 0.7 with an actual value of 1.0, giving a difference of 0.3. For a diffusion model predicting continuous noise values, mean squared error averages the squared differences between predicted and actual noise across pixels. For next-token prediction, cross-entropy assigns a small loss when the correct token received high probability and a large loss when it received low probability. section 9.8 section 12.21 section 11.30

Figure 12.46 The ideal loss-over-time for a diffusion model
12_46

The loss-over-time figure illustrates the useful pattern to look for while training: a downward trend rather than a single impressive score. section 12.21

Training loss is computed on examples the model learns from. To check whether improvement carries beyond those examples, calculate loss separately on a validation set the model never trains on. If training loss falls while validation loss rises, overfitting may be underway; early stopping uses validation loss to decide when to stop. section 11.34

How Grokking AI Algorithms, Second Edition covers it

How deep it goes
Works through numerical errors, mean squared error, cross-entropy intuition, and backpropagation steps; leaves some gradient-update code as a placeholder.
Examples
Compares class predictions, next-token probabilities, and predicted versus actual image noise.
What it assumes
Introduces error through predicted-versus-actual comparisons before moving to weight updates and loss formulas.
What you can do after
Evaluate/understand training progress by interpreting loss trends and checking validation loss for overfitting.
How it connects
Connects objective functions to backpropagation, gradient descent, validation loss, overfitting, and early stopping.

Also explained in

Compare how 30 books explain objective function →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking AI Algorithms, Second Edition. The section links point to the parts of the book it draws on.