The activation menu, with reasons
ReLU — max(0, x). Default for hidden layers in CNNs and most MLPs since 2012. Cheap, sparse, gradients are 1 or 0 — easy to backprop. Failure mode: dead neurons (a unit stuck at zero forever).
GELU — Gaussian Error Linear Unit, smoother than ReLU near zero. Default in transformers (BERT, GPT, ViT). Slightly more expensive but trains better at scale. x * Φ(x).
SiLU / Swish — x * sigmoid(x). Used in EfficientNet, LLaMA, modern image-generation models. Smooth like GELU, slightly cheaper to compute.
Sigmoid — squashes to (0,1). Fine as the output activation for binary classification (paired with BCE loss). Bad as a hidden activation in deep networks — gradients saturate, training stalls.
Tanh — squashes to (-1, 1), zero-centered. Used inside RNNs (LSTMs, GRUs). Same saturation problem as sigmoid for deep stacks.
Softmax — turns a vector of logits into a probability distribution. Almost always the last step before cross-entropy loss. PyTorch's CrossEntropyLoss already includes a numerically stable softmax — do not stack them.
Why activations decide trainability
Activations control the gradient flow. ReLU passes gradients of 1 wherever it is active (and 0 elsewhere), which keeps deep stacks trainable. Sigmoid and tanh saturate at the tails, killing gradients. Choosing the wrong activation is the single most common reason a textbook architecture fails to learn anything on a real dataset.