An OCR text correction method and device

By combining word embedding vectors and character structure vectors in OCR text correction, the scope of error correction is expanded, accuracy and efficiency are improved, and the problem of limited candidate word recall is solved.

CN115641591BActive Publication Date: 2026-03-31太保科技有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-08
Publication Date
2026-03-31

AI Technical Summary

Technical Problem

In existing OCR text correction systems, candidate word recall is limited to the existing confusion set, resulting in low correction accuracy and long inference time.

Method used

By calculating word embedding vectors, correct probabilities, and character structure word embedding vectors, an input word embedding vector set is formed. This set is then input into a trained error correction neural network for error correction, expanding the error correction scope. Error correction is further enhanced by combining contextual semantics and stroke order.

Benefits of technology

It improves the accuracy and efficiency of error correction, reduces the occurrence of missing characters, and avoids the time consumption of multiple encoder encodings.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115641591B_ABST
    Figure CN115641591B_ABST
Patent Text Reader

Abstract

The application provides an OCR text correction method and device. A correct probability of a Chinese character at each position in to-be-corrected text is obtained. A character shape structure word embedding vector of the Chinese character at each position in the to-be-corrected text is obtained. An input word embedding vector of the Chinese character at each position is calculated according to the word embedding vector corresponding to the Chinese character at each position in the to-be-corrected text, the correct probability and the character shape structure word embedding vector, and an input word embedding vector set is formed. The input word embedding vector set is input into a second encoder to form a coded input word embedding multi-dimensional vector. The coded input word embedding multi-dimensional vector is input into a correction layer to obtain corrected text. The correction layer is provided with a correction neural network formed by training of a Chinese corpus. The OCR text correction method and device provided by the application no longer selects a candidate word from an existing confusion set for correction, reduces the occurrence of missing words, and improves the accuracy of correction.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of text correction technology, and in particular to an OCR text correction method and apparatus. Background Technology

[0002] OCR stands for Optical Character Recognition, which primarily utilizes image information for recognition and is widely used in medical settings. In real-world scenarios, poor image quality and image tilt can lead to OCR errors, significantly impacting the performance of downstream tasks. Therefore, text correction for OCR scenarios is crucial.

[0003] Currently, traditional text correction systems mainly consist of three modules: error detection module, candidate recall module, and error correction ranking module. These three modules are independent of each other.

[0004] (1) Error detection module: Identifies the location where the error occurs.

[0005] (2) Candidate Recall Module: For suspected erroneous words, candidate words are recalled based on the existing confusion set. The confusion set is usually constructed through offline candidate mining, using methods such as similar words and actual OCR recognition errors.

[0006] (3) Error correction and sorting module: Sort the error-corrected results according to the language model, etc., and select the optimal result.

[0007] However, the above methods rely on existing confusion sets for candidate word recall, which has a limited range of words and may result in missing candidate words, thus reducing accuracy. Summary of the Invention

[0008] In view of this, embodiments of this application provide an OCR text correction method and apparatus to improve the accuracy of text correction.

[0009] In a first aspect, embodiments of this application provide an OCR text correction method, the method comprising:

[0010] The text to be corrected is vectorized to obtain the word embedding vector of the Chinese character at each position in the text to be corrected. The vectorized text to be corrected is then input into the first encoder and the detection layer in sequence to obtain the correct probability of the Chinese character at each position in the text to be corrected.

[0011] Input the text to be corrected into a pre-trained glyph structure word embedding network model to obtain the glyph structure word embedding vector of Chinese characters at each position in the text to be corrected.

[0012] The input word embedding vector for each Chinese character at each position in the text to be corrected is calculated based on the word embedding vector, the correct probability, and the character structure word embedding vector. The input word embedding vectors of all Chinese characters at all positions in the text to be corrected are then arranged in positional order to form an input word embedding vector set.

[0013] The input word embedding vector set is input into the second encoder for encoding to form the encoded input word embedding multidimensional vector;

[0014] The encoded input words are embedded into a multi-dimensional vector and input into the error correction layer to obtain the corrected text. The error correction layer is equipped with an error correction neural network trained on Chinese corpus.

[0015] Optionally, the input word embedding vector for each Chinese character at each position in the text to be corrected is calculated based on the word embedding vector, the correctness probability, and the glyph structure word embedding vector. The specific calculation formula includes:

[0016] ,

[0017] in,

[0018] n is the position number of the Chinese character in the text to be corrected, and n is less than or equal to the total number of Chinese characters in the text to be corrected.

[0019] Em (n) The input word embedding vector is the Chinese character at the nth position in the text to be corrected.

[0020] Es (n) Let n be the word embedding vector of the Chinese character at the nth position in the text to be corrected;

[0021] Ew (n) The word embedding vector of the glyph structure of the Chinese character at the nth position in the text to be corrected;

