Papers › GraphCodeBERT: Pre-training Code Representations with Data Flow

GraphCodeBERT: Pre-training Code Representations with Data Flow

17 Sep 2020ICLR 2021 1arXiv:2009.08366archive 2025-07-28

Daya Guo, Shuo Ren, Shuai Lu, Zhangyin Feng, Duyu Tang, Shujie Liu, Long Zhou, Nan Duan, Alexey Svyatkovskiy, Shengyu Fu, Michele Tufano, Shao Kun Deng, Colin Clement, Dawn Drain, Neel Sundaresan, Jian Yin, Daxin Jiang, Ming Zhou

Pre-trained models for programming language have achieved dramatic empirical improvements on a variety of code-related tasks such as code search, code completion, code summarization, etc. However, existing pre-trained models regard a code snippet as a sequence of tokens, while ignoring the inherent structure of code, which provides crucial code semantics and would enhance the code understanding process. We present GraphCodeBERT, a pre-trained model for programming language that considers the inherent structure of code. Instead of taking syntactic-level structure of code like abstract syntax tree (AST), we use data flow in the pre-training stage, which is a semantic-level structure of code that encodes the relation of "where-the-value-comes-from" between variables. Such a semantic-level structure is neat and does not bring an unnecessarily deep hierarchy of AST, the property of which makes the model more efficient. We develop GraphCodeBERT based on Transformer. In addition to using the task of masked language modeling, we introduce two structure-aware pre-training tasks. One is to predict code structure edges, and the other is to align representations between source code and code structure. We implement the model in an efficient way with a graph-guided masked attention function to incorporate the code structure. We evaluate our model on four tasks, including code search, clone detection, code translation, and code refinement. Results show that code structure and newly introduced pre-training tasks can improve GraphCodeBERT and achieves state-of-the-art performance on the four downstream tasks. We further show that the model prefers structure-level attentions over token-level attentions in the task of code search.

PaperPDFConference PDFCode

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

Code

microsoft/CodeBERT officialmentioned in paperpytorch report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

Not run by Syntology. Nothing on this page verifies that the listed code works.

Tasks

Clone DetectionCode CompletionCode SearchCode SummarizationCode TranslationLanguage ModelingLanguage ModellingMasked Language ModelingSource Code SummarizationType prediction

Results from the paper archive 2025-07-28

TaskDatasetModelMetricValueRank at snapshotLeaderboardReport
Code Search CodeSearchNet GraphCodeBERT Go 84.1 #4 of 6 Archive leaderboard report
Code Search CodeSearchNet GraphCodeBERT JS 71.1 #4 of 6 Archive leaderboard report
Code Search CodeSearchNet GraphCodeBERT Java 75.7 #4 of 6 Archive leaderboard report
Code Search CodeSearchNet GraphCodeBERT Overall 77.4 #4 of 6 Archive leaderboard report
Code Search CodeSearchNet GraphCodeBERT PHP 72.5 #4 of 6 Archive leaderboard report
Code Search CodeSearchNet GraphCodeBERT Python 87.9 #4 of 6 Archive leaderboard report
Code Search CodeSearchNet GraphCodeBERT Ruby 73.2 #4 of 6 Archive leaderboard report
Type prediction ManyTypes4TypeScript GraphCodeBERT Average Accuracy 62.51 #3 of 9 Archive leaderboard report
Type prediction ManyTypes4TypeScript GraphCodeBERT Average F1 60.57 #3 of 9 Archive leaderboard report
Type prediction ManyTypes4TypeScript GraphCodeBERT Average Precision 60.06 #3 of 9 Archive leaderboard report
Type prediction ManyTypes4TypeScript GraphCodeBERT Average Recall 61.08 #3 of 9 Archive leaderboard report

Ranks are positions in the archive's leaderboards as they stood at the 2025-07-28 snapshot. Results published since then are not among these rows, so a rank here is not a current standing.

Methods

Absolute Position EncodingsAdamAttentionBPEDense ConnectionsDropoutLabel SmoothingLayer NormalizationLinear LayerMulti-Head AttentionPosition-Wise Feed-Forward LayerResidual ConnectionSoftmaxTransformer

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections