mlsanityData to 7 Oct 2026

CoCoSoDa: Effective Contrastive Learning for Code Search

arXiv 2204.03293 ↗First posted 7 Apr 2022cs.SE cs.AI cs.LGcited by 21

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

  1. 2017Attention Is All You Needcited by 59,932
  2. 2020Language Models are Few-Shot Learnerscited by 32,199
  3. 2019RoBERTa: A Robustly Optimized BERT Pretraining Approachcited by 13,266
  4. 2020A Simple Framework for Contrastive Learning of Visual Representationscited by 11,979
  5. 2018Representation Learning with Contrastive Predictive Codingcited by 7,662
  6. 2019Momentum Contrast for Unsupervised Visual Representation Learningcited by 7,482
  7. 2015Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shiftcited by 6,979
  8. 2014Learning Phrase Representations using RNN Encoder-Decoder for Statistical Machine Translationcited by 4,016
  9. 2021SimCSE: Simple Contrastive Learning of Sentence Embeddingscited by 2,168
  10. 2018Unsupervised Feature Learning via Non-Parametric Instance-level Discriminationcited by 1,838
  11. 2017Improved Regularization of Convolutional Neural Networks with Cutoutcited by 1,623
  12. 2018Unsupervised Representation Learning by Predicting Image Rotationscited by 1,586
38 more
  1. 2020Understanding Contrastive Representation Learning through Alignment and Uniformity on the Hyperspherecited by 1,393
  2. 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,286
  3. 2014Convolutional Neural Networks for Sentence Classificationcited by 1,124
  4. 2021CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generationcited by 890
  5. 2019CodeSearchNet Challenge: Evaluating the State of Semantic Code Searchcited by 638
  6. 2020GraphCodeBERT: Pre-training Code Representations with Data Flowcited by 600
  7. 2020Understanding the Behaviour of Contrastive Losscited by 397
  8. 2021Unified Pre-training for Program Understanding and Generationcited by 361
  9. 2022UniXcoder: Unified Cross-Modal Pre-training for Code Representationcited by 355
  10. 2020On the Stability of Fine-tuning BERT: Misconceptions, Explanations, and Strong Baselinescited by 254
  11. 2019Representation Degeneration Problem in Training Natural Language Generation Modelscited by 250
  12. 2020DeCLUTR: Deep Contrastive Learning for Unsupervised Textual Representationscited by 249
  13. 2017A Survey of Machine Learning for Big Code and Naturalnesscited by 220
  14. 2020CERT: Contrastive Self-supervised Learning for Language Understandingcited by 169
  15. 2021COCO-LM: Correcting and Contrasting Text Sequences for Language Model Pretrainingcited by 126
  16. 2019A Neural Model for Generating Natural Language Summaries of Program Subroutinescited by 76
  17. 2020Contrastive Code Representation Learningcited by 76
  18. 2021CoSQA: 20,000+ Web Queries for Code Search and Question Answeringcited by 74
  19. 2021SynCoBERT: Syntax-Guided Multi-Modal Contrastive Pre-Training for Code Representationcited by 63
  20. 2020Self-Supervised Contrastive Learning for Code Retrieval and Summarization via Semantic-Preserving Transformationscited by 49
  21. 2021On the Evaluation of Neural Code Summarizationcited by 47
  22. 2019When Deep Learning Met Code Searchcited by 45
  23. 2019Multi-Modal Attention Network Learning for Semantic Source Code Retrievalcited by 40
  24. 2020Fast and Memory-Efficient Neural Code Completioncited by 38
  25. 2022SPT-Code: Sequence-to-Sequence Pre-Training for Learning Source Code Representationscited by 35
  26. 2013Some Improvements on Deep Convolutional Neural Network Based Image Classificationcited by 34
  27. 2021CAST: Enhancing Code Summarization with Hierarchical Splitting and Reconstruction of Abstract Syntax Treescited by 31
  28. 2021Code Completion by Modeling Flattened Abstract Syntax Trees as Graphscited by 30
  29. 2022RACE: Retrieval-Augmented Commit Message Generationcited by 27
  30. 2021Project-Level Encoding for Neural Source Code Summarization of Subroutinescited by 24
  31. 2020Opportunities and Challenges in Code Search Toolscited by 22
  32. 2020A Multi-Perspective Architecture for Semantic Code Searchcited by 20
  33. 2020Deep Graph Matching and Searching for Semantic Code Retrievalcited by 20
  34. 2021On the Evaluation of Commit Message Generation Models: An Experimental Studycited by 20
  35. 2017Query Expansion Based on Crowd Knowledge for Code Searchcited by 18
  36. 2020Leveraging Code Generation to Improve Code Retrieval and Summarization via Dual Learningcited by 16
  37. 2020CRaDLe: Deep Code Retrieval Based on Semantic Dependency Learningcited by 12
  38. 2021Multimodal Representation for Neural Code Searchcited by 11

50 most cited of 52 All 52 (JSON)

Built on by

Cited by year (2026 to 7 Oct)

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

21 papers.

Sort:

By area:

  1. 2024Agents in Software Engineering: Survey, Landscape, and Visioncited by 60
  2. 2025An Empirical Study of Retrieval-Augmented Code Generation: Challenges and Opportunitiescited by 17
  3. 2024Prompt-based Code Completion via Multi-Retrieval Augmented Generationcited by 16
  4. 2025An Empirical Study of Agent Developer Practices in AI Agent Frameworkscited by 14
  5. 2024Model Editing for LLMs4Code: How Far are We?cited by 8
  6. 2025Beyond Synthetic Benchmarks: Evaluating LLM Performance on Real-World Class-Level Code Generationcited by 8
  7. 2026AlignCoder: Aligning Retrieval with Target Intent for Repository-Level Code Completioncited by 7
  8. 2025A Deep Dive into Retrieval-Augmented Generation for Code Completion: Experience on WeChatcited by 5
  9. 2025SPENCER: Self-Adaptive Model Distillation for Efficient Code Retrievalcited by 5
  10. 2025AdaptiveLog: An Adaptive Log Analysis Framework with the Collaboration of Large and Small Language Modelcited by 4
  11. 2025On The Role of Pretrained Language Models in General-Purpose Text Embeddings: A Surveycited by 3
  12. 2026DRAINCODE: Stealthy Energy Consumption Attacks on Retrieval-Augmented Code Generation via Context Poisoningcited by 3
9 more
  1. 2025OASIS: Order-Augmented Strategy for Improved Code Searchcited by 2
  2. 2025Zero-Shot Cross-Domain Code Search without Fine-Tuningcited by 2
  3. 2025An Empirical Study of Knowledge Distillation for Code Understanding Taskscited by 2
  4. 2026PhoenixRepair: Rethinking Repair Strategy Exploration in Software Agentscited by 2
  5. 2023Contrastive Prompt Learning-based Code Search based on Interaction Matrixcited by 0
  6. 2025URECA: The Chain of Two Minimum Set Cover Problems exists behind Adaptation to Shifts in Semantic Code Searchcited by 0
  7. 2026XSearch: Explainable Code Search via Concept-to-Code Alignmentcited by 0
  8. 2026SynH-Rank: Quality-Aware Code Search via Diverse Data Synthesis and Hierarchical Ranking Trainingcited by 0
  9. 2026Synthetic Semantic Supervision for Contrastive Code Representation Learning in Small Transformers: An Empirical Studycited by 0