TL;DR
This paper introduces an automated pipeline that generates personalized "worked examples" (step-by-step programming tutorials) tailored to a student's specific coding misconceptions. By using Abstract Syntax Trees (ASTs) to extract structural code patterns—termed Knowledge Components (KCs)—from incorrect student submissions, the system successfully steers a Large Language Model (LLM) to generate highly relevant, targeted pedagogical content at scale.
What Problem Does This Paper Address?
In introductory computer science courses, "worked examples" (problems presented alongside their step-by-step solutions and explanations) are highly effective tools for reducing cognitive load and helping struggling students. However, manually authoring these examples to address the diverse array of logical errors made by students is incredibly time-consuming.
While LLMs can generate educational content on demand, generic prompts often yield examples that are either too advanced or completely miss the specific conceptual misunderstanding hidden within a student's broken code. This paper tackles the challenge of automated personalization: how to precisely guide an LLM so that its generated explanations directly target the underlying logical flaws in a student's unique code submission.
Methods
The authors developed a three-stage pipeline that combines structural code analysis with generative AI:
- Pattern-based KC Discovery: The system parses student code into an Abstract Syntax Tree (AST). A Subtree-based Attention Neural Network (SANN) identifies which subtrees are most predictive of whether a solution is correct or incorrect. These subtrees are normalized (replacing specific variables with placeholders) and clustered using a Variational Autoencoder (VAE) and K-Means ($k=50$) to form a standardized inventory of "Knowledge Components" (KCs).
- KC Enrichment: Because raw cluster IDs are unreadable, an LLM translates these structural AST patterns into human-readable labels and one-sentence descriptions (e.g., identifying a "Boolean operator precedence" error).
- Conditioned Generation: To generate a worked example, the pipeline prompts an LLM with the original problem, the student's incorrect code, and the enriched KC descriptions. The LLM is constrained to generate a new but structurally related problem and a 3-to-10-step solution that explicitly addresses and explains the targeted KCs.
The authors compared this KC-conditioned approach against an identical baseline prompt that omitted the explicit KC constraints.
Datasets
The study utilized the publicly available CodeWorkout dataset, which contains 57,670 anonymized Java submissions from 368 CS1 students.
- The authors randomly sampled 50 incorrect student attempts from two distinct problems:
repeatEnd(a string manipulation task) andfix45(an array rearrangement task), resulting in a evaluation dataset of 100 student submissions.
Key Insights and Ideas
- ASTs as a Diagnostic Lens: Simply feeding raw, broken code to an LLM isn't always enough for it to diagnose a novice's exact point of confusion. Transforming the code into abstract structural patterns (KCs) provides a reliable pedagogical anchor for the model.
- The Clutter Trade-off: Forcing an LLM to address too many constraints at once can degrade the structural quality of its output. When a student's code triggered multiple KCs, the model occasionally packed too much information into single steps, blurring the boundaries between distinct instructional steps.
Key Results
The generated worked examples were evaluated by human experts using a rigorous 0–2 scale rubric.
The quantitative comparison revealed significant advantages for the KC-conditioned pipeline:
- Student Relevance: KC-conditioned examples scored 22% higher ($1.89$ vs. $1.67$, $p=0.001$), demonstrating they were significantly better at addressing the student's actual logical errors rather than providing generic solutions.
- Explanation Clarity: Conditioned outputs scored 13% higher on providing clear, novice-friendly explanations ($1.94$ vs. $1.81$, $p=0.027$).
- Expert Preference: In blind comparisons of the 100 generated pairs, experts preferred the KC-conditioned example 41 times, had no preference 50 times, and preferred the baseline only 9 times.
Limitations and Future Work
- Multi-KC Prioritization: Currently, if a student's code maps to multiple KCs, the pipeline treats them equally, sometimes leading to cluttered explanations. The authors plan to use the neural network's attention weights to dynamically prioritize which KC is the most critical to address.
- Lack of Direct Student Evaluation: While expert reviews were highly positive, the current study does not measure actual student learning gains. The authors plan to conduct future classroom studies to evaluate if these personalized examples truly improve student code-reiteration success and concept retention.
Summary updated