论文标题
学习用异质图代表程序
Learning to Represent Programs with Heterogeneous Graphs
论文作者
论文摘要
程序源代码包含复杂的结构信息,可以用树木或图形等结构化数据形式表示。为了获取源代码中的结构信息,大多数现有研究都使用抽象语法树(AST)。一组作品将其他边缘添加到ASTS中,以将源代码转换为图形,并使用图形神经网络来学习程序图的表示形式。尽管这些作品为下游任务提供了其他控制或数据流信息,但它们忽略了AST本身中结构信息的重要方面:不同类型的节点和边缘。在AST中,不同的节点包含不同种类的信息,例如变量或控制流,节点与所有孩子之间的关系也可能不同。 为了解决节点和边缘类型的信息,我们将异质图的概念带入学习源代码,并从ASTS构建异质程序图的新公式,并提供用于节点和边缘的其他类型信息。我们使用编程语言的ASDL语法来定义程序图的节点和边缘类型。然后,我们使用异质图神经网络在这些图表上学习。我们评估了两个任务的方法:代码评论生成和方法命名。这两个任务都需要在完整代码段的语义上进行推理。实验结果表明,我们的方法的表现优于基线模型,包括基于图的模型,表明利用程序图中的节点和边缘的类型信息可以帮助学习程序语义。
Program source code contains complex structure information, which can be represented in structured data forms like trees or graphs. To acquire the structural information in source code, most existing researches use abstract syntax trees (AST). A group of works add additional edges to ASTs to convert source code into graphs and use graph neural networks to learn representations for program graphs. Although these works provide additional control or data flow information to ASTs for downstream tasks, they neglect an important aspect of structure information in AST itself: the different types of nodes and edges. In ASTs, different nodes contain different kinds of information like variables or control flow, and the relation between a node and all its children can also be different. To address the information of node and edge types, we bring the idea of heterogeneous graphs to learning on source code and present a new formula of building heterogeneous program graphs from ASTs with additional type information for nodes and edges. We use the ASDL grammar of programming language to define the node and edge types of program graphs. Then we use heterogeneous graph neural networks to learn on these graphs. We evaluate our approach on two tasks: code comment generation and method naming. Both tasks require reasoning on the semantics of complete code snippets. Experiment results show that our approach outperforms baseline models, including homogeneous graph-based models, showing that leveraging the type information of nodes and edges in program graphs can help in learning program semantics.