Back to Topics

Forward and Backward Propagation

Description

Forward and Backward Propagation are fundamental mechanisms used in training deep neural networks. Together, they enable the network to learn from data and adjust its internal parameters (weights and biases).

Forward Propagation is the process of passing input data through the network layer by layer to generate predictions. Each neuron applies a weighted sum followed by an activation function to produce outputs that are passed to the next layer.

Backward Propagation (Backpropagation) is the process of calculating the error in predictions and updating weights to minimize this error. It uses the chain rule of calculus to compute gradients of the loss function with respect to each weight, enabling gradient descent optimization.

Key Insight

Backpropagation is not learning by itself—it's the mechanism by which gradients are calculated. The actual learning happens through an optimizer (like SGD or Adam) that uses these gradients to update weights.

  • Forward Propagation: Input → Weights → Activation → Output
  • Backward Propagation: Output Error → Gradients → Weight Updates
Forward and Backward Propagation Flow

Forward computes predictions; backward adjusts weights to improve them

Examples

Here's a basic example of forward and backward propagation using NumPy (without using deep learning frameworks):

import numpy as np

# Sigmoid activation and derivative
def sigmoid(x):
    return 1 / (1 + np.exp(-x))

def sigmoid_derivative(x):
    return x * (1 - x)

# Input and output
X = np.array([[0,0], [0,1], [1,0], [1,1]])
y = np.array([[0], [1], [1], [0]])  # XOR problem

# Initialize weights
np.random.seed(1)
weights_input_hidden = 2 * np.random.random((2, 4)) - 1
weights_hidden_output = 2 * np.random.random((4, 1)) - 1

# Training loop
for epoch in range(10000):
    # --- Forward Propagation ---
    hidden_input = np.dot(X, weights_input_hidden)
    hidden_output = sigmoid(hidden_input)
    final_input = np.dot(hidden_output, weights_hidden_output)
    output = sigmoid(final_input)

    # --- Backward Propagation ---
    error = y - output
    d_output = error * sigmoid_derivative(output)
    
    hidden_error = d_output.dot(weights_hidden_output.T)
    d_hidden = hidden_error * sigmoid_derivative(hidden_output)

    # --- Weight Updates ---
    weights_hidden_output += hidden_output.T.dot(d_output)
    weights_input_hidden += X.T.dot(d_hidden)

print("Final Output:\n", output)

This demonstrates a simple 2-layer neural network that learns XOR using raw forward and backpropagation.

Real-World Applications

Neural Network Training

Every neural network—from basic MLPs to advanced transformers—uses forward and backward propagation during training.

Autonomous Vehicles

Neural nets for object detection and lane tracking are trained using backpropagation to minimize prediction errors.

Speech Recognition

Deep models used in ASR systems (e.g., Siri, Google Assistant) are trained using this process to improve accuracy.

Financial Forecasting

Stock market models using neural nets rely on backpropagation to tune prediction functions for better accuracy.

Resources

Video Tutorials

below is the video resource

PDFs

The following documents

Recommended Books

Interview Questions

What is forward propagation?

Forward propagation is the process where input data passes through a neural network and produces output predictions. Each layer applies a linear transformation followed by an activation function.

What is backward propagation?

Backward propagation calculates gradients of the loss with respect to each weight using the chain rule and updates weights to reduce the loss during training.

Why is the chain rule important in backpropagation?

The chain rule enables the gradient of the loss function to be propagated backward layer by layer, allowing each weight in the network to be updated correctly.

What is the role of learning rate in backpropagation?

Learning rate controls how much the weights are adjusted in response to the calculated gradient. A high value can overshoot minima; a low value can slow convergence.