Relative Position Changes Pair Interactions
Relative methods can change query-key and value interactions according to a signed offset such as key minus query. Work through one Shaw-style score, then audit direction, clipping, bucketing, and model-wide interpretation limits.
Absolute methods attach information to one index . A relative method can instead change the interaction between query position and key position according to an offset such as .
Offsets preserve both distance and direction:
- means the key is two positions before the query;
- means query and key share an index;
- means the key is three positions after the query.
Changing the sign convention is valid only if every table lookup, equation, test, and cached index uses the same convention.
One Concrete Relative-Attention Design
Shaw, Uszkoreit, and Vaswani proposed adding a learned relation vector to each query-key interaction. In one-head notation, a score can be written
Their construction can also change the value reading:
Here and are learned vectors for relative offset . This is one relative-position mechanism, not a formula shared by every later method.
Equal Content Can Receive Different Scores
Let one query and three content keys all be
with . For query position , the offsets are . Let
The three scores are
Content alone could not distinguish the equal keys. The relative terms make their direction and distance affect matching.
Clip or Bucket the Offset Range Explicitly
A learned relation table is often finite. One policy clips offsets to a range :
With , offsets and use the same table row. This bounds parameter count but discards exact distance beyond the boundary. Other methods use buckets whose widths grow with distance. The policy is part of the model, not an implementation detail to omit.
Relative Does Not Mean Translation-Invariant Model
If every query and key index shifts by the same amount, remains the same. That algebraic property concerns this position term. Padding boundaries, causal visibility, sequence starts, special tokens, data patterns, and later layers can still make complete model behavior depend on absolute location.
Q1. Choose the signed offset
This chapter defines relative offset as key index minus query index, . A query is at index 6 and a readable key is at index 2. Which offset selects the relation vector?
Compute it first, then check your number.
Hint
Solution
Reference
- Peter Shaw, Jakob Uszkoreit, and Ashish Vaswani, Self-Attention with Relative Position Representations, NAACL 2018.