Contrastive Code Representation Learning
Not on the map. Why?
Abstract (arXiv)
Recent work learns contextual representations of source code by reconstructing tokens from their context. For downstream semantic understanding tasks like summarizing code in English, these representations should ideally capture program functionality. However, we show that the popular reconstruction-based BERT model is sensitive to source code edits, even when the edits preserve semantics. We propose ContraCode: a contrastive pre-training task that learns code functionality, not form. ContraCode pre-trains a neural network to identify functionally similar variants of a program among many non-equivalent distractors. We scalably generate these variants using an automated source-to-source compiler as a form of data augmentation. Contrastive pre-training improves JavaScript summarization and TypeScript type inference accuracy by 2% to 13%. We also propose a new zero-shot JavaScript code clone detection dataset, showing that ContraCode is both more robust and semantically meaningful. On it, we outperform RoBERTa by 39% AUROC in an adversarial setting and up to 5% on natural code.
Key facts. Cited by 76 papers in the map (data through 7 Oct 2026). First posted on arXiv 9 Jul 2020.
Builds on
No reference list yet.
Built on by
Citing papers per year: 2021: 10; 2022: 22; 2023: 15; 2024: 12; 2025: 9; 2026: 8.
76 papers.
Sort:
By area:
- 2021Evaluating Large Language Models Trained on Codecited by 8,053
- 2023Code Llama: Open Foundation Models for Codecited by 2,105
- 2022Text and Code Embeddings by Contrastive Pre-Trainingcited by 358
- 2022ReACC: A Retrieval-Augmented Code Completion Frameworkcited by 117
- 2021DOBF: A Deobfuscation Pre-Training Objective for Programming Languagescited by 68
- 2021SynCoBERT: Syntax-Guided Multi-Modal Contrastive Pre-Training for Code Representationcited by 63
- 2022PanGu-Coder: Program Synthesis with Function-Level Language Modelingcited by 47
- 2021Code Structure Guided Transformer for Source Code Summarizationcited by 29
- 2021Bridging Pre-trained Models and Downstream Tasks for Source Code Understandingcited by 27
- 2021How could Neural Networks understand Programs?cited by 26
- 2024Code Representation Learning At Scalecited by 26
- 2023Deep Learning for Code Intelligence: Survey, Benchmark and Toolkitcited by 22
38 more
- 2022CodeRetriever: Unimodal and Bimodal Contrastive Learning for Code Searchcited by 21
- 2022CoCoSoDa: Effective Contrastive Learning for Code Searchcited by 21
- 2024IRCoder: Intermediate Representations Make Language Models Robust Multilingual Code Generatorscited by 21
- 2022Deep Learning Meets Software Engineering: A Survey on Pre-Trained Models of Source Codecited by 20
- 2021Towards Learning (Dis)-Similarity of Source Code from Program Contrastscited by 17
- 2022Assemble Foundation Models for Automatic Code Summarizationcited by 17
- 2024Prompt-based Code Completion via Multi-Retrieval Augmented Generationcited by 16
- 2022On Distribution Shift in Learning-based Bug Detectorscited by 15
- 2022CODE-MVP: Learning to Represent Source Code from Multiple Views with Contrastive Pre-Trainingcited by 15
- 2022A Survey on Pretrained Language Models for Neural Code Intelligencecited by 13
- 2023Do Large Language Models Pay Similar Attention Like Human Programmers When Generating Code?cited by 13
- 2024ProCQA: A Large-scale Community-based Programming Question Answering Dataset for Code Searchcited by 12
- 2021VarCLR: Variable Semantic Representation Pre-training via Contrastive Learningcited by 11
- 2023Towards Personalized Review Summarization by Modeling Historical Reviews from Customer and Product Separatelycited by 9
- 2021ProtoTransformer: A Meta-Learning Approach to Providing Student Feedbackcited by 8
- 2022Exploring Representation-Level Augmentation for Code Searchcited by 8
- 2022Poison Attack and Defense on Deep Source Code Processing Modelscited by 8
- 2022Soft-Labeled Contrastive Pre-training for Function-level Code Representationcited by 7
- 2022CommitBART: A Large Pre-trained Model for GitHub Commitscited by 6
- 2022Pre-Training Representations of Binary Code Using Contrastive Learningcited by 6
- 2023An Unbiased Transformer Source Code Learning with Semantic Vulnerability Graphcited by 5
- 2025The Code Barrier: What LLMs Actually Understand?cited by 5
- 2025SPENCER: Self-Adaptive Model Distillation for Efficient Code Retrievalcited by 5
- 2026CROP: Task Relevance via Counterfactuals for Selective On-Policy Distillationcited by 5
- 2023TransformCode: A Contrastive Learning Framework for Code Embedding via Subtree Transformationcited by 4
- 2024A Study on Training and Developing Large Language Models for Behavior Tree Generationcited by 4
- 2024CodeFort: Robust Training for Code Generation Modelscited by 4
- 2025ObscuraCoder: Powering Efficient Code LM Pre-Training Via Obfuscation Groundingcited by 4
- 2021Unsupervised Feature Learning for Manipulation with Contrastive Domain Randomizationcited by 3
- 2022NS3: Neuro-Symbolic Semantic Code Searchcited by 3
- 2022Evaluation of Contrastive Learning with Various Code Representations for Code Clone Detectioncited by 3
- 2022Finding Reusable Machine Learning Components to Build Programming Language Processing Pipelinescited by 3
- 2023Neural Machine Translation for Code Generationcited by 3
- 2023Towards Understanding What Code Language Models Learnedcited by 3
- 2023ZC3: Zero-Shot Cross-Language Code Clone Detectioncited by 3
- 2024Assessing the Latent Automated Program Repair Capabilities of Large Language Models using Round-Trip Translationcited by 3
- 2024Uncertainty Awareness of Large Language Models Under Code Distribution Shifts: A Benchmark Studycited by 3
- 2024BLens: Contrastive Captioning of Binary Functions using Ensemble Embeddingcited by 3
50 most cited of 76 All 76 (JSON)
- 2026Reformulation-Contrastive Learning for Mixed Integer Programs30 Sep 2026
- 2026Synthetic Semantic Supervision for Contrastive Code Representation Learning in Small Transformers: An Empirical Study3 Sep 2026
- 2026ExecRetrieval: Measuring the Functional-Correctness Gap in Code-Embedding Retrieval1 Sep 2026
- 2026A Jagged Frontier: Evaluating Robustness of Code Agents to Semantics-Preserving Transformations18 Aug 2026
- 2026Invariant Pretraining for Robust Code Representations15 Aug 2026
- 2026CROP: Task Relevance via Counterfactuals for Selective On-Policy Distillation13 Aug 2026
- 2026On the Robustness of LLMs' Internal Representation of Code Correctness8 Aug 2026
- 2026RepBench: Compiling Benchmarks into Capability Representations for Large Language Models30 Jul 2026
- 2025MATCH: Task-Driven Code Evaluation through Contrastive Learning27 Oct 2025
- 2025Do Code Semantics Help? A Comprehensive Study on Execution Trace-Based Information for Code Large Language Models15 Sep 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
38 more
- 2025AlgoSimBench: Identifying Algorithmically Similar Problems for Competitive Programming21 Jul 2025
- 2025A Benchmark Dataset for Graph Regression with Homogeneous and Multi-Relational Variants29 May 2025
- 2025The Code Barrier: What LLMs Actually Understand?14 Apr 2025
- 2025Semantic-Preserving Transformations as Mutation Operators: A Study on Their Effectiveness in Defect Detection30 Mar 2025
- 2025ObscuraCoder: Powering Efficient Code LM Pre-Training Via Obfuscation Grounding27 Mar 2025
- 2024CodeCipher: Learning to Obfuscate Source Code Against LLMs8 Oct 2024
- 2024BLens: Contrastive Captioning of Binary Functions using Ensemble Embedding12 Sep 2024
- 2024Prompt-based Code Completion via Multi-Retrieval Augmented Generation13 May 2024
- 2024CodeFort: Robust Training for Code Generation Models11 Apr 2024
- 2024ProCQA: A Large-scale Community-based Programming Question Answering Dataset for Code Search25 Mar 2024
- 2024IRCoder: Intermediate Representations Make Language Models Robust Multilingual Code Generators6 Mar 2024
- 2024Beyond Self-learned Attention: Mitigating Attention Bias in Transformer-based Models Using Attention Guidance26 Feb 2024
- 2024Code Representation Learning At Scale2 Feb 2024
- 2024A Study on Training and Developing Large Language Models for Behavior Tree Generation16 Jan 2024
- 2024Assessing the Latent Automated Program Repair Capabilities of Large Language Models using Round-Trip Translation15 Jan 2024
- 2024Uncertainty Awareness of Large Language Models Under Code Distribution Shifts: A Benchmark Study12 Jan 2024
- 2024Enhancing Source Code Classification Effectiveness via Prompt Learning Incorporating Knowledge Features10 Jan 2024
- 2023Deep Learning for Code Intelligence: Survey, Benchmark and Toolkit30 Dec 2023
- 2023AdaCCD: Adaptive Semantic Contrasts Discovery Based Cross Lingual Adaptation for Code Clone Detection13 Nov 2023
- 2023TransformCode: A Contrastive Learning Framework for Code Embedding via Subtree Transformation10 Nov 2023
- 2023Language Agnostic Code Embeddings25 Oct 2023
- 2023ZC3: Zero-Shot Cross-Language Code Clone Detection26 Aug 2023
- 2023Code Llama: Open Foundation Models for Code24 Aug 2023
- 2023Contrastive Learning for API Aspect Analysis31 Jul 2023
- 2023An Exploratory Literature Study on Sharing and Energy Use of Language Models for Source Code5 Jul 2023
- 2023Towards Understanding What Code Language Models Learned20 Jun 2023
- 2023Do Large Language Models Pay Similar Attention Like Human Programmers When Generating Code?2 Jun 2023
- 2023Coarse-Tuning Models of Code with Reinforcement Learning Feedback25 May 2023
- 2023Neural Machine Translation for Code Generation22 May 2023
- 2023Neuro-symbolic Zero-Shot Code Cloning with Cross-Language Intermediate Representation26 Apr 2023
- 2023An Unbiased Transformer Source Code Learning with Semantic Vulnerability Graph17 Apr 2023
- 2023Towards Personalized Review Summarization by Modeling Historical Reviews from Customer and Product Separately27 Jan 2023
- 2022A Survey on Pretrained Language Models for Neural Code Intelligence20 Dec 2022
- 2022CLAWSAT: Towards Both Robust and Accurate Code Models21 Nov 2022
- 2022Poison Attack and Defense on Deep Source Code Processing Models31 Oct 2022
- 2022Exploring Representation-Level Augmentation for Code Search21 Oct 2022
- 2022Soft-Labeled Contrastive Pre-training for Function-level Code Representation18 Oct 2022
- 2022Pre-Training Representations of Binary Code Using Contrastive Learning11 Oct 2022
50 newest of 76 All 76 (JSON)
- 2021Evaluating Large Language Models Trained on Codecited by 8,053
- 2022Text and Code Embeddings by Contrastive Pre-Trainingcited by 358
- 2021DOBF: A Deobfuscation Pre-Training Objective for Programming Languagescited by 68
- 2021SynCoBERT: Syntax-Guided Multi-Modal Contrastive Pre-Training for Code Representationcited by 63
- 2022PanGu-Coder: Program Synthesis with Function-Level Language Modelingcited by 47
- 2021Code Structure Guided Transformer for Source Code Summarizationcited by 29
- 2021Bridging Pre-trained Models and Downstream Tasks for Source Code Understandingcited by 27
- 2021How could Neural Networks understand Programs?cited by 26
- 2024Code Representation Learning At Scalecited by 26
- 2023Deep Learning for Code Intelligence: Survey, Benchmark and Toolkitcited by 22
- 2022CodeRetriever: Unimodal and Bimodal Contrastive Learning for Code Searchcited by 21
- 2022CoCoSoDa: Effective Contrastive Learning for Code Searchcited by 21
12 most cited of 69 All 69 (JSON)
- 2026Reformulation-Contrastive Learning for Mixed Integer Programs30 Sep 2026
- 2026Synthetic Semantic Supervision for Contrastive Code Representation Learning in Small Transformers: An Empirical Study3 Sep 2026
- 2026Invariant Pretraining for Robust Code Representations15 Aug 2026
- 2026CROP: Task Relevance via Counterfactuals for Selective On-Policy Distillation13 Aug 2026
- 2026On the Robustness of LLMs' Internal Representation of Code Correctness8 Aug 2026
- 2026RepBench: Compiling Benchmarks into Capability Representations for Large Language Models30 Jul 2026
- 2025MATCH: Task-Driven Code Evaluation through Contrastive Learning27 Oct 2025
- 2025Do Code Semantics Help? A Comprehensive Study on Execution Trace-Based Information for Code Large Language Models15 Sep 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 Benchmark Dataset for Graph Regression with Homogeneous and Multi-Relational Variants29 May 2025
- 2025The Code Barrier: What LLMs Actually Understand?14 Apr 2025
12 newest of 69 All 69 (JSON)