Method, device, electronic device and medium for generating code error correction model

By continuing to pre-train the pre-trained language model and masking the loss of the correct code segment during the training process, the problem of low prediction accuracy of the code error correction model is solved, achieving higher prediction accuracy and shorter training time.

CN118747133BActive Publication Date: 2025-04-29BEIJING VOLCANO ENGINE TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410961695.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-17
Publication Date
2025-04-29
Estimated Expiration
2044-07-17

AI Technical Summary

Technical Problem

The prediction accuracy of existing code error correction models is low, mainly due to the high loss weight of the correct code segment, which makes the model more inclined to predict based on the correct code segment during training rather than truly mastering the ability to correct code errors.

Method used

The pre-trained language model is continued to be pre-trained by using the sample set of the target programming language, and during the training process, the loss weight of the correct code segment is reduced by masking the loss of a part of the correct code segment, thereby adjusting the parameters of the language model and generating a more accurate code error correction model.

Benefits of technology

It improves the prediction accuracy of the code error correction model, saves training time, reduces the amount of calculation required to calculate the total loss, and shortens the number of training rounds of the language model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118747133B_ABST
    Figure CN118747133B_ABST
Patent Text Reader

Abstract

Embodiments of the present disclosure relate to methods, devices, electronic devices, and media for generating a code correction model. The method includes continuing to pre-train a pre-trained language model using a first sample set of a target programming language. The method also includes determining the masked loss of the language model that continues to be pre-trained by masking a portion of the correct code segment based on a second sample set of the target programming language, and each second sample in the second sample set includes an erroneous code segment and a correct code segment. In addition, the method also includes training the language model that continues to be pre-trained according to the masked loss to generate a code correction model. According to the method of the present disclosure, the accuracy of code correction can be significantly improved, while reducing the time consumption of generating a code correction model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure generally relates to the field of computers, and more particularly, to a method, apparatus, electronic device, and medium for generating a code error correction model. Background Art

[0002] At present, technologies such as neural networks and deep learning are developing rapidly, and artificial intelligence models of various types and functions have emerged. Among them, language models are artificial intelligence models based on machine learning and natural language processing technologies. They learn language patterns and structures by training massive amounts of text data, so that they can understand and generate human language. These models can capture the deep features of language, including grammar, semantics, contextual dependencies, and long-term dependencies during unsupervised learning.

[0003] At present, language models can be applied in various fields of human life, such as intelligent assistants and chatbots, content creation, search engine optimization, education and learning, customer service, finance and investment, etc., which have a profound impact on human life. Summary of the invention

[0004] Embodiments of the present disclosure provide a method, an apparatus, an electronic device, and a computer-readable storage medium for generating a code error correction model.

[0005] According to a first aspect of the present disclosure, a method for generating a code error correction model is provided. The method includes continuing to pre-train a pre-trained language model using a first sample set of a target programming language. The method also includes determining the masked loss of the language model that continues to be pre-trained by masking a portion of the correct code segment based on a second sample set of the target programming language, each second sample in the second sample set including an erroneous code segment and a correct code segment. In addition, the method also includes training the language model that continues to be pre-trained according to the masked loss to generate a code error correction model.

[0006] In a second aspect of the present disclosure, a device for generating a code error correction model is provided. The device includes a continued pre-training module, which is configured to continue pre-training the pre-trained language model using a first sample set of a target programming language. The device also includes a loss determination module, which is configured to determine the masked loss of the continued pre-trained language model by masking a portion of the correct code segment based on a second sample set of the target programming language, each second sample in the second sample set including an erroneous code segment and a correct code segment. In addition, the device also includes a generation module, which is configured to train the continued pre-trained language model according to the masked loss to generate a code error correction model.

[0007] According to a third aspect of the present disclosure, an electronic device is provided, comprising a processor and a memory coupled to the processor, wherein the memory has instructions stored therein, and when the instructions are executed by the processor, the electronic device executes the method according to the first aspect.

[0008] In a fourth aspect of the present disclosure, a computer-readable storage medium is provided, wherein one or more computer instructions are stored on the computer-readable storage medium, wherein the one or more computer instructions are executed by a processor to implement the method according to the first aspect.

[0009] The purpose of this Summary is to introduce a selection of concepts in a simplified form that are further described in the Detailed Description below. This Summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to limit the scope of the claimed subject matter. BRIEF DESCRIPTION OF THE DRAWINGS

[0010] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. In the accompanying drawings, the same or similar reference numerals represent the same or similar elements, wherein:

[0011] Figure 1 A schematic diagram illustrating an example environment in which various embodiments of the present disclosure may be implemented;

[0012] Figure 2 A flow chart of a method for generating a code error correction model according to an embodiment of the present disclosure is shown;

[0013] Figure 3 A flow chart of a method for generating a code error correction model according to an embodiment of the present disclosure is shown;

[0014] Figure 4 A schematic diagram of determining a mask according to an embodiment of the present disclosure is shown;

[0015] Figure 5 A schematic diagram showing determination of masked losses according to an embodiment of the present disclosure is shown;

[0016] Figure 6 A block diagram of an apparatus for generating a code error correction model according to some embodiments of the present disclosure is shown;

[0017] Figure 7 A block diagram of an electronic device according to some embodiments of the present disclosure is shown.

[0018] Throughout the drawings, the same or similar reference numbers denote the same or similar elements. DETAILED DESCRIPTION

