[论文解读] Abstract Syntax Tree for Programming Language Understanding and Representation: How Far Are We?
本文通过在代码克隆检测、代码搜索和代码摘要生成任务中对基于抽象语法树(AST)和基于标记(token)的代码表示学习方法进行综合实证研究,发现尽管AST在理论上具有优势,但使用AST表示的模型在整体上始终表现不如基于标记的表示方法。然而,AST在特定样本子集上表现更优,凸显了在基于AST的代码表示中需采用上下文感知、阶段特定的方法选择策略。
Programming language understanding and representation (a.k.a code representation learning) has always been a hot and challenging task in software engineering. It aims to apply deep learning techniques to produce numerical representations of the source code features while preserving its semantics. These representations can be used for facilitating subsequent code-related tasks. The abstract syntax tree (AST), a fundamental code feature, illustrates the syntactic information of the source code and has been widely used in code representation learning. However, there is still a lack of systematic and quantitative evaluation of how well AST-based code representation facilitates subsequent code-related tasks. In this paper, we first conduct a comprehensive empirical study to explore the effectiveness of the AST-based code representation in facilitating follow-up code-related tasks. To do so, we compare the performance of models trained with code token sequence (Token for short) based code representation and AST-based code representation on three popular types of code-related tasks. Surprisingly, the overall quantitative statistical results demonstrate that models trained with AST-based code representation consistently perform worse across all three tasks compared to models trained with Token-based code representation. Our further quantitative analysis reveals that models trained with AST-based code representation outperform models trained with Token-based code representation in certain subsets of samples across all three tasks. We also conduct comprehensive experiments to evaluate and reveal the impact of the choice of AST parsing/preprocessing/encoding methods on AST-based code representation and subsequent code-related tasks. Our study provides future researchers with detailed guidance on how to select solutions at each stage to fully exploit AST.
研究动机与目标
- 定量评估基于AST的代码表示在促进下游代码相关任务方面的有效性。
- 探究尽管AST具有理论优势,为何基于AST的表示方法在性能上仍可能逊于基于token的表示方法。
- 研究不同的AST解析、预处理和编码方法对多种代码任务中模型性能的影响。
- 为研究人员根据任务上下文选择基于AST的表示技术,提供可操作的、阶段特定的指导。
提出的方法
- 本研究在三个代码相关任务(代码克隆检测、代码搜索和代码摘要生成)中,对比基于AST和基于token的代码表示方法训练的模型表现。
- 评估了四种常见的AST解析方法、六种AST预处理技术以及四种AST编码方法。
- 通过统计分析比较模型性能,并利用子组分析识别AST模型优于token模型的具体情况。
- AST解析阶段使用不同工具和配置将源代码转换为抽象语法树。
- 预处理阶段应用节点归一化、子树剪枝和结构简化等技术,以准备AST用于编码。
- 编码阶段采用Transformer、图神经网络(GNN)和树结构注意力机制等深度学习模型,从AST生成代码嵌入表示。
实验结果
研究问题
- RQ1在代码克隆检测、代码搜索和代码摘要生成任务中,基于AST的代码表示与基于token的表示相比,性能如何?
- RQ2在哪些特定的代码样本子集中,基于AST的表示优于基于token的表示?
- RQ3在AST解析、预处理和编码阶段的不同选择如何影响代码表示模型的最终性能?
- RQ4各种AST表示流水线组件对下游代码智能任务的特定任务影响是什么?
主要发现
- 在所有三项任务(代码克隆检测、代码搜索和代码摘要生成)中,基于AST的代码表示训练的模型始终表现不如基于token的表示训练的模型。
- 尽管整体表现欠佳,但在特定样本子集中,基于AST的模型仍优于基于token的模型——在代码摘要任务中最高达39%的样本,在代码搜索任务中达28%。
- 基于AST的表示性能对解析、预处理和编码方法的选择极为敏感,且其影响因下游任务而异。
- AST优于token的子集通常涉及文本相似度较低的代码,例如结构相似但词汇差异较大的克隆对。
- 本研究发现,不存在一种AST表示流水线配置能普遍优于其他配置,强调了任务特定优化的必要性。
- 结果表明,当前基于AST的代码表示学习缺乏系统性指导,未来工作应聚焦于上下文感知、阶段感知的流水线设计。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。