From Token to Line: Enhancing Code Generation with a Long-Term Perspective

Fuente: arXiv
Gespeichert in:
Bibliographische Detailangaben
Hauptverfasser: Lu, Tingwei, Li, Yangning, Wang, Liyuan, Lin, Binghuai, Lv, Qingsong, Xu, Zishan, Zheng, Hai-Tao, Li, Yinghui, Kim, Hong-Gee
Format: Preprint
Veröffentlicht: 2025
Schlagworte:
Online-Zugang:
Tags: Tag hinzufügen
Keine Tags, Fügen Sie den ersten Tag hinzu!
_version_ 1866914315093671936
author Lu, Tingwei
Li, Yangning
Wang, Liyuan
Lin, Binghuai
Lv, Qingsong
Xu, Zishan
Zheng, Hai-Tao
Li, Yinghui
Kim, Hong-Gee
author_facet Lu, Tingwei
Li, Yangning
Wang, Liyuan
Lin, Binghuai
Lv, Qingsong
Xu, Zishan
Zheng, Hai-Tao
Li, Yinghui
Kim, Hong-Gee
contents The emergence of large language models (LLMs) has significantly promoted the development of code generation task, sparking a surge in pertinent literature. Current research is hindered by redundant generation results and a tendency to overfit local patterns in the short term. Although existing studies attempt to alleviate the issue by adopting a multi-token prediction strategy, there remains limited focus on choosing the appropriate processing length for generations. By analyzing the attention between tokens during the generation process of LLMs, it can be observed that the high spikes of the attention scores typically appear at the end of lines. This insight suggests that it is reasonable to treat each line of code as a fundamental processing unit and generate them sequentially. Inspired by this, we propose the LSR-MCTS algorithm, which leverages MCTS to determine the code line-by-line and select the optimal path. Further, we integrate a self-refine mechanism at each node to enhance diversity and generate higher-quality programs through error correction. Extensive experiments and comprehensive analyses on three public coding benchmarks demonstrate that our method outperforms the state-of-the-art performance approaches.
format Preprint
id arxiv_https___arxiv_org_abs_2504_07433
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle From Token to Line: Enhancing Code Generation with a Long-Term Perspective
Lu, Tingwei
Li, Yangning
Wang, Liyuan
Lin, Binghuai
Lv, Qingsong
Xu, Zishan
Zheng, Hai-Tao
Li, Yinghui
Kim, Hong-Gee
Computation and Language
The emergence of large language models (LLMs) has significantly promoted the development of code generation task, sparking a surge in pertinent literature. Current research is hindered by redundant generation results and a tendency to overfit local patterns in the short term. Although existing studies attempt to alleviate the issue by adopting a multi-token prediction strategy, there remains limited focus on choosing the appropriate processing length for generations. By analyzing the attention between tokens during the generation process of LLMs, it can be observed that the high spikes of the attention scores typically appear at the end of lines. This insight suggests that it is reasonable to treat each line of code as a fundamental processing unit and generate them sequentially. Inspired by this, we propose the LSR-MCTS algorithm, which leverages MCTS to determine the code line-by-line and select the optimal path. Further, we integrate a self-refine mechanism at each node to enhance diversity and generate higher-quality programs through error correction. Extensive experiments and comprehensive analyses on three public coding benchmarks demonstrate that our method outperforms the state-of-the-art performance approaches.
title From Token to Line: Enhancing Code Generation with a Long-Term Perspective
topic Computation and Language
url https://arxiv.org/abs/2504.07433