用可执行代码让大模型真正学会因果反事实推理。
Executable Counterfactuals: Improving LLMs' Causal Reasoning Through Code
- 将因果推理拆解为推断、干预、预测三步,用代码实现可验证的反事实任务。
- 顶尖模型在反事实任务中准确率下降25%-40%,暴露其推理缺陷。
- 强化学习比监督微调更有效,能提升模型在新领域中的泛化能力。
反事实推理是智能的核心,包含三个步骤:从观测中推断潜在变量(溯因),构建替代情景(干预),预测结果(预测)。该能力对提升大模型的因果理解至关重要,尤其在科研等高风险领域。然而现有评估常跳过溯因步骤,仅测试干预推理,导致性能被高估。为此,本文提出可执行反事实框架,通过代码和数学问题实现因果推理的可操作化。该框架明确要求完成三步推理,并支持生成不同难度的合成数据,为评估与改进模型提供新基准。结果显示,o4-mini和Claude-4-Sonnet等先进模型在反事实任务中准确率下降25%-40%。我们构建了含if-else条件的反事实代码训练集,并测试其在含while循环等域外结构上的泛化能力;还检验了代码训练模型能否迁移到反事实数学应用题。监督微调虽提升了同域表现,却损害了跨域性能;而强化学习则激发核心认知行为,使模型在代码任务上性能提升1.5倍至2倍,在数学问题上也优于基线模型。推理轨迹分析进一步证实强化学习的优势。
原文摘要 · Abstract (English)
Counterfactual reasoning, a hallmark of intelligence, consists of three steps: inferring latent variables from observations (abduction), constructing alternatives (interventions), and predicting their outcomes (prediction). This skill is essential for advancing LLMs' causal understanding and expanding their applications in high-stakes domains such as scientific research. However, existing efforts in assessing LLM's counterfactual reasoning capabilities tend to skip the abduction step, effectively reducing to interventional reasoning and leading to overestimation of LLM performance. To address this, we introduce executable counterfactuals, a novel framework that operationalizes causal reasoning through code and math problems. Our framework explicitly requires all three steps of counterfactual reasoning and enables scalable synthetic data creation with varying difficulty, creating a frontier for evaluating and improving LLM's reasoning. Our results reveal substantial drop in accuracy (25-40%) from interventional to counterfactual reasoning for SOTA models like o4-mini and Claude-4-Sonnet. To address this gap, we construct a training set comprising counterfactual code problems having if-else condition and test on out-of-domain code structures (e.g. having while-loop); we also test whether a model trained on code would generalize to counterfactual math word problems. While supervised finetuning on stronger models' reasoning traces improves in-domain performance of Qwen models, it leads to a decrease in accuracy on OOD tasks such as counterfactual math problems. In contrast, reinforcement learning induces the core cognitive behaviors and generalizes to new domains, yielding gains over the base model on both code (improvement of 1.5x-2x) and math problems. Analysis of the reasoning traces reinforces these findings and highlights the promise of RL for improving LLMs' counterfactual reasoning.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。