[0019] It is understandable that the data involved in this technical solution (including but not limited to the data itself, the acquisition or use of the data) shall comply with the requirements of relevant laws, regulations and relevant provisions.

[0020] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.

[0021] In the description of the embodiments of the present disclosure, the term "including" and similar terms should be understood as open inclusion, that is, "including but not limited to". The term "based on" should be understood as "based at least in part on". The term "one embodiment" or "the embodiment" should be understood as "at least one embodiment". The terms "first", "second", etc. may refer to different or the same objects, unless explicitly stated. Other explicit and implicit definitions may also be included below.

[0022] At present, it is necessary to generate a language model (i.e., a code correction model) that can automatically perform code correction, so as to improve work efficiency. In the related art, when fine-tuning the code correction model, in order to improve the accuracy of the prediction, a supervised training method is usually adopted for adjustment. The language model is allowed to master a certain code correction ability by allowing the code correction model to fit the mapping relationship between the sample code segment and the corresponding correct code segment during the generation process. However, due to various reasons, the current prediction accuracy of the code correction model is relatively low, mostly staying at around 30%, for example. In order to improve the accuracy, the related technical solutions usually focus on increasing the number of samples used for training.

[0023] The inventors have found that in the field of code correction, because the number of correct code segments usually far exceeds the number of erroneous code segments, the basis for adjusting parameters each time in the process of generating code correction models in related technologies is mainly the prediction loss caused by the correct code segments. Therefore, a large amount of training for code correction models is how to predict correct code segments based on correct code segments. The prediction ability learned in this way is not what the code correction task needs most. The inventors have found and concluded that the excessively high loss weight of the correct code segments in the samples used for training is an important reason for the relatively low prediction accuracy of the current code correction models.

[0024] In this regard, the present disclosure proposes a method for generating a code error correction model. The method includes continuing to pre-train a pre-trained language model using a first sample set of a target programming language. The method also includes determining the masked loss of the language model that continues to be pre-trained by masking a portion of the correct code segment based on a second sample set of the target programming language, and each second sample in the second sample set includes an erroneous code segment and a correct code segment. In addition, the method also includes training the language model that continues to be pre-trained according to the masked loss to generate a code error correction model.

[0025] According to the method disclosed in the present invention, not only is the sample set of the target programming language used for training in the continued pre-training stage, so that the model has preliminary code error correction capabilities, but also on this basis, by masking the loss of the correct code segment when calculating the total loss, the loss weight of the correct code segment can be reduced, and the parameters of the language model are adjusted using the masked loss, thereby improving the prediction accuracy of the code error correction model. In addition, the method disclosed in the present invention can also save training time, which is not only reflected in the saving of the amount of calculation required to calculate the total loss through masking, but also in the greatly shortened number of training rounds (epochs) of the language model.

[0026] Figure 1 1 is a schematic diagram of an example environment 100 in which embodiments according to the present disclosure may be implemented. Figure 1 As shown, the environment 100 may include a client 102, a network 104, a service unit 106, a sample set 108, an error code segment 110, and a correct code segment 112. The sample set 108 is used to generate a code error correction model. The service unit 106 is communicatively coupled with the client 102 through the network 104. The network 104 may be, for example, a wide area network (WAN), a local area network (LAN), a wireless network, a public telephone network, an intranet, and any other type of network known to those skilled in the art.

[0027] In this embodiment, the method for code error correction is performed by the service unit 106. The method performed by the service unit 106 includes the following steps. The service unit 106 uses a sample set (not shown) for continuing pre-training of the target programming language to continue pre-training to continue pre-training the pre-trained language model. The pre-trained language model can be generated by local pre-training in the service unit 106, or it can be pre-trained and obtained elsewhere. The pre-trained language model can be obtained from the client 102, or it can be saved locally, or it can be a pre-trained language model obtained from other places through the network 104. The target programming language can be any type of programming language supported by the software and hardware in the service unit 106. By using the sample set for continuing pre-training of the target programming language for pre-training, the language model that continues to be pre-trained can have preliminary code error correction capabilities, laying the foundation for subsequent operations.

[0028] Further, the service unit 106 determines the masked loss of the language model that continues to be pre-trained by masking a portion of the correct code segments based on the sample set 108 of the target programming language, and each second sample in the sample set 108 includes an erroneous code segment and a correct code segment. Examples of the second sample may be the various code segment samples shown in the sample set 108. The mask used to mask a portion of the correct code segment may come from the client 102 via the network 104, or may be a mask locally stored by the service unit 106.

[0029] In addition, the service unit 106 trains the pre-trained language model according to the masked loss to generate a code correction model. The service unit 106 can adopt various algorithms for adjusting parameters for training, and can repeatedly train the code correction model using the sample set 108 in the aforementioned manner (determining the loss and adjusting the parameters) for multiple epochs, thereby improving the prediction ability of the code correction model.

[0030] In some embodiments, a portion of samples and corresponding labels can be set as a test set. The test set is used to test the language models that have been trained for different rounds, and a language model with better performance is selected as the above-mentioned code correction model. After generating the code correction model, the service unit 106 can save it locally, for example, save the various parameters of the code correction model, thereby saving the ability learned by the code correction model. In this way, when the code correction model needs to be used at any time, the service unit 106 can be directly requested to call the code correction model locally to provide corresponding prediction services.

[0031] In some embodiments, when using the code correction model, the service unit 106 obtains the error code segment 110 from the client 102 via the network 104. The service unit 106 generates a correct code segment 112 corresponding to the target error code segment according to the code correction model, and transmits it to the client 112 via the network 104.