[0022] Pn represents the probability that the Chinese character at the nth position in the text to be corrected is correct.

[0023] Optionally, the step of sequentially inputting the vectorized text to be corrected into the first encoder and the detection layer to obtain the correct probability of the Chinese character at each position in the text to be corrected includes,

[0024] The vectorized text to be corrected is input into the first encoder. The first encoder encodes the word embedding vector of each Chinese character in the text to be corrected by combining the word embedding vectors of the Chinese characters in the preceding and following positions, and outputs a multi-dimensional vector.

[0025] The multidimensional vector output by the first encoder is used as the input of the detection layer. The detection layer reduces the vector containing contextual semantics corresponding to the Chinese character at each position in the text to be corrected to a one-dimensional vector to form the correct probability of the Chinese character at that position.

[0026] Optionally, before inputting the text to be corrected into a pre-trained glyphic word embedding network model, the process further includes:

[0027] The specific method for training the glyph structure word embedding network model is as follows:

[0028] Define numerical codes for each stroke and structural feature in Chinese characters.

[0029] Extracting Chinese characters from a Chinese character dataset;

[0030] Obtain the structural features corresponding to each Chinese character and the structural feature number corresponding to the structural features;

[0031] Obtain the structural order of each Chinese character's structural features, extract the strokes of each structure according to the structural order, and form corresponding stroke numbers according to the stroke order of the Chinese character.

[0032] The structural feature number and stroke number of each Chinese character are combined to form the numerical code of the Chinese character. The numerical code of each Chinese character is then vectorized by word embedding to obtain the word embedding vector of the character's shape structure.

[0033] Multiple Chinese characters and their corresponding word embedding vectors are input into a deep learning network for training to obtain a word embedding network model.

[0034] Optionally, an error-correcting neural network can be trained using Chinese corpus, including:

[0035] Obtain Chinese corpus, which includes encoded input word embeddings of multiple Chinese words and sentences in a multi-dimensional vector format.

[0036] The Chinese corpus is input into the initialized neural network for training. The correct probability of training correct Chinese characters is 1, and the correct probability of training incorrect Chinese characters is 0, thus obtaining an error correction neural network. After the error correction neural network is trained, the vector values ​​of Chinese characters in the full vocabulary are obtained.

[0037] Optionally, the encoded input words are embedded into a multi-dimensional vector input error correction layer to obtain the corrected text, including:

[0038] The encoded input word is embedded into a multi-dimensional vector and input to the error correction layer. The error correction neural network corrects the error vectors corresponding to Chinese characters in the text to be corrected whose correct probability is less than a preset value and obtains the prediction vector. The error correction neural network retains the correct vectors corresponding to Chinese characters in the text to be corrected whose correct probability is greater than or equal to the preset value and uses them as prediction vectors. The prediction vectors of Chinese characters at each position in the text to be corrected are arranged according to their positions to obtain the prediction vector set.

[0039] Based on the prediction vector set, determine the Chinese character corresponding to the prediction vector of the Chinese character at each position and output the corrected text.

[0040] Optionally, the vectorized text to be corrected is input into the first encoder, including:

[0041] The vectorized text to be corrected is trained and encoded using a self-attention mechanism set within the first encoder.

[0042] Optionally, the first encoder and the second encoder can be the same encoder.

[0043] Secondly, this application proposes an OCR text correction device, which includes: an error detection module, an input word embedding vector acquisition module, a second encoder, and an error correction module.

[0044] The error detection module is used to vectorize the text to be corrected to obtain the word embedding vector of the Chinese character at each position in the text to be corrected, and then input the vectorized text to be corrected into the first encoder and the detection layer in sequence to obtain the correct probability of the Chinese character at each position in the text to be corrected.

[0045] The input word embedding vector acquisition module is used to input the text to be corrected into a pre-trained glyph structure word embedding network model, obtain the glyph structure word embedding vector of each Chinese character in the text to be corrected, and calculate the input word embedding vector of each Chinese character in the text based on the word embedding vector, correct probability and glyph structure word embedding vector of each Chinese character in the text to be corrected.

[0046] The second encoder uses the input word embedding vectors of all Chinese characters in the text to be corrected to form an input word embedding vector set in positional order, and inputs the input word embedding vector set into the second encoder to form the encoded input word embedding multidimensional vector;

[0047] The error correction module is used to embed the encoded input word into a multi-dimensional vector input to the error correction layer to obtain the corrected text. The error correction layer is equipped with an error correction neural network trained on Chinese corpus.

[0048] Optionally, the error detection module includes: an embedding layer, a first encoder, and a detection layer.

[0049] The embedding layer is used to vectorize the text to be corrected to obtain the word embedding vector of the Chinese character at each position in the text to be corrected.

