Papers › Self-Attention with Relative Position Representations
Self-Attention with Relative Position Representations
Peter Shaw, Jakob Uszkoreit, Ashish Vaswani
Relying entirely on an attention mechanism, the Transformer introduced by Vaswani et al. (2017) achieves state-of-the-art results for machine translation. In contrast to recurrent and convolutional neural networks, it does not explicitly model relative or absolute position information in its structure. Instead, it requires adding representations of absolute positions to its inputs. In this work we present an alternative approach, extending the self-attention mechanism to efficiently consider representations of the relative positions, or distances between sequence elements. On the WMT 2014 English-to-German and English-to-French translation tasks, this approach yields improvements of 1.3 BLEU and 0.3 BLEU over absolute position representations, respectively. Notably, we observe that combining relative and absolute position representations yields no further improvement in translation quality. We describe an efficient implementation of our method and cast it as an instance of relation-aware self-attention mechanisms that can generalize to arbitrary graph-labeled inputs.
In Syntology View this paper on Syntology, its page in Syntology's graph. That page adds which of its functions are also present in other papers' code Syntology holds, with dates, and its dated run record as JSON and a README badge. It also lists the repositories linked to the paper, the abstract and the calls for agents.
Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.
For agents, on Syntology's MCP service (how to connect):
get_harvested_code_for_paper(arxiv_id="1803.02155")get_code(code_sha256="…")with a sample'scode_sha256from the list belowget_citation_path(paper_1="1803.02155", paper_2="…")with another paper's arXiv id or titleget_concepts_for_paper(arxiv_id="1803.02155")
Code
No sample from the archive's official repository (tensorflow/tensor2tensor) is linked to this paper; the 23 samples below come from 9 community repositories. Syntology harvested code from tensorflow/tensor2tensor for 3 other papers.
tensorflow/tensor2tensor: Syntology's graph links these samples to Tensor2Tensor for Neural Machine Translation (arXiv:1803.07416; that paper's own run record: 30 ran (of which 0 constructed an object rather than computing a result; 29 with no instrument failure: 0 honoured, 0 violated, 29 with no contract checked; 1 where Syntology's instrument failed) · 18 unverified), Model-Based Reinforcement Learning for Atari (arXiv:1903.00374; that paper's own run record: 16 ran (of which 8 constructed an object rather than computing a result; 10 with no instrument failure: 0 honoured, 0 violated, 10 with no contract checked; 6 where Syntology's instrument failed) · 5 unverified) and Simplify-then-Translate: Automatic Preprocessing for Black-Box Machine Translation (arXiv:2005.11197; that paper's own run record: 2 ran (of which 0 constructed an object rather than computing a result; 0 with no instrument failure: 0 honoured, 0 violated, 0 with no contract checked; 2 where Syntology's instrument failed) · 2 unverified); nothing checks that they implement this paper's method.
Syntology 23 code samples harvested from 9 repositories linked to this paper: 13 ran (of which 4 constructed an object rather than computing a result; 8 with no instrument failure: 2 honoured, 0 violated, 6 with no contract checked; 5 where Syntology's instrument failed) · 10 unverified. Where Syntology's instrument failed: 4 where our contract draft was wrong; 1 where the contract check could not run; failures of Syntology's instrument, not of the code.
By repository: community (archive-listed): 23 samples from 9 repositories, 13 ran (8 with no instrument failure; 5 where Syntology's instrument failed). The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.
No sample is linked to this paper from 3 of its repositories that Syntology harvested for other papers:
- tensorflow/tensor2tensor, official repository: harvested for 3 other papers, listed under the repository
- THUNLP-MT/THUMT, community (archive-listed): harvested for 2 other papers, listed under the repository
- opennmt/ctranslate2, community (archive-listed): harvested for another paper, listed under the repository
Levels written between 2026-09-22 and 2026-09-24 (UTC): the dates Syntology's graph wrote each sample's verification level, not when the code executed.
13 repositories listed; official and paper-mentioned ones first.
Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.
A paper named beside a repository with no sample linked to this paper is shown with that paper's own run record, not this paper's: “ran” means executed on a synthesized input, not that the code is correct, and “where Syntology's instrument failed” counts failures of Syntology's instrument, not of the code. Papers are listed in arXiv-id order, at most three per repository.
Code Syntology ran Syntology
23 samples harvested: 13 ran (of which 4 constructed an object rather than computing a result; 8 with no instrument failure: 2 honoured, 0 violated, 6 with no contract checked; 5 where Syntology's instrument failed) · 10 unverified. “Where Syntology's instrument failed” counts failures of Syntology's instrument, not of the code. Syntology's record for this page has not changed since , the first build that kept a record date for it; when this build read Syntology's graph is in the build record. That date is not when the samples ran.
Licence: 3 of the 23 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.
Harvested from 9 repositories linked to this paper, official or community; the list below is grouped by repository, each group headed by its name and what it is to the paper. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. A line beginning “fixture:” under a sample that ran gives the arguments Syntology's fixture called the sample with, each as name:type/rank/element kind (? where none was recorded), and the type of what the fixture's run returned, exactly as the harness recorded them; the arguments and the returned type were recorded by two separate runs of the same fixture. No output value is shown, and a returned type says nothing about whether the output was right. “Level recorded” gives the UTC date when Syntology's graph wrote the sample's verification level, not when the code executed; where the level was written before Syntology's graph kept that date, the row says “level recorded, date not recorded”. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself. “Our draft was wrong” and “the contract check could not run” are failures of Syntology's instrument, not of the code: the sample ran on Syntology's synthesized input, and then the drafted contract did not describe it, or the check itself raised an error (RAISES), lacked a dependency (DEP_MISSING) or ran out of time (TIMEOUT); hover the label for which. A metamorphic tier, where shown, is evidence of the output's shape, not that the sample implements the method.
Each sample ends with its code_sha256. A sample's code_sha256 is Syntology's identity for that exact code. It is printed in full (16 hexadecimal characters for every sample in this build), and get_code(code_sha256="…") takes it exactly as printed. An agent calls it on Syntology's MCP service (how to connect); click an identity to copy that call.
Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples are grouped by repository: a repository marked official first, then by how directly the repository is tied to the paper, then in the archive's order; never by how many ran. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of six reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar); this paper's copy was not located, so its licence is not recorded; or this paper's copy is cleared, but the stored copy of the same code that Syntology serves is not. Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.
A function or class name links to its page when the name occurs in the harvested code of at least 5 papers; the name is a string, not an identity. A census tag appears when Syntology's census ran implementations with that name on one shared input per bucket: it gives how many were compared, from how many papers, and how many distinct outputs they produced, and names this sample's bucket when this sample was one of them.
d2320a9b0f803ace · report
fixture: returned AttentionError · level recorded 2026-09-22 4d00521ff1fb8ddc · report
fixture: signature x:Tensor/3/float, mask:Tensor/2/bool · returned Tensor · level recorded 2026-09-24 903e293032057e87 · report
fixture: signature tensor:Tensor/2/float · returned str · level recorded 2026-09-22 e668a7dc515efd4a · report
fixture: returned Config · level recorded 2026-09-22 1cb2afe736f259b7 · report
fixture: returned MultiHeadSelfAttentionWithRelativePosition · level recorded 2026-09-22 71c0ce87dcaac659 · report
fixture: signature length:int/0/int, hidden_size:int/0/int, min_timescale:float/0/float, max_timescale:float/0/float · returned EagerTensor · level recorded 2026-09-22 d6ec71d67f113b51 · report
fixture: signature x:EagerTensor/4/float, y:EagerTensor/4/float, z:EagerTensor/3/float, transpose:bool/0/bool · returned EagerTensor · level recorded 2026-09-22 a9285738d93fbcb8 · report
5ed8b4d74e31e691 · report
ce57057c1591618c · report
fixture: returned str · level recorded 2026-09-24 da6d13db984a8839 · report
fixture: signature name:str/0/str · returned _GeneratorContextManager · level recorded 2026-09-22 1a8621ca6bef124e · report
fixture: signature name:str/0/str, mark_as_used:bool/0/bool · returned str · level recorded 2026-09-24 12c7f6b929650b4c · report
49d8363941029a9b · report
census: 9 implementations from 7 papers, 9 distinct outputs across 3 buckets, one shared input per bucket thumt/modules/attention.py unverified BSD-3-Clause (permissive) ·
5697fe35ac9c0449 · report
9ed944fa439aacb7 · report
3b70cfc3a2e7647c · report
fixture: signature x:EagerTensor/2/float, rate:float/0/float, training:bool/0/bool · returned EagerTensor · level recorded 2026-09-22 c372eab93e763761 · report
fixture: signature length:int/0/int, maximum_position:int/0/int, with_cache:bool/0/bool · returned EagerTensor · level recorded 2026-09-22 census: 9 implementations from 7 papers, 9 distinct outputs across 3 buckets, one shared input per bucket opennmt/layers/transformer.py unverified MIT (permissive) ·
5fd90f133d0b4da5 · report
a14d3e5d54c5f021 · report
3d1e1d0aa578918b · report
615a2551db0eca16 · report
53c95ac1e55640a3 · report
fixture: returned RelPosEmb1D · level recorded 2026-09-22 Method as code Syntology
What Syntology's graph records as this paper's claimed method, lifted into code: each assembly names its bricks (functions and classes), each with its own role and its own verification level. An assembly is not a check that the code implements the method correctly or reproduces the paper's results. Levels are each brick's own verification level in Syntology's graph (level 0: no recorded run), listed brick by brick and never combined into one level; “ran” means the brick executed on a synthesized input, not that its output is correct, and the instrument figure counts failures of Syntology's instrument, not of the code. Where a model read the code against the paper's claim, each assembly's label verdict is one model's judgement, kept in this page's JSON twin; it is not calibrated, so no card prints it. Siblings are assemblies lifted from this paper in the same batch for the same method: alternative readings kept side by side; none replaces or supersedes another.
9 assemblies on this paper: 9 harvested, 0 generated, listed in 1 groups (siblings lifted in one batch form one group).
9 sibling assemblies for Self-Attention with Relative Position Representations (harvested), lifted in the same batch on 2026-09-09: alternative readings kept side by side; none replaces or supersedes another.
harvested Assembly for Self-Attention with Relative Position Representations (graph method: Self-Attention with Relative Position Representations). 2 bricks; individually on a fixture: 2 ran (of which 2 constructed an object rather than computing a result; 2 with no instrument failure: 0 honoured, 0 violated, 2 with no contract checked; 0 where Syntology's instrument failed) · 0 unverified; every one of the 2 samples that ran constructed an object rather than computing a result. The assembly has not been run end-to-end.
one of 9 siblings
- MultiHeadSelfAttentionWithRelativePosition entry · level 1 · ran ·
1cb2afe736f259b7 - Config helper · level 1 · ran ·
e668a7dc515efd4a
harvested Assembly for Self-Attention with Relative Position Representations (graph method: Self-Attention with Relative Position Representations). 3 bricks; individually on a fixture: 3 ran (of which 1 constructed an object rather than computing a result; 2 with no instrument failure: 0 honoured, 0 violated, 2 with no contract checked; 1 where Syntology's instrument failed) · 0 unverified. The assembly has not been run end-to-end.
one of 9 siblings
- MultiheadedAttention entry · level 1 · ran ·
4d00521ff1fb8ddc - AttentionError helper · level 1 · ran ·
d2320a9b0f803ace - d helper · level 1 · ran · our draft was wrong ·
903e293032057e87
harvested Assembly for Self-Attention with Relative Position Representations (graph method: Self-Attention with Relative Position Representations). 1 brick; individually on a fixture: 1 ran (of which 0 constructed an object rather than computing a result; 0 with no instrument failure: 0 honoured, 0 violated, 0 with no contract checked; 1 where Syntology's instrument failed) · 0 unverified. The assembly has not been run end-to-end.
one of 9 siblings
- relative_attention_inner entry · level 1 · ran · our draft was wrong ·
d6ec71d67f113b51
harvested Assembly for Self-Attention with Relative Position Representations (graph method: Self-Attention with Relative Position Representations). 1 brick; individually on a fixture: 0 ran · 1 unverified. The assembly has not been run end-to-end.
one of 9 siblings
- RelativeMHA entry · level 0 · unverified ·
5ed8b4d74e31e691
harvested Assembly for Self-Attention with Relative Position Representations (graph method: Self-Attention with Relative Position Representations). 6 bricks; individually on a fixture: 2 ran (of which 0 constructed an object rather than computing a result; 1 with no instrument failure: 1 honoured, 0 violated, 0 with no contract checked; 1 where Syntology's instrument failed) · 4 unverified. The assembly has not been run end-to-end.
one of 9 siblings
- MultiHeadAttention entry · level 0 · unverified ·
5fd90f133d0b4da5 - combine_heads helper · level 0 · unverified ·
a14d3e5d54c5f021 - dropout helper · level 1 · ran; the contract check could not run (RAISES) ·
3b70cfc3a2e7647c - matmul_with_relative_representations helper · level 0 · unverified ·
3d1e1d0aa578918b - relative_positions helper · level 1 · ran · honoured contract ·
c372eab93e763761 - split_heads helper · level 0 · unverified ·
615a2551db0eca16
harvested Assembly for Self-Attention with Relative Position Representations (graph method: Self-Attention with Relative Position Representations). 1 brick; individually on a fixture: 1 ran (of which 0 constructed an object rather than computing a result; 1 with no instrument failure: 1 honoured, 0 violated, 0 with no contract checked; 0 where Syntology's instrument failed) · 0 unverified. The assembly has not been run end-to-end.
one of 9 siblings
- position_encoding_relative entry · level 1 · ran · honoured contract ·
71c0ce87dcaac659
harvested Assembly for Self-Attention with Relative Position Representations (graph method: Self-Attention with Relative Position Representations). 3 bricks; individually on a fixture: 3 ran (of which 1 constructed an object rather than computing a result; 1 with no instrument failure: 0 honoured, 0 violated, 1 with no contract checked; 2 where Syntology's instrument failed) · 0 unverified. The assembly has not been run end-to-end.
one of 9 siblings
- RelPosEmb1D entry · level 1 · ran ·
53c95ac1e55640a3 - rel_pos_emb_1d helper · level 1 · ran; the contract check could not run ·
227b65e34b12edd5 - relative_to_absolute helper · level 1 · ran; the contract check could not run ·
c692e058b3b543f2
harvested Assembly for Self-Attention with Relative Position Representations (graph method: Self-Attention with Relative Position Representations). 1 brick; individually on a fixture: 0 ran · 1 unverified. The assembly has not been run end-to-end.
one of 9 siblings
- BertSelfAttention entry · level 0 · unverified ·
a9285738d93fbcb8
harvested Assembly for Self-Attention with Relative Position Representations (graph method: Self-Attention with Relative Position Representations). 7 bricks; individually on a fixture: 3 ran (of which 0 constructed an object rather than computing a result; 1 with no instrument failure: 0 honoured, 0 violated, 1 with no contract checked; 2 where Syntology's instrument failed) · 4 unverified. The assembly has not been run end-to-end.
one of 9 siblings
- MultiHeadAttention entry · level 0 · unverified ·
5697fe35ac9c0449 - Affine helper · level 0 · unverified ·
12c7f6b929650b4c - MultiHeadAttentionBase helper · level 0 · unverified ·
9ed944fa439aacb7 - scope helper · level 1 · ran · our draft was wrong ·
da6d13db984a8839 - Module helper · level 0 · unverified ·
49d8363941029a9b - unique_name helper · level 1 · ran · our draft was wrong ·
1a8621ca6bef124e - get_scope helper · level 1 · ran ·
ce57057c1591618c
Each brick ends with its code_sha256, Syntology's identity for that exact code; click one to copy the get_code call that returns it. For agents, on Syntology's MCP service: assembly(arxiv_id="1803.02155") returns these assemblies with each brick's role and wiring (how to connect).
Tasks
1 archive task tag without a task page not shown.
Results from the paper archive 2025-07-28
| Task | Dataset | Model | Metric | Value | Rank at snapshot | Leaderboard | Report |
|---|---|---|---|---|---|---|---|
| Machine Translation | WMT2014 English-French | Transformer (big) + Relative Position Representations | BLEU score | 41.5 | #22 of 57 | Archive leaderboard | report |
| Machine Translation | WMT2014 English-German | Transformer (big) + Relative Position Representations | BLEU score | 29.2 | #28 of 91 | Archive leaderboard | report |
Ranks are positions in the archive's leaderboards as they stood at the 2025-07-28 snapshot. Results published since then are not among these rows, so a rank here is not a current standing.
Methods
Introduced by this paper: Relative Position Encodings
Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections