Lesson 05 / 07feed-forward network / field guide
Back to the lesson shelf

LESSON 05 The private workshop

Feed Forward Neural Network Explained (Interactive)

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.

In one lineExpand → activate → compress. Same rule, one token at a time.
POSITION_WISE_FFN / 05 reshaping
one token innew signal outx₁x₃h₁h₂h₃h₄y / output
input → hidden features → outputsame weights / local work
attention mixes; this workshop transforms
Short version: data flows one way, layer by layer. Inside a transformer, attention gathers and the feed-forward network reshapes.Step, change, compare.

↳ Basics / definition

What is a feed forward neural network?

Bundle of glowing fibre-optic strands fanning out in the dark, all running in one direction
Signals travel one way, layer after layer, with no path back.

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:

  • Feed forward network / feedforward network / FFN: the general term, used for any network without cycles.
  • Multilayer perceptron (MLP): a feedforward network whose layers are fully connected (every neuron sees every value from the layer before). This is what most people mean by “feed forward neural network”.
  • Feed-forward layer (in a transformer): a small two-layer MLP inside every transformer block. More on that further down.

If neural networks in general are new to you, start with the neural networks lesson and come back.

Why is it called “feed forward”?

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 structure: layers, weights, biases and activation

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:

  1. Input layer. Not really neurons, just the numbers you feed in. One value per feature: 2 measurements, 784 pixel values, or the 512 numbers of a token vector.
  2. Weights. Every connection from one layer to the next has a weight, a number that says how strongly (and in which direction) that input pushes the neuron. A layer with 3 inputs and 4 neurons has a 4 × 3 grid of weights.
  3. Bias. Each neuron also has one bias, an extra number added after the weighted sum. It shifts the point at which the neuron “switches on”.
  4. Weighted sum. Each hidden neuron computes z = w₁x₁ + w₂x₂ + … + b.
  5. Activation function. The neuron passes z through a simple non-linear function, such as ReLU, and that becomes its output h.
  6. Hidden layers. One or more layers of these neurons. Each one takes the previous layer’s outputs as its inputs. “Deep” learning just means many hidden layers.
  7. Output layer. The last layer turns the final hidden values into the answer: one sigmoid neuron for a yes/no probability, a softmax over several neurons for multiple classes, or a plain linear neuron for a number like a price.
  8. One-way flow. Input → hidden → … → output. No connection skips back, and no neuron feeds itself.

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.

Perceptron vs multilayer perceptron

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.

Activation functions in one minute

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:

  • ReLU, max(0, z): keeps positive values and turns negatives into 0. Cheap, and the default in most hidden layers.
  • GELU: a smooth version of ReLU that lets small negative values through a little. Used in the feed-forward layers of BERT and GPT-2 (Hendrycks & Gimpel, 2016).
  • Sigmoid, 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

A worked example: one forward pass 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:

  • z₁ = 0.6 × 0 + (−0.4) × 1.0 + 0.1 = −0.3, so h₁ = max(0, −0.3) = 0 (the neuron is silent).
  • z₂ = 0.4 × 0 + 0.6 × 1.0 − 0.1 = 0.5, so h₂ = 0.5.
  • z = 1.0 × 0 + (−0.5) × 0.5 + 0.2 = −0.05, so y = 1 / (1 + e^(0.05)) = 1 / 2.0513 ≈ 0.488.

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.

Macro photograph of a printed circuit board with tiny lit components and fine copper traces running in parallel
Fixed wiring, signals in one direction: a forward pass is closer to a circuit than to a conversation.

↳ Compare / architectures

Feedforward vs recurrent (RNN) vs convolutional (CNN) networks

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

How a feedforward network learns: backpropagation and gradient descent

The forward pass makes a prediction. Training makes the predictions better, in a loop:

  1. Forward pass: run a training example through the network and get a prediction.
  2. Loss: compare the prediction with the correct answer and turn the error into one number.
  3. Backpropagation: use the chain rule to work out, layer by layer from the output back to the input, how much each weight and bias contributed to that error (Rumelhart, Hinton & Williams, 1986).
  4. Gradient descent: nudge every parameter a small step in the direction that reduces the loss.
  5. Repeat for thousands or millions of examples.

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:

  • weight from h₁: 1.0 → 1.020
  • weight from h₂: −0.5 → −0.476
  • output bias: 0.2 → 0.240

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

Where feed forward neural networks are used

  • Tabular prediction: credit scoring, churn, demand forecasts and other spreadsheet-shaped data, often as a baseline next to tree models.
  • Classification heads: the last few fully connected layers that turn a CNN’s or transformer’s features into class probabilities.
  • Inside every transformer: each transformer block contains a feed-forward layer, so every large language model is full of small MLPs.
  • Recommendation and ranking: MLPs that combine user and item embeddings into a score.
  • Function approximation: value and policy networks in reinforcement learning, physics surrogates, control.

↳ Bridge / inside a transformer

The feed-forward network 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:

  1. Expand: a linear layer maps the token vector from the model width 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.
  2. Activate: a non-linearity, ReLU in the original paper and GELU in BERT and GPT-2. Many newer LLMs (LLaMA, for example) use a gated variant called SwiGLU (Shazeer, 2020).
  3. Compress: a second linear layer maps the hidden vector back to 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

After context comes transformation.

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.

familiar problem

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.

plain-language definition

A private workshop for each token.

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.

