Rethinking Negative Pairs in Code Search
Haochen Li, Xin Zhou, Anh Tuan Luu, Chunyan Miao
摘要
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 In-foNCE 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 https://github.com/ Alex-HaochenLi/Soft-InfoNCE .
问 Lune
几分钟读透这篇 Paper,不用再花一下午。
Lune 能读完全文,也能读引用它的顶会 Paper,讲清它的结论、证据和局限,每一点都注明出自哪篇 Paper。不用硬啃,也不靠猜。
已有 6 篇顶会 Paper 引用了它。别等审稿人问起,先弄清它们发现了什么。
脉络
- MGS3: A Multi-Granularity Self-Supervised Code Search Framework 引用了 CodeBERT: A Pre-Trained Model for Programming and Natural Languages
- MGS3: A Multi-Granularity Self-Supervised Code Search Framework 引用了 GraphCodeBERT: Pre-training Code Representations with Data Flow
- Rewriting the Code: A Simple Method for Large Language Model Augmented Code Search 引用了 CodeBERT: A Pre-Trained Model for Programming and Natural Languages
- Rewriting the Code: A Simple Method for Large Language Model Augmented Code Search 引用了 GraphCodeBERT: Pre-training Code Representations with Data Flow
- Debiased Contrastive Learning of Unsupervised Sentence Representations 引用了 On the Sentence Embeddings from Pre-trained Language Models
- DrainCode: Stealthy Energy Consumption Attacks on Retrieval-Augmented Code Generation via Context Poisoning 引用了 CodeBERT: A Pre-Trained Model for Programming and Natural Languages
- DrainCode: Stealthy Energy Consumption Attacks on Retrieval-Augmented Code Generation via Context Poisoning 引用了 GraphCodeBERT: Pre-training Code Representations with Data Flow
- Uncertainty-Aware Contrastive Learning with Hard Negative Sampling for Code Search Tasks 引用了 Rewriting the Code: A Simple Method for Large Language Model Augmented Code Search
- Uncertainty-Aware Contrastive Learning with Hard Negative Sampling for Code Search Tasks 引用了 Understanding Contrastive Representation Learning through Alignment and Uniformity on the Hypersphere
- Uncertainty-Aware Contrastive Learning with Hard Negative Sampling for Code Search Tasks 引用了 CodeBERT: A Pre-Trained Model for Programming and Natural Languages
- Uncertainty-Aware Contrastive Learning with Hard Negative Sampling for Code Search Tasks 引用了 GraphCodeBERT: Pre-training Code Representations with Data Flow
引用它的顶会 Paper6
- Rewriting the Code: A Simple Method for Large Language Model Augmented Code SearchHaochen Li, Xin Zhou, Zhiqi ShenACL 2024 · 10 次引用
- DrainCode: Stealthy Energy Consumption Attacks on Retrieval-Augmented Code Generation via Context PoisoningYanli Wang, Jiadong Wu, Tianyue Jiang, Mingwei Liu 等ASE 2025 · 3 次引用
- AlignCoder: Aligning Retrieval with Target Intent for Repository-Level Code CompletionTianyue Jiang, Yanlin Wang, Yanli Wang, Daya Guo 等ASE 2025 · 2 次引用
- Uncertainty-Aware Contrastive Learning with Hard Negative Sampling for Code Search TasksHan Liu, Jiaqing Zhan, Qin ZhangAAAI 2025 · 1 次引用
- MGS3: A Multi-Granularity Self-Supervised Code Search FrameworkRui Li, Junfeng Kang, Qi Liu, Liyang He 等KDD 2025
它引用的 Paper11
- CodeBERT: A Pre-Trained Model for Programming and Natural LanguagesZhangyin Feng, Daya Guo, Duyu Tang, Nan Duan 等EMNLP Findings 2020 · 2,828 次引用
- Understanding Contrastive Representation Learning through Alignment and Uniformity on the HypersphereTongzhou Wang, Phillip IsolaICML 2020 · 2,360 次引用
- GraphCodeBERT: Pre-training Code Representations with Data FlowDaya Guo, Shuo Ren, Shuai Lu, Zhangyin Feng 等ICLR 2021 · 1,644 次引用
- On the Sentence Embeddings from Pre-trained Language ModelsBohan Li, Hao Zhou, Junxian He, Mingxuan Wang 等EMNLP 2020 · 538 次引用
- Debiased Contrastive Learning of Unsupervised Sentence RepresentationsKun Zhou, Beichen Zhang, Wayne Xin Zhao, Ji-Rong WenACL 2022 · 128 次引用
相关 Paper
- Vision Language Pre-training by Contrastive Learning with Cross-Modal Similarity RegulationChaoya Jiang, Wei Ye, Haiyang Xu, Songfang Huang 等ACL 2023 · 7 次引用
- Empowering Collaborative Filtering with Principled Adversarial Contrastive LossAn Zhang, Leheng Sheng, Zhibo Cai, Xiang Wang 等NeurIPS 2023 · 56 次引用
- Contrastive Predictive Coding Done Right for Mutual Information EstimationJongha Ryu, Pavan Yeddanapudi, Xiangxiang Xu, Gregory W. WornellICLR 2026 · 1 次引用
- Does GCL Need a Large Number of Negative Samples? Enhancing Graph Contrastive Learning with Effective and Efficient Negative SamplingYongqi Huang, Jitao Zhao, Dongxiao He, Di Jin 等AAAI 2025 · 11 次引用
- A New Mechanism for Eliminating Implicit Conflict in Graph Contrastive LearningDongxiao He, Jitao Zhao, Cuiying Huo, Yongqi Huang 等AAAI 2024 · 21 次引用
