Lesson 8.5 · 8 min read · about 55 min to master at a very slow pace

Hyperparameters and a Training Recipe

What hyperparameters are, how to search them, how to read a learning rate from the loss curve, and a seven-step procedure for training a network that works.

Not startedJump to quiz

Hyperparameters

Everything not learned by gradient descent: the number of layers and units, activations, learning rate, batch size, number of epochs, regularisation strength , dropout rate and initialisation. Choose them on the validation set.

  • Grid search: every combination; cost grows exponentially with the number of hyperparameters.
  • Random search: usually better once you have more than two or three hyperparameters.
  • Bayesian optimisation, or by hand guided by learning curves.
  • Search and on a log scale (0.001, 0.01, 0.1, …).

Reading the learning rate from the loss curve

00.511.50102030405060epochtraining cost
η too small: slowη about rightη too large: oscillatesη far too large: diverges
The learning rate matters most. A slowly falling cost: raise η. An oscillating or exploding cost: lower it.

A training recipe

  1. Data: shuffle; split train/validation/test; normalise with training statistics; encode categories.
  2. Task: pick the output layer and loss (Section 6).
  3. Sanity check: a reasonably sized network should drive the training cost near zero on about 100 examples. If it can't, there's a bug in the code or data.
  4. Train with mini-batch gradient descent or Adam, recording training and validation curves every epoch.
  5. Underfitting (both errors high): bigger network, longer training, higher ; check normalisation and activations.
  6. Overfitting (large gap): more data or augmentation, weight decay, dropout, early stopping, or a smaller network.
  7. Select hyperparameters on validation, evaluate once on the test set, and report that number.

Stuck? Common doubts

Questions real learners asked while studying this lesson. They stay closed so they don't spoil your own thinking: open only the ones you need.

First passWhy should a network be able to overfit 100 examples?

Because memorising a tiny dataset is the easiest thing a network can do. If it can't even do that, the problem isn't generalisation: it's a bug (wrong labels, a broken gradient, a learning rate far off). It's a quick test that saves hours of tuning.

Going deeperWhat did the lab show matters most for training a small XOR network?

Width had the largest effect: 2 hidden units converged in about 80% of random starts, 3 or more in all of them. The learning rate barely mattered within 0.3–3, but a huge one (300) pushed every unit into saturation on the first step and training stalled at loss 0.25. Very small initial weights (0.1) left all hidden units identical, on a plateau.

Cheatsheet

Training recipe

Split + normalise → output/loss → overfit 100 examples → train, log curves → underfit? bigger/longer → overfit? regularise → test once.

Learning-rate diagnosis

Slow decrease: η too small. Oscillating or diverging cost: η too large. Search η and λ on a log scale.

See every cheatsheet by category →

Check your understanding

Score 75% or more to master this lesson and earn XP. Answer first, then check.

Q1interpretThe training cost oscillates wildly and occasionally jumps up. What should you change first?
Q2applyYour new network can't drive the training loss near zero even on 100 examples. What does this most likely indicate?
Q3conceptWhy search learning rates like 0.001, 0.01, 0.1, 1 rather than 0.1, 0.2, 0.3, 0.4?
Q4applyTraining and validation errors are both high and close. Which change fits the recipe?
Q5conceptWith more than two or three hyperparameters, why is random search usually preferred to grid search?