Learning is the parameter-estimation step that turns a chosen model architecture into a usable model. A model is a parameterized proxy for an unknown function from inputs to desired outputs; learning selects weights, and often biases, so predictions on training inputs match their targets as closely as possible. Once those values are fixed, the model can perform inferencing on new inputs. section 1.2 section 1.3.3
For supervised neural networks, training data consists of sampled input–target pairs, where targets are ground truth commonly produced through labeling. Learning adjusts network parameters to reduce disagreement with those targets. Good training performance alone does not guarantee accurate results on unseen inputs: the architecture needs sufficient expressive power, and the training data must represent the real data adequately. section 7.1 section 7.6
Mathematically, learning is iterative optimization. A loss function measures the badness of a prediction relative to its target; total training loss aggregates that error over training instances. Starting from initial parameter values, each iteration makes a small parameter adjustment intended to lower loss. Gradient descent moves in the negative-gradient direction, while backpropagation supplies gradients for multilayer networks. section 9.1 section 8.4 section 3.5.1
A typical supervised learning cycle is:
- Choose an architecture: a parameterized function expected to approximate the unknown input-to-output relationship. section 1.3.3
- Initialize its weights and biases, then pass a batch of training inputs through the model to produce predictions or raw scores. section 9.2.3
- Compute loss by comparing predictions with ground-truth targets. section 9.1
- Clear prior gradients, backpropagate the loss, and let an optimizer update parameters. section 9.2.3
- Repeat across batches and epochs, then assess held-back test data rather than using it to train. section 8.4
Learning a linear relationship
For observations generated from a noisy linear relationship, a linear model predicts ỹ = w·x + b. Squared prediction errors are averaged or summed into a loss. Repeatedly updating w and b opposite their loss gradients can recover parameters close to the underlying relationship: the illustrated result learns approximately y = 1.50059x + 2.746823 for a true function y = 1.5x + 2.73. section 3.5.1
Training a three-class classifier
A classifier can learn from height and weight data labeled as man, woman, or child. In a PyTorch loop, batches pass through two linear layers; cross-entropy loss compares raw scores to class targets; SGD updates the model. Predictions move closer to the labeled class distribution as loss falls across epochs. section 9.2.3 section 9.2.3
Learning is not guaranteed to find globally optimal parameters. Optimization can fail to converge or stop at a local minimum, and initial weights can affect convergence. When accuracy is inadequate, practical responses include more training data, a different loss function, a different architecture, or retraining from another random start. section 8.4 section 9.2.3
The same core idea extends beyond ordinary supervised classification. A variational autoencoder learns by minimizing a weighted combination of reconstruction loss, which keeps reconstructed inputs close to originals, and KL-divergence loss, which aligns encoder-produced latent distributions with a target distribution. section 14.7.2
Listing 9.10 PyTorch code for one training loop
def train_loop(epoch, data_loader, model, loss_fn, optimizer):
for X_batch, y_gt_batch in data_loader: #1
scores = model(X_batch) #2
loss = loss_fn(scores, y_gt_batch) #3
optimizer.zero_grad() #4
loss.backward() #5
optimizer.step() #6
Inspect the minimal PyTorch training loop: forward pass, loss computation, gradient clearing, backward propagation, and optimizer step appear in their execution order. section 9.2.3























