0:00Intro: MOFUSA Tech Academy
Welcome to MOFUSA Tech Academy. Beyond learning, towards mastery.
0:09Why deeper networks got worse
Here's a puzzle that stumped researchers. If deeper networks are more powerful, adding layers should help, or at worst do nothing. Yet when people trained plain networks with dozens of layers, the deeper ones often did worse, even on their own training data. That's not overfitting. They simply weren't learning properly. It's like a game of telephone. Whisper a message through twenty people and it arrives garbled or faint. In a deep network, the learning signal, the gradient, has to travel backwards through every layer, and it can fade away or blow up.
Today: four inventions that solved this. Careful initialisation, normalisation, dropout, and an idea so simple it seems like cheating, the residual connection, which made networks with over a hundred layers trainable.
1:03Where we are on the map
Season Two, Module Seven, final stop: making deep networks train.
1:09Vanishing and exploding gradients
Remember backpropagation: on the way back, the gradient gets multiplied by a weight and an activation slope at every layer. A long chain of multiplications is dangerous. If the factors are smaller than one, the product shrinks fast. A sigmoid's slope is at most a quarter. Through five sigmoid layers, the signal drops to about one thousandth. Through ten, about one millionth. Through twenty, a trillionth. The early layers get almost no learning signal, so they barely change. That's the vanishing gradient. If the factors are bigger than one, the product explodes.
One and a half, multiplied across fifty layers, is over six hundred million. The updates become enormous, the weights fly off, and the loss turns into "not a number". That's the exploding gradient. To train deep networks, the signal has to stay about the same size as it travels through the layers, in both directions. Every invention today helps with that.
2:18Weight initialisation: Xavier and He
The first fix happens before training even starts: choosing the starting weights at the right scale. Here's a real experiment: a network ten layers deep, two hundred and fifty-six neurons wide, with random starting weights. We push data through and watch how spread out the activations are at each layer. Weights that are too large, with tanh: the neurons get pushed to the flat ends of the curve. Eighty-seven percent of them are stuck near plus or minus one, where the slope is almost zero. Weights that are too small: the signal shrinks layer after layer, to about one hundred-millionth of its size by layer ten.
Both are dead on arrival. Now the fix. Choose the weight variance as one over the number of inputs to each neuron, called Xavier or Glorot initialisation, and tanh activations stay in a usable range. For ReLU, which zeroes out half its inputs, use two over the number of inputs, called He initialisation. The spread stays steady all the way through ten layers: about zero point eight at layer one, and still between zero point eight and zero point nine at layer ten. The idea is simple: each layer should pass on a signal of roughly the same size as it received.
3:42Batch normalisation
The second fix keeps the signal in shape during training. It's called batch normalisation. As a network trains, the values flowing out of each layer keep shifting and stretching, so every layer is chasing a moving target. That was the original idea behind batch normalisation; researchers still debate exactly why it helps, but in practice it steadies training. For each neuron, take its values across the current mini-batch, subtract their mean, and divide by their standard deviation, exactly the standardisation from episode seven, but done inside the network, at every step.
Values of two, four, six and eight become about minus one point three, minus zero point four, plus zero point four and plus one point three. Then comes a clever touch: two learnable parameters, a scale and a shift, so the network can still choose whatever range is best for each neuron. It's not forced to stay at zero and one. At prediction time there may be no batch, so the network uses running averages it collected during training. Introduced in two thousand fifteen, batch normalisation made training faster and much less fragile, often allowing larger learning rates.
4:58Layer normalisation
Batch normalisation has a limitation: it depends on the other examples in the batch. With very small batches, or with sequences of different lengths, that gets awkward. Layer normalisation makes one small change: instead of normalising each neuron across the batch, it normalises across all the neurons of a single example. Picture the data as a grid. Batch norm normalises down the columns; layer norm normalises along each row. It works the same with a batch of one, which is why it, or its simpler cousin RMSNorm, is the standard choice inside transformers and language models.
5:41Dropout
The third invention fights overfitting, the memorisation we watched happen in the digit reader. It's called dropout, and it sounds almost reckless. During training, at every step, randomly switch off a fraction of the neurons, say half, with a different random half each time. The network has to make its predictions with whichever neurons survive. Why would that help? Because no neuron can rely on any particular partner being present, so each one has to learn features that are useful on their own. Another way to see it: every step trains a different thinned-out network, and they all share weights, so the final network behaves like an average of a huge ensemble.
Remember the wisdom of crowds from episode fifteen. One practical detail: during training, the surviving neurons' outputs are doubled, so the total signal stays the same size on average. At prediction time, all the neurons are switched on, and no scaling is needed.
6:43Residual connections: the gradient highway
And now the idea that changed everything: the residual connection. A normal block of layers transforms its input x into some output. A residual block adds the input back on at the end: the output is x plus F of x. There's a shortcut, a skip connection, that carries the input around the block unchanged. This does two wonderful things. First, the block only has to learn the change to make: the residual. If the best thing a layer can do is nothing at all, it just learns F equals zero, which is easy. So adding layers shouldn't make things worse: in principle, the deeper network can always fall back to copying, and in practice that's easy to learn.
Second, look at the gradient. The derivative of x plus F of x is one plus the derivative of F. That "one" is a highway. Gradients can flow straight back through the shortcuts, across fifty or a hundred blocks, without fading away. In two thousand fifteen, residual networks with a hundred and fifty-two layers won the ImageNet image-recognition competition. Today, residual connections are in nearly every deep network, including every transformer. And notice the echo of gradient boosting: each block adds a small correction to what came before.
8:05Gradient clipping
One last safety net for exploding gradients: gradient clipping. If the gradient's overall length is larger than a chosen limit, shrink it down to that limit, keeping its direction. A gradient of thirty, forty has length fifty. Clip it to five, and it becomes three, four: same direction, safe size. It's a standard precaution for recurrent networks, coming in Module Nine, and for large language models.
8:34Putting it all together
Put it all together and you get the recipe behind almost every modern deep network. Each block normalises its input, applies a well-initialised layer and an activation, uses dropout to regularise, and adds a skip connection around the whole thing. Stack dozens of these blocks. Train with AdamW, a warm-up and a decay schedule, and gradient clipping. Add one more ingredient, called attention, and this is very close to a transformer block, which we'll build at the end of this season.
9:09Try it yourself: the initial weight scale
A quick calculation. A layer receives two hundred and fifty-six inputs. What standard deviation should its starting weights have, with Xavier initialisation, and with He initialisation for ReLU? Pause and work it out. Xavier uses a variance of one over n: the square root of one over two hundred and fifty-six is one sixteenth, zero point zero six two five. He uses two over n: about zero point zero eight eight four. Small numbers, carefully chosen so the signal neither shrinks nor explodes as it passes through the layer.
Modern frameworks apply defaults like these automatically, but it's worth knowing what they are, especially when training goes strangely wrong.
10:01Normalisation quirks (train vs eval mode)
Normalisation has a few practical quirks. Batch normalisation behaves differently in training and in use: during training, it normalises with the current batch's statistics; at prediction time, it uses running averages. A classic bug is forgetting to switch the model into evaluation mode, so a customer's prediction changes depending on which other examples happened to be in the same batch. With very small batches, the batch statistics get noisy, which is one reason layer normalisation is preferred in many settings, including the transformers at the end of this season.
10:39Dropout in practice
Dropout is usually applied after dense layers, and inside attention, at rates anywhere from about ten to fifty percent, depending on the task. Too much, and the network underfits: even the training loss stays high. Too little, and it overfits. It must be switched off at prediction time, another reason to remember evaluation mode. Interestingly, very large language models trained on enormous datasets often use little or no dropout during pre-training, because the sheer amount of data already discourages memorisation.
11:15A tiny residual example
Let's put tiny numbers on a residual block. The input is zero point eight, and the block's layers add a small correction of zero point zero five, so the output is zero point eight five. On the way back, the local slope is one plus the slope of the layers. If the layers' slope is minus zero point two, the block's slope is zero point eight, not minus zero point two. Chain ten blocks like that, and you multiply numbers near one, instead of numbers near zero. That "one" from the shortcut is what keeps the gradient alive through very deep networks.
11:53Diagnosing training health
How do you tell whether a deep network is training healthily? Look beyond the loss. Plot the size of the gradients in each layer: tiny gradients in the early layers mean they're vanishing; sudden spikes mean they're exploding. Plot each layer's activations: how many ReLU neurons are dead, how many tanh neurons are saturated. And watch how much each update changes the weights relative to their size. Changes that are too large signal instability. These dashboards turn guesswork into diagnosis.
12:28The recipe, in order of importance
Here's the practical recipe, roughly in order of importance. Start with sensible initialisation and ReLU-family activations. Add normalisation. Add residual connections if the network is deep. Train with Adam or AdamW, with a warm-up and a decaying learning rate, and clip gradients. Then tune regularisation, dropout, weight decay, augmentation and early stopping, using validation data. You'll find this exact recipe inside every transformer block at the end of this season.
13:04Myth vs Fact
Myth: deep learning took off just because computers got faster. Faster hardware mattered enormously, and so did big datasets. But without techniques like ReLU, careful initialisation, normalisation, dropout, residual connections and better optimisers, deep networks would still be very hard to train. It took all three.
13:27Recap
Let's recap. Gradients are products of many factors, so in deep networks they can vanish or explode. Initialising weights at the right scale keeps the signal steady from the start. Batch and layer normalisation keep it steady during training. Dropout randomly thins the network to prevent memorisation. Residual connections let each block learn a correction and give gradients a highway back through the network. And clipping caps any gradient that still explodes. One sentence to remember: keep the signal steady, and give the gradient a highway home.
14:04Next: computer vision
Mission complete. Brightcart's networks can now go deep without forgetting how to learn. And that completes Module Seven, neural networks, from a single neuron to the full toolkit for training deep networks. Next, we teach networks to see. Brightcart has fifty thousand product photos to sort. A fully connected network would need an absurd number of weights for images. The solution is the convolution, an idea loosely inspired by how cells in the visual cortex respond to small regions of what we see. Welcome to computer vision.
See you on the map.