arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2406.10320cs.SEcs.AI
收藏

脱离风格:LLM 与代码风格迁移的不幸经历

Out of style: Misadventures with LLMs and code style transfer

University of California, Santa Cruz(加州大学圣克鲁兹分校);IBM Research(IBM研究院)

Karl Munson, Chih-Kai Ting, Serenity Wade, Anish Savla, Julian Dolby, Kiran Kate, Kavitha Srinivas

AI总结:

本文构建涵盖五类任务的 CSB 基准,严格评估预训练与微调代码语言模型的代码风格迁移能力,发现模型无法完成全部任务,并将发布大规模语料库以支持改进。

摘要:

与文本一样,程序也具有风格,并且就程序的可读性、可维护性和性能而言,某些编程风格比其他风格更可取。然而,除了行长度限制等琐碎的风格准则外,代码风格迁移很难实现自动化。受语言模型在文本风格迁移中取得成功的启发,我们研究代码语言模型是否能够执行代码风格迁移。与文本迁移不同,代码风格迁移具有严格要求:系统需要识别要更改的代码行,正确更改它们,并保持程序的其余部分不变。我们设计了 CSB(Code Style Benchmark,代码风格基准),这是一个涵盖五大类代码风格迁移任务的基准套件,包括将 for 循环转换为列表推导式、消除代码重复、为方法添加装饰器等。随后,我们使用这些测试来检验大型预训练代码语言模型或微调模型能否正确执行风格迁移,并依据严格指标来测试迁移确实发生且代码仍能通过功能测试。令人惊讶的是,语言模型未能完成所有任务,这表明它们在需要代码理解的任务上表现不佳。我们将公开大规模语料库,以帮助社区构建更好的代码模型。

英文摘要:

Like text, programs have styles, and certain programming styles are more desirable than others for program readability, maintainability, and performance. Code style transfer, however, is difficult to automate except for trivial style guidelines such as limits on line length. Inspired by the success of using language models for text style transfer, we investigate if code language models can perform code style transfer. Code style transfer, unlike text transfer, has rigorous requirements: the system needs to identify lines of code to change, change them correctly, and leave the rest of the program untouched. We designed CSB (Code Style Benchmark), a benchmark suite of code style transfer tasks across five categories including converting for-loops to list comprehensions, eliminating duplication in code, adding decorators to methods, etc. We then used these tests to see if large pre-trained code language models or fine-tuned models perform style transfer correctly, based on rigorous metrics to test that the transfer did occur, and the code still passes functional tests. Surprisingly, language models failed to perform all of the tasks, suggesting that they perform poorly on tasks that require code understanding. We will make available the large-scale corpora to help the community build better code models.

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

↑