Abstract
Large language models often expose their brittleness in reasoning tasks, especially while executing long chains of reasoning over context. We propose MemReasoner, a new and simple memory-augmented LLM architecture, in which the memory learns the relative order of facts in context, and enables hopping over them, while the decoder selectively attends to the memory. MemReasoner is trained end-to-end, with optional supporting fact supervision of varying degrees. We train MemReasoner, along with existing memory-augmented transformer models and a state-space model, on two distinct synthetic multi-hop reasoning tasks. Experiments performed under a variety of challenging scenarios, including the presence of long distractor text or target answer changes in test set, show strong generalization of MemReasoner on both single- and two-hop tasks. This generalization of MemReasoner is achieved using none-to-weak supporting fact supervision (using none and 1% of supporting facts for one- and two-hop tasks, respectively). In contrast, baseline models overall struggle to generalize and benefit far less from using full supporting fact supervision. The results highlight the importance of explicit memory mechanisms, combined with additional weak supervision, for improving large language model's context processing ability toward reasoning tasks.
Introduction
While Large Language Models (LLMs) have mastered many natural language processing tasks, they remain notoriously "brittle" when confronted with long-range reasoning. When a question requires connecting multiple facts scattered across a long document—a challenge often called "reasoning-in-a-haystack"—LLMs frequently fail. These failures manifest as hallucinations or a loss of the "dependency chain" amidst irrelevant distractor text.
This paper argues that the limitation is structural rather than just a matter of memory capacity. Standard Transformers struggle to maintain the relative order of facts over long distances and lack a native mechanism for iterative, deliberative thinking. We introduce MemReasoner, a novel memory-augmented architecture designed to conquer these tasks by explicitly encoding the temporal order of facts and using an iterative "hopping" mechanism to query its internal memory.
Methodology
MemReasoner builds on the Larimar framework, introducing three core architectural innovations to enable robust long-range reasoning:
- Latent Episodic Memory: Instead of attending to every raw token in a massive context, the model writes compressed "fact encodings" into a separate latent memory module.
- Temporal Encoding: To resolve temporal dependencies (e.g., tracking an object's location over time), MemReasoner uses a bidirectional Gated Recurrent Unit (GRU) to inject a sense of order into the facts stored in memory.
- Iterative Read & Query Update: For multi-hop tasks, the model performs iterative "hops." It generates an initial query, reads from memory, updates the query based on the retrieved information, and repeats until it converges on a final answer. This mimics a human-like deliberative reasoning process.
Additionally, the model utilizes an Inference-Time Update (IU) to handle extremely long contexts (up to 128k tokens) by dynamically filtering irrelevant contexts before final reasoning, which prevents numerical instabilities.
Experimental Setup
The model was evaluated on several challenging synthetic benchmarks designed to stress-test reasoning:
- BABILong & BABILong-soft: Extensions of the classic bAbi dataset where facts are buried in long stretches of irrelevant text. The "soft" variant uses in-distribution padding to make the haystack harder to search.
- Variable Tracking (VT): A task requiring the model to track value assignments through a chain (e.g., A=5, B=A, find B).
- Location Change: A test for true logical reasoning where the model must handle locations never seen during training.
Results and Discussion
MemReasoner demonstrates superior generalization compared to baselines like Recurrent Memory Transformers (RMT) and Mamba. Notably, MemReasoner generalizes to 128k tokens despite being trained on sequences as short as 14–72 tokens. This suggests that explicit memory structures are more effective for long-range reasoning than simply increasing the context window of a standard Transformer.
Key findings include:
- The Power of Weak Supervision: MemReasoner requires as little as 1% supporting-fact supervision to achieve near-perfect generalization. In contrast, RMT struggles even with 100% supervision.
- Robustness: On the BABILong task, MemReasoner maintained ~90% accuracy on 1-hop tasks up to 128k tokens. In Variable Tracking, it achieved 100% accuracy across all tested lengths, while RMT performance plummeted to ~5% after just 1k tokens.
- Logic over Pattern Matching: In the "Location Change" experiment, MemReasoner achieved 98.6% accuracy, proving it learns underlying logic rather than simple training patterns.
Conclusion
MemReasoner highlights the importance of explicit memory mechanisms and iterative querying for complex reasoning tasks. While currently evaluated on synthetic benchmarks, the architecture's ability to generalize from short training sequences to massive context lengths with minimal supervision offers a promising path for more efficient and robust LLMs. Future work will focus on integrating this framework into unified LLM backbones and testing on more diverse, real-world natural language datasets.
Summary updated