Deep Learning Slides 📂 Introduction · 6 of 18 31 min read

Forward Propagation in Neural Networks: A Visual Walkthrough

Watch an input flow through a network into a prediction. This visual guide breaks forward propagation into four operations — affine transform, activation, layer-by-layer flow, and softmax — then runs two fully worked numerical examples by hand and in NumPy, from a single neuron to a 2-layer network.

Forward Propagation in Neural Networks

Feed an input in one end and watch it flow, layer by layer, into a prediction. No learning, no guesswork — just clean, deterministic arithmetic moving in one direction. This is how a network thinks.
Layer-by-Layer Flow z = Wx + b Activations Worked Examples

Press Next → or use ← → arrow keys

Section 01

The Story: A Whisper Through Many Rooms

Picture a message whispered from room to room. Each room hears the input, reshapes it slightly, and passes its own version to the next. By the final room the whisper has been transformed into a clear decision. A neural network's forward pass works exactly like this — each layer transforms the signal and hands it forward, never backward.
Input Hidden Hidden Output
📖
What forward propagation means

It's the process of passing an input through every layer — computing weighted sums and applying activations — to produce a final prediction. One direction, input to output.

Section 01

Pure, One-Directional Arithmetic

During the forward pass, nothing learns. The weights are fixed; the network simply computes. Every prediction is a deterministic chain of multiply-add-activate steps.

1Direction — input flows only forward
0Weights changed during the pass
=Same input always gives the same output
🔄
Forward computes, backprop corrects

Forward propagation produces the prediction. Only afterward does backpropagation measure the error and adjust the weights. This deck is entirely about that first, forward half.

Section 02

The Four Core Operations

Every forward pass — from a single neuron to GPT — is built from just these four moves:

📐
1 · Affine transform
z = Wx + b. Each neuron takes a weighted sum of inputs and adds a bias. W scales and rotates; b shifts.
🌊
2 · Activation
a = f(z). Applied element-wise, it injects the non-linearity that lets networks bend decision boundaries.
🪜
3 · Layer-by-layer
aˡ = f(Wˡaˡ⁻¹ + bˡ). One layer's output becomes the next layer's input — abstractions stack.
🎯
4 · Softmax output
ŷᵢ = eᶻⁱ / Σeᶻʲ. The final layer turns raw scores into a probability distribution that sums to 1.
🧱
Repeat and stack

Affine then activation, over and over, then a softmax at the end. Master these four and you understand the forward pass of any feedforward network.

Section 02

Operation 1: The Affine Transform

The workhorse step. Multiply the inputs by a weight matrix, add a bias vector — a linear reshaping of the data.

z = Wx + b
W = weight matrix · x = input vector · b = bias vector
The weight matrix rotates and scales the input space — stretching some directions, shrinking others. It decides how strongly each input feeds each neuron.
The bias shifts the result up or down, letting the neuron fire even when all inputs are zero. It moves the decision boundary off the origin.
⚠️
Linear alone isn't enough

Stacking affine transforms only ever produces another affine transform. That's why every hidden layer must follow it with a non-linear activation.

Section 02

Operation 2: The Activation

After the affine step, each value passes through a non-linear function a = f(z). The choice of f shapes what the network can learn:

FunctionFormulaRangeNote
ReLUmax(0, z)[0, ∞)Fast; risk of dead neurons
Sigmoid1/(1 + e⁻ᶻ)(0, 1)Vanishing gradient
Tanh(eᶻ−e⁻ᶻ)/(eᶻ+e⁻ᶻ)(−1, 1)Zero-centred
Softmaxeᶻⁱ / ΣeᶻʲprobabilitiesOutput layer only
🌊
This is where the magic enters

Non-linearity is the reason depth matters. Remove f and the whole network collapses into a single linear layer, no matter how many you stack.

Section 03

The Computation Graph

Zoom out and the forward pass is a graph: inputs on the left, each layer applying affine + activation, flowing rightward to the output. Here's a 2 → 2 → 2 network:

x₁ x₂ a¹₁ a¹₂ ŷ₁ ŷ₂ InputHidden · ReLUOutput · Softmax W¹, b¹W², b²
🔀
Every arrow is a weight

Each connection carries a weight; each node applies its activation. Follow the arrows left to right and you've computed the whole network's prediction.

Section 04

Numerical 1: A Single Neuron

The smallest possible forward pass. Inputs x = [2, 3], weights W = [0.5, −0.4], bias b = 1, ReLU activation.

1
Affine: z = (0.5 × 2) + (−0.4 × 3) + 1 = 1.0 − 1.2 + 1.0 = 0.8
2
Activate: a = ReLU(0.8) = max(0, 0.8) = 0.8
That's the entire operation of one neuron

