Activation functions

core 9 minfundamentalsactivationsgradients

Builds on:Forward pass

The idea

The activation function plays two roles at once. Forward, it shapes what a layer can express — it is the only nonlinear ingredient in the network, the thing that stops a deep stack from collapsing into one affine map. Backward, it acts as a per-unit gradient gate: backprop multiplies by g′(z)g^{\prime}(z) at every layer, so the derivative of your activation gets raised, roughly, to the power of your depth.

That second role decided the history. Classic squashing functions:

σ(z)=11+e−z∈(0,1),tanh⁡(z)=ez−e−zez+e−z∈(−1,1)\sigma(z) = \frac{1}{1 + e^{-z}} \in (0,1), \qquad \tanh(z) = \frac{e^z - e^{-z}}{e^z + e^{-z}} \in (-1, 1)

with derivatives σ′=σ(1−σ)≤0.25\sigma^{\prime} = \sigma(1-\sigma) \le 0.25 and tanh⁡′=1−tanh⁡2≤1\tanh^{\prime} = 1 - \tanh^2 \le 1. Both saturate: for ∣z∣|z| beyond a few units the derivative is essentially zero, and the unit goes silent in the backward pass. Stack ten such layers and the early ones starve.

ReLU, max⁡(0,z)\max(0, z), broke the pattern by being piecewise linear: derivative exactly 1 whenever the unit is active — no shrinkage, no saturation on the positive side, trivially cheap. Its one failure mode is the dead unit: pre-activation negative for all inputs means zero output and zero gradient forever. Leaky ReLU (αz\alpha z for z<0z < 0, α≈0.01\alpha \approx 0.01) and GELU (z Φ(z)z\,\Phi(z), the transformer default) keep a small signal alive on the negative side.

Worked example

How badly does sigmoid throttle the backward pass? Its derivative at a few points:

zzσ(z)\sigma(z)σ′(z)=σ(1−σ)\sigma^{\prime}(z) = \sigma(1 - \sigma)
000.50.50.250.25 (the maximum)
220.8810.8810.1050.105
550.9930.9930.00660.0066

Now chain layers together. The activation contributes one factor per layer, so the best possible activation-derivative product through kk sigmoid layers (every unit sitting exactly at z=0z = 0) is 0.25k0.25^k:

Depth kkSigmoid best case 0.25k0.25^kReLU active path
20.06250.062511
5≈0.001\approx 0.00111
10≈9.5×10−7\approx 9.5 \times 10^{-7}11

And that is the optimistic bound — with realistic pre-activations like z=2z = 2 the per-layer factor is nearer 0.10.1, giving 10−1010^{-10} at depth 10. A gradient that small, multiplied into a sane learning rate, moves first-layer weights by nothing. The same table for ReLU is just 1 at every depth along active paths — which is the honest one-table summary of why deep learning waited for ReLU.

Cheat sheet

NameFormulaRangeDerivativeGotcha
Sigmoid1/(1+e−z)1/(1 + e^{-z})(0,1)(0,1)σ(1−σ)≤0.25\sigma(1-\sigma) \le 0.25saturates both tails; not zero-centered
Tanh2σ(2z)−12\sigma(2z) - 1(−1,1)(-1,1)1−tanh⁡2≤11 - \tanh^2 \le 1still saturates
ReLUmax⁡(0,z)\max(0, z)[0,∞)[0,\infty)00 or 11dead units
Leaky ReLUmax⁡(αz,z)\max(\alpha z, z)(−∞,∞)(-\infty,\infty)α\alpha or 11one more hyperparameter (α≈0.01\alpha \approx 0.01)
GELUz Φ(z)z\,\Phi(z)≈(−0.17,∞)\approx (-0.17, \infty)smooth, near 0/1costlier; transformer default
Softmaxezi/∑jezje^{z_i}/\sum_j e^{z_j}simplex—output probabilities and internal normalized weighting, notably attention

Decision rules

Symptoms → fixes