Neural Code Comprehension: A Learnable Representation of Code Semantics
arXiv:1806.07336
Abstract
With the recent success of embeddings in natural language processing, research has been conducted into applying similar methods to code analysis. Most works attempt to process the code directly or use a syntactic tree representation, treating it like sentences written in a natural language. However, none of the existing methods are sufficient to comprehend program semantics robustly, due to structural features such as function calls, branching, and interchangeable order of statements. In this paper, we propose a novel processing technique to learn code semantics, and apply it to a variety of program analysis tasks. In particular, we stipulate that a robust distributional hypothesis of code applies to both human- and machine-generated programs. Following this hypothesis, we define an embedding space, inst2vec, based on an Intermediate Representation (IR) of the code that is independent of the source programming language. We provide a novel definition of contextual flow for this IR, leveraging both the underlying data- and control-flow of the program. We then analyze the embeddings qualitatively using analogies and clustering, and evaluate the learned representation on three different high-level tasks. We show that even without fine-tuning, a single RNN architecture and fixed inst2vec embeddings outperform specialized approaches for performance prediction (compute device mapping, optimal thread coarsening); and algorithm classification from raw code (104 classes), where we set a new state-of-the-art.
arXiv commentPublished at NeurIPS 2018
Cited by in corpus (20)
- CodeXGLUE: A Machine Learning Benchmark Dataset for Code Understanding and Generation
- Contrastive Code Representation Learning
- Network representation learning systematic review: ancestors and current development state
- ProGraML: Graph-based Deep Learning for Program Optimization and Analysis
- POSET-RL: Phase ordering for Optimizing Size and Execution Time using Reinforcement Learning
- A Survey on Machine Learning Techniques for Source Code Analysis
- Toward Code Generation: A Survey and Lessons from Semantic Parsing
- SEED: Semantic Graph based Deep detection for type-4 clone
- TreeCaps: Tree-Based Capsule Networks for Source Code Processing
- Semantic Code Search for Smart Contracts
- MISIM: A Neural Code Semantics Similarity System Using the Context-Aware Semantics Structure
- Embedding Code Contexts for Cryptographic API Suggestion:New Methodologies and Comparisons
- Report of the Workshop on Program Synthesis for Scientific Computing
- Context-Aware Parse Trees
- A Comparison of Code Embeddings and Beyond
- Deep Data Flow Analysis
- Learning Execution through Neural Code Fusion
- Universal Policies for Software-Defined MDPs
- How could Neural Networks understand Programs?
- Categorization of Program Regions for Agile Compilation using Machine Learning and Hardware Support