Deep Learning for Bug-Localization in Student Programs

Rahul Gupta, Aditya Kanade, Shirish K. ShevadearXiv 2019

Introduction

In the era of Massive Open Online Courses (MOOCs) and large-scale introductory programming classes, providing personalized feedback is a significant challenge. While automated graders can quickly determine if a program passes or fails a test suite, they rarely explain why or where the failure occurs. Traditional bug-localization techniques often fall short: dynamic analysis requires complex instrumentation and execution, while syntactic diffs are easily confused by stylistic variations in student code.

Methodology: A Two-Phase Static Approach

The researchers propose a novel static analysis technique that treats bug localization as a neural network interpretability problem. This approach avoids the need to run potentially buggy code by learning structural patterns of failure directly from the source.

Phase 1: Structural Encoding and the TCNN

To process code effectively, the system first converts source files into Abstract Syntax Trees (ASTs). Unlike standard sequence models (RNNs/LSTMs) that treat code as text, the authors utilize a Tree Convolutional Neural Network (TCNN). The AST is flattened into a 2D matrix using a breadth-first traversal, ensuring that structural subtrees are mapped to spatial neighborhoods in the matrix.

Mapping an Abstract Syntax Tree (AST) to a 2D matrix for convolutional processing.

The TCNN is trained on <program, test_id> pairs to predict a binary outcome: Pass (1) or Fail (0). By using convolutions, the model captures hierarchical logic such as nested loops and conditional branches.

Phase 2: Localization via Neural Attribution

Once the model achieves high predictive accuracy, the focus shifts to localization. The authors employ Integrated Gradients, a neural attribution technique, to identify which input features (lines of code) contributed most to a "Fail" prediction.

The two-phase approach: predicting test outcomes and attributing failures back to specific code lines.

A key innovation in this phase is the use of a "similar correct program" as a neutral baseline for attribution. By comparing a buggy program to a structurally similar correct one in the embedding space, the system ignores benign differences (like variable names) and highlights only the logic errors.

Experimental Results

The model was evaluated using a dataset of C programs from 29 programming tasks, encompassing approximately 270,000 training examples and over 2,000 buggy programs for testing.

  • Predictive Accuracy: The TCNN reached a 96% validation accuracy in predicting test outcomes.
  • Localization Success: The system successfully identified at least one bug within the top 10 most suspicious lines for over 80% of the evaluation programs.
  • Comparative Performance: The deep learning approach consistently outperformed industry-standard dynamic analysis tools like Tarantula and Ochiai, particularly in scenarios where only a single failing test case was available.

Conclusion and Future Directions

This research demonstrates that deep learning can effectively localize bugs in student programs through static analysis of code structure. By leveraging the interpretability of classification models, the system provides actionable feedback without the overhead of dynamic execution. Future work aims to scale this approach to larger industrial projects and integrate generative models for automated program repair.

Summary updated

BibTeX
@misc{gupta2019deep,
  author = {Rahul Gupta and Aditya Kanade and Shirish K. Shevade},
  title = {{Deep Learning for Bug-Localization in Student Programs}},
  year = {2019},
  eprint = {1905.12454},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1905.12454},
}
Figure