Text error correction model establishment method, device, medium and electronic device

Through the training and docking steps of the ELECTRA model, combined with random masking and replacement processing, a text error correction model was established, which solved the problem of lack of error-labeled corpus data and achieved efficient text error correction effects.

CN112507695BActive Publication Date: 2024-10-25PING AN TECH (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202011389555.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-01
Publication Date
2024-10-25
Estimated Expiration
2040-12-01

AI Technical Summary

Technical Problem

In the scenario where there is a lack of error-labeled corpus data, it is difficult to establish an effective text error correction model with existing technology, resulting in the inability to complete the text error correction task.

Method used

By using the ELECTRA model for training, two sets of training steps of random masking and random replacement are used, combined with the generator and discriminator modules, the loss function is calculated to establish a text error correction model, and the discriminator module is filled with pre-trained text The modules are connected to obtain the text error correction model.

Benefits of technology

Without relying on incorrectly labeled corpus data, make full use of correct corpus data, reduce data labeling costs, improve the error correction effect of text error correction models, and achieve effective text error correction tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112507695B_ABST
    Figure CN112507695B_ABST
Patent Text Reader

Abstract

The present disclosure relates to the field of natural language processing, and discloses a method, device, medium and electronic device for establishing a text error correction model. The method includes: obtaining a text corpus; obtaining a first vector corresponding to the characters retained in the text corpus after random masking processing; inputting the first vector into the model so that the generator of the model outputs a second vector, and the discriminator of the model outputs a first prediction result; calculating a first loss function; if the first convergence condition is not met, executing the first vector acquisition step and subsequent steps; obtaining a third vector corresponding to the characters in the text corpus after random replacement processing; inputting the third vector into the discriminator module to obtain a second prediction result; calculating a second loss function; if the second convergence condition is not met, executing the third vector acquisition step and subsequent steps; docking the discriminator with a pre-trained text filling module to obtain a text error correction model. This method reduces the data annotation cost and improves the error correction effect.
Need to check novelty before this filing date? Find Prior Art

Description

Background Art

[0002] In some text processing task scenarios, it is necessary to correct errors in manually written or voice-entered text (mainly spelling errors in input methods, incorrect use of professional terms, etc.) and re-output the corrected text. The typical implementation method of such tasks is to use supervised learning methods to sequence the input text, find incorrect characters and replace them. Although such methods can achieve good results, they must provide high-quality annotated data, which is not available in all projects.

[0003] For example, there are currently scenarios where a large amount of corpus in the corresponding field is available and does not contain errors, but there is no corpus data with error correction annotations, so it is impossible to directly model through the above-mentioned supervised learning method, making it difficult to train a text error correction model. Therefore, for scenarios where there is a lack of corpus data with error annotations, it is currently impossible to build a model that can effectively complete the text error correction task. Summary of the invention

[0004] In the field of natural language processing technology, in order to solve the above technical problems, the purpose of the present disclosure is to provide a method, device, medium and electronic device for establishing a text error correction model.

[0005] According to one aspect of the present disclosure, a method for establishing a text error correction model is provided, the method comprising:

[0006] Get text corpus;

[0007] The training steps for the ELECTRA model using the first loss function include:

[0008] Obtaining a first character vector corresponding to a character retained in the text corpus after random masking, wherein the text corpus includes a plurality of characters;

[0009] Inputting the first character vector corresponding to the retained character into the ELECTRA model so that the generator module in the ELECTRA model outputs a plurality of second character vectors corresponding to the text corpus, and the discriminator module in the ELECTRA model outputs a first prediction result of whether each second character vector matches a corresponding character in the text corpus;

[0010] Calculate a first loss function based on the text corpus, the second character vector and the first prediction result;

[0011] If the first loss function does not meet the corresponding first convergence condition, executing the step of obtaining the first character vector corresponding to the character retained in the text corpus after random masking processing and subsequent steps;

[0012] The step of training the discriminator module using a second loss function comprises:

[0013] Obtaining a third character vector corresponding to the character in the text corpus after random replacement processing;

[0014] Inputting the third character vectors into the discriminator module to obtain a second prediction result output by the discriminator module, wherein the second prediction result indicates whether each of the third character vectors matches a corresponding character in the text corpus;

[0015] Calculate a second loss function based on the text corpus and the second prediction result;

[0016] If the second loss function does not meet the corresponding second convergence condition, executing the step of obtaining a third character vector corresponding to the character in the text corpus after random replacement processing and subsequent steps;

[0017] A docking step is performed, wherein the docking step includes: docking the discriminator module with a pre-trained text filling module to obtain a text error correction model.

[0018] According to another aspect of the present disclosure, a text error correction model establishment device is provided, the device comprising:

[0019] An acquisition module, configured to acquire text corpus;

[0020] The first training step execution module is configured to execute a training step on the ELECTRA model using a first loss function, including:

[0021] Obtaining a first character vector corresponding to a character retained in the text corpus after random masking, wherein the text corpus includes a plurality of characters;

[0022] Inputting the first character vector corresponding to the retained character into the ELECTRA model so that the generator module in the ELECTRA model outputs a plurality of second character vectors corresponding to the text corpus, and the discriminator module in the ELECTRA model outputs a first prediction result of whether each second character vector matches a corresponding character in the text corpus;

[0023] Calculate a first loss function based on the text corpus, the second character vector and the first prediction result;

[0024] If the first loss function does not meet the corresponding first convergence condition, executing the step of obtaining the first character vector corresponding to the character retained in the text corpus after random masking processing and subsequent steps;

[0025] The second training step execution module is configured to perform a training step on the discriminator module using a second loss function, including:

[0026] Obtaining a third character vector corresponding to the character in the text corpus after random replacement processing;

[0027] Inputting the third character vectors into the discriminator module to obtain a second prediction result output by the discriminator module, wherein the second prediction result indicates whether each of the third character vectors matches a corresponding character in the text corpus;

[0028] Calculate a second loss function based on the text corpus and the second prediction result;

[0029] If the second loss function does not meet the corresponding second convergence condition, executing the step of obtaining a third character vector corresponding to the character in the text corpus after random replacement processing and subsequent steps;

[0030] The docking step execution module is configured to execute the docking step, and the docking step includes: docking the discriminator module with a pre-trained text filling module to obtain a text error correction model.

[0031] According to another aspect of the present disclosure, a computer-readable program medium is provided, which stores computer program instructions. When the computer program instructions are executed by a computer, the computer is caused to execute the method as described above.

[0032] According to another aspect of the present disclosure, an electronic device is provided, the electronic device comprising:

[0033] processor;

[0034] A memory having computer-readable instructions stored therein, wherein the computer-readable instructions, when executed by the processor, implement the aforementioned method.

[0035] The technical solution provided by the embodiments of the present disclosure may have the following beneficial effects:

[0036] The text error correction model establishment method, device, medium and electronic device provided by the present disclosure include the following steps: obtaining text corpus; using a first loss function to perform a training step on an ELECTRA model, including: obtaining a first character vector corresponding to a character retained in the text corpus after random masking, wherein the text corpus includes a plurality of characters; inputting the first character vector corresponding to the retained character into the ELECTRA model so that a generator module in the ELECTRA model outputs a plurality of second character vectors corresponding to the text corpus, and a discriminator module in the ELECTRA model outputs a first prediction result of whether each second character vector matches a corresponding character in the text corpus; calculating a first loss function based on the text corpus, the second character vector and the first prediction result; if the first loss function does not meet the corresponding first convergence condition, performing the step of obtaining the first character vector; and The steps of obtaining the first character vector corresponding to the characters retained in the text corpus after random masking and the subsequent steps; performing a training step on the discriminator module using a second loss function, including: obtaining a third character vector corresponding to the characters in the text corpus after random replacement; inputting the third character vector into the discriminator module to obtain a second prediction result output by the discriminator module, wherein the second prediction result indicates whether each of the third character vectors matches the corresponding characters in the text corpus; calculating a second loss function based on the text corpus and the second prediction result; if the second loss function does not meet the corresponding second convergence condition, performing the step of obtaining the third character vector corresponding to the characters in the text corpus after random replacement and the subsequent steps; performing a docking step, wherein the docking step includes: docking the discriminator module with a pre-trained text filling module to obtain a text error correction model.

[0037] Under this method, the text error correction model is trained based on the ELECTRA model. By using two sets of training steps to train the model, the correct corpus data can be fully utilized to train the text error correction model. A model that effectively completes the text error correction task can be established without using corpus data marked with errors, which reduces the data annotation cost and enables the trained text error correction model to obtain better training results, thereby improving the error correction effect of the text error correction model.

[0038] It is to be understood that the foregoing general description and the following detailed description are exemplary only and are not restrictive of the invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0040] Figure 1 is a system architecture diagram of a method for establishing a text error correction model according to an exemplary embodiment;

