Cited by 129Software Engineering ResearchTopic ModelingTeaching and Learning Programming

Contrastive Code Representation Learning

Open access
Jain, Paras, Jain, Ajay, Zhang, Tianjun, Abbeel, Pieter, Gonzalez, Joseph, Stoica, Ion·2021·Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing

Abstract

Recent work learns contextual representations of source code by reconstructing tokens from their context.For downstream semantic understanding tasks like code clone detection, these representations should ideally capture program functionality.However, we show that the popular reconstruction-based RoBERTa model is sensitive to source code edits, even when the edits preserve semantics.We propose Con-traCode: a contrastive pre-training task that learns code functionality, not form.Con-traCode 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 pretraining outperforms RoBERTa on an adversarial code clone detection benchmark by 39% AUROC.Surprisingly, improved adversarial robustness translates to better accuracy over natural code; ContraCode improves summarization and TypeScript type inference accuracy by 2 to 13 percentage points over competitive baselines.All source is available at https://github.com/parasj/contracode.

Integrity signals

Registry

Crossref · 10.18653/v1/2021.emnlp-main.482

Cites

10 of 10 references verified0 citation errors · 0 not checkable

Statistics

Recomputing p-values needs the paper’s full text.

Claims the paper makes

We couldn’t retrieve this paper’s full text, so its claims and self-check weren’t run. The registry and citation checks still apply.

Claims other papers make about this one

Each is checked against this paper’s own text: does it say what the citing paper says it does?

  • Existing techniques for optimizing LLM behavior on code snippets are mainly driven by machine learning approaches and lack explanations of LLM preference or predictable results before actual generation.

    “These optimization techniques are mainly driven by machine learning approaches, lacking explanations on preference of LLM or predictable results before the actual generation.”

    From What Makes In-Context Examples Effective for Code Generation? (2026) · cites this paper as Jain et al. [34]

Cites

Flagged first, then by citations

Cited by

Sorted by citations

Authors
Jain, P., Jain, A., Zhang, T., Abbeel, P., Gonzalez, J., & Stoica, I.
Affiliations
University of California, Berkeley (US)
Venue
Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing
Published
2021
Pages
5954-5971
OpenAlex
W3040955294
Cited by
129
References
10
Citations by year
2026: 6 · 2025: 24 · 2024: 25 · 2023: 34 · 2022: 26 · 2021: 12 · 2020: 2
FWCI
20.11
Type
conference paper
Language
en
Open access
Licence
cc-by
Locations
  • Conference on Empirical Methods in Natural Language Processing (EMNLP) (publishedVersion, cc-by)
  • arXiv (Cornell University) (submittedVersion)
  • arXiv (Cornell University)
Funders
  • National Science Foundation (1730628, 1752814)
  • Nvidia
  • Amazon Web Services
  • VMware
  • Futurewei Technologies
  • Ant Financial Services Group
  • Directorate for Computer and Information Science and Engineering
  • Office of Naval Research
Topics
  • Physical Sciences › Computer Science › Information Systems › Software Engineering Research
  • Physical Sciences › Computer Science › Artificial Intelligence › Topic Modeling
  • Physical Sciences › Computer Science › Computer Science Applications › Teaching and Learning Programming
Keywords
contrastive learning, code representation learning, code clone detection, adversarial robustness, source-to-source compiler, data augmentation, code summarization

About these checks

Registry, retraction, Cites and statistics results are computed, not judged, with one exception: a printed reference that no index lists is read once by a model before it counts as a citation error. Claims are extracted by a model and kept only when their quote appears verbatim in the text; each cited source is then checked, with a model’s help, for whether it says what the claim relies on. Those verdicts can be wrong — read the claim’s quote and the cited source before relying on one.

Statistics and arithmetic are recomputed, not judged.

Confidence bands are shown only for fields calibrated on our annotated test set. None is calibrated yet, so no band is shown.

What counts as a claim ›How we measure confidence ›How we check this ›

Are you an author, or do you see a problem with this page? Request a review