paperbot · PL 论文追踪

全部论文 待读 收藏

P2 A Novel Neural Source Code Representation Based on Abstract Syntax Tree

一种基于抽象语法树的新型神经源代码表示
ICSE 2019 IEEE/ACM 41st International Conference on Software Engineering (ICSE)2019匹配度 3/10 · 该论文属于机器学习与程序语言交叉的代码表示学习,但与用户核心关注的静态分析/形式化验证、LLM/Agent 驱动的程序分析、浮点程序分析及贝叶斯程序分析均无直接关联。其使用 RNN 编码 AST 的方法也非当前较强 LLM/Agent 工具路线,匹配度较低。引用 736 inbox
Jian Zhang, Xu Wang, Hongyu Zhang, Hailong Sun, Kaixuan Wang, Xudong Liu
crossref: 2026-09-12dblp: 2026-09-12

AI 速览

一句话:提出 ASTNN,将大型 AST 拆分为语句树序列并用双向 RNN 编码,显著提升代码分类与克隆检测效果。

利用机器学习分析程序的关键在于如何良好地表示代码片段。传统信息检索方法把程序当作自然语言文本,会丢失重要语义信息;而基于抽象语法树(AST)的神经模型虽表现更好,却因 AST 规模庞大而受困于长程依赖问题。本文提出 ASTNN:不再对整个大 AST 直接建模,而是将其切分为一系列小的语句树,先通过捕获语句的词法与句法知识把每棵语句树编码为向量,再由双向 RNN 对语句向量序列建模,利用语句的自然性最终生成代码片段的向量表示。作者将该表示应用于源代码分类与代码克隆检测两个常见的程序理解任务,实验结果表明其性能优于当前最先进的方法。

问题
现有基于信息检索的方法把代码当自然语言处理会丢失语义信息,而基于整棵 AST 的神经模型因 AST 规模大而存在长程依赖问题,难以有效表示源代码。
方法
ASTNN 将大 AST 切分为语句树序列,逐棵编码语句树以捕获词法与句法信息,再用双向 RNN 建模语句序列,得到代码片段的向量表示。
评估
在源代码分类和代码克隆检测两个程序理解任务上进行实验,结果显示该模型优于现有最先进方法。
原文摘要(Abstract)

Exploiting machine learning techniques for analyzing programs has attracted much attention. One key problem is how to represent code fragments well for follow-up analysis. Traditional information retrieval based methods often treat programs as natural language texts, which could miss important semantic information of source code. Recently, state-of-the-art studies demonstrate that abstract syntax tree (AST) based neural models can better represent source code. However, the sizes of ASTs are usually large and the existing models are prone to the long-term dependency problem. In this paper, we propose a novel AST-based Neural Network (ASTNN) for source code representation. Unlike existing models that work on entire ASTs, ASTNN splits each large AST into a sequence of small statement trees, and encodes the statement trees to vectors by capturing the lexical and syntactical knowledge of statements. Based on the sequence of statement vectors, a bidirectional RNN model is used to leverage the naturalness of statements and finally produce the vector representation of a code fragment. We have applied our neural network based source code representation method to two common program comprehension tasks: source code classification and code clone detection. Experimental results on the two tasks indicate that our model is superior to state-of-the-art approaches.

链接与引用

DOI 原文 · DBLP

BibTeX
@inproceedings{ZhangWZ0WL19,
  title = {A Novel Neural Source Code Representation Based on Abstract Syntax Tree},
  author = {Jian Zhang and Xu Wang and Hongyu Zhang and Hailong Sun and Kaixuan Wang and Xudong Liu},
  booktitle = {ICSE},
  year = {2019},
  doi = {10.1109/icse.2019.00086}
}