[0041] Figure 2 is a flow chart of a method for establishing a text error correction model according to an exemplary embodiment;

[0042] Figure 3 is based on Figure 2 The embodiment is a flowchart showing the details of step 220 of an embodiment;

[0043] Figure 4 is a block diagram of a text error correction model establishment device according to an exemplary embodiment;

[0044] Figure 5 is an example block diagram of an electronic device for implementing the above-mentioned text error correction model establishment method according to an exemplary embodiment;

[0045] Figure 6 A program product for implementing the above-mentioned text error correction model establishment method is shown according to an exemplary embodiment. DETAILED DESCRIPTION

[0046] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Instead, they are merely examples of devices and methods consistent with some aspects of the present invention as detailed in the appended claims.

[0047] In addition, the accompanying drawings are only schematic illustrations of the present disclosure and are not necessarily drawn to scale. The same reference numerals in the drawings represent the same or similar parts, and their repeated descriptions will be omitted. Some of the block diagrams shown in the accompanying drawings are functional entities and do not necessarily correspond to physically or logically independent entities.

[0048] The present disclosure first provides a method for establishing a text error correction model. Text error correction refers to the process of determining the erroneous text content in a given text and modifying the erroneous text content to the correct text content. The given text here can be of any length, such as a phrase, a sentence, a paragraph or even an article. At the same time, the given text here can also be written in various languages, including but not limited to Chinese, English, French, etc. The text error correction model establishment method provided by the present disclosure can establish a model that can automatically perform text error correction, that is, train a text error correction model, and use the established model to automatically complete the text error correction task.

