Activation functions
Quick answer
An activation function bends a dense layer’s output so that stacked layers can represent nonlinear relationships. ReLU, tanh and sigmoid have different output ranges and derivatives; initialization influences whether the gradients can reach earlier layers. Static examples verified locally with Python 3.13.5 and NumPy 2.3.5 where imported. ByteMind execution is unverified.
ReLU and its derivative
z=[-3,0,2]print([max(0,x) for x in z],[int(x>0) for x in z])Expected output: [0, 0, 2] [0, 0, 1]. At zero the example deliberately chooses the zero subgradient convention.
How it works
ReLU(z)=max(0,z) has derivative 1 for positive z and 0 for negative z; at zero choose a subgradient convention (here 0). Tanh maps to (-1,1) and has derivative 1-tanh(z)^2. Sigmoid maps to (0,1), with derivative p*(1-p). Large absolute inputs saturate sigmoid/tanh, making gradients small. ReLU can have inactive units with negative preactivation on all samples. Initialize weights independently with zero-centered random values: Glorot/Xavier variance 2/(fan_in+fan_out) is a common starting point for tanh; He variance 2/fan_in for ReLU under simplifying assumptions. These rules mitigate, not guarantee, stable signal propagation. Zero biases can be fine with randomly initialized weights; identical hidden units may remain identical under deterministic training.
Saturation diagnostic
from math import tanhprint([round(1-tanh(z)**2,5) for z in [0,2,5]])Expected output: [1.0, 0.07065, 0.00018]. Tanh sensitivity falls sharply far from zero, potentially weakening backpropagation.
Common mistakes
Do not confuse activation outputs with derivatives. Do not evaluate exp(-z) blindly for large negative z. Random large weights may saturate units. Do not claim ReLU is differentiable at zero.
Practice and next steps
Compare tanh derivatives at zero and at magnitude five. Change the scale of initial weights and inspect activation histograms before training.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Activation functions — knowledge check
Apply activation functions to small examples and debugging scenarios.
What is the chosen ReLU derivative at zero?
What happens to tanh derivative at large |z|?
Why use random hidden weights instead of identical zero weights?
Which variance is the common He starting rule for ReLU?
What is sigmoid output for finite real logits mathematically?