[Paper Review] Fix Bugs with Transformer through a Neural-Symbolic Edit Grammar
NSEdit proposes a novel Transformer-based code repair method that generates editing sequences using a neural-symbolic edit grammar formulated as a regular language. By combining a pointer network for location selection and ensemble rerankers fine-tuned on validation data, NSEdit achieves a new state-of-the-art accuracy of 24.04% on the Tufano small dataset in the CodeXGLUE benchmark, demonstrating robustness to syntactic bugs and effective edit sequence generation without program analysis inputs.
We introduce NSEdit (neural-symbolic edit), a novel Transformer-based code repair method. Given only the source code that contains bugs, NSEdit predicts an editing sequence that can fix the bugs. The edit grammar is formulated as a regular language, and the Transformer uses it as a neural-symbolic scripting interface to generate editing programs. We modify the Transformer and add a pointer network to select the edit locations. An ensemble of rerankers are trained to re-rank the editing sequences generated by beam search. We fine-tune the rerankers on the validation set to reduce over-fitting. NSEdit is evaluated on various code repair datasets and achieved a new state-of-the-art accuracy ($24.04\%$) on the Tufano small dataset of the CodeXGLUE benchmark. NSEdit performs robustly when programs vary from packages to packages and when buggy programs are concrete. We conduct detailed analysis on our methods and demonstrate the effectiveness of each component.
Motivation & Objective
- To address the challenge of code repair in the presence of syntactic bugs without relying on program analysis or auxiliary representations.
- To improve generalization and robustness in code repair by modeling edits as a structured, differentiable language rather than direct code-to-code translation.
- To enhance beam search output quality in sequence generation by introducing a learnable reranking mechanism that improves precision and recall trade-offs.
- To demonstrate that Transformers can learn complex editing operations through a domain-specific language (DSL) of delete and insert actions, enabling precise, symbolic program transformations.
Proposed method
- NSEdit uses a Transformer encoder-decoder architecture where the encoder processes buggy source code and the decoder generates editing sequences using a neural-symbolic edit grammar as a domain-specific language (DSL).
- The edit grammar is formalized as a regular language with two primitive actions: 'delete' and 'insert', which are embedded as special tokens in the model's vocabulary.
- A pointer network is integrated into the decoder to dynamically select edit locations by retrieving from the encoder’s hidden states, enabling content-based location attention instead of static embeddings.
- The model employs beam search for decoding, followed by an ensemble of fine-tuned rerankers that re-rank hypotheses based on learned confidence signals distinct from the main model’s log-likelihood.
- Rerankers are trained on the validation set to reduce overfitting and improve generalization, with confidence scores used to control precision-recall trade-offs in production deployment.
- The method is trained end-to-end using only buggy and fixed code pairs, without requiring ASTs, DFGs, or error messages, relying solely on the model’s ability to learn syntax and semantics from pre-training.
Experimental results
Research questions
- RQ1Can a Transformer model learn to generate precise editing sequences for buggy code without relying on program analysis representations?
- RQ2Does using a neural-symbolic edit grammar as a DSL improve the robustness and accuracy of code repair compared to direct code generation?
- RQ3To what extent do ensemble rerankers and validation-set fine-tuning improve beam search output quality in code repair?
- RQ4How does the precision-recall trade-off of the reranking score compare to the intrinsic beam search confidence score in real-world deployment scenarios?
Key findings
- NSEdit achieves a new state-of-the-art accuracy of 24.04% on the Tufano small dataset in the CodeXGLUE benchmark, outperforming prior methods that rely on direct code generation or complex graph-based representations.
- The use of ensemble rerankers fine-tuned on the validation set improves top-1 accuracy by 1.69 percentage points compared to a single reranker, demonstrating the effectiveness of ensemble learning in reducing overfitting.
- Fine-tuning the rerankers on the validation set increases accuracy across all top-k settings, with the best performance achieved when both ensemble and fine-tuning are applied.
- The reranking score enables a more efficient precision-recall trade-off than the beam search’s intrinsic log-likelihood score: at 50% precision, the reranking method retains 38.4% recall, while the beam score requires reducing recall to 22.4% to reach the same precision level.
- NSEdit performs robustly across diverse codebases and on concrete buggy programs, indicating strong generalization even when syntax is corrupted.
- The integration of CodeBERT and CodeGPT as backbone encoders and decoders further improves performance, confirming that pre-trained models on code can effectively transfer knowledge to edit sequence generation.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.