{"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/recurrent-memory-transformer","title":"Recurrent Memory Transformer","arxiv_id":"2207.06881","date":"2022-07-14","proceeding":null,"authors":["Aydar Bulatov","Yuri Kuratov","Mikhail S. Burtsev"],"abstract":"Transformer-based models show their effectiveness across multiple domains and tasks. The self-attention allows to combine information from all sequence elements into context-aware representations. However, global and local information has to be stored mostly in the same element-wise representations. Moreover, the length of an input sequence is limited by quadratic computational complexity of self-attention. In this work, we propose and study a memory-augmented segment-level recurrent Transformer (RMT). Memory allows to store and process local and global information as well as to pass information between segments of the long sequence with the help of recurrence. We implement a memory mechanism with no changes to Transformer model by adding special memory tokens to the input or output sequence. Then the model is trained to control both memory operations and sequence representations processing. Results of experiments show that RMT performs on par with the Transformer-XL on language modeling for smaller memory sizes and outperforms it for tasks that require longer sequence processing. We show that adding memory tokens to Tr-XL is able to improve its performance. This makes Recurrent Memory Transformer a promising architecture for applications that require learning of long-term dependencies and general purpose in memory processing, such as algorithmic tasks and reasoning.","url_abs":"https://arxiv.org/abs/2207.06881v2","url_pdf":"https://arxiv.org/pdf/2207.06881v2.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":"recurrent-memory-transformer","repo_url":"https://github.com/booydar/lm-rmt","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"recurrent-memory-transformer","repo_url":"https://github.com/booydar/transformer-xl","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"Apache-2.0"}},{"paper_slug":"recurrent-memory-transformer","repo_url":"https://github.com/booydar/t5-experiments","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null}],"tasks":[{"task_slug":"language-modeling","task_name":"Language Modeling"},{"task_slug":"language-modelling","task_name":"Language Modelling"}],"methods":[{"method_slug":"absolute-position-encodings","method_name":"Absolute Position Encodings"},{"method_slug":"adam","method_name":"Adam"},{"method_slug":"adaptive-input-representations","method_name":"Adaptive Input Representations"},{"method_slug":"adaptive-softmax","method_name":"Adaptive Softmax"},{"method_slug":"attention","method_name":"Attention"},{"method_slug":"bpe","method_name":"BPE"},{"method_slug":"cosine-annealing","method_name":"Cosine Annealing"},{"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":"linear-warmup-with-cosine-annealing","method_name":"Linear Warmup With Cosine Annealing"},{"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":"residual-connection","method_name":"Residual Connection"},{"method_slug":"softmax","method_name":"Softmax"},{"method_slug":"transformer","method_name":"Transformer"},{"method_slug":"transformer-xl","method_name":"Transformer-XL"},{"method_slug":"variational-dropout","method_name":"Variational Dropout"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2207.06881","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2207.06881"}},"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/booydar/transformer-xl","reach":{"status":"ok","spdx":"Apache-2.0"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/booydar/t5-experiments","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/booydar/lm-rmt","reach":null}],"summary":{"ran_honours":1,"ran":3,"ran_draft_wrong":1,"ran_violates":1,"unverified":7},"by_repo_kind":{"official":{"samples":9,"ran":3,"repositories":1},"listed":{"samples":1,"ran":0,"repositories":1},"community":{"samples":2,"ran":2,"repositories":1}},"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":2,"samples":[{"code_sha256_prefix":"7f1040f5e3991d5e","entry":"identity","repo":"lucidrains/recurrent-memory-transformer-pytorch","repo_kind":"community","path":"recurrent_memory_transformer_pytorch/recurrent_memory_transformer.py","file_url":"https://github.com/lucidrains/recurrent-memory-transformer-pytorch/blob/HEAD/recurrent_memory_transformer_pytorch/recurrent_memory_transformer.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":2,"contract_check":"HONOURS","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"7f1040f5e3991d5e"}},{"code_sha256_prefix":"4fbd1dc67be817f3","entry":"AdaptiveEmbedding","repo":"booydar/lm-rmt","repo_kind":"official","path":"pytorch/mem_transformer.py","file_url":"https://github.com/booydar/lm-rmt/blob/HEAD/pytorch/mem_transformer.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"4fbd1dc67be817f3"}},{"code_sha256_prefix":"460c2ddd444dbae3","entry":"DecoderLayer","repo":"booydar/lm-rmt","repo_kind":"official","path":"pytorch/mem_transformer.py","file_url":"https://github.com/booydar/lm-rmt/blob/HEAD/pytorch/mem_transformer.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"460c2ddd444dbae3"}},{"code_sha256_prefix":"17b3ba52d31a4f22","entry":"MultiHeadAttn","repo":"booydar/lm-rmt","repo_kind":"official","path":"pytorch/mem_transformer.py","file_url":"https://github.com/booydar/lm-rmt/blob/HEAD/pytorch/mem_transformer.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"17b3ba52d31a4f22"}},{"code_sha256_prefix":"5444a7d75d38878d","entry":"eval_decorator","repo":"lucidrains/recurrent-memory-transformer-pytorch","repo_kind":"community","path":"recurrent_memory_transformer_pytorch/recurrent_memory_transformer.py","file_url":"https://github.com/lucidrains/recurrent-memory-transformer-pytorch/blob/HEAD/recurrent_memory_transformer_pytorch/recurrent_memory_transformer.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":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"5444a7d75d38878d"}},{"code_sha256_prefix":"aa5486a3650902d8","entry":"exists","repo":null,"repo_kind":null,"path":null,"file_url":null,"link_basis":"identical_code_first_harvested_elsewhere","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":null,"inline_ok":false,"mcp_get_code":{"code_sha256":"aa5486a3650902d8"}},{"code_sha256_prefix":"d6f7759cbb53633c","entry":"MemTransformerLM","repo":"booydar/lm-rmt","repo_kind":"official","path":"pytorch/mem_transformer.py","file_url":"https://github.com/booydar/lm-rmt/blob/HEAD/pytorch/mem_transformer.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"d6f7759cbb53633c"}},{"code_sha256_prefix":"da461b6fa9c6c2a2","entry":"ProjectedAdaptiveLogSoftmax","repo":"booydar/lm-rmt","repo_kind":"official","path":"pytorch/mem_transformer.py","file_url":"https://github.com/booydar/lm-rmt/blob/HEAD/pytorch/mem_transformer.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"da461b6fa9c6c2a2"}},{"code_sha256_prefix":"36ad33d145150380","entry":"RMTBaseModel","repo":"booydar/t5-experiments","repo_kind":"listed","path":"modeling_rmt/base.py","file_url":"https://github.com/booydar/t5-experiments/blob/HEAD/modeling_rmt/base.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":"36ad33d145150380"}},{"code_sha256_prefix":"1a40c2f95182a074","entry":"RelLearnableDecoderLayer","repo":"booydar/lm-rmt","repo_kind":"official","path":"pytorch/mem_transformer.py","file_url":"https://github.com/booydar/lm-rmt/blob/HEAD/pytorch/mem_transformer.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"1a40c2f95182a074"}},{"code_sha256_prefix":"fd30acd200176f09","entry":"RelLearnableMultiHeadAttn","repo":"booydar/lm-rmt","repo_kind":"official","path":"pytorch/mem_transformer.py","file_url":"https://github.com/booydar/lm-rmt/blob/HEAD/pytorch/mem_transformer.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"fd30acd200176f09"}},{"code_sha256_prefix":"4bd79fa041136c60","entry":"RelPartialLearnableDecoderLayer","repo":"booydar/lm-rmt","repo_kind":"official","path":"pytorch/mem_transformer.py","file_url":"https://github.com/booydar/lm-rmt/blob/HEAD/pytorch/mem_transformer.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"4bd79fa041136c60"}},{"code_sha256_prefix":"027c122b94fbe192","entry":"RelPartialLearnableMultiHeadAttn","repo":"booydar/lm-rmt","repo_kind":"official","path":"pytorch/mem_transformer.py","file_url":"https://github.com/booydar/lm-rmt/blob/HEAD/pytorch/mem_transformer.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"027c122b94fbe192"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}