arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2204.03293cs.SEcs.AIcs.LG
收藏

CoCoSoDa:有效的代码搜索对比学习

CoCoSoDa: Effective Contrastive Learning for Code Search

Xi’an Jiaotong University(西安交通大学);School of Software Engineering, Sun Yat-sen University(中山大学软件工程学院);The Chinese University of Hong Kong(香港中文大学);Microsoft Research(微软研究院);Chongqing University(重庆大学)

Ensheng Shi, Yanlin Wang, Wenchao Gu, Lun Du, Hongyu Zhang, Shi Han, Dongmei Zhang, Hongbin Sun

摘要:

代码搜索的目的是为给定的自然语言查询检索语义相关的代码片段。近年来,许多采用对比学习的方法在代码表示学习方面取得了可喜的成果,并大大提高了代码搜索的性能。但是,使用对比学习进行代码搜索还有很大的改进空间。在本文中,我们提出了CoCoSoDa有效地利用对比学习的代码搜索通过两个关键因素在对比学习:数据增强和负样本。具体地说,软数据增强是动态地掩蔽或替换输入序列的某些标记,以生成正样本。动量机制用于通过维护队列和动量编码器在小批量中生成大的且一致的负样本表示。此外,多模态对比学习用于将代码-查询对的表示拉在一起,并将未配对的代码片段和查询分开。我们进行了广泛的实验,以评估我们的方法在大规模数据集与六种程序设计语言的有效性。实验结果表明:(1)CoCoSoDa的表现优于14个基线,特别是在平均MRR分数上分别超过CodeBERT,GraphCodeBERT和UniXcoder 13.3%,10.5%和5.9%。(2)消融研究显示了我们方法的每个组成部分的有效性。(3)我们将我们的技术应用于几种不同的预训练模型,如RoBERTa,CodeBERT和GraphCodeBERT,并观察到它们在代码搜索中的性能显着提高。(4)我们的模型在不同的超参数下表现得很稳健。此外,我们进行定性和定量分析,以探索我们的模型的良好性能背后的原因。

英文摘要:

Code search aims to retrieve semantically relevant code snippets for a given natural language query. Recently, many approaches employing contrastive learning have shown promising results on code representation learning and greatly improved the performance of code search. However, there is still a lot of room for improvement in using contrastive learning for code search. In this paper, we propose CoCoSoDa to effectively utilize contrastive learning for code search via two key factors in contrastive learning: data augmentation and negative samples. Specifically, soft data augmentation is to dynamically masking or replacing some tokens with their types for input sequences to generate positive samples. Momentum mechanism is used to generate large and consistent representations of negative samples in a mini-batch through maintaining a queue and a momentum encoder. In addition, multimodal contrastive learning is used to pull together representations of code-query pairs and push apart the unpaired code snippets and queries. We conduct extensive experiments to evaluate the effectiveness of our approach on a large-scale dataset with six programming languages. Experimental results show that: (1) CoCoSoDa outperforms 14 baselines and especially exceeds CodeBERT, GraphCodeBERT, and UniXcoder by 13.3%, 10.5%, and 5.9% on average MRR scores, respectively. (2) The ablation studies show the effectiveness of each component of our approach. (3) We adapt our techniques to several different pre-trained models such as RoBERTa, CodeBERT, and GraphCodeBERT and observe a significant boost in their performance in code search. (4) Our model performs robustly under different hyper-parameters. Furthermore, we perform qualitative and quantitative analyses to explore reasons behind the good performance of our model.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