arXiv:2509.21499cs.CLcs.PL2025-09被引 4

代码的结构比语义更影响大模型推理能力。

On Code-Induced Reasoning in LLMs

  • 通过扰动代码结构与语义,系统对比其对模型影响。
  • 结构破坏使模型性能下降,尤其在数学和代码任务上。
  • 伪代码和流程图可替代真实代码,提升训练效率。

代码数据已被证明能增强大语言模型(LLMs)的推理能力,但尚不明确是代码的哪些方面起关键作用。本文构建了涵盖十种编程语言的平行指令数据集,对代码的结构或语义属性进行可控扰动,再在五个模型家族、八个规模的LLM上进行微调,并评估其在自然语言、数学和代码任务上的表现。3,331次实验结果表明,模型对结构扰动比语义扰动更敏感,尤其在数学和代码任务中。适当的抽象形式如伪代码和流程图可达到与真实代码相当的效果,且用更少标记符编码相同信息时,性能常能保留甚至提升。令人惊讶的是,即使代码包含误导性信号,只要表面规律存在,仍保持竞争力。此外,语法风格也影响任务收益:Python更利于自然语言推理,而Java、Rust等低层级语言更利于数学任务。本研究为理解代码不同属性如何影响推理提供了系统性洞见,有助于优化训练数据设计。

原文摘要 · Abstract (English)

Code data has been shown to enhance the reasoning capabilities of large language models (LLMs), but it remains unclear which aspects of code are most responsible. We investigate this question with a systematic, data-centric framework. We construct parallel instruction datasets in ten programming languages and apply controlled perturbations that selectively disrupt structural or semantic properties of code. We then finetune LLMs from five model families and eight scales on each variant and evaluate their performance on natural language, math, and code tasks. Across 3,331 experiments, our results show that LLMs are more vulnerable to structural perturbations than semantic ones, particularly on math and code tasks. Appropriate abstractions like pseudocode and flowcharts can be as effective as code, while encoding the same information with fewer tokens without adhering to original syntax can often retain or even improve performance. Remarkably, even corrupted code with misleading signals remains competitive when surface-level regularities persist. Finally, syntactic styles also shape task-specific gains with Python favoring natural language reasoning and lower-level languages such as Java and Rust favoring math. Through our systematic framework, we aim to provide insight into how different properties of code influence reasoning and inform the design of training data for enhancing LLM reasoning capabilities.

大模型推理代码数据结构敏感性

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