[0032] like Figure 1 As shown, in the environment 100, the network 104 can be used to transmit data between the client 102 and the service unit 106. The network 104 has a theoretical bandwidth, which refers to the maximum transmission speed supported by the network 104, which indicates the maximum amount of data that the network 104 can transmit under ideal conditions, usually measured in bits per second (bps). For example, if the theoretical bandwidth of the network 104 is 100Mbps, it means that it can transmit one hundred megabits of data per second under ideal conditions. However, in reality, due to other factors that may exist in the network (e.g., signal interference, bandwidth sharing, transmission delay, etc.), the actual transmission speed of 100Mbps may not be achieved.

[0033] As understood by those skilled in the art, an instance of the service unit 106 may be an independent physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. The servers may be directly or indirectly connected via wired or wireless communications, which is not limited in this application.

[0034] The client 102 may be any type of mobile computing device, including a mobile computer (e.g., a personal digital assistant (PDA), a laptop computer, a notebook computer, a tablet computer, a netbook, etc.), a mobile phone (e.g., a cellular phone, a smart phone, etc.), a wearable computing device (e.g., a smart watch, a head-mounted device, including smart glasses, etc.), or other types of mobile devices. In some embodiments, the client 102 may also be a fixed computing device, such as a desktop computer, a game console, a smart TV, etc. It should be understood that, if the client 102 has sufficient computing power, the client 102 may replace the service unit 106 to complete the above operations, or the client 102 and the service unit 106 may jointly complete the above operations.

[0035] It should be understood that the architecture and functions in the example environment 100 are described for exemplary purposes only and do not imply any limitation on the scope of the present disclosure. Embodiments of the present disclosure may also be applied to other environments with different structures and / or functions.

[0036] The following will combine Figures 2 to 7 The process according to the embodiment of the present disclosure is described in detail. For ease of understanding, the specific data mentioned in the following description are exemplary and are not intended to limit the scope of protection of the present disclosure. It is understood that the embodiments described below may also include additional actions not shown and / or the actions shown may be omitted, and the scope of the present disclosure is not limited in this respect.

[0037] Figure 2 A flowchart of a method 200 for generating a code error correction model according to certain embodiments of the present disclosure is shown. In box 202, a sample set (i.e., a first sample set) for continuing pre-training of a target programming language is used to continue pre-training to continue pre-training of a pre-trained language model. The language model can be any type of language model, for example, a large language model (LLM). The language model can be pre-trained using a variety of samples, for example, various sample libraries or data sets provided on the Internet can be used. In this operation, the initialized language model can be pre-trained to obtain a pre-trained language model, or an existing pre-trained language model can be directly used. A programming language is a formalized language used to express computer programs, which can be recognized and executed by a computer. A programming language is generally composed of a series of predefined grammatical structures and semantic rules, which define how to write valid instruction sequences. For example, the target programming language can be a structured query language (SQL), and the samples in the sample set (i.e., the first sample set) for continuing pre-training are code segments written in the SQL language. The continued pre-training in this operation can be either supervised training or various training methods such as unsupervised training. In the continued pre-training phase, a sample set of the target programming language is used for training, so that the model has preliminary code error correction capabilities.

[0038] In box 204, based on the sample set of the target programming language, the masked loss of the language model that continues to be pre-trained is determined by masking a portion of the correct code segment, and each second sample in the sample set includes an erroneous code segment and a correct code segment. The sample set (i.e., the second sample set) is a sample set for generating a code error correction model. A code segment refers to one or more lines of code. A correct code segment refers to a code segment that does not generate a compilation error. Accordingly, an erroneous code segment indicates a code segment that causes a subsequent compilation process to report an error or report a warning. "Masking a portion of the correct code segment" means that for all the correct code segments in the sample set, when calculating the loss, the loss of the masked portion of the correct code segment is no longer calculated. For example, for each second sample, the predicted loss caused by a few lines of correct code of its correct code segment may no longer be calculated. For another example, for several second samples, the predicted loss caused by all the correct code segments of each second sample may no longer be calculated, and only the loss caused by the erroneous code segment may be calculated. For another example, for several second samples, the predicted loss caused by a few lines of correct code of the correct code segment of each second sample may no longer be calculated. As mentioned above, in the field of code error correction, the inventors found that the loss weight of the correct code segment was too high. Therefore, when fine-tuning the language model, the loss weight of the correct code segment was reduced by masking a part of the correct code segment.

[0039] In block 206, the pre-trained language model is trained according to the masked loss to generate a code error correction model. The "training" here means using the masked loss to optimize the parameters of the pre-trained language model so that the loss of the next prediction of the pre-trained language model is reduced and the prediction is more accurate. Various methods of adjusting parameters can be selected in this operation, including but not limited to the gradient descent algorithm and the adaptive momentum estimation algorithm.

[0040] According to the method disclosed in the present invention, not only is the sample set of the target programming language used for training in the continued pre-training stage, so that the model has preliminary code error correction capabilities, but also on this basis, by masking the loss of the correct code segment when calculating the total loss, the loss weight of the correct code segment can be reduced, and the parameters of the language model are adjusted using the masked loss, thereby improving the prediction accuracy of the code error correction model. In addition, the method disclosed in the present invention can also save training time, which is not only reflected in the saving of the amount of calculation required to calculate the total loss through masking, but also in the greatly shortened number of training rounds (epochs) of the language model.

