CodeGrid: A Grid Representation of Code
Abdoul Kader Kaboré, Earl T. Barr, Jacques Klein, Tegawendé F. Bissyandé
Abstract
Code representation is a key step in the application of AI in software engineering. Generic NLP representations are e ective but do not exploit all the rich structure inherent to code. Recent work has focused on extracting abstract syntax trees (AST) and integrating their structural information into code representations. These AST-enhanced representations advanced the state of the art and accelerated new applications of AI to software engineering. ASTs, however, neglect important aspects of code structure, notably control and data ow, leaving some potentially relevant code signal unexploited. For example, purely image-based representations perform nearly as well as AST-based representations, despite the fact that they must learn to even recognize tokens, let alone their semantics. This result, from prior work, is strong evidence that these new code representations can still be improved; it also raises the question of just what signal image-based approaches are exploiting. We answer this question. We show that code is spatial and exploit this fact to propose CodeGrid, a new representation that embeds tokens into a grid that preserves code layout. Unlike some of the existing state of the art, CodeGrid is agnostic to the downstream task: whether that task is generation or classi cation, CodeGrid can complement the learning algorithm with spatial signal. For example, we show that CNNs, which are inherently spatially-aware models, can exploit CodeGrid outputs to e ectively tackle fundamental software engineering tasks, such as code classi cation, code clone detection and vulnerability detection. PixelCNN leverages CodeGrid's grid representations to achieve code completion. Through extensive experiments, we validate our spatial code hypothesis, quantifying model performance as we vary the degree to which the representation preserves the grid. To demonstrate its generality, we show that CodeGrid augments models, improving their performance on a range of tasks. On clone detection, CodeGrid improves ASTNN's performance by 3.3% F1 score. * Some work carried out while a visiting scholar at Google DeepMind.
Ask about this paper
Your agent reads all of it.
Lune indexed this paper to the last equation, along with the top-tier papers that cite it. Ask a question and the answer quotes them.
Your agent calls
Luneget_paper_fulltext
Free to start. No credit card required.
Terminal
Install the CLIlune papers fulltext 1c1bfc21-fa1f-487a-b485-bd5d38dd20cbCited by top-tier papers1
Ask how each one uses itBuilds on5
- VUDDY: A Scalable Approach for Vulnerable Code Clone DiscoverySeulbae Kim, Seunghoon Woo, Heejo Lee, Hakjoo OhS&P 2017 · 388 citations
- Multi-task Learning based Pre-trained Language Model for Code CompletionFang Liu, Ge Li, Yunfei Zhao, Zhi JinASE 2020 · 162 citations
- Structural Language Models of CodeUri Alon, Roy Sadaka, Omer Levy, Eran YahavICML 2020 · 115 citations
- Software visualization and deep transfer learning for effective software defect predictionJinyin Chen, Keke Hu, Yue Yu, Zhuangzhi Chen et al.ICSE 2020 · 89 citations
- VulDeePecker: A Deep Learning-Based System for Vulnerability DetectionZhen Li, Deqing Zou, Shouhuai Xu, Xinyu Ou et al.NDSS 2018
Related papers
- Comparison and Evaluation of Clone Detection Techniques with Different Code RepresentationsYuekun Wang, Yuhang Ye, Yueming Wu, Weiwei Zhang et al.ICSE 2023 · 15 citations
- Tritor: Detecting Semantic Code Clones by Building Social Network-Based Triads ModelDeqing Zou, Siyue Feng, Yueming Wu, Wenqi Suo et al.FSE 2023 · 6 citations
- The Natural Geometry of Code: Hyperbolic Representation Learning for Program ReasoningWeilin ZhouICLR 2026
- Functional code clone detection with syntax and semantics fusion learningChunrong Fang, Zixi Liu, Yangyang Shi, Jeff Huang et al.ISSTA 2020 · 125 citations
- TreeCen: Building Tree Graph for Scalable Semantic Code Clone DetectionYutao Hu, Deqing Zou, Junru Peng, Yueming Wu et al.ASE 2022 · 30 citations