[0050] The first encoder is used to encode the word embedding vector of the Chinese character at each position in the text to be corrected by combining the word embedding vectors of the Chinese characters at the preceding and following positions, so that the Chinese character vector at each position in the text to be corrected output by the first encoder is a dynamic vector containing contextual semantics.

[0051] The detection layer is used to reduce the dynamic vector containing contextual semantics corresponding to the Chinese character at each position in the text to be corrected to a one-dimensional vector to form the correct probability of the Chinese character at that position.

[0052] Optionally, the device further includes: a network model training module.

[0053] The network model training module includes a definition submodule, an numbering submodule, a vectorization submodule, and a training submodule.

[0054] The definition submodule is used to define the numerical code for each stroke and structural feature in Chinese characters.

[0055] The numbering submodule is used to extract Chinese characters from the Chinese character dataset, obtain the structural features corresponding to each Chinese character and the structural feature number corresponding to the structural features, obtain the structural order of each Chinese character's structural features, extract the strokes of each structure in sequence according to the structural order, form the corresponding stroke number according to the stroke order of the Chinese character, and combine the structural feature number and the stroke number of each Chinese character to form the numerical number of the Chinese character.

[0056] The vectorization submodule is used to vectorize the numerical code of each Chinese character to obtain the character's glyph structure vector;

[0057] The training submodule is used to input the glyph structure vectors of multiple Chinese characters into a deep learning network for training to obtain a glyph structure word embedding network model.

[0058] This application provides an OCR text correction method and apparatus. It calculates the input word embedding vector for each Chinese character position based on word embedding vectors, correctness probabilities, and character structure word embedding vectors. The input word embedding vector set is then input to a second encoder to form an encoded multi-dimensional input word embedding vector. This encoded vector not only includes the contextual meaning of the Chinese characters at each position but also incorporates the stroke order of the characters' character structure. The encoded multi-dimensional input word embedding vector is then input to an error correction layer and processed by a trained error correction neural network to obtain the corrected text. This eliminates the need to select candidate words from an existing confusion set for error correction, reducing the occurrence of missing characters and improving the accuracy of error correction. Attached Figure Description

[0059] To more clearly illustrate the technical solutions in this embodiment or the prior art, the drawings used in the description of the embodiment or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0060] Figure 1A flowchart of an OCR text correction method provided in this application embodiment;

[0061] Figure 2 Flowchart of another OCR text correction method provided in the embodiments of this application;

[0062] Figure 3 A schematic diagram of an OCR text correction device provided in an embodiment of this application;

[0063] Figure 4 A schematic diagram of an error detection module provided in an embodiment of this application;

[0064] Figure 5 A schematic diagram of another OCR text correction device provided in the embodiments of this application;

[0065] Figure 6 A schematic diagram of the error correction module provided in an embodiment of this application. Detailed Implementation

[0066] Inventive concept

[0067] In traditional text correction systems, the candidate recall and correction ranking modules are limited to the existing confusion set, which may lead to omissions and inaccurate corrections. Furthermore, if too many candidate words are recalled, each candidate word must be replaced with another word in the text to calculate the language model probability. Specifically, a score is calculated for each candidate word's answer, and all new candidate sentences are ranked based on their scores, with the sentence with the highest score being selected as the corrected sentence. If there are N candidate answers, there are N corresponding new sentences, each requiring one encoder pass, totaling N encoder passes. This results in a long inference time, impacting the efficiency of the correction system.

[0068] For the reasons mentioned above, this application calculates the input word embedding vector for each Chinese character position based on the word embedding vector, the correctness probability, and the character structure word embedding vector. This input word embedding vector set is then input to a second encoder to form an encoded multi-dimensional input word embedding vector. This encoded vector not only includes the contextual meaning of the Chinese character at each position but also incorporates the stroke order of the character's structure. The encoded multi-dimensional input word embedding vector is then input to an error correction layer and processed by a trained error correction neural network to obtain the corrected text. During the training of the error correction neural network, vectorized Chinese words and phrases are used. The error correction neural network is trained using the stroke order of words and phrases. It employs a full Chinese corpus for training. During error correction, the error correction layer selects words not limited to the existing confusion set, but considering both contextual semantics and stroke order to improve accuracy. Furthermore, compared to existing technologies where candidate words selected from the confusion set form new sentences and are encoded by an encoder, the number of candidate words determines the number of encoder operations, significantly increasing inference time. This application uses a pre-trained error correction neural network to form the full corpus for error correction, eliminating the need for re-encoding and improving efficiency.

[0069] Obviously, the described embodiments are only a part of the embodiments of this application, and not all of the embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0070] Figure 1 A flowchart of an OCR text correction method provided in this application embodiment is shown below. Figure 1 An OCR text correction method includes:

