ChatPaper.aiChatPaper

코드 생성에서의 사고 확장

Think Anywhere in Code Generation

March 31, 2026
저자: Xue Jiang, Tianyu Zhang, Ge Li, Mengyang Liu, Taozhi Chen, Zhenhua Xu, Binhua Li, Wenpin Jiao, Zhi Jin, Yongbin Li, Yihong Dong
cs.AI

초록

대규모 언어 모델(LLM)의 추론 능력 발전은 주로 최종 답변을 제시하기 전에 추론을 수행하는 사전 사고 방식에 의존해왔습니다. 그러나 이러한 접근법은 코드 생성 분야에서 심각한 한계를 보입니다. 문제의 전체적인 복잡성은 코드 구현 과정에서 비로소 드러나는 경우가 많아 사전 사고만으로는 불충분하기 때문입니다. 또한 코드 생성 과정 전반에 걸쳐 상이한 난이도에 따라 추론 노력을 유연하게 할당할 수 없다는 문제도 있습니다. 본 논문에서는 코드 생성 중 임의의 토큰 위치에서 온디맨드 방식으로 추론을 수행할 수 있는 새로운 메커니즘인 Think-Anywhere를 제안합니다. Think-Anywhere는 먼저 LLM이 콜드스타트 학습을 통해 추론 패턴을 모방하도록 가르친 후, 결과 기반 강화학습 보상을 활용하여 모델이 언제, 어디서 추론을 수행할지 자율적으로 탐색하도록 유도합니다. 4개의 주요 코드 생성 벤치마크(LeetCode, LiveCodeBench, HumanEval, MBPP)에서 진행한 폭넓은 실험 결과, Think-Anywhere는 기존 추론 방법과 최근의 사후 학습 접근법을 모두 능가하는 최첨단 성능을 달성하면서 다양한 LLM에 걸쳐 일관된 일반화 성능을 보여주었습니다. 추가 분석을 통해 Think-Anywhere가 모델로 하여금 높은 엔트로피 위치에서 적응적으로 추론을 수행하게 하여 향상된 해석 가능성을 제공함을 확인하였습니다.
English
Recent advances in reasoning Large Language Models (LLMs) have primarily relied on upfront thinking, where reasoning occurs before final answer. However, this approach suffers from critical limitations in code generation, where upfront thinking is often insufficient as problems' full complexity only reveals itself during code implementation. Moreover, it cannot adaptively allocate reasoning effort throughout the code generation process where difficulty varies significantly. In this paper, we propose Think-Anywhere, a novel reasoning mechanism that enables LLMs to invoke thinking on-demand at any token position during code generation. We achieve Think-Anywhere by first teaching LLMs to imitate the reasoning patterns through cold-start training, then leveraging outcome-based RL rewards to drive the model's autonomous exploration of when and where to invoke reasoning. Extensive experiments on four mainstream code generation benchmarks (i.e., LeetCode, LiveCodeBench, HumanEval, and MBPP) show that Think-Anywhere achieves state-of-the-art performance over both existing reasoning methods and recent post-training approaches, while demonstrating consistent generalization across diverse LLMs. Our analysis further reveals that Think-Anywhere enables the model to adaptively invoke reasoning at high-entropy positions, providing enhanced interpretability.
PDF110April 2, 2026