paperbot · PL 论文追踪

全部论文 待读 收藏

P2 CoCoSoDa: Effective Contrastive Learning for Code Search

CoCoSoDa:面向代码搜索的有效对比学习
ICSE 2023 IEEE/ACM 45th International Conference on Software Engineering (ICSE)2023匹配度 2/10 · 该论文属于代码搜索与代码表示学习,利用对比学习提升检索性能,但未涉及静态分析、Agentic 程序、LLM/Agent 改进形式化验证、浮点程序分析或贝叶斯程序分析等用户核心方向。虽然同属机器学习与程序语言交叉,但距离具体研究画像较远。引用 80 inbox
Ensheng Shi, Yanlin Wang, Wenchao Gu, Lun Du, Hongyu Zhang, Shi Han, Dongmei Zhang, Hongbin Sun
crossref: 2026-09-12dblp: 2026-09-12arxiv: 2026-09-12

AI 速览

一句话:提出CoCoSoDa,通过软数据增强、动量负样本与多模态对比学习提升代码搜索性能。

代码搜索旨在根据自然语言查询检索语义相关的代码片段。现有对比学习方法虽已提升代码表示学习和搜索性能,但仍有改进空间。本文提出CoCoSoDa,从对比学习的两个关键因素入手:数据增强与负样本。具体地,采用软数据增强,对输入序列动态掩码或按类型替换部分token以生成正样本;利用队列和动量编码器,在小批量中生成大量且一致的负样本表示;并通过多模态对比学习拉近代码-查询配对表示、推开非配对表示。作者在六种编程语言的大规模数据集上开展实验,与18个基线比较,并进行消融、预训练模型迁移、超参数鲁棒性以及定性与定量分析。结果表明,CoCoSoDa平均MRR分别超过CodeBERT、GraphCodeBERT和UniXcoder 13.3%、10.5%和5.9%。

问题
如何在代码搜索中更有效地利用对比学习,尤其是改进数据增强与负样本设计,以学习更好的代码-查询表示。
方法
提出CoCoSoDa,使用软数据增强构造正样本,借助队列和动量编码器生成一致负样本,并采用多模态对比学习对齐代码与查询表示。
评估
在六种编程语言的大规模代码搜索数据集上与18个基线比较,并通过消融实验、迁移到多种预训练模型、超参数鲁棒性实验及定性与定量分析进行验证。
原文摘要(Abstract)

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 18 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.

链接与引用

DOI 原文 · arXiv · PDF(开放获取) · DBLP

BibTeX
@inproceedings{ShiWGDZHZS23,
  title = {CoCoSoDa: Effective Contrastive Learning for Code Search},
  author = {Ensheng Shi and Yanlin Wang and Wenchao Gu and Lun Du and Hongyu Zhang and Shi Han and Dongmei Zhang and Hongbin Sun},
  booktitle = {ICSE},
  year = {2023},
  doi = {10.1109/icse48619.2023.00185}
}