Jupyter notebooks enable developers to interleave code snippets with rich-text and in-line visualizations. Data scientists use Jupyter notebook as the de-facto standard for creating and sharing machine-learning based solutions, primarily written in Python. Recent studies have demonstrated, however, that a large portion of Jupyter notebooks available on public platforms are undocumented and lacks a narrative structure. This reduces the readability of these notebooks. To address this shortcoming, this paper presents HeaderGen, a novel tool-based approach that automatically annotates code cells with categorical markdown headers based on a taxonomy of machine-learning operations, and classifies and displays function calls according to this taxonomy. For this functionality to be realized, HeaderGen enhances an existing call graph analysis in PyCG. To improve precision, HeaderGen extends PyCG's analysis with support for handling external library code and flow-sensitivity. The former is realized by facilitating the resolution of function return-types. Furthermore, HeaderGen uses type information to perform pattern matching on code syntax to annotate code cells. The evaluation on 15 real-world Jupyter notebooks from Kaggle shows that HeaderGen's underlying call graph analysis yields high accuracy (96.4% precision and 95.9% recall). This is because HeaderGen can resolve return-types of external libraries where existing type inference tools such as pytype (by Google), pyright (by Microsoft), and Jedi fall short. The header generation has a precision of 82.2% and a recall rate of 96.8% with regard to headers created manually by experts. In a user study, HeaderGen helps participants finish comprehension and navigation tasks faster. All participants clearly perceive HeaderGen as useful to their task.
翻译:Jupyter Notebook使开发者能够将代码片段与富文本及内联可视化交错结合。数据科学家将Jupyter Notebook作为创建和分享基于机器学习的解决方案(主要使用Python编写)的事实标准。然而,近期研究表明,公共平台上可获取的Jupyter Notebook中,大部分缺乏文档记录和叙事结构,这降低了其可读性。为解决这一不足,本文提出HeaderGen——一种新颖的基于工具的方法,它基于机器学习操作分类法自动为代码单元添加分类性Markdown标题,并根据该分类法对函数调用进行分类和显示。为实现该功能,HeaderGen增强了PyCG中现有的调用图分析。为提高精度,HeaderGen扩展了PyCG的分析,支持处理外部库代码和流敏感性,前者通过促进函数返回类型的解析实现。此外,HeaderGen利用类型信息对代码语法进行模式匹配,从而标注代码单元。在Kaggle中15个真实Jupyter Notebook上的评估表明,HeaderGen底层调用图分析具有高准确率(精度96.4%,召回率95.9%)。这是因为HeaderGen能解析现有类型推断工具(如Google的pytype、Microsoft的pyright和Jedi)难以处理的外部库返回类型。对于专家手动创建的标题,HeaderGen的标题生成精度为82.2%,召回率为96.8%。在用户研究中,HeaderGen帮助参与者更快地完成理解与导航任务。所有参与者均明确认为HeaderGen对其任务具有实用性。