TransformCode:一种基于子树变换的代码嵌入对比学习框架
TransformCode: A Contrastive Learning Framework for Code Embedding via Subtree Transformation
AI总结:
提出TransformCode框架,通过AST变换进行对比学习,实现编码器与语言无关的代码嵌入,高效适配多种下游任务并超越现有方法。
摘要:
人工智能(AI)通过提升软件开发效率,彻底改变了软件工程(SE)。利用迁移学习的预训练模型(PTMs)的出现,极大地推动了AI for SE的发展。然而,在单个代码标记上操作的现有PTMs存在几个局限性:它们的训练和微调成本高昂;并且它们严重依赖标记数据,以便在特定任务数据集上进行微调。在本文中,我们提出了TransformCode,这是一个以对比学习方式学习代码嵌入的新颖框架。我们的框架与编码器无关且与语言无关,这意味着它可以利用任何编码器模型并处理任何编程语言。我们还提出了一种名为抽象语法树(AST)变换的新颖数据增强技术,该技术对原始代码片段应用语法和语义变换,以生成更多样且鲁棒的样本用于对比学习。与现有方法相比,我们的框架具有几个优势:(1)它灵活且适应性强,因为它可以轻松扩展到其他需要代码表示的下游任务(例如代码克隆检测和分类);(2)它高效且可扩展,因为它不需要大型模型或大量训练数据,并且可以支持任何编程语言;(3)它不局限于无监督学习,通过结合特定任务的标签或目标,也可以应用于一些监督学习任务;(4)它还可以根据计算资源调整编码器参数的数量。我们在几个与代码相关的任务上评估了我们的框架,并证明了其有效性以及相对于SourcererCC、Code2vec和InferCode等最先进方法的优越性。
英文摘要:
Artificial intelligence (AI) has revolutionized software engineering (SE) by enhancing software development efficiency. The advent of pre-trained models (PTMs) leveraging transfer learning has significantly advanced AI for SE. However, existing PTMs that operate on individual code tokens suffer from several limitations: They are costly to train and fine-tune; and they rely heavily on labeled data for fine-tuning on task-specific datasets. In this paper, we present TransformCode, a novel framework that learns code embeddings in a contrastive learning manner. Our framework is encoder-agnostic and language-agnostic, which means that it can leverage any encoder model and handle any programming language. We also propose a novel data-augmentation technique called abstract syntax tree (AST) transformation, which applies syntactic and semantic transformations to the original code snippets, to generate more diverse and robust samples for contrastive learning. Our framework has several advantages over existing methods: (1) It is flexible and adaptable, because it can easily be extended to other downstream tasks that require code representation (such as code-clone detection and classification); (2) it is efficient and scalable, because it does not require a large model or a large amount of training data, and it can support any programming language; (3) it is not limited to unsupervised learning, but can also be applied to some supervised learning tasks by incorporating task-specific labels or objectives; and (4) it can also adjust the number of encoder parameters based on computing resources. We evaluate our framework on several code-related tasks, and demonstrate its effectiveness and superiority over the state-of-the-art methods such as SourcererCC, Code2vec, and InferCode.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。