[0041] In some embodiments, the next token prediction (NTP) method is used to implement the continued pre-training at box 202 to further optimize its language understanding ability. This embodiment includes dividing the sample set used for continued pre-training into multiple sample subsets. Each sample subset may include several samples. The purpose of this division is to implement multi-batch training for the pre-trained language model. This embodiment also includes iteratively predicting each word element using the pre-trained language model according to each sample subset to obtain each corresponding first prediction result. This section describes the core process of continued pre-training-predicting the next word element. The goal of the language model is to predict the next possible word element (index of a word, character or subword) through the input sample and the predicted word element. This process is repeated until the sequence ends. The first prediction result can be mapped based on the word element.

[0042] This embodiment also includes adjusting the pre-trained language model according to each first prediction result to obtain a language model that continues to be pre-trained. When continuing to pre-train the language model, the complete sample set is often very large. In this embodiment, in order to improve computing efficiency and memory management, the data set is divided into several subsets (or batches), and only one subset is used to update the model parameters each time. In this way, limited computing resources can be utilized, and the entire data set can be traversed through multiple iterations to achieve better training results. In addition, the continued pre-training method of the next word prediction is conducive to the language model to master preliminary prediction capabilities for code error correction.

[0043] Figure 3 A flow chart of a method for generating a code error correction model according to an embodiment of the present disclosure is shown. First, an arbitrary initialized language model is obtained. For the initialized language model, the initialized language model is pre-trained using a general sample at 302 to obtain a pre-trained language model at 304. Then, the pre-trained language model is pre-trained using a sample set of the target programming language at 306 (i.e., a sample set for continued pre-training), for example, using the NTP training method, to obtain a continued pre-trained language model at 310. Labeled samples (i.e., a second sample set) can also be used to fine-tune the continued pre-trained language model to generate a code error correction model at 312.

[0044] Calculating the loss for masking a portion of the correct code can be achieved in some embodiments by the following operation. The operation includes determining the difference mark of each second sample based on the sample set and the corresponding label set used to generate the model. As above, the second sample includes both the correct code segment and the error code segment, and the label reflects all the correct code segments after correcting the error code segment. Therefore, in order to mask a portion of the correct code segment, it is necessary to compare each second sample with the corresponding label to determine which ones are correct and which ones are wrong.

[0045] For example, the difference mark can be set to a one-dimensional vector, each element of which indicates whether the corresponding code line is correct or incorrect. And in some embodiments, in response to a line of code of the sample being correct, the element corresponding to the line of code is set to a first value (e.g., "0"). In response to a line of code of the sample being incorrect, the element corresponding to the line of code is set to a second value (e.g., "1"), and the second value is different from the first value. This embodiment provides a simple and effective method for determining a mask, which can improve prediction accuracy and training efficiency.

[0046] The operation also includes setting a mask for the correct code segment according to the difference mark of each second sample. The mask can be a mask set uniformly for all second samples, for example, the code segment between the Nth line and the N+Mth line of the correct code segment is masked, or it can be a mask set separately for each second sample. In addition, the mask can be set randomly or according to predetermined parameters. In some embodiments, the difference mark indicates whether multiple lines of code in the corresponding second sample are correct codes or error codes, and accordingly, the mask indicates the number of lines of the masked code segment in the correct code segment.

[0047] Figure 4 A schematic diagram of determining a mask according to an embodiment of the present disclosure is shown. Figure 4 402 in represents the second sample, and 404 represents the corresponding label. In the second sample 402, the correct code segments are the 1st line of code, the 2nd line of code, the 4th line of code, the 5th line of code, and the 7th line of code, and the incorrect code segments are the 3rd line of code and the 6th line of code. By comparison, the difference label of the second sample 302 can be set to a one-dimensional vector 406, that is, (0, 0, 1, 0, 0, 1, 0), where "0" indicates that the corresponding code line is correct and "1" indicates that the corresponding code line is incorrect. Figure 4 In the illustrated embodiment, the mask may be set to 2, so that when calculating the loss of the second sample, the second line of code for the second sample 402 does not calculate the loss.

[0048] Returning to the aforementioned embodiment, the operation further includes determining the prediction result of each second sample by continuing to pre-train the language model. The prediction result may indicate what the correct code predicted by the language model continuing to pre-train for the second sample should be, thereby implementing code error correction for the second sample. Of course, it is not necessarily the correct code that is completely consistent with the label, but only the code predicted by the language model continuing to pre-train.

[0049] The operation also includes determining the masked loss of the sample set based on the mask according to the label set and the prediction result of each second sample. The prediction loss can be determined by comparing the label and the prediction result. This embodiment provides a simple and easy way to determine the mask and the mask loss, thereby improving the efficiency of generating a code error correction model.

[0050] In some embodiments, each unmasked code segment is determined from the corresponding prediction result of each second sample according to the mask. This embodiment also includes determining the loss of each second sample according to each unmasked code segment and the corresponding label. This embodiment also includes determining the masked loss of the sample set according to the loss of each second sample. This embodiment provides a specific implementation of masking the correct code segment, which does not need to calculate the loss of the masked part, thereby improving the training speed and computing resources.

[0051] Figure 5 A schematic diagram of determining masked losses according to an embodiment of the present disclosure is shown. Figure 5 The left side is the loss determination method without masking, and the right side is the loss determination method with masking.

