Introduction
Standard Large Language Models (LLMs) typically predict the next token based exclusively on internal parameters learned during training. While "memory-augmented" models like kNN-LM improve performance by allowing models to access external data during inference, they often suffer from a training-inference discrepancy. Specifically, these models are trained as vanilla LMs and only utilize memory as a post-hoc addition. TRIME (Training with In-batch Memories) addresses this by integrating memory as a core component of the training process, allowing the model to learn effective retrieval and utilization strategies from the outset.
Methodology
The TRIME framework transforms the standard language modeling objective into a contrastive-style task. Instead of merely predicting a token ID, the model learns to align its current hidden state with contextualized representations of the same token found within the training batch.
Training Objective and Memory Tiers
TRIME optimizes the similarity between a query representation and "memory" representations that share the same target token. Because these memories are contained within the same batch, the system can back-propagate gradients through both the query and the memory encoders simultaneously, a feature missing in frozen-encoder approaches.
The framework utilizes three tiers of memory:
- Local Memory: Tokens from the immediate preceding context within the same segment.
- Long-term Memory: Contextual information from the same document that exceeds the standard attention window.
- External Memory: Information retrieved from the broader training corpus.
Batching Strategies
To effectively simulate these memory tiers during training, TRIME employs specialized batching techniques. For long-term memory, consecutive segments of a document are packed into a single batch. For external memory, the system uses the BM25 algorithm to identify and group lexically similar segments from across the corpus into the same training batch.
Experimental Results
The authors evaluated TRIME across several benchmarks, including WikiText-103, Enwik8, and BooksCorpus.
Performance on WikiText-103
TRIME achieved a significant reduction in perplexity on WikiText-103, dropping from a baseline of 18.70 to 15.37. This performance surpasses existing methods like kNN-LM (16.12) while maintaining negligible computational overhead during the training phase.
Domain Adaptation and Machine Translation
In domain adaptation tests, a TRIME model trained on Wikipedia showed superior generalization when tested on the BooksCorpus compared to kNN-LM. Furthermore, on the IWSLT’14 (De-En) machine translation task, TRIME improved the BLEU score by 1.15 points over a vanilla Transformer, demonstrating its utility beyond standard language modeling.
Discussion and Conclusion
TRIME demonstrates that training language models to use memory explicitly leads to substantial performance gains, particularly for rare words where internal weights may be insufficient. By enabling back-propagation through memory representations, TRIME closes the gap between training and inference. While the approach increases inference latency due to the required nearest-neighbor search, its training efficiency and state-of-the-art results mark a significant advancement in memory-augmented modeling. Future work may focus on mitigating inference overhead and scaling the framework to multi-billion parameter models.
Summary updated