Skip to content
ML to LLMs
Cheat sheets

Activation functions

ReLU, GELU, sigmoid, tanh, and softmax, their derivatives, and where each is used.

ActivationFormulaRangeDerivativeTypical use
ReLUmax⁡(0,z)\max(0, z)[0,∞)[0, \infty)1 if z>0z > 0, else 0hidden layers (default)
Leaky ReLUmax⁡(αz,z)\max(\alpha z, z)(−∞,∞)(-\infty, \infty)1 or α\alphaavoids dead units
GELUz Φ(z)z\,\Phi(z)about (−0.17,∞)(-0.17, \infty)smoothtransformers
Sigmoid1/(1+e−z)1/(1 + e^{-z})(0,1)(0, 1)σ(1−σ)≤0.25\sigma(1 - \sigma) \le 0.25binary output probability, gates
Tanhtanh⁡z\tanh z(−1,1)(-1, 1)1−tanh⁡2z1 - \tanh^2 zRNNs, zero-centered outputs
Softmaxezi/∑jezje^{z_i}/\sum_j e^{z_j}probabilities summing to 1pi(δij−pj)p_i(\delta_{ij} - p_j)multiclass output, attention weights

Why nonlinearity: without it, stacked linear layers collapse into one linear map (W2W1xW_2 W_1 x).

Gradient behavior: sigmoid and tanh saturate (tiny derivatives for large ∣z∣|z|), contributing to vanishing gradients. ReLU's gradient is exactly 1 for positive inputs, but units stuck negative are "dead."

Output layer by task: regression, none; binary, sigmoid; multiclass, softmax; multi-label, one sigmoid per label.

Lessons: The forward pass · Backpropagation · Lab: forward pass