[0049] The implementation terminal of the present disclosure can be any device with computing, processing and communication functions, which can be connected to an external device for receiving or sending data. Specifically, it can be a portable mobile device, such as a smart phone, a tablet computer, a laptop computer, a PDA (Personal Digital Assistant), etc., or it can be a fixed device, such as a computer device, a field terminal, a desktop computer, a server, a workstation, etc. It can also be a collection of multiple devices, such as the physical infrastructure of cloud computing or a server cluster.

[0050] Optionally, the implementation terminal of the present disclosure may be a server or a physical infrastructure of cloud computing.

[0051] Figure 1 FIG. 1 is a schematic diagram of a system architecture of a method for establishing a text error correction model according to an exemplary embodiment. Figure 1 As shown, the system architecture includes a personal computer 110 and a server 120, which are connected via a communication link and can be used to send or receive data. The server 120 is an implementation terminal in this embodiment. The personal computer 110 is deployed with a text corpus for establishing a text error correction model, and the server 120 is provided with a given ELECTRA model and a pre-trained text filling module. When a text error correction model establishment method provided by the present disclosure is applied to Figure 1 In the system architecture shown, a process may be as follows: first, the server 120 obtains the text corpus uploaded by the personal computer 110; then, the server 120 performs the first training step and the second training step of training using the ELECTRA model given by the obtained text corpus, wherein the first training step trains the generator and the discriminator in the ELECTRA model respectively, and the second training step trains the discriminator in the ELECTRA model; finally, when the training is completed, the trained discriminator is connected to the pre-trained text filling module to obtain a text error correction model.

[0052] It is worth mentioning that Figure 1 This is only one embodiment of the present disclosure. Although the implementation terminal in this embodiment is a server, in other embodiments, the implementation terminal may be various terminals or devices as described above; although in this embodiment, the text corpus is located on a personal computer outside the implementation terminal, that is, the text corpus is obtained from a personal computer outside the implementation terminal, in other embodiments or specific applications, the text corpus may be located locally in the implementation terminal, that is, the text corpus can be directly obtained locally. The present disclosure does not make any limitation on this, and the protection scope of the present disclosure should not be limited in any way.

[0053] Figure 2is a flow chart of a method for establishing a text error correction model according to an exemplary embodiment. The method for establishing a text error correction model provided in this embodiment can be executed by a server, such as Figure 2 As shown, the following steps are included:

[0054] Step 210, obtaining text corpus.

[0055] The text corpus here can be a general text corpus, that is, it can be a text corpus different from the scenario in which the text error correction model is applied. Specifically, the text corpus here can be text corpus on various web pages on the Chinese Internet, and the corpus in the scenario in which the text error correction model is applied can be, for example, chat corpus, medical literature corpus, or literature book corpus.

[0056] The text corpus consists of multiple characters (tokens).

[0057] The training step of the ELECTRA model is performed using the first loss function, including the following steps 220 to 250, specifically:

[0058] Step 220, obtaining a first character vector corresponding to the character retained in the text corpus after random masking processing.

[0059] Wherein, the text corpus includes multiple characters.

[0060] Masking is the process of masking characters in the training text corpus with a single character or string. Random masking is the process of randomly selecting characters in the training text corpus for masking. For example, the training text corpus can be "I am an earthling", and after masking, it can become "I [MASK] earthling". In this example, the character "is" is masked by [MASK].

[0061] Figure 3 is based on Figure 2 The embodiment shows a flowchart of the details of step 220 of an embodiment. Figure 3 As shown, step 220 specifically includes the following steps:

[0062] Step 221: convert the text corpus into a plurality of first character vectors.

[0063] The text corpus includes a plurality of characters, and each character corresponds to a first character vector.

[0064] In one embodiment, converting the text corpus into a plurality of first character vectors includes:

[0065] Divide the text corpus into multiple characters;

[0066] Each of the characters is converted into a corresponding first character vector according to a preset vocabulary.

[0067] For example, the preset vocabulary can record the position information of each character, and a one-hot encoding vector can be generated using the position information and one-hot encoding. Then, the one-hot encoding vector can be multiplied by a weight matrix to obtain the corresponding first character vector.

[0068] Step 222: randomly masking the first character vectors corresponding to the characters in a first predetermined proportion in the text corpus to obtain the first character vectors corresponding to the characters retained in the text corpus.

[0069] The first predetermined ratio may be any ratio value set manually, for example, it may be 15%. At this time, if the text corpus includes 100 characters, the first character vectors corresponding to 15 characters will be masked.

