freecoding.school100% FREE · NO SIGNUP
Tensor TownISSUE #21 of 120

activation functions · relu · sigmoid · tanh

NeuraVSThe Overfit Ogre
Neura saysActivation functions add nonlinearity — ReLU, sigmoid, tanh — so networks learn complex patterns.

Without a nonlinear activation, stacked linear layers collapse into one linear layer. ReLU (max(0,x)) is the modern default — simple, fast, avoids vanishing gradients. Sigmoid (0-1) and tanh (-1 to 1) squash outputs but saturate and can vanish gradients in deep nets. Choosing the right activation per layer (ReLU hidden, sigmoid/softmax output) matters for training.

Power-ups you unlock

The Overfit Ogre attacks — common mistakes

Boss battleExplain why stacked linear layers need a nonlinearity between them.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre>ReLU(x) = max(0, x)   ← default hidden
sigmoid → 0..1, tanh → -1..1 (can vanish)
no activation → many layers = one linear layer</pre></body></html>
▶ Open the interactive comic issue
‹ Neural Networks · The Perceptron OriginLoss Functions · Mse · Cross-Entropy ›