{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/self-attention-with-relative-position","title":"Self-Attention with Relative Position Representations","arxiv_id":"1803.02155","date":"2018-03-06","proceeding":"NAACL 2018 6","authors":["Peter Shaw","Jakob Uszkoreit","Ashish Vaswani"],"abstract":"Relying entirely on an attention mechanism, the Transformer introduced by\nVaswani et al. (2017) achieves state-of-the-art results for machine\ntranslation. In contrast to recurrent and convolutional neural networks, it\ndoes not explicitly model relative or absolute position information in its\nstructure. Instead, it requires adding representations of absolute positions to\nits inputs. In this work we present an alternative approach, extending the\nself-attention mechanism to efficiently consider representations of the\nrelative positions, or distances between sequence elements. On the WMT 2014\nEnglish-to-German and English-to-French translation tasks, this approach yields\nimprovements of 1.3 BLEU and 0.3 BLEU over absolute position representations,\nrespectively. Notably, we observe that combining relative and absolute position\nrepresentations yields no further improvement in translation quality. We\ndescribe an efficient implementation of our method and cast it as an instance\nof relation-aware self-attention mechanisms that can generalize to arbitrary\ngraph-labeled inputs.","url_abs":"http://arxiv.org/abs/1803.02155v2","url_pdf":"http://arxiv.org/pdf/1803.02155v2.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"self-attention-with-relative-position","repo_url":"https://github.com/tensorflow/tensor2tensor","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"tf","reach":null},{"paper_slug":"self-attention-with-relative-position","repo_url":"https://github.com/Chatha-Sphere/pno-ai","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"self-attention-with-relative-position","repo_url":"https://github.com/HarunoriKawano/Conformer","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"self-attention-with-relative-position","repo_url":"https://github.com/THUNLP-MT/THUMT","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"tf","reach":null},{"paper_slug":"self-attention-with-relative-position","repo_url":"https://github.com/anonymouscode115/autoregressive_inference","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"tf","reach":null},{"paper_slug":"self-attention-with-relative-position","repo_url":"https://github.com/bzhangGo/zero","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"tf","reach":null},{"paper_slug":"self-attention-with-relative-position","repo_url":"https://github.com/mehdibenamorr/Token-Positional-Bias","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok"}},{"paper_slug":"self-attention-with-relative-position","repo_url":"https://github.com/mehdibenamorr/bert-positional-bias-ner","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"self-attention-with-relative-position","repo_url":"https://github.com/ololo123321/maestro","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"tf","reach":null},{"paper_slug":"self-attention-with-relative-position","repo_url":"https://github.com/opennmt/ctranslate2","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"tf","reach":{"status":"ok","spdx":"MIT"}},{"paper_slug":"self-attention-with-relative-position","repo_url":"https://github.com/thumt/THUMT","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"tf","reach":null},{"paper_slug":"self-attention-with-relative-position","repo_url":"https://github.com/OpenNMT/OpenNMT-tf","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":0,"framework":"tf","reach":null},{"paper_slug":"self-attention-with-relative-position","repo_url":"https://github.com/The-AI-Summer/self-attention-cv","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":0,"framework":"pytorch","reach":null}],"tasks":[{"task_slug":"machine-translation","task_name":"Machine Translation"},{"task_slug":null,"task_name":"Position"},{"task_slug":"translation","task_name":"Translation"}],"methods":[{"method_slug":"absolute-position-encodings","method_name":"Absolute Position Encodings"},{"method_slug":"adam","method_name":"Adam"},{"method_slug":"attention","method_name":"Attention"},{"method_slug":"bpe","method_name":"BPE"},{"method_slug":"dense-connections","method_name":"Dense Connections"},{"method_slug":"dropout","method_name":"Dropout"},{"method_slug":"label-smoothing","method_name":"Label Smoothing"},{"method_slug":"layer-normalization","method_name":"Layer Normalization"},{"method_slug":"linear-layer","method_name":"Linear Layer"},{"method_slug":"multi-head-attention","method_name":"Multi-Head Attention"},{"method_slug":"position-wise-feed-forward-layer","method_name":"Position-Wise Feed-Forward Layer"},{"method_slug":"relu","method_name":"ReLU"},{"method_slug":"relative-position-encodings","method_name":"Relative Position Encodings"},{"method_slug":"residual-connection","method_name":"Residual Connection"},{"method_slug":"softmax","method_name":"Softmax"},{"method_slug":"transformer","method_name":"Transformer"}],"datasets_introduced":[],"methods_introduced":[{"slug":"relative-position-encodings","name":"Relative Position Encodings","full_name":"Relative Position Encodings"}],"results":[{"leaderboard":"/sota/machine-translation-on-wmt2014-english-french","task":"Machine Translation","dataset":"WMT2014 English-French","model":"Transformer (big) + Relative Position Representations","rank_in_archive_order":22,"of":57,"metrics":{"BLEU score":"41.5"},"uses_additional_data":false},{"leaderboard":"/sota/machine-translation-on-wmt2014-english-german","task":"Machine Translation","dataset":"WMT2014 English-German","model":"Transformer (big) + Relative Position Representations","rank_in_archive_order":28,"of":91,"metrics":{"BLEU score":"29.2"},"uses_additional_data":false}],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=1803.02155","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"1803.02155"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/mehdibenamorr/Token-Positional-Bias","reach":{"status":"ok"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/bzhangGo/zero","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/tensorflow/tensor2tensor","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/HarunoriKawano/Conformer","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/The-AI-Summer/self-attention-cv","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/mehdibenamorr/bert-positional-bias-ner","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/OpenNMT/OpenNMT-tf","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/anonymouscode115/autoregressive_inference","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/ololo123321/maestro","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/opennmt/ctranslate2","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/THUNLP-MT/THUMT","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/thumt/THUMT","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/Chatha-Sphere/pno-ai","reach":null}],"summary":{"ran":7,"ran_draft_wrong":3,"ran_fixture":1,"ran_honours":2,"unverified":10},"by_repo_kind":{"listed":{"samples":23,"ran":13,"repositories":9}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"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"},"n_pointer_only_for_licence":3,"samples":[{"code_sha256_prefix":"d2320a9b0f803ace","entry":"AttentionError","repo":"Chatha-Sphere/pno-ai","repo_kind":"listed","path":"model/attention.py","file_url":"https://github.com/Chatha-Sphere/pno-ai/blob/HEAD/model/attention.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"d2320a9b0f803ace"}},{"code_sha256_prefix":"e668a7dc515efd4a","entry":"Config","repo":"HarunoriKawano/Conformer","repo_kind":"listed","path":"model/self_attention.py","file_url":"https://github.com/HarunoriKawano/Conformer/blob/HEAD/model/self_attention.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"e668a7dc515efd4a"}},{"code_sha256_prefix":"1cb2afe736f259b7","entry":"MultiHeadSelfAttentionWithRelativePosition","repo":"HarunoriKawano/Conformer","repo_kind":"listed","path":"model/self_attention.py","file_url":"https://github.com/HarunoriKawano/Conformer/blob/HEAD/model/self_attention.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"1cb2afe736f259b7"}},{"code_sha256_prefix":"4d00521ff1fb8ddc","entry":"MultiheadedAttention","repo":"Chatha-Sphere/pno-ai","repo_kind":"listed","path":"model/attention.py","file_url":"https://github.com/Chatha-Sphere/pno-ai/blob/HEAD/model/attention.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"4d00521ff1fb8ddc"}},{"code_sha256_prefix":"53c95ac1e55640a3","entry":"RelPosEmb1D","repo":"The-AI-Summer/self-attention-cv","repo_kind":"listed","path":"self_attention_cv/pos_embeddings/relative_embeddings_1D.py","file_url":"https://github.com/The-AI-Summer/self-attention-cv/blob/HEAD/self_attention_cv/pos_embeddings/relative_embeddings_1D.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"53c95ac1e55640a3"}},{"code_sha256_prefix":"903e293032057e87","entry":"d","repo":"Chatha-Sphere/pno-ai","repo_kind":"listed","path":"model/attention.py","file_url":"https://github.com/Chatha-Sphere/pno-ai/blob/HEAD/model/attention.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"903e293032057e87"}},{"code_sha256_prefix":"3b70cfc3a2e7647c","entry":"dropout","repo":"OpenNMT/OpenNMT-tf","repo_kind":"listed","path":"opennmt/layers/transformer.py","file_url":"https://github.com/OpenNMT/OpenNMT-tf/blob/HEAD/opennmt/layers/transformer.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"3b70cfc3a2e7647c"}},{"code_sha256_prefix":"ce57057c1591618c","entry":"get_scope","repo":"thumt/THUMT","repo_kind":"listed","path":"thumt/modules/attention.py","file_url":"https://github.com/thumt/THUMT/blob/HEAD/thumt/modules/attention.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"ce57057c1591618c"}},{"code_sha256_prefix":"71c0ce87dcaac659","entry":"position_encoding_relative","repo":"anonymouscode115/autoregressive_inference","repo_kind":"listed","path":"voi/nn/position_encoding.py","file_url":"https://github.com/anonymouscode115/autoregressive_inference/blob/HEAD/voi/nn/position_encoding.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"71c0ce87dcaac659"}},{"code_sha256_prefix":"d6ec71d67f113b51","entry":"relative_attention_inner","repo":"bzhangGo/zero","repo_kind":"listed","path":"modules/rpr.py","file_url":"https://github.com/bzhangGo/zero/blob/HEAD/modules/rpr.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"d6ec71d67f113b51"}},{"code_sha256_prefix":"c372eab93e763761","entry":"relative_positions","repo":"OpenNMT/OpenNMT-tf","repo_kind":"listed","path":"opennmt/layers/transformer.py","file_url":"https://github.com/OpenNMT/OpenNMT-tf/blob/HEAD/opennmt/layers/transformer.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"well_formed","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"c372eab93e763761"}},{"code_sha256_prefix":"da6d13db984a8839","entry":"scope","repo":"thumt/THUMT","repo_kind":"listed","path":"thumt/modules/attention.py","file_url":"https://github.com/thumt/THUMT/blob/HEAD/thumt/modules/attention.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"da6d13db984a8839"}},{"code_sha256_prefix":"1a8621ca6bef124e","entry":"unique_name","repo":"thumt/THUMT","repo_kind":"listed","path":"thumt/modules/attention.py","file_url":"https://github.com/thumt/THUMT/blob/HEAD/thumt/modules/attention.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"1a8621ca6bef124e"}},{"code_sha256_prefix":"12c7f6b929650b4c","entry":"Affine","repo":"thumt/THUMT","repo_kind":"listed","path":"thumt/modules/attention.py","file_url":"https://github.com/thumt/THUMT/blob/HEAD/thumt/modules/attention.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"12c7f6b929650b4c"}},{"code_sha256_prefix":"a9285738d93fbcb8","entry":"BertSelfAttention","repo":"mehdibenamorr/bert-positional-bias-ner","repo_kind":"listed","path":"models/attention.py","file_url":"https://github.com/mehdibenamorr/bert-positional-bias-ner/blob/HEAD/models/attention.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"a9285738d93fbcb8"}},{"code_sha256_prefix":"49d8363941029a9b","entry":"Module","repo":"thumt/THUMT","repo_kind":"listed","path":"thumt/modules/attention.py","file_url":"https://github.com/thumt/THUMT/blob/HEAD/thumt/modules/attention.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"49d8363941029a9b"}},{"code_sha256_prefix":"5fd90f133d0b4da5","entry":"MultiHeadAttention","repo":"OpenNMT/OpenNMT-tf","repo_kind":"listed","path":"opennmt/layers/transformer.py","file_url":"https://github.com/OpenNMT/OpenNMT-tf/blob/HEAD/opennmt/layers/transformer.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"5fd90f133d0b4da5"}},{"code_sha256_prefix":"5697fe35ac9c0449","entry":"MultiHeadAttention","repo":"thumt/THUMT","repo_kind":"listed","path":"thumt/modules/attention.py","file_url":"https://github.com/thumt/THUMT/blob/HEAD/thumt/modules/attention.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"5697fe35ac9c0449"}},{"code_sha256_prefix":"9ed944fa439aacb7","entry":"MultiHeadAttentionBase","repo":"thumt/THUMT","repo_kind":"listed","path":"thumt/modules/attention.py","file_url":"https://github.com/thumt/THUMT/blob/HEAD/thumt/modules/attention.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"9ed944fa439aacb7"}},{"code_sha256_prefix":"5ed8b4d74e31e691","entry":"RelativeMHA","repo":"ololo123321/maestro","repo_kind":"listed","path":"TF1/maestro.py","file_url":"https://github.com/ololo123321/maestro/blob/HEAD/TF1/maestro.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"5ed8b4d74e31e691"}},{"code_sha256_prefix":"a14d3e5d54c5f021","entry":"combine_heads","repo":"OpenNMT/OpenNMT-tf","repo_kind":"listed","path":"opennmt/layers/transformer.py","file_url":"https://github.com/OpenNMT/OpenNMT-tf/blob/HEAD/opennmt/layers/transformer.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a14d3e5d54c5f021"}},{"code_sha256_prefix":"3d1e1d0aa578918b","entry":"matmul_with_relative_representations","repo":"OpenNMT/OpenNMT-tf","repo_kind":"listed","path":"opennmt/layers/transformer.py","file_url":"https://github.com/OpenNMT/OpenNMT-tf/blob/HEAD/opennmt/layers/transformer.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"3d1e1d0aa578918b"}},{"code_sha256_prefix":"615a2551db0eca16","entry":"split_heads","repo":"OpenNMT/OpenNMT-tf","repo_kind":"listed","path":"opennmt/layers/transformer.py","file_url":"https://github.com/OpenNMT/OpenNMT-tf/blob/HEAD/opennmt/layers/transformer.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"615a2551db0eca16"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}