CoCoSoDa: Effective Contrastive Learning for Code Search

Type: Article

Publication Date: 2023-05-01

Citations: 18

DOI: https://doi.org/10.1109/icse48619.2023.00185

Download PDF

Abstract

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 18 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.

Locations

  • arXiv (Cornell University) - View - PDF

Similar Works

Action Title Year Authors
+ CoCoSoDa: Effective Contrastive Learning for Code Search 2022 Ensheng Shi
Wenchao Gub
Yanlin Wang
Lun Du
Hongyu Zhang
Han Shi
Dongmei Zhang
Hongbin Sun
+ CodeRetriever: Unimodal and Bimodal Contrastive Learning for Code Search 2022 Xiaonan Li
Yeyun Gong
Yelong Shen
Xipeng Qiu
Hang Zhang
Bolun Yao
Weizhen Qi
Daxin Jiang
Weizhu Chen
Nan Duan
+ Contrastive Prompt Learning-based Code Search based on Interaction Matrix 2023 Yubo Zhang
Yanfang Liu
Xinxin Fan
Yunfeng Lu
+ Exploring Representation-Level Augmentation for Code Search 2022 Li HaoChen
Chunyan Miao
Cyril Leung
Yanxian Huang
Yuan Huang
Hongyu Zhang
Yanlin Wang
+ Rethinking Negative Pairs in Code Search 2023 Haochen Li
Xin Zhou
Luu Anh Tuan
Chunyan Miao
+ PDF Chat Exploring Representation-level Augmentation for Code Search 2022 Li HaoChen
Chunyan Miao
Cyril Leung
Yanxian Huang
Yuan Huang
Hongyu Zhang
Yanlin Wang
+ Learning Deep Semantic Model for Code Search using CodeSearchNet Corpus 2022 Chen Wu
Ming Yan
+ COSEA: Convolutional Code Search with Layer-wise Attention 2020 Hao Wang
Jia Zhang
Yingce Xia
Jiang Bian
Chao Zhang
Tie‐Yan Liu
+ PDF Chat Rethinking Negative Pairs in Code Search 2023 Haochen Li
Xin Zhou
Anh Luu
Chunyan Miao
+ On Contrastive Learning of Semantic Similarity forCode to Code Search 2023 Anthony Saieva
Saikat Chakraborty
Gail E. Kaiser
+ PDF Chat You Augment Me: Exploring ChatGPT-based Data Augmentation for Semantic Code Search 2024 Yanlin Wang
Lianghong Guo
Ensheng Shi
Wenqing Chen
Jiachi Chen
Wanjun Zhong
Menghan Wang
Hui Li
Hongyu Zhang
Ziyu Lyu
+ PDF Chat You Augment Me: Exploring ChatGPT-based Data Augmentation for Semantic Code Search 2023 Yanlin Wang
Lianghong Guo
Ensheng Shi
Wenqing Chen
Jiachi Chen
Wanjun Zhong
Menghan Wang
Hui Li
Hongyu Zhang
Ziyu Lyu
+ Cascaded Fast and Slow Models for Efficient Semantic Code Search 2021 Akhilesh Gotmare
Junnan Li
Shafiq Joty
Steven C. H. Hoi
+ Survey of Code Search Based on Deep Learning 2023 Yutao Xie
Jiayi Lin
Hande Dong
Lei Zhang
Zhonghai Wu
+ Neural Code Search Evaluation Dataset 2019 Hongyu Li
Seohyun Kim
Satish Chandra
+ AugmentedCode: Examining the Effects of Natural Language Resources in Code Retrieval Models 2021 Mehdi Bahrami
N. C. Shrikanth
Yuji Mizobuchi
Lei Liu
Masahiro Fukuyori
Weipeng Chen
Kazuki Munakata
+ BERT2Code: Can Pretrained Language Models be Leveraged for Code Search? 2021 Abdullah Al Ishtiaq
Masum Hasan
Md. Mahim Anjum Haque
Kazi Sajeed Mehrab
Tanveer Muttaqueen
Tahmid Hasan
Anindya Iqbal
Rifat Shahriyar
+ Neural Code Search Revisited: Enhancing Code Snippet Retrieval through Natural Language Intent 2020 Geert Heyman
Tom Van Cutsem
+ PSCS: A Path-based Neural Model for Semantic Code Search. 2020 Zhensu Sun
Yan Liu
Chen Yang
Qian Yu
+ PSCS: A Path-based Neural Model for Semantic Code Search 2020 Zhensu Sun
Yan Liu
Yang Chen
Qian Yu