Multiply, add the bias, squash. Because 0.8 is positive, ReLU passes it straight through. A network is just thousands of these running in parallel and in sequence.

Section 05

Numerical 2: A Full 2-Layer Network

Now a complete network: Input (2) → Hidden (2, ReLU) → Output (2, Softmax). Here's everything we're given:

x = [1, 2]
W¹ = [[0.1, 0.2], [0.3, 0.4]]
b¹ = [0, 0]
W² = [[0.5, −0.3], [−0.1, 0.6]]
b² = [0, 0]
output activation = Softmax
🎬
Two rounds of affine + activation

We'll push x through Layer 1 (affine → ReLU), then Layer 2 (affine → softmax), and read off a class probability. Next slide runs the numbers.

Section 05

Running the Numbers

1
Layer 1 affine: z¹ = W¹x + b¹ = [0.1·1 + 0.2·2,   0.3·1 + 0.4·2] = [0.5, 1.1]
2
Layer 1 ReLU: a¹ = ReLU([0.5, 1.1]) = [0.5, 1.1] (both positive)
3
Layer 2 affine: z² = W²a¹ + b² = [0.5·0.5 − 0.3·1.1,   −0.1·0.5 + 0.6·1.1] = [−0.08, 0.61]
4
Softmax: e⁻⁰·⁰⁸ ≈ 0.923, e⁰·⁶¹ ≈ 1.840, sum ≈ 2.763 → ŷ = [0.334, 0.666]
🏆
Prediction: Class 1 with 66.6% confidence

The network is more confident in class 1 (66.6%) than class 0 (33.4%). That single number is the end product of the entire forward pass — pure arithmetic, start to finish.

Section 05

The Matrix View — One Layer at Once

We never loop over neurons one at a time. A single matrix multiply computes an entire layer, and a batch of inputs flows through together:

= f( Aˡ⁻¹ + )
Aˡ⁻¹ holds the whole batch as columns — one matmul does it all
QuantityShapeMeaning
(nₗ × nₗ₋₁)weights: this layer's neurons × previous layer's
Aˡ⁻¹(nₗ₋₁ × m)inputs for a batch of m examples
(nₗ × 1)bias, broadcast across the batch
(nₗ × m)this layer's activations for all m examples
Why GPUs love the forward pass

Expressing a layer as one matrix multiply lets hardware process thousands of neurons and hundreds of examples in parallel — the reason modern networks train at all.

Section 06

The Forward Pass in NumPy

The whole 2-layer example is a handful of lines — two matrix multiplies and two activations:

import numpy as np

x  = np.array([1, 2], dtype=float)
W1 = np.array([[0.1, 0.2], [0.3, 0.4]])
b1 = np.zeros(2)
W2 = np.array([[0.5, -0.3], [-0.1, 0.6]])
b2 = np.zeros(2)

def relu(z):    return np.maximum(0, z)
def softmax(z):
    e = np.exp(z - np.max(z))       # stability trick
    return e / e.sum()

z1 = W1 @ x + b1                     # affine, layer 1
a1 = relu(z1)                        # activation
z2 = W2 @ a1 + b2                    # affine, layer 2
y_hat = softmax(z2)                  # output probabilities

print(y_hat)                         # [0.334 0.666]
print("Class", np.argmax(y_hat))       # Class 1
🧩
The code mirrors the math exactly

Each line is one operation from the walkthrough. @ is matrix multiply — the vectorized affine step in action.

Section 06

Forward vs Backward — Two Halves

Forward propagation is only half the training loop. It's worth seeing exactly where it ends and learning begins:

Forward propagationBackpropagation
DirectionInput → outputOutput → input
PurposeProduce a predictionCompute gradients of the error
WeightsUnchangedUpdated
MathsMatrix multiply + activationChain rule of derivatives
At test timeRuns aloneNot used
🎓
At inference, forward is all you need

A deployed model only runs forward propagation — identical to training, minus Dropout and with BatchNorm frozen. Backprop exists purely to teach the weights; once learned, the forward pass does the work.

Section 07

6 Golden Rules

  Forward-pass cheat-sheet
1No weights change during the forward pass — it's purely deterministic arithmetic.
2Every hidden layer needs a non-linear activation, or depth buys you nothing.
3Multi-class output uses Softmax paired with cross-entropy loss.
4Subtract the max logit before Softmax — e^(z − max z) — to stay numerically stable.
5The forward pass is identical at test time, except Dropout is off and BatchNorm is frozen.
6Think in matrices. One matmul per layer processes an entire batch at once.
🚀
You can now trace any prediction

Affine, activate, repeat, softmax. From one neuron to a transformer, forward propagation is the same clean flow — and it's exactly what runs every time a model makes a prediction.