arXiv:2506.10887cs.CLcs.LG2025-06NeurIPS被引 10

模型会凭空联想导致幻觉,也会靠联想学习新知识。

Generalization or Hallucination? Understanding Out-of-Context Reasoning in Transformers

  • 用概念关联机制解释模型为何能泛化也能幻觉
  • 实验证明五种大模型都受该机制影响
  • 适合研究模型推理逻辑与安全性的学者

大型语言模型(LLMs)可通过微调获取新知识,但这一过程表现出令人困惑的双重性:模型能从新事实中惊人地泛化,却也容易生成错误信息。本文提出,这两种行为源于同一机制——跨上下文推理(OCR),即在无因果关系的概念间建立关联以推断含义。我们在五个主流LLM上进行实验,证实OCR确实驱动了泛化与幻觉,取决于关联概念是否具有因果关系。为建立严谨理论,我们将其形式化为合成事实回忆任务。实证显示,采用因子分解输出与值矩阵的一层单头注意力变换器可学会解决该任务,而权重合并的模型则不能,凸显矩阵因子分解的关键作用。理论分析表明,梯度下降的隐式偏差倾向于最小化组合输出-值矩阵的核范数,这解释了为何模型能以高样本效率学习事实与推论,无论相关性是因果还是虚假。本研究为理解OCR现象提供了理论基础,为分析和缓解知识注入中的不良行为提供新视角。

原文摘要 · Abstract (English)

Large language models (LLMs) can acquire new knowledge through fine-tuning, but this process exhibits a puzzling duality: models can generalize remarkably from new facts, yet are also prone to hallucinating incorrect information. However, the reasons for this phenomenon remain poorly understood. In this work, we argue that both behaviors stem from a single mechanism known as out-of-context reasoning (OCR): the ability to deduce implications by associating concepts, even those without a causal link. Our experiments across five prominent LLMs confirm that OCR indeed drives both generalization and hallucination, depending on whether the associated concepts are causally related. To build a rigorous theoretical understanding of this phenomenon, we then formalize OCR as a synthetic factual recall task. We empirically show that a one-layer single-head attention-only transformer with factorized output and value matrices can learn to solve this task, while a model with combined weights cannot, highlighting the crucial role of matrix factorization. Our theoretical analysis shows that the OCR capability can be attributed to the implicit bias of gradient descent, which favors solutions that minimize the nuclear norm of the combined output-value matrix. This mathematical structure explains why the model learns to associate facts and implications with high sample efficiency, regardless of whether the correlation is causal or merely spurious. Ultimately, our work provides a theoretical foundation for understanding the OCR phenomenon, offering a new lens for analyzing and mitigating undesirable behaviors from knowledge injection.

大模型推理机制幻觉

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。