Soft-Labeled Contrastive Pre-training for Function-level Code Representation

Xiaonan Li, Daya Guo, Yeyun Gong, Yun Lin, Yelong Shen +4 more
10/18/2022
cs.CLcs.PLcs.SE
contrastive-ssl

Official code: microsoft/AR2 (72 stars, Python, MIT, last commit 2022-06-16).

Abstract

Code contrastive pre-training has recently achieved significant progress on code-related tasks. In this paper, we present \textbf{SCodeR}, a \textbf{S}oft-labeled contrastive pre-training framework with two positive sample construction methods to learn functional-level \textbf{Code} \textbf{R}epresentation.

Show full abstract

Considering the relevance between codes in a large-scale code corpus, the soft-labeled contrastive pre-training can obtain fine-grained soft-labels through an iterative adversarial manner and use them to learn better code representation. The positive sample construction is another key for contrastive pre-training. Previous works use transformation-based methods like variable renaming to generate semantically equal positive codes. However, they usually result in the generated code with a highly similar surface form, and thus mislead the model to focus on superficial code structure instead of code semantics. To encourage SCodeR to capture semantic information from the code, we utilize code comments and abstract syntax sub-trees of the code to build positive samples. We conduct experiments on four code-related tasks over seven datasets. Extensive experimental results show that SCodeR achieves new state-of-the-art performance on all of them, which illustrates the effectiveness of the proposed pre-training method.

View on arXivView PDF

Code Implementations(1)

microsoft/AR2Official100%
MIT
7210PythonDec 3, 20214 years agoMIT

Similar Papers

Cite this paper

@article{li2022softlabeled,
  title  = {Soft-Labeled Contrastive Pre-training for Function-level Code Representation},
  author = {Xiaonan Li and Daya Guo and Yeyun Gong and Yun Lin and Yelong Shen and Xipeng Qiu and Daxin Jiang and Weizhu Chen and Nan Duan},
  year   = {2022},
  eprint = {2210.09597},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2210.09597}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2210.09597.svg)](https://codeofpaper.com/paper/2210.09597)

Discussion