Activation Functions › Activation Function Comparison

Michael BrenndoerferApril 21, 20255 min read
Language AI HandbookAll chapters
Part 10 of 67Neural Network Foundations
Chapter 62Activation Functions › Activation Function Comparison
Reading section 9 of 16 · Activation Function Comparison · 5 minSection 9 of 16 · 5 min

Book contents

Section 9 of 16 · 5 min read

Activation Functions › Activation Function ComparisonOne section · Sections in this chapter9 / 16 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

To compare these functions, it helps to look at four properties: the output range, whether the function is zero-centered, the gradient at zero, and the computational cost.

Activation function properties summary. Zero-centered means the output distribution has mean close to zero, which reduces gradient sign correlation between layers.
FunctionOutput RangeZero-CenteredGradient at z=0z=0Saturates
Sigmoid(0,1)(0, 1)No0.250.25Both sides
Tanh(−1,1)(-1, 1)Yes1.01.0Both sides
ReLU[0,∞)[0, \infty)No00 (undefined)Negative
Leaky ReLU(−∞,∞)(-\infty, \infty)Approx.0.010.01No
ELU(−α,∞)(-\alpha, \infty)Approx.1.01.0Negative only
SELU(−λα,∞)(-\lambda\alpha, \infty)Yesλ≈1.05\lambda \approx 1.05Negative only
GELU≈(−0.17,∞)\approx(-0.17, \infty)Approx.≈0.5\approx 0.5No
Swish/SiLU≈(−0.28,∞)\approx(-0.28, \infty)Approx.0.50.5No
Mish≈(−0.31,∞)\approx(-0.31, \infty)Approx.≈0.6\approx 0.6No

Gradient Flow Analysis

To understand how these functions affect gradient flow in deep networks, consider what happens when you backpropagate a gradient δ\delta through a layer with activation ff. The gradient signal that reaches the layer below is δ⋅f′(z)\delta \cdot f'(z). If f′(z)<1f'(z) < 1 consistently, the gradient shrinks at each layer. If f′(z)>1f'(z) > 1, it grows (which can cause exploding gradients).

For sigmoid, f′(z)≤0.25f'(z) \leq 0.25 everywhere. Backpropagating through NN sigmoid layers multiplies the gradient by at most 0.25N0.25^N. With just 10 layers, this is (0.25)10≈10−6(0.25)^{10} \approx 10^{-6}: a million-fold reduction. The early layers receive essentially no gradient and their weights barely move.

For ReLU, f′(z)=1f'(z) = 1 on the active side. Backpropagating through NN active ReLU neurons multiplies the gradient by 1N=11^N = 1: no shrinkage at all. This is the core reason ReLU enabled training of deep networks. The caveat is that dead neurons (the f′(z)=0f'(z) = 0 side) block gradient flow entirely, which is why the dying ReLU problem matters for deep or poorly initialized networks.

For GELU and Swish, the derivative near zero is approximately 0.5, and the gradient grows to approximately 1 for large positive inputs. These smooth functions have slightly smaller average gradients than ReLU on the positive side but handle the transition at zero more gracefully, avoiding the hard zero that causes dying neurons. The gradient for GELU varies between approximately 0.5 and 1.0 for typical pre-activation values, which means GELU networks do experience some gradient attenuation but far less than sigmoid networks.

The following plot illustrates gradient magnitude decay across layers for sigmoid versus ReLU, showing the dramatic difference that activation choice makes in deep networks:

Out[7]:
Visualization
Line plot showing gradient magnitude versus layer depth for four activation functions on log scale.
Gradient magnitude decay across 10 network layers for sigmoid, tanh, ReLU, and GELU. Every activation receives the same standard-normal pre-activations at each layer. Sigmoid gradients collapse fastest, while ReLU and the smooth activations retain orders of magnitude more signal through the deepest layers.

Convergence Speed

In controlled experiments on standard benchmarks, the relative convergence speed of activation functions is roughly:

GELU ≈\approx Swish ≈\approx Mish >> ELU >> Leaky ReLU ≈\approx ReLU >> tanh >> sigmoid

This ordering is approximate and architecture-dependent. The modern smooth functions (GELU, Swish, Mish) often converge faster and to slightly better optima, particularly in deeper networks. The advantage over ReLU is often small (a few percent in final accuracy) but consistent enough across benchmarks that transformers standardized on GELU.

The reason the smooth activations tend to converge faster is subtle. ReLU creates a piecewise-linear loss landscape: the loss surface is flat in all the directions where neurons are dead. This means gradient descent must take many small steps around the flat regions. GELU and Swish produce a smoother landscape with fewer flat regions, so gradient descent can move more directly toward the optimum. The difference is not dramatic for shallow networks, but compounds over many layers.