Activation Functions
Why neural networks need non-linearity, and how Sigmoid, ReLU, and GELU each solve the previous function's critical failure.
Without an activation function bending the signal, stacking layers achieves nothing. Mathematically, a deep network composed purely of linear operations collapses into a single linear model.
Sigmoid and Vanishing Gradients
Sigmoid squashes outputs nicely between 0 and 1, but its slope flattens out at the edges. When multiplying gradients through many deep layers, these flat slopes cause the learning signal to vanish completely.
The ReLU Fix
ReLU fixes the vanishing gradient by maintaining a slope of exactly 1 for all positive inputs. However, anything below zero gets a slope of 0, meaning the neuron stops learning entirely—a dead neuron.
Smooth Gating with GELU
GELU and SwiGLU smooth out the sharp kink of ReLU. By providing a probabilistic or learned gating mechanism, they preserve gradients even for slightly negative inputs, making them the standard for large transformers.
Where It Breaks
If you use Sigmoid in a 50-layer network, or pick a learning rate that drives all ReLUs negative, training halts. The loss curves plateau early and stay there, completely stalled by dead neurons or vanishing gradients.
The Quick Version
- Linear operations alone cannot build complex features; an activation function is required.
- Sigmoid causes gradients to vanish in deep networks because it saturates at the extremes.
- ReLU maintains a constant gradient for positive inputs but can create dead neurons.
- GELU and SwiGLU smooth the transition, preserving gradients and improving training in transformers.
- The wrong choice of activation can completely stall training.