How Data Scientists Improve Generated Code Documentation in Jupyter Notebooks

Michael J. Muller, April Yi Wang, Steven I. Ross, Justin D. Weisz, Mayank Agarwal, Kartik Talamadupula, Stephanie Houde, Fernando Martinez, John T. Richards, Jaimie Drozdal, Xuye Liu, David Piorkowski, Dakuo Wang

Abstract

Generative AI models are increasingly proficient at summarizing code, yet they often fail to capture the high-level intent and narrative context essential for data science workflows. This paper investigates how data scientists refine AI-generated documentation within Jupyter Notebooks. Through a controlled experiment with 24 participants using the Themisto documentation tool, we identify a spectrum of "edit-patterns" ranging from minor detail additions to significant tutorial-style rewrites. Our findings suggest that while AI provides a valuable "cold-start," human intervention is critical for providing retrospective and prospective context, establishing a narrative voice, and bridging the gap between raw code and human understanding.

Introduction

In the collaborative and iterative world of data science, Jupyter Notebooks serve as both a development environment and a storytelling medium. Documentation in these notebooks is vital for reproducibility, yet it is often neglected. While modern AI models can generate high-fidelity code summaries, they remain "myopic," often missing the "why" behind specific operations or the broader project narrative. This study explores the "mixed-initiative" relationship between humans and AI, categorizing how data scientists compensate for AI limitations to produce more useful documentation.

Methodology

The researchers conducted a controlled study using Themisto, a JupyterLab extension designed to facilitate automated documentation. Themisto provides three distinct types of documentation prompts:

  1. GNN-based: Summaries generated by a Graph Neural Network.
  2. API-based: Documentation pulled directly from official library references (e.g., Pandas).
  3. Prompt-based: Structural nudges that encourage users to describe specific outputs (e.g., "The table shows...").
Themisto interface showing AI-generated documentation suggestions in a Jupyter Notebook.

Twenty-four data scientists were tasked with documenting two notebooks: one focused on COVID-19 forecasting and another on house price prediction. Each notebook contained nine code cells. The researchers then performed a thematic analysis on the edits made to the AI's suggestions, using a "bag-of-words" approach to identify specific text additions and modifications.

Taxonomy of Edit-Patterns

The analysis revealed that human edits are not uniform; they fall into a structured taxonomy based on the type of information added. A key contribution of this work is the mapping of these edit-patterns onto a two-dimensional space of cognitive effort and documentation complexity.

Spectrum of edit-patterns mapped by inferred participant effort and complexity.
  • Details: These are low-effort, low-complexity edits where users add specific variable names or parameters to the AI's generic summary.
  • Explanations: Mid-range edits that clarify the logic of a code block.
  • Tutorials and Rewritings: High-effort edits where the user either teaches a concept or completely restructures the AI's output to better fit the notebook's narrative.

Key Findings

The "Cold-Start" Efficacy

The study found that participants accepted or built upon AI-generated text in 85% of cases. Only 15% of instances resulted in a total rewrite. This indicates that AI documentation is highly effective as a "cold-start" mechanism, reducing the "blank page" problem for developers. Quantitatively, participants accepted documentation unchanged in 45% of cells and edited the suggestions in 41% of cells.

Contextual Compensation and Narrative Voice

AI models typically analyze code cells in isolation. Humans, however, frequently added retrospective context (explaining how previous steps influenced the current cell) and prospective context (anticipating future steps). Furthermore, data scientists often introduced a "human voice" by using personal pronouns like "we" or "you," transforming technical summaries into a cohesive narrative.

Common Edit Types

  • Details-This-step: The most frequent pattern, appearing in 33.9% of edited cells, where users added specific details about the current operation.
  • Rewriting: Occurred in 14.4% of edited cells.
  • Tutorial-style: Appeared in 8.47% of edits, providing educational value beyond simple description.
  • Stylistic/Structural: 12.7% of edits completed sentence fragments, and 5.08% adjusted Markdown header hierarchies for better organization.

Discussion and Future Work

While the study provides a robust taxonomy, it is limited by its "ecological validity"—participants documented code they did not write themselves. In practice, documenting one's own work might yield even deeper contextual edits.

Future AI models could leverage this "edit data" as a feedback loop. By learning that humans consistently add specific evaluation metrics (like "RMSE") to certain types of cells, AI can be trained to include them automatically. The researchers also propose "human-in-the-loop" systems where AI explicitly requests help for complex sections, specifying the type of documentation needed (e.g., "I need a tutorial-style explanation here"). This collaborative approach promises to make notebook documentation more comprehensive and human-centric.

Summary updated

BibTeX
@inproceedings{muller2021how,
  author = {Michael J. Muller and April Yi Wang and Steven I. Ross and Justin D. Weisz and Mayank Agarwal and Kartik Talamadupula and Stephanie Houde and Fernando Martinez and John T. Richards and Jaimie Drozdal and Xuye Liu and David Piorkowski and Dakuo Wang},
  title = {{How Data Scientists Improve Generated Code Documentation in Jupyter Notebooks}},
  booktitle = {IUI Workshops},
  year = {2021},
}
Figure