arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 1806.07336cs.LGcs.NEcs.PLstat.ML
收藏

神经代码理解:代码语义的可学习表示

Neural Code Comprehension: A Learnable Representation of Code Semantics

ETH Zurich(苏黎世联邦理工学院)

Tal Ben-Nun, Alice Shoshana Jakobovits, Torsten Hoefler

摘要:

随着近年来嵌入在自然语言处理中的成功,已经进行了将类似方法应用于代码分析的研究。大多数作品试图直接处理代码或使用语法树表示,将其视为用自然语言编写的句子。然而,现有的方法都不足以理解程序语义鲁棒,由于结构特征,如函数调用,分支,和可互换的语句顺序。在本文中,我们提出了一种新的处理技术来学习代码语义,并将其应用到各种程序分析任务。特别是,我们规定,一个强大的分布式假设的代码适用于人类和机器生成的程序。遵循这一假设,我们基于独立于源程序设计语言的代码中间表示(IR)定义了嵌入空间inst 2 vec。我们提供了一个新的定义上下文流这个IR,利用底层的数据流和控制流的程序。然后,我们使用类比和聚类定性分析嵌入,并评估三个不同的高级任务的学习表示。我们表明,即使没有微调,单个RNN架构和固定的inst 2 vec嵌入也优于性能预测的专用方法(计算设备映射,最佳线程粗化);以及原始代码(104个类)的算法分类,我们在其中设置了一个新的最先进的。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