Gradient LabStart the lesson

Lessons › Chapter 8: Neural networks

Activation functions

An activation function adds a bend. The most popular, relu, is wonderfully simple: negative numbers become 0, positive numbers pass through unchanged.

Watch it move. This lesson is interactive on Gradient Lab: every step is an animated scene you can replay.

Start the interactive lesson

Step by step

Story

Why the bends?

Leo stacks ten layers, but the network still behaves like a single straight line. Something is missing.

Problem

Why networks need a bend

Each neuron computes a weighted sum, which is a straight-line kind of thing. Stack straight lines on straight lines and you still get a straight line. Without something extra, a 100-layer network is no smarter than one layer.

Concept

ReLU: off, then on

An activation function adds a bend. The most popular, relu, is wonderfully simple: negative numbers become 0, positive numbers pass through unchanged.

Concept

Sigmoid and tanh: smooth S-curves

Sigmoid squashes everything between 0 and 1 (you met it in logistic regression). Tanh is its cousin, running from −1 to 1. They’re used where outputs should stay in a range.

Key idea

Bends let networks draw curves

With a bend after every layer, a network can combine many small kinks into any shape it needs, like this round boundary that no straight line could draw.

Real life

In real life: a switch vs a dimmer

A light switch is either off or on. A dimmer lets more light through the further you turn it. ReLU is a dimmer that stays fully off until you pass zero, then brightens steadily. That simple bend is inside almost every modern network.

Quick check: What does ReLU output for an input of −3?

ReLU turns every negative number into 0 and leaves positives unchanged.

Pseudocode

relu(x)    = max(0, x)          # off below 0, straight line above
sigmoid(x) = 1 / (1 + e^(−x))   # smooth S from 0 to 1
tanh(x)    = an S from −1 to 1

layer_output = activation(W × input + bias)
# without activations, stacked layers collapse into one straight line

Key terms

activation function
The bend applied after a neuron’s sum, such as ReLU or sigmoid.
relu
An activation: 0 for negative inputs, the input itself for positive ones.