A summary still needs processing.
Imagine attention has already gathered clues about the word “bank.” The model now needs to turn that bundle into a sharper, more useful representation for the next layer.
LESSON 05 The private workshop
Short answer: a feed forward neural network is a neural network in which data moves in one direction only: from the input layer, through one or more hidden layers, to the output layer, with no loops or feedback. Each neuron multiplies its inputs by weights, adds a bias and passes the result through an activation function.
A small two-stage workshop that reshapes one token representation without looking at its neighbors.
↳ Basics / definition

A feedforward neural network is the simplest and oldest family of neural networks, and it’s still everywhere. You give it a list of numbers (pixel values, measurements, a token’s vector), it pushes them through a few layers of arithmetic, and it hands back a prediction: a class, a probability, a price, or a new vector.
The defining rule is the direction. Information feeds forward: layer 1 feeds layer 2, layer 2 feeds layer 3, and nothing ever flows back to an earlier layer while the network is making a prediction. There’s no memory of the previous input either. Feed the same numbers in twice and you get exactly the same answer twice.
You’ll see the same idea under several names:
If neural networks in general are new to you, start with the neural networks lesson and come back.
Because each layer’s output is fed forward as the next layer’s input, and that’s the only direction anything travels. The contrast is with recurrent networks, which feed some of their output back into themselves so they can carry information from one step of a sequence to the next. “Feedforward” describes the wiring when the network runs, not how it’s trained. (Training does send an error signal backwards. That’s backpropagation, a separate step.)
↳ Basics / structure
The hero picture at the top of this page and Experiment 01 show the shape: a few input values on the left, a wider column of hidden neurons in the middle, and an output on the right, with every connection pointing the same way. Here are the parts, in the order data meets them:
z = w₁x₁ + w₂x₂ + … + b.z through a simple non-linear function, such as ReLU, and that becomes its output h.In matrix form, a whole layer is one line: h = activation(W·x + b). A network is just that line repeated, with each layer’s h becoming the next layer’s x.
The perceptron (Rosenblatt, 1958) is a single neuron with a hard threshold: weighted sum plus bias, then output 1 if the result is positive and 0 otherwise. It can only separate classes with a straight line, so it famously can’t learn XOR. Stack neurons into at least one hidden layer with a non-linear activation and you get a multilayer perceptron, which can draw curved boundaries. With enough hidden neurons, an MLP can approximate any continuous function on a bounded range to any accuracy you like (the universal approximation theorem, Hornik et al., 1989). “Can approximate” isn’t “will learn easily”, but it’s why this simple design is so useful.
Without an activation, two linear layers collapse into one linear layer, and the network can’t learn anything a straight line can’t. The activation is what makes depth worth having. The common choices:
max(0, z): keeps positive values and turns negatives into 0. Cheap, and the default in most hidden layers.1 / (1 + e⁻ᶻ): squashes any number into the range 0 to 1, so it’s handy for a final “probability of yes” output. Rarely used in hidden layers now because it slows training in deep stacks.You can switch between ReLU and GELU in Experiment 01 and watch one neuron go from exactly zero to slightly negative.
↳ Worked example / by hand
Let’s run a tiny feed forward neural network on paper: 2 inputs → 2 hidden neurons (ReLU) → 1 output neuron (sigmoid). Think of it as a toy yes/no classifier. The weights are made up for the example. In a real network they come from training.
The network’s numbers (9 parameters in total):
| Layer | Neuron | Weights | Bias | Activation |
|---|---|---|---|---|
| Hidden | h₁ | 0.6 (from x₁), −0.4 (from x₂) | 0.1 | ReLU |
| Hidden | h₂ | 0.4 (from x₁), 0.6 (from x₂) | −0.1 | ReLU |
| Output | y | 1.0 (from h₁), −0.5 (from h₂) | 0.2 | sigmoid |
The input: x₁ = 1.0, x₂ = 0.5.
Step 1: hidden neuron 1.
Weighted sum: z₁ = 0.6 × 1.0 + (−0.4) × 0.5 + 0.1 = 0.6 − 0.2 + 0.1 = 0.5.
ReLU: h₁ = max(0, 0.5) = 0.5.
Step 2: hidden neuron 2.
Weighted sum: z₂ = 0.4 × 1.0 + 0.6 × 0.5 + (−0.1) = 0.4 + 0.3 − 0.1 = 0.6.
ReLU: h₂ = max(0, 0.6) = 0.6.
Step 3: output neuron.
Weighted sum: z = 1.0 × 0.5 + (−0.5) × 0.6 + 0.2 = 0.5 − 0.3 + 0.2 = 0.4.
Sigmoid: y = 1 / (1 + e^(−0.4)) = 1 / (1 + 0.6703) = 1 / 1.6703 ≈ 0.599.
The network says “yes” with about 60% confidence. That’s the whole forward pass: multiply, add, activate, repeat. Nothing was looked up and nothing flowed backwards.
What ReLU does: try a different input. Feed x₁ = 0.0, x₂ = 1.0:
Now the answer leans slightly towards “no”, and only hidden neuron 2 had a say. Different inputs light up different hidden neurons. That is how even a small network can respond to combinations of features rather than to each feature separately.
The token workshop below does exactly this with 3 inputs, 3–6 hidden neurons and 3 outputs, and the calculation table shows every sum. To write the same thing in NumPy, follow the neural network from scratch in Python tutorial.