[0070] In one embodiment, obtaining a first character vector corresponding to a character retained in the text corpus after random masking includes:

[0071] Randomly performing masking processing on a second predetermined proportion of characters in the text corpus, wherein the text corpus includes a plurality of characters;

[0072] Each character retained in the text corpus is converted into a corresponding first character vector.

[0073] Similar to the first predetermined ratio, the second predetermined ratio may also be an arbitrary ratio value set manually.

[0074] It can be determined from the above embodiments that the execution order of the two operations of converting the character into the first character vector and the masking process can be replaced with each other, that is, the character itself can be masked, and the first character vector can also be masked.

[0075] Step 230, input the first character vector corresponding to the retained character into the ELECTRA model, so that the generator module in the ELECTRA model outputs multiple second character vectors corresponding to the text corpus, and the discriminator module in the ELECTRA model outputs a first prediction result of whether each second character vector matches the corresponding character in the text corpus.

[0076] ELECTRA (Efficiently Learning an Encoder that Classifies TokenReplacements Accurately) includes a generator and a discriminator, that is, the discriminator module and the generator module in this article. The generator can restore the masked text corpus, while the discriminator can identify the erroneous text corpus in the restored text corpus.

[0077] The generator and discriminator include multiple layers of transformers. The transformer includes an encoder and a decoder. The structure of a single-layer transformer can be summarized as follows:

[0078] x2=Attention(x1); x2=Dropout1(Dense1(x2));

[0079] x2=LayerNormalization1(x1+x2); x3=Dropout2(Dense3(Dense2(x2)));

[0080] x3=LayerNormalization2(x2+x3).

[0081] Among them, Attention represents the attention mechanism, Dense represents the fully connected layer, Dropout represents the random discarding of input, and LayerNormalization represents the layer normalization. x1, x2, and x3 represent the input or output data of each structure.

[0082] The multi-layer Transformer is connected sequentially as follows:

[0083] x1 = Transformer_1(x0);

[0084] x2 = Transformer_2(x1);

[0085] …

[0086] xn=Transformer_n(xn-1).

[0087] Among them, xn is the final output of the network body.

[0088] The first prediction result is a result of the binary classification output of the discriminator module based on the softmax function. For example, the first prediction result may be a vector consisting of elements 0 and 1, where 0 indicates a match and 1 indicates a mismatch.

[0089] Step 240: Calculate a first loss function based on the text corpus, the second character vector, and the first prediction result.

[0090] Specifically, the first loss function can be calculated using the following formula:

[0091] L1=L MLM +λ·L2,

[0092]

[0093]

[0094] Among them, L1 is the first loss function, L2 is the second loss function, λ is the preset proportional coefficient, L MLM is the loss function of the generator module, Softmax is the Softmax layer of the generator module, x′ i The second character vector of the i-th character, y i is the character vector corresponding to the i-th character of the text corpus, n is the number of characters in the text corpus, x″ i is the first prediction result, x i is the i-th character, is the character obtained by replacing the i-th character according to the maximum probability prediction value of the second character vector.

[0095] Step 250: If the first loss function does not meet the corresponding first convergence condition, the step of obtaining the first character vector corresponding to the character retained in the text corpus after random masking processing and subsequent steps are executed.

[0096] The first convergence condition is the condition for terminating the training steps of the ELECTRA model between step 220 and step 250, and can be defined, for example, as the value of the first loss function being less than a predetermined threshold.

[0097] When the first loss function fails to reach the corresponding first convergence condition, step 220 to step 250 will be re-executed.

[0098] Through the above training steps, the prediction errors of the generator module are highly confusing, which increases the learning difficulty of the discriminator module and can quickly improve the performance of the model.

[0099] Next, the second loss function is used to perform a training step on the discriminator module, including the following steps 260 to 290, specifically:

[0100] Step 260: Obtain a third character vector corresponding to the character in the text corpus after random replacement processing.

[0101] Similar to the specific implementation of the random masking process, the specific implementation of the random replacement process can also be performed through the following two embodiments.

[0102] In one embodiment, the character in the text corpus is a first character, and obtaining a third character vector corresponding to the character in the text corpus after random replacement processing includes:

[0103] Convert the first character in the text corpus to the corresponding third character vector;

[0104] Randomly determine the first character to be replaced as the target first character;

[0105] Determine a second character corresponding to the target first character, wherein the second character is used to perform random replacement processing on a third character vector corresponding to the target first character;

[0106] Convert the second character to a corresponding third character vector;

[0107] The third character vector corresponding to the target first character in the third character vector corresponding to the first character in the text corpus is replaced with the third character vector corresponding to the second character.

[0108] In one embodiment, the character in the text corpus is a first character, and obtaining a third character vector corresponding to the character in the text corpus after random replacement processing includes:

[0109] Randomly determine the first character to be replaced as the target first character;

[0110] Determine a second character corresponding to the target first character, wherein the second character is used to perform a random replacement process on the target first character;

[0111] Replacing each target first character in the text corpus with a corresponding second character;

