What Does the Feed-Forward Block Do?
What the feed-forward block does inside each transformer layer, with charts, a small Python run and official sources, for your AI interview.
In short
The feed-forward block is a small network inside each transformer layer. It takes each word's vector on its own and reworks it, so the word carries richer meaning into the next layer.
10 min readIntermediateCommon · estimateFacts checked 26 November 2026
Say it out loud
Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.
The feed-forward block is the part of each transformer layer that works on one word at a time. Attention first lets the words share context. Then the feed-forward block takes each word's vector, runs it through a small two-step network, and gives back a reworked vector. It uses the same weights for every word, and a large share of a model's weights sit in these blocks.
Every transformer layer has two steps. Attention lets each word look at the other words and pull in the context it needs. The feed-forward block comes next. It takes each word's vector, one word at a time, passes it through a small two-step network, and gives back a reworked vector. Then the layer hands everything to the next layer, which repeats the same two steps.
Think of a claims adjuster at an insurer reading a long file. First she reads across the whole file to connect the facts, like a late notice and a policy exclusion. That is the attention step. Then she goes through each line on its own, against the same rule sheet, and notes what that line means now that the links are in place. That second pass is the feed-forward block.
The block itself is simple. A linear step widens the word's vector, a ReLU sets the negative numbers to zero, and a second linear step narrows it back to the usual size. The result is added to the input the block received, so the word keeps what it had. Each word is handled on its own, so the words can be processed side by side.
Why care? These blocks hold a large share of a model's parameters, and researchers describe them as a store of learned patterns. In an interview, say three things: the block works on each word alone, attention does the mixing, and the block holds much of the model's weight count.
What does the feed-forward block do, in plain words?
A transformer layer has two main steps. Attention lets each word look at the other words and pull in the context it needs. The feed-forward block comes next. It takes each word's vector, one word at a time, and reworks it.
Think of a claims adjuster at an insurer. She reads across the whole file to connect the facts, like a late notice and a policy exclusion. That is the attention step. Then she goes through each line on its own, against the same rule sheet, and notes what that line means now that the links are in place. That second pass is the feed-forward block.
In a real model, take the clause "The supplier shall not indemnify the buyer". Attention links "not" to "indemnify". The feed-forward block then turns that linked context into a richer meaning for each word, so the next layer gets more than raw words.
Key words
- Transformer
- The neural network design this whole topic is about. It stacks layers, each with attention and a feed-forward block.
- Vector
- A list of numbers that stands for one word, or part of one, inside the model.
- Position-wise
- Done to each word separately, with no looking at the others.
- ReLU
- A simple bend: it keeps positive numbers and sets negative ones to zero.
- Parameter
- A learned number inside the model, also called a weight.
Where does the feed-forward block sit in a layer?
Every encoder layer in the original paper runs two sub-layers in the same order: attention, then the feed-forward block. The decoder adds a third, attention over the encoder's output. The paper describes the two encoder sub-layers in one sentence:
“The first is a multi-head self-attention mechanism, and the second is a simple, position-wise fully connected feed-forward network.”
Vaswani et al., the original Transformer paper
One transformer layer, in order
Word vectors in
one vector per word
Attention
Words look at each other
blends in context from other words
Feed-forward block
each word, on its own
Next layer
the same two steps again
- 1Each word's vector moves into attention.
- 2The blended words move on to the feed-forward block.
- 3Each word is reworked alone, then the layer hands on.
In the original paper's design, each of the two steps is wrapped in a residual connection, followed by layer normalisation, which rescales the numbers so they stay in a steady range. The residual connection adds the block's input back to its output, so each word keeps what it had and gains the new meaning.
How does the feed-forward block work, step by step?
Inside the block, a word's vector goes through two linear steps with a ReLU bend in between. Here is the path for one word.
- 1
Widen
A linear step, which multiplies the vector by a grid of learned numbers and adds them up, turns it into a longer one. In the original paper, the inner layer has its own size, separate from the input and output.
- 2
Bend
ReLU keeps the positive numbers and sets the negative ones to zero. Without a bend like this, the two linear steps would collapse into a single linear step.
- 3
Narrow
A second linear step squeezes the vector back to the usual size, so the next step gets the shape it expects.
- 4
Add back
The block's input is added to its output. That is the residual connection: the word keeps what it had and gains the new meaning.
Inside the feed-forward block
One word's vector
2 numbers, made up
Widen
2 numbers become 4
ReLU
negatives become zero
Narrow back
4 numbers back to 2
Add the input back
its input is added back
- 1The word's vector moves into the wider layer.
- 2The four widened numbers pass through the bend.
- 3The bent numbers are squeezed back to two.
- 4The result is added to the block's input.
The bend between the two linear steps can differ between models. The original paper used ReLU. Shazeer tested gated variants in these sublayers. Some gave quality gains over ReLU or GELU, another bend of the same kind.
Tip
Asked which activation a model uses? Name ReLU, GELU and the gated versions, then say you would check that model's own documentation for its choice.
Does the feed-forward block look at other words?
No. Attention is the step where words see each other. The paper says the feed-forward network is "applied to each position separately and identically".
Here is a small Python run with made-up numbers. A contract-review model reads three words of one clause. Each word goes through the same weights on its own, and the words never see each other inside the block.
# A contract-review model reads three words of one clause. The weights are made up.
# The feed-forward block widens each word's vector, applies ReLU, then narrows it back.
W1 = [[0.5, -0.2, 0.1, 0.4],
[0.3, 0.8, -0.5, 0.2]] # 2 numbers in, 4 inside
W2 = [[0.6, -0.1],
[0.2, 0.9],
[-0.4, 0.3],
[0.1, 0.5]] # 4 inside, 2 out
def matmul(v, W):
return [sum(v[i] * W[i][j] for i in range(len(v))) for j in range(len(W[0]))]
def ffn(vec):
# Each word goes through the same weights, on its own. Attention is what mixes words.
hidden = [max(0.0, x) for x in matmul(vec, W1)]
return matmul(hidden, W2)
words = {"shall": [1.0, 0.5], "not": [0.2, -1.0], "indemnify": [-0.5, 0.8]}
for word, vec in words.items():
print(word, "->", [round(x, 3) for x in ffn(vec)])Output
shall -> [0.48, 0.365] not -> [-0.208, 0.156] indemnify -> [0.148, 0.666]
Each word gets its own output. Your answer should say that the block is position-wise, and that attention does the mixing.
Tip
Asked whether the block mixes words? Say no, and name attention as the mixing step. The feed-forward block only reworks what each word already holds.
Why does the block matter for model size?
Feed-forward blocks hold a large share of a model's weights. Geva and colleagues (2021) wrote the same in their study of these layers:
“Feed-forward layers constitute two-thirds of a transformer model's parameters”
Geva et al., on feed-forward layers
The same study describes these layers as key-value memories. Each key correlates with a kind of text pattern, and each value pushes the output towards the words likely to come next. Lower layers tend to pick up shallow patterns, and upper layers tend to pick up more meaning.
That is why bigger models carry more weight in these blocks.
What does the interviewer want to hear?
A strong answer covers
- A plain definition: a small two-step network that reworks each word's vector.
- It works on each position separately, with the same weights.
- Attention is the step where words look at each other.
- It holds a large share of the weights, so it drives model size.
- The residual connection adds its input back.
- The bend between the two steps can differ: ReLU in the original, gated variants tested later.
Common traps
Trap"It's the part where the words look at each other."
BetterThat's attention. The feed-forward block works on each word alone.
Trap"It's a small add-on, so it doesn't matter much."
BetterIt holds a large share of the weights, so it matters for cost and size.
Trap"It stores a fixed list of answers."
BetterResearchers describe it as key-value memories: stored patterns that point to likely next words.
Can you spot the wrong claim?
Spot the wrong claim
A design note for a contract-review model makes four claims. Which one is wrong?
Quick check
A claims model is large and slow to run. Which part holds the largest share of its weights?
Can you answer these from memory?
Flash cards · tap a card to flip it
What will they ask next?
- Q064Roughly how many parameters are in one transformer layer?Coming soon
- Q060GELU and SwiGLU activations?Coming soon
- Q043What is self-attention?11 min
- Q053What do residual connections do?12 min
- Q052What is layer norm; pre-norm vs post-norm?11 min
Learn it in depth
Last updated on 26 November 2026
Building an AI product or agent that has to run fast and cheap?
I design and build AI products and agents, the screens and the system behind them. Book a short call and tell me what you need.