[0071] S101. Vectorize the text to be corrected to obtain the word embedding vector of the Chinese character at each position in the text to be corrected, and input the vectorized text to be corrected into the first encoder and the detection layer in sequence to obtain the correct probability of the Chinese character at each position in the text to be corrected.

[0072] The text to be corrected is input into an embedding layer that vectorizes the Chinese characters at each position to obtain word embedding vectors for each character. The vectorized text to be corrected is then input into a first encoder, which may include a self-attention mechanism to establish a connection between the word embedding vectors of each character and the word embedding vectors of the surrounding characters, resulting in a multi-dimensional vector. This multi-dimensional vector is then input into a detection layer, which may use a fully connected network to reduce the multi-dimensional vector to a one-dimensional vector. This one-dimensional vector represents the correct probability of each Chinese character at each position in the text to be corrected.

[0073] S102. Input the text to be corrected into the pre-trained character structure word embedding network model to obtain the character structure word embedding vector of each Chinese character in the text to be corrected.

[0074] The character-structure word embedding network is based on the character-structure Chinese character word embedding representation. It incorporates the stroke order features of Chinese characters for training to obtain better Chinese character word embedding representation.

[0075] S103. Calculate the input word embedding vector of each Chinese character at each position in the text to be corrected, based on the word embedding vector, correct probability, and character structure word embedding vector of each Chinese character at each position. Arrange the input word embedding vectors of all Chinese characters at all positions in the text to be corrected in positional order to form an input word embedding vector set. Input the input word embedding vector set into the second encoder for encoding to form the encoded input word embedding multidimensional vector.

[0076] The input word embedding vector combines the word embedding vector, correct probability, and glyph structure word embedding vector of each Chinese character in the text to be corrected. When it enters the encoder for encoding, it will carry both contextual semantics and glyph structure features, which also adds reference to glyph structure and stroke order for subsequent error correction, thus preparing for improving the error correction accuracy.

[0077] S104. Embed the encoded input word into a multi-dimensional vector input error correction layer to obtain the error-corrected text. The error correction layer is equipped with an error correction neural network trained on Chinese corpus.

[0078] By training the neural network with a large amount of Chinese corpus, the number of error-correcting words involved in the error correction neural network is expanded. Compared with the existing error correction methods that use confusion sets, this expands the range of correct Chinese characters that can be found. At the same time, it eliminates the need to reconstruct sentences from candidate words selected from the confusion set and encode them multiple times, thus improving error correction efficiency.

[0079] The input word embedding vector for each Chinese character position is calculated based on the word embedding vector, the correctness probability, and the character structure word embedding vector. This set of input word embedding vectors is then input into the second encoder to form the encoded multi-dimensional input word embedding vector. This encoded input word embedding vector not only includes the contextual meaning of the Chinese characters at each position but also incorporates the stroke order of the character structure. The encoded multi-dimensional input word embedding vector is then input into the error correction layer and processed by a trained error correction neural network to obtain the corrected text. This eliminates the need to select candidate words from an existing confusion set for error correction, reducing the occurrence of missing characters and improving the accuracy of error correction.

[0080] Figure 2 For a flowchart of another OCR text correction method provided in this application embodiment, please refer to... Figure 2 An OCR text correction method includes:

[0081] S201. Vectorize the text to be corrected to obtain the word embedding vector of the Chinese character at each position in the text to be corrected.

[0082] Text with corrections can be obtained by scanning documents, taking photos, or other methods.

[0083] The text to be corrected is converted into vectors through the embedding layer, which prepares the context for subsequent encoding by the first encoder.

[0084] S202. The vectorized text to be corrected is input into the first encoder. The first encoder encodes the word embedding vector of the Chinese character at each position in the text to be corrected by combining the word embedding vectors of the Chinese characters at the preceding and following positions, and outputs a multi-dimensional vector.

[0085] The self-attention mechanism set in the first encoder, the vectorized text to be corrected is input into the first encoder for encoding, so that there is a semantic relationship between the Chinese characters at each position and the Chinese characters in the context.

[0086] S203. The multidimensional vector output by the first encoder is used as the input of the detection layer. The detection layer reduces the vector containing contextual semantics corresponding to the Chinese character at each position in the text to be corrected to a one-dimensional vector to form the correct probability of the Chinese character at that position.

[0087] The detection layer can be a fully connected layer, which reduces the multidimensional vector obtained in step S202 to a one-dimensional vector, and the one-dimensional vector corresponding to the Chinese character at each position in the error-corrected text represents the correct probability of that Chinese character.

[0088] S204. Input the text to be corrected into the pre-trained character structure word embedding network model to obtain the character structure word embedding vector of each Chinese character in the text to be corrected.

[0089] The method for generating the word embedding network model based on the glyph structure is as follows:

[0090] Define the numerical code for each stroke and structural feature in Chinese characters.

[0091] Extract Chinese characters from a Chinese character dataset.

