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

重新思考代码搜索中的负样本对

Rethinking Negative Pairs in Code Search

Nanyang Technological University(南洋理工大学);Alibaba-NTU Singapore Joint Research Institute(阿里巴巴-南洋理工大学新加坡联合研究院)

Haochen Li, Xin Zhou, Luu Anh Tuan, Chunyan Miao

AI总结:

针对代码搜索中InfoNCE损失存在的假负样本和负样本相关性未区分问题,提出Soft-InfoNCE损失函数,通过加权负样本对提升代码表示学习,实验验证其有效性。

摘要:

近年来,对比学习已成为微调代码搜索模型以提升软件开发效率和效果的关键组成部分。它根据搜索查询将正样本代码片段拉近,同时将负样本推开。在对比学习中,InfoNCE因其更好的性能而成为最广泛使用的损失函数。然而,InfoNCE负样本中的以下问题可能会损害其表示学习:1) 由于代码重复,大规模代码语料库中存在假负样本。2) 未能明确区分负样本之间的潜在相关性。例如,对于快速排序算法查询,冒泡排序算法示例的“负”程度低于文件保存函数。在本文中,我们通过提出一种简单而有效的Soft-InfoNCE损失函数来解决上述问题,该函数在InfoNCE中插入权重项。在我们提出的损失函数中,我们应用三种方法来估计负样本对的权重,并表明原始的InfoNCE损失是Soft-InfoNCE的一个特例。理论上,我们分析了Soft-InfoNCE对控制学习到的代码表示分布以及推导更精确的互信息估计的影响。此外,我们讨论了所提出的损失函数与其他设计替代方案的优越性。大量实验证明了Soft-InfoNCE和权重估计方法在包含六种编程语言的大规模公共数据集上,在最新代码搜索模型下的有效性。源代码可在\url{https://github.com/Alex-HaochenLi/Soft-InfoNCE}获取。

英文摘要:

Recently, contrastive learning has become a key component in fine-tuning code search models for software development efficiency and effectiveness. It pulls together positive code snippets while pushing negative samples away given search queries. Among contrastive learning, InfoNCE is the most widely used loss function due to its better performance. However, the following problems in negative samples of InfoNCE may deteriorate its representation learning: 1) The existence of false negative samples in large code corpora due to duplications. 2). The failure to explicitly differentiate between the potential relevance of negative samples. As an example, a bubble sorting algorithm example is less ``negative'' than a file saving function for the quick sorting algorithm query. In this paper, we tackle the above problems by proposing a simple yet effective Soft-InfoNCE loss that inserts weight terms into InfoNCE. In our proposed loss function, we apply three methods to estimate the weights of negative pairs and show that the vanilla InfoNCE loss is a special case of Soft-InfoNCE. Theoretically, we analyze the effects of Soft-InfoNCE on controlling the distribution of learnt code representations and on deducing a more precise mutual information estimation. We furthermore discuss the superiority of proposed loss functions with other design alternatives. Extensive experiments demonstrate the effectiveness of Soft-InfoNCE and weights estimation methods under state-of-the-art code search models on a large-scale public dataset consisting of six programming languages. Source code is available at \url{https://github.com/Alex-HaochenLi/Soft-InfoNCE}.

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

↑