HELoC: Hierarchical Contrastive Learning of Source Code Representation

Xiao Wang, Qiong Wu, Hongyu Zhang, Chen Lyu, Xue Jiang +3 more
3/27/2022
cs.SE
gnncontrastive-ssl

Official code: Code-Rep/HELoC (6 stars, Python, last commit 2022-01-21).

Abstract

Abstract syntax trees (ASTs) play a crucial role in source code representation. However, due to the large number of nodes in an AST and the typically deep AST hierarchy, it is challenging to learn the hierarchical structure of an AST effectively.

Show full abstract

In this paper, we propose HELoC, a hierarchical contrastive learning model for source code representation. To effectively learn the AST hierarchy, we use contrastive learning to allow the network to predict the AST node level and learn the hierarchical relationships between nodes in a self-supervised manner, which makes the representation vectors of nodes with greater differences in AST levels farther apart in the embedding space. By using such vectors, the structural similarities between code snippets can be measured more precisely. In the learning process, a novel GNN (called Residual Self-attention Graph Neural Network, RSGNN) is designed, which enables HELoC to focus on embedding the local structure of an AST while capturing its overall structure. HELoC is self-supervised and can be applied to many source code related downstream tasks such as code classification, code clone detection, and code clustering after pre-training. Our extensive experiments demonstrate that HELoC outperforms the state-of-the-art source code representation models.

View on arXivView PDF

Code Implementations(1)

Code-Rep/HELoCOfficial100%
66Python, TclDec 28, 20214 years ago

Similar Papers

Cite this paper

@article{wang2022heloc,
  title  = {HELoC: Hierarchical Contrastive Learning of Source Code Representation},
  author = {Xiao Wang and Qiong Wu and Hongyu Zhang and Chen Lyu and Xue Jiang and Zhuoran Zheng and Lei Lyu and Songlin Hu},
  year   = {2022},
  eprint = {2203.14285},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2203.14285}
}

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/2203.14285.svg)](https://codeofpaper.com/paper/2203.14285)

Discussion