Training of large language model for text error correction, error correction method and related device
By annotating and joint loss training on the sets for the wrong correct sentences, the problem of wasting correct text and overfitting the model in text error correction is solved, and the accuracy and generalization performance of error correction are improved.
Patent Information
- Application Number
- CN202510070331.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-16
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2045-01-16
AI Technical Summary
The prior art has problems in text error correction, the model is prone to overfitting, and poor generalization performance.
By obtaining the wrong correct sentence pair set, the forward error correction preference label and the negative error correction preference label are marked for the wrong text and correct text of each subset respectively. Preset joint loss is used to train the large language model for preference tuning to obtain a large language model for text error correction.
It avoids the waste of correct text, reduces the risk of model overfitting, and improves the generalization performance and error correction accuracy of the model.
Smart Images

Figure CN119494000B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of text error correction, and in particular to a training and error correction method of a large language model for text error correction and related devices. Background Art
[0002] During the training phase, existing large language models used for text error correction usually use a rule system to construct pairs of error-correct sentence pairs as training corpus, and then use the supervised fine-tuning (SFT) method to tune and train the large language model based on the training corpus to obtain a large language model that has the ability to generate correct text based on the original text.
[0003] However, due to the fact that multiple people have annotated an incorrect text, there may be multiple correct texts corresponding to it. In order to avoid the multiple correct texts bringing bad training effects to the SFT training process of the large language model, usually only one of the correct texts is selected to be included in the training corpus, resulting in the waste of some correct texts.
[0004] In addition, the SFT training process uses cross entropy loss, which is prone to overfitting and poor generalization performance after multiple rounds of training on a large language model. Summary of the invention
[0005] In view of the above problems, this application provides a training and correction method of a large language model for text error correction and related devices to solve the problems of waste of correct text, easy overfitting of the model, and poor generalization performance in the prior art. The specific solution is as follows:
[0006] The first aspect of the present application provides a method for training a large language model for text error correction, comprising:
[0007] Obtaining a set of incorrect and correct sentence pairs, wherein the set of incorrect and correct sentence pairs includes a plurality of subsets, each subset includes an incorrect text and at least one corresponding correct text, and the incorrect texts in different subsets are different;
[0008] For each erroneous text and each corresponding correct text contained in each subset, a positive error correction preference label and a negative error correction preference label are respectively marked for the erroneous text and the correct text to obtain a first training corpus, wherein the positive error correction preference label is a label of the correct text, and the negative error correction preference label is a label of the erroneous text;
[0009] Based on the first training corpus, a preset joint loss is used to perform preference tuning training on the initial large language model to obtain a large language model for text correction, wherein the preset joint loss is composed of a supervision loss and a preference loss, the supervision loss is used to measure the difference between the first output of the initial large language model and the positive error correction preference label, and the preference loss is used to measure the label that the initial large language model is more inclined to select with respect to the positive error correction preference label and the negative error correction preference label.
[0010] In a possible implementation, based on the first training corpus, using a preset joint loss to perform preference tuning training on the initial large language model to obtain a large language model for text error correction includes:
[0011] For each erroneous text and each corresponding correct text contained in each subset, a positive verification preference label and a negative verification preference label are respectively marked for the erroneous text and the correct text to obtain a second training corpus, wherein the positive verification preference label is a label representing a correct judgment result of whether the corresponding text has an error, and the negative verification preference label is a label representing an incorrect judgment result of whether the corresponding text has an error;
[0012] Based on the first training corpus and the second training corpus, the initial large language model is trained by using a preset joint loss to obtain the large language model for text error correction;
[0013] The supervised loss is also used to measure the difference between the second output of the initial large language model and the positive verification preference label, and the preference loss is also used to measure the label that the initial large language model is more inclined to select with respect to the positive verification preference label and the negative verification preference label.
[0014] In a possible implementation, the preference loss is the ratio of the probability of the initial large language model outputting a positive preference label to the probability of the initial large language model outputting a negative preference label, wherein, when the positive preference label is the positive error correction preference label, the negative preference label is the negative error correction preference label, and when the positive preference label is the positive verification preference label, the negative preference label is the negative verification preference label.
[0015] In one possible implementation, the supervised loss is a negative log-likelihood loss.
[0016] The second aspect of the present application provides a text error correction method, comprising:
[0017] Obtain the original text to be corrected;
[0018] Generate a first prompt instruction prompt based on the original text;
[0019] Inputting the first prompt instruction prompt into the large language model for text error correction of any implementation of the first aspect to obtain an error correction verification result indicating whether the original text has an error;
[0020] If the error correction verification result is an error, generating a second prompt instruction prompt based on the original text;
[0021] The second prompt instruction prompt is input into the large language model for text error correction in any implementation of the first aspect above, to obtain a corrected text corresponding to the original text.
[0022] The third aspect of the present application provides a training device for a large language model for text error correction, comprising:
[0023] A training text acquisition module, used to acquire a set of incorrect and correct sentence pairs, wherein the set of incorrect and correct sentence pairs includes a plurality of subsets, each subset includes an incorrect text and at least one corresponding correct text, and the incorrect texts in different subsets are different;
[0024] A first corpus generation module is used to label the erroneous text and each corresponding correct text contained in each subset with a positive error correction preference label and a negative error correction preference label, respectively, to obtain a first training corpus, wherein the positive error correction preference label is a label of the correct text, and the negative error correction preference label is a label of the erroneous text;
[0025] A large model training module is used to perform preference tuning training on an initial large language model based on the first training corpus using a preset joint loss to obtain a large language model for text error correction, wherein the preset joint loss is composed of a supervision loss and a preference loss, the supervision loss is used to measure the difference between the first output of the initial large language model and the positive error correction preference label, and the preference loss is used to measure the label that the initial large language model is more inclined to select with respect to the positive error correction preference label and the negative error correction preference label.
[0026] A fourth aspect of the present application provides a text error correction device, comprising:
[0027] A predicted text acquisition module is used to acquire the original text to be corrected;
[0028] A first instruction generating module, used for generating a first prompt instruction prompt based on the original text;
[0029] an error determination module, configured to input the first prompt instruction prompt into the large language model for text error correction of any implementation of the first aspect, and obtain an error correction verification result indicating whether the original text has an error;
[0030] A second instruction generating module, configured to generate a second prompt instruction prompt based on the original text when the error correction verification result is an error;
[0031] A text correction module is used to input the second prompt instruction prompt into the large language model for text correction in any implementation method of the first aspect above, to obtain a corrected text corresponding to the original text.
[0032] In a fifth aspect, the present application provides a computer program product, comprising computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements the training method of a large language model for text correction according to the first aspect or any implementation of the first aspect, or implements the text correction method according to the second aspect.
[0033] A sixth aspect of the present application provides an electronic device, comprising at least one processor and a memory connected to the processor, wherein:
[0034] The memory is used to store computer programs;
[0035] The processor is used to execute the computer program so that the electronic device can implement the training method of a large language model for text correction according to the first aspect or any implementation of the first aspect, or implement the text correction method according to the second aspect.
[0036] In a seventh aspect, the present application provides a computer storage medium, which carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement the training method of a large language model for text correction according to the first aspect or any implementation of the first aspect, or implement the text correction method according to the second aspect.
[0037] By means of the above technical scheme, the training method of the large language model for text error correction provided by the present application, for the erroneous text contained in each subset of the set of error-correct sentence pairs and each corresponding correct text, the erroneous text and the correct text are respectively labeled with positive error correction preference labels and negative error correction preference labels to obtain a first training corpus, and based on the first training corpus, the initial large language model is subjected to preference tuning training using a preset joint loss to obtain a large language model for text error correction, wherein the joint loss is composed of a supervision loss and a preference loss, the supervision loss is used to measure the difference between the first output of the initial large language model and the positive error correction preference label, and the preference loss is used to measure the label that the initial large language model is more inclined to select for the positive error correction preference label and the negative error correction preference label. It can be seen from this that the present application can not only generate training corpus based on erroneous text, but also generate training corpus based on each correct text corresponding to the erroneous text, thereby avoiding the waste of correct text. Furthermore, the present application can not only mark positive error correction preference labels, but also mark negative error correction preference labels, and jointly train the initial large language model based on the two types of labels and the corresponding joint losses, so that the trained model is less likely to overfit, thereby improving the generalization performance of the model and improving the accuracy of the error correction of the large language model trained for text error correction. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] 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. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale.
[0039] Figure 1 A schematic diagram of a system architecture provided for this application;
[0040] Figure 2 A schematic diagram of an optional hardware structure of the terminal 100 provided in this application;
[0041] Figure 3 A schematic diagram of the structure of a server 200 provided in this application;
[0042] Figure 4 A schematic diagram of the training process of a large language model for text error correction provided by the prior art;
[0043] Figure 5 A flowchart of a method for training a large language model for text error correction provided in this application;
[0044] Figure 6 A schematic diagram of two sets of error correction preference training data constructed with error texts as error correction prompts;
[0045] Figure 7 A schematic diagram of two sets of error correction preference training data constructed with correct texts as error correction prompts;
[0046] Figure 8 A schematic diagram of a set of verification preference training data constructed using error texts as verification prompts;
[0047] Fig. 9 A schematic diagram of two sets of verification preference training data constructed with correct text as verification prompt instructions;
[0048] Fig.10 A schematic diagram of the training process of a large language model for text error correction provided by the prior art;
[0049] Fig.11 A flowchart of a text error correction method provided by this application;
[0050] Fig.12 A schematic diagram of the structure of a large language model training device for text error correction provided by the present application;
[0051] Fig.13 A structural schematic diagram of a text error correction device provided by this application;
[0052] Fig.14 A schematic diagram of the structure of an electronic device provided in this application. DETAILED DESCRIPTION
[0053] The following describes the embodiments of the present application in conjunction with the drawings in the embodiments of the present application. The terms used in the implementation method section of the present application are only used to explain the specific embodiments of the present application, and are not intended to limit the present application.
[0054] The embodiments of the present application are described below in conjunction with the accompanying drawings. Those skilled in the art will appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0055] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, which is only to describe the distinction mode adopted by the objects of the same attributes when describing in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.
[0056] See also Figure 1 , Figure 1 A schematic diagram of a system architecture is shown. The system may include a terminal 100 and a server 200. The server 200 may include one or more servers ( Figure 1 In the example, a server is included, and the server 200 can provide the method provided in the embodiment of the present application for one or more terminals.
[0057] Among them, an application can be installed on the terminal 100, and the above application and web page can provide an interface. The terminal 100 can receive relevant parameters entered by the user on the interface and send the above parameters to the server 200. The server 200 can obtain processing results based on the received parameters and return the processing results to the terminal 100.
[0058] It should be understood that in some optional implementations, the terminal 100 can also complete the action of obtaining the processing result based on the received parameters by itself without the cooperation of the server, and the embodiments of the present application are not limited to this.
[0059] Next describe Figure 1 The product form of the mid-terminal 100;
[0060] The terminal 100 in the embodiment of the present application can be a mobile phone, a tablet computer, a wearable device, a vehicle-mounted device, an augmented reality (AR) / virtual reality (VR) device, a laptop computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), etc., and the embodiment of the present application does not impose any restrictions on this.
[0061] Figure 2 An optional hardware structure diagram of the terminal 100 is shown.
[0062] refer to Figure 2 As shown, the terminal 100 may include a radio frequency unit 110, a memory 120, an input unit 130, a display unit 140, a camera 150 (optional), an audio circuit 160 (optional), a speaker 161 (optional), a microphone 162 (optional), an earphone jack 163 (optional), a processor 170, an external interface 180, a power supply 190 and other components. Those skilled in the art will appreciate that Figure 2 These are merely examples of terminals or multi-function devices and do not constitute limitations on the terminals or multi-function devices, which may include more or fewer components than those shown in the figures, or combinations of certain components, or different components.
[0063] The input unit 130 can be used to receive input digital or character information, and generate key signal input related to the user settings and function control of the portable multifunctional device. Specifically, the input unit 130 may include a touch screen 131 (optional) and / or other input devices 132. The touch screen 131 can collect the user's touch operations on or near it (such as the user's operation on or near the touch screen using any suitable object such as fingers, joints, stylus, etc.), and drive the corresponding connection device according to a pre-set program. The touch screen can detect the user's touch action on the touch screen, convert the touch action into a touch signal and send it to the processor 170, and can receive and execute the command sent by the processor 170; the touch signal at least includes the touch point coordinate information. The touch screen 131 can provide an input interface and an output interface between the terminal 100 and the user. In addition, the touch screen can be implemented using multiple types such as resistive, capacitive, infrared and surface acoustic wave. In addition to the touch screen 131, the input unit 130 can also include other input devices. Specifically, other input devices 132 may include, but are not limited to, one or more of a physical keyboard, function keys (such as a volume control key, a switch key, etc.), a trackball, a mouse, a joystick, and the like.
[0064] Among them, the input device 132 can receive input data and the like.
[0065] The display unit 140 may be used to display information input by a user or provided to a user, various menus of the terminal 100, an interactive interface, file display, and / or playback of any multimedia file.
[0066] The memory 120 can be used to store instructions and data. The memory 120 can mainly include an instruction storage area and a data storage area. The data storage area can store various data, such as multimedia files, texts, etc.; the instruction storage area can store software units such as operating systems, applications, instructions required for at least one function, or their subsets and extensions. It can also include a non-volatile random access memory; provide the processor 170 with hardware, software and data resources including management of computing and processing equipment, and support control software and applications. It is also used for the storage of multimedia files, and the storage of running programs and applications.
[0067] The processor 170 is the control center of the terminal 100. It uses various interfaces and lines to connect various parts of the entire terminal 100. By running or executing instructions stored in the memory 120 and calling data stored in the memory 120, it executes various functions of the terminal 100 and processes data, thereby controlling the terminal device as a whole. Optionally, the processor 170 may include one or more processing units; preferably, the processor 170 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface and application program, and the modem processor mainly processes wireless communication. It is understandable that the above-mentioned modem processor may not be integrated into the processor 170. In some embodiments, the processor and the memory may be implemented on a single chip, and in some embodiments, they may also be implemented separately on separate chips. The processor 170 may also be used to generate corresponding operation control signals, send them to corresponding components of the computing and processing device, read and process data in the software, especially read and process data and programs in the memory 120, so that each functional module therein performs corresponding functions, thereby controlling the corresponding components to act according to the requirements of the instructions.
[0068] Among them, the memory 120 can be used to store the training method of the large language model for text correction or the software code related to the text correction method, the processor 170 can execute the training method of the large language model for text correction or the steps of the text correction method, and can also schedule other units (such as the above-mentioned input unit 130 and the display unit 140) to implement corresponding functions.
[0069] The radio frequency unit 110 (optional) can be used for receiving and sending information or receiving and sending signals during a call, for example, after receiving the downlink information of the base station, it is sent to the processor 170 for processing; in addition, the designed uplink data is sent to the base station. Generally, the RF circuit includes but is not limited to an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier (Low Noise Amplifier, LNA), a duplexer, etc. In addition, the radio frequency unit 110 can also communicate with network devices and other devices through wireless communication. The wireless communication can use any communication standard or protocol, including but not limited to Global System of Mobile Communication (Global System of Mobile Communication, GSM), General Packet Radio Service (General Packet Radio Service, GPRS), Code Division Multiple Access (Code Division Multiple Access, CDMA), Wideband Code Division Multiple Access (Wideband Code Division Multiple Access, WCDMA), Long Term Evolution (Long Term Evolution, LTE), email, Short Messaging Service (SMS), etc.
[0070] In this embodiment of the present application, the RF unit 110 can send data to the server 200 and receive processing results sent by the server 200.
[0071] It should be understood that the radio frequency unit 110 is optional and can be replaced by other communication interfaces, such as a network port.
[0072] The terminal 100 also includes a power supply 190 (such as a battery) for supplying power to various components. Preferably, the power supply can be logically connected to the processor 170 through a power management system, so that the power management system can manage functions such as charging, discharging, and power consumption.
[0073] The terminal 100 further includes an external interface 180 , which may be a standard Micro USB interface or a multi-pin connector, and may be used to connect the terminal 100 to communicate with other devices, or to connect a charger to charge the terminal 100 .
[0074] Although not shown, the terminal 100 may also include a flashlight, a wireless fidelity (WiFi) module, a Bluetooth module, sensors with different functions, etc., which are not described in detail here. Some or all of the methods described below may be applied in the following embodiments. Figure 2 In the terminal 100 shown.
[0075] Next describe Figure 1 The product form of the server 200;
[0076] Figure 3 A structural diagram of a server 200 is provided, such as Figure 3 As shown, the server 200 includes a bus 201, a processor 202, a communication interface 203, and a memory 204. The processor 202, the memory 204, and the communication interface 203 communicate with each other via the bus 201.
[0077] The bus 201 may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 3 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0078] The processor 202 may be any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).
[0079] The memory 204 may include a volatile memory, such as a random access memory (RAM). The memory 204 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD), or a solid state drive (SSD).
[0080] Among them, the memory 204 can be used to store the training method of the large language model for text correction or the software code related to the text correction method, the processor 202 can execute the steps of the training method of the large language model for text correction or the text correction method of the chip, and can also schedule other units to implement corresponding functions.
[0081] It should be understood that the above-mentioned terminal 100 and server 200 can be centralized or distributed devices, and the processors in the above-mentioned terminal 100 and server 200 (such as processor 170 and processor 202) can be hardware circuits (such as application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), general-purpose processors, DSPs, microprocessors or microcontrollers, etc.), or a combination of these hardware circuits. For example, the processor can be a hardware system with an instruction execution function, such as a CPU, DSP, etc., or a hardware system without an instruction execution function, such as an ASIC, FPGA, etc., or a combination of the above-mentioned hardware systems without an instruction execution function and hardware systems with an instruction execution function.
[0082] See also Figure 4 , which is a schematic diagram of the training process of a large language model for text error correction provided by the prior art.
[0083] For the incorrect text "She didn't attend the party because she was sick and couldn't go out", the corresponding correct texts include correct text 1 "She didn't attend the party because she was sick and couldn't go out" and correct text 2 "She didn't attend the party because she was sick and couldn't go out".
[0084] In order to avoid the trouble caused by multiple correct texts to a large language model, the prior art usually selects one from multiple correct texts for use. For example, one is selected from the above-mentioned correct text 1 and correct text 2, and the SFT instruction tuning data is constructed in combination with the incorrect text. For example, the instruction prompt is "Please check whether there are spelling, grammatical or logical errors in the following text separated by ```. If there are any errors, modify and output the modified text. ``` She did not attend the party because she was sick and could not go out. ```###Correct text: ", and the generated target is "She did not attend the party because she was sick and could not go out."
[0085] After constructing the SFT instruction tuning data as described above, it can be used as training corpus to train a large language model (LLM) using cross entropy loss.
[0086] The above solution only uses one of the multiple correct texts to train the large language model, resulting in a waste of some correct texts. In addition, the cross entropy loss is prone to overfitting after multiple rounds of training of the large language model, resulting in poor generalization performance.
[0087] In order to solve the above problems, the present application provides a training method for a large language model for text error correction. The training method for a large language model for text error correction of an embodiment of the present application is described in detail below in conjunction with the accompanying drawings.
[0088] Reference Figure 5 , Figure 5 A flow chart of a method for training a large language model for text error correction provided in an embodiment of the present application, the method may include:
[0089] Step S501: Obtain a set of incorrect and correct sentence pairs, where the set of incorrect and correct sentence pairs includes multiple subsets, each subset includes an incorrect text and at least one corresponding correct text, and the incorrect texts in different subsets are different.
[0090] For example, one subset of the set of incorrect and correct sentence pairs is: {Incorrect text 1: Yesterday was the last day of the transfer deadline; Correct text 1: Yesterday was the transfer deadline}; another subset is: {Incorrect text 2: She did not attend the party because she was sick and could not go out; Correct text 2: She did not attend the party because she was sick and could not go out; Correct text 3: She did not attend the party because she was sick and could not go out}.
[0091] Step S502: for each erroneous text contained in each subset and each corresponding correct text, label the erroneous text and the correct text with a positive error correction preference label and a negative error correction preference label, respectively, to obtain a first training corpus.
[0092] Among them, the positive error correction preference label is the label of the correct text, and the negative error correction preference label is the label of the incorrect text.
[0093] In order to enable the initial large language model to learn the difference between the erroneous text and the correct text through comparison and output a more correct text, here, the initial large language model refers to the large language model used for training in this application. In this embodiment, for the erroneous text contained in each subset, the erroneous text can be labeled with a positive error correction preference label and a negative error correction preference label, where the positive error correction preference label is the positive direction of the text output by the initial large language model. By labeling the two types of labels, positive and negative, the initial large language model can more accurately understand the difference between the two types of labels. After multiple rounds of training, the probability assigned by the initial large language model to the positive error correction preference label is greater than the probability assigned to the negative error correction preference label, so that the subsequent trained model, when faced with the texts corresponding to the positive error correction preference label and the negative error correction preference label, will try to select the correct text corresponding to the positive error correction preference label based on the above probability, and will not select the erroneous text corresponding to the negative error correction preference label.
[0094] Since one erroneous text may correspond to multiple correct texts, this embodiment can use each correct text as a positive error correction preference label when marking the erroneous text with a positive error correction preference label, thereby obtaining multiple groups of error correction preference training data.
[0095] For example, taking the above-mentioned error text 2 and the corresponding correct text 2 and correct text 3 as examples, the two sets of error correction preference training data obtained are as follows: Figure 6 In this embodiment, the error text 2 can be used to construct the error correction prompt instruction prompt, and the correct text and the error text can be used to construct the preference tuning data, so as to obtain the following two sets of error correction preference training data.
[0096] The first set of error correction preference training data: the error correction prompt is "Please check whether there are spelling, grammatical or logical errors in the following text separated by ```. If there are any errors, modify and output the modified text. ``` She did not attend the party because she was sick and could not go out. ```### Correct text: ", positive error correction preference label ( Figure 6 Use a smiley face means, the same below) is "She did not attend the party because she was sick and could not go out.", the negative error correction preference label ( Figure 6 With crying face Indicates, the same below) is "She did not attend the party because she was sick and could not go out.".
[0097] The second set of error correction preference training data: the error correction prompt is "Please check whether there are spelling, grammatical or logical errors in the following text separated by ```. If there are any errors, modify and output the modified text. ``` She did not attend the party because she was sick and could not go out. ```###Correct text:", the positive error correction preference label is "She did not attend the party because she was sick and could not go out.", and the negative error correction preference label is "She did not attend the party because she was sick and could not go out.".
[0098] In this embodiment, the erroneous text and the corresponding correct text can also be expanded and converted to more effectively perform preference training on the initial large language model. That is, in this embodiment, each correct text contained in each subset can be labeled with a positive error correction preference label and a negative error correction preference label for the correct text. The positive error correction preference label is the label of the correct text, and the negative error correction preference label is the label of the erroneous text corresponding to the correct text, which is the same as the label of the erroneous text corresponding to the correct text.
[0099] For example, see Figure 7 , which is a schematic diagram of two sets of error correction preference training data constructed with correct text as error correction prompt instructions.
[0100] and Figure 6 different, Figure 7 Correct text 2 and correct text 3 are used to construct error correction prompt instructions respectively, and the correct text and the error text are combined to construct preference tuning data, and the following two sets of error correction preference training data are obtained.
[0101] The third set of error correction preference training data: the error correction prompt is "Please check whether there are spelling, grammatical or logical errors in the following text separated by ```. If there are any errors, modify and output the modified text. ```She did not attend the party because she was sick and could not go out. ```###Correct text:", the positive error correction preference label is "She did not attend the party because she was sick and could not go out.", and the negative error correction preference label is "She did not attend the party because she was sick and could not go out.".
[0102] The fourth set of error correction preference training data: the error correction prompt is "Please check whether there are spelling, grammatical or logical errors in the following text separated by ```. If there are any errors, modify and output the modified text. ``` She did not attend the party because she was sick and could not go out. ```### Correct text: ", the positive error correction preference label is "She did not attend the party because she was sick and could not go out.", and the negative error correction preference label is "She did not attend the party because she was sick and could not go out.".
[0103] That is, in this embodiment, for each subset, the erroneous text in the subset and each correct text can construct an error-correct sentence pair, and for each error-correct sentence pair, two sets of error correction preference training data can be constructed by exchanging the error and correct text in the error correction prompt part. By exchanging the error and correct text, on the one hand, the error correction preference training data can be expanded, and on the other hand, it helps the initial large language model to more accurately choose between the error text and the correct text by comparing the error text and the correct text.
[0104] Step S503: Based on the first training corpus, a preset joint loss is used to perform preference tuning training on the initial large language model to obtain a large language model for text error correction.
[0105] As described above, the first training corpus includes error correction preference training data constructed based on the erroneous texts in all subsets and at least one corresponding correct text. In this embodiment, the first training corpus can be used as training data for the initial large language model to perform preference tuning training on the initial large language model.
[0106] In order to be able to use the first training corpus for preference tuning training, the present application adopts a preset joint loss. Here, the preset joint loss consists of a supervision loss and a preference loss, the supervision loss is used to measure the difference between the first output of the initial large language model and the positive error correction preference label, and the preference loss is used to measure the label that the initial large language model is more inclined to select for the positive error correction preference label and the negative error correction preference label.
[0107] The above-mentioned first output refers to the corrected text output by the initial large language model for the first training corpus. More specifically, the first output is the corrected text output by the initial large language model based on the error correction prompt instruction prompt in the first training corpus (for example, the error correction prompt instruction prompt in the four sets of error correction preference training data provided above).
[0108] The training method of the large language model for text error correction provided by the present application, for the erroneous text contained in each subset of the set of error-correct sentence pairs and each corresponding correct text, the erroneous text and the correct text are respectively labeled with positive error correction preference labels and negative error correction preference labels to obtain a first training corpus, and based on the first training corpus, the initial large language model is tuned and trained using a preset joint loss to obtain a large language model for text error correction, wherein the joint loss is composed of a supervision loss and a preference loss, the supervision loss is used to measure the difference between the first output of the initial large language model and the positive error correction preference label, and the preference loss is used to measure the label that the initial large language model is more inclined to select for the positive error correction preference label and the negative error correction preference label. It can be seen from this that the present application can not only generate training corpus based on erroneous text, but also generate training corpus based on each correct text corresponding to the erroneous text, thereby avoiding the waste of correct text. Furthermore, the present application can not only mark positive error correction preference labels, but also mark negative error correction preference labels, and jointly train the initial large language model based on the two types of labels and the corresponding joint losses, so that the trained model is less likely to overfit, thereby improving the generalization performance of the model and improving the accuracy of the error correction of the large language model trained for text error correction.
[0109] In addition, the large language model for text error correction provided by the prior art has high requirements on the amount and quality of training data because it only uses cross entropy loss. The large language model for text error correction provided by this solution annotates positive error correction preference labels and negative error correction preference labels for the erroneous text and each corresponding correct text, and uses a joint loss consisting of supervision loss and preference loss to train the initial large language model, so that the trained large language model for text error correction uses less training data and has lower requirements on the quality of training data when achieving the same error correction effect as the prior art.
[0110] After conducting experiments on the large language model for text correction provided by the prior art, it was found that the large language model for text correction still has the problem of over-correcting text that originally had no grammatical errors. In order to solve this problem, the present application can verify the original text to be corrected before correcting the error. If there are errors, such as the above-mentioned spelling, grammar, logic, etc., the original text is corrected, otherwise, no correction is performed.
[0111] Based on this, this application provides another large language model for text error correction.
[0112] Specifically, on the basis of the first training corpus mentioned above, a second training corpus for verification can be added, and then based on the first training corpus and the second training corpus, a preset joint loss is used to perform preference tuning training on the initial large language model to obtain a large language model for text error correction.
[0113] Optionally, the process of determining the second training corpus includes: for each erroneous text contained in each subset and each corresponding correct text, labeling the erroneous text and the correct text with a positive verification preference label and a negative verification preference label, respectively, to obtain a second training corpus, wherein the positive verification preference label is a label of a correct judgment result that characterizes whether the corresponding text has an error, and the negative verification preference label is a label of an incorrect judgment result that characterizes whether the corresponding text has an error.
[0114] Specifically, for the error text included in each subset, a positive verification preference label and a negative verification preference label are marked for the error text, wherein the positive verification preference label is error and the negative verification preference label is correct.
[0115] For each correct text contained in each subset, a positive verification preference label and a negative verification preference label are annotated for the correct text, wherein the positive verification preference label is correct and the negative verification preference label is incorrect.
[0116] Still taking the above-mentioned error text 2 and the corresponding correct text 2 and correct text 3 as an example, this embodiment can first construct a verification prompt instruction prompt with error text 2, and construct preference tuning data with a combination of correct and incorrect judgments to obtain the following set of verification preference training data.
[0117] like Figure 8 As shown, the first set of verification preference training data: the verification prompt is "Please check whether there are spelling, grammatical or logical errors in the following text separated by ```. ``` She did not attend the party because she was sick and could not go out. ```### True or False Judgment: ", the positive verification preference label is "wrong", and the negative verification preference label is "correct".
[0118] In addition, this embodiment can also construct a verification prompt instruction prompt with the correct text 2 and the correct text 3 corresponding to the error text 2, respectively, and construct preference tuning data with a combination of correct and incorrect judgments, to obtain the following two sets of verification preference training data.
[0119] like Fig. 9 As shown, the second set of verification preference training data: the verification prompt is "Please check whether there are spelling, grammatical or logical errors in the following text separated by ```. ``` She did not attend the party because she was sick and could not go out. ```### True or False Judgment: ", the positive verification preference label is "correct" and the negative verification preference label is "false".
[0120] The third set of verification preference training data: the verification prompt is "Please check whether there are spelling, grammatical or logical errors in the following text separated by ```. ``` She did not attend the party because she was sick and could not go out. ```### True or false judgment: ", the positive verification preference label is "correct" and the negative verification preference label is "false".
[0121] That is, for each subset, this embodiment can construct a set of verification preference training data based on the erroneous text and each correct text in the subset, and the verification preference training data constructed based on the erroneous text and correct text in all subsets constitute the above-mentioned second training corpus.
[0122] In this embodiment, based on the first training corpus and the second training corpus, the initial large language model can be trained by using a preset joint loss. The training process is as follows: Fig.10 shown.
[0123] like Fig.10 , taking wrong text 2, correct text 2 and correct text 3 as examples, a total of seven sets of preference training data are constructed using the method provided in the previous article.
[0124] After constructing the preference training data as described above, this embodiment can use it as training corpus, use the joint loss consisting of the supervision loss SFT and the preference loss to train the initial large language model LLM, and obtain a large language model for text error correction.
[0125] As mentioned above, for the first training corpus, the supervision loss is used to measure the difference between the first output of the initial large language model and the positive error correction preference label, and the preference loss is used to measure the label that the initial large language model is more inclined to select for the positive error correction preference label and the negative error correction preference label.
[0126] Similarly, for the second training corpus, the supervision loss is used to measure the difference between the second output of the initial large language model and the positive verification preference label, and the preference loss is used to measure the label that the initial large language model is more inclined to select for the positive verification preference label and the negative verification preference label.
[0127] The above-mentioned second output refers to the correct or incorrect judgment result output by the initial large language model for the second training corpus. More specifically, the second output is the correct or incorrect judgment result output by the initial large language model based on the verification prompt instruction prompt in the second training corpus (for example, the verification prompt instruction prompt in the three sets of verification preference training data provided above).
[0128] That is, the above-mentioned supervision loss can calculate the deviation between the output of the initial large language model (including the first output and the second output) and the positive preference label, and thus obtain the supervision loss Here, when the output of the initial large language model is the first output, the positive preference label refers to the positive error correction preference label; when the output of the initial large language model is the second output, the positive preference label refers to the positive verification preference label.
[0129] The above preference loss can calculate the deviation between the probability of the initial large language model outputting a positive preference label and the probability of outputting a negative preference label, and thus obtain the preference loss Here, when the positive preference label is a positive error correction preference label, the negative preference label is a negative error correction preference label; when the positive preference label is a positive verification preference label, the negative preference label is a negative verification preference label.
[0130] In order to better aggregate the above-mentioned supervision loss and preference loss to obtain the joint loss, optionally, weights can be set for the supervision loss and the preference loss respectively to obtain the joint loss by weighted summation.
[0131] For example, if the weight of the supervision loss is 1, the weight of the preference loss is λ, which represents the weight of the preference loss in the overall loss. Optionally, λ is a value between 0.01 and 0.1.
[0132] Optionally, the joint loss is calculated as:
[0133] Formula (1);
[0134] in, Indicates the original text to be corrected, that is, the text in the prompt command prompt; The target text that indicates rejection is the text in the crying face, that is, the text in the negative preference label; Indicates the selected target text, that is, the text inside the smiley face, that is, the text inside the positive preference tag; Indicates that in a given , and joint loss expectations under Indicates joint loss.
[0135] Those skilled in the art should understand that the initial large language model is predicted token by token in both the training and prediction stages. Therefore, in one round of prediction, a supervision loss and a preference loss can be calculated for each character token contained in the original text to be corrected, and then a weighted sum result (i.e. ), in this embodiment, the weighted sum of all character tokens contained in the original text to be corrected is averaged, that is, the above-mentioned expected .
[0136] Optionally, the above-mentioned supervised loss may be a cross entropy loss or a negative log-likelihood loss (NLL).
[0137] Taking negative log-likelihood loss as an example, the calculation formula of supervision loss is:
[0138] Formula (2);
[0139] in, Indicates that in a given The initial large language model output The probability of express The 1st to t-1th character tokens in express The tth character token in Indicates that in a given and In the case of the 1st to t-1 character tokens, the initial large language model outputs The probability of the t-th character token in .
[0140] Optionally, the above preference loss is the ratio of the probability of the initial large language model outputting a positive preference label to the probability of the initial large language model outputting a negative preference label, wherein when the positive preference label is a positive error correction preference label, the negative preference label is a negative error correction preference label, and when the positive preference label is a positive verification preference label, the negative preference label is a negative verification preference label. The calculation formula of the preference loss is as follows:
[0141] Formula (3);
[0142] in, Indicates that in a given The initial large language model output probability.
[0143] In summary, the embodiments of the present application convert paired error correction corpora (i.e., sets of pairs of incorrect and correct sentences) into data that can be trained using both supervised training and preference tuning, and perform tuning on the basis of the pre-trained initial large language model, so that the tuned large language model for text correction has the ability to correct spelling and grammatical errors in general texts.
[0144] In the generation verification, this application utilizes the autoregressive text generation capability of the initial large language model. There is no need to design and add a new network to implement verification. Instead, it innovatively uses words such as "correct" and "wrong" generated by the language model for judgment. Experimental results show that the introduction of this auxiliary verification can effectively improve the performance of text error correction.
[0145] In the loss part, this application uses a joint loss consisting of supervision loss and preference loss, so that the model can not only fit the distribution of training corpus in units of character tokens, but also adjust the inductive bias of the model by comparing the whole sentence, thereby improving the accuracy of error correction.
[0146] Based on the above large language model with verification capability for text error correction, the present application also provides a text error correction method. Fig.11 , is a flow chart of the text error correction method provided by this application. Fig.11 , the method may include:
[0147] Step S1101: Obtain the original text to be corrected.
[0148] Step S1102: Generate a first prompt instruction prompt based on the original text.
[0149] Here, the first prompt instruction prompt corresponds to the verification prompt instruction prompt in the previous text. For details, please refer to the previous introduction and will not be repeated here.
[0150] Step S1103: input the first prompt instruction prompt into the large language model for text error correction to obtain an error correction verification result indicating whether there is an error in the original text.
[0151] The large language model for text correction here refers to a large language model for text correction with verification capability, that is, the large language model for text correction obtained by training with the first training corpus and the second training corpus.
[0152] If the above error correction verification result is correct, the original text can be directly output. If the above error correction verification result is wrong, the error correction is performed according to the subsequent steps.
[0153] Step S1104: If the error correction verification result is an error, a second prompt instruction prompt is generated based on the original text.
[0154] Here, the second prompt instruction prompt corresponds to the error correction prompt instruction prompt in the previous text. For details, please refer to the previous introduction and will not be repeated here.
[0155] Step S1105: input the second prompt instruction prompt into the large language model for text error correction to obtain the corrected text corresponding to the original text.
[0156] The large language model for text correction here refers to a large language model for text correction with verification capability, that is, the large language model for text correction obtained by training with the first training corpus and the second training corpus.
[0157] This embodiment divides the actual prediction stage into two stages: the first stage performs generation verification judgment. If the judgment result is that the original text is correct, the original text is directly output; if the judgment result is wrong, the second stage of error correction is performed to output the corrected text. This two-stage error correction method is more in line with the situation in actual application scenarios where the proportion of erroneous text is relatively smaller than that of correct text, and can avoid excessive correction of the original text.
[0158] At the same time, since the number of words output by the large language model used for text correction is proportional to the resource consumption and time consumption, the two-stage reasoning method of the present application can effectively reduce the cost of correcting all input original texts in actual scenarios.
[0159] The above introduces a large language model training method for text correction and a text correction method provided in an embodiment of the present application. The following will introduce a device for executing the above-mentioned large language model training method for text correction and a text correction method.
[0160] See also Fig.12 , Fig.12 A schematic diagram of a structure of a large language model training device for text error correction provided in an embodiment of the present application. Fig.12 As shown, the device may include:
[0161] The training text acquisition module 1201 is used to acquire a set of incorrect and correct sentence pairs, where the set of incorrect and correct sentence pairs includes multiple subsets, each subset includes an incorrect text and at least one corresponding correct text, and the incorrect texts in different subsets are different;
[0162] The first corpus generation module 1202 is used to label the erroneous text and each corresponding correct text contained in each subset with a positive error correction preference label and a negative error correction preference label, respectively, to obtain a first training corpus, wherein the positive error correction preference label is the label of the correct text, and the negative error correction preference label is the label of the erroneous text;
[0163] The large model training module 1203 is used to perform preference tuning training on the initial large language model based on the first training corpus using a preset joint loss to obtain a large language model for text error correction, wherein the preset joint loss is composed of a supervision loss and a preference loss, the supervision loss is used to measure the difference between the first output of the initial large language model and the positive error correction preference label, and the preference loss is used to measure the label that the initial large language model is more inclined to select with respect to the positive error correction preference label and the negative error correction preference label.
[0164] In a possible implementation, the training device for a large language model for text error correction provided by the present application may also include: a second corpus generation module.
[0165] The second corpus generation module is used to label the erroneous text and each corresponding correct text contained in each subset with a positive verification preference label and a negative verification preference label, respectively, to obtain a second training corpus, wherein the positive verification preference label is a label of a correct judgment result representing whether the corresponding text has an error, and the negative verification preference label is a label of an incorrect judgment result representing whether the corresponding text has an error.
[0166] Based on this, the above-mentioned large model training module 1203 can be specifically used for: based on the first training corpus and the second training corpus, the initial large language model is trained with a preset joint loss to perform preference tuning to obtain a large language model for text correction, wherein the supervision loss is also used to measure the difference between the second output of the initial large language model and the positive verification preference label, and the preference loss is also used to measure the label that the initial large language model is more inclined to select with respect to the positive verification preference label and the negative verification preference label.
[0167] In a possible implementation, the above preference loss is the ratio of the probability of the initial large language model outputting a positive preference label to the probability of the initial large language model outputting a negative preference label, wherein, when the positive preference label is a positive error correction preference label, the negative preference label is a negative error correction preference label, and when the positive preference label is a positive verification preference label, the negative preference label is a negative verification preference label.
[0168] In one possible implementation, the above supervised loss is a negative log-likelihood loss.
[0169] The training device for a large language model for text error correction provided in this application corresponds to the training method for a large language model for text error correction provided in the previous text. For details, please refer to the previous introduction and will not be repeated here.
[0170] See also Fig.13 , Fig.13 This is a schematic diagram of the structure of a text error correction device provided in an embodiment of the present application. Fig.13 As shown, the device may include:
[0171] The predicted text acquisition module 1301 is used to acquire the original text to be corrected;
[0172] A first instruction generating module 1302, used to generate a first prompt instruction prompt based on the original text;
[0173] The error determination module 1303 is used to input the first prompt instruction prompt into the above-mentioned large language model for text error correction to obtain an error correction verification result indicating whether there is an error in the original text;
[0174] The second instruction generating module 1304 is used to generate a second prompt instruction prompt based on the original text when the error correction verification result is an error;
[0175] The text error correction module 1305 is used to input the second prompt instruction prompt into the above-mentioned large language model for text error correction to obtain a corrected text corresponding to the original text.
[0176] The text correction device provided in this application corresponds to the text correction method provided in the previous text. For details, please refer to the previous introduction and will not be repeated here.
[0177] The present application also provides an electronic device in an embodiment. Fig.14 As shown, it shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiment of the present application. The electronic device in the embodiment of the present application may include but is not limited to fixed terminals such as mobile phones, laptops, PDAs (personal digital assistants), PADs (tablet computers), desktop computers, etc. Fig.14 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0178] like Fig.14As shown, the electronic device may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 1401, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1402 or a program loaded from a storage device 1408 to a random access memory (RAM) 1403. When the electronic device is powered on, various programs and data required for the operation of the electronic device are also stored in the RAM 1403. The processing device 1401, the ROM 1402, and the RAM 1403 are connected to each other via a bus 1404. An input / output (I / O) interface 1405 is also connected to the bus 1404.
[0179] Typically, the following devices may be connected to the I / O interface 1405: an input device 1406 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 1407 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 1408 including, for example, a memory card, a hard disk, etc.; and a communication device 1409. The communication device 1409 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Although Fig.14 An electronic device having various devices is shown, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0180] Also provided in an embodiment of the present application is a computer program product, including computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements any method for training a large language model for text correction or any text correction method provided in an embodiment of the present application.
[0181] A computer-readable storage medium is also provided in an embodiment of the present application. The storage medium carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement any of the training methods for a large language model for text correction or any of the text correction methods provided in the embodiments of the present application.
[0182] It should also be noted that the device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed over multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, in the drawings of the device embodiments provided by the present application, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines.
[0183] Through the description of the above implementation mode, the technicians in the field can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course, it can also be implemented by special hardware including special integrated circuits, special CPUs, special memories, special components, etc. In general, all functions completed by computer programs can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be various, such as analog circuits, digital circuits or special circuits. However, for the present application, software program implementation is a better implementation mode in more cases. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer floppy disk, a U disk, a mobile hard disk, a ROM, a RAM, a disk or an optical disk, etc., including a number of instructions to enable a computer device (which can be a personal computer, a training device, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0184] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.
[0185] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, a computer, a training device, or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, training device, or data center. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device, a data center, etc. that includes one or more available media integrations. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)), etc.
Claims
1. A method for training a large language model for text error correction, characterized in that: include: Obtaining a set of incorrect and correct sentence pairs, wherein the set of incorrect and correct sentence pairs includes a plurality of subsets, each subset includes an incorrect text and at least one corresponding correct text, and the incorrect texts in different subsets are different; For each erroneous text and each corresponding correct text contained in each subset, a positive error correction preference label and a negative error correction preference label are respectively marked for the erroneous text and the correct text to obtain a first training corpus, wherein the positive error correction preference label is a label of the correct text, and the negative error correction preference label is a label of the erroneous text; Based on the first training corpus, a preset joint loss is used to perform preference tuning training on the initial large language model to obtain a large language model for text error correction, wherein the preset joint loss is composed of a supervision loss and a preference loss, the supervision loss is used to measure the difference between the first output of the initial large language model and the positive error correction preference label, and the preference loss is used to measure the label that the initial large language model is more inclined to select with respect to the positive error correction preference label and the negative error correction preference label; The method of performing preference tuning training on the initial large language model based on the first training corpus using a preset joint loss to obtain a large language model for text error correction includes: For each erroneous text and each corresponding correct text contained in each subset, a positive verification preference label and a negative verification preference label are respectively marked for the erroneous text and the correct text to obtain a second training corpus, wherein the positive verification preference label is a label representing a correct judgment result of whether the corresponding text has an error, and the negative verification preference label is a label representing an incorrect judgment result of whether the corresponding text has an error; Based on the first training corpus and the second training corpus, the initial large language model is trained by using a preset joint loss to obtain the large language model for text error correction; The supervised loss is also used to measure the difference between the second output of the initial large language model and the positive verification preference label, and the preference loss is also used to measure the label that the initial large language model is more inclined to select with respect to the positive verification preference label and the negative verification preference label.
2. The method for training a large language model for text error correction according to claim 1, characterized in that: The preference loss is the ratio of the probability of the initial large language model outputting a positive preference label to the probability of the initial large language model outputting a negative preference label, wherein, when the positive preference label is the positive error correction preference label, the negative preference label is the negative error correction preference label, and when the positive preference label is the positive verification preference label, the negative preference label is the negative verification preference label.
3. The method for training a large language model for text error correction according to claim 1, characterized in that: The supervised loss is the negative log-likelihood loss.
4. A text error correction method, characterized in that: include: Obtain the original text to be corrected; Generate a first prompt instruction prompt based on the original text; Inputting the first prompt instruction prompt into the large language model for text error correction according to any one of claims 1 to 3 to obtain an error correction verification result indicating whether the original text has an error; If the error correction verification result is an error, generating a second prompt instruction prompt based on the original text; The second prompt instruction prompt is input into the large language model for text error correction described in any one of claims 1 to 3 to obtain a corrected text corresponding to the original text.
5. A training device for a large language model for text error correction, characterized in that: include: A training text acquisition module, used to acquire a set of incorrect and correct sentence pairs, wherein the set of incorrect and correct sentence pairs includes a plurality of subsets, each subset includes an incorrect text and at least one corresponding correct text, and the incorrect texts in different subsets are different; A first corpus generation module is used to label the erroneous text and each corresponding correct text contained in each subset with a positive error correction preference label and a negative error correction preference label, respectively, to obtain a first training corpus, wherein the positive error correction preference label is a label of the correct text, and the negative error correction preference label is a label of the erroneous text; A large model training module, configured to perform preference tuning training on an initial large language model based on the first training corpus using a preset joint loss to obtain a large language model for text error correction, wherein the preset joint loss is composed of a supervision loss and a preference loss, the supervision loss is used to measure the difference between the first output of the initial large language model and the positive error correction preference label, and the preference loss is used to measure the label that the initial large language model is more inclined to select with respect to the positive error correction preference label and the negative error correction preference label; The large model training module is specifically used for: For each erroneous text and each corresponding correct text contained in each subset, a positive verification preference label and a negative verification preference label are respectively marked for the erroneous text and the correct text to obtain a second training corpus, wherein the positive verification preference label is a label representing a correct judgment result of whether the corresponding text has an error, and the negative verification preference label is a label representing an incorrect judgment result of whether the corresponding text has an error; Based on the first training corpus and the second training corpus, the initial large language model is trained by using a preset joint loss to obtain the large language model for text error correction; The supervised loss is also used to measure the difference between the second output of the initial large language model and the positive verification preference label, and the preference loss is also used to measure the label that the initial large language model is more inclined to select with respect to the positive verification preference label and the negative verification preference label.
6. A text error correction device, characterized in that: include: A predicted text acquisition module is used to acquire the original text to be corrected; A first instruction generating module, used for generating a first prompt instruction prompt based on the original text; an error determination module, configured to input the first prompt instruction prompt into the large language model for text error correction according to any one of claims 1 to 3, and obtain an error correction verification result characterizing whether there is an error in the original text; A second instruction generating module, configured to generate a second prompt instruction prompt based on the original text when the error correction verification result is an error; A text correction module is used to input the second prompt instruction prompt into the large language model for text correction described in any one of claims 1 to 3 to obtain a corrected text corresponding to the original text.
7. A computer program product, characterized in that It includes computer-readable instructions, which, when executed on an electronic device, enable the electronic device to implement the large language model training method for text correction as described in any one of claims 1 to 3 or the text correction method as described in claim 4.
8. An electronic device, characterized in that: The method comprises at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program so that the electronic device can implement the training method of a large language model for text correction as described in any one of claims 1 to 3 or the text correction method as described in claim 4.
9. A computer storage medium, characterized in that The storage medium carries one or more computer programs, which, when executed by an electronic device, enable the electronic device to implement the large language model training method for text correction as described in any one of claims 1 to 3 or the text correction method as described in claim 4.
Citation Information
Patent Citations
Chinese text error correction and verification method and device, equipment and storage medium
CN115169330A