[0092] Obtain the structural features corresponding to each Chinese character and the structural feature number corresponding to the structural features.

[0093] Obtain the structural order of each Chinese character's structural features, extract the strokes of each structure according to the structural order, and form corresponding stroke numbers according to the stroke order of the Chinese character.

[0094] The structural feature number and stroke number of each Chinese character are combined to form the numerical code of the Chinese character. The numerical code of each Chinese character is then vectorized by word embedding to obtain the word embedding vector of the character's shape structure.

[0095] Multiple Chinese characters and their corresponding word embedding vectors are input into a deep learning network for training to obtain a word embedding network model.

[0096] When identifying erroneous Chinese characters in the text to be corrected, the judgment of character structure is introduced. Not only is the character itself used as a whole for word embedding, but word embedding is also established through character structure. The combination of the two improves the accuracy of error correction.

[0097] The character-structure word embedding network model is trained using a GRU network to obtain the character-structure word embedding vectors of Chinese characters.

[0098] S205. Calculate the input word embedding vector for each Chinese character at each position in the text to be corrected, based on the word embedding vector, correct probability, and character structure word embedding vector.

[0099] The specific formula for calculating the input word embedding vector is as follows:

[0100] ,

[0101] in,

[0102] n is the position number of the Chinese character in the text to be corrected, and n is less than or equal to the total number of Chinese characters in the text to be corrected.

[0103] Em (n) The input word embedding vector is the Chinese character at the nth position in the text to be corrected.

[0104] Es (n) Let n be the word embedding vector of the Chinese character at the nth position in the text to be corrected;

[0105] Ew (n) The word embedding vector of the glyph structure of the Chinese character at the nth position in the text to be corrected;

[0106] Pn represents the probability that the Chinese character at the nth position in the text to be corrected is correct.

[0107] The input word embedding vector formula is obtained by multiplying the word embedding vector by the correct probability and summing the word embedding vector of the character structure by the correct probability. In subsequent encoding and error correction, the relationship between the word embedding vector and the character structure word embedding vector is established. When the correct probability Pn is smaller, (1-Pn) is larger, and Em is more determined by the character structure of Chinese characters. This allows for the simultaneous consideration of word embedding and character structure word embedding of Chinese characters during subsequent training of the error correction layer. The correct vector is selected from the full vocabulary of the error correction layer training. This solves the problem that traditional error correction methods cannot correct text outside the confusion vocabulary. It also solves the problem that too many candidate words in the error correction module lead to increased model inference time.

[0108] S206. Arrange the input word embedding vectors of all Chinese characters in the text to be corrected in positional order to form an input word embedding vector set. Input the input word embedding vector set into the second encoder to encode and form the encoded input word embedding multidimensional vector.

[0109] The second encoder can be the same encoder as the first encoder, and both are equipped with a self-attention mechanism.

[0110] S207. Embed the encoded input word into a multi-dimensional vector input error correction layer to obtain the error-corrected text. The error correction layer is equipped with an error correction neural network trained on Chinese corpus.

[0111] The training method for the error correction neural network is as follows:

[0112] A Chinese corpus is obtained, which is an encoded input word embedding multi-dimensional vector. The Chinese corpus is input into an initialized neural network for training. The correct probability of training correct Chinese characters is one, and the correct probability of training incorrect Chinese characters is zero. An error correction neural network is obtained. After the error correction neural network is trained, the vector values ​​of Chinese characters in the full vocabulary are obtained.

[0113] The Chinese corpus consists of encoded input word embeddings of multi-dimensional vectors, which involves processing multiple Chinese words and phrases within the corpus as follows:

[0114] Each Chinese character in the Chinese phrase is embedded through an embedding layer, and the output of the embedding layer is sequentially passed through the first encoder and the detection layer to obtain the correct probability of each Chinese character in the Chinese phrase.

[0115] The Chinese words and phrases are input into the glyph structure word embedding network model to obtain the word embeddings of the corresponding Chinese words and phrases. The input word embeddings of the Chinese words and phrases are calculated and input into the second encoder to obtain the encoded input word embedding multidimensional vector of the Chinese words and phrases.

[0116] The encoded input words are embedded into a multi-dimensional vector and input into the error correction layer to obtain the corrected text. The specific method is as follows:

[0117] The encoded input word is embedded into a multi-dimensional vector and input to the error correction layer. The error correction neural network corrects the error vectors corresponding to Chinese characters in the text to be corrected whose correct probability is less than a preset value and obtains the prediction vector. The error correction neural network retains the correct vectors corresponding to Chinese characters in the text to be corrected whose correct probability is greater than or equal to the preset value and uses them as prediction vectors. The prediction vectors of Chinese characters at each position in the text to be corrected are arranged according to their positions to obtain the prediction vector set.