the basic storyinput → operation → output
  1. 01 / enterOne vector arrives.

    A token representation, such as [0.80, 0.20, 0.60], enters.

  2. 02 / expandMore feature slots.

    A linear layer makes a wider hidden vector so several combinations can be inspected.

  3. 03 / activateKeep useful signals.

    ReLU can set negative signals to zero; GELU bends them smoothly instead.

  4. 04 / compressReturn to model width.

    A second linear layer mixes hidden features back into the model-sized vector.

  5. 05 / leaveA changed representation.

    The output continues through the transformer block, ready for the next operation.

analogy + its limit

Workshop, not a lookup table.

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.

mental checklist

Ask four questions.

  • What vector enters?
  • How wide is the hidden workspace?
  • Which activation changes the signal?
  • What vector leaves?
first experiment / 01Open the token workshop

01 One token, five states

Make the chain visible.

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.

Run the private workshop.

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].

EXPERIMENT / 01x → W₁x → activation → W₂h → y
input signal / feature balance

The three numbers are feature strengths, not words. Switch one balance to see different neurons respond.

activation / what happens to a signal?

ReLU keeps positive values and turns negative values into exactly 0. That clear zeroing makes the boundary easy to inspect.

step through the causal chain

Start with the token vector. Nothing has been transformed yet.

01 / inputx

Token representation

Three feature values arrive from the earlier transformer work.

[0.80, 0.20, 0.60]shape [3] / calculated upstream
02 / expandz = W₁x + b₁

Pre-activation

Each hidden neuron forms a weighted sum before the gate.

[0.85, 0.26, −0.08, 0.76]shape [4] / learned W₁, calculated z
03 / activateh = φ(z)

Gated features

Activation changes the pre-activation values one by one.

[0.85, 0.26, 0.00, 0.76]shape [4] / calculated h
04 / compressy = W₂h + b₂

Output projection

The wide hidden signal is remixed into model width.

[0.95, −0.06, 0.47]shape [3] / learned W₂, calculated y
05 / outputnext layer

A new token signal

The vector is ready to meet the residual path and continue.

[0.95, −0.06, 0.47]same values / new role in the block
hidden neurons / feature barswidth 4 / activation: ReLU

Neuron 3 is silent because its pre-activation is negative. ReLU turns that value into 0.

stage 01 / input selectedtoy weights / no training

The hidden width is a workspace, not a second sentence. One token enters; one token leaves.

02 Same rule, different token

One workshop. Many tokens.

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.

Watch the private rule repeat.

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.

COMPARISON / 01same W₁ + same φ + same W₂
input vector[0.80, 0.20, 0.60]
same rule ↓
hidden activation[0.85, 0.26, 0.00, 0.76]
same rule ↓
output vector[0.95, −0.06, 0.47]
token A selected / local transformation onlyclick another token to compare

Attention asks, “which positions should contribute?” The feed-forward network asks, “how should this one representation change?”

03 Do the small math

Every bar has a receipt.

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.

Read one neuron from left to right.

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.

CALCULATION / 01three products → one sum
input x[0.80, 0.20, 0.60]
W₁ row / neuron 1[1.00, −0.50, 0.25]
bias b₁0.00
Live expansion calculation for the selected token
hidden neuronweighted sum before activationactivation
second projection / W₂h[0.95, −0.06, 0.47]

y₁ = 0.70×0.85 + 0.20×0.26 + −0.10×0.00 + 0.40×0.76 = 0.95

shapes in this toy

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.

default calculation / values match the runnable coderounded to two decimals

A neuron is not a tiny person with a label. It is a weighted sum followed by a shared rule.

04 Make it runnable

The whole mechanism in plain JS.

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.

Input → expand → activate → compress → output.

The snippet uses the same default numbers as the calculation above. Run it in the page and compare the observed output with the receipt.

feed-forward.js / smallest runnable core
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))));
observed output[0.95, −0.06, 0.47]This matches the hand calculation: the code is doing the same two matrix-shaped passes.
what enters

input is one token vector with three values.

what acts

expand computes four dot products, ReLU changes them, then compress computes three more dot products.

what leaves

output is a new three-value vector. The example omits batching, residual connections, normalization, and training.

WHAT IS DEFERRED / KEEP THE CORE CLEAR

Useful details, later.

Real transformer feed-forward blocks add engineering and training context that this field guide intentionally leaves out. The core causal chain stays the same.

01 / residual path

The block usually adds the old vector back.

Production transformer layers commonly wrap the sub-layer in residual connections and layer normalization.

02 / batching + hardware

Many tokens can be computed in parallel.

“One token at a time” describes independence, not a slow loop. Hardware can process the whole sequence batch together.

03 / trained weights

The weights are learned from error.

Here the numbers are fixed for inspection. Training changes them so outputs become useful for the task.

TRY IT YOURSELF / CONSOLIDATE

Predict before you click.

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.

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

A private
workshop.

Seven quick answers about feed forward neural networks and the feed-forward layer inside a transformer.

· illustrative lesson

01 / definitionWhat does a feed-forward network do in 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.

02 / shapeWhy expand, activate and compress?

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.

03 / positionsDoes an FFN mix information between tokens?

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.

04 / basicsWhat is a feed forward neural network?

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).

05 / namingWhy is it called feed forward?

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.

06 / architecturesIs a CNN a feedforward neural network?

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.

07 / trainingWhat is the difference between feedforward and backpropagation?

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.

06next field guide

Trans
former block.

Open transformer block lesson