Memory Tokens: Large Language Models Can Generate Reversible Sentence Embeddings

Ignacio Sastre, Aiala Rosá
6/17/2025
cs.CLcs.AIcs.LG

No official code found. Best implementation: nsuruguay05/memory_token (6 stars, last commit 2025-06-24).

Abstract

In this work, we observe an interesting phenomenon: it is possible to generate reversible sentence embeddings that allow an LLM to reconstruct the original text exactly, without modifying the model's weights. This is achieved by introducing a special memory token, whose embedding is optimized through training on a fixed sequence. When prompted with this embedding, the model reconstructs the fixed sequence exactly. We evaluate this phenomenon across English and Spanish datasets, sequences of up to approximately 240 tokens, and model scales ranging from 100M to 8B parameters. Notably, Llama 3.1 8B successfully reconstructs all tested sequences. Our findings highlight an interesting capability of LLMs and suggest potential applications in memory-based retrieval, compression, and controlled text generation.

View on arXivView PDF

Code Implementations(1)

Official implementation for the paper "Memory Tokens: Large Language Models Can Generate Reversible Sentence Embeddings"

60PythonFeb 14, 20251 years ago

Similar Papers

Cite this paper

@article{sastre2025memory,
  title  = {Memory Tokens: Large Language Models Can Generate Reversible Sentence Embeddings},
  author = {Ignacio Sastre and Aiala Rosá},
  year   = {2025},
  eprint = {2506.15001},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2506.15001v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2506.15001.svg)](https://codeofpaper.com/paper/2506.15001)

Discussion