[Paper Review] CodeGen-Test: An Automatic Code Generation Model Integrating Program Test Information
This paper proposes CodeGen-Test, a novel automatic code generation model that integrates program test information into an iterative generation process to improve functional correctness. By incorporating test feedback and using a new metric, Test-Acc, the model achieves a 6% absolute improvement in test accuracy over existing models, demonstrating that functional validation enhances code quality beyond syntax compliance.
Automatic code generation is to generate the program code according to the given natural language description. The current mainstream approach uses neural networks to encode natural language descriptions, and output abstract syntax trees (AST) at the decoder, then convert the AST into program code. While the generated code largely conforms to specific syntax rules, two problems are still ignored. One is missing program testing, an essential step in the process of complete code implementation; the other is only focusing on the syntax compliance of the generated code, while ignoring the more important program functional requirements. The paper proposes a CodeGen-Test model, which adds program testing steps and incorporates program testing information to iteratively generate code that meets the functional requirements of the program, thereby improving the quality of code generation. At the same time, the paper proposes a new evaluation metric, test accuracy (Test-Acc), which represents the proportion of passing program test in generated code. Different from the previous evaluation metric, which only evaluates the quality of code generation from the perspective of character similarity, the Test-Acc can evaluate the quality of code generation from the Program functions. Moreover, the paper evaluates the CodeGen-test model on a python data set "hearthstone legend". The experimental results show the proposed method can effectively improve the quality of generated code. Compared with the existing optimal model, CodeGen-Test model improves the Bleu value by 0.2%, Rouge-L value by 0.3% and Test-Acc by 6%.
Motivation & Objective
- To address the gap in current code generation models that focus only on syntax correctness and ignore functional validation.
- To enhance code quality by integrating program test results as feedback in an iterative generation process.
- To propose a new evaluation metric, Test-Acc, that measures functional correctness rather than just syntactic similarity.
- To validate the effectiveness of test information and iterative refinement in improving code generation performance.
Proposed method
- The model uses a sequence-to-sequence framework with a dual-encoder architecture: one for code and one for test information.
- It employs iterative refinement, where generated code is tested and feedback is used to guide subsequent generations.
- Test information is encoded separately and fused with code embeddings to guide the decoder in generating functionally correct code.
- The model is trained end-to-end on a Python dataset (Hearthstone Legend), with test results used as supervision signals in later iterations.
- A new evaluation metric, Test-Acc, is introduced to measure the proportion of generated code that passes functional tests.
- Abllation studies are conducted to evaluate the contribution of test information and code history in the iterative process.
Experimental results
Research questions
- RQ1Can integrating program test feedback into the code generation process improve functional correctness of generated code?
- RQ2How does the inclusion of test information affect the performance of code generation models?
- RQ3Does iterative refinement using test results lead to better code quality compared to single-pass generation?
- RQ4How does the proposed Test-Acc metric compare to traditional metrics like BLEU and ROUGE in evaluating functional correctness?
- RQ5What is the optimal number of iterations for the iterative code generation process?
Key findings
- CodeGen-Test improves Test-Acc by 6% compared to the best existing model, demonstrating significant gains in functional correctness.
- The model achieves a 0.2% higher BLEU score and a 0.3% higher ROUGE-L score than the state-of-the-art model.
- Ablation studies show that both test information and previous code history are essential for optimal performance, with the full model outperforming ablated versions.
- Performance improves with iteration count up to N=3, but gains plateau beyond N=2 due to data sparsity in later iterations.
- The number of training samples decreases significantly across iterations (from 533 to 104), limiting further improvement despite iterative refinement.
- The proposed Test-Acc metric effectively captures functional correctness, offering a more meaningful evaluation than syntax-based metrics alone.
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.