mlsanityData to 7 Oct 2026

Rethinking Negative Pairs in Code Search

arXiv 2310.08069 ↗First posted 12 Oct 2023cs.SE cs.CL cs.IRcited by 14

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

  1. 2018Representation Learning with Contrastive Predictive Codingcited by 7,662
  2. 2013Efficient Estimation of Word Representations in Vector Spacecited by 4,346
  3. 2021SimCSE: Simple Contrastive Learning of Sentence Embeddingscited by 2,168
  4. 2020Understanding Contrastive Representation Learning through Alignment and Uniformity on the Hyperspherecited by 1,393
  5. 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,286
  6. 2019CodeSearchNet Challenge: Evaluating the State of Semantic Code Searchcited by 638
  7. 2020GraphCodeBERT: Pre-training Code Representations with Data Flowcited by 600
  8. 2022Text and Code Embeddings by Contrastive Pre-Trainingcited by 358
  9. 2022UniXcoder: Unified Cross-Modal Pre-training for Code Representationcited by 355
  10. 2018The Adverse Effects of Code Duplication in Machine Learning Models of Codecited by 123
  11. 2020Boosting Contrastive Self-Supervised Learning with False Negative Cancellationcited by 119
  12. 2021CoSQA: 20,000+ Web Queries for Code Search and Question Answeringcited by 74
12 more
  1. 2021SynCoBERT: Syntax-Guided Multi-Modal Contrastive Pre-Training for Code Representationcited by 63
  2. 2022Debiased Contrastive Learning of Unsupervised Sentence Representationscited by 56
  3. 2020Self-Supervised Contrastive Learning for Code Retrieval and Summarization via Semantic-Preserving Transformationscited by 49
  4. 2021Incremental False Negative Detection for Contrastive Learningcited by 48
  5. 2019When Deep Learning Met Code Searchcited by 45
  6. 2017Query Expansion Based on Crowd Knowledge for Code Searchcited by 18
  7. 2022Code Search: A Survey of Techniques for Finding Codecited by 18
  8. 2022CODE-MVP: Learning to Represent Source Code from Multiple Views with Contrastive Pre-Trainingcited by 15
  9. 2021Multimodal Representation for Neural Code Searchcited by 11
  10. 2022Code Search based on Context-aware Code Translationcited by 11
  11. 2022Exploring Representation-Level Augmentation for Code Searchcited by 8
  12. 2022Soft-Labeled Contrastive Pre-training for Function-level Code Representationcited by 7

Built on by

Cited by year (2026 to 7 Oct)

Citing papers per year: 2023: 1; 2024: 3; 2025: 5; 2026: 5.

14 papers.

Sort:

By area: