101 puffs

Chapter 2 · Neural networksPuff 7 of 23

Why layers can bend the line

One neuron can only draw a straight line, as the last puff showed. But most patterns aren’t straight: the dots below dip, rise and dip again. What happens if you give a network a whole row of neurons? And what is it about them that lets the line bend?

Guess first

Stack ten neurons that only multiply and add, with nothing that bends or squashes. What can the stack draw?

Play with it

Fig. 1 · Adding up hinges Bending a line to fit a wave

Slide the number of hidden neurons from 1 to 12 and watch the blue line bend. Then press “Remove the bends”.

How it works

Tap a step to see it in the figure.

Check yourself

Why do neural networks need activation functions?

Go deeper: the mathReLU, why linear layers collapse, and what “universal” means

The activation

An activation function is what a neuron does to its total after adding up. ReLU (rectified linear unit) keeps positive totals and zeroes the rest:

ReLU(z) = max(0, z)

The network on this page

One input x, a hidden layer of n ReLU neurons (hidden because you only see their effect through the output), and one output neuron that adds them up:

f(x) = v1 ReLU(w1x + b1) + …
+ vn ReLU(wnx + bn) + c

To keep the picture honest and simple, the page fixes each wi = 1 and sets bi so the hinges sit evenly across the range, at x = 5. The output knobs vi and c are then found exactly by least squares, the same “best fit” formula as in puff 1, just with more knobs: v = …. The typical miss is …. Because the hinges can’t move, one or two of them can even do slightly worse than a plain straight line: half of a lone hinge is stuck flat. In a real network the hinge positions are learned too, by the nudging you’ll see in the next two puffs, so they move to wherever bends are needed.

Why it collapses without the bend

Without an activation, a layer just multiplies by a table of weights W and adds biases b. Do it twice and you can multiply out the brackets:

W2(W1x + b1) + b2
= (W2W1)x + (W2b1 + b2)

That is one layer again, with weights W2W1. However many layers you stack, it all folds into a single straight line. With the bends removed, the best this page’s network can do is y = …. Many settings of the knobs give that same line, so the figure shows the one closest to the knobs the network had with its bends, which lets you see each neuron’s own straight line.

How far can bending go?

The universal approximation theorem says one hidden layer with enough neurons can match any smooth curve as closely as you like, on a limited range. George Cybenko proved it in 1989 for S-shaped activations, Kurt Hornik in 1991 for a much wider family, and Leshno and colleagues in 1993 showed that any activation except a plain polynomial works, ReLU included. The catch: it promises that good weights exist, not how many neurons you need or how to find them. In practice networks stack several layers, because layers that bend the bends of the layer before can make far more pieces from the same number of neurons (Montúfar and colleagues, 2014). ReLU itself became popular after Nair and Hinton used it in 2010.

Sources

  1. G. Cybenko, “Approximation by superpositions of a sigmoidal function”, Mathematics of Control, Signals and Systems 2, 303–314, 1989.
  2. K. Hornik, “Approximation capabilities of multilayer feedforward networks”, Neural Networks 4(2), 251–257, 1991.
  3. V. Nair and G. E. Hinton, “Rectified linear units improve restricted Boltzmann machines”, Proceedings of ICML, 807–814, 2010.
  4. I. Goodfellow, Y. Bengio and A. Courville, Deep Learning, MIT Press, 2016, section 6.4.
  5. The wavy data are made up for this page: a smooth wave plus a little noise.