[0112] Each character in the replaced text corpus is converted into a corresponding third character vector.

[0113] Through the above two embodiments, it can be determined that the execution order of converting the character into the third character vector and the replacement operation can be replaced with each other, that is, the character itself can be randomly replaced, and the third character vector can also be randomly replaced.

[0114] In one embodiment, determining the second character corresponding to the target first character includes:

[0115] For each of the target first characters, determine a character with the same pinyin as the target first character as the second character corresponding to the target first character.

[0116] For example, the characters "人" and "仁" have the same pinyin, so they can be replaced with each other.

[0117] In this embodiment, by performing replacement processing using characters with the same pinyin, the confusion of characters in the text corpus is increased. Therefore, the training effect can be improved.

[0118] In one embodiment, the determining the second character corresponding to the target first character includes:

[0119] For each of the target first characters, determine a character whose similarity to the pinyin of the target first character reaches a predetermined index as the second character corresponding to the target first character.

[0120] For example, the pinyin of "陈" and "程", "李" and "林" are similar enough to be replaced with each other.

[0121] In this embodiment, by performing replacement processing using characters with similar pinyin, the confusion of characters in the text corpus is further increased. Therefore, the training effect can be further improved.

[0122] In one embodiment, the determining the second character corresponding to the target first character includes:

[0123] For each of the target first characters, randomly select a character from a pre-established dictionary as the second character corresponding to the target first character.

[0124] In this embodiment, by determining the second character in a random selection from the dictionary, the types of errors in the text corpus are increased, and the confusion of characters in the text corpus is improved. Therefore, the training effect can be further improved.

[0125] In one embodiment, the randomly determining the first character to be subject to replacement processing as the target first character includes:

[0126] Obtain a text corpus sample set, where the text corpus sample set includes a plurality of text corpus samples, the incorrect characters in each text corpus sample, and the correct characters corresponding to each incorrect character;

[0127] Obtain the correct characters ranked in the top predetermined proportion in descending order of quantity from the correct characters as the target correct characters;

[0128] Use the target correct characters in the text corpus as the target first characters.

[0129] In this embodiment, by counting the correct characters corresponding to the incorrect characters in the text corpus sample set, the correct characters with a larger number are used as target correct characters, and the target first character is determined in the text corpus based on the target correct characters, so that the model can learn the characters that are prone to errors in a timely manner, thereby quickly improving the performance of the model.

[0130] The above embodiment provides three methods of determining the second character, namely homophones, near-phonetic characters, and dictionaries, and one method of determining the target first character. However, in actual situations, for characters in the same text corpus, the above methods can be arbitrarily combined to perform random replacement processing.

[0131] Step 270: input the third character vector into the discriminator module to obtain a second prediction result output by the discriminator module.

[0132] The second prediction result indicates whether each of the third character vectors matches the corresponding character in the text corpus.

[0133] Step 280: Calculate a second loss function based on the text corpus and the second prediction result.

[0134] Specifically, the second loss function can be calculated using the following formula:

[0135]

[0136] Wherein, L2 is the second loss function, n is the number of characters in the text corpus, and x″ i is the second prediction result, x i is the i-th character, is the character obtained by randomly replacing the i-th character.

[0137] Step 290: If the second loss function does not meet the corresponding second convergence condition, the step of obtaining the third character vector corresponding to the character in the text corpus after random replacement processing and subsequent steps are executed.

[0138] The second convergence condition is the condition for terminating the training step of the discriminator module between step 260 and step 290. For example, it can be defined as the value of the second loss function being less than a predetermined threshold. The second convergence condition can be the same or similar to the first convergence condition, or can be completely different.

[0139] If the second loss function does not meet the corresponding second convergence condition, step 260 to step 290 will be re-executed.

[0140] In one embodiment, each time the training step performed using the first loss function is iteratively executed a first predetermined number of times, the training step performed using the second loss function is iteratively executed a second predetermined number of times, and after the training step performed using the second loss function is iteratively executed, the training step performed using the first loss function is iteratively executed again.

[0141] In other words, in this embodiment, the training step performed using the first loss function and the training step performed using the second loss function are iteratively performed in sequence.

[0142] In one embodiment, the training step performed using the first loss function and the training step performed using the second loss function are performed alternately.

[0143] After executing a round of training steps using the first loss function, another round of training steps using the second loss function is executed, and after executing a round of training steps using the second loss function, another round of training steps using the first loss function is executed, and so on. In this embodiment, since the two sets of training steps are executed alternately, the generator module and the discriminator module can be trained alternately and progressively, so that the output of the generator module can be well matched with the discriminator module, thereby obtaining a good training effect.

[0144] Through the above-mentioned training step performed using the second loss function, the discriminator is further trained by additionally constructing text errors using a random replacement process operation, which further improves the performance of the discriminator.

[0145] In one embodiment, the training step performed using the first loss function and the training step performed using the second loss function are performed based on the AdamW optimization algorithm to train the ELECTRA model.

