Adapter Layers › Worked Example
Language AI HandbookAll chapters Adapter Layers › Worked ExampleOne section · Sections in this chapter5 / 10 ↓
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
Let's trace through an adapter computation manually to build deep intuition for how the bottleneck transformation works. Following the computation step by step reveals how each component contributes to the final output, verifies our understanding of the mathematics, and clarifies the interaction between compression, nonlinearity, and the residual connection. Working through the numbers by hand is particularly valuable for understanding what "near-zero initialization" means concretely and why the residual produces small, targeted modifications rather than wholesale replacement of the representation.
Consider a simplified scenario with hidden dimension and bottleneck dimension . While real adapters operate in much higher dimensions, this small example allows us to see every number in the computation and check each step. We begin with an input hidden state representing a token in our transformer:
This vector might represent, for example, the token "review" in the sentence "Write a product review." The four dimensions capture different aspects of the token's meaning and context as computed by the layers above. Our adapter has the following weights, which we treat as fixed for this example but would in practice be learned through gradient descent:
The zero bias in reflects the near-zero initialization strategy. At initialization, both weight matrices would be set to small random values close to zero. This keeps the adapter contributes nearly nothing to start.
Step 1: Down-projection
The first step compresses the 4-dimensional input to a 2-dimensional bottleneck representation. This linear transformation identifies which combinations of input features are most relevant for the task. We compute the matrix-vector product by taking the dot product of each row of with the input vector :
Computing each element explicitly:
Adding the bias shifts the compressed representation:
The down-projection has compressed our 4-dimensional input into a 2-dimensional representation. The values are small, which is typical for a nearly-initialized adapter: the weight matrix is not yet "tuned" to emphasize large variations in the input, so the compressed representation is close to the bias.
Step 2: Nonlinearity (ReLU)
The activation function introduces nonlinearity, letting the adapter to model complex patterns that no linear transformation could capture. ReLU zeroes out negative values while passing positive values unchanged:
Notice that the second dimension is zeroed by ReLU, because . Effectively, only one of the two bottleneck dimensions contributes to the output at this point in our example. This sparsity is characteristic of ReLU networks: negative activations are simply shut off, creating a selective routing of information. Depending on the input, different bottleneck dimensions will be active, letting the adapter to implement different transformations for different types of inputs. This context-dependent routing is a key reason why the nonlinearity is needed: without it, the adapter would apply exactly the same linear transformation to every input, regardless of content.
Step 3: Up-projection
The final transformation expands the activated bottleneck representation back to the original hidden dimension. Since the second dimension of is zero, only the first column of contributes to the output, making the computation particularly clean:
The up-projection produces a 4-dimensional output. Each element is the scalar multiple of 0.11 times the corresponding entry in the first column of . The result is a small modification vector: positive adjustments to dimensions 1, 2, and 4; a small negative adjustment to dimension 3. This pattern reflects the task-specific correction the adapter has learned to apply.
Step 4: Residual connection
Finally, the adapter output is added to the original input through the residual connection, combining the pretrained representation with the task-specific modification:
The adapter has made small, targeted adjustments to each dimension of the hidden state. Notice how the original structure is preserved: the values remain in roughly the same range as before, with only modest shifts in each dimension. The third dimension decreased slightly (0.800 to 0.778), while the fourth changed most dramatically relative to its original value (from to , almost halving the magnitude of the negative value). The residual connection ensures these changes are additive modifications rather than complete replacements, which is the basic mechanism that allows adapters to retain pretrained knowledge while learning new behaviors.
This example uses a nearly-converged adapter (weights are small but non-trivial). For a freshly initialized adapter with weights close to zero, the modification vector would be much closer to , and . The adapter gradually grows its influence through training as gradients accumulate.



