Zubnet AILearnWiki › Feedforward Network
Fundamentals

Feedforward Network

FFN, MLP Block
The component in each Transformer layer that processes each token independently through two linear transformations with an activation function in between. While attention mixes information across tokens (which tokens relate to which), the feedforward network processes each token's representation individually, applying non-linear transformations that encode knowledge and perform computation.

Why it matters

The feedforward network is where most of a Transformer's knowledge is stored. Attention gets all the glory, but the FFN layers contain the majority of the model's parameters (typically 2/3 of total parameters) and are where factual associations, language patterns, and learned computations primarily reside. Understanding this helps explain phenomena like knowledge editing and model pruning.

Deep Dive

The standard FFN: FFN(x) = W2 · activation(W1 · x + b1) + b2, where W1 projects from the model dimension to a larger intermediate dimension (typically 4x), the activation function introduces non-linearity, and W2 projects back to the model dimension. Each position (token) passes through this independently — the FFN doesn't see other tokens, only the attention layer does.

SwiGLU and Gated Variants

Modern LLMs (LLaMA, Mistral, etc.) use SwiGLU instead of the standard FFN: SwiGLU(x) = (W1 · x · SiLU) ⊗ (W3 · x). This adds a third weight matrix (W3) and a gating mechanism that lets the network control what information passes through. Despite the extra parameters, it performs better at equivalent compute, so the intermediate dimension is adjusted down to compensate. This is a case where a slightly more complex component improves the whole system.

Knowledge Storage

Research suggests that FFN layers function like key-value memories: the first linear layer (W1) detects patterns in the input (keys), and the second linear layer (W2) maps those patterns to output updates (values). "The Eiffel Tower is in" activates specific neurons in W1, which through W2 promote the token "Paris." This key-value interpretation explains why FFN layers store factual knowledge and why knowledge editing techniques can modify specific facts by updating specific FFN weights.

Related Concepts

← All Terms
← Federated Learning Few-Shot Learning →