C.W.K.
Stream
Lesson 02 of 05 · published

Activation Functions: The Spark of Non-Linearity

~8 min · activation, relu, sigmoid, non-linearity

Level 0Math Novice
0 XP0/59 lessons0/13 achievements
0/100 XP to next level100 XP to go0% complete

Why Linear Alone Can't Win

Stack 100 linear layers without anything between them and you get... one linear layer. The composition of linear functions is still linear. A 100-layer purely-linear network has the exact same expressive power as a single linear regression. Useless waste of compute.

Activation functions introduce non-linearity. They're the kink in the line that lets the network bend reality into useful shapes. Without them, no curves, no boundaries, no understanding of cats vs dogs.

The Activation Zoo

ActivationFormulaWhen to use
ReLUDefault in modern deep nets. Cheap, doesn't vanish for positive inputs.
SigmoidOutput layer for binary classification. Squeezes to (0, 1) — interpretable as probability.
TanhSqueezes to (-1, 1). Used in older RNNs.
SoftmaxOutput layer for multi-class classification. Squeezes to a probability distribution.
GeLU / SiLUsmooth ReLU variantsModern Transformers, LLMs.

Why ReLU Took Over

Sigmoid's max derivative is 0.25. Stack many and gradients vanish (we saw this in the Calculus track). ReLU's derivative is 1 for positive inputs — gradients flow through unchanged. Plus it's just max(0, x), which is cheap on hardware. The 2012 deep learning revival was largely "ReLU + GPUs + ImageNet."

Activations turn linear stacks into universal function approximators. ReLU is the modern default; pick others only when you have a specific reason.

Code

The activation zoo, head to head·python
import torch
import torch.nn.functional as F

x = torch.linspace(-5, 5, 11)

print("input :", x)
print("relu  :", F.relu(x))
print("sigmoid:", torch.sigmoid(x))
print("tanh  :", torch.tanh(x))
print("gelu  :", F.gelu(x))

External links

Exercise

Plot ReLU, sigmoid, and GeLU on the same axes for x in [-5, 5]. Notice how ReLU is straight-line at zero, sigmoid is smooth and saturates, GeLU is a smoother ReLU. Pick the right one when you write nn.Linear(...) followed by F.???(x).
Hint
Each activation has a personality. ReLU = sharp gate. Sigmoid = smooth gate that saturates. GeLU = ReLU's polite older cousin used in modern transformers.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.