[0118] Based on the prediction vector set, determine the Chinese character corresponding to the prediction vector of the Chinese character at each position and output the corrected text.

[0119] The encoded input word embedding multidimensional vector is corrected by an error correction neural network in the error correction layer to obtain a prediction vector set. The error correction neural network is trained on a large amount of Chinese corpus to obtain a full vocabulary. The error correction neural network corrects the encoded input word embedding vector to obtain prediction vectors. Correct vectors are retained, and incorrect vectors are replaced with correct vectors obtained from the error correction neural network. Finally, the prediction vector set of the text to be corrected is obtained, and the correct Chinese character corresponding to the vector of each Chinese character is determined based on the prediction vector set. The corrected text is then output.

[0120] Set the formula for calculating the input word embedding vector. When the probability of correctness Pn is smaller, (1-Pn) is larger, and Em is more determined by the glyph structure of Chinese characters. This formula takes into account both the word embedding of Chinese characters and the word embedding of glyph structure. During the training of the error correction layer, when the accuracy of semantic judgment of Chinese characters is low, the error correction neural network is trained to make further judgments through glyph structure. Moreover, the error correction neural network is trained with a large amount of Chinese corpus to form a full vocabulary, which solves the problem that traditional error correction methods cannot correct text outside the confusion vocabulary. It also solves the problem that too many candidate words in the error correction module lead to an increase in model inference time, thereby improving the accuracy and efficiency of error correction.

[0121] The above describes some specific implementations of an OCR text correction method provided in this application. Based on this, this application also provides a corresponding apparatus. The apparatus provided in this application will be described below from the perspective of functional modularity.

[0122] See Figure 3 The diagram shows the structure of an OCR text correction device. The device 200 includes: an error detection module 210, an input word embedding vector acquisition module 220, a second encoder 230, and an error correction module 240.

[0123] The error detection module 210 is used to vectorize the text to be corrected to obtain the word embedding vector of the Chinese character at each position in the text to be corrected, and input the vectorized text to be corrected into the first encoder and the detection layer in sequence to obtain the correct probability of the Chinese character at each position in the text to be corrected.

[0124] The input word embedding vector acquisition module 220 is used to input the text to be corrected into a pre-trained glyph structure word embedding network model, obtain the glyph structure word embedding vector of each Chinese character in the text to be corrected, and calculate the input word embedding vector of each Chinese character in the text based on the word embedding vector, correct probability and glyph structure word embedding vector of each Chinese character in the text to be corrected.

[0125] The second encoder 230 uses the input word embedding vectors of all Chinese characters in the text to be corrected to form an input word embedding vector set by arranging them in positional order, and inputs the input word embedding vector set into the second encoder to encode and form the encoded input word embedding multidimensional vector;

[0126] The error correction module 240 is used to embed the encoded input word into a multi-dimensional vector input to the error correction layer to obtain the corrected text. The error correction layer is equipped with an error correction neural network trained on Chinese corpus.

[0127] See Figure 4 The diagram shown illustrates an error detection module 210, which includes an embedding layer 211, a first encoder 212, and a detection layer 213.

[0128] The embedding layer 211 is used to vectorize the text to be corrected to obtain the word embedding vector of the Chinese character at each position in the text to be corrected.

[0129] The first encoder 212 is used to encode the word embedding vector of the Chinese character at each position in the text to be corrected by combining the word embedding vector of the Chinese character at the previous and next positions, so that the Chinese character vector at each position in the text to be corrected output by the first encoder is a dynamic vector containing contextual semantics.

[0130] The detection layer 213 is used to reduce the dynamic vector containing contextual semantics corresponding to the Chinese character at each position in the text to be corrected to a one-dimensional vector to form the correct probability of the Chinese character at that position.

[0131] See Figure 5 The diagram shows another OCR text correction device, which also includes a network model training module 250.

[0132] The network model training module includes a definition submodule 251, an numbering submodule 252, a vectorization submodule 253, and a training submodule 254.

[0133] The definition submodule 251 is used to define the numerical code for each stroke and structural feature in Chinese characters.

[0134] The numbering submodule 252 is used to extract Chinese characters from the Chinese character dataset, obtain the structural features corresponding to each Chinese character and the structural feature number corresponding to the structural features, obtain the structural order of each Chinese character's structural features, extract the strokes of each structure in sequence according to the structural order, form the corresponding stroke number according to the stroke order of the Chinese character, and combine the structural feature number and the stroke number of each Chinese character to form the numerical number of the Chinese character.

[0135] The vectorization submodule 253 is used to vectorize the numerical code of each Chinese character to obtain the character's glyph structure vector;

[0136] The training submodule 254 is used to input the glyph structure vectors of multiple Chinese characters into a deep learning network for training to obtain a glyph structure word embedding network model.

[0137] See Figure 6 The diagram shown illustrates the error correction module 240, which includes a prediction vector set acquisition module 241 and a corrected text acquisition module 242.

