CodeArt:当符号缺失时通过注意力正则化构建更好的代码模型
CodeArt: Better Code Models by Attention Regularization When Symbols Are Lacking
AI总结:
CodeArt针对代码符号缺失问题,提出利用程序分析提取上下文并通过注意力掩码正则化预训练代码模型,在二进制相似性、类型推断和恶意软件家族分类任务上显著超越现有SOTA。
摘要:
基于Transformer的代码模型在许多软件工程任务中表现出色。然而,当符号缺失或信息量不足时,其有效性会下降。原因在于,没有符号的帮助,模型可能无法学会关注正确的关联/上下文。我们提出了一种在符号缺失情况下预训练通用代码模型的新方法。我们观察到,在这种情况下,程序会退化为用非常原始的语言编写的内容。因此,我们提出使用程序分析先验地提取上下文(而不是像普通模型那样依赖符号和掩码语言建模)。然后,我们利用一种新颖的注意力掩码方法,只允许模型关注这些上下文,例如双向程序依赖传递闭包和token共现。同时,利用固有的自注意力机制来学习哪些被允许的注意力比其他注意力更重要。为了实现这一想法,我们增强了BERT模型的普通token化和模型架构,构建并利用了注意力掩码,并引入了一种新的预训练算法。我们从头开始预训练这个类似BERT的模型,使用的数据集包含2600万个经过剥离的二进制函数,并带有我们工具提取的显式程序依赖信息。我们将该模型应用于三个下游任务:二进制相似性、类型推断和恶意软件家族分类。我们的预训练模型可以将这些任务中的SOTA分别从53%提高到64%、从49%提高到60%、从74%提高到94%。它还大幅优于其他代码理解模型的通用预训练技术。
英文摘要:
Transformer based code models have impressive performance in many software engineering tasks. However, their effectiveness degrades when symbols are missing or not informative. The reason is that the model may not learn to pay attention to the right correlations/contexts without the help of symbols. We propose a new method to pre-train general code models when symbols are lacking. We observe that in such cases, programs degenerate to something written in a very primitive language. We hence propose to use program analysis to extract contexts a priori (instead of relying on symbols and masked language modeling as in vanilla models). We then leverage a novel attention masking method to only allow the model attending to these contexts, e.g., bi-directional program dependence transitive closures and token co-occurrences. In the meantime, the inherent self-attention mechanism is utilized to learn which of the allowed attentions are more important compared to others. To realize the idea, we enhance the vanilla tokenization and model architecture of a BERT model, construct and utilize attention masks, and introduce a new pre-training algorithm. We pre-train this BERT-like model from scratch, using a dataset of 26 million stripped binary functions with explicit program dependence information extracted by our tool. We apply the model in three downstream tasks: binary similarity, type inference, and malware family classification. Our pre-trained model can improve the SOTAs in these tasks from 53% to 64%, 49% to 60%, and 74% to 94%, respectively. It also substantially outperforms other general pre-training techniques of code understanding models.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。