Gated Linear Units › The Gating Mechanism

Michael BrenndoerferUpdated June 14, 20253 min read
Language AI HandbookAll chapters
Part 15 of 67Transformer Blocks
Chapter 109Gated Linear Units › The Gating Mechanism
Reading section 2 of 16 · The Gating Mechanism · 3 minSection 2 of 16 · 3 min

Book contents

Section 2 of 16 · 3 min read

Gated Linear Units › The Gating MechanismOne section · Sections in this chapter2 / 16 ↓
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 diving into the GLU formulation, let's understand what gating means. A gate is a learned mechanism that controls information flow. The idea comes from LSTM networks, where gates solve the vanishing gradient problem by allowing gradients to flow unimpeded through time. In the context of feed-forward layers, gates serve a different purpose: they create multiplicative interactions that increase expressiveness.

Gating Mechanism

A gate is a learned function that produces values in a bounded range (typically 0 to 1) that multiply another signal. When the gate outputs 0, the signal is blocked; when it outputs 1, the signal passes through unchanged. Values between 0 and 1 attenuate the signal proportionally.

Consider the difference between additive and multiplicative interactions. A standard FFN uses purely additive interactions: the output is a weighted sum of transformed features. Multiplication introduces second-order terms. When you multiply two linear functions of the input, you get terms like xi⋅xjx_i \cdot x_j, which allows the network to model interactions between features that addition alone cannot capture.

The power of gating becomes clear when you consider what a gate can learn. A gate can learn to be "always open" (outputting 1), in which case the GLU behaves like a standard linear layer. It can learn to be "always closed" (outputting 0), effectively pruning that dimension. Or it can learn input-dependent behavior, opening for some patterns and closing for others. This flexibility subsumes the standard FFN as a special case while enabling much richer transformations.

In[3]:
Code
import numpy as np


def sigmoid(x):
    """Sigmoid activation for gating."""
    return 1 / (1 + np.exp(-np.clip(x, -500, 500)))


# Demonstrate gating behavior
x = np.linspace(-3, 3, 100)
gate_values = sigmoid(x)
signal = np.sin(x)
gated_output = signal * gate_values
Out[4]:
Visualization
Line plot showing signal, gate values, and their product demonstrating how gating controls information flow.
The gating mechanism in action. The signal (blue) is multiplied by gate values (orange dashed) that range from 0 to 1. The gated output (green) shows how the gate selectively passes or blocks the signal: when gate values approach 0 (left side), the output is suppressed regardless of signal magnitude.