Lesson 4.2core2 h⚡ live demo

Activation functions

The small nonlinear choice that decides whether gradients survive

The activation function is a one-line decision with network-wide consequences: it decides whether a 50-layer network trains at all. Sigmoids made deep networks untrainable for twenty years; ReLU unlocked AlexNet (5.3 Architectures: LeNet → AlexNet → VGG → Inception → ResNet → EfficientNet → ConvNeXt); GELU and SwiGLU sit inside every modern transformer (7.4 Inside the block: residuals, LayerNorm, FFN and embeddings). Knowing each function's derivative and saturation behaviour is what lets you read a stalled training run (4.8 Training dynamics and debugging) and pick the right default without guessing.

You'll be able to

  • Write the formula and derivative of sigmoid, tanh, ReLU and its variants, GELU/SiLU and softmax
  • Derive why products of layer Jacobians make gradients vanish with saturating activations and why ReLU avoids it
  • Explain dead ReLUs, their cause and their cure
  • Match output activations to tasks and losses, and explain why models should output logits
  • State the 2026 defaults for hidden activations in CNNs, MLPs and transformers

Key ideas

  1. Sigmoid and tanh saturate: their derivatives are at most 1/4 and 1, and near zero for large |z|.
  2. Backprop multiplies one Jacobian diag(φ'(z)) per layer; with saturating activations the product shrinks geometrically — the vanishing-gradient problem.
  3. ReLU's derivative is exactly 1 on active units, so gradients pass through unattenuated; this unlocked deep networks in 2012.
Show 4 more key ideas
  1. A ReLU unit whose pre-activation is negative for every input is dead forever; large learning rates and bad initialization cause it; leaky/GELU variants avoid it.
  2. GELU = z·Φ(z) and SiLU = z·σ(z) are smooth, slightly non-monotonic ReLUs; GELU/SwiGLU are the transformer defaults.
  3. Softmax turns logits into probabilities with Jacobian ∂pᵢ/∂zⱼ = pᵢ(δᵢⱼ − pⱼ); it is shift-invariant and temperature-scalable.
  4. Models should output logits; the loss function applies sigmoid/softmax stably.

Suggested path through this lesson