liveBook · Manning

Forward pass

As explained in Math and Architectures of Deep Learning

The layer-by-layer computation, or forward pass, that produces neural-network activations and outputs from an input.

A forward pass generates a neural network’s output from an input by evaluating its layers in order. In a layered network, each layer receives only the preceding layer’s output, so an MLP can compute its prediction without explicitly expanding the entire nested function. section 8.2 section 8.3.2

For layer l, compute the pre-activation z^(l) = W^(l)a^(l−1) + b^(l), then apply an activation function a^(l) = σ(z^(l)). The input serves as a^(−1), and the final activation is the network output. Repeating these two operations turns matrix arithmetic and nonlinearities into a prediction. section 8.3.2 section 8.6

A forward pass has three practical properties:

  • It proceeds from the layer nearest the input toward the output layer. section 8.6
  • It needs only the current and preceding layer’s values during sequential evaluation. section 8.3.2
  • It supplies the prediction used to calculate loss before backpropagation produces parameter gradients. section 8.4.6

A PyTorch classifier

A model with two linear layers computes scores by nesting the layers: scores = linear2(linear1(X)). During training, the forward pass returns these raw scores to cross-entropy loss; prediction applies softmax and argmax afterward to obtain a class. section 9.2.3 section 9.2.3

Listing 8.1 PyTorch code for forward propagation
def Z(x, W_l, b_l):                    #1
    return torch.matmul(W_l, x) + b_l

def A(z_l):                            #2
    return torch.sigmoid(z_l)




def forward(x, W, b):                  #3
    L = len(W) - 1
    a_l = x
    for l in range(0, L + 1):          #4
        z_l = Z(a_l, W[l], b[l])       #5
        a_l = A(z_l)                   #6
    return a_l

The implementation shows the computation directly: calculate each layer’s affine transform, apply sigmoid, feed the activation into the next iteration, and return the final activation. section 8.3.2

How Math and Architectures of Deep Learning covers it

How deep it goes
Derives affine and activation computations, explains sequential evaluation, and demonstrates a PyTorch loop without expanding the full nested function.
Examples
Uses layered MLP equations, a PyTorch forward function, and a two-layer height-and-weight classifier.
What it assumes
Builds from perceptrons, layered networks, matrix-vector multiplication, and nonlinear activation functions.
What you can do after
Apply it via PyTorch to compute model scores, predictions, and training losses.
How it connects
Connects multilayer perceptrons, linear layers, activation functions, loss, and backpropagation.

Also explained in

Compare how 8 books explain forward pass →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Math and Architectures of Deep Learning. The section links point to the parts of the book it draws on.