CodeSAM:通过将自注意力与多代码视图图融合的源代码表示学习
CodeSAM: Source Code Representation Learning by Infusing Self-Attention with Multi-Code-View Graphs
AI总结:
CodeSAM提出通过自注意力掩码将AST、DFG、CFG等多种代码视图融入Transformer模型,在语义代码搜索、代码克隆检测和程序分类三个下游任务上超越CodeBERT和GraphCodeBERT,实现紧凑高效的小型代码语言模型。
摘要:
机器学习(ML)在软件工程(SE)中的应用日益突出,因为它能够显著提升各类SE应用的性能。这一进展在很大程度上归功于可泛化的源代码表示的发展,这些表示能够有效捕捉代码的语法和语义特征。近年来,受自然语言处理(NLP)启发的预训练Transformer模型在SE任务中取得了显著成功。然而,源代码包含嵌入在其语法中的结构和语义属性,这些属性可以从结构化代码视图(如抽象语法树(AST)、数据流图(DFG)和控制流图(CFG))中提取。这些代码视图可以补充NLP技术,进一步改进SE任务。遗憾的是,目前没有灵活的框架能够有效地将任意代码视图融入现有的Transformer模型中。因此,在本工作中,我们提出了CodeSAM,这是一种新颖的可扩展框架,通过创建自注意力掩码将多个代码视图融入Transformer模型。我们使用CodeSAM在下游SE任务(语义代码搜索、代码克隆检测和程序分类)上微调小型语言模型(SLM)如CodeBERT。实验结果表明,通过使用该技术,与GraphCodeBERT和CodeBERT等SLM相比,在微调过程中利用单个代码视图或代码视图组合,我们在所有三个任务上都提升了下游性能。我们相信,这些结果表明CodeSAM这类技术有助于创建紧凑而高性能的代码SLM,适用于资源受限的环境。
英文摘要:
Machine Learning (ML) for software engineering (SE) has gained prominence due to its ability to significantly enhance the performance of various SE applications. This progress is largely attributed to the development of generalizable source code representations that effectively capture the syntactic and semantic characteristics of code. In recent years, pre-trained transformer-based models, inspired by natural language processing (NLP), have shown remarkable success in SE tasks. However, source code contains structural and semantic properties embedded within its grammar, which can be extracted from structured code-views like the Abstract Syntax Tree (AST), Data-Flow Graph (DFG), and Control-Flow Graph (CFG). These code-views can complement NLP techniques, further improving SE tasks. Unfortunately, there are no flexible frameworks to infuse arbitrary code-views into existing transformer-based models effectively. Therefore, in this work, we propose CodeSAM, a novel scalable framework to infuse multiple code-views into transformer-based models by creating self-attention masks. We use CodeSAM to fine-tune a small language model (SLM) like CodeBERT on the downstream SE tasks of semantic code search, code clone detection, and program classification. Experimental results show that by using this technique, we improve downstream performance when compared to SLMs like GraphCodeBERT and CodeBERT on all three tasks by utilizing individual code-views or a combination of code-views during fine-tuning. We believe that these results are indicative that techniques like CodeSAM can help create compact yet performant code SLMs that fit in resource constrained settings.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。