FFN⁡(x)\operatorname{FFN}(\mathbf{x})

FFN — the feed-forward network

Read "F F N of x". It is a small two-layer neural network applied to each token's vector on its own, with the same weights for every token.

In the original Transformer paper, FFN⁡(x)=max⁡(0,xW1+b1)W2+b2\operatorname{FFN}(\mathbf{x}) = \max(0, \mathbf{x}W_1 + \mathbf{b}_1)W_2 + \mathbf{b}_2: multiply, add a bias, set negatives to zero, then multiply and add a bias again. Modern models replace the max⁡(0,⋅)\max(0, \cdot) with GELU or SwiGLU.

It is called position-wise because tokens do not exchange information here. Attention moves information between tokens; the FFN transforms each token by itself. The nonlinearity in the middle is essential: without it, W1W_1 followed by W2W_2 would be the same as a single matrix W1W2W_1 W_2, and the extra layer would add nothing.

Where the course uses it

Related terms