paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Duetcs: Code Style Transfer through Generation and Retrieval

DUETCS:通过生成与检索的代码风格迁移
ICSE 2023 IEEE/ACM 45th International Conference on Software Engineering (ICSE)2023匹配度 1/10 · 论文研究代码风格迁移,属于程序生成与程序转换任务,与用户关注的静态分析/形式化验证、浮点程序分析、贝叶斯程序分析以及 LLM/Agent 与这些方向的交叉均无关。引用 9 inbox
Binger Chen, Ziawasch Abedjan
crossref: 2026-09-12dblp: 2026-09-12

AI 速览

一句话:提出无监督代码风格迁移方法 DUETCS,分别学习风格与内容嵌入,结合生成与检索实现任意目标风格。

代码风格直接影响代码理解,自动将代码风格迁移到用户偏好或保持一致有助于项目协作维护并最大化开源代码价值。现有代码风格化工作要么局限于代码格式化,要么需要人工预定义风格检查与转换规则。本文提出无监督方法,支持任意代码风格的自动迁移。其核心思想是利用 Big Code 数据库分别学习风格与内容嵌入,从而生成或检索功能相同且具有目标风格的代码。作者精心编码风格与内容特征,使风格嵌入可从任意代码中学习,并探索了基于注意力的风格生成模型与元学习,在 DUETCS 中实现;同时补充检索模式,利用相同嵌入直接在 Big Code 中搜索目标代码。实验表明,DUETCS 比现有基线能捕获更多风格方面。

问题
现有代码风格化方法要么局限于代码格式化,要么需要人工预定义风格检查与转换规则,无法自动处理任意代码风格。
方法
利用 Big Code 数据库分别学习风格与内容嵌入,探索基于注意力的生成模型与元学习,并辅以基于相同嵌入的检索模式,生成或检索功能相同、风格符合目标偏好的代码。
评估
实验表明,DUETCS 相比现有基线能够捕获更多代码风格方面。
原文摘要(Abstract)

Coding style has direct impact on code comprehension. Automatically transferring code style to user's preference or consistency can facilitate project cooperation and maintenance, as well as maximize the value of open-source code. Existing work on automating code stylization is either limited to code formatting or requires human supervision in pre-defining style checking and transformation rules. In this paper, we present unsupervised methods to assist automatic code style transfer for arbitrary code styles. The main idea is to leverage Big Code database to learn style and content embedding separately to generate or retrieve a piece of code with the same functionality and the desired target style. We carefully encode style and content features, so that a style embedding can be learned from arbitrary code. We explored the capabilities of novel attention-based style generation models and meta-learning and implemented our ideas in DUETCS. We complement the learning-based approach with a retrieval mode, which uses the same embeddings to directly search for the desired piece of code in Big Code. Our experiments show that DUETCS captures more style aspects than existing baselines.

链接与引用

DOI 原文 · DBLP

BibTeX
@inproceedings{ChenA23,
  title = {Duetcs: Code Style Transfer through Generation and Retrieval},
  author = {Binger Chen and Ziawasch Abedjan},
  booktitle = {ICSE},
  year = {2023},
  doi = {10.1109/icse48619.2023.00198}
}