Activation functions introduce nonlinearity after the linear transformation in each neuron.
| Function | Formula | Range | Notes |
|---|---|---|---|
| Sigmoid | Historical; saturates → vanishing gradients | ||
| Tanh | Zero-centered but still saturates | ||
| ReLU | Default. Fast, no saturation for . Dead neurons if always | ||
| Leaky ReLU | Fixes dead neuron problem, | ||
| GELU | Smooth ReLU. Default in transformers (BERT, GPT) | ||
| SwiGLU | — | Gated variant. Used in modern LLMs (LLaMA, PaLM) |

Why ReLU dominates:
- Gradient is 1 for positive inputs → no vanishing gradient
- Computationally trivial (just a threshold)
- Sparse activation (many zeros) → efficient representation
- Dying ReLU: if a pre-activation is negative for every input, it receives zero gradient forever and the unit goes dead. Leaky ReLU ( for ) fixes this.
Gated activations (modern LLMs):
- Swish (smooth, non-monotonic):
- GLU — one projection produces content, another produces a gate:
- SwiGLU plugs Swish into the GLU gate:
Swish derivative reuses the sigmoid derivative: .
Why non-linearities are essential: without them, stacked layers collapse to a single linear map () — extra depth adds no representational power. With non-linearities, deep networks become universal function approximators.
Choosing:
- CNNs → ReLU
- Transformers → GELU or SwiGLU
- Output layer: sigmoid (binary), softmax (multiclass), none (regression)
See also: The Artificial Neuron, Weight Initialization, Backpropagation