Skip to main content
QUICK REVIEW

[论文解读] Evaluating the Impact of Source Code Parsers on ML4SE Models

Ilya Utkin, Egor Spirin|arXiv (Cornell University)|Jun 17, 2022
Software Engineering Research被引用 4
一句话总结

本文评估了不同源代码解析器对机器学习在软件工程(ML4SE)中模型性能的影响,重点关注Java中的方法名预测。通过使用名为SuperParser的新工具,作者对比了八种解析器在两种模型(TreeLSTM和Code2Seq)上的表现,发现解析器的选择显著影响模型质量,TreeLSTM的性能差异最高达27%,Code2Seq的差异达5.5%。

ABSTRACT

As researchers and practitioners apply Machine Learning to increasingly more software engineering problems, the approaches they use become more sophisticated. A lot of modern approaches utilize internal code structure in the form of an abstract syntax tree (AST) or its extensions: path-based representation, complex graph combining AST with additional edges. Even though the process of extracting ASTs from code can be done with different parsers, the impact of choosing a parser on the final model quality remains unstudied. Moreover, researchers often omit the exact details of extracting particular code representations. In this work, we evaluate two models, namely Code2Seq and TreeLSTM, in the method name prediction task backed by eight different parsers for the Java language. To unify the process of data preparation with different parsers, we develop SuperParser, a multi-language parser-agnostic library based on PathMiner. SuperParser facilitates the end-to-end creation of datasets suitable for training and evaluation of ML models that work with structural information from source code. Our results demonstrate that trees built by different parsers vary in their structure and content. We then analyze how this diversity affects the models' quality and show that the quality gap between the most and least suitable parsers for both models turns out to be significant. Finally, we discuss other features of the parsers that researchers and practitioners should take into account when selecting a parser along with the impact on the models' quality. The code of SuperParser is publicly available at https://doi.org/10.5281/zenodo.6366591. We also publish Java-norm, the dataset we use to evaluate the models: https://doi.org/10.5281/zenodo.6366599.

研究动机与目标

  • 研究源代码解析器的选择如何影响依赖抽象语法树(AST)的ML4SE模型的性能。
  • 解决以往ML4SE研究中缺乏透明度和可复现性的问题,这些研究在提取AST时常常省略解析器细节。
  • 开发一个统一的、与解析器无关的框架,以标准化跨多种解析器和编程语言的ML就绪代码数据集的创建。
  • 使用两种广泛使用的模型(TreeLSTM和Code2Seq)评估解析器多样性对模型质量的影响。
  • 提供实证证据表明,解析器选择是ML4SE流水线中的关键超参数,而非无关紧要的实现细节。

提出的方法

  • 开发了SuperParser,一个基于PathMiner构建的多语言、与解析器无关的库,可统一地从源代码中提取AST和代码表示,支持多种解析器。
  • 实现了基于YAML的配置系统,允许用户通过极少的代码更改切换解析器,从而实现一致的端到端数据集创建。
  • 在方法名预测任务上评估了八种不同Java解析器的模型性能:JavaCC、ANTLR、Rhino、Squirrel、Tree-sitter、JDT、Javac和JShell。
  • 使用每种解析器从同一代码库中提取AST和基于路径的表示(用于Code2Seq),确保模型训练和评估的输入一致。
  • 采用Java-norm数据集——其规模与Java-small相似,但验证集和测试集更具多样性——以实现稳健且具有代表性的模型评估。
  • 使用F1-score和ChrF测量模型性能,跨不同解析器比较结果,以评估AST结构差异的影响。

实验结果

研究问题

  • RQ1源代码解析器的选择如何影响依赖AST的ML4SE模型的性能?
  • RQ2AST结构与内容的差异(如树深度、节点数量或标记多样性)在多大程度上影响模型质量?
  • RQ3是否存在一个对ML4SE模型普遍最优的解析器,还是最佳解析器取决于模型架构?
  • RQ4统一的、与解析器无关的框架能否提升ML4SE研究中的可复现性和可比性?
  • RQ5使用不同解析器训练的模型之间的性能差异有多大?这些差异是否具有统计显著性?

主要发现

  • 解析器的选择显著影响模型性能,TreeLSTM的F1-score因解析器不同而最高波动达27.0%。
  • 对于Code2Seq,最佳与最差解析器之间的F1-score差距为5.5%,在近期ML4SE文献中被视为显著差异。
  • TreeLSTM与Code2Seq对解析器的相对排名不同,表明不存在普遍最优的解析器——选择取决于模型架构和处理方式。
  • 不同解析器生成的AST在结构(如树深度、大小)和内容(如不同节点类型的数量、标记分布)上存在差异,这些差异直接影响模型学习。
  • SuperParser工具可实现跨多种解析器的一致、可复现的数据集创建,仅需极少配置更改,提升了实验透明度。
  • 与本研究一同发布的Java-norm数据集,相比Java-small具有更丰富多样的验证集和测试集,提供了更具代表性的评估集,且无需增加计算成本。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。