Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Activation functions decide whether a neuron fires — shaping what a network can learn, how gradients flow, and how quickly training converges. Without them, deep networks collapse into linear models.
Think of a light switch — either on or off. The output is completely binary, with an abrupt discontinuity at zero.
The derivative is zero everywhere except at x=0 where it is undefined. This makes gradient-based learning impossible — the network cannot determine how to adjust weights.
Binary classifiers in simple perceptrons. Largely replaced by sigmoid in modern practice. Sometimes used in binary neural networks for edge deployment.
Using it in hidden layers — gradients never flow backward. Use sigmoid instead if a probabilistic binary output is needed.
Sigmoid is a smooth, differentiable approximation of the step function. For any real gradient-based training, sigmoid is the proper substitute.
A straight line through the origin. No matter how many layers use linear activations, the entire network collapses to a single linear transformation — depth provides no representational benefit.
The gradient is constant (α) everywhere — no vanishing or exploding gradient caused by this function itself. However, stacking linear layers collapses to one linear layer, so depth is useless.
The output layer for regression tasks where the target is continuous and unbounded. Never used in hidden layers of a network meant to learn non-linear functions.
Using linear activations in hidden layers. You lose all representational power — the network cannot model anything beyond a hyperplane.
ReLU provides non-linearity while still being linear in the positive domain, making it far more powerful in hidden layers.
An S-shaped curve that is steep near zero and flat at the extremes. Large positive inputs saturate toward 1, large negative inputs toward 0. The output is always a valid probability.
f'(x) = f(x)(1 - f(x)), maximized at 0.25 when x=0. At saturation (|x| > 4), the gradient approaches zero — vanishing gradient in deep networks.
The output layer for binary classification. In LSTMs, used for gate activations. Avoid in deep hidden layers — use ReLU family instead.
Using sigmoid in hidden layers of deep networks. The vanishing gradient kills learning in early layers. Also, outputs are always positive, biasing weight updates.
Tanh is zero-centered and generally preferable to sigmoid in hidden layers. For outputs, softmax generalizes sigmoid to multi-class.
A steeper, zero-centered version of sigmoid. Outputs negative for negative inputs, positive for positive — exactly what we want for weight updates to go in either direction symmetrically.
f'(x) = 1 - tanh²(x), peaking at 1.0 when x=0. Still suffers from vanishing gradients at saturation, but less severely than sigmoid.
RNN hidden states, LSTM cell gates, older feedforward networks. Still preferred over sigmoid in hidden layers due to zero-centering.
Confusing the gradient range — tanh's derivative peaks at 1 (not 0.25 like sigmoid), making it significantly better. But it still vanishes for |x| > 2.
Sigmoid times 2 minus 1. Strictly better than sigmoid for hidden layers due to zero-centering. In modern deep networks, ReLU often outperforms both.
A ramp function. When a neuron sees a negative input, it outputs zero — it becomes inactive. When positive, it passes the signal unchanged. This sparsity is computationally efficient and biologically plausible.
Gradient is 1 for positive inputs, 0 for negative. No vanishing gradient on the positive side. The dying ReLU problem: neurons with consistently negative preactivations output zero gradient — permanently dead.
Default choice for hidden layers in CNNs, MLPs, and most feedforward architectures. Combined with batch normalization for deep networks.
High learning rates can kill ReLUs permanently. Dead neurons output zero gradient forever — use learning rate warmup or Leaky ReLU variants to mitigate.
Leaky ReLU and ELU fix the dying neuron problem. GELU and Swish outperform ReLU on many benchmarks. ReLU remains the default due to simplicity.
A tiny leak for negative values — just enough gradient to rescue dying neurons. Visually almost identical to ReLU, but with a shallow slope instead of zero on the left.
1 for x>0, α for x≤0. No dead neuron problem. Small but consistent gradient for all inputs ensures every neuron can recover.
Anywhere you would use ReLU but fear dead neurons — particularly useful with very deep networks or aggressive learning rates.
Setting α too large (>0.2) — the function loses the sparsity benefit of ReLU. Very small α (0.01) is usually the right default.
PReLU makes α a learnable parameter. ELU produces smoother negative outputs. SELU has self-normalizing properties. All are improvements on Leaky ReLU in different ways.
The network itself decides how much to leak for each neuron. Some neurons may learn high α (nearly linear), others near-zero α (nearly ReLU). Each neuron adapts to its role.
Backprop through x and through α. For negative x, dL/dα = dL/df * x, allowing α to be updated. Introduces extra parameters but minimal overhead.
Used in ResNet and other image classification networks. Introduced by He et al. (2015), showing improvement over ReLU for deep residual networks.
On small datasets, the extra parameters may cause overfitting. Initialize α conservatively (e.g., 0.25). Consider weight decay on α.
Leaky ReLU uses fixed α (simpler). PReLU learns α (more expressive). ELU provides a smooth alternative for the negative regime.
Imagine Leaky ReLU but with a smooth curve instead of a line for negatives. The exponential form means the negative output saturates at −α, pushing mean activations closer to zero.
1 for x>0, α·eˣ for x≤0. Smooth everywhere, no kink at origin. Negative saturation region still has vanishing gradient for large |x|.
Deep fully-connected networks, residual networks, situations where smooth gradients matter. Introduced as an improvement over ReLU with better statistical properties.
Not using appropriate α for your problem. α=1 is the standard default. Be aware of computational cost in inference-critical deployments.
SELU is a scaled ELU with provably self-normalizing properties. Swish and GELU often outperform ELU on modern benchmarks but are more expensive.
SELU is the activation equivalent of batch normalization baked into the function itself. With the right weight initialization, activations automatically stay normalized — no batch norm needed.
λ for x>0, λ·α·eˣ for x≤0. The specific constants ensure the network is a contraction mapping — activations converge to normalized distributions.
Self-normalizing Neural Networks (SNNs). Works best in deep feedforward architectures with no residual connections, used with AlphaDropout.
Using SELU with standard He initialization — it requires LeCun initialization. Also, SELU breaks with residual connections or standard dropout.
ELU without the scaling constants. The scaling is crucial for self-normalization. In practice, batch norm + ReLU often achieves similar results more flexibly.
Imagine smoothing out the kink in ReLU. At x=0, ReLU has a sharp corner — Softplus rounds this corner. For large |x|, softplus ≈ ReLU for positive and ≈ 0 for negative.
f'(x) = 1/(1+e⁻ˣ) = sigmoid(x). Derivative is sigmoid! This means gradient vanishes slightly for large negative x but never reaches exactly zero.
Variational Autoencoders (VAE) where smooth activations help optimization. Also used when differentiability everywhere is required (e.g., second-order optimization).
Expecting Softplus to outperform ReLU in standard classification — it typically does not despite its theoretical smoothness advantage.
ReLU is a piecewise linear approximation. Softplus is fully smooth. In practice, the difference is minor — ReLU wins on speed and sparsity.
Like tanh but using |x| in the denominator rather than an exponential. This makes it cheaper to compute and slower to saturate — inputs must be larger to push the function into its flat regions.
f'(x) = 1/(1+|x|)². Decays as 1/x² rather than exponentially, so gradients vanish more slowly than tanh.
Situations where tanh is appropriate but computational budget is limited. Found in some older architectures and specialized applications.
Assuming it is always better than tanh — in practice the difference is small and problem-dependent.
Tanh saturates exponentially; Softsign saturates polynomially (slower). This gives Softsign slightly better gradient flow. ReLU variants are generally preferable in both cases.
GELU asks: how likely is this input to be active under a Gaussian? Large positive inputs are almost certainly active; large negatives almost certainly inactive; near zero, there's uncertainty — GELU applies a smooth, probabilistic gate.
Complex but smooth. Has a slightly negative region near x ≈ -0.17, then rises steeply. This non-monotone property correlates with improved optimization landscapes.
Default activation in transformers (BERT, GPT-2/3/4, RoBERTa, T5). Also used in vision transformers (ViT) and other modern architectures.
Using the less accurate approximation — always use the tanh-based approximation rather than computing the true CDF. In non-NLP tasks, benchmark before assuming GELU wins.
Outperforms ReLU in transformers. Swish (x·sigmoid(x)) is a related function. SwiGLU (used in LLaMA) extends this concept further.
The input gates itself — large positives pass through near-unchanged (sigmoid→1), near-zero inputs are suppressed, and the function has a slight negative region that acts as implicit regularization.
f'(x) = f(x) + σ(βx)(1-f(x)). Smooth everywhere. The slight non-monotonicity (the dip below zero) is believed to help escape poor local optima.
Used in EfficientNet and other modern vision models. Good default for deep CNNs and MLPs. β=1 (called SiLU in PyTorch) is the standard choice.
Overcomplicating with β tuning — β=1 is nearly always optimal. Note: PyTorch calls this SiLU (Sigmoid Linear Unit).
GELU ≈ x·Φ(x); Swish = x·σ(βx). These are closely related — GELU uses the Gaussian CDF, Swish uses sigmoid. Performance is similar; GELU is preferred in NLP, Swish in vision.
Mish is like Swish but with a richer negative region — the curve dips more deeply before rising. This creates a self-regularizing effect and strong gradient flow near the origin.
Complex composite derivative involving softplus, tanh, and their derivatives. Always non-zero, smooth everywhere, with stronger gradient near origin than Swish.
YOLOv4 and derivatives, some vision transformers. Strong choice for object detection. Generally competitive with Swish across domains.
Expecting significant gains over Swish in every task — improvements are dataset and task dependent. The extra computation may not be justified.
More complex than Swish with a deeper negative dip. Both are non-monotone self-gated functions. Mish slightly outperforms Swish on some detection benchmarks.
Imagine each class competing for probability mass. Softmax amplifies differences — the largest value dominates exponentially, squashing smaller ones. The outputs always sum to exactly 1.
Jacobian (not scalar derivative). For i≠j: ∂fᵢ/∂xⱼ = -fᵢfⱼ. For i=j: ∂fᵢ/∂xⱼ = fᵢ(1-fᵢ). Combined with cross-entropy loss, simplifies to (predicted - true).
Output layer for multi-class classification in virtually every classifier. Also used in attention mechanisms (scaled dot-product attention in transformers).
Computing softmax then log for cross-entropy — use log_softmax directly for numerical stability (avoids log(0) issues from overflow).
Sigmoid is the binary special case of softmax (K=2). In attention, softmax normalizes attention scores to weights summing to 1.
All fifteen activation functions across key performance dimensions.
| Function | Output Range | Differentiable | Computational Cost | Vanishing Gradient | Best Use Case |
|---|---|---|---|---|---|
| Step Function | {0, 1} | No (at 0) | Very Low | Extreme | Binary output |
| Linear Function | (-∞, +∞) | Yes (constant) | Minimal | None (exploding risk) | Output layer (regression) |
| Sigmoid | (0, 1) | Yes | Low-Medium | High (deep nets) | Binary classification output |
| Tanh | (-1, 1) | Yes | Low-Medium | Moderate | RNNs, hidden layers |
| ReLU | [0, +∞) | No (at 0) | Very Low | Low (positive) | Deep networks, CNNs |
| Leaky ReLU | (-∞, +∞) | No (at 0) | Very Low | Very Low | Drop-in ReLU replacement |
| PReLU | (-∞, +∞) | No (at 0) | Low | Very Low | Image classification (ResNets) |
| ELU | (-α, +∞) | Yes (everywhere) | Low-Medium | Low | Deep networks needing smoothness |
| SELU | (−λα, +∞) | Yes (everywhere) | Medium | Low | Feedforward networks (self-norm) |
| Softplus | (0, +∞) | Yes | Medium | Low | Smooth ReLU alternative |
| Softsign | (-1, 1) | Yes | Low | Moderate | Alternative to tanh |
| GELU | (≈-0.17, +∞) | Yes | Medium | Low | Transformers, BERT, GPT |
| Swish | (≈-0.28, +∞) | Yes | Low-Medium | Low | Deep networks (Google Brain) |
| Mish | (≈-0.31, +∞) | Yes | Medium-High | Low | Object detection (YOLO) |
| Softmax | (0, 1) | Yes | Low-Medium | Moderate | Multi-class output layer |
Watch how different activation functions transform signals flowing through a neural network.
Draw a custom input curve by clicking and dragging. Select an activation function to see the transformation in real time.