arXiv:2601.21894cs.LG2026-01

代码结构复杂度影响大模型推理能力,选对代码才能有效提升。

Not All Code Is Equal: A Data-Centric Study of Code Complexity and LLM Reasoning

  • 用环复杂度和逻辑行数控制代码结构,构建对比数据集。
  • 83%实验显示限定复杂度范围的代码效果优于混合复杂度。
  • 适合想优化推理能力但数据有限的研究者或工程师。

大型语言模型(LLMs)的推理能力常归因于生成思维链的能力。近期研究表明,代码训练可进一步增强该能力,但现有研究多将代码视为通用信号,未明确其具体贡献属性。本文聚焦代码的结构复杂度,涵盖控制流与组合结构,探究其在微调过程中如何影响模型对多步推理的内化。研究涵盖两种场景:解决方案驱动的复杂度(同一问题的不同解法)、任务驱动的复杂度(任务本身的难易差异)。通过环复杂度(cyclomatic complexity)与逻辑行数(logical lines of code)构建受控微调数据集,评估多种开源大模型在多样化推理基准上的表现。结果表明,尽管代码有助于提升推理,但其结构属性决定实际效用:在83%的实验中,限制微调数据于特定结构复杂度范围的表现优于使用结构多样化的代码,揭示了一条超越规模扩展的数据中心化改进路径。

原文摘要 · Abstract (English)

Large Language Models (LLMs) increasingly exhibit strong reasoning abilities, often attributed to their capacity to generate chain-of-thought-style intermediate reasoning. Recent work suggests that exposure to code can further enhance these skills, but existing studies largely treat code as a generic training signal, leaving open the question of which properties of code actually contribute to improved reasoning. To address this gap, we study the structural complexity of code, which captures control flow and compositional structure that may shape how models internalise multi-step reasoning during fine-tuning. We examine two complementary settings: solution-driven complexity, where complexity varies across multiple solutions to the same problem, and problem-driven complexity, where complexity reflects variation in the underlying tasks. Using cyclomatic complexity and logical lines of code to construct controlled fine-tuning datasets, we evaluate a range of open-weight LLMs on diverse reasoning benchmarks. Our findings show that although code can improve reasoning, structural properties strongly determine its usefulness. In 83% of experiments, restricting fine-tuning data to a specific structural complexity range outperforms training on structurally diverse code, pointing to a data-centric path for improving reasoning beyond scaling.

大模型推理代码复杂度数据质量

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