Add a residual vector coordinate by coordinate
Type the indices of each value in their original order. · 183 words
A residual connection adds a transformer's sublayer output to its input, coordinate by coordinate. Suppose a token's input vector is x = [2, -1, 3], and an attention sublayer returns a = [1, 2, -1]. The residual result is x + a = [3, 1, 2]: the first coordinate is 2 + 1 = 3, the second is -1 + 2 = 1, and the third is 3 - 1 = 2. The block does not replace x. It adds a learned update while retaining the original features.
In a separate text-classification example, the current hidden vector is h = [4, 1], and a feed-forward sublayer proposes delta = [0.5, -0.5]. The next residual vector is h + delta = [4.5, 0.5]. A replacement would discard h, but the sum keeps earlier evidence and adds only the proposed change. Stacking residual sublayers therefore lets later blocks refine a representation instead of rebuilding it. Because every hidden vector has the same ordered feature slots, the addition stays coordinate-aligned. The direct route from h to the sum also helps gradients reach earlier blocks during training.
Check your recall
If x = [2, -1, 3] and the attention output is [1, 2, -1], what is the residual vector?
Check your answer
Add matching coordinates: [2 + 1, -1 + 2, 3 - 1] = [3, 1, 2].
Sources and credits
Original KeyTouch lesson. Background reading · Vaswani et al. · Attention Is All You Need.