Automated Identification of Logical Errors in Programs: Advancing Scalable Analysis of Student Misconceptions

Muntasir Hoq, Ananya Rao, Reisha Jaishankar, Krish Piryani, Nithya Janapati, Jessica Vandenberg, Bradford W. Mott, Narges Norouzi, James C. Lester, Bita AkramEdm 2025

Introduction

In large-scale Computer Science (CS) education, providing personalized feedback is a significant challenge. While modern compilers effectively catch syntax errors, "logical errors"—where code executes but produces incorrect results—remain difficult to diagnose. These errors often reflect deep-seated student misconceptions or flawed problem-solving strategies. Traditionally, identifying these errors requires manual grading or the creation of exhaustive test cases and rubrics, neither of which scales effectively to classes with hundreds or thousands of students. Furthermore, many automated models function as "black boxes," informing students that their code is incorrect without explaining the location or nature of the error. This research presents an explainable, automated framework designed to identify latent learning difficulties directly from the structural semantics of student code.

Methodology

The proposed framework is built upon a modified Subtree-based Attention Neural Network (SANN), designed to capture the semantic nuances of programming logic through several key innovations:

  1. Abstract Syntax Tree (AST) Embedding: The model represents code as an AST, which is then decomposed into subtrees. A "two-way embedding" approach is employed, capturing both individual node data and the broader subtree structures to preserve the code's semantic meaning.
  2. Multi-Error Attention Mechanism: Standard SANN models typically utilize a softmax activation in their attention layers, which forces the model to focus on a single "most important" segment. Recognizing that student programs often contain multiple concurrent logical errors, the researchers replaced softmax with a sigmoid activation. This allows the model to assign high attention weights to multiple independent subtrees simultaneously.
  3. Entropy Regularization: To ensure the model remains selective and does not assign attention to irrelevant code segments, an entropy regularization term was added to the loss function. This forces the model to focus specifically on the most relevant erroneous segments.
  4. Downstream Integration: The resulting "code vectors"—which implicitly encode error information—were integrated into two predictive models:
  5. Deep Knowledge Tracing (DKT): An LSTM-based model used to predict a student's success on subsequent attempts.
  6. Performance Prediction: A model designed to forecast a student's final exam grade based on their submission history.

Experimental Setup and Datasets

The study utilized a dataset from the CodeWorkout platform, consisting of 57,670 Java code submissions from 368 students across 50 introductory programming problems (e.g., caughtSpeeding, sum13). To evaluate the model's diagnostic capabilities, human experts manually labeled 1,574 submissions for logical errors, categorizing them as syntactic (but compilable), strategic, or conceptual. The researchers also utilized normalized final exam grades to validate the model's predictive accuracy.

Key Insights

  • Correctness as a Proxy for Logic: The model successfully learns to identify logical errors by training solely on program correctness (binary pass/fail). The attention mechanism naturally gravitates toward the structural anomalies that cause failure without requiring pre-defined error labels.
  • Structural Understanding: By extracting the structural reasons for failure rather than relying on binary labels, the model gains a deeper representation of a student’s knowledge state.
  • Explainability: Because the model applies attention over AST subtrees, it generates a "heat map" of the code. This provides a built-in mechanism for pointing students or instructors to the specific lines of code that are likely problematic.

Results

The modified SANN framework demonstrated superior performance across several metrics:

  • Program Correctness: The model achieved an F1-score of 0.87, outperforming state-of-the-art baselines such as code2vec (0.83) and ASTNN (0.80).
  • Error Identification: In expert evaluations, the model achieved a 96% recall in identifying logical errors for specific problems, with recall rates ranging from 83% to 97% across diverse problem sets.
  • Knowledge Tracing: Integrating SANN code vectors into a DKT model improved the Area Under the Curve (AUC) to 72.45%, a 10% improvement over the baseline DKT (65.87%).
  • Grade Prediction: The model predicted final exam grades with an RMSE of 0.17 and an $R^2$ of 0.50, significantly outperforming traditional regression models.

Limitations and Future Work

While promising, the framework currently has limitations. It is restricted to compilable Java code, as it relies on AST generation; this excludes students who struggle with syntax before reaching the logical stage. Additionally, the model occasionally struggles to distinguish between "careless" typos and deep "conceptual" misunderstandings, as both can appear similar within the AST structure. Future research will focus on integrating this framework into adaptive learning systems to provide real-time, automated hints and worked examples tailored to specific detected errors.

Summary updated

BibTeX
@inproceedings{hoq2025automated,
  author = {Muntasir Hoq and Ananya Rao and Reisha Jaishankar and Krish Piryani and Nithya Janapati and Jessica Vandenberg and Bradford W. Mott and Narges Norouzi and James C. Lester and Bita Akram},
  title = {{Automated Identification of Logical Errors in Programs: Advancing Scalable Analysis of Student Misconceptions}},
  booktitle = {Edm},
  year = {2025},
  doi = {10.48550/arxiv.2505.10913},
}
Figure