Text error correction method and device
By aligning the OCR text and the corrected text, the problem of inconsistent word count in the OCR text correction method is solved, the correction accuracy is improved, and the number of words in the corrected text is ensured to be consistent with that in the OCR recognized text.
Patent Information
- Application Number
- CN202011363197.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-28
- Publication Date
- 2025-09-12
- Estimated Expiration
- 2040-11-28
AI Technical Summary
In existing OCR text correction methods, the number of words in the text after OCR recognition is inconsistent with the number of words in the text after correction, resulting in an inability to determine whether the corrected text is correct. Correct text may be corrected, resulting in low accuracy.
By aligning the OCR text and the correction text to make the number of words or characters the same, and selecting the optimal correction word in the vocabulary, the optimal correction word at the correction position is determined.
Improves the accuracy of text correction, avoids correct words from being corrected, and ensures that the number of words in the text after correction is consistent with the text after OCR recognition.
Smart Images

Figure CN114581921B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of natural language processing technology, and in particular to a text error correction method and device. Background Art
[0002] Optical character recognition (OCR) is the process of using an electronic device (such as a scanner or digital camera) to examine characters printed on paper, determine their shape by detecting patterns of light and dark, and then translate these shapes into computer text using character recognition methods. However, due to issues such as image quality and page complexity, errors may occur in the text after OCR recognition. Consequently, OCR text error correction technology has gradually emerged.
[0003] Currently, when correcting OCR text, the text recognized by OCR technology is typically used as the input text for the correction model. The correction model then corrects the OCR input text to obtain the corrected text, and finally outputs the corrected text. This method may result in the number of words in the OCR recognized text and the corrected text being different. In this case, it is impossible to determine whether the corrected text is correct or the OCR recognized text is correct. It is also possible that the correct text recognized by OCR will be corrected. Therefore, this method has low accuracy. Summary of the Invention
[0004] The present application provides a text error correction method and device to improve the accuracy of text error correction.
[0005] In a first aspect, the present application provides a text correction method, which includes: obtaining a first optical character recognition (OCR) text and a first correction text, wherein the first correction text is obtained by correcting the first OCR text using a correction model; aligning the first OCR text and the first correction text to obtain a second OCR text and a second correction text, wherein the second OCR text and the second correction text have the same number of words; determining a text correction position for the second OCR text and the second correction text; and determining the optimal correction word at the correction position among the second OCR text, the second correction text, and candidate words.
[0006] Through the above technical solution, the server can align the OCR text and the correction text output by the model, and then determine the correction text corresponding to the final OCR text based on the aligned text and candidate words. Compared with the existing technology of directly using the correction text output by the model as the final correction text, it can improve the correction ability and the accuracy of text correction.
[0007] In a possible implementation, the first OCR text and the first error-correcting text are aligned to obtain a second OCR text and a second error-correcting text, including: determining that the first OCR text and the first error-correcting text have the same number of characters; segmenting the first OCR text and the first error-correcting text according to spaces, and comparing the length of words at each position of the first OCR text and the first error-correcting text in turn; the words are words obtained after word segmentation; merging the texts with more words in the first OCR text and the first error-correcting text according to the length of the words to obtain the second OCR text and the second error-correcting text; or supplementing the texts with fewer words in the first OCR text and the first error-correcting text with symbols according to the length of the words to obtain the second OCR text and the second error-correcting text.
[0008] Through the above technical solution, the server can align the OCR text and the correction text output by the model at the word level, so that the number of words in the two texts is the same. In this way, the word positions of the two texts can correspond one-to-one, which can facilitate the determination of the correction position and then correct the words at the correction position.
[0009] In a possible implementation, if it is determined that the first OCR text and the first error-correction text have different numbers of characters, the first OCR text and the first error-correction text are pre-aligned to obtain a third OCR text and a third error-correction text.
[0010] As a possible implementation method, the first OCR text and the first error-correction text are pre-aligned to obtain a third OCR text and a third error-correction text, including: calculating the edit distance between each character in the first OCR text and each character in the first error-correction text in sequence; supplementing characters of the first OCR text and the first error-correction text with fewer characters according to the size of the edit distance to obtain a third OCR text and a third error-correction text, wherein the third OCR text has the same number of characters as the third error-correction text, and the edit distance between the third OCR text and each character in the third error-correction text is the smallest.
[0011] Through the above technical solution, when the number of characters in the OCR text and the correction text is different, the server can first align the two texts at the character level so that the number of characters in the two texts is the same, and minimize the editing distance of the two texts through character alignment.
[0012] In a possible implementation, for the second OCR text and the second error-corrected text, determining the text error-correction position includes: aligning the second OCR text and the second error-corrected text according to spaces, and determining the positions where the number of characters in the second OCR text and the second error-corrected text is the same but the characters are different as the text error-correction positions.
[0013] In a possible implementation, the candidate words are determined as follows: comparing the word at the text error-correction position in the second OCR text with N words in a pre-stored lexicon in sequence to obtain N edit distances between the word at the text error-correction position in the second OCR text and the N words, where N is a positive integer; selecting M edit distances from the N edit distances, and using the M words corresponding to the M edit distances as candidate words, where M < N and M is a positive integer.
[0014] Through the above technical solution, the server can select some words with smaller edit distances from the lexicon compared to the words in the second OCR text, which facilitates the subsequent selection of the optimal error-corrected word.
[0015] In a possible implementation, in the second OCR text, the second error-corrected text, and the candidate words, determining the optimal error-corrected word at the error-correction position includes: if it is determined that the word at the error-correction position in the second error-corrected text is in the lexicon, using the word at the error-correction position in the second error-corrected text as the optimal error-corrected word; if it is determined that the word at the error-correction position in the second error-corrected text is not in the lexicon, and it is determined that there is a candidate word in the candidate words that meets the preset condition, using the candidate word that meets the preset condition as the optimal error-corrected word; if it is determined that there is no candidate word in the candidate words that meets the preset condition, using the word at the error-correction position in the second OCR text as the optimal error-corrected word.
[0016] Wherein, the preset condition includes any one of the following conditions: the ratio of the edit distance between the candidate word and the word at the error-correction position in the second OCR text to the word length of the first set word is less than the set threshold, where the first set word is the word with the longest word length selected from the candidate word and the word at the error-correction position in the second OCR text; or the ratio of the edit distance between the candidate word and the word at the error-correction position in the second OCR text to the word at the error-correction position in the second OCR text is less than the set threshold; or the edit distance between the candidate word and the word at the error-correction position in the second OCR text is less than the set threshold.
[0017] Through the above technical solution, the server can determine the optimal correction word among the aligned OCR text, the aligned correction text and the candidate words after word-level alignment. Compared with the existing method of directly using the correction text output by the model as the final correction text, this method can improve the accuracy of text correction.
[0018] In the second aspect, the present application provides a text correction device, which can execute the corresponding functional modules in the above-mentioned first aspect or any possible implementation method of the first aspect, such as an acquisition module and a processing module. The functional modules can be implemented by hardware, or the corresponding software can be implemented by hardware.
[0019] In one possible design, the structure of the device may include an acquisition module and a processing module, which can perform the corresponding functions in the above-mentioned first aspect or each possible implementation of the first aspect. Please refer to the detailed description in the method example for details, which will not be repeated here.
[0020] In one possible design, the structure of the apparatus may include a transceiver and a processor, and optionally a memory. The transceiver is used to transmit and receive data and to communicate and interact with other devices in the communication system. The processor is configured to support the apparatus in performing the corresponding functions of the first aspect or each possible implementation of the first aspect. The memory is coupled to the processor and stores program instructions and data necessary for the apparatus.
[0021] In a third aspect, an embodiment of the present application further provides a computer storage medium having a computer program stored therein, wherein the computer program, when executed by a computer, causes the computer to perform the method provided in any of the above aspects. The computer-readable storage medium stores program instructions, and when the program instructions are run on a computer, causes the computer to perform the first aspect of the embodiment of the present application and any possible design thereof. Exemplarily, the computer-readable storage medium can be any available medium that a computer can access. Taking this as an example but not limited to: the computer-readable medium may include a non-transitory computer-readable medium, a random-access memory (RAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a CD-ROM or other optical disk storage, a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and can be accessed by a computer.
[0022] In a fourth aspect, an embodiment of the present application further provides a computer program, which, when executed on a computer, enables the computer to execute the method provided in any of the above aspects.
[0023] In a fifth aspect, an embodiment of the present application further provides a chip, which is used to read a computer program stored in a memory and to execute the method provided in any of the above aspects.
[0024] For each of the above-mentioned aspects from the second to the fifth aspects and the technical effects that may be achieved by each of the aspects, please refer to the above-mentioned description of the technical effects that can be achieved by various possible solutions in the first aspect, and no further details will be given here. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] Figure 1 A schematic diagram of an application scenario provided in an embodiment of the present application;
[0026] Figure 2A A schematic block diagram of a text error correction method provided in an embodiment of the present application;
[0027] Figure 2B A flowchart of a text error correction method provided in an embodiment of the present application;
[0028] Figure 3 A schematic diagram of the processing process of an error correction model provided in an embodiment of the present application;
[0029] Figure 4 A flow chart of a method for determining an optimal error correction word provided in an embodiment of the present application;
[0030] Figure 5 A flowchart of a text error correction method provided in an embodiment of the present application;
[0031] Figure 6 A schematic diagram of the structure of a text error correction device provided in an embodiment of the present application;
[0032] Figure 7 A schematic diagram of a text error correction device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0033] The implementation of this embodiment will be described in detail below with reference to the accompanying drawings.
[0034] It should be noted that this method can be applied to the fields of artificial intelligence (AI) and optical character recognition (OCR).
[0035] like Figure 1 The following is a schematic diagram of an application scenario provided by an embodiment of the present application. Figure 1As shown, this scenario includes: user 10, terminal device 11, and server 12. Various clients can be installed in terminal device 11. After a communication connection is established between the client of terminal device 11 and server 12 via a communication network, the client of terminal device 11 can send content to be identified and corrected to server 12. Server 12 then performs identification and correction, obtains a correction result, and then sends the correction result to the client of terminal device 11.
[0036] The terminal device 11 and the server 12 can be connected to each other via a communication network, which can be a local area network (LAN) or a wide area network (WAN) connected via a relay device. The terminal device 11 can be a mobile phone, tablet computer, laptop computer, personal computer, etc., and the server 12 can be any server device that can support the corresponding identification service and error correction service.
[0037] When the communication network for communication connection between the terminal device 11 and the server 12 is a local area network, illustratively, the communication network can be a short-range communication network such as a wireless fidelity (WiFi) hotspot network, a Bluetooth (BT) network, or a near field communication (NFC) network.
[0038] When the communication network for communication connection between the terminal device 11 and the server 12 is a wide area network, illustratively, the communication network can be a third-generation mobile communication technology (3G) network, a fourth-generation mobile communication technology (4G) network, a fifth-generation mobile communication technology (5G) network, a future evolved public land mobile network (PLMN) or the Internet, etc.
[0039] Currently, the process of correcting text is as follows: an image to be recognized is input, and then the image is recognized using OCR technology to obtain a recognition result. The text in the recognition result is then used as the text to be corrected, and the text recognized by the OCR technology is corrected using an error correction model to obtain corrected text, which is then used as the final text. After using this method for error correction, it is not certain whether the text recognized by the OCR technology is correct or whether the text after correction is correct. Furthermore, it is possible that correct text may be corrected. For example, a word in the text recognized by the OCR technology may be correct, but may become incorrect after correction by the error correction model. In other words, the text obtained by this current error correction method has low accuracy.
[0040] In view of this, an embodiment of the present application provides a text correction method. First, the text recognized by the OCR technology is aligned with the text corrected by the correction model, so that the number of words in the text recognized by the OCR technology is the same as the number of words in the text after correction. Then, for the words in the position that need to be corrected, the optimal word is selected from the aligned OCR text, the aligned correction text, and the candidate words as the final correction word. This can first ensure that the number of words in the text after OCR recognition is the same as the number of words in the text after correction. Therefore, when correcting text, it can avoid the situation where correct words in the OCR text are corrected, thereby improving the accuracy of text correction.
[0041] It should be noted that the "plurality" involved in the embodiments of the present application refers to greater than or equal to two. In addition, in the description of the embodiments of the present application, the words "first" and "second" are only used for the purpose of distinguishing the description and should not be understood as indicating or implying relative importance or order.
[0042] First, the processing process of the text error correction method of this application is briefly introduced. Figure 2A As shown, the server first obtains the OCR text, and then inputs the OCR text into the error correction model (for example, seq2seq language error correction model) to obtain the model output text. After obtaining the OCR text and the model output text corresponding to the OCR text, the text alignment scheme can be executed on the two texts (that is, the two texts are aligned) to obtain the aligned OCR text and the aligned model output text respectively. Then the decision scheme is executed, that is, which word should be the correct one at the position where error correction is required in the aligned OCR text and the aligned model output text. At this point, the edit distance between the words of the aligned OCR text and the words in the vocabulary can be calculated in this application, and then candidate words are selected in the vocabulary (for example, 8 candidate words are selected). Finally, a decision is made based on the selected candidate words, the aligned OCR text, and the aligned model output text to obtain the correct word at the error correction position, and then the final error correction text is obtained.
[0043] The following is a detailed introduction to the text error correction method provided in the embodiments of the present application.
[0044] like Figure 2B As shown, this is a flow chart of a text error correction method provided by an embodiment of the present application, see Figure 2B As shown, the method may include the following steps:
[0045] S201: The server obtains an image to be recognized.
[0046] The image to be identified here may be a page of a picture in a portable document format (PDF) file, or may be an advertisement leaflet, a poster, etc., which is not limited in this application.
[0047] S202: The server recognizes the image to be recognized using OCR technology to obtain OCR recognized text.
[0048] In the embodiment of the present application, OCR technology can be used to recognize the image to be recognized and convert the characters on the image into an encodable text format. Please refer to the specific implementation of the existing technology here and no further explanation will be given here.
[0049] S203: Input the OCR recognized text into the error correction model, perform error correction on the OCR text, and obtain an error-corrected text.
[0050] As a possible implementation, the OCR-recognized text can be input into an error correction model, such as a sequence-to-sequence (seq2seq) model, which can then be used to correct the OCR-recognized text and output the corrected text. It should be noted that the seq2seq model is a character-based neural translation model.
[0051] like Figure 3 As shown in FIG, a schematic diagram of error correction using a seq2seq model is provided in an embodiment of the present application. For example, assuming that the text after OCR recognition is 4 characters, namely "h", "c", "r", and "e", these 4 characters can first be input into a network, such as a long short-term memory network (LSTM), and the input characters are characterized and encoded at the encoding end, and then the extracted features are sent to the decoding end. The " <bos>" is the start flag, " <eos>" is the end flag. The decoder decodes the input features to obtain the corrected text. For example, four characters are corrected to "h", "e", "r", and "e". The detailed process of error correction in the seq2seq model can be found in the prior art and will not be elaborated here.
[0052] S204: Align the OCR text with the error correction text to obtain aligned OCR text and aligned error correction text.
[0053] It should be noted that there is no limit on the number of words in the text in the embodiments of the present application.
[0054] Since OCR text may contain misrecognized words compared to the original text, when the OCR text is fed into the seq2seq model, the incorrect words in the OCR text may be corrected, or the correct words in the OCR text may be corrected. Therefore, the number of words in the OCR text and the corrected text (i.e., the text output by the model) may not match. For example, if the OCR text contains one word, the seq2seq model may output three words.
[0055] In an embodiment of the present application, the OCR text and the correction text can be aligned so that the number of words in the OCR text and the correction text after alignment is the same. This can make the word positions of the two texts correspond one to one, which is conducive to determining the correction position, thereby correcting the words at the correction position and improving the accuracy of text correction.
[0056] Specifically, the server can determine whether the number of characters in the OCR text and the error correction text is the same. If they are the same, the OCR text and the error correction text are directly aligned at the word level. If they are different, the OCR text and the error correction text are first aligned at the character level so that the number of characters in the OCR text and the error correction text are the same. On this basis, the server can continue to compare the number of words in the OCR text and the error correction text. If the number of words in the OCR text is different from the number of words in the error correction text, the number of words in the OCR text and the error correction text can be aligned at the word level so that the number of words in the OCR text and the error correction text are the same.
[0057] It should be noted that word-level alignment can be understood as adding placeholders or merging words so that two texts with different numbers of words have the same number of words after alignment.
[0058] Based on this, this application may include the following situations:
[0059] Case 1: The length of the word in the OCR text is the same as the length of the word at the corresponding position in the correction text.
[0060] In this application, if the word lengths of the OCR text and the correction text at each position are the same, that is, the word positions in the OCR text and the correction text can correspond one to one, it can be understood that the number of words in the OCR text and the correction text is the same, and no processing is required.
[0061] In this case, the text after alignment is still the same as before alignment, that is, the OCR aligned text is the same as the OCR text, and the aligned error-corrected text is the same as the error-corrected text.
[0062] Case 2: The length of a word in the correction text is the same as the sum of the lengths of multiple words at the corresponding position in the OCR text.
[0063] For example, suppose the OCR text and the correction text are as follows:
[0064] OCR text: my pen is in m{bag.
[0065] Correction text: my pen is in my bag.
[0066] In the example above, the OCR text and the correction text have different character counts. Therefore, the OCR text and the correction text can first be aligned at the character level to ensure that the OCR text and the correction text have the same number of characters. Specifically, the server can compare each character in the OCR text with each character in the correction text, calculate the edit distance, and then supplement characters based on the edit distance to minimize the edit distance between the two texts.
[0067] In the above example, since the other characters of the OCR text and the error correction text are the same, it is sufficient to make the number of characters of "m", "{" plus the space between these two characters in the OCR text the same as the number of characters of the error correction text "my". The "m", "{" plus the space between these two characters in the OCR text is a total of 3 characters, while "my" in the error correction text is two characters, that is, there is a difference of one character between the OCR text and the error correction text. Therefore, it is necessary to add a character to the error correction text. For example, a placeholder can be added to make the number of characters of the two texts the same. In addition, when adding a placeholder, the position of the placeholder can be determined by the size of the calculated edit distance, that is, how to add the placeholder can minimize the edit distance between the two texts.
[0068] For example, after aligning the above text at the character level, the following text can be obtained:
[0069] Character alignment OCR text: my pen is in m{bag.
[0070] Character alignment correction text: my pen is in my△y bag.
[0071] Of course, it is understandable that the text after the above character alignment is only a schematic illustration. For example, other symbols may also be added, and this application does not make any specific limitations on this.
[0072] It should be noted that the edit distance can be understood as the number of conversion operations between characters or words in two texts. The conversion may include character deletion, character insertion, and character modification.
[0073] For example, assume that the word aligned with the OCR text at the error correction position is "apple", and the words in the vocabulary may include "app", "apples", "apply", etc. When "apple" is transformed into "app", two characters need to be deleted. Correspondingly, when "app" is transformed into "apple", two characters need to be added. Therefore, the edit distance between "apple" and "app" is 2.
[0074] Similarly, when "apple" is transformed into "apples", one character needs to be added, so the edit distance between "apple" and "apples" is 1; when "apple" is transformed into "apply", one character needs to be modified, so the edit distance between "apple" and "apply" is 1.
[0075] After character-level alignment, you can perform word-level alignment on the aligned text. That is, based on the aligned text, you can make the two texts have the same number of words. Specifically, you can segment the aligned text based on spaces, then compare the word lengths of the two texts one by one. You can adjust the word count of the texts by adding placeholders or merging words, ultimately making the two texts have the same number of words.
[0076] Continuing with the above example, in the example, from the 14th to the 16th character positions, the character alignment correction text "m△y" is a single word with a length of 3, while the character alignment OCR text includes two words, "m" and "{", and a space. That is, the sum of the lengths of the two words in the character alignment OCR text from the 14th to the 16th character positions is equal to the sum of the lengths of the single word in the character alignment correction text. It should be noted that the length of "m{" is the length of two characters, 2, plus the length of a space, 1, that is, 2+1=3.
[0077] To address this situation, in an embodiment of the present application, the character alignment correction text can be kept unchanged, and then multiple words in the aligned OCR text can be merged into one word. For example, the words "m" and "{n" in the character alignment OCR text can be merged into one word "m{", so that the number of words in the two texts is the same. In other words, the number of words in the two texts can be aligned by merging words.
[0078] For example, the OCR text and error-corrected text after word-level alignment are as follows:
[0079] Word-aligned OCR text: my pen is in m{bag.
[0080] Word alignment correction text: my pen is in my△y bag.
[0081] Furthermore, since "m△y" contains a placeholder, it will generate a large number of candidate words when determining the candidate words for the correction word. This may take a long time to select the correction word due to the large number of candidate words, and the selected correction word may not be optimal. Therefore, in the embodiment of the present application, after performing word-level alignment, the placeholder added during character-level alignment can be deleted. For example, in the above example, the text after final alignment is as follows:
[0082] Align OCR text: my pen is in m{bag.
[0083] Alignment correction text: my pen is in my bag.
[0084] It should be noted that the "aligned OCR text" involved in the embodiments of the present application is the OCR text after word-level alignment, also known as "word-aligned OCR text", and the "aligned error-corrected text" is the error-corrected text after word-level alignment, also known as "word-aligned error-corrected text". Sometimes they may be used interchangeably, but it should be understood that they have the same meaning.
[0085] Case 3: The length of a word in the OCR text is the same as the sum of the lengths of multiple words at the corresponding position in the correction text.
[0086] For example, suppose the OCR text and the correction text are as follows:
[0087] OCR text: my ballpen is in my bag.
[0088] Correction text: my ba pen is in my bag.
[0089] In this example, the number of characters in the OCR text and the error correction text differs by 1 character, and the OCR text has fewer characters than the error correction text. Therefore, a placeholder needs to be added to the OCR text to make the number of characters in the two texts the same.
[0090] For example, after level-level alignment, two text examples are as follows:
[0091] Character alignment OCR text: my ballpen is in my bag.
[0092] Character alignment correction text: my ba△pen is in my bag.
[0093] Since the OCR text and the correction text have different numbers of characters from the 4th to the 7th character positions, a placeholder can be added after "ba" to make the number of characters in the two texts the same and minimize the edit distance between the two texts.
[0094] On this basis, the text after the above character alignment is aligned at the word level. Specifically, in this example, at the 4th character position to the 10th character position, the word in the character alignment correction text is "ballpen", that is, one word, and the word length is 7, while the words at the corresponding positions in the character alignment OCR text are "ba△" and "pen", that is, two words, plus the space in the middle, the total word length is 7. In other words, the length of one word "ballpen" in the character alignment correction text is the same as the sum of the lengths of the two words ba△" and "pen" in the character alignment OCR text and the space in the middle. Therefore, when performing text alignment, the two words in the character alignment OCR text can be merged into one word so that the number of words in the two texts is consistent.
[0095] For example, the OCR text and error-corrected text after word-level alignment are as follows:
[0096] Word-aligned OCR text: my ballpen is in my bag.
[0097] Word alignment correction text: my ba△pen is in my bag.
[0098] Furthermore, when performing character-level alignment, a placeholder was added to the OCR text. Therefore, the added placeholder "△" can be deleted. For example, the resulting aligned OCR text and aligned error-corrected text are as follows:
[0099] Align OCR text: my ballpen is in my bag.
[0100] Alignment correction text: my bapen is in my bag.
[0101] Case 4: At a certain position, the sum of the lengths of multiple words in the OCR text is the same as the sum of the lengths of multiple words at the corresponding position in the correction text.
[0102] For example, suppose the OCR text and error correction text are as follows:
[0103] OCR text: I am going out with friends this weekend.
[0104] Correction text: I am going out with fn e os this weekend.
[0105] In the above example, the sum of the length of the sixth word "fri", the length of the seventh word "ods", and the length of the space between the two words in the OCR text is 7. The sum of the length of the sixth word "fn", the length of the seventh word "e", the length of the eighth word "os", and the length of the two spaces between these three words in the correction text is also 7. In other words, the length of the word "fri ods" in the OCR text is the same as the length of the word "fn e os" in the correction text.
[0106] In this case, the application can determine how to align based on the number of words in the OCR text and the error correction text at that position. Specifically, it can include the following two situations:
[0107] The first case: At this position, the number of words in the OCR text is greater than the number of words in the error correction text.
[0108] As a possible implementation method, at a certain position, when the number of words in the OCR text is greater than the number of words in the correction text, when aligning the OCR text with the correction text, the OCR text can be kept unchanged, and then a placeholder such as @ is added after the correction text to supplement the position of the correction text, so that the number of words in the aligned OCR text and the correction text is the same.
[0109] Assume that at the position where the words are inconsistent (for example, from the Nth position to the Mth position in the OCR text, where M>N and M and N are positive integers), the number of words in the OCR text is 3 and the number of words in the correction text is 2. The example is as follows:
[0110] OCR text: there is a cat.
[0111] Correction text: there isccc ee.
[0112] In this example, the OCR text and the error correction text have the same number of characters, so character-level alignment is not required. That is, the OCR text and the error correction text can be directly aligned at the word level.
[0113] From the above example, it can be seen that the number of words in the two texts from the 7th character position to the 14th character position is inconsistent. At this time, since the number of words in the correction text and the number of words in the OCR text at this position differ by one, a placeholder can be added after the correction text to supplement the missing word.
[0114] For example, the aligned OCR text and error-corrected text are as follows:
[0115] Word-aligned OCR text: there is a cat.
[0116] Word alignment correction text: there isccc ee@.
[0117] This alignment method can make the number of words in the two texts consistent, so that the words can correspond one to one, making it easier to determine the position of the word to be corrected.
[0118] It should be noted that in the embodiment of the present application, if the number of words in the OCR text is greater than the number of words in the error correction text, other symbols, such as " / ", "\", etc., can also be used to fill in the difference, and are not limited to the placeholders in the above examples.
[0119] The second case: at this position, the number of words in the OCR text is less than the number of words in the error correction text.
[0120] In one possible implementation, if at a certain position, the number of words in the OCR text is less than the number of words in the correction text, then when aligning the OCR text with the correction text, the OCR text can be kept unchanged, and then the words corresponding to the number of extra words in the correction text compared to the OCR text can be merged into one word.
[0121] Assume that at the position where the words are inconsistent, the number of words in the OCR text is 2, and the number of words in the error correction text is 3, such as the following example:
[0122] OCR text: there isccc ee.
[0123] Correction text: there is a cat.
[0124] In this example, the OCR text and the error correction text have the same number of characters, so the OCR text and the error correction text can be directly aligned at the word level.
[0125] For this example, the extra word in the correction text can be merged with the previous word so that the number of words in the OCR text is the same as the number of words in the correction text. In this example, at the position where the words are inconsistent, the number of words in the correction text is one more than the number of words in the OCR text. Therefore, the three words in the correction text can be merged into two words.
[0126] For example, the aligned OCR text and error-corrected text are as follows:
[0127] Word-aligned OCR text: there isccc ee.
[0128] Word alignment correction text: there is a cat.
[0129] It should be understood that the text after the above alignment is only an illustrative illustration and may also be in other forms. For example, the word alignment correction text may also be "there is_a cat.", etc. This application does not limit this.
[0130] Through this alignment method, the number of words in the OCR text and the correction text is the same, that is, each word in the OCR text can correspond to a word in the correction text.
[0131] In an embodiment of the present application, for situation 4, when the sum of the lengths of multiple words in the OCR text is the same as the sum of the lengths of multiple words in the model output text (i.e., the correction text), the number of words in the OCR text shall prevail to avoid correcting the originally correct words in the OCR text.
[0132] S205: Determine the error correction position for the aligned OCR text and the aligned error correction text.
[0133] In step S204, the server may align the OCR text with the error correction text to obtain an aligned OCR text and an aligned error correction text, and then compare the aligned OCR text with the aligned error correction text to determine the error correction position.
[0134] As a possible implementation, the server can sequentially compare words at the same location in the aligned OCR text and the aligned correction text. If the two words at the same location are inconsistent, the word at that location is determined to require correction, and that location can be considered the correction location. Alternatively, locations with the same number of characters but different characters in the aligned OCR text and the aligned correction text can be determined as text correction locations.
[0135] Of course, in the embodiments of the present application, the error correction positions may be at least one, and the present application does not limit this.
[0136] S206: For the error correction positions, determine the optimal error correction words at the error correction positions.
[0137] In a possible implementation, for the error correction positions, an optimal word can be selected from the words at the error correction positions corresponding to the aligned OCR text, the words at the error correction positions corresponding to the aligned error correction text, and the candidate words as the word at the error correction position.
[0138] It should be noted that in the embodiments of the present application, a word library can be pre-saved. The word library may include multiple different words, such as N words. The candidate words can be the words selected from the pre-saved N words.
[0139] Specifically, in the present application, the edit distance between the words in the aligned OCR text and the words in the word library can be calculated, and then M (where M is a positive integer greater than 1) words are selected as candidate words. Exemplarily, the words at the text error correction positions of the aligned OCR text are compared with the N words in the pre-saved word library in sequence to obtain N edit distances between the words at the text error correction positions of the aligned OCR text and the N words. N is a positive integer; then M edit distances are selected from the N edit distances, and the M words corresponding to the M edit distances are used as candidate words. M < N and M is a positive integer.
[0140] Next, how to determine the error correction words at the error correction positions will be specifically introduced.
[0141] As Figure 4 shown, it is a flowchart of a method for determining the optimal error correction words at the error correction positions provided by the embodiments of the present application. Refer to Figure 4 shown, this method may include the following steps:
[0142] S401: Determine that the words at the error correction positions of the aligned OCR text and the aligned error correction text are different.
[0143] In the embodiments of the present application, it can be determined whether the words at the corresponding positions of the aligned OCR text and the aligned error correction text are the same. If they are the same, it means that this position is not an error correction position, and the word at this position can be the word at this position in the aligned OCR text or the aligned error correction text. If they are different, step S402 is executed.
[0144] S402: Determine whether the word at the error correction position of the aligned error correction text is in the word library. If the word at the error correction position of the aligned error correction text is in the word library, the word at this error correction position in the aligned error correction text is used as the optimal error correction word. If the word at the error correction position of the aligned error correction text is not in the word library, continue to execute step S403.
[0145] S403: Determine whether the ratio of the edit distance to the word length in the candidate word is less than a set threshold. If so, the candidate word is used as the optimal correction word at the correction position; otherwise, the word in the aligned OCR text at the correction position is used as the optimal correction word.
[0146] As a possible implementation method, we can first determine the edit distance between the candidate word and the word in the aligned OCR text, then determine the longest word length between the word in the aligned OCR text and the candidate word, and finally select the final correction word based on the ratio of the edit distance to the longest word length, and select the candidate word that meets the conditions.
[0147] For example, assume that the alignment of OCR text and correction text is as follows:
[0148] Align OCR text: I have an apple.
[0149] Alignment correction text: I have an applo.
[0150] In this example, the correction position is the position of the fourth word in the text. In the aligned OCR text, the fourth word is "apple", and in the aligned correction text, the fourth word is "applo". Assuming that the candidate words include: apples, apply, app, apple, the ratio corresponding to the candidate word apples is: 1 / 6 = 0.1666, the ratio corresponding to the candidate word apply is: 1 / 5 = 0.2, the ratio corresponding to the candidate word app is: 2 / 5 = 0.4, and the ratio corresponding to apple is 0.
[0151] Assuming the threshold is set to 0.1, the ratio of the edit distance to the word length in the candidate words above is 0, which is the candidate word "apple". Therefore, the optimal correction word at the correction position is "apple". In other words, in this example, the word in the aligned OCR text is correct.
[0152] It is understood that the words whose edit distance to word length ratio is less than the set threshold may include one or more words. If there are multiple words, the word with the smallest ratio is selected. If there are multiple words with the smallest ratio, one of them is arbitrarily selected as the final error correction word.
[0153] As another possible implementation method, the edit distance between the candidate word and the word in the aligned OCR text can be determined first, and then the ratio of the edit distance to the word length in the aligned OCR text can be calculated, and the candidate word with a ratio less than a set threshold can be used as the optimal correction word.
[0154] Taking the above example again, the word in the aligned OCR text is "apple", and the candidate words include: apples, apply, app, apple. The ratio corresponding to the candidate word apples is: 1 / 5 = 0.2, the ratio corresponding to the candidate word apply is: 1 / 5 = 0.2, the ratio corresponding to the candidate word app is: 2 / 5 = 0.4, and the ratio corresponding to apple is 0.
[0155] Assuming the threshold is set to 0.1, the ratio of the edit distance to the word length in the candidate words above is 0, which is the candidate word "apple". Therefore, the optimal correction word at the correction position is "apple". In other words, in this example, the word in the aligned OCR text is correct.
[0156] As another possible implementation, the edit distance between the candidate word and the word in the aligned OCR text can be determined first, and then the candidate word with an edit distance less than a set threshold (or the candidate word with the smallest edit distance) can be selected as the optimal correction word. Continuing with the above example, the word in the aligned OCR text is "apple", and the candidate words include: apples, apply, app, apple. Among the candidate words, the smallest edit distance is 0, that is, the edit distance corresponding to the candidate word "apple". In this case, the candidate word with an edit distance of 0, that is, "apple", can be selected as the optimal correction word.
[0157] It should be noted that since the candidate words are obtained by calculating the edit distance between the aligned OCR text and the vocabulary, the word at the correction position in the aligned OCR text may appear in the candidate words. In other words, in this application, if the word at the correction position in the aligned OCR text is in the vocabulary, the corresponding edit distance is 0, and the final correction word is the word at the correction position in the aligned OCR text.
[0158] Through the above method, the optimal correction word for the correction position can be selected from the aligned correction text and candidate words, and then the final text after OCR text correction can be obtained, which can improve the accuracy of text correction.
[0159] In an embodiment of the present application, the above-mentioned text alignment scheme can be used to align the corresponding words of the OCR text and the model output text, making the two texts comparable, so that the optimal output can be selected, instead of using the model output text as the final error correction output as in the prior art. In comparison, the scheme of the present application can improve the accuracy of text error correction.
[0160] Based on the above embodiment, this application also provides a flow chart of a text error correction method, see Figure 5 As shown, the method may include the following steps:
[0161] S501: Acquire a first optical character recognition (OCR) text and a first error correction text.
[0162] S502: Determine whether the number of characters in the first OCR text and the first error correction text is the same. If they are the same, proceed to step S503; if they are different, proceed to step S504.
[0163] S503: Align the first OCR text and the first error-corrected text to obtain a second OCR text and a second error-corrected text.
[0164] As a possible implementation method, the first OCR text and the first error correction text can be segmented according to spaces, and the length of the words at each position of the first OCR text and the first error correction text can be compared in sequence; the words are the words obtained after the word segmentation process; then, based on the length of the words, the texts with more words in the first OCR text and the first error correction text are merged to obtain the second OCR text and the second error correction text; or, based on the length of the words, the texts with fewer words in the first OCR text and the first error correction text are supplemented with symbols to obtain the second OCR text and the second error correction text. For the specific implementation process, please refer to Figure 2B The detailed description of step S204 in the illustrated embodiment will not be repeated here.
[0165] S504: Pre-align the first OCR text and the first error-corrected text to obtain a third OCR text and a third error-corrected text.
[0166] If the number of characters in the first OCR text and the first error correction text is different, the first OCR text and the first error correction text are pre-aligned so that the number of characters in the first OCR text and the first error correction text is the same, and then step S503 is executed.
[0167] As a possible implementation method, the edit distance between each character in the first OCR text and each character in the first error correction text can be calculated in sequence, and then the characters of the first OCR text and the text with fewer characters in the first error correction text are supplemented according to the size of the edit distance to obtain a third OCR text and a third error correction text. Among them, the number of characters in the third OCR text and the third error correction text is the same, and the edit distance between each character in the third OCR text and the third error correction text is the smallest. For the specific implementation process, please refer to Figure 2B The detailed description of step S204 in the illustrated embodiment will not be repeated here.
[0168] S505: Determine a text error correction position for the second OCR text and the second error correction text.
[0169] S506: Determine the optimal error correction word at the error correction position among the second OCR text, the second error correction text, and the candidate words.
[0170] It should be noted that the specific implementation of step S505 and step S506 can be found in Figure 2B The detailed description of step S205 and step S206 in the illustrated embodiment will not be repeated here.
[0171] Based on the above embodiment, the present application also provides a text error correction device, the structure of which is as follows: Figure 6 As shown, the device 600 may include: an acquisition module 601 and a processing module 602.
[0172] The acquisition module 601 is configured to acquire a first optical character recognition (OCR) text and a first error-corrected text, where the first error-corrected text is obtained by correcting the first OCR text using an error-correction model. The processing module 602 is configured to align the first OCR text and the first error-corrected text acquired by the acquisition module 601 to obtain a second OCR text and a second error-corrected text, where the second OCR text and the second error-corrected text have the same number of words.
[0173] The processing module 602 is further configured to determine a text correction position for the second OCR text and the second correction text, and determine an optimal correction word at the correction position among the second OCR text, the second correction text, and candidate words.
[0174] In one possible implementation, the processing module 602 is specifically used to align the first OCR text and the first error-correcting text in the following manner to obtain a second OCR text and a second error-correcting text: determine that the number of characters in the first OCR text and the first error-correcting text is the same; segment the first OCR text and the first error-correcting text according to spaces, and compare the length of words at each position in the first OCR text and the first error-correcting text in turn; the words are words obtained after word segmentation; merge the texts with more words in the first OCR text and the first error-correcting text according to the length of the words to obtain a second OCR text and a second error-correcting text; or supplement the texts with fewer words in the first OCR text and the first error-correcting text with symbols according to the length of the words to obtain a second OCR text and a second error-correcting text.
[0175] In a possible implementation, the processing module 602 is further configured to: if it is determined that the first OCR text and the first error-correction text have different numbers of characters, pre-align the first OCR text and the first error-correction text to obtain a third OCR text and a third error-correction text.
[0176] The processing module 602 is specifically configured to pre-align the first OCR text and the first error-corrected text in the following manner to obtain a third OCR text and a third error-corrected text: successively calculate the edit distance between each character in the first OCR text and each character in the first error-corrected text; supplement characters to the text with fewer characters in the first OCR text and the first error-corrected text according to the magnitude of the edit distance to obtain a third OCR text and a third error-corrected text, where the number of characters in the third OCR text is the same as that in the third error-corrected text, and the edit distance between each character in the third OCR text and each character in the third error-corrected text is the smallest.
[0177] In a possible implementation manner, the processing module 602 is specifically configured to determine the text error-correction positions for the second OCR text and the second error-corrected text in the following manner: align the second OCR text and the second error-corrected text according to spaces, and determine the positions where the number of characters is the same but the characters are different in the second OCR text and the second error-corrected text as the text error-correction positions. [[ID=...]]
[0178] In a possible implementation manner, the candidate words are determined in the following way: compare the word at the text error-correction position in the second OCR text with N words in a pre-stored word library successively to obtain N edit distances between the word at the text error-correction position in the second OCR text and the N words, where N is a positive integer; select M edit distances from the N edit distances, and use the M words corresponding to the M edit distances as candidate words, where M < N and M is a positive integer.
[0179] In a possible implementation manner, the processing module 602 is specifically configured to determine the optimal error-corrected word at the error-correction position in the second OCR text, the second error-corrected text, and the candidate words in the following manner: if it is determined that the word at the error-correction position in the second error-corrected text is in the word library, use the word at the error-correction position in the second error-corrected text as the optimal error-corrected word; if it is determined that the word at the error-correction position in the second error-corrected text is not in the word library and it is determined that there are candidate words in the candidate words that meet the preset conditions, use the candidate words that meet the preset conditions as the optimal error-corrected words; if it is determined that there are no candidate words in the candidate words that meet the preset conditions, use the word at the error-correction position in the second OCR text as the optimal error-corrected word.
[0180] Among them, the preset conditions include any one of the following conditions: the ratio of the edit distance between the candidate word and the word of the second OCR text at the error correction position to the word length corresponding to the first set word is less than a set threshold, and the first set word is the word with the longest word length selected from the candidate word and the words of the second OCR text at the error correction position; or the ratio of the edit distance between the candidate word and the word of the second OCR text at the error correction position to the word of the second OCR text at the error correction position is less than a set threshold; or the edit distance between the candidate word and the word of the second OCR text at the error correction position is less than a set threshold.
[0181] It should be noted that the division of modules in the above embodiments of the present application is illustrative and is only a logical functional division. In actual implementation, there may be other division methods. In addition, the functional units in the various embodiments of the present application may be integrated into a processing unit, or may exist separately physically, or two or more units may be integrated into a single unit. The above-mentioned integrated units may be implemented in the form of hardware or in the form of software functional units.
[0182] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0183] Based on the above embodiments, the present application also provides a schematic diagram of a text error correction device, which is used to implement the text error correction method in the above embodiments. Figure 7 As shown, the apparatus 700 includes: a transceiver 701, one or more processors 702, and one or more memories 703. The transceiver 701, the processor 702, and the memory 703 are interconnected. In the embodiment of the present application, the transceiver 701 can be used to implement the above Figure 6 The method executed by the acquisition module 601 in the embodiment of the present invention, the processor 702 can be used to implement the above Figure 6 The method executed by the processing module 602 in .
[0184] Optionally, the transceiver 701, the processor 702, and the memory 703 are interconnected via a bus 704. The bus 704 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, and the like. For ease of representation, Figure 7 Only one thick line is used in the diagram, but this does not mean that there is only one bus or one type of bus.
[0185] In the embodiment of the present application, the processor 702 can be a general-purpose processor, a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component, and can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiment of the present application. The general-purpose processor can be a microprocessor or any conventional processor, etc. The steps of the method disclosed in the embodiment of the present application can be directly embodied as being executed by a hardware processor, or can be executed by a combination of hardware and software modules in the processor. The software module can be located in the memory 703, and the processor 702 reads the program instructions in the memory 703 and completes the steps of the above method in combination with its hardware.
[0186] In the embodiment of the present application, the memory 703 may be a non-volatile memory, such as a hard disk drive (HDD) or a solid-state drive (SSD), or a volatile memory (volatile memory), such as RAM. The memory may also be any other medium that can be used to carry or store desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory in the embodiment of the present application may also be a circuit or any other device that can implement a storage function, for storing instructions and / or data.
[0187] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and units can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0188] Based on the above embodiments, the present application further provides a computer storage medium, in which a computer program is stored. When the computer program is executed by a computer, the computer executes the text error correction method provided in the above embodiments.
[0189] Based on the above embodiments, an embodiment of the present application further provides a computer program, which, when executed on a computer, enables the computer to execute the text error correction method provided in the above embodiments.
[0190] Based on the above embodiments, an embodiment of the present application further provides a chip, which is used to read a computer program stored in a memory and to execute the text error correction method provided in the above embodiments.
[0191] An embodiment of the present application also provides a computer program product, including instructions, which, when executed on a computer, enables the computer to execute the text error correction method provided in the above embodiment.
[0192] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by instructions. These instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the steps in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0193] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0194] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.< / eos> < / bos>
Claims
1. A text error correction method, characterized in that: include: Obtaining a first optical character recognition (OCR) text and a first error-corrected text, where the first error-corrected text is obtained by correcting the first OCR text using an error-correction model; Aligning the first OCR text and the first error-corrected text to obtain a second OCR text and a second error-corrected text, wherein the second OCR text and the second error-corrected text have the same number of words; Determining a text error correction position for the second OCR text and the second error correction text; An optimal error correction word at the error correction position is determined among the second OCR text, the second error correction text, and candidate words.
2. The method according to claim 1, wherein Aligning the first OCR text and the first error-corrected text to obtain a second OCR text and a second error-corrected text includes: Determining that the first OCR text and the first error-corrected text have the same number of characters; Segmenting the first OCR text and the first error-corrected text according to spaces, and sequentially comparing the lengths of words at each position in the first OCR text and the first error-corrected text; the words are words obtained after the segmentation process; The first OCR text and the first error correction text with more words are merged according to the length of the words to obtain a second OCR text and a second error correction text; or the first OCR text and the first error correction text with fewer words are supplemented with symbols according to the length of the words to obtain a second OCR text and a second error correction text.
3. The method according to claim 2, wherein Before determining that the first OCR text and the first error-correcting text have the same number of characters, the method further includes: If it is determined that the first OCR text and the first error-correcting text have different numbers of characters, pre-aligning the first OCR text and the first error-correcting text to obtain a third OCR text and a third error-correcting text, wherein the third OCR text and the third error-correcting text have the same number of characters; The third OCR text is used as the first OCR text, and the third error-corrected text is used as the first error-corrected text.
4. The method according to claim 3, wherein Pre-aligning the first OCR text and the first error-corrected text to obtain a third OCR text and a third error-corrected text includes: sequentially calculating the edit distance between each character in the first OCR text and each character in the first error correction text; According to the size of the editing distance, characters of the text with fewer characters in the first OCR text and the first error correction text are supplemented to obtain a third OCR text and a third error correction text, and the editing distance between each character in the third OCR text and the third error correction text is the smallest.
5. The method according to claim 1, wherein Determining a text error correction position for the second OCR text and the second error-corrected text includes: The second OCR text and the second error correction text are aligned according to spaces, and positions where the second OCR text and the second error correction text have the same number of characters but different characters are determined as text error correction positions.
6. The method according to any one of claims 1 to 5, characterized in that The candidate words are determined in the following manner: Compare the word of the second OCR text at the text error correction position with N words in a pre - saved word library in sequence, and obtain N edit distances between the word of the second OCR text at the text error correction position and the N words, where N is a positive integer; Select M edit distances from the N edit distances, and use the M words corresponding to the M edit distances as candidate words, where M < N and M is a positive integer.
7. The method according to claim 6, wherein Determine the optimal error - corrected word at the error correction position among the second OCR text, the second error - corrected text, and the candidate words, including: If it is determined that the word of the second error - corrected text at the error correction position is in the word library, use the word of the second error - corrected text at the error correction position as the optimal error - corrected word; If it is determined that the word of the second error - corrected text at the error correction position is not in the word library, and it is determined that there are candidate words that meet the preset conditions among the candidate words, use the candidate words that meet the preset conditions as the optimal error - corrected word; If it is determined that there are no candidate words that meet the preset conditions among the candidate words, use the word of the second OCR text at the error correction position as the optimal error - corrected word; Among them, the preset conditions include any one of the following conditions: The ratio of the edit distance between the candidate word and the word of the second OCR text at the error correction position to the word length of the word corresponding to the first set word is less than the set threshold, where the first set word is the word with the longest word length selected from the candidate word and the word of the second OCR text at the error correction position; or The ratio of the edit distance between the candidate word and the word of the second OCR text at the error correction position to the word of the second OCR text at the error correction position is less than the set threshold; or The edit distance between the candidate word and the word of the second OCR text at the error correction position is less than the set threshold.
8. A text error correction device, characterized in that: It includes: An acquisition module, configured to acquire a first optical character recognition (OCR) text and a first error - corrected text, where the first error - corrected text is obtained by correcting the first OCR text using an error - correction model; A processing module, configured to align the first OCR text and the first error - corrected text acquired by the acquisition module to obtain a second OCR text and a second error - corrected text, where the number of words in the second OCR text and the second error - corrected text is the same; The processing module is further configured to, for the second OCR text and the second error - corrected text, determine the text error correction position, and determine the optimal error - corrected word at the error correction position among the second OCR text, the second error - corrected text, and the candidate words.
9. The device according to claim 8, wherein Specifically, the processing module aligns the first OCR text and the first error - corrected text in the following manner to obtain a second OCR text and a second error - corrected text: Determine that the number of characters in the first OCR text and the first error - corrected text is the same; Segment the first OCR text and the first corrected text by spaces, and sequentially compare the lengths of the words at each position in the first OCR text and the first corrected text; the word is the word obtained after the segmentation process. Merge the words of the text with more words in the first OCR text and the first corrected text according to the length of the word to obtain the second OCR text and the second corrected text; or supplement symbols to the text with fewer words in the first OCR text and the first corrected text according to the length of the word to obtain the second OCR text and the second corrected text.
10. The device according to claim 9, wherein The processing module is further configured to: If it is determined that the number of characters in the first OCR text and the first corrected text is different, perform pre-alignment on the first OCR text and the first corrected text to obtain the third OCR text and the third corrected text, and the number of characters in the third OCR text and the third corrected text is the same; Take the third OCR text as the first OCR text and the third corrected text as the first corrected text.
11. The device according to claim 10, wherein The processing module is specifically configured to pre-align the first OCR text and the first corrected text in the following manner to obtain the third OCR text and the third corrected text: Sequentially calculate the edit distance between each character in the first OCR text and each character in the first corrected text; Supplement characters to the text with fewer characters in the first OCR text and the first corrected text according to the magnitude of the edit distance to obtain the third OCR text and the third corrected text, and the edit distance between each character in the third OCR text and the third corrected text is the smallest.
12. The device according to claim 8, wherein The processing module is specifically configured to determine the text correction position for the second OCR text and the second corrected text in the following manner: Align the second OCR text and the second corrected text by spaces, and determine the positions where the characters are the same in number but different as the text correction positions.
13. The device according to any one of claims 8 to 12, characterized in that: The candidate word is determined by the following method: Sequentially compare the word at the text correction position in the second OCR text with N words in the pre-stored word library to obtain N edit distances between the word at the text correction position in the second OCR text and the N words, where N is a positive integer; Select M edit distances from the N edit distances, and use the M words corresponding to the M edit distances as candidate words, where M < N and M is a positive integer.
14. The device according to claim 13, wherein The processing module is specifically configured to determine the optimal correction word at the correction position in the second OCR text, the second corrected text, and the candidate words in the following manner: If it is determined that the word at the correction position in the second corrected text is in the word library, use the word at the correction position in the second corrected text as the optimal correction word; If it is determined that the word at the correction position in the second error correction text is not in the vocabulary, and it is determined that there is a candidate word that meets the preset conditions among the candidate words, then the candidate word that meets the preset conditions is used as the optimal error correction word; If it is determined that there is no candidate word that meets the preset condition among the candidate words, the word at the error correction position in the second OCR text is used as the optimal error correction word; The preset conditions include any one of the following conditions: a ratio of an edit distance between the candidate word and the word in the second OCR text at the error correction position to a word length corresponding to a first set word is less than a set threshold, and the first set word is the word with the longest word length selected from the candidate word and the word in the second OCR text at the error correction position; or The ratio of the edit distance between the candidate word and the word in the second OCR text at the error correction position to the word in the second OCR text at the error correction position is less than a set threshold; or An edit distance between the candidate word and a word in the second OCR text at the error correction position is less than a set threshold.
15. A computer storage medium, characterized in that The computer storage medium stores a computer program, and when the computer program is executed by a computer, the computer is enabled to execute the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Method and device for text error correction, server and storage medium
CN106598939A
Text error correction method and device
CN111079412A