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