Zubnet AIAprenderWiki › Feedforward Network
Fundamentos

Feedforward Network

FFN, MLP Block
El componente en cada capa Transformer que procesa cada token independientemente a través de dos transformaciones lineales con una función de activación entre medio. Mientras la atención mezcla información entre tokens (qué tokens se relacionan con cuáles), el feedforward network procesa la representación de cada token individualmente, aplicando transformaciones no lineales que codifican conocimiento y realizan computación.

Por qué importa

El feedforward network es donde se almacena la mayoría del conocimiento de un Transformer. La atención recibe toda la gloria, pero las capas FFN contienen la mayoría de parámetros del modelo (típicamente 2/3 del total) y es donde asociaciones factuales, patrones de lenguaje y computaciones aprendidas residen principalmente. Entender esto ayuda a explicar fenómenos como knowledge editing y 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.

Conceptos relacionados

← Todos los términos
← Federated Aprendering Few-Shot Aprendering →