---
title: "Contextual forgetting — 上下文遗忘"
source: "https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98"
wiki: "systems-analysis.info/int"
article: "Contextual_forgetting_—_上下文遗忘"
language: "zh"
categories:
  - "Category:Chinese"
  - "Category:Large language models"
  - "Category:Machine learning"
revision_id: 1226
wiki_created_at: 2026-09-06T22:45:25Z
wiki_modified_at: 2026-09-06T22:45:25Z
downloaded_at: 2026-09-07T22:44:49Z
---

# Contextual forgetting — 上下文遗忘

**大型语言模型中的上下文遗忘**（Contextual Forgetting）是一个多方面的现象，指大型语言模型 (LLM)在单次交互中丢失、忽略或低效使用先前提供的信息<sup>[\[1\]](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_note-howard-cds-1)</sup>。与人类记忆不同，LLM 没有长期状态存储，仅依赖于**上下文窗口**——即模型一次可以处理的有限文本量（以词元为单位）。这个窗口充当了模型的短期或工作记忆<sup>[\[2\]](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_note-liu2023-lost-in-middle-2)</sup>。

这种限制最著名的表现是**“中间遗忘”（Lost in the Middle）**问题——即模型倾向于更好地处理位于长上下文开头和结尾的信息，而对中间部分的信息处理较差<sup>[\[2\]](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_note-liu2023-lost-in-middle-2)</sup>。这种现象并非故障，而是源于 Transformer 架构及其训练原理的一个基本特性。

## 两种遗忘类型：上下文遗忘与灾难性遗忘

区分 LLM 中的两种根本不同类型的“遗忘”至关重要：上下文内遗忘和灾难性遗忘。

### 上下文内遗忘（中间遗忘）

这类遗忘发生在与已训练模型的**单次交互会话**（推理过程）中。它与**上下文窗口**的限制有关。当对话或文档的长度超过窗口大小时，模型会“忘记”最旧的片段，以便为新内容腾出空间。即使在窗口范围内，来自上下文中间部分的信息也可能被低效使用。这是模型工作记忆的一种限制<sup>[\[3\]](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_note-aclanthology-lost-in-middle-3)</sup>。在通俗文章中，这种现象也被称为**“上下文退化综合征”**（Context Degradation Syndrome, CDS）<sup>[\[1\]](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_note-howard-cds-1)</sup>。

### 灾难性遗忘（模型漂移）

这类遗忘，也称为“模型漂移”（*model drift*），发生在对模型进行新数据**微调（fine-tuning）**的过程中。当一个在海量通用知识语料库上预训练的模型，在特定领域的数据集（例如医学文本）上进行微调时，其权重会发生改变。这可能导致与新任务无关的、先前习得的知识和技能发生退化或被“抹去”<sup>[\[4\]](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_note-greyling-catastrophic-4)</sup>。

## 原因与机制

上下文遗忘是 Transformer 架构和向量空间几何的直接结果。

### Lost in the Middle - “中间遗忘”效应

斯坦福大学 2023 年一项名为《Lost in the Middle》的研究清晰地表明，LLM 从长上下文中提取信息的性能呈现出一条**U形曲线**<sup>[\[2\]](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_note-liu2023-lost-in-middle-2)</sup>。当相关信息位于上下文的开头（**首因效应**）或结尾（**近因效应**）时，回答的准确性最高；而当信息“隐藏”在中间时，准确性会显著下降。 这种现象的原因如下：

- **注意力机制**：Transformer 架构的本质使其为了保持全局连贯性，会不成比例地关注初始词元（即所谓的“注意力锚点”或 *attention sinks*）以及局部上下文，这导致了对中间部分的“焦点”减弱<sup>[\[5\]](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_note-neurips-poster-vectors-5)</sup>。
- **预训练数据**：模型通常在相对较短的文本上进行训练，在这些文本中，重要信息很少会距离开头数万个词元之远，这妨碍了它们有效利用超长上下文的能力<sup>[\[6\]](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_note-an2024-context-fall-short-6)</sup>。

## 表现与后果

- **上下文退化综合征**：在长时间的对话中，模型开始“跟不上思路”，重复回答，与先前确立的事实相矛盾，并给出越来越笼统和模糊的答案<sup>[\[1\]](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_note-howard-cds-1)</sup>。
- **多阶段任务失败**：在需要通过多轮对话来明确条件任务中，模型可能会“固守”最初的错误假设，而忽略后续的澄清，导致完全无法解决问题<sup>[\[7\]](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_note-arxiv-multi-turn-lost-7)</sup>。
- **文档分析的不可靠性**：在分析长篇报告或法律文件时，LLM 可能会遗漏位于中间部分的关键事实，这使其成为执行此类任务的不可靠工具。

## 缓解与预防策略

研究人员和开发人员采用多种方法来解决上下文遗忘问题。

