Graph-Augmented Code Summarization in Computational Notebooks

April Yi Wang, Dakuo Wang, Xuye Liu, Lingfei Wu

Abstract

Computational notebooks are widely used for data science experimentation, yet they often lack the descriptive documentation necessary for reproducibility and collaboration. This paper presents Themisto, an automated system that generates documentation for Jupyter Notebooks. By utilizing a Hierarchical Attention-based Convolutional Graph Neural Network (HAConvGNN) alongside API documentation retrieval and human-in-the-loop prompts, Themisto captures the structural and contextual nuances of notebook code. Evaluation on Kaggle datasets demonstrates that this approach significantly outperforms traditional sequence-to-sequence models, effectively doubling performance metrics.

Introduction

Data scientists frequently use computational notebooks for rapid, iterative experimentation. However, the "storytelling" aspect of these notebooks is often neglected, resulting in "fragmented and drafty" documents that are difficult to interpret. Existing automated code summarization tools, primarily designed for traditional software source code, struggle with notebooks due to contextual complexity—where documentation must explain rationale and output interpretation—and structural mismatch, where a single markdown cell may describe multiple disparate code blocks.

Methodology

Themisto addresses these challenges through a three-pronged framework integrated directly into the Jupyter interface:

  1. HAConvGNN (Hierarchical Attention-based Convolutional GNN): This model processes code structure via Abstract Syntax Trees (ASTs) rather than simple text. It employs a hierarchical attention mechanism to encode the context of four adjacent code cells, allowing it to generate summaries that span multiple logical blocks.
  2. Query-Based Retrieval: For common library functions (e.g., Pandas, NumPy, Scikit-learn), the system matches code against a curated database of official API documentation to provide high-quality, reliable summaries.
  3. Prompt-Based Nudging: Recognizing that AI cannot always infer a scientist's specific intent, Themisto uses a "human-in-the-loop" approach. It prompts users to interpret visual outputs or provide reasons for specific code segments.
The Themisto interface integrated into Jupyter, showing automated prompts (B, C) and user-input nudges (D) based on code execution (A).

Model Architecture

The core of the generative component is the HAConvGNN, which treats code as a graph to capture logic more effectively than string-based models. By looking at a window of adjacent cells, the model mimics human reading patterns in notebooks, focusing on the flow of data.

The full architecture of the HAConvGNN model, illustrating the flow from Code AST Embeddings through hierarchical attention layers to the final decoder.

Datasets and Evaluation

The HAConvGNN model was trained on a curated dataset of 28,625 code-summary pairs extracted from the top 10% of publicly available notebooks across 20 major Kaggle competitions. The data was preprocessed into graph-based structures suitable for GNN training.

Key Results

The model was evaluated against standard baselines using ROUGE-1 scores. The results indicate that the hierarchical graph-based approach nearly doubles the performance of traditional sequence-based models like code2seq.

Model Precision Recall F-Measure
code2seq 11.45 8.46 8.23
graph2seq 13.21 9.87 9.51
HAConvGNN 22.87 16.92 16.58

Discussion and Limitations

While Themisto represents a significant advancement, several limitations remain. The query-based retrieval is currently limited to three major libraries, and while ROUGE scores have improved, the generated text often still requires human refinement. Future work will focus on expanding library coverage and conducting human-centered AI research to observe how these automated suggestions impact long-term data science workflows.

Summary updated

BibTeX
@inproceedings{wang2021graph,
  author = {April Yi Wang and Dakuo Wang and Xuye Liu and Lingfei Wu},
  title = {{Graph-Augmented Code Summarization in Computational Notebooks}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {2021},
  doi = {10.24963/ijcai.2021/717},
}
Figure