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.

Not startedJump to quiz

The functions

-1012-4-2024z
sigmoid σ(z)tanh(z)ReLU max(0, z)
Sigmoid squashes to (0, 1), tanh to (−1, 1); ReLU is zero for negative inputs and the identity for positive ones.
00.250.51-4-2024z
σ'(z) ≤ 0.25tanh'(z) ≤ 1ReLU' = 0 or 1
Derivatives. Sigmoid and tanh fade to zero for large |z| (saturation). ReLU's derivative is exactly 1 on the positive side.
ActivationFormulaRangeDerivativeTypical use and limitation
Sigmoid(0, 1), at most 0.25Binary output probability; saturates
tanh(−1, 1), at most 1Zero-centred hidden units; still saturates
ReLU[0, ∞)0 for , 1 for Default for hidden layers; can "die"
Sign if , if {−1, +1}0 almost everywhereThreshold constructions; untrainable by gradients
Linear(−∞, ∞)1Regression output
Softmax(0, 1), sums to 1Section 6Multi-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:

  1. Outside, power rule: , so you get .
  2. Inside, exponential rule: . The 1 is a constant, so it vanishes. The exponent stays ; you only multiply by its derivative, .
  3. Multiply:

Thumb rule: "The power rule lowers the power. The exponential rule keeps the exponent and multiplies by its derivative." So , never .

Cheatsheet

Sigmoid

; (at ). Saturates for large .

tanh and ReLU

tanh , . ReLU , derivative 0 or 1.

Sign is untrainable

Its derivative is 0 almost everywhere, so gradient descent gets no signal. Use sigmoid, tanh or ReLU.

See every cheatsheet by category →

Check your understanding

Score 75% or more to master this lesson and earn XP. Answer first, then check.

Q1calculateA sigmoid unit outputs . What is its derivative at that point?
Q2conceptWhat is the largest value the sigmoid derivative can take, and where?
Q3conceptWhy can't networks of sign-activation units be trained by gradient descent?
Q4interpretA hidden unit has pre-activation . Compared with , how much gradient does a sigmoid pass through it?
Q5conceptWhat advantage does tanh have over the sigmoid for hidden units?