[0146] By using the AdamW optimization algorithm for training, the model training can converge quickly, thereby ensuring training efficiency.

[0147] Next, a docking step will be performed, which includes:

[0148] Step 2100, docking the discriminator module with a pre-trained text filling module to obtain a text error correction model.

[0149] After the discriminator module is connected to the pre-trained text filling module, the output result of the discriminator module will be input into the pre-trained text filling module as input information.

[0150] The pre-trained text filling module can be based on various models that can restore or recover the text corpus after random masking.

[0151] In one embodiment, the pre-trained text filling module is established based on the Bert model.

[0152] The BERT (Bidirectional Encoder Representation from Transformers) model can perform tasks such as text classification, word segmentation, and word generation. It is also built on the Transformer module.

[0153] The final output layer of the BERT model is based on the softmax function for multi-classification output, and the number of categories corresponds to the number of words in the vocabulary.

[0154] The discriminator module of the text error correction model may also include a module for vector conversion before it, which can convert text into word vector representation.

[0155] Specifically, the data processing process when applying the text error correction model is as follows: after a section of text corpus is input into the text error correction model, the characters in the section of text corpus are first converted into word vector representations, such as [t1, t2, t3, t4, t5], and then the word vector representation is input into the discriminator module to obtain a prediction result vector, such as [0, 0, 0, 0, 1], where 1 indicates that the corresponding character is an incorrect character. Next, the corresponding elements in the word vector representation are masked according to the position of the incorrect character in the prediction result vector, and the masked word vector representation is input into a pre-trained text filling module, such as the BERT model, to finally obtain the corrected text corpus output by the pre-trained text filling module.

[0156] In one embodiment, the text corpus is a common text corpus belonging to multiple scenarios, and the pre-trained text filling module is trained using the text corpus of the scenario to which the text error correction model is applied.

[0157] In this embodiment, the ELECTRA model is trained by using common text corpora belonging to multiple scenarios, so that the ELECTRA model can be trained using a wider range of corpus data, and the discriminator in the trained ELECTRA model can effectively identify the positions of erroneous characters in the text corpus. On this basis, since the pre-trained text filling module is specifically trained using the text corpus of the scenario to which the text error correction model is applied, the accuracy of the error correction is guaranteed.

[0158] In one embodiment, the discriminator module is interfaced with the pre-trained text filling module via a bidirectional long short-term memory network.

[0159] In this embodiment, a bidirectional long short-term memory network (Bi-LSTM) is also included between the discriminator module and the pre-trained text filling module. By utilizing the bidirectional long short-term memory network to extract bidirectional temporal feature information of the text corpus, various performance indicators such as the accuracy of the text error correction model can be improved.

[0160] In one embodiment, after performing the docking step, the method further comprises:

[0161] Obtaining the text corpus output by the text error correction model within the predetermined time period at every predetermined time period;

[0162] Sending the text corpus to a user terminal, and having a user of the user terminal verify the text corpus to obtain a verified text corpus returned by the user terminal;

[0163] The first training step and the second training step are re-executed using the text corpus and the verification text corpus to further train the text error correction model.

[0164] In this embodiment, the text error correction model is trained again by periodically acquiring text corpus output by the text error correction model and corresponding verification text corpus, so that the performance of the text error correction model can be continuously improved.

[0165] In summary, according to Figure 2 The text error correction model establishment method provided in the embodiment trains the text error correction model based on the ELECTRA model. By training the model using two sets of training steps, correct corpus data can be fully utilized to train the text error correction model. A model that effectively completes the text error correction task can be established without using incorrectly annotated corpus data, thereby reducing the data annotation cost and enabling the trained text error correction model to obtain better training results, thereby improving the error correction effect of the text error correction model.

[0166] The present disclosure also provides a device for establishing a text error correction model. The following is an embodiment of the device of the present disclosure.

[0167] Figure 4 FIG. 1 is a block diagram of a text error correction model establishment device according to an exemplary embodiment. Figure 4 As shown, the device 400 includes:

[0168] The acquisition module 410 is configured to acquire text corpus;

[0169] The first training step execution module 420 is configured to execute a training step on the ELECTRA model using a first loss function, including:

[0170] Obtaining a first character vector corresponding to a character retained in the text corpus after random masking, wherein the text corpus includes a plurality of characters;

[0171] Inputting the first character vector corresponding to the retained character into the ELECTRA model so that the generator module in the ELECTRA model outputs a plurality of second character vectors corresponding to the text corpus, and the discriminator module in the ELECTRA model outputs a first prediction result of whether each second character vector matches a corresponding character in the text corpus;

[0172] Calculate a first loss function based on the text corpus, the second character vector and the first prediction result;

[0173] If the first loss function does not meet the corresponding first convergence condition, executing the step of obtaining the first character vector corresponding to the character retained in the text corpus after random masking processing and subsequent steps;

[0174] The second training step execution module 430 is configured to perform a training step on the discriminator module using a second loss function, including:

[0175] Obtaining a third character vector corresponding to the character in the text corpus after random replacement processing;

