MODULE 16 ยท Middle-track ยท 2.5 hours

If you have never overfitted a network, you cannot train one

The network without any magic: neuron, layers, backpropagation. Then we overfit it on purpose to see exactly what that looks like on the training curves.

Open this module in the simulator All 23 lessons

The first two modules are free, no card. The rest are $20/month.

๐Ÿข The situation

The team's Friday tech talk. Lena:

"You've already seen that boosting beats neural nets on tables. But ahead of us are images (module 17) and deeper text work โ€” there neural networks have no alternative. Today we dissect how they work, without magic: the neuron, layers, backprop. Homework โ€” train a net in PyTorch and overfit it on purpose to see what that looks like. Whoever hasn't overfitted a network doesn't know how to train one."

๐ŸŽฏ Your task

  1. Understand the network's anatomy: neuron, activations, layers, backpropagation.
  2. Train a network in PyTorch: write the training loop by hand.
  3. See overfitting on the learning curves and defeat it.

๐Ÿ“š Theory

The neuron and layers

A single neuron = that same linear model: output = activation(wยทx + b). A network is layers of neurons: one layer's outputs become the next layer's inputs. A composition of linear layers with non-linear activations between them can approximate arbitrarily complex functions.

Activations: without them a stack of linear layers collapses into one linear model. The hidden-layer standard is ReLU max(0, x): simple, fast, doesn't "vanish" like sigmoid. At the output: sigmoid (binary classification), softmax (multiclass), nothing (regression).

How the network learns: backpropagation

The same gradient descent from module 4, but the gradients over millions of weights are computed by the chain rule from output to input โ€” that is backprop. One training step:

  1. Forward: run the batch, get predictions and the loss.
  2. Backward: loss.backward() โ€” PyTorch computes all gradients itself (autograd).
  3. Optimizer step: optimizer.step() โ€” update the weights; optimizer.zero_grad() โ€” reset the gradients (they accumulate otherwise โ€” rookie bug #1).
A fully connected network inputs (features) hidden layer + ReLU output โ† backprop: gradients flow right to left The training ECG stop here train val โ†‘ = overfitting epochs โ†’
Left: the forward pass goes left to right; backprop gradients flow right to left. Right: diverging train/val curves are the signal to stop.

The training vocabulary

Learning curves โ€” the training's ECG


What to remember

  • A neuron = a linear model + an activation; depth + non-linearity = expressiveness.
  • The loop: forward โ†’ loss โ†’ backward โ†’ step โ†’ zero_grad.
  • The learning rate is hyperparameter #1; the train/val curves are the main diagnostic tool.
  • Dropout, weight decay, early stopping โ€” the standard anti-overfitting kit.

Next in this module: Practice: PyTorch

Open the module โ†’

Nearby lessons

15 Support is drowning in tickets 17 Defects on the conveyor: computer vision

The whole program โ€” 23 lessons