### 扩大上下文窗口

最直接的方法是增加上下文窗口的大小。现代模型，如 **Claude 3**（20万词元）和 **Gemini 1.5 Pro**（高达200万词元），已显著扩展了这一限制<sup>[\[8\]](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_note-anthropic-claude3-family-8)[\[9\]](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_note-google-gemini1-5-pro-9)</sup>。然而，研究表明，仅仅扩大窗口并不能保证其被有效利用，“中间遗忘”问题依然存在<sup>[\[2\]](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_note-liu2023-lost-in-middle-2)</sup>。

### 高级提示工程

巧妙地构建提示可以显著提高性能。Anthropic 公司提出了以下实践建议<sup>[\[10\]](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_note-anthropic-long-context-tips-10)</sup>：

- **将文档置于开头**：将长文本放在提示的最开始，位于指令和问题之前。
- **使用 XML 标签**：用 \`\<document\>\` 标签包裹文档，以实现清晰分隔。
- **用引文支撑回答**：指示模型先提取相关引文，然后基于这些引文形成答案。

### Retrieval-Augmented Generation (RAG) - 检索增强生成

一种根本不同的方法是，不将所有信息都放入上下文窗口，而是将其外置于外部系统（如向量数据库），并根据请求提供。

1.  **检索 (Retrieve)**：当收到请求时，系统在外部数据库中搜索相关信息。
2.  **增强 (Augment)**：将找到的片段添加到原始请求中。
3.  **生成 (Generate)**：LLM 基于提供的上下文生成答案。

**RAG** 允许处理几乎无限量的数据，并能访问最新且经过验证的信息，从而降低了产生幻觉的风险，是目前最可靠的解决方案之一<sup>[\[11\]](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_note-google-cloud-rag-11)</sup>。

## 外部链接

- <a href="https://cs.stanford.edu/~nfliu/papers/lost-in-the-middle.arxiv2023.pdf" class="external text" rel="nofollow">Lost in the Middle: How Language Models Use Long Contexts</a> — 斯坦福大学的原始研究。
- <a href="https://www.anthropic.com/news/100k-context-windows" class="external text" rel="nofollow">Anthropic 公司宣布 Claude 模型支持 100K 上下文窗口</a>

## 参考文献

- Liu, N. F. et al. (2023). *Lost in the Middle: How Language Models Use Long Contexts*. <a href="https://arxiv.org/abs/2307.03172" class="external text" rel="nofollow">arXiv:2307.03172</a>.
- An, C. et al. (2024). *Why Does the Effective Context Length of LLMs Fall Short?*. <a href="https://arxiv.org/abs/2410.18745" class="external text" rel="nofollow">arXiv:2410.18745</a>.
- Ding, J. et al. (2023). *LongNet: Scaling Transformers to 1,000,000,000 Tokens*. <a href="https://arxiv.org/abs/2307.02486" class="external text" rel="nofollow">arXiv:2307.02486</a>.
- Yang, A. et al. (2024). *Context Parallelism for Scalable Million-Token Inference*. <a href="https://arxiv.org/abs/2411.01783" class="external text" rel="nofollow">arXiv:2411.01783</a>.
- Chen, S. et al. (2023). *Extending Context Window of Large Language Models via Positional Interpolation*. <a href="https://arxiv.org/abs/2306.15595" class="external text" rel="nofollow">arXiv:2306.15595</a>.
- Ding, Y. et al. (2024). *LongRoPE: Extending LLM Context Window Beyond 2 Million Tokens*. <a href="https://arxiv.org/abs/2402.13753" class="external text" rel="nofollow">arXiv:2402.13753</a>.
- Li, S. et al. (2023). *Functional Interpolation for Relative Positions Improves Long Context Transformers*. <a href="https://arxiv.org/abs/2310.04418" class="external text" rel="nofollow">arXiv:2310.04418</a>.
- Dong, Z. et al. (2024). *Exploring Context Window of Large Language Models via Decomposed Positional Vectors*. <a href="https://arxiv.org/abs/2405.18009" class="external text" rel="nofollow">arXiv:2405.18009</a>.
- Laban, P. et al. (2025). *LLMs Get Lost in Multi-Turn Conversation*. <a href="https://arxiv.org/abs/2505.06120" class="external text" rel="nofollow">arXiv:2505.06120</a>.
- Li, R. et al. (2024). *Extending Context Window in Large Language Models with Segmented Base Adjustment for Rotary Position Embeddings*. *Applied Sciences*, 14(7), 3076. <a href="https://www.mdpi.com/2076-3417/14/7/3076" class="external text" rel="nofollow">DOI:10.3390/app14073076</a>.
- Yang, A. & Reizenstein, J. (2024). *Exploring Context Window of LLMs via Decomposed Positional Vectors* (NeurIPS Poster). <a href="https://neurips.cc/virtual/2024/poster/92943" class="external text" rel="nofollow">NeurIPS 2024</a>.

## 注释

1.  <span id="cite_note-howard-cds-1">↑ <sup>[1.0](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_ref-howard-cds_1-0)</sup> <sup>[1.1](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_ref-howard-cds_1-1)</sup> <sup>[1.2](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_ref-howard-cds_1-2)</sup> Howard, James. «Context Degradation Syndrome: When Large Language Models Lose the Plot». *jameshoward.us*. <a href="https://jameshoward.us/2024/11/26/context-degradation-syndrome-when-large-language-models-lose-the-plot/" class="external autonumber" rel="nofollow">[1]</a></span>
2.  <span id="cite_note-liu2023-lost-in-middle-2">↑ <sup>[2.0](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_ref-liu2023-lost-in-middle_2-0)</sup> <sup>[2.1](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_ref-liu2023-lost-in-middle_2-1)</sup> <sup>[2.2](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_ref-liu2023-lost-in-middle_2-2)</sup> <sup>[2.3](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_ref-liu2023-lost-in-middle_2-3)</sup> Liu, Nelson F.; et al. «Lost in the Middle: How Language Models Use Long Contexts». *arXiv*. <a href="https://cs.stanford.edu/~nfliu/papers/lost-in-the-middle.arxiv2023.pdf" class="external autonumber" rel="nofollow">[2]</a></span>
3.  <span id="cite_note-aclanthology-lost-in-middle-3">[↑](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_ref-aclanthology-lost-in-middle_3-0) Liu, Nelson F.; et al. «Lost in the Middle: How Language Models Use Long Contexts». *ACL Anthology*. <a href="https://aclanthology.org/2024.tacl-1.9/" class="external autonumber" rel="nofollow">[3]</a></span>
4.  <span id="cite_note-greyling-catastrophic-4">[↑](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_ref-greyling-catastrophic_4-0) Greyling, Cobus. «Catastrophic Forgetting In LLMs». *Medium*. <a href="https://cobusgreyling.medium.com/catastrophic-forgetting-in-llms-bf345760e6e2" class="external autonumber" rel="nofollow">[4]</a></span>
5.  <span id="cite_note-neurips-poster-vectors-5">[↑](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_ref-neurips-poster-vectors_5-0) «Exploring Context Window of Large Language Models via Decomposed Positional Vectors». *NeurIPS Proceedings*. <a href="https://neurips.cc/virtual/2024/poster/92943" class="external autonumber" rel="nofollow">[5]</a></span>
6.  <span id="cite_note-an2024-context-fall-short-6">[↑](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_ref-an2024-context-fall-short_6-0) An, Chenxin; et al. «Why Does the Effective Context Length of LLMs Fall Short?». *arXiv*. <a href="https://arxiv.org/html/2410.18745v1" class="external autonumber" rel="nofollow">[6]</a></span>
7.  <span id="cite_note-arxiv-multi-turn-lost-7">[↑](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_ref-arxiv-multi-turn-lost_7-0) «LLMs Get Lost In Multi-Turn Conversation». *arXiv*. <a href="https://arxiv.org/html/2505.06120v1" class="external autonumber" rel="nofollow">[7]</a></span>
8.  <span id="cite_note-anthropic-claude3-family-8">[↑](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_ref-anthropic-claude3-family_8-0) «Introducing the next generation of Claude». *Anthropic*. <a href="https://www.anthropic.com/news/claude-3-family" class="external autonumber" rel="nofollow">[8]</a></span>
9.  <span id="cite_note-google-gemini1-5-pro-9">[↑](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_ref-google-gemini1-5-pro_9-0) «Google's Gemini 1.5 Pro - Revolutionizing AI with a 1M Token Context Window». *Medium*. <a href="https://medium.com/google-cloud/googles-gemini-1-5-pro-revolutionizing-ai-with-a-1m-token-context-window-bfea5adfd35f" class="external autonumber" rel="nofollow">[9]</a></span>
10. <span id="cite_note-anthropic-long-context-tips-10">[↑](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_ref-anthropic-long-context-tips_10-0) «Long context prompting tips». *Anthropic Documentation*. <a href="https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/long-context-tips" class="external autonumber" rel="nofollow">[10]</a></span>
11. <span id="cite_note-google-cloud-rag-11">[↑](https://systems-analysis.info/int/Contextual_forgetting_%E2%80%94_%E4%B8%8A%E4%B8%8B%E6%96%87%E9%81%97%E5%BF%98#cite_ref-google-cloud-rag_11-0) «What is Retrieval-Augmented Generation (RAG)?». *Google Cloud*. <a href="https://cloud.google.com/use-cases/retrieval-augmented-generation" class="external autonumber" rel="nofollow">[11]</a></span>