↳ Compare / architectures
All three are built from the same weighted-sum-plus-activation neurons. What changes is the wiring.
| Feedforward network (MLP) | Recurrent neural network (RNN) | Convolutional neural network (CNN) | |
|---|---|---|---|
| Direction of data | One way, input → output | Loops: a hidden state is fed back at every time step | One way, input → output |
| Connections | Every neuron sees the whole previous layer (fully connected) | Same weights reused at each step of a sequence | Small filters slide over the input and share weights |
| Memory of earlier inputs | None | Yes, through the hidden state | None (beyond what fits in its receptive field) |
| Input shape | Fixed-length vector | Sequence of any length | Grid: image, audio spectrogram, etc. |
| Good at | Tabular data, small classifiers, layers inside bigger models | Sequences, time series (LSTM, GRU) | Images and other spatial data |
| Is it feedforward? | Yes | No | Yes, a specialised kind |
Two points trip people up. First, a CNN is a feedforward network: its data still flows one way with no cycles. It just replaces full connections with shared, local filters (Goodfellow et al., Deep Learning, 2016). When people contrast “feedforward vs CNN” they usually mean “fully connected MLP vs CNN”. See CNN layers explained for convolution and pooling. Second, a transformer is also feedforward when it runs: attention looks across the whole sequence at once instead of looping through it step by step.
↳ Training / backpropagation
The forward pass makes a prediction. Training makes the predictions better, in a loop:
One step with our example. Say the correct answer for x = (1.0, 0.5) was “yes” (1). The network said 0.599, so with a sigmoid output and cross-entropy loss, the error signal at the output is 0.599 − 1 ≈ −0.401. The gradient for each output weight is that signal times the hidden value it multiplies: −0.401 × 0.5 ≈ −0.201 for the weight from h₁, and −0.401 × 0.6 ≈ −0.241 for the weight from h₂. With a learning rate of 0.1, updating just the output layer:
Run the forward pass again and the output rises from 0.599 to about 0.614. Closer to 1, and backpropagation would also adjust the hidden layer at the same time. The gradient descent lesson lets you watch this downhill walk interactively.
So “feedforward vs backpropagation” isn’t a choice between two kinds of network. Feedforward describes how data moves when the network makes a prediction. Backpropagation is how the network gets trained.
↳ In practice / uses
↳ Bridge / inside a transformer
This is where the rest of this lesson zooms in. A transformer block has two main parts. Attention lets each token gather information from the other tokens. Then a position-wise feed-forward network works on each token’s vector on its own. That FFN is a feed forward neural network with one hidden layer, the same shape as the worked example above, just much wider:
d_model to a wider hidden size d_ff, usually about 4× wider. In the original Transformer (Vaswani et al., 2017) that’s 512 → 2048.d_model, so it can be added to the residual stream and passed to the next block.Two things make it different from a stand-alone MLP. It uses the same weights at every position, so token 1 and token 500 go through the identical network. And it never mixes positions: all communication between tokens happens in attention, and all per-token processing happens here. Because of that 4× expansion, the FFN layers hold roughly two-thirds of the weights in a typical transformer block (8·d_model² of about 12·d_model², not counting biases and norms).
The experiments below trace one token through a toy version: 3 features in, 3–6 hidden neurons, 3 features out. For how the FFN sits between residual connections and layer norms, see the transformer block lesson, and for the full pipeline from tokens to next-word probabilities, how a transformer works.
00 Overview / start here
Attention can bring useful information into a token. A feed-forward network then works on that token’s representation alone, turning combinations of features into a new signal.
Imagine attention has already gathered clues about the word “bank.” The model now needs to turn that bundle into a sharper, more useful representation for the next layer.
A feed-forward network applies the same two learned linear transformations and a nonlinear activation to each token separately. No token can hand information to its neighbor inside this operation.
A token representation, such as [0.80, 0.20, 0.60], enters.
A linear layer makes a wider hidden vector so several combinations can be inspected.
ReLU can set negative signals to zero; GELU bends them smoothly instead.
A second linear layer mixes hidden features back into the model-sized vector.
The output continues through the transformer block, ready for the next operation.
The input is a bundle of ingredients, hidden neurons are temporary workbenches, and the output is a repacked bundle. The limit: neurons do not have human names like “meaning” or “grammar”; those labels are teaching shorthand, not a readable dictionary.
01 One token, five states
Choose a signal, change the hidden capacity or activation, and step through the same token from input to output. The weights stay fixed so you can see which control caused each change.
The default vector is [0.80, 0.20, 0.60]. Its shape is [3]: three features for one token. The hidden workspace has shape [4] by default, and the output returns to shape [3].
The three numbers are feature strengths, not words. Switch one balance to see different neurons respond.
ReLU keeps positive values and turns negative values into exactly 0. That clear zeroing makes the boundary easy to inspect.
Three feature values arrive from the earlier transformer work.
shape [3] / calculated upstreamEach hidden neuron forms a weighted sum before the gate.
shape [4] / learned W₁, calculated zActivation changes the pre-activation values one by one.
shape [4] / calculated hThe wide hidden signal is remixed into model width.
shape [3] / learned W₂, calculated yThe vector is ready to meet the residual path and continue.
same values / new role in the blockNeuron 3 is silent because its pre-activation is negative. ReLU turns that value into 0.
The hidden width is a workspace, not a second sentence. One token enters; one token leaves.
02 Same rule, different token
Transformers reuse the same feed-forward weights at every position. Click a token below: only the input vector changes. The rule, hidden width, and activation stay the same.
This is the contrast with attention: attention mixes information across token positions; the feed-forward step applies the same local transformation independently to each position.
Attention asks, “which positions should contribute?” The feed-forward network asks, “how should this one representation change?”
03 Do the small math
The visualization is not guessing. Each hidden value is a sum of three products, and each output value is a sum of hidden features multiplied by a second row of weights.
The table starts from the default bank-like vector, width 4, and ReLU. Learned weights are shown in blue-gray; values calculated from them are live.
| hidden neuron | weighted sum before activation | activation |
|---|
y₁ = 0.70×0.85 + 0.20×0.26 + −0.10×0.00 + 0.40×0.76 = 0.95
x has shape [3]; W₁ has shape [4 × 3]; h has shape [4]; W₂ has shape [3 × 4]; y has shape [3]. Matrix dimensions tell us which multiplication is legal and what width comes out.
A neuron is not a tiny person with a label. It is a weighted sum followed by a shared rule.
04 Make it runnable
Once the states are clear, the code is short. There is no framework here: arrays hold vectors, loops compute dot products, and the activation is one ordinary function.
The snippet uses the same default numbers as the calculation above. Run it in the page and compare the observed output with the receipt.
const input = [0.8, 0.2, 0.6];
const expand = [
[1.0, -0.5, 0.25],
[-0.3, 1.0, 0.5],
[0.6, 0.2, -1.0],
[0.1, 0.7, 0.9],
];
const preActivation = expand.map((row) =>
row.reduce((sum, weight, index) => sum + weight * input[index], 0),
);
const hidden = preActivation.map((value) => Math.max(0, value));
const compress = [
[0.7, 0.2, -0.1, 0.4],
[-0.4, 0.8, 0.6, 0.1],
[0.2, -0.3, 0.9, 0.5],
];
const output = compress.map((row) =>
row.reduce((sum, weight, index) => sum + weight * hidden[index], 0),
);
console.log(output.map((value) => Number(value.toFixed(2))));input is one token vector with three values.
expand computes four dot products, ReLU changes them, then compress computes three more dot products.
output is a new three-value vector. The example omits batching, residual connections, normalization, and training.
Real transformer feed-forward blocks add engineering and training context that this field guide intentionally leaves out. The core causal chain stays the same.
Production transformer layers commonly wrap the sub-layer in residual connections and layer normalization.
“One token at a time” describes independence, not a slow loop. Hardware can process the whole sequence batch together.
Here the numbers are fixed for inspection. Training changes them so outputs become useful for the task.
Start with the default token. First predict what happens to neuron 3 when you switch from ReLU to GELU. Then choose “edge-heavy,” set width to 6, and explain which stage changed the vector’s shape and which stage changed its values.
With ReLU, neuron 3 is exactly 0 because its pre-activation is −0.08. GELU keeps a small negative value instead of hard-zeroing it, so the hidden vector changes smoothly. Width changes how many hidden slots exist; activation changes the values inside those slots.
PRIMARY SOURCE The original Transformer paper places a position-wise fully connected feed-forward network beside multi-head attention in each layer. Its position-wise design is the basis for this lesson’s contrast: attention relates positions, while this sub-layer transforms each position independently. Read section 3.1 of Attention Is All You Need.
FAQ Feed-forward networks / quick answers
Seven quick answers about feed forward neural networks and the feed-forward layer inside a transformer.
It transforms each token’s current vector independently: a first matrix expands the features, an activation changes the response, and a second matrix compresses them back to model width.
The wider hidden space gives the network more room to form feature combinations. The nonlinear activation keeps the two linear steps from collapsing into one simple linear transformation.
No. The same weights are reused at every position, but the operation works on one position’s vector at a time. Attention is the part that mixes information across positions.
A feed forward neural network is a neural network where data flows one way, from the input layer through hidden layers to the output layer, with no loops. Each neuron computes a weighted sum of its inputs plus a bias and applies an activation function. A fully connected one is also called a multilayer perceptron (MLP).
Because each layer’s output is fed forward as the next layer’s input, and nothing flows back to an earlier layer while the network makes a prediction. Recurrent networks are the contrast: they feed their hidden state back into themselves at each step of a sequence.
Yes. A convolutional neural network passes data one way with no cycles, so it is a feedforward network. It uses small shared filters instead of full connections between layers. When people compare “feedforward vs CNN”, they usually mean a fully connected MLP vs a CNN.
Feedforward is how data moves through the network to make a prediction: input to output, one direction. Backpropagation is the training method that runs afterwards: it sends the error backwards through the layers to work out how to adjust each weight. Most feedforward networks are trained with backpropagation and gradient descent.