The T5 relative position bias injects position information by adding a single learned number (a scalar) per queryβkey distance to the attention scores. It was used by Raffel et al. in 2019 in the paper on T5, a model that takes text as input and produces text as output (Section 2.1). No position is added to the input embeddings.
The scaled dot-product attention in the Transformer does not distinguish word order on its own. The original Transformer added sinusoidal positional encoding or learned positional embeddings to the input. The T5 paper adopts this method as a simplified form of relative position representations, which learn a vector per distance.
There are two simplifications.
- Add a single number instead of a vector: Relative position representations add a vector of head size per distance to the keys and values, whereas T5 only adds one number to the score.
- Group distances: Near distances are distinguished one by one, and farther distances are grouped into increasingly wide ranges (buckets). T5 uses 32 buckets, and every distance beyond about 128 falls into the same bucket.
Because the numbers are learned, each head can flexibly decide from data how distance should matter, such as "attend strongly to the adjacent word" or "ignore slightly distant words."
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 relative position representations, RoPE, and ALiBi, so the injection points can be compared directly. The right shows the computed mapping of distances to buckets.

