Activation Functions, In Full Depth
Neural Network Fundamentals explained why nonlinear activations are necessary at all — without one, stacking linear layers collapses into a single linear function, no matter how deep. This page catalogs the actual functions used in practice, their tradeoffs, and why the field's default choice has shifted over time.
The Core Tradeoffs to Judge Any Activation By
- Saturation: does the function flatten out (near-zero gradient) for large inputs? Saturating functions cause vanishing gradients in deep networks (see Training Deep Networks).
- Zero-centered output: is the output centered around 0, or always positive? Non-zero-centered activations (like sigmoid) can slow convergence because gradients on the next layer's weights end up all-same-sign.
- Computational cost: a cheap function (ReLU: one comparison) matters when it's evaluated billions of times per training step.
- Dead units: can the function get permanently stuck outputting zero (or a constant) for some inputs, with zero gradient to ever recover?
Historical / Saturating Functions
Binary Step: if else . Not differentiable at zero and has zero gradient everywhere else — unusable for gradient-based training. Included only because it's the original (1950s-era) perceptron activation, conceptually the ancestor of everything below.
Sigmoid: (see Logistic Regression for the full derivation). Smooth, output in — but saturates hard at both ends (gradient for large) and isn't zero-centered. Rarely used in hidden layers today; still standard for a binary classifier's output layer, where you specifically want a probability.
Tanh: , output in . Same saturation problem as sigmoid, but zero-centered — a real improvement, which made it the default hidden-layer activation before ReLU took over.
Try it yourself: implement the sigmoid activation from scratch, against real test cases.
The ReLU Family
ReLU (Rectified Linear Unit): . The modern default: trivially cheap, doesn't saturate for , and empirically trains faster than sigmoid/tanh in deep networks. Its flaw: the dying ReLU problem — if a neuron's weights drift so its input is always negative, its output and gradient are permanently 0, and it can never recover via gradient descent (the gradient through it is exactly 0, so no update ever fixes it).
Leaky ReLU: if else (small , e.g. 0.01) — allows a small negative-side gradient specifically to fix dying ReLU, at negligible extra cost.
PReLU (Parametric ReLU): same shape as Leaky ReLU, but is a learned parameter rather than fixed — lets the network decide per-channel how much negative-side leak is useful.
ELU (Exponential Linear Unit): if else . Smoothly saturates on the negative side (rather than Leaky ReLU's straight line) toward , which pushes mean activations closer to zero — empirically speeds up convergence — at the cost of computing an exponential.
SELU (Scaled ELU): ELU with specific fixed constants (, scale ) chosen so that, under specific initialization and architecture conditions, activations self-normalize (maintain roughly zero mean, unit variance) across layers without needing explicit BatchNorm/LayerNorm.
The Modern Default: Smooth Gated Units
GELU (Gaussian Error Linear Unit): , where is the standard normal CDF — intuitively, "multiply the input by the probability a standard Gaussian is less than the input." Smooth everywhere (no sharp elbow like ReLU), slightly negative for small negative , then approaches linear for large . The standard activation in Transformers (BERT, GPT-family, and most modern LLMs use GELU in their feed-forward blocks — see Attention & Transformers) because the smoothness empirically helps optimization at scale compared to ReLU's hard kink.
Swish / SiLU: — same "gate the input by a sigmoid of itself" idea as GELU, using the exact sigmoid instead of the Gaussian CDF. Very similar shape and behavior to GELU in practice; the choice between them is often more about convention/library defaults than a meaningful performance difference.
Mish: — another smooth, self-gated activation in the same family as GELU/Swish, used in some modern CNN architectures (e.g. YOLO variants).
Auxiliary Functions
Softplus: — a smooth approximation of ReLU (no sharp corner at 0), used as a building block inside Mish above and occasionally as an activation itself when smoothness at zero specifically matters.
Softsign: — a cheaper (no exponential), zero-centered alternative to tanh with similar S-shape but different tail behavior (approaches ±1 polynomially rather than exponentially).
Identity: — used at a regression output layer (where you want the raw linear value, not squashed into a bounded range — see Linear Regression), and conceptually as the "no activation" baseline.
Softmax: unlike every function above, softmax operates on a whole vector at once, not element-by-element: — converts a vector of raw scores into a probability distribution that sums to 1. This is the standard output-layer activation for multi-class classification (see Logistic Regression — Softmax Regression) and is exactly what turns an LLM's raw output scores into a probability distribution over the next token.
Try it yourself: implement a numerically stable softmax from scratch, against real test cases.
Quick Reference
| Function | Range | Zero-centered? | Saturates? | Typical use |
|---|---|---|---|---|
| Sigmoid | (0, 1) | No | Both ends | Binary output layer |
| Tanh | (-1, 1) | Yes | Both ends | Legacy RNN hidden layers |
| ReLU | [0, ∞) | No | Negative side only | CNN hidden layers (classic default) |
| Leaky ReLU / PReLU | (-∞, ∞) | Roughly | No | Fixing dying ReLU |
| ELU / SELU | (-α, ∞) | Roughly | Negative side (smoothly) | Self-normalizing nets |
| GELU | (-~0.17, ∞) | Roughly | No | Transformers (default) |
| Swish / SiLU | (-~0.28, ∞) | Roughly | No | Transformers, modern CNNs |
| Softmax | (0,1), sums to 1 | N/A (vector) | N/A | Multi-class output layer |
Next: Loss Functions — what each of these activations gets paired with to actually train a network.