FFN Activation Functions › Why Nonlinearity Is Non-Negotiable
Language AI HandbookAll chapters FFN Activation Functions › Why Nonlinearity Is Non-NegotiableOne section · Sections in this chapter2 / 15 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Before examining specific activation functions, it is worth building a deeper intuition for why nonlinearity matters so much. The feed-forward sublayer in a transformer takes a vector of dimension , projects it up to a higher-dimensional space of size , applies an activation, and then projects back down. In mathematical terms, a two-layer FFN computes:
where:
- : the input vector from the attention sublayer
- : the first projection (expands dimensionality)
- : the first bias vector
- : the activation function applied elementwise
- : the second projection (reduces dimensionality back)
- : the second bias vector
If were the identity function (no nonlinearity), the composition would simplify to , which is just a linear transformation. Stacking twenty such layers would still produce one linear transformation. All that computation would buy you nothing beyond a single matrix multiply.
The universal approximation theorem tells us that a network with a single hidden layer and a nonlinear activation can approximate any continuous function to arbitrary precision, given enough hidden units. The key requirement is exactly that nonlinearity. In practice, deeper networks with smaller hidden layers learn more efficiently than shallow networks with enormous hidden layers, but the theoretical foundation is the same: nonlinearity is the ingredient that maps matrix multiplication into universal function approximation.
For language modeling specifically, the FFN layers are thought to store factual knowledge. Research by Geva et al. (2021) showed that individual FFN layers function like key-value memories: the first layer's columns act as "keys" that match patterns in the input, and the second layer's rows act as "values" that contribute to the output distribution. The activation function is what allows these keys to be selective, activating strongly for certain input patterns and weakly for others. Without nonlinearity, every key would always partially match every input, making the retrieval process incoherent.
Notice that the FFN's nonlinearity is fundamentally different from attention's nonlinearity. Attention creates nonlinear interactions between positions (which tokens attend to which). The FFN creates nonlinear transformations within each position independently. Together, these two nonlinearities give the transformer its expressive power.
The history of activation functions mirrors the history of deep learning itself. Early neural networks used sigmoid and tanh activations, which saturate for large input values, causing vanishing gradients in deep networks. ReLU, introduced to the deep learning community by Nair and Hinton in 2010 and popularized by Krizhevsky et al. in AlexNet (2012), solved the vanishing gradient problem for positive inputs and enabled training of networks dozens of layers deep. The decade following ReLU saw dozens of proposed alternatives, including Leaky ReLU and PReLU as well as ELU and SELU, each addressing edge cases. GELU and SiLU represent the current generation, optimized for the specific demands of large-scale transformer training.