[0052] For the case on the left, 502 indicates the input sample data, which can be obtained by processing according to the prompt engineering. 504 indicates a part of the correct code segment. 506 indicates the wrong code segment. 508 indicates another part of the correct code segment. 530 indicates the total loss. After the prediction result of a second sample is determined using the language model 510 that has been pre-trained, the losses caused by the code segments 504, 506, and 508 will be calculated as the unmasked loss 530. The model parameters are subsequently adjusted according to the unmasked loss 530.

[0053] For the case on the right, 512 indicates the same sample data input, which can be obtained by processing according to the prompt engineering. 514 indicates a part of the correct code segment of 504. 516 indicates the correct code segment masked in 504. 518 indicates another part of the correct code segment in 504. 520 indicates an incorrect code segment. 522 indicates a part of the correct code segment of 508. 524 indicates the correct code segment masked in 508. 526 indicates another part of the correct code segment in 508. 532 indicates the total loss. After the prediction result of the second sample is determined using the language model 528 that has been pre-trained, only the losses caused by the code segments 514, 518, 520, 522, and 526 will be calculated as the masked loss 532. The model parameters are subsequently adjusted according to the masked loss 532.

[0054] In addition, for determining the prediction result of each second sample, each second sample can be input into a language model that has been pre-trained. For example, the sample can be pre-processed using a prompt project to analyze and obtain information such as code content. Then, the language model that has been pre-trained iteratively predicts each word unit according to the next word prediction NTP method. A word unit is an index of several characters, and finally, the corresponding prediction result of each second sample is determined according to each unit. Determining the prediction result by the next word prediction NTP method can improve the prediction accuracy.

[0055] When preparing a sample set (i.e., the second sample set) for generating a model, a large amount of manual annotation work is often required. In some embodiments, a number of initial samples and corresponding multiple initial labels of the target programming language can be obtained, and the multiple initial labels can be input into another language model for prediction to obtain multiple predicted samples. This embodiment also includes using the multiple predicted samples and the multiple initial samples together as a sample set for generating a model.

[0056] In this embodiment, another language model is used to make predictions with the label representing the correct code segment as input. If the prediction result is inconsistent with the input sample, it means that the prediction result is wrong. At this time, the prediction result can be recorded and added to the sample set, and its label is the input label, so as to automatically obtain a second sample. This can save a lot of manpower and improve the efficiency of preparing sample sets.

[0057] After the code error correction model is generated, the model can be directly called to perform code error correction. For example, a target error code segment can be obtained, and a target correct code segment corresponding to the target error code segment can be generated according to the code error correction model generated in the above embodiment, thereby achieving code error correction.

[0058] Figure 6FIG. 6 is a block diagram of an apparatus 600 for generating a code error correction model according to some embodiments of the present disclosure. Figure 6 As shown, the device 600 includes a continuing pre-training module 602, which is configured to continue pre-training the pre-trained language model using a sample set for continuing pre-training of the target programming language. The device 600 also includes a loss determination module 604, which is configured to determine the masked loss of the language model that continues to be pre-trained by masking a portion of the correct code segment based on a second sample set of the target programming language, and each second sample in the second sample set includes an erroneous code segment and a correct code segment. In addition, the device 600 also includes a generation module 606, which is configured to train the language model that continues to be pre-trained according to the masked loss to generate a code error correction model.

[0059] Figure 7 A block diagram of an electronic device 700 is shown in accordance with certain embodiments of the present disclosure. Figure 7 FIG. 1 is a block diagram of an electronic device 700 according to some embodiments of the present disclosure. The device 700 may be a device or apparatus described in an embodiment of the present disclosure. Figure 7 As shown, the device 700 includes a central processing unit (CPU) and / or a graphics processing unit (GPU) 701, which can perform various appropriate actions and processes according to computer program instructions stored in a read-only memory (ROM) 702 or computer program instructions loaded from a storage unit 708 to a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the device 700 can also be stored. The CPU / GPU 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704. Although not shown in FIG. Figure 7 As shown in FIG. 7 , device 700 may further include a coprocessor.

[0060] A number of components in the device 700 are connected to the I / O interface 705, including: an input unit 706, such as a keyboard, a mouse, etc.; an output unit 707, such as various types of displays, speakers, etc.; a storage unit 708, such as a disk, an optical disk, etc.; and a communication unit 709, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 709 allows the device 700 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0061] The various methods or processes described above may be performed by the CPU / GPU 701. For example, in some embodiments, the methods may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 708. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 700 via the ROM 702 and / or the communication unit 709. When the computer program is loaded into the RAM 703 and executed by the CPU / GPU 701, one or more steps or actions in the methods or processes described above may be performed.

[0062] In some embodiments, the methods and processes described above may be implemented as a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for executing various aspects of the present disclosure.

[0063] Computer readable storage medium can be a tangible device that can hold and store instructions used by an instruction execution device. Computer readable storage medium can be, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination thereof. More specific examples (non-exhaustive list) of computer readable storage medium include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, for example, a punch card or a convex structure in a groove on which instructions are stored, and any suitable combination thereof. The computer readable storage medium used here is not interpreted as a transient signal itself, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagated by a waveguide or other transmission medium (for example, a light pulse by an optical fiber cable), or an electrical signal transmitted by a wire.

[0064] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.

