Relative position representations learn vectors that encode "how far apart two words are" rather than "which position a word is at", and add them directly into the attention computation. They were proposed by Shaw, Uszkoreit, and Vaswani in 2018.
The scaled dot-product attention in the Transformer does not distinguish word order on its own. The original Transformer added absolute positions to the input embeddings using sinusoidal positional encoding or learned positional embeddings. However, grammatical relations such as "a particle comes right after the subject" are often determined by the distance between words rather than by where they sit in the sentence.
Relative position representations therefore add nothing to the input. Instead, when attention compares a query word with a key word , a vector that depends on the distance is added. Because the distance is clipped at a fixed value , only vectors are learned.
The left of the figure at the top of the article shows where position information is injected. It has the same layout as the figures in the articles on learned positional embeddings, RoPE, and ALiBi, so the injection points can be compared directly. The right is a table of which distance vector is used for each pair of words.

