GraphCodeBERT
Pre-trained Transformer encoder for source code that reads a program's data flow alongside its tokens.
Language · 323 operations Checked
Click or tap a spot to read it up close. Scroll or drag inside the diagram to move through it. Zoom with + and − or Ctrl and scroll. Press 0 for the whole graph. Swipe inside the diagram to move through it. Use + and − to zoom.
At a glance
- Task
- Language
- Parameters
- 124.6M
- Operations
- 323
- Framework
- PyTorch
- Recurrent
- No
- Published
- ICLR 2021
- Cited by
- 478 (as of 29 October 2026)
- Authors
- Daya Guo, Shuo Ren, Shuai Lu and others
- Source
- GitHub: microsoft/CodeBERT
- License
- MIT
- Checked
- Passed: the trace was replayed operation by operation and matched the model's own output for this input.
Files
The file opened in a new tab. Use your browser's Save command there to keep it.
The diagram is a drawing of a TorchLens trace of the source code. It contains no code or weights.
Details
- Stable ID
- m17130
- Graph hash
- 59f0944b3d9a00342000e69226c213b596a5761c400ccf63b85b5aafac1a22c4
- Skeleton hash
- 1486024734e0631147eeff00088b5f9e975576593b096a3379a261ea02b62f6b
- Architecture hash
- ca8d88f2769e396e1f5b74b9d58cb7f139d860142bcfe17809ba9f6465224b11
- Diagram SHA-256
- 1e9359d5840d75aa116c2c8313669233aaf4a6bcd629e2494722f166391d0d57
- TorchLens version
- 2.36.0
- Renderer
- graphviz 2.43.0+pyvips 3.2.0+libvips 8.18.7+render-opts@06c1f0d3
- Check
- Forward pass replayed in PyTorch
What it is
GraphCodeBERT is a pre-trained model for programming language that considers the structure of code. The paper's starting point is that earlier pre-trained models treated a code snippet as a sequence of tokens and ignored that structure. The structure it uses is data flow, a semantic-level view of code, chosen over the syntax-level abstract syntax tree (AST). Data flow encodes where the value of each variable comes from.
The network is a 12-layer Transformer with 768-dimensional hidden states and 12 attention heads. Data flow enters through a graph-guided masked attention function. Pre-training keeps masked language modeling and adds two structure-aware tasks. One predicts code structure edges and the other aligns representations between source code and code structure.
The model is trained on the CodeSearchNet dataset, which includes 2.3M functions with document pairs for six programming languages. To speed up training, the authors initialized it with the released parameters of CodeBERT. The paper evaluates on four tasks: code search, clone detection, code translation and code refinement. It also reports that the model prefers structure-level attentions over token-level attentions in code search.
Key idea. GraphCodeBERT brings data flow into pre-training for code, with two new structure-aware tasks that learn representations from source code and data flow.
- GraphCodeBERT
- graphcodebert-base
- code pre-training
- data flow
- code search
- clone detection
- code translation
- code refinement
- code embeddings
- programming language model
AI-written summary, based on the paper and checked automatically against it; not reviewed by a person. Corrections welcome.
Cite the paper
@misc{guo2021graphcodebertpretrainingcoderepresentations,
title={GraphCodeBERT: Pre-training Code Representations with Data Flow},
author={Daya Guo and Shuo Ren and Shuai Lu and Zhangyin Feng and Duyu Tang and Shujie Liu and Long Zhou and Nan Duan and Alexey Svyatkovskiy and Shengyu Fu and Michele Tufano and Shao Kun Deng and Colin Clement and Dawn Drain and Neel Sundaresan and Jian Yin and Daxin Jiang and Ming Zhou},
year={2021},
eprint={2009.08366},
archivePrefix={arXiv},
primaryClass={cs.SE},
url={https://arxiv.org/abs/2009.08366},
}