liveBook · Manning

Chapter 9: Loss, optimization, and regularization

What you will learn in chapter 9 of Math and Architectures of Deep Learning

This introduction frames neural-network training as minimizing a loss by optimizing weights, then previews loss choices, optimization methods, regularization, overfitting, and dropout.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This introduction frames neural-network training as minimizing a loss by optimizing weights, then previews loss choices, optimization methods, regularization, overfitting, and dropout.

Key terms: function approximator, neural network architecture, weights, loss function, training, optimization, classifiers, decision boundaries, feature space, ground truth

9.1 Loss functions

This section defines loss as a measure of prediction badness against ground truth and frames training as minimizing total loss across training instances.

Key terms: loss function, prediction, ground truth, training data instance, total training loss, individual training data instance, iterative optimization, minimizes

9.1.1 Quantification and geometrical view of loss

This section reviews how supervised-training loss compares predictions with ground truth, aggregates mismatches across training data, and can be visualized as a complex loss surface.

Key terms: output vector, prediction vector, ground truth, GT vector, loss, forward pass, overall training loss, training data instance, n, superscript (i)

9.1.2 Regression loss

This subsection defines regression loss as the L2-norm error between a model output vector and its ground-truth vector for one training instance.

Key terms: regression loss, L2 norm, output vector, GT vector, components, N-dimensional, number of classes, summation

9.1.3 Cross-entropy loss

This section reviews cross-entropy as a classification loss that penalizes a model according to the probability it assigns to the correct class, including its two-class form.

Key terms: cross-entropy loss, ground truth, GT, one-hot vector, prediction vector, class probability, correct class, ground-truth class, negative log, logarithm

9.1.4 Binary cross-entropy loss for image and vector mismatches

This section applies binary cross-entropy to measure mismatches between normalized images or vectors, using image reconstruction in an autoencoder as the motivating example.

Key terms: binary cross-entropy loss, normalized tensors, ground truth, pixels, autoencoder, embedding, compressed representation, reconstruction, reconstruction loss, minimum

9.1.5 Softmax

This section explains how softmax converts a classifier’s unbounded class scores into smooth, normalized class probabilities while preserving the winning class.

Key terms: score vector, predicted label, max score, softmax function, softmax vector, predicted probability, argmaxonehot, one-hot vector, softmax, continuous

9.1.6 Softmax cross-entropy loss

This section explains why classifier networks commonly combine a final softmax layer with cross-entropy loss and illustrates how that loss rewards confident correct predictions.

Key terms: softmax, cross-entropy loss, softmax cross-entropy loss, ground-truth probabilities, classifier, one-hot vector, GT, softmax output, class probability, single operation

9.1.7 Focal loss

This section introduces focal loss, which reweights binary cross-entropy so training concentrates on hard rather than easy examples, especially under class imbalance.

Key terms: data imbalance, easy examples, hard examples, ground truth, GT, binary CE loss, (1-y)^γ, y^γ, γ, focal loss

9.1.8 Hinge loss

This subsection explains multiclass hinge loss as a margin-based classification loss that stops penalizing scores once the correct class is sufficiently ahead of every incorrect class.

Key terms: hinge loss, softmax CE loss, margin, multiclass SVM loss, ground-truth class, correct-class score, incorrect-class score

9.2 Optimization

This section frames neural-network training as iterative optimization of a loss surface, introducing gradient-based parameter updates, learning rates, sampling, and epochs.

Key terms: loss, ground truth (GT), training data, loss surface, weights, biases, negative gradient, iteration, weight update, bias update

9.2.1 Geometrical view of optimization

This subsection frames neural-network optimization as iterative parameter updates in the negative loss-gradient direction.

Key terms: optimization, gradient of the loss, parameters, weights, biases, negative gradient

9.2.2 Stochastic gradient descent and minibatches

This subsection explains how stochastic gradient descent reduces the cost of gradient computation by using random minibatches rather than the entire training dataset.

Key terms: training dataset, gradient of the loss function, epoch, O(n2), stochastic gradient descent, SGD, minibatch, random sampled subset, gradient, weight parameters

9.2.3 PyTorch code for SGD

This subsection implements minibatch SGD in PyTorch for a three-class height-and-weight classifier, covering data loading, model and loss setup, and the training loop.

Key terms: torch.utils.data.Dataset, __len__, __getitem__, DataLoader, minibatch, batch_size, linear layers, softmax, cross-entropy loss, CE loss

9.2.4 Momentum

This section explains how momentum combines current and past gradient updates to reduce noisy zigzags, carry optimization through small flat regions, and emphasize recent descent directions.

Key terms: momentum, stochastic gradient estimates, minibatch, downhill component, loss surface, flat region, zero gradient, past update, momentum-based gradient descent, momentum equation

9.2.5 Geometric view: Constant loss contours, gradient descent, and momentum

This section uses a two-weight quadratic loss to visualize why gradient descent moves inward across constant-loss contours and why momentum reaches low-loss regions in fewer steps.

Key terms: constant loss contours, loss surface, concentric circles, global minimum, zero-loss contour, gradient, negative gradient, orthogonal direction, constant loss contour, radially inward

9.2.6 Nesterov accelerated gradients

This section explains how Nesterov accelerated gradients reduce momentum overshooting by evaluating the gradient at a look-ahead destination rather than the current point.

Key terms: Nesterov’s accelerated gradient-based optimization, estimated destination point, vanilla momentum-based approach, weighted average, gradient, previous step’s update, overshooting, minimum, estimated destination, opposite direction

9.2.7 AdaGrad

This section introduces AdaGrad as an optimizer that assigns each parameter an adaptive learning rate based on its history of squared gradients.

Key terms: learning rate, per-parameter LR, loss surface, parameter vector, gradient dimensions, AdaGrad, state vector, squared partial derivatives, gradient vector, Hadamard operator

9.2.8 Root-mean-squared propagation

This section explains how RMSProp replaces AdaGrad’s ever-growing squared-gradient accumulator with a decaying weighted average so per-parameter learning rates remain adaptive without vanishing.

Key terms: AdaGrad, state vector, learning rate, partial derivatives, RMSProp, squared gradient magnitude vectors, γ, dimension-adaptive, unroll the recursion, weighted sum

9.2.9 Adam optimizer

This section explains how Adam combines momentum-style gradient averaging with RMSProp-style adaptive scaling, then corrects their early-iteration bias.

Key terms: Adam, state vectors, momentum, RMSProp, β1, β2, bias correction, v̂t, ŝt, past values

9.3 Regularization

This section introduces regularization as a way to prevent overfitting and contrasts overfitting with underfitting through their causes and training-versus-test performance.

Key terms: abstractions, training instances, inferencing, overfitting, expressive power, perceptrons, weights, training data, testing data, regularization

9.3.1 Minimum descriptor length: An Occam’s razor view of optimization

This section motivates regularization as choosing a simple solution among the many neural-network parameter settings that can minimize the same loss.

Key terms: loss function, weights, biases, Heaviside step function, parameter values, Occam’s razor, regularization, regularization penalty, R(θ), L(θ)

9.3.2 L2 regularization

This section defines L2 regularization as adding a squared weight-vector norm penalty to the loss and shows how its strength is configured as weight decay in PyTorch.

Key terms: L2 regularization, L2 norm, Euclidean norm, weight vector, regularized loss, lambda, weight decay, PyTorch, optimizer, L2-regularized loss

9.3.3 L1 regularization

9.3.4 Sparsity: L1 vs. L2 regularization

This section explains why L1 regularization produces sparse zero-valued weights whereas L2 regularization usually produces small but nonzero weights.

Key terms: L1 regularization, L2 regularization, sparse models, dense weight vectors, gradient, weights

9.3.5 Bayes’ theorem and the stochastic view of optimization

This section recasts supervised loss minimization as maximum-likelihood or maximum-a-posteriori probabilistic optimization.

Key terms: training instance, ground truth, network parameters, likelihood, mutually independent, loss function, maximum likelihood estimation, MLE, unregularized loss, optimal parameter set

9.3.6 Dropout

This section presents dropout as a training-only regularizer that randomly disables nodes to reduce overfitting and effectively simulate an ensemble of subnetworks.

Key terms: dropout, perceptron, training, inferencing, probability p, off probability 1−p, overfitting, co-adaptation, regularization, L2 regularization

9.4 Summary

This summary connects loss selection, gradient-based optimization, and regularization as the components of neural-network training that seek accurate parameters without overfitting.

Where this is used later

Concepts explained in this chapter

← Chapter 8: Training neural networks: Forward propagation and backpropagation Chapter 10: Convolutions in neural networks →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.