arXiv:2508.00901cs.LGcs.CL2025-08

揭示单层Transformer如何存储与提取知识,解释为何微调后仍能回忆未见过的事实。

Provable Knowledge Acquisition and Extraction in One-Layer Transformers

  • 通过理论证明模型在预训练中学习到关系特征方向和结构化注意力模式。
  • 微调可激活预训练中的关系特征,实现对未显式学习事实的提取。
  • 知识提取成功依赖于关系模板覆盖度,而非重复学习每条事实,适用于低秩微调。

大型语言模型在预训练中可能接触到事实知识,但在微调后却无法可靠使用。尽管已有大量实证证据表明MLP层存储事实关联且微调影响事实召回,但预训练、知识存储与微调后提取之间的训练动态机制仍不清楚。本文研究一个简化的单层Transformer,包含自注意力与MLP模块,通过下一个词预测进行训练,并随后在问答数据上微调。在适当的正则条件下,我们首先证明模型能达到接近最优的预训练损失,同时学习到结构化的注意力模式和特定关系的特征方向,揭示了知识获取机制。接着,我们表明微调能将问答提示格式转化为触发预训练关系特征的信号,使模型能够提取未在微调中重新出现的事实。我们的分析提出了知识提取的关系覆盖特性:微调无需重访每个存储的主语-答案对,只需覆盖足够多的潜在关系模板方向,这些方向是预训练时编码事实的方式。因此,提取效果随预训练多样性与微调覆盖度提升而改善,但随关系模板空间增大而变难。反之,覆盖不足会导致知识虽已存储却不可访问,为幻觉现象提供一种简化机制。该理论适用于全参数与低秩微调,解释了为何在关系覆盖充足时,低秩适配仍可恢复预训练事实知识。合成数据及基于PopQA的GPT-2/Llama实验验证了预测趋势。

原文摘要 · Abstract (English)

Large language models may encounter factual knowledge during pre-training yet fail to reliably use that knowledge after fine-tuning. Despite growing empirical evidence that MLP layers store factual associations and fine-tuning affects factual recall, the training-dynamics mechanisms linking next-token pre-training, knowledge storage, and post-fine-tuning extraction remain poorly understood. We study this problem in a stylized one-layer transformer with self-attention and MLP modules, trained by next-token prediction and subsequently fine-tuned on question-answering data. Under suitable regularity conditions, we first prove that the model reaches near-optimal pre-training loss while learning structured attention patterns and relation-specific feature directions, giving a mechanism for factual knowledge acquisition. We then show that fine-tuning can turn the Q&A prompt format into a trigger for pre-trained relation features, enabling the model to extract facts that are not revisited during fine-tuning. Our analysis yields a relation-covering characterization of knowledge extraction: fine-tuning need not revisit every stored subject-answer pair, but it must cover enough latent relation-template directions through which facts were encoded during pre-training. Consequently, extraction improves with pre-training multiplicity and fine-tuning coverage, but becomes harder as the relation-template universe grows. Conversely, insufficient coverage leads to a failure regime in which facts may be stored but remain inaccessible, providing a stylized mechanism for hallucination. The theory applies to both full and low-rank fine-tuning, offering insight into why low-rank adaptation can recover pre-trained factual knowledge when relation coverage is sufficient. Experiments on synthetic data and PopQA-based GPT-2/Llama models support the predicted trends.

Transformer知识提取微调理论分析

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