[0065] The computer program instructions for performing the disclosed operation may be assembler instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, programming languages ​​including object-oriented programming languages, and conventional procedural programming languages. Computer-readable program instructions may be executed completely on a user's computer, partially on a user's computer, executed as an independent software package, partially on a user's computer, partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., utilizing an Internet service provider to connect via the Internet). In certain embodiments, by utilizing the state information of a computer-readable program instruction to customize an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), the electronic circuit may execute a computer-readable program instruction, thereby realizing various aspects of the present disclosure.

[0066] These computer-readable program instructions can be provided to a processing unit of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processing unit of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0067] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0068] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the equipment, method and computer program product according to multiple embodiments of the present disclosure. In this regard, each frame in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of a module, program segment or instruction includes one or more executable instructions for realizing the specified logical function. In some implementations as replacements, the functions marked in the frame can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous frames can actually be executed substantially in parallel, and they can sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each frame in the block diagram and / or flow chart, and the combination of frames in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.

[0069] The embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The choice of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.

[0070] Some example implementations of the present disclosure are listed below.

[0071] Example 1. A method for generating a code error correction model, comprising:

[0072] Continue pre-training the pre-trained language model using a first sample set of the target programming language;

[0073] determining a masked loss of the continued pre-trained language model by masking a portion of correct code segments based on a second set of samples of the target programming language, each second sample in the second set of samples including an erroneous code segment and a correct code segment; and

[0074] The continued pre-trained language model is trained according to the masked loss to generate the code error correction model.

[0075] Example 2. The method according to Example 1, wherein continuing to pre-train the pre-trained language model using the first sample set of the target programming language comprises:

[0076] Dividing the first sample set into a plurality of first sample subsets;

[0077] According to each first sample subset, using the pre-trained language model to iteratively predict each word unit to obtain each corresponding first prediction result; and

[0078] The pre-trained language model is adjusted according to each first prediction result to obtain the continuously pre-trained language model.

[0079] Example 3. The method of Examples 1-2, wherein determining the masked loss of the continued pre-trained language model by masking a portion of correct code based on a second sample set of the target programming language comprises:

[0080] Determining a differential label for each second sample according to the second sample set and the corresponding label set;

[0081] According to the difference mark of each second sample, setting a mask for the correct code segment;

[0082] Determining a prediction result for each second sample by using the language model that has been continuously pre-trained; and

[0083] Based on the mask, a masked loss for the second set of samples is determined according to the set of labels and the prediction result of each second sample.

[0084] Example 4. The method of Examples 1-3, wherein based on the mask, determining the masked loss of the second set of samples according to the set of labels and the prediction result of each second sample comprises:

[0085] determining each unmasked code segment from a corresponding prediction result of each second sample according to the mask;

[0086] Determining the loss of each second sample according to each unmasked code segment and the corresponding label; and

[0087] A masked loss for the second set of samples is determined based on the loss of each second sample.

[0088] Example 5. The method according to Examples 1-4, wherein the difference mark indicates whether a plurality of lines of code in the corresponding second sample are correct codes or incorrect codes, respectively, and the mask indicates the number of lines of the masked code segment in the correct code segment.

[0089] Example 6. The method according to examples 1-5 further includes:

[0090] Setting the difference flag to a one-dimensional vector;

[0091] In response to a line of code of the second sample being correct, setting an element corresponding to the line of code to a first value; and

[0092] In response to a line of code of the second sample being erroneous, an element corresponding to the line of code is set to a second value, where the second value is different from the first value.

[0093] Example 7. The method according to Examples 1-6, wherein determining the prediction result of each second sample by the continued pre-trained language model comprises:

[0094] Input each second sample into the language model that has been continuously pre-trained;

[0095] Iteratively predicting each word-gram by the continuously pre-trained language model; and

[0096] A corresponding prediction result of each second sample is determined according to each dimension.

[0097] Example 8. The method according to Examples 1-7, wherein before determining the masked loss of the continued pre-trained language model by masking a portion of correct code based on a second sample set of the target programming language, the method further comprises:

[0098] Acquire a plurality of initial samples and corresponding initial labels of the target programming language;

[0099] Inputting the multiple initial labels into another language model for prediction to obtain multiple prediction samples; and

[0100] The multiple predicted samples and the multiple initial samples are taken together as the second sample set.

[0101] Example 9. The method of Examples 1-8, further comprising:

[0102] Get the target error code segment; and

[0103] A target correct code segment corresponding to the target erroneous code segment is generated according to the code error correction model.

[0104] Example 10. A device for generating a code error correction model, the device comprising:

[0105] A continuing pre-training module is configured to continue pre-training the pre-trained language model using a first sample set of the target programming language;

[0106] a loss determination module configured to determine a masked loss of the continued pre-trained language model by masking a portion of correct code segments based on a second sample set of the target programming language, each second sample in the second sample set including an erroneous code segment and a correct code segment; and

[0107] A generating module is configured to train the pre-trained language model according to the masked loss to generate the code error correction model.

[0108] Example 11. The apparatus of Example 10, wherein the continuing pre-training module comprises:

[0109] a division module, configured to divide the first sample set into a plurality of first sample subsets;

[0110] A first prediction module is configured to iteratively predict each word unit using the pre-trained language model according to each first sample subset to obtain each corresponding first prediction result; and

[0111] The first adjustment module is configured to adjust the pre-trained language model according to each first prediction result to obtain the continuously pre-trained language model.

[0112] Example 12. The apparatus of Examples 10-11, wherein the loss determination module comprises:

