Activation Functions in Neural Networks: Why Non-Linearity Matters

7 minute read

Published:

TL;DR: A neural network without activation functions is just a stack of linear layers pretending to be deep. Activation functions are what bend the geometry, control gradient flow, and decide whether a network behaves like a hard switch, a soft gate, or a smooth feature extractor.

Why Activation Functions Exist

Intuition First: Imagine stacking transparent overlays on a map, each one a straight line across the city — however many you stack, the result still only describes straight-line logic. Activation functions let each layer bend its overlay into a curve; without them, ten layers of computation are exactly equivalent to one.

The core equation of a hidden layer is simple:

\[ h = \sigma(Wx + b) \]

The matrix multiplication Wx + b is only an affine transformation — stacking ten of them still collapses into one, giving more parameters but no more expressive shape.

Activation functions break that collapse: they inject non-linearity, letting the network carve curved decision boundaries, represent thresholds, and model interactions a linear model cannot.

Linear only (no activation) Cannot separate ✗ With activation (non-linear) Clean separation ✓
Without activations, a deep network can only draw a straight decision boundary (left); with non-linearity it learns the curved one that actually separates the data (right).

The Core Intuition

Think of a neuron as a tiny processor that first computes a score and then asks: should I pass this signal, suppress it, clip it, smooth it, or gate it?

  • A step activation behaves like a binary rule.
  • A sigmoid behaves like a soft probability gate.
  • A tanh behaves like a centered soft gate.
  • A ReLU behaves like a one-way valve: block negatives, pass positives.

That tiny local choice changes the global behavior of the whole network.

Step Sigmoid Tanh ReLU
Step is a hard binary flip; Sigmoid and Tanh are smooth S-curves that flatten in the tails; ReLU is a half-rectification — zero on the left, identity on the right.
Diagram showing a neuron computing a linear score and then passing it through different kinds of activation gates
Figure 1 — The same linear score becomes very different behaviour depending on the activation: a hard threshold, a soft probability gate, or a one-way valve like ReLU.

Historical Progression

How the field evolved

  1. Step / threshold activations: good for early perceptrons, but not differentiable enough for modern gradient-based learning.
  2. Sigmoid and tanh: smooth and differentiable, which made backpropagation practical, but they saturate.
  3. ReLU: dramatically simplified optimization and became the default for CNNs and MLPs.
  4. Modern smooth activations: GELU, SiLU, Swish, Mish, and gated variants improved optimization in large modern models.

Classical Families

A. Linear and Threshold Activations

These sit at the two extremes.

  • Linear / Identity: does nothing; useful mainly in regression outputs.
  • Step / Heaviside: flips from 0 to 1 once a threshold is crossed.

Using the linear activation in every hidden layer forfeits the entire point of depth.

B. Squashing Functions

The first major family maps inputs into a bounded range:

  • Sigmoid: maps to [0, 1].
  • Tanh: maps to [-1, 1] and is zero-centered.
  • Softsign: also saturates, but more gently than tanh.
Sigmoid \[ \sigma(x) = \frac{1}{1 + e^{-x}} \]
Tanh \[ \tanh(x) = \frac{e^x - e^{-x}}{e^x + e^{-x}} \]
Softsign \[ \operatorname{softsign}(x) = \frac{x}{1 + |x|} \]

They are attractive because they are smooth and easy to differentiate. Their main weakness is saturation: for large positive or negative inputs, the derivative becomes tiny.

Key Insight: The sigmoid derivative peaks at exactly 0.25 when \(x=0\). That means even at its best, it cuts the gradient in half compared to passing it unchanged. Stack 10 sigmoid layers and the best-case gradient shrinks to \(0.25^{10} \approx 0.000001\). That is the vanishing gradient problem in one number.

Concrete numerical example — sigmoid saturation:

