Why nonlinearity

AI from scratch · 6 of a series

Why nonlinearity: lesson transcript

1. The ring, again

This café is busy only on mild, moderately sunny days: a ring of quiet days around a core of busy ones. One neuron makes one straight cut, and the best cut still gets seventeen days wrong. We need something that can bend.

2. Stack them

The obvious move: use more neurons. Three of them each look at the two inputs and make their own cut; a fourth neuron reads their three outputs and makes the final call. That fourth one is a neuron like any other: a weighted sum, then a threshold.

3. Three cuts mixed is… one cut

Here are the three hidden cuts, faint. Mix them with the sliders and watch the final boundary. However you weight them, it is a straight line. Multiply out the algebra and every weighted sum of weighted sums collapses to a single weighted sum: a stack of plain neurons is still one neuron.

4. Add a bend

Change one thing: a hidden neuron passes on its value only when it is positive, and sends zero otherwise. That kink is called ReLU. On the map, a neuron used to shade both sides of its cut, positive and negative. Now one side goes dark. The neuron has stopped being a line and become a half-plane.

5. Now the mix can fold

Same three cuts, same sliders, but each hidden neuron now only speaks on its own side. Where two half-planes overlap the boundary bends. With three of them the output can fence off a region: one cut could never do that. The bends are where all the power comes from.

6. Four bends make a ring

Train four bent neurons with gradient descent, exactly as before, and their four cuts arrange themselves around the busy core. The output fences it in from every side. Zero wrong, from a rule that is nothing but straight cuts and kinks.

7. Name it: the activation function

The bend is the *activation function*, and it is the reason deep networks are more than a very expensive straight line. ReLU is the everyday choice; the smooth S-shapes came first. Any of them works. Without one, a thousand layers collapse to a single cut.

8. Did it land?

Someone builds a very deep network but forgets the activation function.

Check your understanding

A network with ten hidden layers but no activation function is trained on the ring café. What is the best it can do?

Each layer is a weighted sum of the layer before, and a weighted sum of weighted sums is just a weighted sum: the ten layers multiply out to one. The boundary is one straight line no matter how deep you go. Only the kinks let cuts combine into folds.