[0113] a difference marking module, configured to determine a difference marking of each second sample according to the second sample set and the corresponding label set;

[0114] a mask determination module configured to set a mask for the correct code segment according to the difference mark of each second sample;

[0115] A second prediction module, configured to determine a prediction result of each second sample by using the pre-trained language model; and

[0116] The second loss determination module is configured to determine the masked loss of the second sample set according to the label set and the prediction result of each second sample based on the mask.

[0117] Example 13. The apparatus of Examples 10-12, wherein the second loss determination module comprises:

[0118] A selection module configured to determine each unmasked code segment from the corresponding prediction result of each second sample according to the mask;

[0119] A third loss determination module, configured to determine the loss of each second sample according to each unmasked code segment and the corresponding label; and

[0120] A fourth loss determination module is configured to determine the masked loss of the second sample set according to the loss of each second sample.

[0121] Example 14. The apparatus of Examples 10-13, wherein the difference mark indicates whether a plurality of lines of code in the corresponding second sample are correct codes or error codes, respectively, and the mask indicates the number of lines of the masked code segment in the correct code segment.

[0122] Example 15. The apparatus of Examples 10-14, further comprising:

[0123] A vector setting module, configured to set the difference mark to a one-dimensional vector;

[0124] A first element setting module, configured to, in response to a line of code of the second sample being correct, set an element corresponding to the line of code to a first value; and

[0125] The second element setting module is configured to set the element corresponding to a line of code of the second sample to a second value in response to the line of code being erroneous, wherein the second value is different from the first value.

[0126] Example 16. The apparatus of Examples 10-15, wherein the second prediction module comprises:

[0127] A first input module, configured to input each second sample into the language model that has been continuously pre-trained;

[0128] A third prediction module, configured to iteratively predict each word unit using the continuously pre-trained language model; and

[0129] The fourth prediction module is configured to determine a corresponding prediction result of each second sample according to each dimension.

[0130] Example 17. The apparatus of Examples 10-16, further comprising:

[0131] A first acquisition module is configured to acquire a plurality of initial samples and corresponding initial labels of the target programming language;

[0132] a reverse prediction module, configured to input the multiple initial labels into another language model for prediction to obtain multiple prediction samples; and

[0133] The sample determination module is configured to use the multiple predicted samples and the multiple initial samples together as the second sample set.

[0134] Example 18. The apparatus of Examples 10-17, further comprising:

[0135] A second acquisition module is configured to acquire a target error code segment; and

[0136] The correction module is configured to generate a target correct code segment corresponding to the target erroneous code segment according to the code error correction model.

[0137] Example 19. An electronic device comprising:

[0138] Processor; and

[0139] a memory coupled to the processor, the memory having instructions stored therein, the instructions, when executed by the processor, causing the device to perform actions, the actions comprising:

[0140] Continue pre-training the pre-trained language model using a first sample set of the target programming language;

[0141] determining a masked loss of the continued pre-trained language model by masking a portion of correct code segments based on a second set of samples of the target programming language, each second sample in the second set of samples including an erroneous code segment and a correct code segment; and

[0142] The continued pre-trained language model is trained according to the masked loss to generate the code error correction model.

[0143] Example 20. The electronic device of Example 19, wherein continuing to pre-train the pre-trained language model using the first sample set of the target programming language comprises:

[0144] Dividing the first sample set into a plurality of first sample subsets;

[0145] According to each first sample subset, using the pre-trained language model to iteratively predict each word unit to obtain each corresponding first prediction result; and

[0146] The pre-trained language model is adjusted according to each first prediction result to obtain the continuously pre-trained language model.

[0147] Example 21. The electronic device of Examples 19-20, wherein based on a second sample set of the target programming language, determining the masked loss of the continued pre-trained language model by masking a portion of correct code comprises:

[0148] Determining a differential label for each second sample according to the second sample set and the corresponding label set;

[0149] According to the difference mark of each second sample, setting a mask for the correct code segment;

[0150] Determining a prediction result for each second sample by using the language model that has been continuously pre-trained; and

[0151] Based on the mask, a masked loss for the second set of samples is determined according to the set of labels and the prediction result of each second sample.

[0152] Example 22. An electronic device according to Examples 19-21, wherein based on the mask, determining the masked loss of the second set of samples according to the set of labels and the prediction result of each second sample comprises:

[0153] determining each unmasked code segment from a corresponding prediction result of each second sample according to the mask;

[0154] Determining the loss of each second sample according to each unmasked code segment and the corresponding label; and

[0155] A masked loss for the second set of samples is determined based on the loss of each second sample.

[0156] Example 23. An electronic device according to Examples 19-22, wherein the difference mark indicates whether a plurality of lines of code in the corresponding second sample are correct codes or error codes, respectively, and the mask indicates the number of lines of the masked code segment in the correct code segment.

[0157] Example 24. The electronic device of Examples 19-23, wherein the actions further include:

[0158] Setting the difference flag to a one-dimensional vector;

[0159] In response to a line of code of the second sample being correct, setting an element corresponding to the line of code to a first value; and

[0160] In response to a line of code of the second sample being erroneous, an element corresponding to the line of code is set to a second value, where the second value is different from the first value.

[0161] Example 25. The electronic device of Examples 19-24, wherein determining a prediction result of each second sample by the continued pre-trained language model comprises:

[0162] Input each second sample into the language model that has been continuously pre-trained;

[0163] Iteratively predicting each word-gram by the continuously pre-trained language model; and

