Show why token order needs a position signal

Type the indices of each value in their original order. · 201 words

Attention computes relationships among token vectors, but by itself it does not know their order. Imagine the sentences 'The dog bites the man' and 'The man bites the dog.' They contain the same tokens, so without a position signal every occurrence of a word has the same vector. Self-attention uses learned queries, keys, and values to score and combine token information. In both sentences, the set of token vectors is the same. Reordering the tokens merely reorders the output rows. It does not change which content receives a particular attention pattern. The two meanings therefore remain indistinguishable to that attention layer.

A position signal breaks this symmetry. A common choice is to add a position vector p_i to each token embedding x_i before attention: e_i = x_i + p_i. For positions 0, 1, and 2, suppose p_0 = [0], p_1 = [1], and p_2 = [2]. In 'dog bites man,' the embeddings become x_dog + [0], x_bites + [1], and x_man + [2]. In the reversed order, they become x_man + [0], x_bites + [1], and x_dog + [2]. The positional terms stay tied to slots, so query-key scores can now differ. Learned or sinusoidal position vectors provide this order information.

Check your recall

If no positional signal is added and the token rows are reordered, how does the self-attention output change?

Check your answer

The output rows are reordered in the same way. Without position information, self-attention cannot distinguish different orders of the same token set.

Sources and credits

Original KeyTouch lesson. Background reading · Vaswani et al. · Attention Is All You Need.