[0138] The prediction vector set acquisition module 241 is used to embed the encoded input word into the multi-dimensional vector input error correction layer. The error correction neural network corrects the error vectors corresponding to Chinese characters with a correct probability less than a preset value in the text to be corrected to obtain the prediction vector. The error correction neural network retains the correct vectors corresponding to Chinese characters with a correct probability greater than or equal to the preset value in the text to be corrected as the prediction vector. The prediction vectors of Chinese characters at each position in the text to be corrected are arranged according to their positions to obtain the prediction vector set.

[0139] The text acquisition module 242 after error correction is used to determine the Chinese character corresponding to the prediction vector of the Chinese character at each position based on the prediction vector set and output the text after error correction.

[0140] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on its differences from other embodiments. In particular, the apparatus embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.

[0141] The above description is merely an exemplary implementation of this application and is not intended to limit the scope of protection of this application.

Claims

1. An OCR text correction method, characterized by, The method comprises: vectorizing the text to be corrected to obtain word embedding vectors of each position of Chinese characters in the text to be corrected, and inputting the vectorized text to be corrected into a first encoder and a detection layer in sequence to obtain the correct probability of each position of Chinese characters in the text to be corrected; inputting the text to be corrected into a pre-trained word form structure word embedding network model to obtain word form structure word embedding vectors of each position of Chinese characters in the text to be corrected; calculating the input word embedding vectors of each position of Chinese characters according to the word embedding vectors, the correct probability and the word form structure word embedding vectors of each position of Chinese characters in the text to be corrected, and arranging the input word embedding vectors of all positions of Chinese characters in the text to be corrected in sequence to form an input word embedding vector set; inputting the input word embedding vector set into a second encoder to form an encoded input word embedding multi-dimensional vector; inputting the encoded input word embedding multi-dimensional vector into a correction layer to obtain a corrected text, wherein the correction layer is provided with a correction neural network formed by training a Chinese corpus; calculating the input word embedding vectors of each position of Chinese characters according to the word embedding vectors, the correct probability and the word form structure word embedding vectors of each position of Chinese characters in the text to be corrected, and the specific calculation formula comprises: , wherein, n is the position number of Chinese characters in the text to be corrected, and n is less than or equal to the total number of Chinese characters in the text to be corrected; Em (n) is the input word embedding vector of the Chinese character at the n-th position in the text to be corrected; Es (n) is the word embedding vector of the Chinese character at the n-th position in the text to be corrected; Ew (n) is the word embedding vector of the character in the n-th position of the text to be corrected; Pn is the correct probability of the Chinese character at the nth position in the text to be corrected.

2. The method of claim 1, wherein, The vectorized text to be corrected is inputted into a first encoder and a detection layer in sequence to obtain the correct probability of each position of Chinese characters in the text to be corrected, which comprises: inputting the vectorized text to be corrected into a first encoder, wherein the first encoder encodes the word embedding vectors of each position of Chinese characters in the text to be corrected in combination with the word embedding vectors of the Chinese characters before and after the position, and outputs a multi-dimensional vector; inputting the multi-dimensional vector outputted by the first encoder as the input of the detection layer, wherein the detection layer reduces the vector containing the context semantics corresponding to each position of Chinese characters in the text to be corrected to a one-dimensional vector to form the correct probability of the Chinese character at the position.

3. The method of claim 1, wherein, Before inputting the text to be corrected into the pre-trained word form structure word embedding network model, further comprising: training the word form structure word embedding network model, and the specific method is: defining the digital number of each stroke and each structure feature in Chinese characters, extracting Chinese characters from a Chinese character data set; obtaining the structure features corresponding to each Chinese character and the structure feature numbers corresponding to the structure features; obtaining the structure sequence of each Chinese character structure feature, extracting the strokes of each structure in sequence according to the structure sequence, and forming the corresponding stroke number according to the stroke sequence of the Chinese character; combining the structure feature number and the stroke number of each Chinese character to form the digital number of the Chinese character, and obtaining the word form structure word embedding vector of the Chinese character through word embedding vectorization; inputting a plurality of Chinese characters and the word form structure word embedding vectors corresponding to the Chinese characters into a deep learning network to obtain the word form structure word embedding network model.

4. The method of claim 1, wherein, forming a correction neural network by training a Chinese corpus, which comprises: obtaining a Chinese corpus, wherein the Chinese corpus comprises encoded input word embedding multi-dimensional vectors of a plurality of Chinese sentences, The neural network initialized by the Chinese corpus is trained, a correct Chinese character training correct probability is one, and an error Chinese character training correct probability is zero, to obtain an error correction neural network, and vector values of Chinese characters in a full vocabulary library are obtained after the error correction neural network is trained.