[0176] Inputting the third character vectors into the discriminator module to obtain a second prediction result output by the discriminator module, wherein the second prediction result indicates whether each of the third character vectors matches a corresponding character in the text corpus;

[0177] Calculate a second loss function based on the text corpus and the second prediction result;

[0178] If the second loss function does not meet the corresponding second convergence condition, executing the step of obtaining a third character vector corresponding to the character in the text corpus after random replacement processing and subsequent steps;

[0179] The docking step execution module 440 is configured to execute the docking step, which includes: docking the discriminator module with a pre-trained text filling module to obtain a text error correction model.

[0180] According to a third aspect of the present disclosure, an electronic device capable of implementing the above method is also provided.

[0181] It will be appreciated by those skilled in the art that various aspects of the present invention may be implemented as a system, method or program product. Therefore, various aspects of the present invention may be specifically implemented in the following forms, namely: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software, which may be collectively referred to herein as a "circuit", "module" or "system".

[0182] Refer to the following Figure 5 The electronic device 500 according to this embodiment of the present invention is described. Figure 5 The electronic device 500 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0183] like Figure 5 As shown, the electronic device 500 is in the form of a general computing device. The components of the electronic device 500 may include but are not limited to: at least one processing unit 510, at least one storage unit 520, and a bus 530 connecting different system components (including the storage unit 520 and the processing unit 510).

[0184] The storage unit stores program codes, which can be executed by the processing unit 510, so that the processing unit 510 executes the steps according to various exemplary embodiments of the present invention described in the above “Embodiment Method” section of this specification.

[0185] The storage unit 520 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 521 and / or a cache memory unit 522 , and may further include a read-only memory unit (ROM) 523 .

[0186] The storage unit 520 may also include a program / utility 524 having a set (at least one) of program modules 525, such program modules 525 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.

[0187] Bus 530 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.

[0188] The electronic device 500 may also communicate with one or more external devices 700 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 500, and / or may communicate with any device that enables the electronic device 500 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 550, such as communicating with a display unit 540. Furthermore, the electronic device 500 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter 560. As shown, the network adapter 560 communicates with other modules of the electronic device 500 via a bus 530. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 500, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0189] Through the description of the above implementation, it is easy for those skilled in the art to understand that the example implementation described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the implementation of the present disclosure.

[0190] According to a fourth aspect of the present disclosure, a computer-readable storage medium is also provided, on which a program product capable of implementing the above method of the present specification is stored. In some possible implementations, various aspects of the present invention may also be implemented in the form of a program product, which includes a program code, and when the program product is run on a terminal device, the program code is used to enable the terminal device to perform the steps according to various exemplary implementations of the present invention described in the above "Exemplary Method" section of the present specification.

[0191] refer to Figure 6 As shown, a program product 600 for implementing the above method according to an embodiment of the present invention is described, which can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited thereto. In this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, an apparatus or a device.

[0192] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0193] Computer readable signal media may include data signals propagated in baseband or as part of a carrier wave, in which readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Readable signal media may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0194] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing.

[0195] Program code for performing the operations of the present invention may be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java, C++, etc., and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., through the Internet using an Internet service provider).

[0196] In addition, the above-mentioned figures are only schematic illustrations of the processes included in the method according to an exemplary embodiment of the present invention, and are not intended to be limiting. It is easy to understand that the processes shown in the above-mentioned figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.

[0197] It should be understood that the present invention is not limited to the exact construction that has been described above and shown in the drawings and that various modifications and changes may be performed without departing from its scope. The scope of the present invention is limited only by the appended claims.

Claims

1. A method for establishing a text error correction model, characterized in that: The method comprises: Get text corpus; The training steps for the ELECTRA model using the first loss function include: Obtaining a first character vector corresponding to a character retained in the text corpus after random masking, wherein the text corpus includes a plurality of characters; Inputting the first character vector corresponding to the retained character into the ELECTRA model so that the generator module in the ELECTRA model outputs a plurality of second character vectors corresponding to the text corpus, and the discriminator module in the ELECTRA model outputs a first prediction result of whether each second character vector matches a corresponding character in the text corpus; Calculate a first loss function based on the text corpus, the second character vector and the first prediction result; The first loss function is calculated using the following formula: L1=L MLM +λ·L2, Among them, L1 is the first loss function, L2 is the second loss function, λ is the preset proportional coefficient, L MLM is the loss function of the generator module, sofmax is the sofmax layer of the generator module, and x′ i The second character vector of the i-th character, y i is the character vector corresponding to the i-th character of the text corpus, n is the number of characters in the text corpus, x″ i is the first prediction result, x i is the i-th character, is the character obtained by replacing the i-th character according to the maximum probability prediction value of the second character vector; If the first loss function does not meet the corresponding first convergence condition, executing the step of obtaining the first character vector corresponding to the character retained in the text corpus after random masking processing and subsequent steps; The step of training the discriminator module using a second loss function comprises: Obtaining a third character vector corresponding to a character in the text corpus after random replacement processing; the character in the text corpus is a first character, and obtaining the third character vector corresponding to the character in the text corpus after random replacement processing includes: converting the first character in the text corpus into a corresponding third character vector; randomly determining a first character to be replaced as a target first character; for each of the target first characters, determining a character having the same pinyin as the target first character as a second character corresponding to the target first character; Inputting the third character vectors into the discriminator module to obtain a second prediction result output by the discriminator module, wherein the second prediction result indicates whether each of the third character vectors matches a corresponding character in the text corpus; Calculate a second loss function based on the text corpus and the second prediction result; If the second loss function does not meet the corresponding second convergence condition, executing the step of obtaining a third character vector corresponding to the character in the text corpus after random replacement processing and subsequent steps; A docking step is performed, wherein the docking step includes: docking the discriminator module with a pre-trained text filling module to obtain a text error correction model.

