What a Neural Network Computes
Weighted sums all the way down
A neural network is a stack of weighted ladders: inputs pass through layers of weighted sums + activations to a prediction. Understanding the forward pass is the base layer for everything from CNNs to transformers.
What you will learn
- Describe the forward pass through a layer
- Explain parameters vs activations vs layers
- Build a tiny network by hand
What is this?
A neural network takes a vector of numbers (a document embedding, pixel values, features) and pushes it through layers. Each layer computes weights × inputs plus a bias, passes the result through a nonlinear activation, and hands the output to the next layer. The final layer produces the prediction. Every modern model — including transformers — is this same mechanism arranged at scale.
Why do you need it?
- LLMs are neural networks; you cannot reason about capacity, cost or errors without the forward-pass mental model.
- Attention, embeddings and logits are all linear maps + nonlinearities with bigger bookkeeping.
- Understanding layer widths helps reason about compute and memory footprints.
- Debug surprises (NaN, saturation) trace back to layer math.
Mental model
An assembly line of weighted votes
A neural network layer
Each station takes every part from the previous station, weighs each one's importance, sums the votes, applies an on/off-ish decision, and passes its verdict on. Stack stations and you build predictions from parts.
How it works
- Inputs x form a vector; each layer has a weight matrix W and bias b.
- The layer computes z = W·x + b — a weighted vote across all inputs.
- A nonlinearity (ReLU, tanh) transforms z; without it the whole stack collapses to one linear map.
- Stacked layers compose into richer features: edges → shapes → objects (vision), tokens → phrases → meaning (text).
- The final layer maps to logits; softmax/excitation turns logits into probabilities.
The forward pass.
Examples
Two scaled conjuncts by hand
import numpy as np x = np.array([0.5, 0.3]) # input featuresW1 = np.array([[0.2, -0.4], [0.1, 0.3]])b1 = np.array([0.0, 0.1])z1 = W1 @ x + b1a1 = np.maximum(0.0, z1) # ReLUW2 = np.array([[1.0, -1.0]])out = W2 @ a1 print(out) # a real-valued head output from a 2-layer netExactly one forward pass end to end. Scale the weights and stack thousands of layers, and you have the compute a transformer performs per token.
In production
- An embeddings model is a network whose hidden activations become the vectors you retrieve against.
- A classifier head trained on a frozen embedding is one linear layer over a pre-trained base.
- Serving-size math (how many params, what precision) derives directly from layer widths.
Best practices
- Reason in layers and parameter counts, not 'model size' vaguely.
- Profile the forward pass for latency before optimizing anything else.
- Use standard activations unless you have measured reason not to.
Common mistakes
- Believing 'deep' always beats 'wide' without measuring the task.
- Confusing activations (per-input) with parameters (static weights).
- Hand-rolling forward passes in app code instead of using the library's optimized path.
Common issues
All outputs identical regardless of inputActivation saturation or loss of gradient signal
Check for scale issues, dead ReLUs and normalization.
Debugging tips
- NaN in predictions usually means activations exploded — check normalization and learning rate, not the data.
- A frozen feature layer + fine head regressing? Verify the gradient actually flows (dummy-training a single batch).
Interview checkpoint
Hands-on lab
- Compute a 2-layer network forward pass with no libraries
- Verify shapes and output sanity by hand
- Trace one weight's influence on the output
Forward Pass in Pure Python
30 min · intermediate
Quick quiz
Which quantity is adjusted during training?
A stack of linear-only layers can model any nonlinear function.