What is forward propagation in a neural network?
Forward propagation is the computation a neural network runs to turn an input into a prediction. Each layer takes the previous layer's outputs, multiplies them by its weights, adds them up, and applies an activation function. The result flows to the next layer until the output layer produces the answer.
Every use of a trained model is a forward pass: classifying an image, scoring a loan application, or generating the next word in a chatbot reply. Training runs the forward pass too, because the loss and the gradients are both computed from its outputs. The example here follows one cat photo through a network with 3 inputs, two hidden layers of 4 neurons, and 2 outputs.
Key ideas
- A forward pass turns an input vector into a prediction, one layer at a time.
- Each neuron computes a weighted sum of its inputs and applies an activation function.
- A whole layer is one matrix multiplication followed by an element-wise activation.
- Layers must run in order, but neurons within a layer can run in parallel.
- With random weights, the forward pass still produces an answer, just a poor one.
- Training uses the forward pass's outputs to compute the loss and the gradients.
Common questions
What is the difference between forward propagation and backpropagation?
Forward propagation computes the prediction from the input. Backpropagation runs after it, starting from the loss and moving backward to compute each weight's gradient. Inference needs only the forward pass; training needs both.
Is forward propagation the same as inference?
Inference is running a trained model on new data, and it consists of forward passes. During training, a forward pass is also run on every batch of training examples, so forward propagation is used in both phases.
Why do activations need to be stored during the forward pass?
Backpropagation needs each layer's inputs and outputs to compute the gradients. During training, the framework keeps them in memory until the backward pass is done. At inference time nothing is stored, which is why running a model takes much less memory than training it.
How is forward propagation done for a batch of inputs?
The input vectors are stacked into a matrix X with one row per example. Each layer then computes σ(XW + b) in one matrix multiplication, producing outputs for every example at once. Batching makes far better use of GPU hardware than processing examples one by one.
Related explainers
- Neural Networks — Neurons, layers, and how networks learn
- Activation Functions — Why networks need non-linearity to learn
- Backpropagation — How networks learn from their mistakes
- Weight Initialization — Xavier, He, and why random weights matter
- Tensors, Broadcasting & Reshaping — The data structures of deep learning
- Loss Functions — How networks measure their mistakes
References
- Goodfellow, Bengio & Courville (2016), "Deep Learning", chapter 6: Deep Feedforward Networks
- Nielsen, "Neural Networks and Deep Learning", chapter 1
- Zhang et al., "Dive into Deep Learning", Forward Propagation, Backward Propagation, and Computational Graphs
- Glorot & Bengio (2010), "Understanding the difficulty of training deep feedforward neural networks", AISTATS
Last updated