arXiv:2605.07237cs.CL2026-05被引 1

让语言模型直接用代码思考,提升数学推理准确率

Teaching Language Models to Think in Code

论文配图:Teaching Language Models to Think in Code
图 1 · 摘自论文原文
  • 用代码作为核心推理工具,取代自然语言与代码交替的旧模式
  • 在5个数学竞赛题上超越所有基线,40亿参数模型胜过2350亿参数大模型
  • 99.2%的答案基于代码执行结果,能自动修复执行错误,适合追求高精度推理的研究者

工具集成推理(TIR)是当前语言模型解决数学问题的主要范式,结合自然语言推理与代码执行。但该方法存在三大局限:代码常作为事后验证,中间自然语言计算易出错,且自然语言与代码角色重叠。本文提出ThinC(Thinking in Code)框架,使代码本身成为推理主体而非辅助工具。ThinC先进行简短的自然语言规划,随后所有推理通过仅由执行输出连接的代码块完成。我们从教师模型中蒸馏出12.2k条以代码为中心的推理轨迹,并对ThinC-1.7B和ThinC-4B进行监督微调与强化学习训练。ThinC-4B在五个竞赛级数学基准上持续优于所有TIR基线,甚至超过更大的Qwen3-235B-A22B-Thinking模型。分析显示,99.2%的最终答案基于解释器输出,且模型可在不依赖自然语言干预的情况下可靠恢复代码执行失败。

原文摘要 · Abstract (English)

Tool-integrated reasoning (TIR) has emerged as a dominant paradigm for mathematical problem solving in language models, combining natural language (NL) reasoning with code execution. However, this interleaved setup has three key limitations: code often acts as a post-hoc verifier, intermediate NL computations are error-prone, and NL and code play overlapping rather than clearly distinct roles. We propose ThinC (Thinking in Code), a framework in which code itself serves as the reasoner rather than as a tool invoked by NL. A ThinC trajectory begins with a brief NL planning step, after which all reasoning unfolds through code blocks connected only by their execution outputs. We distill 12.2k code-centric trajectories from a teacher model and train ThinC-1.7B and ThinC-4B with supervised fine-tuning followed by reinforcement learning. ThinC-4B consistently outperforms every TIR baseline on five competition-level math benchmarks and even surpasses the much larger Qwen3-235B-A22B-Thinking. Further analysis shows that ThinC reasons through code: 99.2% of its final answers are grounded in interpreter output, and the model recovers reliably from code execution failures without intermediate NL reasoning. Our code and models will be released soon.

代码推理数学推理语言模型强化学习

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