Code generation model training method based on Chinese prompt
By generating and integrating Chinese prompt code data sets and using the QLoRA fine-tuning method, the performance of the code generation model in Chinese programming scenarios is optimized, which solves the problem of the code generation model's insufficient understanding of Chinese prompts and achieves higher accuracy and Comprehension.
Patent Information
- Application Number
- CN202410894400.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-04
- Publication Date
- 2024-10-29
AI Technical Summary
Existing code generation models perform poorly in parsing and understanding Chinese prompts, mainly due to the lack of a large enough and professional Chinese prompt code data set, resulting in insufficient code generation capabilities of the model in Chinese programming scenarios.
By using artificial intelligence to generate a Chinese prompt code data set, and combining it with the English prompt code data set for cleaning and integration, the QLoRA efficient fine-tuning method is used to fine-tune the code generation base model and optimize the model's code generation capabilities in Chinese programming scenarios.
It improves the code generation model's ability to understand Chinese prompts. At the same time, without damaging the accuracy of the original model code generation, it further improves the accuracy and solves the problem of the scarcity of Chinese prompt code data sets.
Smart Images

Figure CN118860352A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of code generation, and in particular to a code generation model training method based on Chinese prompts. Background Art
[0002] The wide application of code large language models (Code LLMs) in the field of software engineering is increasingly attracting widespread attention in the industry. At present, there are relatively rich data sets in the field of code generation, which can be divided into two categories according to their uses. One type of data set is: natural language-code pairs<Text,Code> , which is mainly used to train and test large code models; the other type of data set contains programming problems and corresponding test cases, which are used to evaluate the executable capability of the code.<Text,Code> Datasets are usually crawled from websites such as GitHub and Stack Overflow, and researchers often use such data to train large code models to improve model performance.<Text,Code> The size of the dataset is usually large.
[0003] However, although the scale of code generation datasets is large, there are limitations in the distribution of languages, and the programming languages used are mainly Java and Python, and the natural language is mainly English. Therefore, although the existing code generation models have played a practical role in the software development process, the current research on large code models mainly focuses on the scenario of generating code with English prompts, which makes these models unable to parse and understand Chinese prompts. It is difficult to accurately capture the exact Chinese programming intentions and generate code that meets expectations. This is mainly due to the lack of a sufficiently large and professional Chinese prompt code dataset, which leads to a lack of sufficient training data and background knowledge when the model understands Chinese prompts and generates code based on them. In view of this, how to efficiently collect, organize and utilize Chinese prompt code datasets to improve the ability of large code models to understand and process Chinese prompts has become a problem that needs to be solved urgently. Summary of the invention
[0004] In view of the above problems, an embodiment of the present invention provides a code generation model training method based on Chinese prompts.
[0005] An embodiment of the present invention provides a code generation model training method based on Chinese prompts, comprising:
[0006] Use artificial intelligence AI to generate Chinese prompt code data sets;
[0007] Obtain an English prompt code dataset from an open source platform, and perform data cleaning and deduplication operations on the data in the English prompt code dataset;
[0008] Generate a training data set based on the Chinese prompt code data set and the English prompt code data set;
[0009] The QLoRA efficient fine-tuning method is used to fine-tune the code generation base model based on the training data set to optimize the code generation capability of the code generation base model in Chinese programming scenarios;
[0010] The fine-tuned code base model is trained using the training data set, and the code base model is adjusted based on the training results to obtain a code generation model.
[0011] Compared with the prior art, the beneficial effects of the present invention are: solving the problem of scarcity of Chinese prompt code data sets in the current code generation field, improving the code base model's ability to understand Chinese prompts through the Chinese prompt code data sets, and at the same time, without damaging the accuracy of the original model code generation, it also achieves further improvement in accuracy.
[0012] Optionally, the process of using artificial intelligence AI to generate a Chinese prompt code data set includes:
[0013] Organize the core knowledge points of programming languages to form an initial seed set;
[0014] Each seed in the initial seed set is embedded into a fixed task template to obtain a task prompt, wherein the task prompt is used to prompt the artificial intelligence AI to generate exercise questions related to a given core knowledge point;
[0015] Polish and optimize the obtained task prompts to make them accurate and diverse, and ensure that the task prompts can inspire the artificial intelligence AI to generate creative and targeted practice questions;
[0016] The polished and optimized task prompts are input to the artificial intelligence AI to generate practice questions corresponding to the core knowledge points;
[0017] For each generated exercise question, AI is used again to generate the corresponding answer;
[0018] The generated exercise questions and answers are combined to obtain the Chinese prompt code dataset, and the purity and efficiency of the Chinese prompt code dataset are ensured through deduplication operation.
[0019] Optionally, the process of obtaining the English prompt code dataset from the open source platform and performing cleaning and deduplication operations on the data in the English prompt code dataset includes:
[0020] Data collection phase
[0021] Collect and organize English prompt code datasets related to programming language generation tasks from the HuggingFace open source platform;
[0022] Data cleaning phase
[0023] There are two cleaning levels: the first-level cleaning strategy involves file attributes, including discarding large files that exceed the predetermined conditions and discarding abnormal texts; the second-level cleaning strategy relies on analyzing data features to clean up data that does not meet the requirements of grammatical correctness and code quality;
[0024] Data deduplication stage
[0025] Multi-granularity deduplication is performed on the English prompt code dataset: one is to calculate the hash value of the data. If the hash values of multiple data are the same, the data is considered to be duplicate data, and one of the duplicate data is retained; the other is to divide each data into blocks of fixed size and calculate the SimHash value of each block, weight the SimHash values of each block and aggregate them to obtain the SimHash value of the data. If the similarity between the SimHash values of the data exceeds the similarity threshold, it is considered to be duplicate data, and one of the duplicate data is retained.
[0026] Optionally, the secondary cleaning strategy relies on analyzing data features to clean up data that does not meet grammatical correctness and code quality requirements. The process includes:
[0027] Analyze the correctness, readability, redundancy, naming style, and coupling characteristics of the data, and clean up the data that does not meet the requirements of grammatical correctness and code quality.
[0028] Optionally, the process of generating a training data set based on the Chinese prompt code data set and the English prompt code data set includes:
[0029] Translating the English prompt code data set to obtain a translated Chinese prompt code data set, and generating a first mixed prompt code data set using the English prompt code data and the translated Chinese prompt code data set;
[0030] Translating the Chinese prompt code data set to obtain a translated English prompt code data set, and generating a second mixed prompt code data set using the Chinese prompt code data and the translated English prompt code data set;
[0031] A combined English prompt code dataset is generated by translating the English prompt code dataset and the English prompt code data, a combined Chinese prompt code dataset is generated by translating the Chinese prompt code dataset and the Chinese prompt code dataset, and a third mixed prompt code dataset is generated by combining the English prompt code dataset and the Chinese prompt code dataset.
[0032] Optionally, the process of training the fine-tuned code base model using the training dataset includes:
[0033] Phase 1: Use the English prompt code dataset, the translated English prompt code dataset, and the combined English prompt code dataset to train the code base model to collect the potential improvement effect of the dataset on the model's code generation ability;
[0034] Phase II: Use the Chinese prompt code dataset, the translated Chinese prompt code dataset, and the combined Chinese prompt code dataset to train the code-based model trained in the first phase to verify whether the dataset can improve the model's ability to understand Chinese prompts;
[0035] The third stage: Use the first mixed prompt code dataset, the second mixed prompt code dataset and the third mixed prompt code dataset to train the code base model trained in the second stage to explore whether the dataset can improve the model's understanding of Chinese prompts while ensuring the model's code generation performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] The drawings described herein are used to provide a further understanding of the present invention, constitute a part of the present application, and do not constitute a limitation of the present invention. In the drawings:
[0037] Figure 1 A flowchart of a code generation model training method based on Chinese prompts provided in an embodiment of the present invention;
[0038] Figure 2 A flowchart of a training data set integration process provided by an embodiment of the present invention;
[0039] Figure 3 A flowchart of a Chinese prompt code data set generation process provided by an embodiment of the present invention;
[0040] Figure 4 An example of an English prompt code data set provided by an embodiment of the present invention;
[0041] Figure 5 An example of a Chinese prompt code data set provided by an embodiment of the present invention;
[0042] Figure 6 The loss graph of the model training process provided by the embodiment of the present invention, wherein Figure a is the loss graph corresponding to the training of the translated Chinese prompt code dataset, Figure b is the loss graph corresponding to the training of the Chinese prompt code dataset, and Figure c is the loss graph corresponding to the training of the combined Chinese prompt code dataset. DETAILED DESCRIPTION
[0043] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the embodiments and the accompanying drawings. Here, the illustrative embodiments of the present invention and their descriptions are used to explain the present invention, but are not intended to limit the present invention.
[0044] See also Figure 1 , a code generation model training method based on Chinese prompts provided by an embodiment of the present invention comprises:
[0045] S1. Generate Chinese prompt code dataset using artificial intelligence AI;
[0046] S2. Obtain an English prompt code dataset from an open source platform, and perform cleaning and deduplication operations on the data in the English prompt code dataset;
[0047] S3, generating a training data set based on the Chinese prompt code data set and the English prompt code data set;
[0048] S4. Use the QLoRA efficient fine-tuning method to fine-tune the code generation base model based on the training data set to optimize the code generation capability of the code generation base model in the Chinese programming scenario;
[0049] S5. Use the training data set to train the fine-tuned code base model, and adjust the code base model based on the training results to obtain a code generation model.
[0050] In practice, the Chinese prompt code dataset constructed by the present invention mainly comes from two aspects: First, a rich dataset containing 25k programming exercises is generated using ChatGPT. In order to ensure the accuracy and reliability of these exercises and their answers, a ChatGPT model and manual dual supervision method are adopted to strictly review and proofread each exercise question and its answer. The dataset widely covers hundreds of Python-related core knowledge points such as basic grammar, data structure, algorithm application, database query and machine learning, such as Figure 5 The following is an example of a Chinese prompt code dataset. For details, see the specific generation process of the Chinese prompt code dataset. Figure 3 ,include:
[0051] Organize the core knowledge points of programming languages to form an initial seed set;
[0052] Each seed in the initial seed set is embedded into a fixed task template "Task Prompt" to obtain a task prompt, wherein the task prompt is used to prompt the artificial intelligence AI to generate exercise questions related to a given core knowledge point;
[0053] Polish and optimize the obtained task prompts to make them accurate and diverse, and ensure that the task prompts can inspire the artificial intelligence AI to generate creative and targeted practice questions;
[0054] The polished and optimized task prompts are input to the artificial intelligence AI to generate practice questions corresponding to the core knowledge points;
[0055] For each generated exercise question, AI is used again to generate the corresponding answer;
[0056] The generated exercise questions and answers are combined to obtain the Chinese prompt code dataset, and the purity and efficiency of the Chinese prompt code dataset are ensured through deduplication operation.
[0057] Next, we collected and organized 20k high-quality English prompt code datasets related to Python code generation tasks from HuggingFace, a well-known open source platform, such as Figure 4 The following is an example from the English prompt code dataset. In the process of collecting the English prompt code dataset, a systematic approach was adopted, including three key steps: data collection, data cleaning, and data deduplication, to ensure that the collected code data is both rich and accurate. Specifically:
[0058] Data collection phase
[0059] We collected and organized English prompt code datasets related to programming language generation tasks from the HuggingFace open source platform. The mobile phone code samples cover different fields and scenarios, which are both rich and diverse and have practical application value, laying a solid material foundation for subsequent data cleaning and deduplication operations.
[0060] Data cleaning phase
[0061] It is divided into two cleaning levels: the first-level cleaning strategy involves file attributes, including discarding large files that exceed predetermined conditions (such as files with more than 10,000 lines or single files larger than 1MB) and discarding abnormal texts (such as texts with an average length greater than 100 lines); the second-level cleaning strategy relies on analyzing data features to clean up data that does not meet grammatical correctness and code quality requirements.
[0062] In the data cleaning stage of collecting Python code datasets from the HuggingFace open source platform, the second-level filtering strategy mainly relies on program analysis. The specific data features will be analyzed from the following aspects:
[0063] Correctness Metrics: After performing syntax validation and error detection, it can be observed that the number of errors is inversely proportional to the code quality. The higher the error frequency, the lower the code quality.
[0064] Readability: Larger methods, classes, and more method parameters tend to be associated with lower code quality. This is due to the increased complexity and decreased readability that often accompanies large methods, classes, and more parameters.
[0065] Redundancy: The presence of redundant classes is a sign of poor code quality. Redundancy in classes often leads to increased complexity and reduced maintainability.
[0066] Naming style: Identifier names that are too long or too short can affect code quality. Short names may not adequately describe the purpose of the variable or function, while overly long names may hinder readability.
[0067] Coupling: It is a measure of the degree of association between modules. The strength of coupling depends on the complexity of the interface between modules, the way to call modules, and the amount of data transmitted through the interface. Coupling between modules refers to the dependency relationship between modules, including control relationship, calling relationship, data transmission relationship, etc.
[0068] Data deduplication stage
[0069] Multi-granularity deduplication is performed on the English prompt code dataset: one is to calculate the hash value of the data. If the hash values of multiple data are the same, the data is considered to be duplicate data, and one of the duplicate data is retained. Deduplication can be completed by calculating the MD5 hash value. MD5 is a widely used hash algorithm that can map data of any length to a 128-bit hash value. This hash value can uniquely identify the content of the file. The calculated MD5 hash values are compared. If the MD5 hash values of two or more files are found to be the same, it can be determined that they are duplicates; the second method is to divide each data into blocks of fixed size and calculate the SimHash value of each block. The SimHash values of each block are weighted and aggregated to obtain the SimHash value of the data. If the similarity between the SimHash values of the data exceeds the similarity threshold (such as ≥0.95), it is considered to be duplicate data, and one of the duplicate data is retained.
[0070] After completing the collection and integration of the above two data sets, a total of 45k high-quality code data sets were successfully gathered, of which 25k were Chinese prompt code data and 20k were English prompt code data. In order to further enrich and improve the Chinese prompt code data set, the GPT-4.0-turbo API was further called to accurately and fluently translate the English prompt part of the 20k data set (ie, the Instruction or Question part). At the same time, in order to build a more complete reference group and ensure the comprehensiveness and comparability of the data set, the prompt part of the original 25k Chinese prompt code data is also translated into the corresponding English. This two-way translation work ensures the accuracy and completeness of the code data set. Figure 2As shown in the figure, we finally obtained a high-quality Chinese (English) prompt code dataset containing 45k samples. At the same time, it can be open sourced to the Huggingface platform for use and reference by researchers. The construction of this dataset not only fills the gap in the field of code generation under Chinese prompts, but also provides strong data support for subsequent model training and performance improvement.
[0071] In one implementation, the training data set is generated based on 25k Chinese prompt code data, 25k English prompt code data, 20k English prompt code data, 20k Chinese prompt code data, 45k Chinese prompt code data, and 45k English prompt code data, specifically including:
[0072] Translating the English prompt code data set to obtain a translated Chinese prompt code data set, and generating a first mixed prompt code data set using the English prompt code data and the translated Chinese prompt code data set;
[0073] Translating the Chinese prompt code data set to obtain a translated English prompt code data set, and generating a second mixed prompt code data set using the Chinese prompt code data and the translated English prompt code data set;
[0074] A combined English prompt code dataset is generated by translating the English prompt code dataset and the English prompt code data, a combined Chinese prompt code dataset is generated by translating the Chinese prompt code dataset and the Chinese prompt code dataset, and a third mixed prompt code dataset is generated by combining the English prompt code dataset and the Chinese prompt code dataset.
[0075] The code base model selected is the CodeLlama-Python 7B model, which has 7B parameters. This version is specially optimized and adapted for the Python programming language, making it perform well in Python code generation tasks and enabling it to be optimized and adjusted under moderate computing resource conditions.
[0076] It is worth mentioning that although CodeLlama-Python 7B's performance in code generation tasks has not yet reached the level of top large models such as GPT4, precisely because of this feature, it has become an ideal candidate to demonstrate the potential impact of the technical solution of the present invention in improving the capabilities of large models.
[0077] In practice, fine-tuning of large models is an effective way to improve performance. Through fine-tuning, specific behaviors in the model can be added or eliminated. QLoRA efficient fine-tuning technology uses innovative high-precision methods to quantize the pre-trained model to 4 bits, and combines it with learnable low-rank adapter weights. By back-propagating gradients and adjusting quantized weights, it can save memory without sacrificing performance.
[0078] The entire training process of the code-based model is carefully divided into three stages. In the first stage, the model is first trained using English prompt data to observe the potential improvement effect of the collected code dataset on code generation capabilities, and serve as a control group for subsequent experiments. In the second stage, further fine-tuning experiments are conducted using the integrated Chinese prompt code dataset to verify whether this dataset can indeed improve the model's understanding of Chinese prompts. In the third stage, code data with mixed Chinese and English instructions is used to explore whether it is possible to improve the model's understanding of Chinese prompts while ensuring that its code generation performance is not damaged. That is, the specific training process includes:
[0079] Phase 1: Use the English prompt code dataset, the translated English prompt code dataset, and the combined English prompt code dataset to train the code base model to collect the potential improvement effect of the dataset on the model's code generation ability;
[0080] Phase II: Use the Chinese prompt code dataset, the translated Chinese prompt code dataset, and the combined Chinese prompt code dataset to train the code-based model trained in the first phase to verify whether the dataset can improve the model's ability to understand Chinese prompts;
[0081] The third stage: Use the first mixed prompt code dataset, the second mixed prompt code dataset and the third mixed prompt code dataset to train the code base model trained in the second stage to explore whether the dataset can improve the model's understanding of Chinese prompts while ensuring the model's code generation performance.
[0082] Experimental procedures
[0083] In view of the complexity of the code generation task and the extremely high requirements for accuracy, it is necessary to strictly control the quality of the dataset. After detailed data construction, a code dataset of Chinese, English and mixed instructions with a total of 45k samples (including 25k and 20k parts) was successfully constructed. This paper focuses on the supervised instruction fine-tuning training of the CodeLlama-Python 7B model. The core work is to enhance its ability to follow Chinese prompts. Based on these carefully constructed high-quality code datasets, a total of three main experiments were designed to comprehensively evaluate the performance of the model. Specifically:
[0084] 1) First, the CodeLlama-Python 7B model was trained on a series of 20k data sets. The experiment named CodeLlama-Python-20k is a pure English prompt code data control group experiment based on the 20k high-quality English prompt code data set collected by the HuggingFace platform; the experiment named CodeLlama-Python-20k-chinese uses the corresponding translated 20k Chinese prompt code data to train the model; and the experiment named CodeLlama-Python-20k-mix uses 20k Chinese and English mixed instruction code data (i.e. 20k English prompt code data + 20k Chinese prompt code data, a total of 40k data).
[0085] 2) Subsequently, a similar experimental design was used to train the CodeLlama-Python 7B model using the 25k Chinese prompt dataset generated by ChatGPT. The three models CodeLlama-Python-25k, CodeLlama-Python-25k-chinese, and CodeLlama-Python-25k-mix correspond to the training results of 25k samples of English prompt code data, 25k samples of Chinese prompt code data, and 50k samples of Chinese and English mixed instruction code data.
[0086] 3) Finally, the dataset size was further expanded, and the CodeLlama-Python 7B model was trained using the full 45k (25k+20k) dataset. Similarly, three models, CodeLlama-Python-45k, CodeLlama-Python-45k-chinese, and CodeLlama-Python-45k-mix, were trained, corresponding to the training results of 45k samples of English prompt code data, 45k samples of Chinese prompt code data, and 90k samples of Chinese and English mixed instruction code data.
[0087] Parameter configuration: Based on the fine-tuning experiment of the CodeLlama-Python 7B model, the key parameter configurations are listed in Table 1. These parameter configurations have an important impact on the accuracy and stability of the experimental results. Through careful selection and adjustment, the effectiveness and reliability of the experimental process are ensured.
[0088] Table 1 Experimental process model parameter configuration
[0089]
[0090] Loss: Figure 5As shown in the figure, no matter how big the training dataset is, the Loss value shows a sharp or slow decline in the early stage of training. After about two epochs, the training curve gradually stabilizes, showing a steady improvement in model performance. This phenomenon shows that as training progresses, the model gradually adapts to and learns the features in the dataset, thereby achieving more stable performance.
[0091] Comparison with baselines: The code generation performance of the nine models involved in the experiment (i.e., CodeLlama-Python-20k, CodeLlama-Python-20k-chinese, CodeLlama-Python-20k-mix, CodeLlama-Python-25k, CodeLlama-Python-25k-chinese, CodeLlama-Python-25k-mix, CodeLlama-Python-45k, CodeLlama-Python-45k-chinese, CodeLlama-Python-45k-mix) was evaluated on the HumanEval evaluation dataset in comparison with existing code language models (Code LLMs) of similar size. To ensure fairness, not only the score results of the nine models involved in the experiment are shown, but also the statistics of non-experimental models (such as StarCoder, CodeT5, etc.) in Table 2 are collected from existing reports.
[0092] Table 2. Scores of code models of similar size on HumanEval
[0093]
[0094] In the evaluation, the nine models involved in this experiment performed well. The scores not only improved further compared with the base model CodeLlama-Python, which already performed well, but also surpassed many other code-large models. This remarkable achievement strongly proves the effectiveness of the dataset carefully constructed in this chapter in improving the accuracy of code-large models in code generation tasks. This dataset not only enhances the understanding ability of the code-large model in the Chinese context, but also ensures that the model's code generation accuracy is not lost while its understanding ability of Chinese instructions is improved. Further analysis shows that the models trained on the English prompt dataset of the same scale often score higher than the models trained on the Chinese prompt dataset. This finding may be related to the fact that the training data that the CodeLlama model is exposed to during the training process are all English prompts, which makes the model's effect when learning Chinese prompt data slightly worse than English prompt data. However, it is worth noting that models such as WizardCoder and DeepseekCoder are specifically optimized for Python code generation tasks. Therefore, although the nine models involved in this experiment have shown impressive performance, they still face certain challenges in the evaluation of Python code generation tasks compared with these specifically optimized models.
[0095] Qualitative analysis: 1) The value of model specialization is significantly reflected in code generation capabilities
[0096] Through a series of comparative experiments, the performance improvement brought by model specialization is deeply explored. First, by comparing Llama2 and CodeLlama in Table 2, it can be found that although Llama2 is extensively trained on 2T tokens, only 500B tokens are additionally trained in the dataset related to the code task, which makes Llama270B perform roughly equivalent to CodeLlama 7B on the Python coding benchmark. This result highlights the importance of professional dataset training in improving model performance. Next, when further comparing CodeLlama and CodeLlama-Python, it can be found that although CodeLlama is trained on professional code datasets for more than two epochs, CodeLlama-Python, which is trained on 100B additional tokens of Python data combination, has made significant progress on the Python code generation benchmark. This fully proves that deep training for a specific task (such as Python code generation) can effectively improve the performance of the model on this task. Finally, CodeLlama-Python is compared with subsequent experimental models (such as CodeLlama-Python-20k, etc.). These experimental models have been fine-tuned in terms of data scale, training strategy, etc., further improving the performance of the model on Python code generation tasks. These results not only verify the effectiveness of model specialization, but also provide valuable experience and inspiration for subsequent research.
[0097] In summary, model specialization has significant value in improving code generation capabilities. Through in-depth training and adjustment for different tasks and fields, the performance of the model on specific tasks can be effectively improved, thereby better meeting the needs of actual applications.
[0098] 2) Chinese prompt code data promotes the Chinese prompt compliance ability of the code model
[0099] When faced with Chinese problem descriptions, models that have not been fine-tuned with Chinese prompt code data often produce some errors when outputting programs. However, after special fine-tuning training, the code-based model has significantly improved its ability to understand Chinese. It can more accurately understand Chinese problem descriptions and generate correct program results based on these understandings. This improvement not only enhances the practicality of the model, but also lays a solid foundation for its application in a wider Chinese context.
[0100] 3) Chinese and English mixed code data promotes code generation capabilities
[0101] From the scores of CodeLlama-Python-20k-mix and CodeLlama-Python-45k, and CodeLlama-Python-25k-mix and CodeLlama-Python-45k on the HumanEval benchmark in Table 1, we can clearly observe that, when the dataset size is similar, the Chinese-English mixed instruction code dataset has further improved its ability in code generation tasks compared to the pure English dataset. This finding not only verifies the effectiveness of the Chinese-English mixed instruction code dataset in model training, but also provides new ideas and methods for improving the performance of code generation models. By using Chinese-English mixed instruction code data, we can more comprehensively cover programming habits and code styles in different natural language environments, so that the model can better adapt to complex programming tasks.
[0102] In summary, the created Chinese enhanced code dataset is effective in improving the code big model's ability to understand Chinese prompts. It also proves that it can further improve the accuracy without compromising the accuracy of the original model's code generation. Through a series of carefully designed experiments, three important findings were also obtained: First, the value of model specialization is significantly reflected in the code generation ability, and specialized training significantly improves the model's performance on specific tasks. Second, the code data with Chinese prompts has played a significant role in promoting the code big model's ability to follow Chinese prompts, and improved the model's ability to understand instructions in the Chinese programming environment. Finally, the code data with mixed Chinese and English instructions has a positive role in promoting code generation capabilities. The use of mixed Chinese and English instruction code data enables the model to more comprehensively cover programming needs in different natural language environments.
[0103] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.
Claims
1. A code generation model training method based on Chinese prompts, characterized in that: include: Use artificial intelligence AI to generate Chinese prompt code data sets; Obtain an English prompt code dataset from an open source platform, and perform data cleaning and deduplication operations on the data in the English prompt code dataset; Generate a training data set based on the Chinese prompt code data set and the English prompt code data set; The QLoRA efficient fine-tuning method is used to fine-tune the code generation base model based on the training data set to optimize the code generation capability of the code generation base model in Chinese programming scenarios; The fine-tuned code base model is trained using the training data set, and the code base model is adjusted based on the training results to obtain a code generation model.
2. The code generation model training method based on Chinese prompts as claimed in claim 1, characterized in that: The process of using artificial intelligence AI to generate a Chinese prompt code dataset includes: Organize the core knowledge points of programming languages to form an initial seed set; Each seed in the initial seed set is respectively embedded into a fixed task template to obtain a task prompt, wherein the task prompt is used to prompt the artificial intelligence AI to generate exercise questions related to a given core knowledge point; Polish and optimize the obtained task prompts to make them accurate and diverse, and ensure that the task prompts can inspire the artificial intelligence AI to generate creative and targeted practice questions; The polished and optimized task prompts are input to the artificial intelligence AI to generate practice questions corresponding to the core knowledge points; For each generated exercise question, AI is used again to generate the corresponding answer; The generated exercise questions and answers are combined to obtain the Chinese prompt code dataset, and the purity and efficiency of the Chinese prompt code dataset are ensured through deduplication operation.
3. The code generation model training method based on Chinese prompts as claimed in claim 1, characterized in that: The process of obtaining the English prompt code dataset from the open source platform and cleaning and deduplicating the data in the English prompt code dataset includes: Data collection phase Collect and organize English prompt code datasets related to programming language generation tasks from the HuggingFace open source platform; Data cleaning phase There are two cleaning levels: the first-level cleaning strategy involves file attributes, including discarding large files that exceed the predetermined conditions and discarding abnormal texts; the second-level cleaning strategy relies on analyzing data features to clean up data that does not meet the requirements of grammatical correctness and code quality; Data deduplication stage Multi-granularity deduplication is performed on the English prompt code dataset: one is to calculate the hash value of the data. If the hash values of multiple data are the same, the data is considered to be duplicate data, and one of the duplicate data is retained; the other is to divide each data into blocks of fixed size and calculate the SimHash value of each block, weight the SimHash values of each block and aggregate them to obtain the SimHash value of the data. If the similarity between the SimHash values of the data exceeds the similarity threshold, it is considered to be duplicate data, and one of the duplicate data is retained.
4. The code generation model training method based on Chinese prompts as claimed in claim 3, characterized in that: The secondary cleaning strategy relies on analyzing data features. The process of cleaning data that does not meet the requirements of grammatical correctness and code quality includes: Analyze the correctness, readability, redundancy, naming style, and coupling characteristics of the data, and clean up the data that does not meet the requirements of grammatical correctness and code quality.
5. The code generation model training method based on Chinese prompts as claimed in claim 1, characterized in that: The process of generating a training dataset based on the Chinese prompt code dataset and the English prompt code dataset includes: Translating the English prompt code data set to obtain a translated Chinese prompt code data set, and generating a first mixed prompt code data set using the English prompt code data and the translated Chinese prompt code data set; Translating the Chinese prompt code data set to obtain a translated English prompt code data set, and generating a second mixed prompt code data set using the Chinese prompt code data and the translated English prompt code data set; A combined English prompt code dataset is generated by translating the English prompt code dataset and the English prompt code data, a combined Chinese prompt code dataset is generated by translating the Chinese prompt code dataset and the Chinese prompt code dataset, and a third mixed prompt code dataset is generated by combining the English prompt code dataset and the Chinese prompt code dataset.
6. The code generation model training method based on Chinese prompts as claimed in claim 5, characterized in that: The process of training the fine-tuned code base model using the training dataset includes: Phase 1: Use the English prompt code dataset, the translated English prompt code dataset, and the combined English prompt code dataset to train the code base model to collect the potential improvement effect of the dataset on the model's code generation ability; Phase II: Use the Chinese prompt code dataset, the translated Chinese prompt code dataset, and the combined Chinese prompt code dataset to train the code-based model trained in the first phase to verify whether the dataset can improve the model's ability to understand Chinese prompts; The third stage: Use the first mixed prompt code dataset, the second mixed prompt code dataset and the third mixed prompt code dataset to train the code base model trained in the second stage to explore whether the dataset can improve the model's understanding of Chinese prompts while ensuring the model's code generation performance.
Citation Information
Cited By
Code generation model training method and electronic equipment
CN120822039A