2. The method according to claim 1, characterized in that The obtaining of a first character vector corresponding to a character retained in the text corpus after random masking includes: Converting a text corpus into a plurality of first character vectors, wherein the text corpus includes a plurality of characters, and each character corresponds to a first character vector; Randomly mask first character vectors corresponding to a first predetermined proportion of characters in the text corpus to obtain first character vectors corresponding to characters retained in the text corpus.

3. The method according to claim 2, characterized in that The step of converting the text corpus into a plurality of first character vectors includes: Divide the text corpus into multiple characters; Each of the characters is converted into a corresponding first character vector according to a preset vocabulary.

4. The method according to claim 1, characterized in that: The second character is used to perform random replacement processing on the third character vector corresponding to the target first character, and the obtaining of the third character vector corresponding to the character in the text corpus after the random replacement processing also includes: Convert the second character to a corresponding third character vector; The third character vector corresponding to the target first character in the third character vector corresponding to the first character in the text corpus is replaced with the third character vector corresponding to the second character.

5. The method according to any one of claims 1 to 4, characterized in that: The training steps performed using the first loss function and the training steps performed using the second loss function are performed alternately.

6. The method according to any one of claims 1 to 4, characterized in that: The text corpus is a general text corpus belonging to multiple scenarios, and the pre-trained text filling module is trained using the text corpus of the scenario to which the text error correction model is applied.

7. A text error correction model building device, characterized in that: The device comprises: An acquisition module, configured to acquire text corpus; The first training step execution module is configured to execute a training step on the ELECTRA model using a first loss function, including: Obtaining a first character vector corresponding to a character retained in the text corpus after random masking, wherein the text corpus includes a plurality of characters; Inputting the first character vector corresponding to the retained character into the ELECTRA model so that the generator module in the ELECTRA model outputs a plurality of second character vectors corresponding to the text corpus, and the discriminator module in the ELECTRA model outputs a first prediction result of whether each second character vector matches a corresponding character in the text corpus; Calculate a first loss function based on the text corpus, the second character vector and the first prediction result; The first loss function is calculated using the following formula: L1=L MLM +λ·L2, Among them, L1 is the first loss function, L2 is the second loss function, λ is the preset proportional coefficient, L MLM is the loss function of the generator module, sofmax is the sofmax layer of the generator module, and x′ i The second character vector of the i-th character, y i is the character vector corresponding to the i-th character of the text corpus, n is the number of characters in the text corpus, x″ i is the first prediction result, x i is the i-th character, is the character obtained by replacing the i-th character according to the maximum probability prediction value of the second character vector; If the first loss function does not meet the corresponding first convergence condition, executing the step of obtaining the first character vector corresponding to the character retained in the text corpus after random masking processing and subsequent steps; The second training step execution module is configured to perform a training step on the discriminator module using a second loss function, including: Obtaining a third character vector corresponding to a character in the text corpus after random replacement processing; the character in the text corpus is a first character, and when the second training step execution module obtains the third character vector corresponding to a character in the text corpus after random replacement processing, it is further configured to: convert the first character in the text corpus into a corresponding third character vector; randomly determine a first character to be replaced as a target first character; for each of the target first characters, determine a character that has the same pinyin as the target first character as a second character corresponding to the target first character; Inputting the third character vectors into the discriminator module to obtain a second prediction result output by the discriminator module, wherein the second prediction result indicates whether each of the third character vectors matches a corresponding character in the text corpus; Calculate a second loss function based on the text corpus and the second prediction result; If the second loss function does not meet the corresponding second convergence condition, executing the step of obtaining a third character vector corresponding to the character in the text corpus after random replacement processing and subsequent steps; The docking step execution module is configured to execute the docking step, and the docking step includes: docking the discriminator module with a pre-trained text filling module to obtain a text error correction model.

8. A computer-readable program medium, characterized in that The computer program instructions are stored therein, and when the computer program instructions are executed by a computer, the computer is caused to execute the method according to any one of claims 1 to 6.

9. An electronic device, characterized in that: The electronic device comprises: processor; A memory having computer-readable instructions stored thereon, wherein when the computer-readable instructions are executed by the processor, the method according to any one of claims 1 to 6 is implemented.