Papers › Self-Attention with Relative Position Representations

Self-Attention with Relative Position Representations

6 Mar 2018NAACL 2018 6arXiv:1803.02155archive 2025-07-28

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.

PaperPDFConference PDFCodeCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="1803.02155")

Code

Syntology Ran 13 of 23 code samples harvested from 9 repositories linked to this paper; 10 have no recorded run. Of those that ran: 2 ran · honoured contract; 3 ran · our draft was wrong; 1 ran · fixture could not drive it; 7 ran with no contract checked.

By repository: community (archive-listed): 23 samples from 9 repositories, 13 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

13 repositories listed; official and paper-mentioned ones first.

tensorflow/tensor2tensor officialmentioned in papermentioned on GitHubtf report
Chatha-Sphere/pno-ai mentioned on GitHubpytorch report
HarunoriKawano/Conformer mentioned on GitHubpytorch report
THUNLP-MT/THUMT mentioned on GitHubtf report
bzhangGo/zero mentioned on GitHubtf report
mehdibenamorr/Token-Positional-Bias mentioned on GitHubpytorch report
mehdibenamorr/bert-positional-bias-ner mentioned on GitHubpytorch report
ololo123321/maestro mentioned on GitHubtf report
opennmt/ctranslate2 mentioned on GitHubtfMIT report
thumt/THUMT mentioned on GitHubtf report

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.

Code Syntology ran Syntology

23 samples harvested; 13 ran; 2 honoured the contract we drafted; 10 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

2ran · honoured contract
3ran · our draft was wrong
1ran · fixture could not drive it
7ran
10unverified

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; each sample names its own and says which. “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. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (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 from a repository marked official are listed first. 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 four 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; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). 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.

AttentionError Chatha-Sphere/pno-ai/model/attention.py community (archive-listed) ran · metamorphic tier: deterministic MIT (permissive) · d2320a9b0f803ace · report
Config HarunoriKawano/Conformer/model/self_attention.py community (archive-listed) ran · metamorphic tier: deterministic Apache-2.0 (permissive) · e668a7dc515efd4a · report
MultiHeadSelfAttentionWithRelativePosition HarunoriKawano/Conformer/model/self_attention.py community (archive-listed) ran · metamorphic tier: deterministic Apache-2.0 (permissive) · 1cb2afe736f259b7 · report
MultiheadedAttention Chatha-Sphere/pno-ai/model/attention.py community (archive-listed) ran fingerprinted MIT (permissive) · 4d00521ff1fb8ddc · report
RelPosEmb1D The-AI-Summer/self-attention-cv/self_attention_cv/pos_embeddings/relative_embeddings_1D.py community (archive-listed) ran MIT (permissive) · 53c95ac1e55640a3 · report
d Chatha-Sphere/pno-ai/model/attention.py community (archive-listed) ran · our draft was wrong MIT (permissive) · 903e293032057e87 · report
dropout OpenNMT/OpenNMT-tf/opennmt/layers/transformer.py community (archive-listed) ran · fixture could not drive it MIT (permissive) · 3b70cfc3a2e7647c · report
get_scope thumt/THUMT/thumt/modules/attention.py community (archive-listed) ran BSD-3-Clause (permissive) · ce57057c1591618c · report
position_encoding_relative anonymouscode115/autoregressive_inference/voi/nn/position_encoding.py community (archive-listed) ran · honoured contract fingerprinted no licence file found · pointer only · 71c0ce87dcaac659 · report
relative_attention_inner bzhangGo/zero/modules/rpr.py community (archive-listed) ran · our draft was wrong fingerprinted BSD-3-Clause (permissive) · d6ec71d67f113b51 · report
relative_positions OpenNMT/OpenNMT-tf/opennmt/layers/transformer.py community (archive-listed) ran · honoured contract MIT (permissive) · c372eab93e763761 · report
scope thumt/THUMT/thumt/modules/attention.py community (archive-listed) ran · our draft was wrong BSD-3-Clause (permissive) · da6d13db984a8839 · report
unique_name thumt/THUMT/thumt/modules/attention.py community (archive-listed) ran fingerprinted BSD-3-Clause (permissive) · 1a8621ca6bef124e · report
Affine thumt/THUMT/thumt/modules/attention.py community (archive-listed) unverified BSD-3-Clause (permissive) · 12c7f6b929650b4c · report
BertSelfAttention mehdibenamorr/bert-positional-bias-ner/models/attention.py community (archive-listed) unverified no licence file found · pointer only · a9285738d93fbcb8 · report
Module thumt/THUMT/thumt/modules/attention.py community (archive-listed) unverified BSD-3-Clause (permissive) · 49d8363941029a9b · report
MultiHeadAttention OpenNMT/OpenNMT-tf/opennmt/layers/transformer.py community (archive-listed) unverified MIT (permissive) · 5fd90f133d0b4da5 · report
MultiHeadAttention thumt/THUMT/thumt/modules/attention.py community (archive-listed) unverified BSD-3-Clause (permissive) · 5697fe35ac9c0449 · report
MultiHeadAttentionBase thumt/THUMT/thumt/modules/attention.py community (archive-listed) unverified BSD-3-Clause (permissive) · 9ed944fa439aacb7 · report
RelativeMHA ololo123321/maestro/TF1/maestro.py community (archive-listed) unverified no licence file found · pointer only · 5ed8b4d74e31e691 · report
combine_heads OpenNMT/OpenNMT-tf/opennmt/layers/transformer.py community (archive-listed) unverified MIT (permissive) · a14d3e5d54c5f021 · report
matmul_with_relative_representations OpenNMT/OpenNMT-tf/opennmt/layers/transformer.py community (archive-listed) unverified MIT (permissive) · 3d1e1d0aa578918b · report
split_heads OpenNMT/OpenNMT-tf/opennmt/layers/transformer.py community (archive-listed) unverified MIT (permissive) · 615a2551db0eca16 · report

Tasks

Machine TranslationTranslation

1 archive task tag without a task page not shown.

Results from the paper archive 2025-07-28

TaskDatasetModelMetricValueRank at snapshotLeaderboardReport
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

Absolute Position EncodingsAdamAttentionBPEDense ConnectionsDropoutLabel SmoothingLayer NormalizationLinear LayerMulti-Head AttentionPosition-Wise Feed-Forward LayerReLURelative Position EncodingsResidual ConnectionSoftmaxTransformer

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