[论文解读] SynCoBERT: Syntax-Guided Multi-Modal Contrastive Pre-Training for Code Representation
SynCoBERT 引入基于语法的目标(标识符预测和 AST 边预测)以及一个多模态对比学习框架,从代码、注释和 AST 学习代码表示,在相同的预训练语料和模型规模下,在四个代码智能任务上达到最新效果。
Code representation learning, which aims to encode the semantics of source code into distributed vectors, plays an important role in recent deep-learning-based models for code intelligence. Recently, many pre-trained language models for source code (e.g., CuBERT and CodeBERT) have been proposed to model the context of code and serve as a basis for downstream code intelligence tasks such as code search, code clone detection, and program translation. Current approaches typically consider the source code as a plain sequence of tokens, or inject the structure information (e.g., AST and data-flow) into the sequential model pre-training. To further explore the properties of programming languages, this paper proposes SynCoBERT, a syntax-guided multi-modal contrastive pre-training approach for better code representations. Specially, we design two novel pre-training objectives originating from the symbolic and syntactic properties of source code, i.e., Identifier Prediction (IP) and AST Edge Prediction (TEP), which are designed to predict identifiers, and edges between two nodes of AST, respectively. Meanwhile, to exploit the complementary information in semantically equivalent modalities (i.e., code, comment, AST) of the code, we propose a multi-modal contrastive learning strategy to maximize the mutual information among different modalities. Extensive experiments on four downstream tasks related to code intelligence show that SynCoBERT advances the state-of-the-art with the same pre-training corpus and model size.
研究动机与目标
- 通过利用编程语言的符号性和句法属性,推动改进的代码表示。
- 结合多模态信息(代码、注释和 AST)以捕捉关于代码语义的互补信息。
- 设计两种新颖的预训练目标(Identifier Prediction 和 AST Edge Prediction)来编码标识符和 AST 边。
- 引入多模态对比学习机制,以最大化跨模态的互信息。
- 在使用相同的预训练语料和模型规模的前提下,在关键代码智能任务上展示出最新的性能。
提出的方法
- 提出 SynCoBERT,一个在代码、注释和 AST 表征上进行预训练的 12 层 Transformer 编码器。
- 使用多模态掩码语言模型(MMLM)在自然语言 NL、编程语言 PL 和 AST 中预测被掩码的标记。
- 引入 Identifier Prediction(IP),将每个代码标记分类为标识符或非标识符。
- 引入 AST Edge Prediction(TEP),预测 AST 节点之间边的存在性。
- 应用多模态对比学习(MCL)目标,在代码、注释和 AST 模态之间最大化互信息,使用成对数据(NL-PL-AST)和非成对数据,结合同批次和跨批次负采样。
- 将总体预训练目标整合为 MMLM、IP、TEP、MCL 的组合,加上 L2 正则化。
实验结果
研究问题
- RQ1基于语法引导的目标(IP 和 TEP)能否超越现有基于 MLM 的预训练提升代码表示?
- RQ2利用带对比学习的多模态信息(代码、注释、AST)是否能在跨任务上获得更具普适性的代码表示?
- RQ3在相同预训练设置下,SynCoBERT 在多样的代码智能任务(代码搜索、克隆检测、缺陷检测、程序翻译)上的表现如何?
主要发现
- 在相同预训练语料和模型规模下,SynCoBERT 在多项代码智能任务上达到最先进的结果。
- IP 与 TEP 目标有助于性能提升,证明了利用代码的符号性和句法属性的价值。
- 多模态对比学习(MCL)带来显著提升,突出跨模态互信息对代码表示的益处。
- 与 CodeBERT、GraphCodeBERT 等强基线相比,SynCoBERT 提升了自然语言代码搜索、代码克隆检测、代码缺陷检测和程序翻译。
- 消融结果显示,去除 IP、TEP 或 MCL 将降低性能,其中 MCL 对代码搜索的影响尤为显著。
- 由于学习到的句法知识,该模型能够泛化到预训练中未见过的语言(例如 C#/Java 翻译)。
更好的研究,从现在开始
从论文设计到论文写作,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。