Effective Hard Negative Mining for Contrastive Learning-based Code Search

计算机科学 编码(集合论) 人工智能 程序设计语言 集合(抽象数据类型)
作者
Ye Fan,Chuanyi Li,Jidong Ge,LiGuo Huang,Bin Luo
出处
期刊:ACM Transactions on Software Engineering and Methodology [Association for Computing Machinery]
标识
DOI:10.1145/3695994
摘要

Background. Code search aims to find the most relevant code snippet in a large codebase based on a given natural language query. An accurate code search engine can increase code reuse and improve programming efficiency. The focus of code search is how to represent the semantic similarity of code and query. With the development of code pre-trained models, the pattern of using numeric feature vectors (embeddings) to represent code semantics and using vector distance to represent semantic similarity has replaced traditional string matching methods. The quality of semantic representations is critical to the effectiveness of downstream tasks such as code search. Currently, the state-of-the-art (SOTA) learning method uses the contrastive learning paradigm. The objective of contrastive learning is to maximize the similarity between matching code and query (positive samples) and minimize the similarity between mismatched pairs (negative samples). To increase the reusing of negative samples, prior contrastive learning approaches use a large queue (memory bank) to store embeddings. Problem. However, there is still a lot of room for improvement in using negative examples for code search: ① Due to the random selection of negative samples, semantic representations learned by existing models cannot distinguish similar codes well. ② Since semantic vectors in the memory bank are reused from previous inference results and then directly used for loss function calculation without gradient descent, the model cannot effectively learn the negative sample semantic information. Method. To solve the above problems, we propose a contrastive learning code search model with hard negative mining called CoCoHaNeRe: ❶ To enable the model to distinguish similar codes, we introduce hard negative examples into contrastive training, which are negative examples in the codebase that are most similar to positive examples. As a result, hard negative examples are most likely to make the model make mistakes. ❷ To improve the learning efficiency of negative samples during training, we add all hard negative examples to the model's gradient descent process. Result. To verify the effectiveness of CoCoHaNeRe, we conducted experiments on large code search datasets with six programming languages, as well as similar retrieval tasks code clone detection and code question answering. Experimental results show that our model achieves SOTA performance. In the code search task, the average MRR score of CoCoHaNeRe exceeds CodeBERT, GraphCodeBERT, and UniXcoder by 11.25%, 8.13%, and 7.38%, respectively. It has also made great progress in code clone detection and code question answering. In addition, our method performs well in different programming languages and code pre-training models. Furthermore, qualitative analysis shows that our model effectively distinguishes high-order semantic differences between similar codes.
最长约 10秒,即可获得该文献文件

科研通智能强力驱动
Strongly Powered by AbleSci AI
科研通是完全免费的文献互助平台,具备全网最快的应助速度,最高的求助完成率。 对每一个文献求助,科研通都将尽心尽力,给求助人一个满意的交代。
实时播报
CaoRouLi完成签到,获得积分10
刚刚
1秒前
罐装发布了新的文献求助10
1秒前
HopeStar完成签到,获得积分10
1秒前
2秒前
科研通AI5应助坚定丑采纳,获得10
2秒前
友好白凡发布了新的文献求助30
4秒前
5秒前
皮影完成签到,获得积分10
7秒前
董小星发布了新的文献求助10
7秒前
赘婿应助不安的橘子采纳,获得10
7秒前
lzc完成签到,获得积分10
8秒前
端端仔发布了新的文献求助10
8秒前
LeichterL发布了新的文献求助10
8秒前
寻绿完成签到,获得积分10
9秒前
9秒前
小呆鹿发布了新的文献求助10
10秒前
科研通AI5应助投石问路采纳,获得10
10秒前
dc完成签到,获得积分10
11秒前
罐装发布了新的文献求助10
11秒前
CodeCraft应助lzc采纳,获得10
11秒前
12秒前
zhang发布了新的文献求助10
12秒前
kun发布了新的文献求助10
14秒前
15秒前
15秒前
锦鲤发布了新的文献求助10
17秒前
苹果煎饼完成签到,获得积分10
17秒前
17秒前
可爱的函函应助xiaoyan采纳,获得10
19秒前
小鱼儿发布了新的文献求助10
20秒前
Lucas应助iuuuuu采纳,获得10
20秒前
瀛瀛发布了新的文献求助20
22秒前
罐装发布了新的文献求助10
22秒前
ink发布了新的文献求助10
22秒前
22秒前
追风少年完成签到,获得积分10
23秒前
redking发布了新的文献求助10
26秒前
虚心的夏青完成签到,获得积分10
27秒前
苏苏完成签到,获得积分10
27秒前
高分求助中
All the Birds of the World 4000
Production Logging: Theoretical and Interpretive Elements 3000
Les Mantodea de Guyane Insecta, Polyneoptera 2000
Machine Learning Methods in Geoscience 1000
Resilience of a Nation: A History of the Military in Rwanda 888
Essentials of Performance Analysis in Sport 500
Measure Mean Linear Intercept 500
热门求助领域 (近24小时)
化学 材料科学 医学 生物 工程类 有机化学 物理 生物化学 纳米技术 计算机科学 化学工程 内科学 复合材料 物理化学 电极 遗传学 量子力学 基因 冶金 催化作用
热门帖子
关注 科研通微信公众号,转发送积分 3730648
求助须知:如何正确求助?哪些是违规求助? 3275292
关于积分的说明 9991544
捐赠科研通 2990897
什么是DOI,文献DOI怎么找? 1641265
邀请新用户注册赠送积分活动 779676
科研通“疑难数据库(出版商)”最低求助积分说明 748331