Text correction method and device, computer device, storage medium and program product
By incorporating a teacher-student model architecture and contextual information, the problem of low reliability in traditional text correction methods is solved, achieving more accurate and reasonable text correction results.
Patent Information
- Application Number
- CN202411658837.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-20
- Publication Date
- 2025-11-04
- Estimated Expiration
- 2044-11-20
AI Technical Summary
In traditional text correction methods, newly generated words may not conform to the semantics of the text, resulting in low reliability of error correction.
A teacher-student model architecture is adopted, in which the student model is trained by the teacher model and sample data. Contextual information of the correct sample text is introduced, and the parameters of the student model are adjusted by combining model loss and reward mechanisms to improve the accuracy of error correction and the rationality of the context.
It improves the reliability of text correction, makes the corrected text more consistent with the context and semantics, and enhances the accuracy and coherence of the predicted corrected text.
Smart Images

Figure CN119578409B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of artificial intelligence, in particular to a text correction method and device, computer equipment, storage medium and program product. BACKGROUND
[0002] Text correction is an important natural language processing task, aiming to automatically detect and correct misspelled words, grammatical errors and other language errors in text.
[0003] In the traditional technology, the wrong words are usually replaced to generate new words; however, the newly generated words may not conform to the semantics of the text, thereby there is a problem of low reliability of text correction. SUMMARY
[0004] Therefore, it is necessary to provide a text correction method, device, computer equipment, storage medium and program product to improve the reliability of text correction.
[0005] In a first aspect, the present application provides a text correction method, comprising:
[0006] obtaining a target text to be corrected;
[0007] inputting the target text to be corrected into a target correction model to obtain a target corrected text; wherein the target correction model is obtained by training a student model according to a teacher model and sample data; the sample data includes a sample text to be corrected, a sample correct text corresponding to the sample text to be corrected, and context information corresponding to the sample correct text.
[0008] In one embodiment, the target correction model is obtained by training in the following manner:
[0009] inputting the sample text to be corrected into the teacher model to obtain a first predicted corrected text, and inputting the sample text to be corrected into the student model to obtain a second predicted corrected text;
[0010] determining a model loss according to the sample correct text corresponding to the sample text to be corrected, the first predicted corrected text and the second predicted corrected text;
[0011] determining context information corresponding to the second predicted corrected text;
[0012] determining a model reward according to the second predicted corrected text, the sample correct text, the context information corresponding to the sample correct text, and the context information corresponding to the second predicted corrected text;
[0013] adjust model parameters of the student model according to the model loss and the model reward, to obtain a target correction model.
[0014] In one of the embodiments, the determining the model loss according to the sample correct text corresponding to the sample text to be corrected, the first predicted correction text and the second predicted correction text comprises:
[0015] determining a first loss according to the sample correct text and the second predicted correction text;
[0016] determining a second loss according to the first predicted correction text and the second predicted correction text;
[0017] determining the model loss according to the first loss, the second loss and a loss coefficient.
[0018] In one of the embodiments, the determining the model reward according to the second predicted correction text, the sample correct text, context information corresponding to the sample correct text and context information corresponding to the second predicted correction text comprises:
[0019] determining a first reward according to a semantic distance between the second predicted correction text and the sample correct text, a text length of the second predicted correction text and a text length of the sample correct text;
[0020] determining a second reward according to an information difference between the context information corresponding to the sample correct text and the context information corresponding to the second predicted correction text;
[0021] determining the model reward according to the first reward, the second reward and a reward coefficient.
[0022] In one of the embodiments, the determining the first reward according to the semantic distance between the second predicted correction text and the sample correct text, the text length of the second predicted correction text and the text length of the sample correct text comprises:
[0023] determining the semantic distance between the second predicted correction text and the sample correct text;
[0024] selecting a maximum text length from the text length of the second predicted correction text and the text length of the sample correct text;
[0025] determining the first reward according to a ratio between the semantic distance and the maximum text length.
[0026] In one of the embodiments, the adjusting the model parameters of the student model according to the model loss and the model reward, to obtain the target correction model comprises:
[0027] In a case where the model reward is greater than a set threshold, gradient data of the model loss with respect to model parameters of the student model is determined according to the model loss and the model reward;
[0028] The model parameters are adjusted according to the gradient data to obtain a target error correction model.
[0029] In a second aspect, the present application further provides a text error correction device, the device comprising:
[0030] An acquisition module is configured to acquire a target text to be corrected.
[0031] An error correction module is configured to input the target text to be corrected into a target error correction model to obtain a target corrected text, wherein the target error correction model is obtained by training a student model according to a teacher model and sample data, and the sample data comprises a sample text to be corrected, a sample correct text corresponding to the sample text to be corrected, and context information corresponding to the sample correct text.
[0032] In a third aspect, the present application further provides a computer device, comprising a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
[0033] A target text to be corrected is acquired.
[0034] The target text to be corrected is input into a target error correction model to obtain a target corrected text, wherein the target error correction model is obtained by training a student model according to a teacher model and sample data, and the sample data comprises a sample text to be corrected, a sample correct text corresponding to the sample text to be corrected, and context information corresponding to the sample correct text.
[0035] In a fourth aspect, the present application further provides a computer readable storage medium, the computer readable storage medium stores a computer program, and the computer program is executed by a processor to implement the following steps:
[0036] A target text to be corrected is acquired.
[0037] The target text to be corrected is input into a target error correction model to obtain a target corrected text, wherein the target error correction model is obtained by training a student model according to a teacher model and sample data, and the sample data comprises a sample text to be corrected, a sample correct text corresponding to the sample text to be corrected, and context information corresponding to the sample correct text.
[0038] In a fifth aspect, the present application also provides a computer program product comprising a computer program which, when executed by a processor, implements the following steps:
[0039] obtaining a target text to be corrected;
[0040] inputting the target text to be corrected into a target correction model to obtain a target corrected text; wherein the target correction model is obtained by training a student model according to a teacher model and sample data; the sample data comprises a sample text to be corrected, a sample correct text corresponding to the sample text to be corrected, and context information corresponding to the sample correct text.
[0041] The above text correction method, device, computer device, storage medium and program product obtain a target text to be corrected, and then input the target text to be corrected into a target correction model to obtain a target corrected text; wherein the target correction model is obtained by training a student model according to a teacher model and sample data; the sample data comprises a sample text to be corrected, a sample correct text corresponding to the sample text to be corrected, and context information corresponding to the sample correct text. In the above scheme, the context information corresponding to the sample correct text is introduced in the process of training the target correction model, so that the predicted corrected text is more consistent with the text semantics of the context, thereby improving the text correction reliability. BRIEF DESCRIPTION OF DRAWINGS
[0042] Figure 1 A flowchart of a text correction method according to an embodiment;
[0043] Figure 2 A flowchart of obtaining a target correction model according to an embodiment;
[0044] Figure 3 A flowchart of determining a model loss according to an embodiment;
[0045] Figure 4 A flowchart of determining a model reward according to an embodiment;
[0046] Figure 5 A flowchart of determining a first reward according to an embodiment;
[0047] Figure 6 A flowchart of obtaining a target correction model according to another embodiment;
[0048] Figure 7 A schematic diagram of training a target correction model according to an embodiment;
[0049] Figure 8 A structural block diagram of a text correction device according to an embodiment;
[0050] Figure 9 Figure 1 is a schematic diagram of the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0051] In order to make the purposes, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and should not be used to limit the present application.
[0052] The text correction method provided by the embodiments of the present application can be applied to an application environment for correcting error text. The method can be executed by a server or a terminal with certain computing power. The server can be implemented by an independent server or a server cluster composed of multiple servers. The terminal can be, but is not limited to, various personal computers, notebook computers, smart phones, tablet computers, Internet of Things devices and portable wearable devices. The Internet of Things device can be a smart speaker, a smart television, a smart air conditioner, a smart vehicle device, etc. The portable wearable device can be a smart watch, a smart bracelet, a head-mounted device, etc.
[0053] In one embodiment, as shown in Figure 1 , a text correction method is provided. Taking the server as an example, the method comprises the following steps:
[0054] S101, obtaining target text to be corrected.
[0055] For example, the target text to be corrected can be a sentence, a word, a paragraph of text data or several paragraphs of text data, and the problems in the target text to be corrected can be incorrect characters, syntax errors and semantic errors, etc. For example, after obtaining the text data, the obtained text data can be preprocessed, which can include word segmentation, removal of stop words, etc. Then, the processed text is converted into the input format of the model to obtain the target text to be corrected.
[0056] For example, the obtained text data is ( ), and the preprocessed text data is , wherein represents processing of the text, represents conversion of the processed text into the input format of the model.
[0057] S102, inputting the target text to be corrected into a target correction model to obtain a target corrected text.
[0058] Furthermore, the target text to be corrected can be input into the target error correction model, which will extract features and output the target corrected text based on the extracted text features. The target corrected text is the correct text corresponding to the target text to be corrected.
[0059] The target error correction model is trained on the student model using the teacher model and sample data. The teacher model can use Bidirectional Encoder Representations from Transformer (BERT), while the student model can use a lightweight Transformer model. This way, the teacher and student models have similar basic network backbones. During knowledge distillation, the student model learns the error correction capabilities of the teacher model, achieving high performance with less data and computational resources, thus improving text error correction efficiency. Furthermore, the student model can transfer knowledge from complex tasks in the teacher model to related tasks, enhancing its generalization ability.
[0060] The sample data includes the sample text to be corrected, the corresponding correct sample text, and the contextual information of the correct sample text. This ensures that the corrected text remains coherent and logical within its context.
[0061] The aforementioned text correction method obtains the target text to be corrected; then, it inputs this target text into a target correction model to obtain the target corrected text. The target correction model is trained on a student model using a teacher model and sample data. The sample data includes the sample text to be corrected, the corresponding correct sample text, and the contextual information of the correct sample text. This approach incorporates the contextual information of the correct sample text during the training of the target correction model, making the predicted corrected text more consistent with the semantics of the context, thereby improving the reliability of text correction.
[0062] In some alternative implementations, see [link to relevant documentation]. Figure 2 , Figure 2 A flowchart illustrating the process of obtaining a target error correction model is provided, which includes the following steps:
[0063] S201, input the sample text to be corrected into the teacher model to obtain the first predicted corrected text, and input the sample text to be corrected into the student model to obtain the second predicted corrected text.
[0064] Exemplarily, the sample to-be-corrected text can be input into the teacher model to obtain the first predicted correction text, and the sample to-be-corrected text can be input into the student model to obtain the second predicted correction text; wherein the teacher model can be understood as a trained model, which can correctly predict the correction text, and the student model is used to learn the prediction ability of the teacher model, that is, to imitate the output of the teacher model.
[0065] S202, determining a model loss according to the sample correct text corresponding to the sample to-be-corrected text, the first predicted correction text and the second predicted correction text.
[0066] Further, the model loss of the predicted correction text of the student model can be determined according to the difference between the sample correct text corresponding to the sample to-be-corrected text and the second predicted correction text output by the student model, and the model loss of the student model imitating the output of the teacher model can be determined according to the difference between the first predicted correction text and the second predicted correction text, and the comprehensive model loss of the student model can be determined according to the two model losses.
[0067] S203, determining the context information corresponding to the second predicted correction text.
[0068] Exemplarily, the context information corresponding to the second predicted correction text can also be determined. For example, the second predicted correction text can be input into a text generation model, and the text generation model outputs the context information corresponding to the second predicted correction text. Wherein the text generation model can be trained in advance using sample texts and context information corresponding to the sample texts.
[0069] S204, determining a model reward according to the second predicted correction text, the sample correct text, the context information corresponding to the sample correct text, and the context information corresponding to the second predicted correction text.
[0070] Exemplarily, the model reward reflecting the correctness of the predicted correction text of the student model can be determined according to the second predicted correction text output by the student model and the sample correct text; and the model reward reflecting the coherence and rationality of the predicted correction text of the student model in the context can be determined according to the context information corresponding to the sample correct text and the context information corresponding to the second predicted correction text; and the comprehensive model reward of the student model can be determined according to the two rewards.
[0071] S205, adjusting the model parameters of the student model according to the model loss and the model reward to obtain a target correction model.
[0072] Further, the parameter adjustment direction of the model parameters of the student model can be adjusted according to the model loss and the model reward to speed up the training speed of the student model and improve the accuracy of the predicted correction text of the student model, and finally obtain the target correction model.
[0073] In this embodiment, the training process of the student model is guided by both model loss and model reward, and the direction of parameter adjustment of the student model's parameters is adjusted. On the one hand, this can speed up the training of the student model, and on the other hand, it can improve the accuracy of the student model in predicting and correcting text.
[0074] In some alternative implementations, see [link to relevant documentation]. Figure 3 , Figure 3 A flowchart illustrating the process of determining model loss is provided, which includes the following steps:
[0075] S301, Determine the first loss based on the sample correct text and the second predicted correct text.
[0076] For example, a first loss can be determined based on a loss function, according to the correct sample text and the second predicted correct text. The first loss can be understood as cross-entropy loss, which reflects the difference between the second predicted correct text predicted by the student model and the correct sample text, that is, it reflects the reliability of the correct text output by the student model.
[0077] S302, determine the second loss based on the first predicted correction text and the second predicted correction text.
[0078] Furthermore, a second loss can be determined based on the loss function, according to the first predicted corrected text and the second predicted corrected text. The second loss can be understood as distillation loss, which is used to reflect the difference between the second predicted corrected text predicted by the student model and the first predicted corrected text output by the teacher model, that is, to reflect the difference between the outputs of the student model and the teacher model.
[0079] S303, determine the model loss based on the first loss, the second loss, and the loss coefficient.
[0080] Furthermore, the combined model loss of the student model can be determined based on the first and second losses, as well as the loss coefficients. For example, it can be determined using the following formula:
[0081]
[0082]
[0083]
[0084]
[0085]
[0086] in, For model loss, The first loss, is a second loss, is a second predicted correction text corresponding to the i-th sample to-be-corrected text output by the student model, is a second predicted correction text corresponding to the i-th sample to-be-corrected text output by the teacher model, is the i-th sample to-be-corrected text, is a sample correct text of the i-th sample to-be-corrected text, is a loss coefficient, and N is the number of sample to-be-corrected texts, is a temperature parameter.
[0087] In the embodiments of the present application, the first loss is determined according to the sample correct text and the second predicted correction text, which is used to reflect the correctness of the predicted correction text output by the student model; and the second loss is determined according to the first predicted correction text and the second predicted correction text, which is used to reflect the difference between the predicted correction text output by the student model and the predicted correction text output by the teacher model; the model loss of the student model is determined according to the first loss and the second loss, which is used to guide the student model to imitate the output of the teacher model and to correctly output the predicted text, thereby ensuring the accuracy of the predicted text output by the student model and reducing the complexity of data processing of the student model, and thus improving the efficiency of the student model in predicting the correction text.
[0088] In some optional implementations, the student model is trained by participating in Figure 4 , Figure 4 A flowchart for determining a model reward is provided, specifically comprising the following steps:
[0089] S401, determining a first reward according to a semantic distance between the second predicted correction text and the sample correct text, a text length of the second predicted correction text, and a text length of the sample correct text.
[0090] For example, the semantic distance between the second predicted correction text and the sample correct text can be determined based on an edit distance function. The edit distance function can adopt . Then the first reward can be determined according to the semantic distance between the second predicted correction text and the sample correct text, the text length of the second predicted correction text, and the text length of the sample correct text; wherein the first reward is used to reflect the correctness of the second predicted correction text output by the student model.
[0091] S402, determining a second reward according to an information difference between context information corresponding to the sample correct text and context information corresponding to the second predicted correction text.
[0092] Further, the context information corresponding to the sample correct text and the context information corresponding to the second predicted correction text can be subjected to a bitwise OR operation, and the information difference between the context information corresponding to the sample correct text and the context information corresponding to the second predicted correction text can be determined according to the result of the bitwise OR operation, and then the second reward can be determined according to the information difference between the context information corresponding to the sample correct text and the context information corresponding to the second predicted correction text. For example, the second reward can be determined by the following formula:
[0093]
[0094]
[0095]
[0096]
[0097]
[0098] wherein, is the second reward, is the context information of the i-th sample correct text, is the context information of the i-th second predicted correction text, is the i-th second predicted correction text, is the i-th sample correct text, and k is the number of texts before and after the text, represents processing of the text, for example, word segmentation and removal of stop words and the like; represents conversion of the processed text into an input format of the model.
[0099] S403, determining a model reward according to the first reward, the second reward and a reward coefficient.
[0100] Further, the model reward can be determined according to the first reward, the second reward and the reward coefficient. For example, the model reward can be determined by the following formula:
[0101]
[0102] wherein, is the model reward, is the reward coefficient, is the first reward, is the second reward.
[0103] In the embodiments of the present application, the model reward is determined according to the first reward, the second reward and the reward coefficient, which is used to guide the descending direction of the gradient data of the model loss with respect to the model parameters, so as to improve the training speed of the student model and strengthen the output of the student model, so that the student model outputs more reliable second prediction correction text.
[0104] In some optional implementations, referring to Figure 5 , Figure 5 A flowchart for determining the first reward is provided, specifically comprising the following steps:
[0105] S501, determining a semantic distance between the second prediction correction text and the sample correct text.
[0106] For example, the semantic distance between the second prediction correction text and the sample correct text can be determined based on an edit distance function, for example, the determined semantic distance is , wherein, is the second prediction correction text, is the sample correct text.
[0107] S502, selecting a maximum text length from the text length of the second prediction correction text and the text length of the sample correct text.
[0108] Further, the maximum text length can be selected from the text length of the second prediction correction text and the text length of the sample correct text, for example, the selected maximum text length is , wherein, is the text length of the second prediction correction text, is the text length of the sample correct text.
[0109] S503, determining the first reward according to the ratio between the semantic distance and the maximum text length.
[0110] Further, the first reward can be determined according to the ratio between the semantic distance and the maximum text length. Specifically, it can be calculated by the following formula:
[0111]
[0112] In the embodiments of the present application, an implementation for determining the first reward is provided to facilitate the training process of the student model.
[0113] In some optional implementations, referring to Figure 6 , Figure 6 Another flowchart for obtaining a target correction model is provided, specifically comprising the following steps:
[0114] S601, in a case where the model reward is greater than a set threshold, determining gradient data of the model loss with respect to the model parameters of the student model according to the model loss and the model reward.
[0115] For example, the training of the student model guided by the model reward can be based on a reinforcement learning Q-learning algorithm. For example, the current text and context information thereof can be taken as a state s, and a character or word in the text is corrected as an action a. The action a affects the state s, and after the action a corrects a text, a new text is obtained as a new state s', and the model reward is calculated according to the new text. If the model reward is greater than a set threshold, it means that the correction result is positive, so that the student model receives positive feedback for continuous training.
[0116] Further, the reinforcement result fed back by the action a can be updated as follows:
[0117]
[0118] wherein, is a value function of the Q-learning algorithm; is a discount factor, representing the degree of attenuation of future rewards; is a learning rate, representing the step size of each update learning; represents the maximum value obtained in all possible actions in the new state .
[0119] The set threshold can be set to 0. Thus, in a case where the model reward is greater than the set threshold, the gradient data of the model loss with respect to the model parameters of the student model can be determined according to the model loss and the model reward.
[0120] S602, adjusting the model parameters according to the gradient data to obtain a target correction model.
[0121] Further, the model parameters can be adjusted according to the gradient data to obtain a target correction model.
[0122] In the embodiments of the present application, in a case where the model reward is greater than a set threshold, the correction result of the student model is reliable, and in a case where the student model outputs a reliable correction result, the model parameters can be adjusted according to the gradient data to strengthen the output performance of the student model, and further guide the adjustment direction of the model parameters. Not only can the training speed of the student model be improved, but also the reliability of the student model in correcting the text can be improved.
[0123] In some optional implementations, referring to Figure 7 , Figure 7An example of training a target error correction model is provided. In the data preprocessing stage, sample data can be collected, which can include sample text to be corrected, sample correct text corresponding to the sample text to be corrected, and context information corresponding to the sample correct text. The context information corresponding to the sample correct text can also be generated based on the sample correct text using a text generation model. Further preprocessing of the sample data can be performed, such as tokenization, removal of stop words, and conversion to model input format.
[0124] In the teacher-student model training stage, the sample data can be used to train the teacher model, and the trained teacher model can be saved. Then, knowledge distillation can be performed on the teacher model and the student model to make the student model imitate the output of the teacher model. In the double reward mechanism training stage, the context reward, i.e., the second reward, and the accuracy reward, i.e., the first reward, can be calculated. Based on the first reward and the second reward, the total reward, i.e., the model reward, can be determined. When the model reward is greater than a set threshold, the gradient data of the model loss with respect to the model parameters of the student model can be determined based on the model loss and the model reward to train the student model. The Q value can be updated based on the model reward, and the state s can be updated to accumulate the total reward based on the state.
[0125] The present application embodiment considers that the teacher model parameters are large and the inference speed is slow, which is difficult to deploy on resource-limited devices. Therefore, a teacher-student model is adopted to learn the error correction ability of the teacher model through the student model. Based on the teacher-student network model, a lightweight Transformer model is designed as the student model. In this way, the teacher model and the student model have similar basic network backbones. In the knowledge distillation learning process, high performance can be achieved with less data and computing resources. The knowledge of complex tasks in the teacher model can be transferred to related tasks, and the generalization ability of the student model is improved. Furthermore, the present application embodiment combines the reinforcement learning method of accuracy reward and context rationality reward. Through the design of the two rewards, the model can not only correct errors accurately, but also ensure that the corrected text remains coherent and reasonable in the context.
[0126] It should be understood that although the steps in the flowcharts involved in the embodiments described above are shown in sequence according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, the execution of these steps is not strictly limited in sequence, and these steps can be executed in other orders. Moreover, at least some of the steps in the flowcharts involved in the embodiments described above can include multiple steps or multiple stages, which are not necessarily executed at the same time but can be executed at different times, and the execution order of these steps or stages is not necessarily sequential but can be alternately or alternately executed with at least part of other steps or steps or stages in other steps.
[0127] Based on the same inventive concept, the embodiments of the present application also provide a text correction device for implementing the above-mentioned text correction method. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme described in the above method, so the specific limitations in one or more text correction device embodiments provided below can refer to the limitations of the text correction method described above, which will not be repeated here.
[0128] In one embodiment, as shown in Figure 8 a text correction device is provided, comprising:
[0129] The acquisition module 10 is configured to acquire a target text to be corrected.
[0130] The correction module 20 is configured to input the target text to be corrected into a target correction model to obtain a target corrected text. The target correction model is obtained by training a student model according to a teacher model and sample data. The sample data includes a sample text to be corrected, a sample correct text corresponding to the sample text to be corrected, and context information corresponding to the sample correct text.
[0131] The above-mentioned text correction device acquires a target text to be corrected, and then inputs the target text to be corrected into a target correction model to obtain a target corrected text. The target correction model is obtained by training a student model according to a teacher model and sample data. The sample data includes a sample text to be corrected, a sample correct text corresponding to the sample text to be corrected, and context information corresponding to the sample correct text. In the process of training the target correction model, the context information corresponding to the sample correct text is introduced, so that the predicted corrected text is more consistent with the text semantics of the context, thereby improving the text correction reliability.
[0132] In one embodiment, the device further comprises:
[0133] The prediction module is configured to input the sample text to be corrected into the teacher model to obtain first predicted correction text, and input the sample text to be corrected into the student model to obtain second predicted correction text.
[0134] The first determination module is configured to determine a model loss according to the sample correct text corresponding to the sample text to be corrected, the first predicted correction text, and the second predicted correction text.
[0135] The second determination module is configured to determine context information corresponding to the second predicted correction text.
[0136] The third determination module is configured to determine a model reward according to the second predicted correction text, the sample correct text, context information corresponding to the sample correct text, and context information corresponding to the second predicted correction text.
[0137] The adjustment module is configured to adjust model parameters of the student model according to the model loss and the model reward to obtain a target correction model.
[0138] In one of the embodiments, the first determination module is specifically configured to:
[0139] determine a first loss according to the sample correct text and the second predicted correction text, determine a second loss according to the first predicted correction text and the second predicted correction text, and determine the model loss according to the first loss, the second loss, and a loss coefficient.
[0140] In one of the embodiments, the third determination module specifically includes:
[0141] The first determination subunit is configured to determine a first reward according to a semantic distance between the second predicted correction text and the sample correct text, a text length of the second predicted correction text, and a text length of the sample correct text.
[0142] The second determination subunit is configured to determine a second reward according to an information difference between the context information corresponding to the sample correct text and the context information corresponding to the second predicted correction text.
[0143] The third determination subunit is configured to determine the model reward according to the first reward, the second reward, and a reward coefficient.
[0144] In one of the embodiments, the first determination subunit is specifically configured to:
[0145] determine the semantic distance between the second predicted correction text and the sample correct text, select a maximum text length from the text length of the second predicted correction text and the text length of the sample correct text, and determine the first reward according to a ratio between the semantic distance and the maximum text length.
[0146] In one of the embodiments, the adjustment module is specifically configured to:
[0147] In a case where the model reward is greater than a set threshold, gradient data of the model loss with respect to the model parameters of the student model is determined according to the model loss and the model reward; and the model parameters are adjusted according to the gradient data to obtain a target error correction model.
[0148] The various modules in the text error correction apparatus can be implemented in whole or in part by software, hardware, and combinations thereof. The various modules can be embedded in or independent of a processor in a computer device in hardware form, or stored in a memory in a computer device in software form, so as to be called and executed by a processor to perform operations corresponding to the various modules.
[0149] In an embodiment, a computer device is provided, which can be a server, and an internal structure diagram thereof can be as shown in Figure 9 The computer device includes a processor, a memory, and a network interface connected through a system bus. The processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for running the operating system and the computer program in the non-volatile storage medium. The database of the computer device is configured to store text data. The network interface of the computer device is configured to communicate with an external terminal through a network connection. The computer program is executed by the processor to implement a text error correction method.
[0150] Those skilled in the art can understand that Figure 9 The structure shown in the figure is only a block diagram of part of the structure related to the scheme of the present application, and does not constitute a limitation on the computer device to which the scheme of the present application is applied. A specific computer device can include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0151] In an embodiment, a computer device is provided, which includes a memory and a processor. The memory stores a computer program. The processor executes the computer program to implement the following steps:
[0152] Obtaining a target text to be corrected;
[0153] Inputting the target text to be corrected into a target error correction model to obtain a target corrected text; wherein the target error correction model is obtained by training a student model according to a teacher model and sample data; and the sample data includes a sample text to be corrected, a sample correct text corresponding to the sample text to be corrected, and context information corresponding to the sample correct text.
[0154] In an embodiment, the processor further executes the computer program to implement the following steps:
[0155] inputting the sample to-be-corrected text into the teacher model to obtain first predicted correction text, and inputting the sample to-be-corrected text into the student model to obtain second predicted correction text; determining a model loss according to the sample correct text corresponding to the sample to-be-corrected text, the first predicted correction text, and the second predicted correction text; determining context information corresponding to the second predicted correction text; determining a model reward according to the second predicted correction text, the sample correct text, the context information corresponding to the sample correct text, and the context information corresponding to the second predicted correction text; and adjusting the model parameters of the student model according to the model loss and the model reward to obtain a target correction model.
[0156] In one embodiment, the processor, when executing the computer program, also implements the following steps:
[0157] determining a first loss according to the sample correct text and the second predicted correction text; determining a second loss according to the first predicted correction text and the second predicted correction text; and determining the model loss according to the first loss, the second loss, and a loss coefficient.
[0158] In one embodiment, the processor, when executing the computer program, also implements the following steps:
[0159] determining a first reward according to a semantic distance between the second predicted correction text and the sample correct text, a text length of the second predicted correction text, and a text length of the sample correct text; determining a second reward according to an information difference between the context information corresponding to the sample correct text and the context information corresponding to the second predicted correction text; and determining the model reward according to the first reward, the second reward, and a reward coefficient.
[0160] In one embodiment, the processor, when executing the computer program, also implements the following steps:
[0161] determining a semantic distance between the second predicted correction text and the sample correct text; selecting a maximum text length from the text length of the second predicted correction text and the text length of the sample correct text; and determining the first reward according to a ratio between the semantic distance and the maximum text length.
[0162] In one embodiment, the processor, when executing the computer program, also implements the following steps:
[0163] In a case where the model reward is greater than a set threshold, determining gradient data of the model loss with respect to the model parameters of the student model according to the model loss and the model reward; and adjusting the model parameters according to the gradient data to obtain the target correction model.
[0164] In one embodiment, a computer-readable storage medium is provided, which stores a computer program. The computer program is executed by a processor to implement the following steps:
[0165] obtaining a target text to be corrected;
[0166] inputting the target text to be corrected into a target correction model to obtain a target corrected text, wherein the target correction model is obtained by training a student model according to a teacher model and sample data, and the sample data comprises a sample text to be corrected, a sample correct text corresponding to the sample text to be corrected, and context information corresponding to the sample correct text.
[0167] In one embodiment, the computer program, when executed by the processor, further implements the following steps:
[0168] inputting the sample text to be corrected into the teacher model to obtain a first predicted corrected text, and inputting the sample text to be corrected into the student model to obtain a second predicted corrected text; determining a model loss according to the sample correct text corresponding to the sample text to be corrected, the first predicted corrected text and the second predicted corrected text; determining context information corresponding to the second predicted corrected text; determining a model reward according to the second predicted corrected text, the sample correct text, the context information corresponding to the sample correct text, and the context information corresponding to the second predicted corrected text; and adjusting model parameters of the student model according to the model loss and the model reward to obtain the target correction model.
[0169] In one embodiment, the computer program, when executed by the processor, further implements the following steps:
[0170] determining a first loss according to the sample correct text and the second predicted corrected text; determining a second loss according to the first predicted corrected text and the second predicted corrected text; and determining the model loss according to the first loss, the second loss and a loss coefficient.
[0171] In one embodiment, the computer program, when executed by the processor, further implements the following steps:
[0172] determining a first reward according to a semantic distance between the second predicted corrected text and the sample correct text, a text length of the second predicted corrected text and a text length of the sample correct text; determining a second reward according to an information difference between the context information corresponding to the sample correct text and the context information corresponding to the second predicted corrected text; and determining the model reward according to the first reward, the second reward and a reward coefficient.
[0173] In one embodiment, the computer program, when executed by the processor, further implements the following steps:
[0174] determining a semantic distance between the second predicted corrected text and the sample correct text; selecting a maximum text length from the text length of the second predicted corrected text and the text length of the sample correct text; and determining the first reward according to a ratio between the semantic distance and the maximum text length.
[0175] In one embodiment, the computer program, which is executed by a processor, further implements the following steps:
[0176] In the case that the model reward is greater than a set threshold, gradient data of the model loss with respect to the model parameters of the student model is determined according to the model loss and the model reward; and the model parameters are adjusted according to the gradient data to obtain the target error correction model.
[0177] In one embodiment, a computer program product is provided, comprising a computer program which, when executed by a processor, implements the following steps:
[0178] Obtaining a target text to be corrected;
[0179] Inputting the target text to be corrected into a target error correction model to obtain a target corrected text; wherein the target error correction model is obtained by training a student model according to a teacher model and sample data; and the sample data comprises a sample text to be corrected, a sample correct text corresponding to the sample text to be corrected, and context information corresponding to the sample correct text.
[0180] In one embodiment, the computer program, which is executed by a processor, further implements the following steps:
[0181] Inputting the sample text to be corrected into the teacher model to obtain a first predicted corrected text, and inputting the sample text to be corrected into the student model to obtain a second predicted corrected text; determining a model loss according to the sample correct text corresponding to the sample text to be corrected, the first predicted corrected text and the second predicted corrected text; determining context information corresponding to the second predicted corrected text; determining a model reward according to the second predicted corrected text, the sample correct text, the context information corresponding to the sample correct text, and the context information corresponding to the second predicted corrected text; and adjusting the model parameters of the student model according to the model loss and the model reward to obtain the target error correction model.
[0182] In one embodiment, the computer program, which is executed by a processor, further implements the following steps:
[0183] Determining a first loss according to the sample correct text and the second predicted corrected text; determining a second loss according to the first predicted corrected text and the second predicted corrected text; and determining the model loss according to the first loss, the second loss and a loss coefficient.
[0184] In one embodiment, the computer program, which is executed by a processor, further implements the following steps:
[0185] The first reward is determined according to a semantic distance between the second predicted correction text and the sample correct text, a text length of the second predicted correction text, and a text length of the sample correct text; the second reward is determined according to an information difference between context information corresponding to the sample correct text and context information corresponding to the second predicted correction text; and the model reward is determined according to the first reward, the second reward, and a reward coefficient.
[0186] In one embodiment, the computer program, when executed by the processor, further implements the following steps:
[0187] The semantic distance between the second predicted correction text and the sample correct text is determined; a maximum text length is selected from the text length of the second predicted correction text and the text length of the sample correct text; and the first reward is determined according to a ratio between the semantic distance and the maximum text length.
[0188] In one embodiment, the computer program, when executed by the processor, further implements the following steps:
[0189] In a case where the model reward is greater than a set threshold, gradient data of the model loss with respect to model parameters of the student model is determined according to the model loss and the model reward; and the model parameters are adjusted according to the gradient data to obtain a target correction model.
[0190] It should be noted that the user information (including but not limited to user equipment information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the present application are all information and data authorized by the user or authorized by all parties.
[0191] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer readable storage medium, and when the computer program is executed, the processes of the above-mentioned embodiments of the methods can be included. Any reference to memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical storage, high-density embedded non-volatile memory, resistive memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration but not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc. The database involved in the embodiments provided in the present application can include at least one of a relational database and a non-relational database. The non-relational database can include a distributed database based on a block chain, etc., without being limited thereto. The processor involved in the embodiments provided in the present application can be a general-purpose processor, a central processing unit, a graphics processing unit, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., without being limited thereto.
[0192] Any combination of the technical features of the above embodiments can be made. In order to make the description simple, all possible combinations of the technical features in the above embodiments are not described, however, as long as the combination of the technical features does not exist, it should be considered as the scope of the present application.
[0193] The above embodiments only express several implementation manners of the present application, and the description is more specific and detailed, but it should not be understood as a limitation on the scope of the patent of the present application. It should be pointed out that for ordinary skilled in the art, without departing from the concept of the present application, a number of modifications and improvements can be made, which are within the scope of protection of the present application. Therefore, the protection scope of the present application should be subject to the appended claims.
Claims
1. A text error correction method, characterized in that, The method includes: Obtain the target text to be corrected; The target text to be corrected is input into the target error correction model to obtain the target corrected text; wherein, the target error correction model is obtained by training the student model based on the teacher model and sample data; the sample data includes the sample text to be corrected, the sample correct text corresponding to the sample text to be corrected, and the context information corresponding to the sample correct text. The target error correction model is trained in the following way: The sample text to be corrected is input into the teacher model to obtain the first predicted corrected text, and the sample text to be corrected is input into the student model to obtain the second predicted corrected text. The model loss is determined based on the sample correct text corresponding to the sample text to be corrected, the first predicted correct text, and the second predicted correct text. A first reward is determined based on the semantic distance between the second predicted corrected text and the sample correct text, the text length of the second predicted corrected text, and the text length of the sample correct text; the first reward is an accuracy reward. The second reward is determined based on the information difference between the context information corresponding to the correct sample text and the context information corresponding to the second predicted corrected text; the second reward is a context reward. The model reward is determined based on the first reward, the second reward, and the reward coefficient; The model parameters of the student model are adjusted based on the model loss and the model reward to obtain the target error correction model.
2. The method according to claim 1, characterized in that, The step of determining the model loss based on the sample correct text corresponding to the sample text to be corrected, the first predicted corrected text, and the second predicted corrected text includes: Based on the correct sample text and the second predicted corrected text, determine the first loss; The second loss is determined based on the first predicted corrected text and the second predicted corrected text; The model loss is determined based on the first loss, the second loss, and the loss coefficient.
3. The method according to claim 1, characterized in that, The step of determining the first reward based on the semantic distance between the second predicted corrected text and the sample correct text, the text length of the second predicted corrected text, and the text length of the sample correct text includes: Determine the semantic distance between the second predicted corrected text and the sample correct text; Select the maximum text length from the text length of the second predicted corrected text and the text length of the sample correct text; The first reward is determined based on the ratio between the semantic distance and the maximum text length.
4. The method according to claim 1, characterized in that, The step of adjusting the model parameters of the student model based on the model loss and the model reward to obtain the target error correction model includes: If the model reward is greater than a set threshold, the gradient data of the model loss relative to the model parameters of the student model is determined based on the model loss and the model reward. The model parameters are adjusted based on the gradient data to obtain the target error correction model.
5. The method according to claim 1, characterized in that, The method further includes: The second predicted corrected text is input into the text generation model to obtain the context information corresponding to the second predicted corrected text.
6. The method according to claim 1, characterized in that, The step of determining the second reward based on the information difference between the context information corresponding to the correct sample text and the context information corresponding to the second predicted corrected text includes: Perform a bitwise OR operation on the context information corresponding to the correct sample text and the context information corresponding to the second predicted corrected text. Based on the bitwise OR operation result, determine the information difference between the context information corresponding to the correct sample text and the context information corresponding to the second predicted corrected text; The second reward is determined based on the information difference between the context information corresponding to the correct sample text and the context information corresponding to the second predicted corrected text.
7. A text correction device, characterized in that, The device includes: The acquisition module is used to acquire the target text to be corrected; The error correction module is used to input the target text to be corrected into the target error correction model to obtain the target corrected text; wherein, the target error correction model is obtained by training the student model based on the teacher model and sample data; the sample data includes the sample text to be corrected, the sample correct text corresponding to the sample text to be corrected, and the context information corresponding to the sample correct text. The target error correction model is trained in the following way: The sample text to be corrected is input into the teacher model to obtain the first predicted corrected text, and the sample text to be corrected is input into the student model to obtain the second predicted corrected text. The model loss is determined based on the sample correct text corresponding to the sample text to be corrected, the first predicted correct text, and the second predicted correct text. A first reward is determined based on the semantic distance between the second predicted corrected text and the sample correct text, the text length of the second predicted corrected text, and the text length of the sample correct text; the first reward is an accuracy reward. The second reward is determined based on the information difference between the context information corresponding to the correct sample text and the context information corresponding to the second predicted corrected text; the second reward is a context reward. The model reward is determined based on the first reward, the second reward, and the reward coefficient; The model parameters of the student model are adjusted based on the model loss and the model reward to obtain the target error correction model.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
BERT and feedforward neural network-based text error correction method
CN112836496A
Model training method, text classification method, system and device and storage medium
CN117421592A