Invariant Pretraining for Robust Code Representations
Not on the map. Why?
Abstract (arXiv)
Encoder-based code representation models remain widely deployed for discriminative tasks such as clone detection and code classification, where their small size and low inference cost are decisive. Their robustness, however, is fragile: under invariant programs, semantically equivalent code written in different syntactic forms, learned representations degrade substantially even though program behavior is unchanged. We present an empirical study of this robustness gap across four encoder baselines, two downstream tasks, and four datasets, together with a minimal code-only continued pretraining recipe that closes much of it. Our method, invariant pretraining (InvPT), applies semantic-preserving transformations to the corpus and combines masked language modeling with multi-positive supervised contrastive learning that treats all augmentations of the same source function as positives, mixing self-contrast pairs (same code, different masks) with invariant-contrast pairs (transformed code) for positives of varying difficulty. Unlike prior contrastive code encoders, InvPT does not require paired natural-language data. Across our evaluation, InvPT improves robustness on transformed test sets by up to 11 percentage points on clone detection and 19 on code classification while matching or improving standard accuracy, and our ablations isolate multi-positive invariant contrast as the main source of the gains. Our aim is not a new objective but a careful measurement of where encoder robustness breaks and how far a simple, code-only recipe can recover it.
Key facts. No citing papers in the map yet (data through 7 Oct 2026). Builds on 46 of its 59 references that are in the map. First posted on arXiv 15 Aug 2026.
Builds on
46 of 59 references.
References · 46
- 2018BERT: Pre-training of Deep Bidirectional Transformers for Language Understandingcited by 40,204
- 2020A Simple Framework for Contrastive Learning of Visual Representationscited by 11,979
- 2021Evaluating Large Language Models Trained on Codecited by 8,053
- 2018Representation Learning with Contrastive Predictive Codingcited by 7,662
- 2019Momentum Contrast for Unsupervised Visual Representation Learningcited by 7,482
- 2016Overcoming catastrophic forgetting in neural networkscited by 4,718
- 2020Supervised Contrastive Learningcited by 2,803
- 2021SimCSE: Simple Contrastive Learning of Sentence Embeddingscited by 2,168
- 2023Code Llama: Open Foundation Models for Codecited by 2,105
- 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,286
- 2025Qwen3 Embedding: Advancing Text Embedding and Reranking Through Foundation Modelscited by 1,175
- 2018The Secret Sharer: Evaluating and Testing Unintended Memorization in Neural Networkscited by 847
34 more
- 2021CodeXGLUE: A Machine Learning Benchmark Dataset for Code Understanding and Generationcited by 732
- 2019CodeSearchNet Challenge: Evaluating the State of Semantic Code Searchcited by 638
- 2020GraphCodeBERT: Pre-training Code Representations with Data Flowcited by 600
- 2024Smarter, Better, Faster, Longer: A Modern Bidirectional Encoder for Fast, Memory Efficient, and Long Context Finetuning and Inferencecited by 527
- 2022UniXcoder: Unified Cross-Modal Pre-training for Code Representationcited by 355
- 2023CodeT5+: Open Code Large Language Models for Code Understanding and Generationcited by 327
- 2020A Metric Learning Reality Checkcited by 317
- 2019Devign: Effective Vulnerability Identification by Learning Comprehensive Program Semantics via Graph Neural Networkscited by 266
- 2021CodeNet: A Large-Scale AI for Code Dataset for Learning a Diversity of Coding Taskscited by 199
- 2024Vulnerability Detection with Code Language Models: How Far Are We?cited by 133
- 2025EmbeddingGemma: Powerful and Lightweight Text Representationscited by 128
- 2020Contrastive Code Representation Learningcited by 76
- 2022Natural Attack for Pre-trained Models of Codecited by 72
- 2019Adversarial Examples for Models of Codecited by 61
- 2022NatGen: Generative pre-training by "Naturalizing" source codecited by 53
- 2020Self-Supervised Contrastive Learning for Code Retrieval and Summarization via Semantic-Preserving Transformationscited by 49
- 2024Why Warmup the Learning Rate? Underlying Mechanisms and Improvementscited by 45
- 2020Semantic Robustness of Models of Source Codecited by 43
- 2021Multilingual training for Software Engineeringcited by 43
- 2020On the Generalizability of Neural Program Models with respect to Semantic-Preserving Program Transformationscited by 41
- 2024CoRNStack: High-Quality Contrastive Data for Better Code Retrieval and Rerankingcited by 37
- 2020Adversarial Robustness for Codecited by 36
- 2021Bridging Pre-trained Models and Downstream Tasks for Source Code Understandingcited by 27
- 2023Prompt Fuzzing for Fuzz Driver Generationcited by 27
- 2023Understanding Programs by Exploiting (Fuzzing) Test Casescited by 13
- 2025Efficient Code Embeddings from Code Generation Modelscited by 12
- 2021VarCLR: Variable Semantic Representation Pre-training via Contrastive Learningcited by 11
- 2023Code Representation Pre-training with Complements from Program Executionscited by 8
- 2024Large Language Models Are Overparameterized Text Encoderscited by 6
- 2024UniTSyn: A Large-Scale Dataset Capable of Enhancing the Prowess of Large Language Models for Program Testingcited by 5
- 2024FuzzAug: Data Augmentation by Coverage-guided Fuzzing for Neural Test Generationcited by 3
- 2024Towards Better Code Understanding in Decoder-Only Models with Contrastive Learningcited by 3
- 2025How the Misuse of a Dataset Harmed Semantic Clone Detectioncited by 3
- 2025Making Large Language Models Efficient Dense Retrieverscited by 2
Built on by
Not cited yet.