arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2305.04508cs.SE
收藏

基于微调的硬负采样改进代码搜索

Improving Code Search with Hard Negative Sampling Based on Fine-tuning

Hande Dong, Jiayi Lin, Yanlin Wang, Yichong Leng, Jiawei Chen, Yutao Xie

AI总结:

本文提出交叉编码器与Retriever-Ranker级联框架,并引入基于排序的硬负采样方法,以增强代码搜索中查询与代码的token级交互建模和硬负样本区分能力。

摘要:

预训练代码模型已成为代码搜索任务的最先进范式。该范式包括在与搜索无关的任务(如掩码语言建模)上预训练模型,随后进入专注于搜索相关任务的微调阶段。典型的微调方法是采用双编码器架构分别编码查询和代码的语义嵌入,然后基于这些嵌入计算它们的相似度。然而,典型的双编码器架构在建模查询与代码之间的token级交互方面存在不足,这限制了模型的能力。为解决这一局限,我们引入了一种用于代码搜索的交叉编码器架构,该架构联合编码查询与代码的拼接。我们进一步引入了一个Retriever-Ranker(RR)框架,将双编码器和交叉编码器级联起来,以提升评估和在线服务的效率。此外,我们提出了一种基于排序的硬负采样(PS)方法,以提高交叉编码器区分硬负代码的能力,从而进一步增强级联的RR框架。在四个数据集上使用三种代码模型进行的实验证明了我们所提方法的优越性。我们已在 https://github.com/DongHande/R2PS 公开了代码。

英文摘要:

Pre-trained code models have emerged as the state-of-the-art paradigm for code search tasks. The paradigm involves pre-training the model on search-irrelevant tasks such as masked language modeling, followed by the fine-tuning stage, which focuses on the search-relevant task. The typical fine-tuning method is to employ a dual-encoder architecture to encode semantic embeddings of query and code separately, and then calculate their similarity based on the embeddings. However, the typical dual-encoder architecture falls short in modeling token-level interactions between query and code, which limits the capabilities of model. To address this limitation, we introduce a cross-encoder architecture for code search that jointly encodes the concatenation of query and code. We further introduce a Retriever-Ranker (RR) framework that cascades the dual-encoder and cross-encoder to promote the efficiency of evaluation and online serving. Moreover, we present a ranking-based hard negative sampling (PS) method to improve the ability of cross-encoder to distinguish hard negative codes, which further enhances the cascaded RR framework. Experiments on four datasets using three code models demonstrate the superiority of our proposed method. We have made the code available at https://github.com/DongHande/R2PS.

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

↑