Rethinking Negative Pairs in Code Search
Not on the map. Why?
Abstract (arXiv)
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 urlhttps://github.com/Alex-HaochenLi/Soft-InfoNCE.
Key facts. Cited by 14 papers in the map (data through 7 Oct 2026). Builds on 24 of its 45 references that are in the map. First posted on arXiv 12 Oct 2023.
Builds on
24 of 45 references.
References · 24
- 2018Representation Learning with Contrastive Predictive Codingcited by 7,662
- 2013Efficient Estimation of Word Representations in Vector Spacecited by 4,346
- 2021SimCSE: Simple Contrastive Learning of Sentence Embeddingscited by 2,168
- 2020Understanding Contrastive Representation Learning through Alignment and Uniformity on the Hyperspherecited by 1,393
- 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,286
- 2019CodeSearchNet Challenge: Evaluating the State of Semantic Code Searchcited by 638
- 2020GraphCodeBERT: Pre-training Code Representations with Data Flowcited by 600
- 2022Text and Code Embeddings by Contrastive Pre-Trainingcited by 358
- 2022UniXcoder: Unified Cross-Modal Pre-training for Code Representationcited by 355
- 2018The Adverse Effects of Code Duplication in Machine Learning Models of Codecited by 123
- 2020Boosting Contrastive Self-Supervised Learning with False Negative Cancellationcited by 119
- 2021CoSQA: 20,000+ Web Queries for Code Search and Question Answeringcited by 74
12 more
- 2021SynCoBERT: Syntax-Guided Multi-Modal Contrastive Pre-Training for Code Representationcited by 63
- 2022Debiased Contrastive Learning of Unsupervised Sentence Representationscited by 56
- 2020Self-Supervised Contrastive Learning for Code Retrieval and Summarization via Semantic-Preserving Transformationscited by 49
- 2021Incremental False Negative Detection for Contrastive Learningcited by 48
- 2019When Deep Learning Met Code Searchcited by 45
- 2017Query Expansion Based on Crowd Knowledge for Code Searchcited by 18
- 2022Code Search: A Survey of Techniques for Finding Codecited by 18
- 2022CODE-MVP: Learning to Represent Source Code from Multiple Views with Contrastive Pre-Trainingcited by 15
- 2021Multimodal Representation for Neural Code Searchcited by 11
- 2022Code Search based on Context-aware Code Translationcited by 11
- 2022Exploring Representation-Level Augmentation for Code Searchcited by 8
- 2022Soft-Labeled Contrastive Pre-training for Function-level Code Representationcited by 7
Built on by
Citing papers per year: 2023: 1; 2024: 3; 2025: 5; 2026: 5.
14 papers.
Sort:
By area:
- 2026When Does LeJEPA Learn a World Model?cited by 27
- 2024Rewriting the Code: A Simple Method for Large Language Model Augmented Code Searchcited by 17
- 2025CLEF: Clinically-Guided Contrastive Learning for Electrocardiogram Foundation Modelscited by 7
- 2026AlignCoder: Aligning Retrieval with Target Intent for Repository-Level Code Completioncited by 7
- 2024Multi-modal Relation Distillation for Unified 3D Representation Learningcited by 5
- 2024Towards noise contrastive estimation with soft targets for conditional modelscited by 4
- 2023Language Models are Better Bug Detector Through Code-Pair Classificationcited by 3
- 2025GiFT: Gibbs Fine-Tuning for Code Generationcited by 3
- 2026DRAINCODE: Stealthy Energy Consumption Attacks on Retrieval-Augmented Code Generation via Context Poisoningcited by 3
- 2025OASIS: Order-Augmented Strategy for Improved Code Searchcited by 2
- 2026PhoenixRepair: Rethinking Repair Strategy Exploration in Software Agentscited by 2
- 2025URECA: The Chain of Two Minimum Set Cover Problems exists behind Adaptation to Shifts in Semantic Code Searchcited by 0
- 2026Natural Language Code Retrieval for 1C:Enterprise: An Open Benchmark and Efficient Bi-Encoder20 Aug 2026
- 2026PhoenixRepair: Rethinking Repair Strategy Exploration in Software Agents21 Jul 2026
- 2026When Does LeJEPA Learn a World Model?25 May 2026
- 2026DRAINCODE: Stealthy Energy Consumption Attacks on Retrieval-Augmented Code Generation via Context Poisoning28 Jan 2026
- 2026AlignCoder: Aligning Retrieval with Target Intent for Repository-Level Code Completion27 Jan 2026
- 2025CLEF: Clinically-Guided Contrastive Learning for Electrocardiogram Foundation Models1 Dec 2025
- 2025EnzyCLIP: A Cross-Attention Dual Encoder Framework with Contrastive Learning for Predicting Enzyme Kinetic Constants29 Nov 2025
- 2025OASIS: Order-Augmented Strategy for Improved Code Search11 Mar 2025
- 2025GiFT: Gibbs Fine-Tuning for Code Generation17 Feb 2025
- 2025URECA: The Chain of Two Minimum Set Cover Problems exists behind Adaptation to Shifts in Semantic Code Search11 Feb 2025
- 2024Multi-modal Relation Distillation for Unified 3D Representation Learning19 Jul 2024
- 2024Towards noise contrastive estimation with soft targets for conditional models22 Apr 2024
- 2026When Does LeJEPA Learn a World Model?cited by 27
- 2026When Does LeJEPA Learn a World Model?25 May 2026
- 2024Rewriting the Code: A Simple Method for Large Language Model Augmented Code Searchcited by 17
- 2025CLEF: Clinically-Guided Contrastive Learning for Electrocardiogram Foundation Modelscited by 7
- 2026AlignCoder: Aligning Retrieval with Target Intent for Repository-Level Code Completioncited by 7
- 2024Multi-modal Relation Distillation for Unified 3D Representation Learningcited by 5
- 2024Towards noise contrastive estimation with soft targets for conditional modelscited by 4
- 2023Language Models are Better Bug Detector Through Code-Pair Classificationcited by 3
- 2025GiFT: Gibbs Fine-Tuning for Code Generationcited by 3
- 2025OASIS: Order-Augmented Strategy for Improved Code Searchcited by 2
- 2025URECA: The Chain of Two Minimum Set Cover Problems exists behind Adaptation to Shifts in Semantic Code Searchcited by 0
- 2025EnzyCLIP: A Cross-Attention Dual Encoder Framework with Contrastive Learning for Predicting Enzyme Kinetic Constantscited by 0
- 2026Natural Language Code Retrieval for 1C:Enterprise: An Open Benchmark and Efficient Bi-Encodercited by 0
- 2026Natural Language Code Retrieval for 1C:Enterprise: An Open Benchmark and Efficient Bi-Encoder20 Aug 2026
- 2026AlignCoder: Aligning Retrieval with Target Intent for Repository-Level Code Completion27 Jan 2026
- 2025CLEF: Clinically-Guided Contrastive Learning for Electrocardiogram Foundation Models1 Dec 2025
- 2025EnzyCLIP: A Cross-Attention Dual Encoder Framework with Contrastive Learning for Predicting Enzyme Kinetic Constants29 Nov 2025
- 2025OASIS: Order-Augmented Strategy for Improved Code Search11 Mar 2025
- 2025GiFT: Gibbs Fine-Tuning for Code Generation17 Feb 2025
- 2025URECA: The Chain of Two Minimum Set Cover Problems exists behind Adaptation to Shifts in Semantic Code Search11 Feb 2025
- 2024Multi-modal Relation Distillation for Unified 3D Representation Learning19 Jul 2024
- 2024Towards noise contrastive estimation with soft targets for conditional models22 Apr 2024
- 2024Rewriting the Code: A Simple Method for Large Language Model Augmented Code Search9 Jan 2024
- 2023Language Models are Better Bug Detector Through Code-Pair Classification14 Nov 2023