[0164] A corresponding prediction result of each second sample is determined according to each dimension.

[0165] Example 26. The electronic device of Examples 19-25, wherein before determining the masked loss of the continued pre-trained language model by masking a portion of correct code based on a second sample set of the target programming language, the actions further include:

[0166] Acquire a plurality of initial samples and corresponding initial labels of the target programming language;

[0167] Inputting the multiple initial labels into another language model for prediction to obtain multiple prediction samples; and

[0168] The multiple predicted samples and the multiple initial samples are taken together as the second sample set.

[0169] Example 27. The electronic device of Examples 19-26, wherein the actions further include:

[0170] Get the target error code segment; and

[0171] A target correct code segment corresponding to the target erroneous code segment is generated according to the code error correction model.

[0172] Example 28. A computer-readable storage medium having one or more computer instructions stored thereon, wherein the one or more computer instructions are executed by a processor to implement the method according to any one of Examples 1 to 9.

[0173] Example 29. A computer program product tangibly stored on a computer-readable medium and comprising computer-executable instructions that, when executed by a device, cause the device to perform a method according to any one of Examples 1 to 9.

[0174] Although the disclosure has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. Instead, the specific features and actions described above are merely example forms of implementing the claims.

Claims

1. A method for generating a code error correction model, comprising: Continue pre-training the pre-trained language model using a first sample set of the target programming language; Based on a second sample set of the target programming language, determining a masked loss of the continued pre-trained language model by masking a portion of correct code segments, each second sample in the second sample set including an erroneous code segment and a correct code segment, the masked loss excluding a loss of the masked portion of correct code segments for at least a portion of the second samples of the second sample set; as well as The continued pre-trained language model is trained according to the masked loss to generate the code error correction model.

2. The method according to claim 1, wherein continuing to pre-train the pre-trained language model using the first sample set of the target programming language comprises: Dividing the first sample set into a plurality of first sample subsets; According to each first sample subset, use the pre-trained language model to iteratively predict each word unit to obtain each corresponding first prediction result; as well as The pre-trained language model is adjusted according to each first prediction result to obtain the continuously pre-trained language model.

3. The method according to claim 1, wherein determining the masked loss of the continued pre-trained language model by masking a portion of correct code based on the second sample set of the target programming language comprises: Determining a differential label for each second sample according to the second sample set and the corresponding label set; According to the difference mark of each second sample, setting a mask for the correct code segment; Determining a prediction result for each second sample by using the language model that has been continuously pre-trained; as well as Based on the mask, a masked loss for the second set of samples is determined according to the set of labels and the prediction result of each second sample.

4. The method of claim 3, wherein determining the masked loss of the second set of samples according to the label set and the prediction result of each second sample based on the mask comprises: determining each unmasked code segment from a corresponding prediction result of each second sample according to the mask; Determine the loss of each second sample according to each unmasked code segment and the corresponding label; as well as A masked loss for the second set of samples is determined based on the loss of each second sample. 5 . The method according to claim 3 , wherein the difference mark indicates whether a plurality of lines of code in the corresponding second sample are correct codes or error codes, respectively, and the mask indicates the number of lines of the masked code segment in the correct code segment.

6. The method according to claim 5, further comprising: Setting the difference flag to a one-dimensional vector; In response to a line of code of the second sample being correct, setting an element corresponding to the line of code to a first value; and In response to a line of code of the second sample being erroneous, an element corresponding to the line of code is set to a second value, where the second value is different from the first value.

7. The method according to claim 3, wherein determining the prediction result of each second sample by the language model that continues to be pre-trained comprises: Input each second sample into the language model that has been continuously pre-trained; Iteratively predicting each word unit by the continuously pre-trained language model; as well as A corresponding prediction result of each second sample is determined according to each dimension.

8. The method according to claim 1, wherein before determining the masked loss of the continued pre-trained language model by masking a portion of correct code based on the second sample set of the target programming language, the method further comprises: Acquire a plurality of initial samples and corresponding initial labels of the target programming language; Inputting the multiple initial labels into another language model for prediction to obtain multiple prediction samples; as well as The multiple predicted samples and the multiple initial samples are taken together as the second sample set.

9. The method according to claim 1, further comprising: Get the target error code segment; as well as A target correct code segment corresponding to the target erroneous code segment is generated according to the code error correction model.

10. A device for generating a code error correction model, comprising: A continuing pre-training module is configured to continue pre-training the pre-trained language model using a first sample set of the target programming language; a loss determination module configured to determine, based on a second sample set of the target programming language, a masked loss of the language model that continues to be pre-trained by masking a portion of correct code segments, each second sample in the second sample set including an erroneous code segment and a correct code segment, the masked loss excluding the loss of the masked portion of correct code segments for at least a portion of the second samples in the second sample set; as well as A generating module is configured to train the pre-trained language model according to the masked loss to generate the code error correction model.

11. An electronic device, comprising: processor; as well as A memory coupled to the processor, the memory having instructions stored therein, wherein when the instructions are executed by the processor, the electronic device executes the method according to any one of claims 1 to 9.

12. A computer-readable storage medium having computer-executable instructions stored thereon, wherein the computer-executable instructions are executed by a processor to implement the method according to any one of claims 1 to 9.

Citation Information

Patent Citations

  • Processing method for pre-training language model, and spoken language understanding system

    CN114023306A

  • Text error correction model training method and device and text error correction method and device

    CN114048733A