0:00Intro: MOFUSA Tech Academy
Welcome to MOFUSA Tech Academy. Beyond learning, towards mastery.
0:09Ten layers, one straight line: the hook
Last episode, two layers of neurons solved a problem one neuron couldn't. So why not stack ten layers? Or a hundred? Watch this. A ten-layer network, with one small thing removed: the bend inside each neuron, the activation function. Its output is a dead straight line. Ten layers of neurons, and it's no smarter than a single one. Switch the bends back on, and suddenly the network can follow any curve. Today we'll build full multi-layer networks, see exactly why those little bends are the whole secret, and meet a famous theorem that says a big enough network can approximate almost any function.
Season Two, Module Seven, stop two: multi-layer networks.
1:01Anatomy of a network
Let's meet a real network. Brightcart's drivers sometimes write numbers by hand on delivery notes, and a network reads them. Each handwritten digit is a tiny image, eight by eight pixels, so sixty-four numbers. Those sixty-four values form the input layer. They feed into a hidden layer of thirty-two neurons. Every input connects to every hidden neuron, which is why this is called a fully connected, or dense, layer. And the hidden layer feeds an output layer of ten neurons, one for each digit from zero to nine. How many parameters is that?
Sixty-four times thirty-two weights, plus thirty-two biases, is two thousand and eighty. Then thirty-two times ten, plus ten: three hundred and thirty. In total, two thousand four hundred and ten numbers to learn. Small by today's standards, as we'll see.
1:58The forward pass as matrices
Computing a network's output is called the forward pass, and it's just matrix multiplication, layer by layer. The input vector is multiplied by the first layer's weight matrix, the bias is added, and each result goes through the activation function. That gives the hidden layer's values. Then the same again: multiply by the next weight matrix, add the bias, and for classification apply softmax to get ten probabilities. Watch a handwritten seven flow through. Signals pulse forward, layer by layer, and the output for "seven" lights up highest.
Every layer follows the same recipe: activation of weights times the previous layer, plus bias. And just like in episode two, we can stack a whole batch of images into a matrix and push them all through at once, which is exactly what graphics cards are built for.
2:52Why activation functions are essential
Why did the ten-layer network collapse to a straight line? Let's see it with real numbers. Without activations, the first layer computes W one times x, and the second computes W two times that. But matrix multiplication can be grouped: W two times W one is just another matrix. With these two matrices, the product is two, four, four, three. So two layers do exactly what one layer with this single matrix would do. Stack a hundred linear layers and they still collapse into one. Remember the grid-bending picture from episode two.
Two linear transformations in a row are still a linear transformation: straight lines stay straight. Put a non-linear activation in between and the space can crease and fold. And folding is what lets the network untangle complicated data. So the activation function isn't a detail. It's the reason depth works at all.
3:52Sigmoid, tanh, ReLU and GELU
Here's the gallery of activation functions you'll meet most often. The sigmoid squashes everything into zero to one. It's useful for outputs that are probabilities, but inside a deep network it has a problem: its slope is at most a quarter, and it's almost flat at both ends. We'll see in episode twenty-eight why that's a big deal. Tanh is a close cousin, ranging from minus one to one and centred on zero, which often helps hidden layers learn a bit faster than the sigmoid. But it also flattens out at the ends. And then there's ReLU, the rectified linear unit: zero for negative inputs, and the input itself for positive ones.
It's almost embarrassingly simple, cheap to compute, and it doesn't flatten out for positive values. Its spread in the early twenty-tens made deep networks much easier to train, and it's still a default choice. ReLU has one weakness: a neuron that only ever receives negative inputs outputs zero forever, and stops learning. That's called a dead neuron. Leaky ReLU gives negative inputs a small slope to prevent it. And GELU, a smooth relative of ReLU, is the standard choice inside many transformers, which we'll build in Module Ten.
5:19Build any curve from ReLU hinges
How can neurons possibly represent curves? Let's build one from parts. Here's Meera's discount curve from Module Three. A single ReLU neuron, shifted and scaled, is a hinge: flat, then a straight ramp. Add hinges together and you get a bendy line made of straight pieces. With three hinge neurons, we can follow the curve in three pieces. The worst error is about one percentage point. With six neurons, the pieces get shorter and the error drops to about a quarter. Pause and predict: double it again, to twelve neurons.
How much smaller does the error get? About four times smaller: under seven hundredths. The approximation is now indistinguishable from the curve. Halve the piece length, and for a smooth curve like this, the error falls by about four. This is the intuition behind a famous result, the universal approximation theorem. A network with a single hidden layer and enough neurons can approximate any continuous function on a bounded range as closely as you want. But read the fine print. The theorem says the right weights exist.
It doesn't say how many neurons you'll need, and it doesn't promise training will find them.
6:44Output layers and loss functions
The hidden layers can use ReLU, but the output layer must match the task, and so must the loss. For regression, like predicting delivery minutes, use a single output with no activation at all, so it can produce any number, and train with mean squared error. For a yes-or-no question, like churn, use one sigmoid output with binary cross-entropy. For choosing one of several classes, like which digit, use softmax outputs with categorical cross-entropy. And when an example can have several labels at once, say a product that's both a gift and fragile, use one sigmoid per label.
These pairings come straight from the cost functions we've already studied. A neural network just learns a richer function before the final step.
7:36Depth vs width
If one hidden layer is enough in theory, why build deep networks? Efficiency. Think of folding a strip of paper. Fold it once, then fold the folded strip again, and again. Each fold doubles the layers, because every new fold reuses all the folds before it. Deep networks work in a similar way: each layer builds on the patterns found by the previous one. Researchers have shown that deep ReLU networks can create vastly more linear pieces than shallow networks with the same number of neurons. There's an intuitive story too.
In an image network, early layers detect edges, later layers combine edges into shapes, then parts, then whole objects. Each layer builds a slightly more abstract description, and we'll see exactly that in Module Eight. The catch is that deep networks are harder to train. The rest of this module is about exactly how we train them, and the tricks that make depth work.
8:40Try it yourself: a forward pass with ReLU
Your turn to run a network. Two inputs, one and two; two hidden ReLU neurons; one output. Pause and compute the hidden values and the output. First hidden neuron: one times one, minus one times two, plus zero: minus one. ReLU turns negative values into zero, so this neuron is switched off. Second neuron: half of one, plus half of two, minus one: zero point five, which ReLU passes through unchanged. Output: one times zero, plus two times zero point five, plus zero point five: one point five. Notice what ReLU did: for this input, the first neuron simply dropped out of the calculation.
A different input might switch it back on. A ReLU network is like a huge collection of straight-line pieces, with the input deciding which pieces are active.
9:41Counting parameters as networks grow
Parameter counts grow quickly. Our digit network, sixty-four to thirty-two to ten, has two thousand four hundred and ten parameters. Add a wider hidden layer and an extra one, sixty-four to a hundred and twenty-eight to sixty-four to ten, and it jumps to over seventeen thousand. The rule is simple: a dense layer from n inputs to m outputs has n times m weights plus m biases. Large language models have billions of parameters, and most of them live in big matrices exactly like these.
10:15Choosing activations in practice
In practice, activation choices are fairly settled. For hidden layers, ReLU is a solid default; switch to Leaky ReLU if you find many neurons have died, and expect GELU or similar smooth variants inside transformers. For outputs, match the task: no activation for regression, sigmoid for yes-or-no or multiple labels, softmax for choosing one class. And avoid stacking many sigmoid or tanh layers deep inside a network, for reasons we'll see in episode twenty-eight. A useful check while training: what share of your ReLU neurons output zero for every example?
If it's large, they've died.
11:02Why not just one enormous layer?
The universal approximation theorem says one wide layer is enough in principle. So why do practitioners build deep networks? Because composition is efficient. Patterns in the real world are built from parts: pixels form strokes, strokes form digits; letters form words, words form sentences. A deep network can reuse what each layer learned, building complex features from simpler ones, often with far fewer neurons than a single enormous layer would need. The price is that very deep networks are harder to train, which is exactly what episode twenty-eight solves.
11:41What the hidden layer learns, visually
Here's what the hidden layers actually do, made visible. Two classes, tangled together like interleaved spirals: no straight line can separate them. A small network trains on them. Now plot the data as the first hidden layer sees it: partly untangled. As the second layer sees it: almost separable by a straight line. Each layer bends the space a little more, until the final layer can draw a simple line. That's the grid-warping picture from episode two, happening inside a real network.
12:16Common beginner mistakes
Some mistakes catch nearly every beginner. Using the wrong output activation, like softmax for predicting a delivery time. Pairing the wrong loss with the output, like squared error on softmax probabilities for classification. Feeding in unscaled inputs. Getting layer shapes wrong, the shape rule from episode two strikes again. And building a huge network for a tiny dataset, which simply memorises it. Check these five, and most early networks start behaving.
12:47Myth vs Fact
Myth: the universal approximation theorem means neural networks can learn anything. Fact: it only says a good approximation exists. It doesn't guarantee gradient descent will find it, that the network will be a practical size, or that it will generalise beyond its training data. Those are the real challenges, and they're what the rest of this module is about.
13:11Recap
Let's recap. A network computes each layer as an activation of weights times the previous layer plus a bias. Without non-linear activations, every layer collapses into one. Sigmoid, tanh and ReLU are the classic choices, with ReLU and its relatives dominating hidden layers today. The output layer and the loss must match the task. And with enough neurons a network can approximate any continuous function, while depth lets it do so efficiently. One sentence to remember: weights move the space, and activations bend it.
13:50Next: backpropagation
Mission complete. Brightcart's digit reader has an architecture: sixty-four inputs, thirty-two hidden neurons, ten outputs, and two thousand four hundred and ten parameters. And we know why each layer needs its bend. But how do we set two thousand four hundred and ten dials, or, in a language model, billions? For each one, we need to know which way to turn it. Next episode: backpropagation, the algorithm that makes deep learning possible, worked through step by step with real numbers. See you on the map.