Code Generation Model Training for Syntax-Aware Program Completion
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Existing code generation methods based on conditional probability language models fail to effectively learn the semantics of program code, leading to inaccurate code generation due to the inability to capture structural information.
Innovation Solution
A code generation model is trained using a multi-task learning approach that combines a code understanding task to learn syntax and semantic features, and a code generation task to generate new code, utilizing masking techniques to enhance the model's understanding of program code.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Productivity
If a conditional probability language model is used for code generation, then the model can predict the next program symbol based on preceding text information, but the model fails to learn the semantics of program code and cannot capture structural information
Solution Approach 1:
The training task is segmented into two independent parts: a code understanding task for learning syntax and semantic features, and a code generation task for learning the generation process. This segmentation allows the model to separately master code comprehension and generation capabilities, resolving the contradiction between generation efficiency and accuracy.
Solution Approach 2:
The code understanding task is performed as a preliminary action before code generation. By first training the model to understand and capture syntax and semantic features through the code understanding task, the model builds a foundation of code knowledge that enhances subsequent code generation accuracy without sacrificing efficiency.
2Device complexity
If only statistical distribution of program symbols is learned, then the code generation process is simple, but the generated code lacks semantic understanding and structural information
Solution Approach 1:
The training process is segmented into distinct code understanding and code generation tasks. The code understanding task focuses on learning syntax and semantic features, while the code generation task focuses on generating new code. This segmentation increases reliability by ensuring the model separately masters both comprehension and generation, while the modular structure keeps the overall complexity manageable.
Solution Approach 2:
The model is designed to perform multiple functions through a unified architecture that handles both code understanding and code generation tasks. This multi-functionality improves reliability by enabling the model to leverage its understanding capabilities during generation, while the shared architecture avoids the need for separate systems, managing complexity effectively.
Data Source
AI summary
The present disclosure relates to a code generation method and apparatus, a storage medium, and an electronic device, to improve the accuracy of automatically generated code. The method includes: acquiring target text, where the target text includes program code text to be supplemented or natural language text for describing a code function; and inputting the target text into a code generation model to obtain a target program code generated based on the target text, where the code generation model is obtained by training a code understanding task and a code generation task, the code understanding task is used for the code generation model to learn a syntax feature and a semantic feature of a sample program code, and the code generation task is used for the code generation model to learn a process of generating a new program code based on the sample program code.


