Lesson 4.1 · 9 min read · about 55 min to master at a very slow pace
Sigmoid, tanh, ReLU and Friends
The common activation functions side by side: their formulas, ranges and derivatives, where each is used, and why the sign function cannot be trained by gradient descent.
The functions
| Activation | Formula | Range | Derivative | Typical use and limitation |
|---|---|---|---|---|
| Sigmoid | (0, 1) | , at most 0.25 | Binary output probability; saturates | |
| tanh | (−1, 1) | , at most 1 | Zero-centred hidden units; still saturates | |
| ReLU | [0, ∞) | 0 for , 1 for | Default for hidden layers; can "die" | |
| Sign | if , if | {−1, +1} | 0 almost everywhere | Threshold constructions; untrainable by gradients |
| Linear | (−∞, ∞) | 1 | Regression output | |
| Softmax | (0, 1), sums to 1 | Section 6 | Multi-class output probabilities |
Two derivatives to know by heart
Sigmoid. . It peaks at , where and . At : , . At : , . Large inputs saturate the unit and kill its gradient.
tanh. , which peaks at 1. tanh is a rescaled sigmoid, , and being zero-centred it often trains a little better in hidden layers.
Why the sign function can't be trained
Away from , a small change in the weights doesn't change a sign unit's output at all, so its derivative is zero almost everywhere (and undefined at 0). Gradient descent gets no signal about which way to move. That's why trainable networks use smooth or piecewise-linear activations instead.
Stuck? Common doubts
Questions real learners asked while studying this lesson. They stay closed so they don't spoil your own thinking: open only the ones you need.
First passHow do I remember the sigmoid derivative?
Write and differentiate: . Since , this is . In backpropagation you already have from the forward pass, so the derivative costs one multiplication: .
Going deeperHow do I derive σ′ = σ(1 − σ)? Why isn't the derivative of e^(−z) something like −e^(−2z)?
Write and use the chain rule, outside then inside:
- Outside, power rule: , so you get .
- Inside, exponential rule: . The 1 is a constant, so it vanishes. The exponent stays ; you only multiply by its derivative, .
- Multiply:
Thumb rule: "The power rule lowers the power. The exponential rule keeps the exponent and multiplies by its derivative." So , never .
Cheatsheet
Sigmoid
tanh and ReLU
Sign is untrainable
Check your understanding
Score 75% or more to master this lesson and earn XP. Answer first, then check.