A forward pass computes a neural network's output by carrying inputs through its units in the forward direction. Each neuron combines incoming features using learned weights, then produces a signal for the next layer. In a single-neuron model, this resembles linear regression followed by an activation function. section 5.1.3
Layered networks repeat this process: one group of predictions becomes the input to the next, allowing successive layers to refine outputs and represent more complicated functions. A forward pass supplies the predictions that a loss function can evaluate. section 5.1.3 section 5.2.5
A minimal PyTorch forward pass follows this pattern:
- Define the network layers in the constructor, such as one linear layer receiving every feature. section 5.2.5
- Implement forward() to send the input through the layer and apply the sigmoid activation. section 5.2.5
- Call model(X) to obtain predictions, compute binary cross-entropy, and then use backpropagation and an optimizer to update weights. section 5.2.5
Predicting from names
A logistic-regression neural network accepts 3,663 TF-IDF features and returns one probability for each name. Passing names such as John, Ruby, and Sarah through the model produces values such as 0.0196, 0.4964, and 0.8199. These are forward-pass outputs; training uses them to calculate loss before changing the weights. section 5.2.5
>>> import torch >>> class LogisticRegressionNN(torch.nn.Module): ... def __init__(self, num_features, num_outputs=1): ... super().__init__() ... self.linear = torch.nn.Linear(num_features, num_outputs) ... def forward(self, X): ... return torch.sigmoid(self.linear(X)) >>> model = LogisticRegressionNN(num_features=vecs.shape[1], num_outputs=1) >>> model LogisticRegressionNN( (linear): Linear(in_features=3663, out_features=1, bias=True) )
Inspect the compact PyTorch implementation of a one-neuron forward() method. section 5.2.5







