Skip to content
AI360XpertBeta
Core ML

Visual explainer

Activation Functions

Compare sigmoid, ReLU, GELU and Leaky ReLU on checked curves, build XOR with two hidden units, and separate local slopes from full-network gradients.

Affine layers alone cannot separate the four XOR points.
Affine layers alone cannot separate the four XOR points.

Nonlinear activations let hidden layers represent functions that stacked weighted sums alone cannot. Each activation transforms a neuron's scalar score before the next layer mixes its outputs. Here, filled circles are class 0 and triangles class 1. The synthetic unit-square XOR inputs (0, 0), (0, 1), (1, 0), (1, 1) need labels 0, 1, 1, 0.

The same-class diagonals cross at their common midpoint. An affine score there cannot simultaneously average negative endpoint scores for class 0 and nonnegative endpoint scores for class 1. Composing affine layers still gives one affine map. A nonlinear hidden transformation changes that restriction; the MLP sequence follows a full construction.

Sigmoid Bends the Line

Sigmoid has maximum local slope 0.25 at zero.
Sigmoid has maximum local slope 0.25 at zero.

Sigmoid computes σ(z) = 1 / (1 + exp(−z)). It maps finite inputs strictly between 0 and 1: about 0.119 at −2, 0.5 at zero and 0.881 at 2. The dashed tangent touches the marked zero-input point. Its local derivative is σ(z)(1 − σ(z)), maximized at 0.25 when σ(z) = 0.5.

Scenes two through four and eight share the same scales: 100 drawing units per input unit and 80 per output unit. Their displayed interval is −2 to 2; sigmoid's more saturated tails continue outside it. A shallow slope is not an exactly flat gate.

ReLU Gates the Input

ReLU has local slope zero below zero and one above zero.
ReLU has local slope zero below zero and one above zero.

ReLU computes max(0, z). At −1 it returns zero with derivative zero; at 1 it returns 1 with derivative one. The flat and rising branches show the difference on the shared axes. At the kink z = 0, the classical derivative is undefined; training implementations choose a convention there.

These are derivatives with respect to the activation's own input. They are not guarantees about the gradient through every weight, other path or loss function in a network.

GELU Rounds the Corner

Exact GELU is smooth and can output negative values.
Exact GELU is smooth and can output negative values.

The GELU paper defines G(z) = zΦ(z), where Φ is the standard normal cumulative distribution function. This page uses that exact definition, rather than the paper's tanh approximation. Its outputs at −1, 0 and 1 are about −0.159, 0 and 0.841. The ring identifies the negative value on the same scale as the previous curves; no enlarged dip is implied.

The plotted curve uses cubic segments fitted to exact values and derivatives at half-unit intervals. Smoothness does not imply a nonzero derivative everywhere: G′(z) = Φ(z) + zφ(z), with φ the standard normal density, reaches zero near −0.752. The derivative at zero is 0.5.

Bends Crack XOR

Two ReLU hidden units represent XOR with explicit weights.
Two ReLU hidden units represent XOR with explicit weights.

Return to the original input axes. Choose s = x₁ + x₂ and compute:

h1=ReLU⁡(s),h2=ReLU⁡(s−1),q=h1−2h2.h_1=\operatorname{ReLU}(s),\qquad h_2=\operatorname{ReLU}(s-1),\qquad q=h_1-2h_2.

Sums 0, 1 and 2 produce hidden pairs (0, 0), (1, 0), (2, 1), then scores 0, 1 and 0. Predict 1 when q > 0.5. Within the unit square, the positive strip lies between s = 0.5 and s = 1.5; those are the two exact boundary segments. The four original corner positions stay fixed. These analytically chosen weights demonstrate representation, not a training result.

Change One Activation

Switching activations changes scores even with fixed weights.
Switching activations changes scores even with fixed weights.

Replace both hidden ReLUs with exact GELU and keep every weight, bias and threshold fixed. Now q = G(s) − 2G(s − 1). Sums 0, 1, 2 yield approximately 0.317311, 0.841345, 0.271810. All four corner labels still match at threshold 0.5, but the scores differ.

Filled circles and solid segments show ReLU; outlined diamonds and dashed segments show GELU. The segments only guide the eye through the three discrete sums. They do not approximate the continuous GELU score between those sums. Choosing an activation changes the function and its computation cost; compare optimization and held-out behavior instead of assuming a swap improves accuracy.

Multiply Local Factors

Small local factors can shrink a backward signal.
Small local factors can shrink a backward signal.

In a scalar chain with unit interlayer weights, start with a backward signal of magnitude 1. Each sigmoid local slope is at most 0.25. After zero, one and two such factors, the magnitude bounds are 1, 0.25 and 0.0625. Bar lengths share one scale and show the shrinking upper bound, not measured gradients from a training run.

Ten factors give a bound of 0.25¹⁰ ≈ 0.000000954. The unit-weight assumption matters. Full layer propagation includes weights and their Jacobians, along with other paths and the loss derivative. Local activation slopes alone cannot establish that the entire network freezes.

Keep a Negative Slope

Leaky ReLU preserves a small slope for negative inputs.
Leaky ReLU preserves a small slope for negative inputs.

Leaky ReLU keeps z for positive inputs and uses αz for negative inputs. Here α = 0.1 is an illustrative choice. At z = −2 it outputs −0.2 with local derivative 0.1. The dashed branch is ordinary ReLU's zero output, compared on the same scales.

This avoids the exactly zero derivative on that negative branch. It does not guarantee useful full-network gradients: repeated factors of 0.1 can still shrink a signal, and weights can shrink or enlarge it too. The chosen α is not a universal recommendation.

Include the Weight

Weights change the full derivative even when ReLU's local slope is one.
Weights change the full derivative even when ReLU's local slope is one.

This controlled example changes the axes: x is a positive input from 0 to 2, and the vertical axis is the output of the complete scalar layer f(x) = ReLU(wx). For positive x and positive w, the ReLU gate's local derivative is 1, while the full input derivative is 1 × w.

With w = 2, f(1) = 2 and df/dx = 2. With w = 0.5, f(1) = 0.5 and df/dx = 0.5. Both use the same ReLU, but the complete derivatives differ fourfold. The curves share their x and output scales; the classical derivative at x = 0 is excluded from this positive-input argument.

Where It Breaks

Negative ReLU preactivations block that local data-loss gradient.
Negative ReLU preactivations block that local data-loss gradient.

Both marked preactivations, −2 and −1, lie on ReLU's flat zero branch. For a finite incoming loss derivative, multiplication by its local derivative zero blocks that backward route. The arrow and stop bar depict backward gradient flow, separate from the forward function curve.

If a unit stays negative on every training example, ordinary data-loss gradients through its gate cannot adjust its incoming parameters while those conditions persist. This is the inactive-unit failure. A single negative sample does not imply a dead unit across the dataset, and a blocked route does not imply every network path is blocked. Upstream changes or other update terms can change the preactivations. Monitor the actual activation and gradient behavior rather than inferring it from an activation name.

The Quick Version

  • Affine layers alone cannot fit the four XOR labels.
  • Sigmoid's maximum local slope is one quarter.
  • ReLU clips negatives and keeps positive inputs unchanged.
  • Exact GELU is smooth and can produce negative outputs.
  • Two constructed hidden ReLUs represent all four XOR labels.
  • Switching activations changes scores with fixed weights.
  • Repeated small factors can shrink a backward signal.
  • Leaky ReLU keeps a chosen negative-side slope.
  • Full layer derivatives include weights as well as activation slopes.
  • Negative ReLU inputs block their local data-loss gradient route.