研究大模型如何完成两步逻辑推理,发现微调后准确率接近完美。
How Do LLMs Perform Two-Hop Reasoning in Context?
- 通过合成数据训练模型,观察其推理过程中的注意力变化。
- 微调后模型准确率接近100%,且能泛化到更长推理链。
- 揭示了从随机猜测到结构化推理的阶段性转变机制。
苏格拉底是人。所有人都是会死的。因此,苏格拉底会死。这种论证模式体现了典型的两步推理。形式上,两步推理指通过两个逻辑步骤连接相邻概念以得出结论,最终结论依赖于两步信息的整合。它是人类推理的核心,对形式逻辑和日常决策至关重要。尽管大语言模型(LLMs)取得进展,我们发现当存在干扰项时,它们在简单两步推理任务中仍会失败。在合成数据集上观察到,预训练模型常随机选择所有可能结论。然而,经过少量微调后,模型达到近似完美的准确率,并展现出强大的长度泛化能力。为理解内在机制,我们在合成任务上从头训练一个3层Transformer,并逆向解析其内部信息流。发现注意力得分随训练呈现清晰演化:经历从初始随机猜测到结构化顺序查询机制的突变阶段——模型在早期层先检索前序与桥梁概念,再用它们推导最终答案。最后,这些动态可被一个仅含三个参数的注意力网络有效捕捉。
原文摘要 · Abstract (English)
``Socrates is human. All humans are mortal. Therefore, Socrates is mortal.'' This form of argument illustrates a typical pattern of two-hop reasoning. Formally, two-hop reasoning refers to the process of inferring a conclusion by making two logical steps, each connecting adjacent concepts, such that the final conclusion depends on the integration of both steps. It is one of the most fundamental components of human reasoning and plays a crucial role in both formal logic and everyday decision-making. Despite recent progress in large language models (LLMs), we surprisingly find that they can fail at solving simple two-hop reasoning problems when distractors are present. We observe on a synthetic dataset that pre-trained LLMs often resort to random guessing among all plausible conclusions. However, after few steps of fine-tuning, models achieve near-perfect accuracy and exhibit strong length generalization. To understand the underlying mechanisms, we train a 3-layer Transformer from scratch on a synthetic two-hop reasoning task and reverse-engineer its internal information flow. We observe a clear progression in the attention logits throughout training. This pictures a sharp phase transition from an initial stage of random guessing to the emergence of a structured sequential query mechanism, where the model first retrieves the preceding and the bridge concepts in the early layers and then uses them to infer the final answer. Finally, we show that these dynamics can be captured by a minimal three-parameter attention-only network.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。