Introduction
In Massive Open Online Courses (MOOCs), providing timely feedback to thousands of students is a significant challenge. Researchers have developed SYNFIX, a tool that leverages Recurrent Neural Networks (RNNs) to automatically repair syntax errors in student programming assignments. By learning from thousands of syntactically correct submissions, SYNFIX can successfully fix nearly 32% of broken programs, offering immediate assistance in environments where human teaching assistants are scarce.
The Challenge of Syntax Errors
Syntax errors represent a major hurdle for novice programmers, accounting for approximately 34% of all student submissions in introductory courses. While automated tools exist to assist with logic or style, most rely on Abstract Syntax Trees (ASTs). This creates a "chicken and egg" problem: an AST can only be generated if the code is already syntactically correct. Standard compilers provide error messages, but these are often cryptic for beginners. SYNFIX addresses this by suggesting code fixes without requiring a successful parse of the buggy program.
The SYNFIX Methodology
SYNFIX treats programming as a natural language problem, an approach inspired by the "Big Code" movement. The system operates in two distinct phases: training and repair.
- Training: For a specific programming task, the system tokenizes all available syntactically correct student submissions. It then trains an RNN to act as a language model. Given a sequence of code tokens, the model learns to predict the most likely subsequent token.
- Repair (The SYNFIX Algorithm): When a student submits code with a syntax error, the tool identifies the error location provided by the Python interpreter. It feeds the code prefix (the sequence before the error) into the RNN to predict the next $k$ tokens. SYNFIX then iteratively attempts to insert or replace tokens at the error site. If these local fixes fail, a "Previous Line" strategy is employed, where the tool attempts to rewrite the entire erroneous line based on the preceding context. A fix is deemed successful if the resulting code passes the Python parser.
Experimental Setup and Datasets
The study evaluated SYNFIX using a dataset of 40,835 Python submissions from an introductory programming course (6.00x) on the edX platform. The evaluation focused on five specific benchmark problems, ranging in complexity and vocabulary size.
Out of the total submissions, 14,203 (34.78%) contained syntax errors, forming the primary test set for the repair tool.
Key Insights and Discussion
Several critical observations emerged from the development and testing of SYNFIX:
- Problem-Specific Models: Rather than training a single monolithic model for the entire Python language, the researchers trained individual models for each assignment. Since student solutions for specific tasks tend to be repetitive, these specialized models are highly effective at capturing task-specific patterns.
- The "Previous Line" Strategy: This strategy proved vital because compilers often misidentify the exact location of a syntax error. By allowing the RNN to rewrite the entire line containing the reported error, SYNFIX effectively bypasses the inaccuracies of compiler error localization.
- RNN vs. LSTM Performance: Interestingly, simple RNNs slightly outperformed Long Short-Term Memory (LSTM) networks. This suggests that the dependencies required for syntax repair are often local, and the higher complexity of LSTMs may lead to overfitting on smaller, per-problem datasets.
Results and Performance
The system demonstrated significant efficacy in real-world scenarios:
- Total Fix Rate: SYNFIX completely repaired 31.69% (4,501/14,203) of buggy submissions.
- Partial Success: An additional 6.39% of submissions had their primary syntax error resolved, even if subsequent errors remained.
- Efficiency: Training a model takes approximately 1.5 hours on a standard laptop, and generating a fix is nearly instantaneous, making it suitable for real-time pedagogical feedback.
- Vocabulary Thresholding: Replacing rare variable names with a generic
IDENTtoken significantly improved the model's ability to generalize across diverse coding styles.
Limitations and Future Directions
While promising, SYNFIX has areas for improvement. Currently, the algorithm focuses on fixing one error at a time. Furthermore, a "successful" fix is defined purely by syntactic validity; the suggested code might be logically incorrect. Future iterations could incorporate semantic checks by running test cases against the suggested repairs. Additionally, the researchers propose using Bidirectional RNNs to leverage context from both before and after the error site, potentially increasing the accuracy of the generated repairs.