Activation Functions
Activation Functions — The nonlinearity that lets networks bend.
Without a nonlinear activation, stacking layers is pointless — it collapses back to one linear map. Activations like ReLU and sigmoid are what let networks learn curves and complex boundaries.
- Sigmoid
- Tanh
- ReLU
- Leaky ReLU
- GELU
- Current x / depth
Activation controls
The idea in plain words
Without a nonlinear activation, stacking layers is pointless — the whole network collapses back to a single linear map. Activations like ReLU and sigmoid are what let a network learn curves and complex boundaries.
Each function’s derivative is what training actually uses. Sigmoid’s derivative flatlines at the extremes while ReLU’s stays alive — the visual root cause of vanishing gradients in deep networks.
Now, the math
Common activations and their behavior at the extremes:
- the sigmoid gradient — peaks at 0.25, vanishes for large |x|.
- exactly 1 for positive inputs — no shrinkage.
▸ Show the derivation
During backprop, the gradient is multiplied by the activation’s derivative at every layer. Sigmoid derivatives are at most 0.25, so through many layers the product shrinks exponentially toward zero. ReLU’s derivative of 1 preserves the signal — the main reason it replaced sigmoid in deep nets.
Trace it by hand
Push the SAME pre-activation z = 1.5 through sigmoid, tanh, and ReLU, then repeat with z = -2 to expose ReLU's dead zone. All values computed with the repo's activation core and rounded to 4 decimal places.
Sigmoid at z equal to 1.5
Squashed into the 0-to-1 range — useful when the output should read as a probability.
Tanh at the same z
Tanh maps to the range from -1 to 1 and is already near its ceiling at z equal to 1.5.
ReLU at the same z
For positive inputs ReLU is the identity — no squashing at all, the value passes straight through.
Now the same comparison at z equal to -2
Sigmoid and tanh return small but informative values; ReLU clamps the input to exactly zero.
The derivatives tell the training story
At z equal to -2 a ReLU neuron passes zero gradient — it is dead and cannot learn from that input. For positive z its derivative is exactly 1, which is why gradients survive deep ReLU stacks.
What just happened: The same z = 1.5 became 0.8176, 0.9051, or 1.5 depending only on the activation choice — and at z = -2, ReLU output and gradient are both exactly zero while sigmoid still passes a 0.105 gradient: the dead-zone trade-off in two numbers.
Now Break It
Try this: Sigmoid saturates at the extremes, its gradient vanishing — deep sigmoid nets barely learn.
Control: Activation selector (sigmoid) with large inputs
What happens: Vanishing gradient! Sigmoid flattens at the extremes — its gradient dies and deep layers stop learning.
Where activation functions is used
Activation functions are the nonlinear switches that let neural networks bend, curve, and carve up input space in ways a straight line never could, and the choice of activation has repeatedly reshaped what deep learning can achieve. Sigmoid and tanh dominated early networks, but the rise of ReLU (rectified linear unit) around 2010 to 2012 was a major factor in making very deep networks trainable, helping spark the modern deep learning era in computer vision. Today activations like GELU and SiLU power large language models, while softmax turns raw scores into class probabilities at the output of classifiers. Every time a network recognizes a face, translates a sentence, or ranks a search result, activation functions are quietly injecting the nonlinearity that makes it possible.
The central misconception is that activations are a minor detail; in truth, without a nonlinear activation, stacking layers is pointless because the composition of linear maps is still just one linear map, collapsing a deep network into a single-layer model. A second pitfall is the vanishing gradient problem: sigmoid and tanh saturate at their extremes, where their derivatives shrink toward zero, so gradients flowing back through many layers fade away and early layers barely learn. ReLU eases this by keeping a constant gradient for positive inputs, though it introduces the dead neuron problem, where units stuck at negative inputs output zero forever, which variants like leaky ReLU are designed to counter.
Frequently asked questions
What is an activation function?
Why do neural networks need nonlinear activations?
What is ReLU and why is it popular?
What are vanishing gradients?
When should I use softmax?
What is a dead neuron in ReLU?
Written & reviewed by the ML Visualization team · Last updated .