5. The method of claim 4, wherein, The encoded input word embedding multi-dimensional vector is input into the error correction layer to obtain the error-corrected text, which comprises: The encoded input word embedding multi-dimensional vector is input into the error correction layer, the error correction neural network corrects the error vector corresponding to the Chinese character with a correct probability less than a preset value in the text to be corrected to obtain a prediction vector, the error correction neural network retains the correct vector corresponding to the Chinese character with a correct probability greater than or equal to the preset value in the text to be corrected as the prediction vector, and the prediction vectors of the Chinese characters at each position in the text to be corrected are arranged according to the positions to obtain a prediction vector set; The prediction vector set is used to determine the prediction vector corresponding to the Chinese character at each position, and the error-corrected text is output.

6. The method of claim 1, wherein, The vectorized text to be corrected is input into the first encoder, which comprises: The vectorized text to be corrected is trained and encoded by the self-attention mechanism arranged in the first encoder.

7. The method of claim 6, wherein, The first encoder and the second encoder are the same encoder.

8. An OCR text correction apparatus characterized by comprising: The device comprises an error detection module, an input word embedding vector acquisition module, a second encoder, and an error correction module, The error detection module is used to vectorize the text to be corrected to obtain word embedding vectors of Chinese characters at each position in the text to be corrected, and the vectorized text to be corrected is input into the first encoder and the detection layer in sequence to obtain correct probabilities of Chinese characters at each position in the text to be corrected. The input word embedding vector acquisition module is used to input the text to be corrected into a pre-trained glyph structure word embedding network model to obtain glyph structure word embedding vectors of Chinese characters at each position in the text to be corrected, and to calculate input word embedding vectors of Chinese characters at each position according to the word embedding vectors, the correct probabilities, and the glyph structure word embedding vectors of Chinese characters at each position in the text to be corrected. The second encoder is used to arrange the input word embedding vectors of Chinese characters at all positions in the text to be corrected in sequence to form an input word embedding vector set, and to input the input word embedding vector set into the second encoder to form an encoded input word embedding multi-dimensional vector. The error correction module is used to input the encoded input word embedding multi-dimensional vector into the error correction layer to obtain the error-corrected text, and the error correction layer is provided with an error correction neural network formed by training a Chinese corpus. The input word embedding vectors of Chinese characters at each position are calculated according to the word embedding vectors, the correct probabilities, and the glyph structure word embedding vectors of Chinese characters at each position in the text to be corrected, and the specific calculation formula comprises: , wherein, n is the position number of the Chinese character in the text to be corrected, and n is less than or equal to the total number of Chinese characters in the text to be corrected; Em (n) is the input word embedding vector of the Chinese character at the n-th position in the text to be corrected; Es (n) is the word embedding vector of the Chinese character at the n-th position in the text to be corrected; Ew (n) is the word embedding vector of the character in the n-th position of the text to be corrected; Pn is the correct probability of the Chinese character at the nth position in the text to be corrected.

9. The apparatus of claim 8, wherein, The error detection module comprises an embedding layer, a first encoder, and a detection layer, The embedding layer is used to vectorize the text to be corrected to obtain word embedding vectors of Chinese characters at each position in the text to be corrected. The first encoder is configured to combine the word embedding vector of each Chinese character in the to-be-corrected text with the word embedding vectors of the Chinese characters in the front and rear positions to encode the Chinese character vector of each position in the to-be-corrected text, so that the Chinese character vector of each position in the to-be-corrected text output by the first encoder is a dynamic vector containing context semantics. The detection layer is configured to reduce the dynamic vector containing context semantics corresponding to each Chinese character in the to-be-corrected text to a one-dimensional vector to form the correct probability of the Chinese character in the position.

10. The apparatus of claim 8, wherein, The device further comprises a network model training module, The network model training module comprises a definition submodule, a numbering submodule, a vectorization submodule and a training submodule, The definition submodule is configured to define the numerical number of each stroke and each structural feature in a Chinese character, The numbering submodule is configured to extract Chinese characters from a Chinese character data set, obtain the structural features corresponding to each Chinese character and the structural feature numbers corresponding to the structural features, obtain the structural order of each structural feature of the Chinese character, sequentially extract the strokes of each structure according to the structural order, form the stroke numbers according to the stroke order of the Chinese character, and combine the structural feature numbers and the stroke numbers of each Chinese character to form the numerical number of the Chinese character; The vectorization submodule is configured to vectorize the numerical number of each Chinese character to obtain the glyph structure vector of the Chinese character; The training submodule is configured to input the glyph structure vectors of a plurality of Chinese characters into a deep learning network to obtain a glyph structure word embedding network model.

Citation Information

Patent Citations

  • Error correction method and device for Chinese text, and computer equipment

    CN112395861A

  • Chinese character-level feature and language model-based Chinese OCR error correction method

    CN113408535A