Lensa ML
Lensa ML

How Activation Functions Work

Step 1 of 6

Why Not Just Linear?

Without activation, layers collapse into one

-22-11Layer 1: y = 2x + 1Layer 2: y = 3x − 1
LAYER 1
y = 2x + 1
LAYER 2
y = 3x − 1

Two separate linear layers: Layer 1 and Layer 2. Press Compose layers to see what happens when we pass Layer 1's output into Layer 2.

Step 1 of 6: Why Not Just Linear?

Without activation, layers collapse into one

-22-11Layer 1: y = 2x + 1Layer 2: y = 3x − 1
LAYER 1
y = 2x + 1
LAYER 2
y = 3x − 1

Two separate linear layers: Layer 1 and Layer 2. Press Compose layers to see what happens when we pass Layer 1's output into Layer 2.

Step 2 of 6: The Sigmoid

Squashing everything between 0 and 1

-4-2241saturatedsaturated10σ(0.0) = 0.500σ(x) = 1/(1+e⁻ˣ)
Slide to explorex = 0.00
OUTPUT
0.5000
GRADIENT
0.2500

The sigmoid squashes any input to (0, 1). But in the saturated regions (far left/right), the gradient nearly vanishes — making learning painfully slow.

Step 3 of 6: ReLU — Keep It Simple

Zero if negative, pass if positive

-4-224-11dead zonegradient = 0ReLU(1.0) = 1.0f'(x) = 1ReLU(x) = max(0, x)
Move through the kinkx = 1.00
OUTPUT
1.00
GRADIENT
1

ReLU is beautifully simple: pass positive values through, zero out negatives. The gradient is always 0 or 1 — no vanishing! But neurons with only negative inputs become permanently dead.

Step 4 of 6: Tanh — Centered Sigmoid

Output centered around zero for faster learning

-4-224-11+1−1σ(x) [0,1]tanh(x) [−1,1]tanh = 0.000σ = 0.500
Compare both outputsx = 0.00
TANH OUTPUT
0.0000
SIGMOID OUTPUT
0.5000

Tanh is a zero-centered version of sigmoid, ranging from −1 to +1. This means its outputs are roughly balanced, which helps gradients flow in both directions and often makes training faster.

Step 5 of 6: The Activation Zoo

Leaky ReLU, ELU, Swish, and friends

Leaky ReLU
ELU
Swish
GELU
Leaky ReLU
RANGE(−∞, ∞)
DIFFERENTIABLEYes (except 0)
ZERO-CENTEREDNo

Beyond ReLU, researchers have designed many variants. Leaky ReLU fixes dead neurons, Swish and GELU are smooth and used in modern transformers. Each trades off simplicity, speed, and gradient flow.

Step 6 of 6: Activations in Action

Watch non-linearity create decision boundaries

Linear boundaryInner (A)Outer (B)
Activation function:
BOUNDARY TYPE
Linear
ACCURACY
27/60 (45%)
MISCLASSIFIED
33 ✕

Without activations, the network can only draw a straight line as the decision boundary. It misclassifies 33 points (marked ✕). Toggle the activation on to see how a curved boundary separates the clusters much better.