arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2401.04514cs.SEcs.CLcs.IRcs.LG
收藏

重写代码:一种用于大型语言模型增强代码搜索的简单方法

Rewriting the Code: A Simple Method for Large Language Model Augmented Code Search

Nanyang Technological University(南洋理工大学)

Haochen Li, Xin Zhou, Zhiqi Shen

AI总结:

针对代码搜索中生成增强检索框架因代码风格偏差导致改进受限的问题,提出ReCo方法通过重写代码库代码进行风格归一化,显著提升多种检索设置下的准确率,并引入首个代码风格相似性度量指标。

摘要:

在代码搜索中,生成增强检索(GAR)框架通过生成示例代码片段来增强查询,已成为解决代码片段与自然语言查询之间模态错位这一主要挑战的有前景的策略,特别是得益于大型语言模型(LLMs)所展示的代码生成能力。然而,我们的初步调查表明,这种LLM增强框架带来的改进有些受限。这一局限性可能归因于这样一个事实:生成的代码尽管在功能上是准确的,但常常与代码库中的真实代码在风格上表现出明显的偏差。在本文中,我们扩展了基础的GAR框架,并提出了一种简单而有效的方法,该方法额外重写了代码库中的代码(ReCo)以实现风格归一化。实验结果表明,ReCo在多种搜索场景下的稀疏检索(高达35.7%)、零样本密集检索(高达27.6%)和微调密集检索(高达23.6%)设置中显著提升了检索准确率。为了进一步阐明ReCo的优势并促进代码风格归一化的研究,我们引入了Code Style Similarity,这是首个专为量化代码风格相似性而设计的指标。值得注意的是,我们的实证发现揭示了现有指标在捕捉风格细微差异方面的不足。源代码和数据可在https://github.com/Alex-HaochenLi/ReCo获取。

英文摘要:

In code search, the Generation-Augmented Retrieval (GAR) framework, which generates exemplar code snippets to augment queries, has emerged as a promising strategy to address the principal challenge of modality misalignment between code snippets and natural language queries, particularly with the demonstrated code generation capabilities of Large Language Models (LLMs). Nevertheless, our preliminary investigations indicate that the improvements conferred by such an LLM-augmented framework are somewhat constrained. This limitation could potentially be ascribed to the fact that the generated codes, albeit functionally accurate, frequently display a pronounced stylistic deviation from the ground truth code in the codebase. In this paper, we extend the foundational GAR framework and propose a simple yet effective method that additionally Rewrites the Code (ReCo) within the codebase for style normalization. Experimental results demonstrate that ReCo significantly boosts retrieval accuracy across sparse (up to 35.7%), zero-shot dense (up to 27.6%), and fine-tuned dense (up to 23.6%) retrieval settings in diverse search scenarios. To further elucidate the advantages of ReCo and stimulate research in code style normalization, we introduce Code Style Similarity, the first metric tailored to quantify stylistic similarities in code. Notably, our empirical findings reveal the inadequacy of existing metrics in capturing stylistic nuances. The source code and data are available at \url{https://github.com/Alex-HaochenLi/ReCo}.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