CoCoSoDa: Effective Contrastive Learning for Code Search
Not on the map. Why?
Abstract (arXiv)
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 14 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.
Key facts. Cited by 21 papers in the map (data through 7 Oct 2026). Builds on 52 of its 86 references that are in the map. First posted on arXiv 7 Apr 2022.
Builds on
52 of 86 references.
References · 52
- 2017Attention Is All You Needcited by 59,932
- 2020Language Models are Few-Shot Learnerscited by 32,199
- 2019RoBERTa: A Robustly Optimized BERT Pretraining Approachcited by 13,266
- 2020A Simple Framework for Contrastive Learning of Visual Representationscited by 11,979
- 2018Representation Learning with Contrastive Predictive Codingcited by 7,662
- 2019Momentum Contrast for Unsupervised Visual Representation Learningcited by 7,482
- 2015Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shiftcited by 6,979
- 2014Learning Phrase Representations using RNN Encoder-Decoder for Statistical Machine Translationcited by 4,016
- 2021SimCSE: Simple Contrastive Learning of Sentence Embeddingscited by 2,168
- 2018Unsupervised Feature Learning via Non-Parametric Instance-level Discriminationcited by 1,838
- 2017Improved Regularization of Convolutional Neural Networks with Cutoutcited by 1,623
- 2018Unsupervised Representation Learning by Predicting Image Rotationscited by 1,586
38 more
- 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
- 2014Convolutional Neural Networks for Sentence Classificationcited by 1,124
- 2021CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generationcited by 890
- 2019CodeSearchNet Challenge: Evaluating the State of Semantic Code Searchcited by 638
- 2020GraphCodeBERT: Pre-training Code Representations with Data Flowcited by 600
- 2020Understanding the Behaviour of Contrastive Losscited by 397
- 2021Unified Pre-training for Program Understanding and Generationcited by 361
- 2022UniXcoder: Unified Cross-Modal Pre-training for Code Representationcited by 355
- 2020On the Stability of Fine-tuning BERT: Misconceptions, Explanations, and Strong Baselinescited by 254
- 2019Representation Degeneration Problem in Training Natural Language Generation Modelscited by 250
- 2020DeCLUTR: Deep Contrastive Learning for Unsupervised Textual Representationscited by 249
- 2017A Survey of Machine Learning for Big Code and Naturalnesscited by 220
- 2020CERT: Contrastive Self-supervised Learning for Language Understandingcited by 169
- 2021COCO-LM: Correcting and Contrasting Text Sequences for Language Model Pretrainingcited by 126
- 2019A Neural Model for Generating Natural Language Summaries of Program Subroutinescited by 76
- 2020Contrastive Code Representation Learningcited by 76
- 2021CoSQA: 20,000+ Web Queries for Code Search and Question Answeringcited by 74
- 2021SynCoBERT: Syntax-Guided Multi-Modal Contrastive Pre-Training for Code Representationcited by 63
- 2020Self-Supervised Contrastive Learning for Code Retrieval and Summarization via Semantic-Preserving Transformationscited by 49
- 2021On the Evaluation of Neural Code Summarizationcited by 47
- 2019When Deep Learning Met Code Searchcited by 45
- 2019Multi-Modal Attention Network Learning for Semantic Source Code Retrievalcited by 40
- 2020Fast and Memory-Efficient Neural Code Completioncited by 38
- 2022SPT-Code: Sequence-to-Sequence Pre-Training for Learning Source Code Representationscited by 35
- 2013Some Improvements on Deep Convolutional Neural Network Based Image Classificationcited by 34
- 2021CAST: Enhancing Code Summarization with Hierarchical Splitting and Reconstruction of Abstract Syntax Treescited by 31
- 2021Code Completion by Modeling Flattened Abstract Syntax Trees as Graphscited by 30
- 2022RACE: Retrieval-Augmented Commit Message Generationcited by 27
- 2021Project-Level Encoding for Neural Source Code Summarization of Subroutinescited by 24
- 2020Opportunities and Challenges in Code Search Toolscited by 22
- 2020A Multi-Perspective Architecture for Semantic Code Searchcited by 20
- 2020Deep Graph Matching and Searching for Semantic Code Retrievalcited by 20
- 2021On the Evaluation of Commit Message Generation Models: An Experimental Studycited by 20
- 2017Query Expansion Based on Crowd Knowledge for Code Searchcited by 18
- 2020Leveraging Code Generation to Improve Code Retrieval and Summarization via Dual Learningcited by 16
- 2020CRaDLe: Deep Code Retrieval Based on Semantic Dependency Learningcited by 12
- 2021Multimodal Representation for Neural Code Searchcited by 11
50 most cited of 52 All 52 (JSON)
Built on by
Citing papers per year: 2023: 1; 2024: 3; 2025: 11; 2026: 6.
21 papers.
Sort:
By area:
- 2024Agents in Software Engineering: Survey, Landscape, and Visioncited by 60
- 2025An Empirical Study of Retrieval-Augmented Code Generation: Challenges and Opportunitiescited by 17
- 2024Prompt-based Code Completion via Multi-Retrieval Augmented Generationcited by 16
- 2025An Empirical Study of Agent Developer Practices in AI Agent Frameworkscited by 14
- 2024Model Editing for LLMs4Code: How Far are We?cited by 8
- 2025Beyond Synthetic Benchmarks: Evaluating LLM Performance on Real-World Class-Level Code Generationcited by 8
- 2026AlignCoder: Aligning Retrieval with Target Intent for Repository-Level Code Completioncited by 7
- 2025A Deep Dive into Retrieval-Augmented Generation for Code Completion: Experience on WeChatcited by 5
- 2025SPENCER: Self-Adaptive Model Distillation for Efficient Code Retrievalcited by 5
- 2025AdaptiveLog: An Adaptive Log Analysis Framework with the Collaboration of Large and Small Language Modelcited by 4
- 2025On The Role of Pretrained Language Models in General-Purpose Text Embeddings: A Surveycited by 3
- 2026DRAINCODE: Stealthy Energy Consumption Attacks on Retrieval-Augmented Code Generation via Context Poisoningcited by 3
9 more
- 2025OASIS: Order-Augmented Strategy for Improved Code Searchcited by 2
- 2025Zero-Shot Cross-Domain Code Search without Fine-Tuningcited by 2
- 2025An Empirical Study of Knowledge Distillation for Code Understanding Taskscited by 2
- 2026PhoenixRepair: Rethinking Repair Strategy Exploration in Software Agentscited by 2
- 2023Contrastive Prompt Learning-based Code Search based on Interaction Matrixcited by 0
- 2025URECA: The Chain of Two Minimum Set Cover Problems exists behind Adaptation to Shifts in Semantic Code Searchcited by 0
- 2026XSearch: Explainable Code Search via Concept-to-Code Alignmentcited by 0
- 2026SynH-Rank: Quality-Aware Code Search via Diverse Data Synthesis and Hierarchical Ranking Trainingcited by 0
- 2026Synthetic Semantic Supervision for Contrastive Code Representation Learning in Small Transformers: An Empirical Studycited by 0
- 2026Synthetic Semantic Supervision for Contrastive Code Representation Learning in Small Transformers: An Empirical Study3 Sep 2026
- 2026PhoenixRepair: Rethinking Repair Strategy Exploration in Software Agents21 Jul 2026
- 2026SynH-Rank: Quality-Aware Code Search via Diverse Data Synthesis and Hierarchical Ranking Training19 Jul 2026
- 2026XSearch: Explainable Code Search via Concept-to-Code Alignment15 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
- 2025An Empirical Study of Agent Developer Practices in AI Agent Frameworks1 Dec 2025
- 2025Beyond Synthetic Benchmarks: Evaluating LLM Performance on Real-World Class-Level Code Generation30 Oct 2025
- 2025An Empirical Study of Knowledge Distillation for Code Understanding Tasks21 Aug 2025
- 2025SPENCER: Self-Adaptive Model Distillation for Efficient Code Retrieval1 Aug 2025
- 2025On The Role of Pretrained Language Models in General-Purpose Text Embeddings: A Survey28 Jul 2025
- 2025A Deep Dive into Retrieval-Augmented Generation for Code Completion: Experience on WeChat24 Jul 2025
9 more
- 2025Zero-Shot Cross-Domain Code Search without Fine-Tuning10 Apr 2025
- 2025OASIS: Order-Augmented Strategy for Improved Code Search11 Mar 2025
- 2025URECA: The Chain of Two Minimum Set Cover Problems exists behind Adaptation to Shifts in Semantic Code Search11 Feb 2025
- 2025An Empirical Study of Retrieval-Augmented Code Generation: Challenges and Opportunities23 Jan 2025
- 2025AdaptiveLog: An Adaptive Log Analysis Framework with the Collaboration of Large and Small Language Model19 Jan 2025
- 2024Model Editing for LLMs4Code: How Far are We?11 Nov 2024
- 2024Agents in Software Engineering: Survey, Landscape, and Vision13 Sep 2024
- 2024Prompt-based Code Completion via Multi-Retrieval Augmented Generation13 May 2024
- 2023Contrastive Prompt Learning-based Code Search based on Interaction Matrix10 Oct 2023
- 2025An Empirical Study of Retrieval-Augmented Code Generation: Challenges and Opportunitiescited by 17
- 2024Prompt-based Code Completion via Multi-Retrieval Augmented Generationcited by 16
- 2025A Deep Dive into Retrieval-Augmented Generation for Code Completion: Experience on WeChatcited by 5
- 2026DRAINCODE: Stealthy Energy Consumption Attacks on Retrieval-Augmented Code Generation via Context Poisoningcited by 3
- 2026DRAINCODE: Stealthy Energy Consumption Attacks on Retrieval-Augmented Code Generation via Context Poisoning28 Jan 2026
- 2025A Deep Dive into Retrieval-Augmented Generation for Code Completion: Experience on WeChat24 Jul 2025
- 2025An Empirical Study of Retrieval-Augmented Code Generation: Challenges and Opportunities23 Jan 2025
- 2024Prompt-based Code Completion via Multi-Retrieval Augmented Generation13 May 2024
- 2024Model Editing for LLMs4Code: How Far are We?cited by 8
- 2025Beyond Synthetic Benchmarks: Evaluating LLM Performance on Real-World Class-Level Code Generationcited by 8
- 2026AlignCoder: Aligning Retrieval with Target Intent for Repository-Level Code Completioncited by 7
- 2025SPENCER: Self-Adaptive Model Distillation for Efficient Code Retrievalcited by 5
- 2025AdaptiveLog: An Adaptive Log Analysis Framework with the Collaboration of Large and Small Language Modelcited by 4
- 2025On The Role of Pretrained Language Models in General-Purpose Text Embeddings: A Surveycited by 3
- 2025OASIS: Order-Augmented Strategy for Improved Code Searchcited by 2
- 2025Zero-Shot Cross-Domain Code Search without Fine-Tuningcited by 2
- 2025An Empirical Study of Knowledge Distillation for Code Understanding Taskscited by 2
- 2023Contrastive Prompt Learning-based Code Search based on Interaction Matrixcited by 0
- 2025URECA: The Chain of Two Minimum Set Cover Problems exists behind Adaptation to Shifts in Semantic Code Searchcited by 0
- 2026XSearch: Explainable Code Search via Concept-to-Code Alignmentcited by 0
12 most cited of 13 All 13 (JSON)
- 2026Synthetic Semantic Supervision for Contrastive Code Representation Learning in Small Transformers: An Empirical Study3 Sep 2026
- 2026XSearch: Explainable Code Search via Concept-to-Code Alignment15 May 2026
- 2026AlignCoder: Aligning Retrieval with Target Intent for Repository-Level Code Completion27 Jan 2026
- 2025Beyond Synthetic Benchmarks: Evaluating LLM Performance on Real-World Class-Level Code Generation30 Oct 2025
- 2025An Empirical Study of Knowledge Distillation for Code Understanding Tasks21 Aug 2025
- 2025SPENCER: Self-Adaptive Model Distillation for Efficient Code Retrieval1 Aug 2025
- 2025On The Role of Pretrained Language Models in General-Purpose Text Embeddings: A Survey28 Jul 2025
- 2025Zero-Shot Cross-Domain Code Search without Fine-Tuning10 Apr 2025
- 2025OASIS: Order-Augmented Strategy for Improved Code Search11 Mar 2025
- 2025URECA: The Chain of Two Minimum Set Cover Problems exists behind Adaptation to Shifts in Semantic Code Search11 Feb 2025
- 2025AdaptiveLog: An Adaptive Log Analysis Framework with the Collaboration of Large and Small Language Model19 Jan 2025
- 2024Model Editing for LLMs4Code: How Far are We?11 Nov 2024
12 newest of 13 All 13 (JSON)