BiLSTM and LSTM networks: an efficient alternative to large language models for python syntax error correction
摘要
Automatic Program Repair (APR) can reduce the effort required to identify and correct programming errors. This study proposes PySynFix, a computationally lightweight APR system for Python syntax error correction. The system uses a Bidirectional Long Short-Term Memory (BiLSTM) network for multi-class error classification and a Long Short-Term Memory (LSTM) network for token-level repair, supported by hybrid fault localization based on Abstract Syntax Tree parsing and Microsoft’s Pyright tool. Trained on 6,000 synthetically generated faulty samples, PySynFix achieved 98% classification accuracy and 98.44% token-correction accuracy with a 98.91% F1 score. On the proposed test dataset, it repaired 794 out of 925 faulty cases (85.84%), outperforming the rule-based PyNar system (52.3%). On an IBM CodeNet-derived benchmark, PySynFix achieved a 59.2% repair success rate, compared with 25.17% for PyNar under the same category setup. Additional zero-shot experiments with Qwen3-Coder achieved 84.33–88.67% repair rates on token-level errors and 80.00% on indentation errors in the proposed dataset, as well as an overall repair rate of 71.83% on the same 600-case IBM-derived setup. Computational-footprint experiments showed that PySynFix requires substantially fewer parameters and lower inference-time resources than representative transformer-based code models. The evaluation focuses on syntactic validity rather than semantic equivalence, positioning PySynFix as a task-specific and resource-efficient solution for Python syntax repair.