让大模型学会利用过去对话中的关键信息,提升长程推理能力。
TransMem: Transforming Hidden States into Memory for Large Language Models

- 将历史隐藏状态转为可复用的记忆,动态干预当前推理过程。
- 在多个数据集上提升10%以上准确率,最大增益达29.25点F1。
- 轻量级设计,适配不同规模模型,适合需要长记忆的智能体任务。
大型语言模型代理在处理长期交互历史时,需从过往观察和行动中识别并利用任务相关证据。然而,先前计算出的表示中蕴含的有效信息常被忽略。本文提出轻量级推理时参数化记忆模块TransMem,将冻结的LLM主干网络产生的稀疏历史隐藏状态转化为可重用的记忆表示。通过轻量门控网络动态作用于当前隐藏状态,避免重复编码上下文。为学习可迁移的记忆使用策略而非特定任务知识,引入证据条件自蒸馏:记忆增强的学生模型处理完整上下文,匹配仅基于证据的教师模型(共享相同冻结主干)的预测分布。在LoCoMo、HotpotQA和MemoryAgentBench上的实验表明,跨不同架构与规模均取得一致提升:LoCoMo上F1提升11.58–29.25,HotpotQA上提升10.20–13.03,MemoryAgentBench平均准确率从29.54%提升至40.00%。结果证明稀疏历史隐藏状态是高效且有效的长上下文记忆基础。代码已开源。
原文摘要 · Abstract (English)
Large language model (LLM) agents increasingly operate over long interaction histories, where effective reasoning requires identifying and exploiting task-relevant evidence distributed across past observations and actions. However, useful information encoded in previously computed representations is often underutilized during subsequent generation. We propose \textbf{TransMem}, a lightweight inference-time parametric memory module that transforms sparse historical hidden states from a frozen LLM backbone into reusable memory representations. TransMem uses a lightweight gating network to dynamically apply the latent intervention to the current hidden states, without repeatedly encoding the preceding context. To learn transferable memory utilization rather than task-specific knowledge, we introduce evidence-conditioned self-distillation. A memory-augmented student processes the full context and matches the predictive distribution of an evidence-only teacher that shares the same frozen backbone. Experiments on LoCoMo, HotpotQA, and MemoryAgentBench demonstrate consistent improvements across different model architectures and scales. TransMem yields gains of 11.58--29.25 $F_1$ on LoCoMo and 10.20--13.03 $F_1$ on HotpotQA, while improving the average MemoryAgentBench accuracy from 29.54\% to 40.00\%. These results establish sparse historical hidden states as an effective and efficient memory substrate for long-context LLM agents. Our code is available at https://github.com/Haodong-Lei-Ray/TransMem.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。