๐Ÿ”ฅLimited Offer: Get 50% OFFon AI & Full Stack Courses๐Ÿ”ฅ
Back to Deep Learning Notes
Topic #60

Forward Propagation

Forward propagation is the process of pushing an input through every layer of a network, in order, to produce a final prediction. It's called "forward" to distinguish it from backpropagation, which runs in the opposite direction.

The General Formula, Layer by Layer

\[ \mathbf{a}^{(0)} = \mathbf{x}, \qquad \mathbf{z}^{(l)} = \mathbf{W}^{(l)}\mathbf{a}^{(l-1)} + \mathbf{b}^{(l)}, \qquad \mathbf{a}^{(l)} = \phi^{(l)}(\mathbf{z}^{(l)}) \]

Starting from the input \(\mathbf{a}^{(0)}=\mathbf{x}\), each layer \(l\) computes its pre-activation \(\mathbf{z}^{(l)}\) (a matrix multiplication plus bias) and then its activation \(\mathbf{a}^{(l)}\) (applying the layer's non-linearity). The final layer's activation is the network's prediction, \(\hat{\mathbf{y}} = \mathbf{a}^{(L)}\) for an \(L\)-layer network.

Full Numerical Walkthrough โ€” A Tiny 2-Layer Network

Input \(\mathbf{x}=[1, 2]\). Layer 1: \(\mathbf{W}^{(1)} = \begin{bmatrix}0.1 & 0.2\\0.3 & 0.4\end{bmatrix}\), \(\mathbf{b}^{(1)}=[0.1, 0.1]\), ReLU activation.

\[ \mathbf{z}^{(1)} = \begin{bmatrix}0.1(1)+0.2(2)+0.1\\0.3(1)+0.4(2)+0.1\end{bmatrix} = \begin{bmatrix}0.6\\1.2\end{bmatrix}, \qquad \mathbf{a}^{(1)} = \text{ReLU}(\mathbf{z}^{(1)}) = \begin{bmatrix}0.6\\1.2\end{bmatrix} \]

Layer 2 (output): \(\mathbf{W}^{(2)}=[0.5, -0.5]\), \(b^{(2)}=0\), sigmoid activation.

\[ z^{(2)} = 0.5(0.6) + (-0.5)(1.2) + 0 = 0.3 - 0.6 = -0.3 \] \[ \hat{y} = \sigma(-0.3) = \frac{1}{1+e^{0.3}} \approx 0.426 \]

The network's final prediction for this input is approximately 0.426.

Code โ€” The Same Computation in PyTorch

import torch
import torch.nn as nn

class TinyNet(nn.Module):
    def __init__(self):
        super().__init__()
        self.layer1 = nn.Linear(2, 2)
        self.layer2 = nn.Linear(2, 1)

    def forward(self, x):
        a1 = torch.relu(self.layer1(x))    # layer 1: weighted sum + ReLU
        y_hat = torch.sigmoid(self.layer2(a1))   # layer 2: weighted sum + sigmoid
        return y_hat

model = TinyNet()
x = torch.tensor([[1.0, 2.0]])
prediction = model(x)   # this single call performs the entire forward pass
print(prediction)

Note that model(x) (equivalently, model.forward(x)) is exactly this note's formula, executed automatically โ€” every "forward pass" you'll write for the rest of this hub follows this same layer-by-layer pattern, however many layers or however specialized (convolutional, attention-based) they are.

Common Mistakes

  • Applying an activation function to the very last output when the loss function already expects raw logits โ€” e.g. applying sigmoid before nn.BCEWithLogitsLoss, which applies sigmoid internally for numerical stability.
  • Forgetting that forward propagation, by itself, does not involve any learning โ€” it only computes a prediction from the network's current weights; learning happens afterward, in the backward pass and weight update.

Interview Relevance

Q: "Walk through what happens during a neural network's forward pass." The input is passed through each layer in sequence: at each layer, the previous layer's output is multiplied by that layer's weight matrix, a bias is added, and a non-linear activation function is applied โ€” the result becomes the input to the next layer. This repeats until the final (output) layer, whose activation is the network's prediction.

Practice Question

For a 2-layer network with \(\mathbf{W}^{(1)}=[[1,0],[0,1]]\), \(\mathbf{b}^{(1)}=[0,0]\), ReLU, then \(\mathbf{W}^{(2)}=[1,1]\), \(b^{(2)}=0\), no output activation โ€” compute the forward pass output for input \(\mathbf{x}=[-1, 3]\).

Want to go beyond the notes?

Join CodingNow 2.0's Deep Learning course โ€” live mentorship, real projects, and 100% placement support.

Enroll Now โ€” Free Demo Available

Forward Propagation โ€“ FAQs

Quick answers about learning Forward Propagation in Deep Learning.

This free note from CodingNow 2.0 explains Forward Propagation in Deep Learning โ€” concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Deep Learning topic on CodingNow 2.0, including Forward Propagation, is 100% free with no signup required.
With focused practice, most students grasp Forward Propagation in 1โ€“3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) โ€” expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now