Machine learning with football · Chapter 8 · Neural networks

Activation functions

Without a nonlinear step between layers, a deep network is just a line. ReLU, sigmoid and tanh fix that.

Estimated time: 10 minutes · page 3 of 7

The nonlinear step

Chapter 3 passed a linear model through the sigmoid to get a probability. A neural network does the same at every neuron. It computes the weighted sum, then runs it through an activation function before handing it on. Because that step bends the numbers, stacking layers can build up shapes no single line can make.

ActivationFormulaOutput
Sigmoid1 / (1 + e−x)0 to 1
tanhtanh(x)−1 to 1, steeper
ReLUmax(0, x)0 for negatives, x otherwise

ReLU, the rectified linear unit, is the usual first choice. It's cheap to compute, and its gradient doesn't shrink toward zero the way the S-shapes do at their flat ends, which matters once networks get deep. Any function can serve as an activation, and different layers can use different ones.

Switch the activation on the board and the network retrains. Linear gives a flat slope, and the other three bend the map, each in its own way. A network is just neurons in layers, weights and biases between them, and an activation on each neuron.

Neural networks aren't always better than a well-chosen feature cross. They're a flexible alternative when you can't guess the cross.

Check yourself

Which activation is the usual first choice for hidden layers?
What does ReLU give for an input of −2.5? And for 1.7?

Leagues