通过反思错误思维提升代码生成的搜索质量
RethinkMCTS: Refining Erroneous Thoughts in Monte Carlo Tree Search for Code Generation
- 用MCTS先搜思维路径,再生成代码
- 结合细粒度执行反馈修正错误推理
- 适合追求高精度代码生成的研究者
树搜索在代码生成中表现优异。现有方法将树搜索与反思结合,通过总结过往错误实现迭代优化,但仍面临两大挑战:一是直接在代码空间中搜索,忽略关键的推理过程;二是基于反思的方法仅累积历史错误,未提供正确推理路径,导致后续搜索难以找到最优解,降低搜索质量。本文提出RethinkMCTS框架,系统性探索并优化代码生成的推理过程。具体而言,采用MCTS在代码生成前搜索思维路径,并集成名为rethink的精炼机制,利用细粒度代码执行反馈修正搜索过程中的错误思维,确保搜索路径与更优推理对齐,从而提升整体搜索质量。大量实验表明,RethinkMCTS优于此前基于搜索和反馈增强的代码生成基线方法。
原文摘要 · Abstract (English)
Tree search methods have demonstrated impressive performance in code generation. Previous methods combine tree search with reflection that summarizes past mistakes to achieve iterative improvement. However, these methods face significant challenges. First, they search directly within the code language space, neglecting the underlying reasoning process critical for effective code generation. Second, reflection-based approaches merely accumulate historical errors in memory without providing correct reasoning pathways, making it difficult for subsequent search iterations to identify optimal solutions, resulting in decreased search quality. In this work, we propose RethinkMCTS, a framework that systematically explores and refines the reasoning process for code generation. Specifically, we employ MCTS to search for thoughts before code generation and integrate MCTS with a refinement mechanism called rethink, which incorporates fine-grained code execution feedback to refine erroneous thoughts during the search. It ensures the search path aligns with better reasoning, improving overall search quality. Through extensive experiments, we demonstrate that RethinkMCTS outperforms previous search-based and feedback-enhanced code generation baselines.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。