A Chinese text error correction method and device based on deep learning
By improving the BERT model and combining it with the global attention model, paying attention to the hidden states of all decoders, we solve the problem of poor error correction in Chinese text caused by only focusing on local information in the existing technology, and achieve higher error correction accuracy. and user experience.
Patent Information
- Application Number
- CN202210539475.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-18
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2042-05-18
AI Technical Summary
Existing Chinese text error correction methods only focus on part of the information of the input sequence and cannot focus on global information, resulting in poor error correction effects.
Using the improved BERT model, the candidate word set is added to the replacement team and the probability of candidate word replacement is increased. It is combined with the global attention model for decoding and pays attention to the hidden states of all decoders to correct text errors.
It improves the accuracy of Chinese text error correction, reduces noise, and makes up for the shortcomings of the local attention mechanism, making Chinese text error correction under robot speech recognition and question and answer tasks more accurate.
Smart Images

Figure CN114912442B
Abstract
Description
Technical Field
[0001] The present application relates to the field of natural language processing technology, and in particular to a Chinese text error correction method and device based on deep learning. Background Art
[0002] In robot speech recognition and question-answering tasks, due to the influence of Chinese similarity factors such as easily confused words, words with the same pinyin but different glyphs, and words with similar glyphs but different meanings, the robot may not recognize the user's intentions, resulting in the execution of incorrect tasks or the inability to recognize tasks.
[0003] Existing Chinese text error correction methods are generally based on the concatenation of different language models or deep learning models, and most of the error correction methods are based on context information. The attention mechanism used is mostly a local attention mechanism. This method focuses on part of the input sequence information during decoding, rather than the hidden state of all decoders, and cannot pay attention to global information, resulting in poor error correction effect. Summary of the invention
[0004] The embodiments of the present application provide a Chinese text error correction method and device based on deep learning, which are used to solve the following technical problems: the existing Chinese text error correction method only focuses on part of the information of the input sequence, fails to focus on the global information, and has a poor error correction effect.
[0005] The present application embodiment adopts the following technical solutions:
[0006] On the one hand, an embodiment of the present application provides a Chinese text correction method based on deep learning, the method comprising: training an improved BERT model based on a preset training sequence to obtain a BERT improved model; encoding the text to be corrected through the BERT improved model to obtain a feature vector of each character in the text to be corrected, context features, and a preset number of candidate word vectors corresponding to each character; decoding the feature vector of each character in the text to be corrected, context features, and the preset number of candidate word vectors through a global attention model to obtain the corrected text.
[0007] In a feasible implementation, based on a preset training sequence, an improved BERT model is trained to obtain an improved BERT model, specifically comprising: pre-acquiring a candidate character set from the Internet; wherein the candidate character set includes characters that are easy to make mistakes and confuse, characters with the same pinyin but different glyphs, and characters with similar glyphs but different meanings; combining the candidate character set with the BERT model to obtain an improved BERT model; inputting the preset training sequence into the improved BERT model to obtain the improved BERT model.
[0008] In a feasible implementation, the candidate word set is combined with the BERT model to obtain an improved BERT model, specifically including: setting the probability of replacing the word to be replaced corresponding to each token position in each training sequence with "mask" to 35%, the probability of replacing it with the candidate word vector in the candidate word set to 30%, the probability of replacing it with the word to be replaced corresponding to other token positions to 10%, and the probability of remaining unchanged to 25%, to obtain the improved BERT model.
[0009] In a feasible implementation, the text to be corrected is encoded by the BERT improved model to obtain a feature vector of each word in the text to be corrected, context features, and a preset number of candidate word vectors corresponding to each word, specifically including: inputting the text to be corrected into the trained BERT improved model so that the BERT improved model outputs the feature vector of each word in the text to be corrected and the judgment result of each word; wherein the judgment result is correct or incorrect; outputting a preset number of candidate word vectors corresponding to each word in the text to be corrected in the candidate word set by the BERT improved model; and obtaining the context features of each word in the text to be corrected according to the feature vector of each word in the text to be corrected.
[0010] In a feasible implementation, the BERT improved model is used to output a preset number of candidate word vectors corresponding to each word in the text to be corrected in the candidate word set, specifically including: outputting the first K candidate word vectors corresponding to each word in the text to be corrected in the candidate word set through the BERT improved model; wherein K∈[1,N i ],N i is the total number of candidate characters corresponding to the i-th character in the text to be corrected in the candidate character set; the candidate character vector is a word embedding vector.
[0011] In a feasible implementation, after outputting the first K candidate word vectors corresponding to each word in the text to be corrected in the candidate word set through the BERT improved model, the method further includes: performing regularization processing on the obtained candidate word vector to obtain a regularized candidate word vector.
[0012] In a feasible implementation, the feature vector of each word in the text to be corrected, the context features, and the preset number of candidate word vectors are decoded through a global attention model to obtain a corrected text, specifically including: if the judgment result of any one or more words in the text to be corrected is wrong, then from all the obtained regularized candidate word vectors, K regularized candidate word vectors corresponding to the words with the judgment result of being wrong are selected; the selected regularized candidate word vectors are input into the global attention model together with the context features for decoding to obtain the corrected text.
[0013] In a feasible implementation, the selected regularized candidate word vector is input into the global attention model together with the context features for decoding to obtain the corrected text, specifically comprising: performing weighted summation processing on the input regularized candidate word vector through the global attention mechanism in the global attention model to obtain the weighted features corresponding to each regularized candidate word vector; based on the weighted features and the context features, determining the candidate word with the highest accuracy to replace the wrong word in the text to be corrected to obtain the corrected text.
[0014] In a feasible implementation, the global attention model is used to match k weighted features of any input wrong character with the context features of the wrong character, and the candidate character corresponding to the weighted feature with the highest matching degree is determined as the candidate character with the highest accuracy rate, and the wrong character is replaced. After all the wrong characters in the text to be corrected are replaced, the corrected text is output.
[0015] On the other hand, an embodiment of the present application also provides a Chinese text correction device based on deep learning, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor so that the at least one processor can execute a Chinese text correction method based on deep learning according to any of the above embodiments.
[0016] The embodiment of the present application adds the candidate character set to the replacement team of the BERT model and appropriately increases the probability of the token being replaced by the candidate character set, so that the BERT model can output the first few candidate characters closest to each character in the recognized text when identifying the text to be corrected, and then input the candidate characters into the global attention model to obtain the corrected text. The attention mechanism of many Chinese text correction methods is a local attention mechanism, which mainly focuses on part of the information of the input sequence during decoding, rather than the hidden state of all decoders. The present application uses a decoder with a global attention mechanism, which can reduce noise, make up for the shortcomings of the local attention mechanism, and improve the accuracy of text correction. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0018] Figure 1 A flow chart of a Chinese text error correction method based on deep learning provided in an embodiment of the present application;
[0019] Figure 2 A schematic diagram of Chinese text error correction provided in an embodiment of the present application;
[0020] Figure 3 A schematic diagram of the structure of a Chinese text error correction device based on deep learning provided in an embodiment of the present application. DETAILED DESCRIPTION
[0021] In order to enable those skilled in the art to better understand the technical solutions in this application, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are only part of the embodiments of this application, not all of them. Based on the embodiments of this specification, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this application.
[0022] The present application embodiment provides a Chinese text error correction method based on deep learning, such as Figure 1 As shown, the Chinese text error correction method based on deep learning specifically includes steps S101-S106:
[0023] S101. Based on a preset training sequence, the improved BERT model is trained to obtain a BERT improved model.
[0024] Specifically, firstly, a candidate character set is pre-collected on the Internet, wherein the candidate character set includes characters that are easy to be mistaken or confused, characters with the same pinyin but different glyphs, and characters with similar glyphs but different meanings.
[0025] In one embodiment, characters that are easy for users to make mistakes or confuse, characters with the same pinyin but different glyphs, and characters with similar glyphs but different meanings can be collected in Google to form a candidate character set.
[0026] Furthermore, the candidate word set is combined with the existing BERT model to obtain an improved BERT model. The preset training sequence is input into the improved BERT model to obtain the BERT improved model.
[0027] Among them, the method for improving the BERT model is: the probability of replacing the to-be-replaced word corresponding to each token position in each training sequence with "mask" is set to 35%, the probability of replacing it with a candidate word vector in the candidate word set is set to 30%, the probability of replacing it with the to-be-replaced word corresponding to other token positions is set to 10%, and the probability of remaining unchanged is set to 25%, thereby obtaining the improved BERT model.
[0028] As a feasible implementation method, when performing pre-training tasks, the existing BERT model will randomly select a token position in each training sequence with a probability of 15% for prediction, and this token position will be replaced with other content with three probabilities. The existing replacement rules are: 80% probability of replacing with "mask", 10% probability of replacing with any other word in the token position, and 10% probability of remaining unchanged. However, the present application has made some adjustments here, adding the candidate word set to the replacement team, and the probability of each token in the training sequence being replaced with other words is: 35% probability of replacing with "mask", 30% probability of replacing with a candidate word in the candidate word set, 10% probability of replacing with any other token, and 25% probability of remaining unchanged. The present application adds the candidate word set to the replacement team of the BERT model, and appropriately increases the probability of a token being replaced by the candidate word set, so that the BERT model can output the first few candidate words closest to each word in the recognized text when identifying the text to be corrected, for subsequent error correction.
[0029] S102, encoding the text to be corrected by using the BERT improved model to obtain a feature vector of each word in the text to be corrected, context features, and a preset number of candidate word vectors corresponding to each word.
[0030] Specifically, the text to be corrected is input into the trained BERT improved model, so that the BERT improved model outputs the feature vector of each word in the text to be corrected and the judgment result of each word, wherein the judgment result is correct or wrong.
[0031] Furthermore, the BERT improved model is used to output a preset number of candidate word vectors corresponding to each word in the text to be corrected in the candidate word set. Then, according to the feature vector of each word in the text to be corrected, the context features of each word in the text to be corrected are obtained. Then, the obtained candidate word vectors are regularized to obtain regularized candidate word vectors.
[0032] As a feasible implementation method, the BERT improved model is used to output the first K candidate word vectors corresponding to each word in the text to be corrected in the candidate word set. i ],N iis the total number of candidate words corresponding to the i-th word in the text to be corrected in the candidate word set. The candidate word vector is the word embedding vector.
[0033] In one embodiment, if the input text to be corrected is "How is the weather today?", assuming that there are 10 candidate characters for the word "true" in the candidate character set, then K can be set to an integer between 1 and 10, and the first K candidate characters for the word "true" are output.
[0034] S103, decoding the feature vector of each word in the text to be corrected, the context features, and a preset number of candidate word vectors through a global attention model to obtain a corrected text.
[0035] Specifically, if the judgment result of any one or more words in the text to be corrected is wrong, then among all the obtained regularized candidate word vectors, K regularized candidate word vectors corresponding to the words whose judgment result is wrong are selected. The selected regularized candidate word vectors are input into the global attention model together with the context features for decoding to obtain the corrected text. Specifically: through the global attention mechanism in the global attention model, the input regularized candidate word vectors are weighted and summed to obtain the weighted features corresponding to each regularized candidate word vector. According to the weighted features and the context features, the candidate word with the highest accuracy is determined to replace the wrong word in the text to be corrected to obtain the corrected text.
[0036] As a feasible implementation method, according to weighted features and context features, the candidate word with the highest accuracy is determined to replace the wrong word in the text to be corrected to obtain the corrected text, which specifically includes: through a global attention model, k weighted features of any input wrong word are matched with the context features of the wrong word, and the candidate word corresponding to the weighted feature with the highest matching degree is determined as the candidate word with the highest accuracy, and the wrong word is replaced. After all the wrong words in the text to be corrected are replaced, the corrected text is output.
[0037] The attention mechanism of many Chinese text error correction methods is a local attention mechanism, which focuses on part of the information of the input sequence during decoding, rather than the hidden state of all decoders. This application uses a decoder with a global attention mechanism, which can reduce noise and make up for the shortcomings of the local attention mechanism.
[0038] In one embodiment, the input of the global attention mechanism decoder in this application is: first, the context features of each word in the text to be corrected after being encoded by the improved BERT model, and second, the top k candidate words of the wrong word after being encoded by the improved BERT model. Figure 2As shown, after inputting "What's the weather like today" into the improved BERT model (i.e., the BERT modified model), the first two candidate words for the character "真" in the output sentence are: "什" and "怎". Then, it is input into the global attention decoder to output the corrected text. Each word in the candidate word set can obtain a word embedding vector after passing through the improved BERT model. After regularization, it is weighted and summed through the attention mechanism to obtain the weighted features of each token.
[0039] In addition, the embodiment of the present application also provides a Chinese text error correction device based on deep learning, as Figure 3 shown. The Chinese text error correction device based on deep learning specifically includes:
[0040] At least one processor; and a memory communicatively connected to the at least one processor; wherein,
[0041] The memory stores instructions that can be executed by the at least one processor, so that the at least one processor can execute:
[0042] Based on a preset training sequence, train the improved BERT model to obtain a BERT modified model;
[0043] Encode the text to be corrected through the BERT modified model to obtain the feature vector of each character, the context feature, and the preset number of candidate word vectors corresponding to each character in the text to be corrected;
[0044] Decode the feature vector of each character, the context feature, and the preset number of candidate word vectors in the text to be corrected through the global attention model to obtain the corrected text.
[0045] The present application proposes a Chinese text error correction method and device based on deep learning. The applicable scenarios of this method are: Chinese text error correction in robot speech recognition and question-and-answer tasks. The present application first inputs the text to be corrected, and then encodes it using an improved BERT-based model (adding a candidate word set for replacement). The difference between the present application and BERT is that the candidate word set is added to the replacement queue and the replacement probability is appropriately increased. The token in each training sequence has a slightly different replacement probability from that of BERT. And the global attention mechanism model is used to focus on all the hidden states of the decoder instead of only focusing on a part of the information in the input sequence. After training and learning with such a model, the system can enable the BERT model to output the first few candidate words closest to each character in the recognized text when recognizing the text to be corrected, and then input the candidate words into the global attention model to obtain the corrected text. Through the Chinese text error correction method provided by the present application, the accuracy of Chinese text error correction can be improved, making the Chinese text error correction in robot speech recognition and question-and-answer tasks more accurate and enhancing the user experience.
[0046] Each embodiment in this application is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0047] The above describes specific embodiments of the present application. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0048] The above is only an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the embodiments of the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the embodiments of the present application should be included in the scope of the claims of the present application.
Claims
1. A Chinese text error correction method based on deep learning, characterized in that: The method comprises: Based on the preset training sequence, the improved BERT model is trained to obtain the BERT improved model, which specifically includes: A candidate character set is obtained in advance from the Internet; wherein the candidate character set includes characters that are easy to make mistakes or confuse, characters with the same pinyin but different glyphs, and characters with similar glyphs but different meanings; the candidate character set is combined with the BERT model to obtain an improved BERT model, specifically including: The probability of replacing the to-be-replaced word corresponding to each token position in each training sequence with "mask" is set to 35%, the probability of replacing it with the candidate word vector in the candidate word set is set to 30%, the probability of replacing it with the to-be-replaced word corresponding to other token positions is set to 10%, and the probability of remaining unchanged is set to 25%, thereby obtaining the improved BERT model; Inputting the preset training sequence into the improved BERT model to obtain the improved BERT model; The text to be corrected is encoded by the BERT improved model to obtain a feature vector of each word in the text to be corrected, context features, and a preset number of candidate word vectors corresponding to each word, specifically including: Input the text to be corrected into the trained BERT improved model, so that the BERT improved model outputs the feature vector of each word in the text to be corrected and the judgment result of each word; wherein the judgment result is correct or wrong; Outputting a preset number of candidate word vectors corresponding to each word in the to-be-corrected text in the candidate word set through the BERT improved model, specifically comprising: outputting the first K candidate word vectors corresponding to each word in the to-be-corrected text in the candidate word set through the BERT improved model; wherein K∈[1,N i ],N i is the total number of candidate characters corresponding to the i-th character in the text to be corrected in the candidate character set; the candidate character vector is a word embedding vector; Regularizing the obtained candidate word vector to obtain a regularized candidate word vector; Obtaining context features of each word in the text to be corrected according to the feature vector of each word in the text to be corrected; The feature vector of each word in the text to be corrected, the context features, and the preset number of candidate word vectors are decoded through a global attention model to obtain a corrected text, specifically including: If the judgment result of any one or more words in the text to be corrected is an error, then from all the obtained regularized candidate word vectors, K regularized candidate word vectors corresponding to the words whose judgment results are errors are selected; the selected regularized candidate word vectors are input into the global attention model together with the context features for decoding to obtain the corrected text, specifically including: The global attention mechanism in the global attention model is used to perform weighted summation processing on the input regularized candidate word vector to obtain weighted features corresponding to each regularized candidate word vector; based on the weighted features and the context features, the candidate word with the highest accuracy is determined to replace the wrong word in the text to be corrected to obtain the corrected text.
2. According to the Chinese text error correction method based on deep learning according to claim 1, it is characterized in that: Determining the candidate word with the highest accuracy rate to replace the wrong word in the text to be corrected according to the weighted features and the context features to obtain the corrected text specifically includes: Through the global attention model, k weighted features of any input wrong character are matched with the context features of the wrong character, and the candidate character corresponding to the weighted feature with the highest matching degree is determined as the candidate character with the highest accuracy rate, and the wrong character is replaced. After all the wrong characters in the text to be corrected are replaced, the corrected text is output.
3. A Chinese text error correction device based on deep learning, characterized in that: The device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, so that the at least one processor can execute the Chinese text error correction method based on deep learning according to any one of claims 1-2.
