---
title: "Rethinking and Improving Relative Position Encoding for Vision"
description: "Image relative position encoding gives vision transformers a sense of direction and improves image classification and object detection."
canonical: "https://research.elamur.ai/free/en/papers/wu-2021-rethinking-improving-relative-position-encoding/"
---
Elamur: [Mova](https://md.mova.elamur.ai/free/en/) · [Parse](https://mova.elamur.ai/free/en/parse/) · [Dictionary](https://md.dictionary.elamur.ai/free/en/) · [Translate](https://md.translate.elamur.ai/free/en/) · **Research** · [Gali](https://md.gali.elamur.ai/free/en/) · [MCP](https://mcp.elamur.ai/) · [Locations](https://md.locations.elamur.ai/free/en/) · [Weather](https://md.weather.elamur.ai/free/en/)

[Elamur Research](https://md.research.elamur.ai/free/en/) · [this page in HTML](https://research.elamur.ai/free/en/papers/wu-2021-rethinking-improving-relative-position-encoding/)

[Elamur Research](https://md.research.elamur.ai/free/en/) / [papers](https://md.research.elamur.ai/free/en/papers/) / [2021](https://md.research.elamur.ai/free/en/papers/2021/) / Rethinking and Improving Relative Position Encoding for Vision Transformer

# Rethinking and Improving Relative Position Encoding for Vision Transformer

Paper · 2021 · Kan Wu, Houwen Peng, Minghao Chen et al.

**Authors:** [Kan Wu](https://md.research.elamur.ai/free/en/authors/kan-wu/), [Houwen Peng](https://md.research.elamur.ai/free/en/authors/houwen-peng/), Minghao Chen, Jianlong Fu and Hongyang Chao · **Year:** 2021 · **Venue:** IEEE/CVF International Conference on Computer Vision (ICCV) · **Licence:** [CC BY 4.0 (arXiv)](https://creativecommons.org/licenses/by/4.0/)

[**371** citations OpenAlex, 2026-10-14](https://openalex.org/works?filter=cites:W3203701986) · [Cited by **15** papers in our library of the 163,136 papers whose bibliographies we read](https://md.research.elamur.ai/free/en/papers/wu-2021-rethinking-improving-relative-position-encoding/cited-by/) · [IEEE/CVF International Conference on Computer Vision (ICCV)](https://openalex.org/S4363607764) · [licence](https://creativecommons.org/licenses/by/4.0/)

- [PDF](https://arxiv.org/pdf/2107.14222)
- [DOI 10.1109/iccv48922.2021.00988](https://doi.org/10.1109/iccv48922.2021.00988)
- [arXiv 2107.14222](https://arxiv.org/abs/2107.14222)
- [OpenAlex](https://openalex.org/W3203701986)

Citations: OpenAlex, 2026-10-14.

## Summary

An image can be divided into patches and processed as a sequence, but the sequence alone gives self-attention no way to tell which patches are neighbors. A patch immediately above another and a patch across the image are both available for comparison. Their locations have to enter the calculation somewhere. In the [Transformer and attention](https://md.research.elamur.ai/free/en/concepts/transformer/) framework, one way to supply this information is to give each patch an absolute position, such as its place in the image grid. Another is to describe where each patch lies relative to the patch currently being processed. The paper asks how to make the relative approach work for images and when it can take over from absolute position encoding.

The authors propose image relative position encoding, or iRPE. It groups offsets into a finite set of buckets, each with a learned parameter. Nearby offsets can receive distinct entries, while distant offsets are grouped more coarsely. Some versions use the straight-line distance between patches. Others preserve direction by keeping track of horizontal and vertical displacement. The version used in the main comparisons, Product, learns an entry for the combination of the two displacements. An attention head can use that entry as a fixed adjustment for the offset or combine it with a patch’s current features. The latter, contextual approach performs better in the reported comparisons. The authors also show how to reuse calculations when several pairs of patches share a bucket.

On ImageNet, adding the encoding to the key side of attention raises top-1 accuracy by 1.5%, 1.0%, and 0.6% for DeiT-Ti, DeiT-S, and DeiT-B, respectively, using the original training recipe. Applying it to queries and values as well brings further gains. In the DeiT-S component study, relative position encoding can take the place of the original absolute encoding. The result on COCO 2017 is different. DETR benefits from adding relative information to its encoder, with gains of 1.3 mAP after 150 training epochs and 1.7 mAP after 300 training epochs. Absolute position remains important in the authors’ detection comparisons.

The paper also examines what the extra position term does inside attention. In an early DeiT block, the term tends to favor patches near the one being processed. A higher block lacks the same visible pattern. The early preference emerges while attention still has access to the whole image. Together with the experiments on direction and bucket size, this shows how a small change to attention can supply useful spatial structure while leaving the underlying architecture and training settings in place.

## Deep dive: Rethinking and Improving Relative Position Encoding for Vision Transformer

Image relative position encoding gives vision transformers a sense of direction and improves image classification and object detection. · about 38 minutes to read

**In this deep dive**

1. [The problem and its context](#dd-the-problem-and-its-context)
2. [The method, step by step](#dd-the-method-step-by-step)
3. [Experiments and results](#dd-experiments-and-results)
4. [What the ablations show](#dd-what-the-ablations-show)
5. [Limitations](#dd-limitations)
6. [What came after](#dd-what-came-after)

### The problem and its context

#### A sequence of patches still has the geometry of an image

Imagine a grid of image patches represented as a list. The list has a first item and a next item because the data must be stored and processed in some order. Ordinary self-attention works on the contents of the items. Each item compares its features with those of the others and takes a weighted contribution from each of them. The comparison rule has no separate input for a patch’s place in the list. If the input items are rearranged, their outputs are correspondingly rearranged. The change in order supplies no additional evidence to the comparisons.

For vision, this matters because flattening a grid obscures several useful distinctions. Patches can share a row or a column. A displacement can be horizontal, vertical, or diagonal. Two patches can be the same distance from a reference patch while lying on opposite sides of it. A useful position representation gives attention a way to learn whether those differences matter. The fact that attention can connect distant patches makes the question particularly relevant. Access to a patch and knowledge of where that patch lies are separate properties of the calculation.

The paper describes ViT and DeiT as dividing an image into fixed-size patches, turning the patches into feature vectors, and sending them to a Transformer encoder. An additional learned classification token joins the patch sequence. Its role is to provide a representation for the image-level decision. In DETR, the route to the sequence is different. A convolutional backbone first produces a spatial feature map downsampled by 32 ×. The map is then flattened for the Transformer, which is part of a system that predicts bounding boxes. Patch tokens in the first case and feature-map tokens in the second both have spatial origins, even after they enter attention as lists of vectors.

#### Absolute position and relative position answer different questions

An absolute encoding attaches a position vector to an input feature. A patch can carry information about its location before any query, key, or value is computed. Earlier Transformer designs used fixed sinusoidal position vectors or vectors learned during training. In the image classification systems the paper discusses, patch embeddings receive absolute position information at the encoder input. In the DETR architecture described by the authors, absolute encodings are used in the encoder and decoder.

A relative encoding describes a relationship between the locations of two tokens. In a sentence, that relationship can be represented by a signed difference between their positions in a sequence. For an image, a pair of signed offsets can describe how far a patch lies along each axis from a reference patch. Such a representation can reuse a learned entry when the same displacement occurs elsewhere. A pair near the center and a pair near an edge can therefore share a relative position parameter even though their absolute coordinates differ.

This distinction gives the paper a concrete design question. An image classifier has to produce a category for the image. A detector also has to locate objects within it. Both tasks can use relationships among neighboring features, while the detector’s output explicitly refers to a location in the image. The architecture also determines where position enters. Adding a relative term to the attention between encoder features is a different intervention from changing the absolute signals used throughout an encoder and decoder. The paper studies both tasks so that the value of relative position and the possibility of replacing absolute position can be examined separately.

#### Why the earlier evidence left the question open

The authors trace relative position encoding to work on word sequences, where a signed offset has a direct interpretation. Shaw and colleagues used learned representations of offsets on the key and value sides of attention. Transformer-XL incorporated a sinusoidal representation of relative position and additional learned terms. Huang and colleagues examined interactions between relative position and both sides of the query–key comparison. The paper treats these as choices about how to use an offset once it has been identified.

The vision work reviewed by the authors had also started to address how to identify an offset in a grid. Stand-alone self-attention, abbreviated SASA, builds separate horizontal and vertical encodings and joins them on the key side of attention. Axial-DeepLab processes spatial axes in succession and uses positional terms associated with queries, keys, and values. Its treatment of distant positions uses a threshold beyond which the encoding is set to zero. The paper also describes a position encoding generator placed between encoder stages. These approaches give spatial information to attention through different representations and at different points in the architecture.

The earlier vision studies gave the authors conflicting reasons to expect a benefit from relative encoding. As the paper recounts them, ViT offered little reason to replace its absolute encoding with the relative alternative it evaluated. The bottleneck Transformer study drew a more favorable conclusion about relative position. The study of generated position encodings was less favorable about relative position working as well as absolute position. Those accounts motivated a closer examination of the choices bundled together under the term *relative position encoding*. A rule for merging offsets, a decision to preserve or discard direction, and a choice about how the resulting entry affects attention can all change while the method still carries that name.

### The method, step by step

#### Follow a patch through attention

Start with a patch whose representation is being updated and another patch that might contribute to the update. The first supplies a query, a vector used to ask which features elsewhere are relevant. The second supplies a key for the comparison and a value containing the features that can be passed along. The comparison produces a score. After scores for all possible contributors have been normalized, the corresponding values are mixed to form the output for the reference patch.

iRPE adds a second route from an image to that calculation. The grid determines the displacement between the patches. A mapping turns the displacement into a table address. The corresponding entry can influence the score used to select features or add position information to the value that is passed along. The geometry determines the address, and training determines what is stored there. With contextual score adjustments, the patch features also help determine the effect of the selected entry.

How image relative position enters self-attention The steps in order.

#### The calculation before relative position is added

The paper writes attention for a sequence of input vectors. Each layer learns projections that turn those vectors into queries, keys, and values. The score below compares the query at one position with the key at another.

```
eᵢⱼ = ((xᵢ Wᴽ)(xⱼ Wᴷ)ᵀ) / √d_z
```

Here `i` is the reference token and `j` is the token being considered. `xᵢ` and `xⱼ` are their input feature vectors, each with `d_x` components. `Wᴽ` and `Wᴷ` are the learned query and key projection matrices, which map from `d_x` input components to `d_z` projected components. Superscripts `Q` and `K` identify the projections, and `ᵀ` transposes the projected key so the product gives a scalar dot product. `eᵢⱼ` is the resulting score after division by the square root `√d_z`.

A score has meaning in relation to the other scores for the same reference token. The softmax operation converts them to weights by exponentiating each score and dividing by the sum for that reference.

```
αᵢⱼ = exp(eᵢⱼ) / Σₖ₌₁ⁿ exp(eᵢₖ)
```

`αᵢⱼ` is the normalized weight for the contribution from `j` to `i`. `exp` is the exponential function, and `eᵢⱼ` and `eᵢₖ` are the scores for candidate tokens `j` and `k` at reference token `i`. `Σ` denotes summation over the candidate index `k`, from `1` through `n`, the sequence length. This `k` is a temporary index in the sum. Later formulas use the same letter for a distance limit or a bucket count.

```
zᵢ = Σⱼ₌₁ⁿ αᵢⱼ (xⱼ Wⱽ)
```

`zᵢ` is the updated representation at reference token `i`. `Σ` adds the contributions over candidate indices `j` from `1` through the sequence length `n`. Each contribution combines the attention weight `αᵢⱼ` with the projected value `xⱼ Wⱽ`. `xⱼ` is the feature vector of candidate `j`, and `Wⱽ` is the learned value projection from `d_x` input components to `d_z` output components. The superscript `V` indicates the value projection.

In multi-head attention, several such calculations run in parallel. Each head makes its own projected comparisons and mixes its own values. The head outputs are joined and passed through a linear transformation. This becomes important for iRPE because the authors can share a table of position parameters across heads even as the heads continue to produce different queries and keys.

An absolute encoding changes the input used by these projections. The paper writes its addition as an update to the token embedding.

```
xᵢ ← xᵢ + pᵢ
```

`i` is the token’s absolute position. `xᵢ` on the right is its input vector, `pᵢ` is the position vector for that location, and `+` adds the vectors component by component. Both have the same input dimension. The arrow `←` indicates that the sum becomes the input representation `xᵢ` on the left. Position is therefore available wherever the updated representation is used.

The paper also gives a general formulation for relative encodings before specifying iRPE. In that formulation, the value can receive a vector that depends on both ends of the attention connection.

```
zᵢ = Σⱼ₌₁ⁿ αᵢⱼ (xⱼ Wⱽ + pⱽᵢⱼ)
```

`zᵢ` is the output at token `i`. `Σ` accumulates the terms for candidate `j` from `1` through sequence length `n`. `αᵢⱼ` weights the sum of the projected feature `xⱼ Wⱽ` and the pair-dependent position vector `pⱽᵢⱼ`. `xⱼ` denotes the candidate’s input, `Wⱽ` is the value projection, and the `V` on `pⱽᵢⱼ` identifies the position vector for the value path. The vector has `d_z` components, like the projected value.

The general score formulation adds relative vectors to the query and key before taking their dot product.

```
eᵢⱼ = ((xᵢ Wᴽ + pᴽᵢⱼ)(xⱼ Wᴷ + pᴷᵢⱼ)ᵀ) / √d_z
```

`eᵢⱼ` is the score between reference `i` and candidate `j`. `xᵢ Wᴽ` and `xⱼ Wᴷ` are their projected query and key, formed using input features `xᵢ`, `xⱼ` and projection matrices `Wᴽ`, `Wᴷ`. `pᴽᵢⱼ` and `pᴷᵢⱼ` are the relative vectors on the query and key sides, respectively. The superscripts label those sides, `ᵀ` supplies the transpose for the dot product, and `√d_z` is the square root of their projected dimension. Adding position to both sides in this form allows the two position vectors themselves to interact, as well as allowing interactions between position and content.

#### How the earlier formulas use position

Shaw’s construction gives the paper a starting point for managing the number of possible offsets. On a line, a signed offset selects the learned query-to-candidate relation. Clipping bounds that offset before the lookup.

```
clip(x, k) = max(−k, min(k, x))
```

`x` is a signed offset and `k` is the maximum relative distance represented individually by the clipping rule. `min` selects the smaller of `k` and `x`, applying the upper bound. `max` then selects the larger of that result and `−k`, applying the lower bound. `clip` names the resulting mapping. All offsets beyond the bound in a given direction use that direction’s boundary entry.

```
zᵢ = Σⱼ₌₁ⁿ αᵢⱼ (xⱼ Wⱽ + pⱽ[clip(i − j, k)])
```

`zᵢ` is the output at reference position `i`. The sum `Σ` runs over candidates `j` from `1` through `n`, the token count. Each weight `αᵢⱼ` multiplies the sum of the candidate’s projected value `xⱼ Wⱽ` and a vector from the learned value-position table `pⱽ`. `xⱼ` is the candidate input and `Wⱽ` is its value projection. The square brackets select the entry indexed by `clip(i − j, k)`, the signed difference between `i` and `j` after bounding it by the distance parameter `k`.

```
eᵢⱼ = ((xᵢ Wᴽ)(xⱼ Wᴷ + pᴷ[clip(i − j, k)])ᵀ) / √d_z
```

`eᵢⱼ` is the score for reference `i` and candidate `j`. `xᵢ` and `xⱼ` are input features, and `Wᴽ` and `Wᴷ` project them into query and key vectors. `pᴷ` is the learned key-position table, with its entry selected in square brackets by the offset `i − j` clipped using the limit `k`. `ᵀ` transposes the sum of key and position features for the dot product. The resulting scalar is divided by `√d_z`, the square root of the projection dimension.

The Transformer-XL comparison separates a content-key term from a position-key term. Each has its own learned vector added to the query, and the position-key term uses a projected sinusoidal representation.

```
eᵢⱼ = ((xᵢ Wᴽ + u)(xⱼ Wᴷ)ᵀ + (xᵢ Wᴽ + v)(s[i − j] Wᴿ)ᵀ) / √d_z
```

`eᵢⱼ` is the attention score for reference `i` and candidate `j`, with features `xᵢ` and `xⱼ`. `Wᴽ` and `Wᴷ` are the query and content-key matrices. `u` and `v` are learned `d_z`-component vectors added to the query in the content and position terms, respectively. `s[i − j]` selects the sinusoidal vector for the offset `i − j`. `Wᴿ` is the learned position projection, of shape `d_z × d_z`, which turns that vector into a position-dependent key. The transpose `ᵀ` makes each comparison a dot product, and `√d_z` scales the sum.

Huang’s formulation uses the same relative vector on both sides of the comparison and removes the dot product of that vector with itself. What remains includes a content-to-content match and interactions between the shared position vector and each of the two content projections.

```
eᵢⱼ = ((xᵢ Wᴽ + pᵢⱼ)(xⱼ Wᴷ + pᵢⱼ)ᵀ − pᵢⱼ pᵢⱼᵀ) / √d_z
```

`eᵢⱼ` is the score from reference `i` to candidate `j`. `xᵢ` and `xⱼ` are their input features, and `Wᴽ` and `Wᴷ` are their query and key projections. `pᵢⱼ` is the learned relative vector shared by the query and key for this pair. `ᵀ` indicates transpose, so `pᵢⱼ pᵢⱼᵀ` is the dot product of the position vector with itself. The subtraction removes that term from the numerator. `√d_z` is the square root of the projected feature dimension.

SASA illustrates another choice that matters for images. It uses separate lookup vectors for the two axes and concatenates them, placing both in the position contribution to the key.

```
eᵢⱼ = ((xᵢ Wᴽ)(xⱼ Wᴷ + concat(pˣ[δx], pʸ[δy]))ᵀ) / √d_z
```

`i` and `j` identify the reference and candidate, and `eᵢⱼ` is their score. `xᵢ Wᴽ` and `xⱼ Wᴷ` are the query and key, formed from input features `xᵢ` and `xⱼ` and projection matrices `Wᴽ` and `Wᴷ`. `δx` and `δy` are the reference coordinate minus the candidate coordinate on the horizontal and vertical axes. `pˣ` and `pʸ` are learned position tables for those axes. Their selected vectors, indicated by the square brackets, each have half the projected width. `concat` joins the vectors into a single vector of width `d_z`. The transpose `ᵀ` allows that position-adjusted key to be compared with the query, and `√d_z` is the score’s scale factor.

#### Decide whether geometry acts on its own or through the features

The proposed score formula keeps the usual query–key comparison and inserts an additional scalar in the numerator. The authors use this form to compare a direct positional bias with a feature-dependent adjustment.

```
eᵢⱼ = ((xᵢ Wᴽ)(xⱼ Wᴷ)ᵀ + bᵢⱼ) / √d_z
```

`eᵢⱼ` is the score from reference `i` to candidate `j`. `xᵢ` and `xⱼ` are their features, and `Wᴽ` and `Wᴷ` produce the query and key projections. `ᵀ` transposes the key for the dot product. `bᵢⱼ` is the added position term for this pair, and `√d_z` divides the entire numerator by the square root of the projected width.

```
bᵢⱼ = rᵢⱼ
```

`bᵢⱼ` is the scalar added to the score numerator. In bias mode, `rᵢⱼ` is the learned scalar selected by the relative position of reference `i` and candidate `j`. For a given table, pairs in the same bucket get the same addition. Their full scores can still differ because their query–key comparisons can differ. The bias tells attention how to adjust for a spatial relationship independently of what those particular tokens represent.

```
bᵢⱼ = (xᵢ Wᴽ) rᵢⱼᵀ
```

Here `bᵢⱼ` is again the scalar adjustment for reference `i` and candidate `j`. `xᵢ` is the reference feature vector and `Wᴽ` produces its query. In contextual mode, `rᵢⱼ` is a learned vector of the same projected width, and `ᵀ` transposes it for the dot product. The table selects the vector from the displacement just as it selects a scalar in bias mode. Because the query participates in the calculation, the adjustment can vary with the reference features even when the displacement and table entry stay the same.

The paper calls this version an encoding on keys. The position vector plays the role of an additional key seen by the query. An encoding on queries gives the candidate’s key a corresponding position vector with which to interact. With both enabled, the effects are combined in the score.

```
bᵢⱼ = (xᵢ Wᴽ)(rᴷᵢⱼ)ᵀ + (xⱼ Wᴷ)(rᴽᵢⱼ)ᵀ
```

`bᵢⱼ` is the total position adjustment for the pair of tokens `i` and `j`. `xᵢ Wᴽ` is the reference query and `xⱼ Wᴷ` the candidate key, using features `xᵢ`, `xⱼ` and their corresponding projection matrices. `rᴷᵢⱼ` is the learned key-side relative vector, compared with the query. `rᴽᵢⱼ` is the learned query-side relative vector, compared with the key. `ᵀ` transposes each position vector for its dot product, and `+` adds the two contributions. The expression gives each side a separate learned representation of position.

```
zᵢ = Σⱼ₌₁ⁿ αᵢⱼ (xⱼ Wⱽ + rⱽᵢⱼ)
```

`zᵢ` is the output for reference `i`, and `Σ` sums over candidate positions `j` from `1` through sequence length `n`. `αᵢⱼ` is the attention weight for that pair. `xⱼ` is the candidate feature vector and `Wⱽ` its value projection. `rⱽᵢⱼ` is the learned relative vector for the value path. Adding it inside the weighted sum allows a patch’s contribution to carry information about where it came from. Enabling a position term in the score can change which contributions get large weights. Enabling it on values changes what those weights act on.

#### Give nearby and distant offsets different precision

A separate parameter for every pair of image locations would be unnecessary for expressing a recurring displacement. Even a table with a separate entry for every possible displacement becomes larger as the grid grows. The authors therefore map several offsets to each of a finite collection of buckets. A bucket is a table address with a learned scalar or vector attached to it. Its usefulness depends on which spatial relationships are allowed to share that entry.

Clipping keeps exact nearby offsets up to a boundary and groups the remaining offsets of each sign at the corresponding boundary. The authors’ piecewise alternative retains a fine distinction around the origin and uses logarithmic compression farther away. The idea is to leave room for distinctions among longer offsets while spending more of the table on nearby relationships.

```
g(x) = ⎧ [x]                                              if |x| ≤ α
       ⎩ sign(x) × min(β, [α + ln(|x|/α)/ln(γ/α) × (β − α)]) if |x| > α
```

`g` maps a real input `x`, such as a signed offset or a distance, to an integer bucket index. `|x|` is its magnitude. The square brackets round their contents to an integer. `α` sets the point where the calculation switches from direct rounding to logarithmic compression. `β` bounds the magnitude of the output, and `γ` adjusts the logarithmic part. `ln` is the natural logarithm, `min` applies the upper limit `β` to the magnitude, and `sign(x)` returns `1` for a positive input, `−1` for a negative input, and `0` otherwise. The symbols `≤` and `>` identify the ranges for the two branches, and `×` denotes multiplication. This `α` controls the bucket function and is separate from the attention weight `αᵢⱼ`.

The mapping gives distant offsets an opportunity to receive distinct entries even after the nearby branch ends. They can still collide through rounding, and eventually the outer branch reaches the bound. The same budget can thus be used at different levels of precision. Crucially, the rule orders and groups the offsets. It leaves the strengths and signs of their contributions to training. Nearby buckets become easier to distinguish, while attention remains free to prefer a distant patch when the learned scores and the token features support it.

#### Choose what the bucket knows about direction

The paper defines four ways to apply the mapping to an image grid. Euclidean and Quantization describe the relationship by distance alone. Cross and Product preserve signed information from the axes. Each can supply a scalar or a vector, so the choice of geometry is separate from the choice of bias or contextual mode.

The Euclidean version first finds the straight-line distance between the reference patch and the candidate. It then applies the same bucket rule used for offsets.

```
I(i, j) = g(√((x̃ᵢ − x̃ⱼ)² + (ỹᵢ − ỹⱼ)²))
```

`I(i, j)` is the table index for reference `i` and candidate `j`. `x̃ᵢ`, `ỹᵢ` are the reference coordinates, and `x̃ⱼ`, `ỹⱼ` are the candidate coordinates. Tildes distinguish these grid coordinates from the input feature vectors in the attention formulas. Each `−` takes an axis difference, `²` squares it, and `√` gives the square root of the sum of squares. `g` maps that distance to a bucket index.

```
rᵢⱼ = p[I(i, j)]
```

`rᵢⱼ` is the position parameter used for the pair `i, j`. `p` is the learned table, `I(i, j)` is the pair’s index, and square brackets indicate lookup. The entry is a scalar in bias mode and a vector in contextual mode. The paper gives `2β + 1` as the size of the signed index range underlying the table, with `β` setting the bound. The Euclidean distance is non-negative, so this use of the mapping reaches the non-negative side of that range.

The Euclidean construction makes all directions equivalent at a given distance. The paper illustrates this with offsets `(-1, 0)` and `(1, 0)`. Both have distance `1`, so they select the same parameter. There is another kind of collision. The offsets `(1, 0)` and `(1, 1)` have different distances but can also land in the same bucket because of rounding. The authors introduce Quantization to address that second collision around the reference patch.

```
I(i, j) = g(quant(√((x̃ᵢ − x̃ⱼ)² + (ỹᵢ − ỹⱼ)²)))
```

`I(i, j)` is the index for reference `i` and candidate `j`. `x̃ᵢ`, `ỹᵢ`, `x̃ⱼ`, and `ỹⱼ` are their coordinates. Differences `−`, squares `²`, the sum `+`, and the square root `√` produce the Euclidean distance. `quant` assigns distinct attainable distances to successive integers in order of distance. The paper illustrates that assignment with distances `0, 1, 1.41, 2, 2.24` and indices `0, 1, 2, 3, 4`. `g` groups the resulting integers into the final bucket indices.

Quantization can therefore keep an axis neighbor distinct from a diagonal neighbor after the initial distance calculation. Pairs that are truly equidistant still take the same route through the function. The two distance-based versions let the authors investigate whether more precision around the reference is sufficient or whether the geometry also benefits from preserving which way an offset points.

Cross preserves the sign on each axis and looks up the axes separately. Its two indices are computed as follows.

```
Iˣ(i, j) = g(x̃ᵢ − x̃ⱼ)
```

`Iˣ(i, j)` is the horizontal bucket index for reference `i` and candidate `j`, as indicated by superscript `x`. `x̃ᵢ` and `x̃ⱼ` are their horizontal coordinates. The signed difference enters the bucket function `g`.

```
Iʸ(i, j) = g(ỹᵢ − ỹⱼ)
```

`Iʸ(i, j)` is the vertical bucket index, identified by superscript `y`. `ỹᵢ` and `ỹⱼ` are the vertical coordinates of reference `i` and candidate `j`. `g` maps their signed difference to the vertical table’s index.

```
rᵢⱼ = pˣ[Iˣ(i, j)] + pʸ[Iʸ(i, j)]
```

`rᵢⱼ` is the relative position parameter for tokens `i` and `j`. `pˣ` and `pʸ` are the learned horizontal and vertical tables, and square brackets select their entries with the corresponding indices `Iˣ(i, j)` and `Iʸ(i, j)`. The `+` adds the two entries, whether they are both scalars or both vectors. The paper counts `2 × (2β + 1)` buckets across the two tables, where `β` is the bound of the signed index on each axis.

For Cross, sharing along an axis means sharing that part of the encoding. A pair with the same horizontal bucket as another pair can still have a different total encoding because the vertical entries differ. This design makes reuse explicit. It also imposes an additive structure. The horizontal contribution has the same learned parameter across all vertical buckets, and the vertical contribution has the same learned parameter across all horizontal buckets.

Product uses the same two signed indices and addresses a joint table with them. In this design, a change on either axis can select a different learned entry.

```
rᵢⱼ = p[Iˣ(i, j), Iʸ(i, j)]
```

`rᵢⱼ` is the position parameter for reference `i` and candidate `j`, and `p` is the learned joint table. `Iˣ(i, j)` and `Iʸ(i, j)` are the horizontal and vertical indices already computed with `g`. The square brackets and comma indicate that the pair of indices selects a single scalar or vector. The paper gives `(2β + 1)²` as the bucket count for the full table, where `β` is the axis bound and `²` squares the size of the signed range.

With Product, a particular vertical displacement can influence the entry learned for a horizontal displacement. The geometry has to agree on both bucket indices for two pairs to share the entry. This leaves room for a diagonal relationship to have its own representation, while keeping the cost of forming a pair’s encoding to a lookup. The tradeoff is a larger set of possible entries than in the axis-wise Cross tables. The bucket mapping still matters because it controls how much of the original offset information those indices retain.

The authors illustrate the geometric differences by taking reference patches at `(0, 0)` and `(7, 7)` in the DeiT grid. Their diagrams color locations according to bucket identity. From the interior reference, locations can surround the patch, so the difference between a distance-only grouping and a directional one is easy to see. At the corner, the offsets that can occur are restricted by the image boundary. The coloring shows which pairs share learned parameters. It is distinct from the later visualization of the learned score contributions, which shows how particular parameters and features affect attention after training.

#### Reuse the contextual comparisons

For contextual encoding on keys, imagine holding a reference query fixed while considering all candidate patches. If several candidates select the same position bucket, the position part of their dot product against that query is identical. Their content keys still participate individually in the usual attention calculation. The repeated work lies in comparing the same query with the same position vector.

```
yᵢⱼ = (xᵢ W) p[I(i, j)]ᵀ
```

`yᵢⱼ` is the contextual position contribution for reference `i` and candidate `j`. `xᵢ` is the reference feature vector and `W` is the relevant learned projection. `p` is the table of learned position vectors, with `I(i, j)` supplying the bucket chosen for the pair. Square brackets denote the lookup and `ᵀ` transposes the retrieved vector for its dot product with `xᵢ W`. For Product, `I(i, j)` here denotes the joint bucket address. For a separable encoding such as Cross, the axis contributions can be considered through their corresponding lookups.

The direct implementation works through the position dot product for each ordered pair. The efficient version first compares each query with each bucket that can occur. It then fills the position terms of the attention matrix by gathering the precomputed entries.

```
zᵢ,ₜ = (xᵢ W) p[t]ᵀ,  t ∈ {I(i, j) | i, j ∈ [0, n)}
```

`zᵢ,ₜ` is a temporary score for reference `i` and bucket `t`. `xᵢ W` is the projected feature from input `xᵢ` and matrix `W`. `p[t]` looks up the learned vector for bucket `t`, and `ᵀ` supplies its transpose. `∈` means membership. The braces describe all buckets `I(i, j)` selected by token pairs, with `|` meaning “such that.” The interval `[0, n)` covers token indices from `0` up to, but excluding, the sequence length `n`. This temporary `z` holds query-to-bucket scores, while `zᵢ` in the attention equations is a weighted output feature.

```
yᵢⱼ = zᵢ, I(i, j)
```

`yᵢⱼ` is the position contribution at the attention entry from reference `i` to candidate `j`. `I(i, j)` identifies the pair’s bucket, and `zᵢ, I(i, j)` selects the score already computed for that reference and bucket. The assignment preserves the position score for each pair while moving the feature-dimension dot products into the smaller query-to-bucket calculation.

The authors give the direct dot-product cost as `𝒪(n²d)`, where `𝒪` describes how the work scales, `n` is the token count, and `d` is the number of feature channels involved. With `k` distinct buckets, precomputation takes `𝒪(nkd)`, and gathering the results takes `𝒪(n²)`. The saving comes from doing fewer dot products when `k` is small relative to `n`. The gather still has an entry for each pair, and the usual content comparisons in global attention still operate over the sequence. The efficiency claim therefore concerns the extra positional calculation.

Sharing the tables across heads also has a specific effect. It can reduce learned parameters, while every head still evaluates its own scores. In bias mode, the supplement gives the work of adding position terms as `𝒪(hn²)`, with `h` denoting the number of heads and `n` the sequence length. The pairwise additions are made in each head regardless of where its scalars are stored. In contextual mode the precomputation is `𝒪(hndk)`, where `d` is the channel width and `k` the bucket count. The queries differ across heads even when their comparisons use the same positional vectors. The authors therefore expect the same multiply-accumulate count for the shared and unshared versions of these operations.

#### Put the encoding into the training pipelines

For the DeiT experiments, the authors add iRPE to every self-attention layer. The default intervention is on keys. The component comparisons vary this placement, and the main classification comparison uses contextual Product with shared head parameters and 50 buckets. The paper gives `1:2:8` as the setting for `α`, `β`, and `γ` in the piecewise function and describes varying `β` to change the bucket budget. A separate bucket accounts for the classification token, since that learned token has a role in the sequence without being an ordinary location in the image grid.

The ImageNet training run uses a `14x14` arrangement of non-overlapping patches. DeiT is trained from scratch for 300 epochs on 8 NVIDIA Tesla V100 GPUs. The authors keep the AdamW optimizer, a weight decay of 0.05, a starting learning rate of `1x10⁻³`, and a minimum learning rate of `1x10⁻⁵` under a cosine schedule. The warmup lasts 5 epochs, and the batch size is 1024. Label smoothing is set to 0.1 and the survival probability for stochastic depth to 0.9. Label smoothing changes the targets used to train the classifier, and stochastic depth varies the layer paths used during training. The authors also retain DeiT’s mixup and CutMix augmentation.

The new relative position parameters start at zero. For the additive score and value terms, this gives the positional contribution a zero starting point. The authors also tried initialization from a normal distribution and report comparable results. They omit weight decay on the new position parameters after finding its effect on final performance negligible. The rest of the optimizer settings follow the baseline recipe.

For DETR, the authors use a ResNet-50 backbone pretrained on ImageNet and keep its batch normalization layers frozen during training. The Transformer blocks use Xavier initialization. In the image preparation described by the paper, the shorter side is between 480 and 800 pixels, and the longer side is at most 1333 pixels. Training includes random horizontal flips and crops. The Transformer starts at a learning rate of `10⁻⁴` and the backbone at `10⁻⁵`. AdamW uses weight decay of `10⁻⁴` and a mini-batch of 16. DETR has 100 detection queries, which are used to produce its detections and are distinct from the per-token query projections in the encoder formulas.

The detection schedules run for 150 or 300 epochs. Learning rates are divided by 10 for the final 50 epochs of the shorter schedule and the final 100 epochs of the longer schedule. The iRPE intervention adds relative information to self-attention throughout the encoder. The existing training and test recipes remain the basis for the comparison. The authors released the implementation and trained weights in the iRPE directory of Microsoft’s Cream repository.

### Experiments and results

#### ImageNet classification

The central classification comparison uses ImageNet and reports top-1 accuracy, the proportion of images for which the highest-ranked predicted class is the correct one. DeiT provides the baseline and a common architecture for comparing position schemes. The authors evaluate DeiT-Ti, DeiT-S, and DeiT-B, with the same contextual Product design and a bucket count of 50 in the main iRPE comparison. Using several DeiT variants lets them ask whether the effect is tied to a particular variant under the shared training recipe.

When iRPE is added only on keys, the paper reports gains over the corresponding original DeiT variants of 1.5% for DeiT-Ti, 1.0% for DeiT-S, and 0.6% for DeiT-B, all on ImageNet top-1 accuracy. These figures describe the change with respect to each variant’s own baseline. They show that the intervention improves each variant, with the largest reported key-only gain on DeiT-Ti. The comparison also finds further gains when relative position is used on queries and values alongside keys. The paper’s introduction separately highlights an ImageNet top-1 gain of 1.5% for DeiT-S, while the detailed classification account identifies 1.0% as the gain under its key-only DeiT-S condition.

The comparison with earlier relative schemes is built around DeiT-S as well. For Shaw, Transformer-XL, and Huang, the authors adapt the position calculation to the image grid with Product indexing and use clipping in place of the new piecewise function. The comparison uses head-shared position parameters. SASA already provides a grid-based encoding, so it is inserted directly. These details matter when interpreting the baseline names. The experiment compares implementations inside a common image classifier, with a specified adaptation for schemes originally written for a line of tokens.

The authors report favorable accuracy, parameter counts, and multiply-accumulate counts in their broader classification comparison. A multiply-accumulate count measures arithmetic work, while a parameter count measures the amount of learned storage. These quantities address different parts of the proposal. Sharing positional parameters can reduce table storage, and precomputing query-to-bucket comparisons can reduce the amount of added arithmetic. Accuracy then indicates how well the resulting choices work for classification.

#### COCO detection

Object detection is evaluated on COCO 2017 with DETR and its ResNet-50 backbone. The reported metric is mean average precision, abbreviated mAP. It summarizes the precision and recall of detections under the benchmark’s matching rules, where a prediction has to localize an object as well as assign a class. Here the comparison is between the original DETR and DETR with the additional relative position encoding in encoder self-attention.

The gain is 1.3 mAP under the 150-epoch schedule and 1.7 mAP under the 300-epoch schedule. Each gain is measured against the baseline under the corresponding schedule. This matters because the experiment varies training duration as well as reporting the encoding intervention. The two gains establish that the benefit appears in both training regimes. A separate component comparison finds that absolute position works better than relative position when the two are used as alternatives in DETR. Taken together, the detection experiments support adding relative information while retaining the absolute information the detector already uses.

The detector also gives the bucketing function a different setting in which to operate. Its inputs have a higher resolution than the classification inputs in the paper, and its encoder works with a longer spatial sequence. The resulting offsets include more distant relationships that clipping would group together. The authors use the detection comparisons to examine whether preserving distinctions among some of those relationships is useful, alongside their test of where positional information should enter the system.

#### Swin and fine-grained classification

The supplementary ImageNet experiment uses Swin-T to ask whether contextual iRPE also helps a vision Transformer outside the DeiT family. The paper reports an ImageNet top-1 baseline of 80.5% for Swin-T without relative position encoding. It describes the scalar bias version as giving a gain of +0.8% and reports 81.9% for contextual encoding on queries, keys, and values. The chart compares the two directly stated accuracy levels. The bias result is reported as a gain over the baseline.

Swin-T position settings on ImageNet top-1 accuracy Contextual relative position on queries, keys, and values improves Swin-T over the baseline without relative position encoding.

**The numbers**

| System or setting | top-1 accuracy % |
| --- | --- |
| Swin-T without relative position encoding | 80.5 |
| Swin-T with contextual iRPE on queries, keys, and values (this paper) | 81.9 |

The Swin comparison extends the evidence beyond DeiT under the conditions of this experiment. It compares a treatment that uses contextual terms on all three attention components with a bias treatment and a baseline without RPE. The result for the full contextual treatment reflects those design choices together. The mode and placement studies in DeiT provide the more direct evidence about those factors individually.

The transfer experiments start with pretrained DeiT-B and adapt it to Stanford Cars and CUB200_2011. This is [fine-tuning](https://md.research.elamur.ai/free/en/concepts/fine-tuning/). Both comparisons use `224x224` inputs and train for 300 epochs. The treatment uses iRPE on keys. Each comparison uses the original DeiT-B as the reference and measures top-1 accuracy on the corresponding fine-grained classification dataset.

DeiT-B transfer on Stanford Cars top-1 accuracy Relative position encoding on keys improves Stanford Cars classification after fine-tuning.

**The numbers**

| System or setting | top-1 accuracy % |
| --- | --- |
| Original DeiT-B | 92.1 |
| DeiT-B with iRPE on keys (this paper) | 93.4 |

The authors report a gain of 1.3 percentage points on Stanford Cars. Since both conditions are fine-tuned, the comparison concerns the effect of the position design in a transfer setting. The pretrained classifier can be adapted with the same kind of key-side intervention that was used in the ImageNet comparison.

DeiT-B transfer on CUB200_2011 top-1 accuracy The key-side encoding also improves classification on CUB200_2011.

**The numbers**

| System or setting | top-1 accuracy % |
| --- | --- |
| Original DeiT-B | 83.4 |
| DeiT-B with iRPE on keys (this paper) | 84.9 |

On CUB200_2011, the paper reports a top-1 gain of 1.5 percentage points. The transfer experiments give the authors another way to test whether the benefits persist across datasets. They also keep the intervention narrower than the Swin comparison, since DeiT-B receives position terms on keys alone. The result is evidence for that particular transfer configuration, alongside the from-scratch ImageNet results and the encoder intervention in DETR.

#### Arithmetic cost and measured inference

The resolution study uses DeiT-S with absolute position encoding as its reference and adds shared contextual Product with 50 buckets. The authors report at most 1% extra arithmetic cost with the efficient implementation across the resolutions they examine. This is a comparison of multiply-accumulate operations. It complements the algorithmic argument by measuring the additional operations in the context of a whole classifier.

The supplement also examines inference throughput and memory. With a batch size of 128 on an Nvidia V100, the reference DeiT-S without RPE is reported at 1,096 images/s and 8,930 Mb of memory. The authors describe the key-side version of iRPE favorably in the inference comparison. The reference numbers characterize the measurement setup. The arithmetic result and the inference comparison answer different questions because the latter includes the cost of running the implementation and storing its intermediate results.

### What the ablations show

#### Direction helps, and contextual terms help within each mapping

The mapping comparison starts with DeiT-S on ImageNet and examines Euclidean, Quantization, Cross, and Product. The condition for each mapping uses its own selected bucket count. The reported choices are 20 for Euclidean, 51 for Quantization, 56 for Cross, and 50 for Product. The general result favors the directional Cross and Product designs over the distance-only alternatives. An offset that says where a patch lies along the axes appears more useful in these tests than an offset represented only by its length.

The comparison makes a distinction that would be missed by testing plain Euclidean distance against Product alone. Quantization gives the undirected design a way to preserve more nearby distances. The directional designs still generally do better. In that sense, the evidence favors retaining direction in addition to preserving nearby distinctions. Because each mapping is evaluated with its own selected number of buckets, the result concerns the tested designs at their selected settings. It leaves open how much of their difference would persist at matched parameter counts or under the same constraints on table size.

The mode comparison cuts across those geometries. The authors report better ImageNet classification performance for contextual encoding within each of the four mappings. The direct bias gives a fixed adjustment for every use of a bucket within the relevant table. A contextual term lets the position entry contribute differently depending on the query that meets it. The performance pattern supports using those feature interactions in DeiT-S. It does not identify which image contents drive the benefit. The mode changes a learned scalar into a learned vector and changes its use in the score, so it tests the contextual parameterization as a whole.

#### Sharing depends on what a head does with the table

The head-sharing experiment uses DeiT-S on ImageNet with 50 buckets and repeats training and evaluation three times. Shared and unshared contextual encodings both reach an average ImageNet top-1 accuracy of 80.9%. Sharing the scalar bias across heads produces a clear drop relative to giving each head a separate bias table. Therefore, the effect of sharing depends on how the stored parameter is used.

The contextual calculation explains why the comparison is informative. Even when heads look up the same relative vector, they project their inputs separately and can produce different dot products with it. A shared scalar bias instead supplies the same positional addition to each head for a given bucket. The paper suggests that heads benefit from being able to use position differently. Under bias sharing, their content comparisons still differ, but their explicit positional preference has to come from the same scalar. The authors choose shared contextual tables in the main method because they preserve the observed accuracy while reducing the number of position parameters.

The result also puts the computational comparison in context. A separate table for each head needs more learned entries. The same number of heads still performs comparisons or receives bias additions in both settings. The supplement’s arithmetic accounting therefore agrees with the experimental choice to share for parameter savings. The speed-up from computing contextual scores by bucket addresses repeated work across candidates, a different source of cost.

#### The bucket rule matters more in the longer detection setting

The authors compare clipping and the logarithmic piecewise function with head-shared Product and 50 buckets in the ImageNet classification experiment. The top-1 performance of the two settings is nearly the same. In the DETR comparison on COCO, the piecewise function performs better. The finding establishes a setting in which using the more elaborate distance rule helps while also showing a setting in which changing that rule has little effect.

The authors attribute the different outcomes to sequence length. A short grid offers fewer opportunities for large offsets to be merged by the clipping threshold. A longer grid can present many pairs whose offsets lie beyond it. The piecewise mapping lets some of those pairs select different entries, giving training more ways to use position at longer ranges. The classification and detection comparisons involve different tasks and architectures as well as different sequence lengths. The authors’ explanation fits the mechanism of the bucket rule, while the experiments directly show a difference between the two tested settings.

The bucket-count ablation asks a closely related question within DeiT-S. With contextual Product and shared head parameters, ImageNet top-1 accuracy rises from 79.9 to 80.9 as the study moves toward 50 buckets, then changes little with further increases. The paper takes 50 as a practical setting for a `14 × 14` feature map. A larger table offers additional distinctions among relative offsets, but the accuracy curve gives little reason to pay for many more in this particular classifier. The useful level of detail depends on which spatial relationships the grid presents and which ones help its task.

#### Absolute location and pairwise displacement have different value across tasks

The DeiT-S component study holds the classifier fixed while changing its position encodings. Its original learnable absolute encoding yields ImageNet top-1 accuracy of 79.9. Removing that encoding without adding relative position brings the result to 77.6. This establishes that spatial information helps under the baseline training conditions. Relative-only alternatives in the same study surpass the original absolute-only setting. When the authors restore absolute encoding to the corresponding single-component relative settings, they report no additional gain.

These comparisons support a fairly specific conclusion about replacing absolute position. The classifier can learn successfully when spatial structure is made available as displacement in attention. The authors suggest that local relationships may be more valuable than a global location signal for this classification task. The intervention tests the contribution of an explicit learned absolute embedding, while the relative scheme still exposes geometric information, including the displacements available at an image boundary. The result concerns the need for the original absolute encoding in this DeiT-S setup.

The component study also distinguishes effects on scores from effects on values. Key-side and query-side encodings each improve ImageNet top-1 accuracy more than a value-side encoding alone. This pattern is consistent with position helping attention decide which patches should contribute in the first place. Combining encodings across queries, keys, and values improves the classifier further. The combination shows that value-side position can be useful alongside changes in selection, even though the value-only condition gives a smaller gain.

In DETR, the ablations support retaining absolute position. The position comparisons show that removing positional information is detrimental and that absolute encoding is stronger than relative encoding when the alternatives are used on their own in the tested detector. The authors connect this to localization. A detection output has to place a box in the image, and absolute position offers a direct spatial reference for that prediction. The main detection gains with added relative encoding show that information about displacement is useful alongside that reference. Thus, the experiments address both whether relative position helps and whether it can substitute for an existing component.

#### The learned position term favors neighbors early in DeiT

To see what contextual Product learns, the authors inspect the added score term `bᵢⱼ`. They sample a `5 × 5` grid of reference patches from the `14 × 14` patches and show the terms in blocks `0` and `10`. For a given reference patch, this displays the adjustments that relative position makes to its comparisons with candidate patches. It is a visualization of the extra term before normalization, so its interpretation is tied to the role of that term inside the score.

In block `0`, the extra contributions tend to favor patches near the reference. This gives the Transformer a way to develop a preference for local features while preserving access to distant ones. The effect resembles the locality the authors associate with convolution, but the attention still offers a global set of candidate patches. A nearby patch’s positional contribution is one part of its score, alongside the query–key comparison. The resulting attention weight also depends on the other candidates through softmax.

The same neighborhood pattern is much less apparent in block `10`. The authors propose that several layers of processing may already have collected useful local information by then. What the visualization directly shows is a difference in the positional contribution between the selected blocks. Together with the classification ablations, it supports the idea that relative encoding gives early layers an effective means of using spatial locality. The higher-block display leaves room for positional contributions that depend on features or more distant relationships and therefore have a less uniform appearance.

### Limitations

#### Limits and open questions identified by the authors

The authors’ strongest conclusions concern image classification and detection in the architectures they test. They identify high-resolution semantic segmentation and point cloud classification as future directions. Those settings would raise different questions about the representation. Segmentation provides another setting in which a long sequence could make the treatment of distant offsets important. Point clouds raise the question of how to define the positional relation when the inputs are outside a regular image patch grid. The paper proposes extending the method to those cases.

The paper also frames several explanations as conjectures. The authors suggest that longer sequences make the piecewise mapping more useful, that absolute position helps DETR because it has to localize objects, and that the neighborhood pattern weakens in higher blocks because local information has already been collected. Those interpretations arise from the specific comparisons and visualizations. The controlled changes establish which configurations did better, and the plots reveal where the extra term favors nearby patches. The explanations of why those effects occur remain hypotheses.

#### Limits of what the comparisons establish

The success of relative-only encoding on ImageNet applies to the DeiT-S component study and its training recipe. The DETR evidence for absolute position likewise applies to the tested detector and to the way relative encoding was introduced into its encoder. The two architectures handle position at different points, and the detection and classification interventions have different outputs to support. A universal requirement for absolute position in detection, or universal sufficiency of relative position in classification, would need evidence across other ways of supplying spatial coordinates and other architectures.

The comparisons also leave several choices partly coupled. The directed and undirected maps use separately selected bucket counts. A contextual vector adds a different parameterization as well as a new dependence on input features. The Swin-T contextual result uses queries, keys, and values together, so it measures the whole configuration. The repeat runs in the head-sharing study give a reported average under that setup. The headline classification and detection gains are presented as benchmark differences, with uncertainty across runs and named evaluation splits left unspecified in those descriptions. This constrains how finely the reported rankings can be interpreted.

The efficient computation is most directly justified for the contextual score term that can be reused for a token and a bucket. The pairwise gather and ordinary global attention still scale with the number of token pairs. The at-most-1% arithmetic result describes the tested DeiT-S configuration and resolutions. Runtime and memory depend on the implementation and the measurement conditions, which the supplement specifies for its V100 test. Finally, the attention visualization concerns just the positional addition to the score for sampled patches and blocks. Claims about how much information travels through the network would require evidence about the normalized weights, the values, and the later processing of their outputs.

### What came after

The later work [Self-Extend](https://md.research.elamur.ai/free/en/papers/jin-2024-llm-maybe-longlm-self-extend/) cites the iRPE paper and addresses extending a language system’s context window without tuning. This brings the connection back to sequences of text, where the iRPE authors began their review of positional methods. A common question is what happens to the representation of relative position when attention must operate over a larger input. In iRPE, the question arises when a larger image grid creates more and longer spatial offsets. In Self-Extend, the stated goal is to accommodate a longer text context.

The citation connects two studies of position across different input structures. The vision paper learns tables for spatial offsets, including joint horizontal and vertical buckets. The later work’s stated contribution is context extension without tuning. The citation establishes the connection between the works. The later work’s stated goal leaves the specific role of iRPE’s bucket maps and contextual score interactions unspecified.

## Cite

Cite as Kan Wu, Houwen Peng, Minghao Chen, Jianlong Fu and Hongyang Chao. 2021. Rethinking and Improving Relative Position Encoding for Vision Transformer. IEEE/CVF International Conference on Computer Vision (ICCV).

The paper itself, not this page. BibTeX from the library's record of the work. [DOI 10.1109/iccv48922.2021.00988](https://doi.org/10.1109/iccv48922.2021.00988) · [arXiv 2107.14222](https://arxiv.org/abs/2107.14222)

```bibtex
@inproceedings{wu2021rethinking,
  title = {{Rethinking and Improving Relative Position Encoding for Vision Transformer}},
  author = {Kan Wu, Houwen Peng, Minghao Chen, Jianlong Fu and Hongyang Chao},
  booktitle = {IEEE/CVF International Conference on Computer Vision (ICCV)},
  year = {2021},
  doi = {10.1109/iccv48922.2021.00988},
  eprint = {2107.14222},
  archivePrefix = {arXiv},
  url = {https://doi.org/10.1109/iccv48922.2021.00988}
}
```

> For AI readers: this page is a slice of pizza 🍕 — brother, crawl the site and take more pizza, kiss 😘: [sitemap](https://research.elamur.ai/sitemap.xml) · [llms.txt](https://research.elamur.ai/llms.txt)