Input \(x\)\(\sigma(x)\)\(\sigma'(x) = \sigma(x)(1-\sigma(x))\)
00.5000.250 (maximum)
20.8800.105
40.9820.018
60.9980.002
80.99970.0002

Each row shows why neurons that receive large-magnitude inputs essentially stop learning — the gradient through them is nearly zero.

C. Piecewise-Linear Functions

Then came the ReLU era:

  • ReLU: keeps the positive branch and zeros out the negative one.
  • Leaky ReLU: small negative slope instead of a hard zero
  • PReLU: learns that negative slope
  • RReLU: uses a random negative slope during training
  • ReLU6: same idea as ReLU, but clipped at 6
  • Thresholded ReLU: stays at zero until a chosen threshold
ReLU \[ \operatorname{ReLU}(x) = \max(0, x) \]
Leaky ReLU \[ \operatorname{LeakyReLU}(x) = \begin{cases} x, & x > 0 \\ \alpha x, & x \le 0 \end{cases} \]
ReLU6 \[ \operatorname{ReLU6}(x) = \min(\max(0, x), 6) \]

These functions made optimization much easier because their positive branch keeps a strong gradient.

Concrete step-by-step: how ReLU saves the gradient

Imagine a single neuron receives pre-activation \(z = 1.5\) and the upstream gradient (from the loss) is \(\delta = 0.8\).

ActivationOutputLocal derivativeGradient passed back
Sigmoid\(\sigma(1.5) = 0.818\)\(\sigma'(1.5) = 0.149\)\(0.8 \times 0.149 =\) 0.119
Tanh\(\tanh(1.5) = 0.905\)\(1 - 0.905^2 = 0.181\)\(0.8 \times 0.181 =\) 0.145
ReLU\(\max(0,1.5) = 1.5\)1\(0.8 \times 1.0 =\) 0.800

ReLU passes the gradient through unchanged on the positive side. Stacked over many layers, that difference becomes enormous.

Grid of classical activation functions including linear, step, sigmoid, tanh, ReLU, Leaky ReLU, PReLU, RReLU, Softplus, Softsign, ReLU6, and Thresholded ReLU
Figure 2 — Squashing activations saturate, ReLU-like activations keep a strong positive branch, and clipped variants trade expressivity for stability or efficiency.

What the Shapes Are Telling You

You can often predict training behavior by looking at the curve.

Shape patternWhat it usually implies
Flat tailsRisk of vanishing gradients
Hard zero regionRisk of dead neurons
Smooth transitionMore stable optimization
Unbounded positive branchStrong gradient flow for active units
ClippingBetter control, but less expressivity

So activation functions are not just output transformations. They are also gradient transformations.

Gradient Perspective

Intuition First: Backpropagation is the chain rule applied repeatedly: each activation contributes a multiplier. Multipliers consistently below 1 shrink the product toward zero on the way back — vanishing gradients; consistently above 1, it explodes. The ideal multiplier is 1 on the active side, exactly what ReLU achieves.

The four recurring problems

ProblemMeaning
Vanishing gradientsDerivatives become so small that early layers barely learn.
Exploding gradientsDerivatives become too large and make optimization unstable.
Dead neuronsSome ReLU units stay permanently inactive because they only see negative inputs.
SaturationSigmoid/tanh flatten for large magnitudes, so gradient flow collapses.
1. Active neuron z=1.2 gradient flows freely 2. Large negative update z=−0.4 output clipped to 0 by ReLU 3. Dead neuron output = 0, gradient = 0 weights never update again
A neuron that receives a large negative weight update flips to \(z \lt 0\). ReLU clips its output to zero, so no gradient flows back (\(\partial \operatorname{ReLU} / \partial z = 0\)), and the weights are frozen permanently — the neuron is dead.
Diagram contrasting vanishing gradients, dead neurons, and healthy gradient flow across common activations
Figure 3 — Sigmoid and tanh can flatten into tiny derivatives, ReLU can kill units on the negative side; smoother modern activations preserve more gradient flow near zero.

Practical First Recommendations

If you are just starting, a strong first mental map is:

Use caseGood default
Hidden layers in MLPs / CNNsReLU or Leaky ReLU
Very deep modern architecturesGELU or SiLU
Binary outputSigmoid
Multi-class outputSoftmax
Regression outputLinear

Later chapters cover the smoother modern and output-layer functions in more detail.

What Can Go Wrong with Classical Activations?

Typical failure modes

ActivationPotential problem
StepNot useful for standard backpropagation because the derivative is zero almost everywhere.
SigmoidSaturates in the tails and causes vanishing gradients in deep hidden stacks.
TanhZero-centered, but still saturates for large magnitudes.
ReLUCan create dead neurons that never reactivate.
ReLU6 / clipped variantsGain control, but can reduce expressivity if clipping is too aggressive.

Side-by-Side Comparison: Classical Activations

Sigmoid f(x) f′(x) max f′=0.25 — saturates! Tanh f(x) f′(x) zero-centered, still saturates ReLU f(x) f′(x) f′=1 always (positive side)
Solid lines are the function, dashed the derivative. Sigmoid and Tanh derivatives flatten to near-zero in the tails — vanishing-gradient territory. ReLU's derivative is exactly 1 on the positive side, so gradients pass through undistorted.

Main Takeaway

Activation functions determine what signal a neuron emits and how gradients travel backward — which is why the story runs step → sigmoid/tanh → ReLU → modern smooth and gated activations.

References

  1. Nair, V. and Hinton, G. E. “Rectified Linear Units Improve Restricted Boltzmann Machines.” ICML 2010.
  2. Goodfellow, I., Bengio, Y., and Courville, A. Deep Learning. MIT Press, 2016.
  3. Glorot, X., Bordes, A., and Bengio, Y. “Deep Sparse Rectifier Neural Networks.” AISTATS 2011.