Text error detection methods, apparatus, computer equipment and storage media

By acquiring the character position information of the image for layout restoration and text vectorization, and combining BERT and CRF models for text error detection, the problem of identifying and correcting similar-looking and similar-sounding characters in Chinese text is solved, thus improving the accuracy of text error detection.

CN112307749BActive Publication Date: 2025-10-31TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011181568.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-10-29
Publication Date
2025-10-31
Estimated Expiration
2040-10-29

AI Technical Summary

Technical Problem

There are a large number of errors in Chinese texts, such as characters with similar shapes and sounds. Existing technologies have difficulty effectively identifying and correcting these errors, especially in the process of automatic speech recognition and optical character recognition.

Method used

By acquiring the image to be recognized, identifying characters and determining their positions, restoring the layout, converting it into a text vector, and inputting it into a trained text error detection model for error detection, the text is then corrected using the BERT sequence labeling model and CRF technology.

Benefits of technology

It improves the accuracy of text error detection, effectively identifying and correcting errors in text, especially in complex layouts and diverse text scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112307749B_ABST
    Figure CN112307749B_ABST
Patent Text Reader

Abstract

A text error detection method, apparatus, computer device, and storage medium are disclosed. The method includes: acquiring an image to be recognized; recognizing characters from the image to be recognized, and determining the character position information of each character; restoring the layout of each character based on the character position information to obtain text to be detected; converting the text to be detected into a corresponding text vector; inputting the text vector into a text error detection model determined through training, and obtaining the text error detection result of the text to be detected output by the text error detection model. The above method, after recognizing characters in an image, restores the layout of the characters based on their positions to obtain the text to be detected, then vectorizes the text to be detected, and determines the text error detection result of the text to be detected based on the vectorization result and the text error detection model. The text to be detected obtained after layout restoration is more suitable for the application scenario, which helps to improve the accuracy of text error detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and particularly to a text error detection method, apparatus, computer device, and storage medium. Background Art

[0002] There are a large number of Chinese characters with similar shapes and similar pronunciations in Chinese text. For example, there are often a large number of errors of characters with similar pronunciations in the text obtained by pinyin input or ASR (Automatic Speech Recognition) speech transcription; while there are often a large number of errors of characters with similar shapes in the text obtained by handwriting / Wubi input or OCR recognition. For example, "activity recommendation" may be transcribed as "activity promotion", "one hundred contracts" may be recognized as "one hundred top contracts", etc. At the same time, similar entity words composed of different characters with similar shapes or similar pronunciations may each be a reasonable entity word when viewed alone, and it is only possible to determine whether it is correct in a specific context. Therefore, it is very necessary to detect errors in text. Summary of the Invention

[0003] Based on this, in view of the above technical problems, it is necessary to provide a text error detection method, apparatus, computer device, and storage medium.

[0004] A text error detection method, the method comprising:

[0005] Obtain a to-be-recognized picture;

[0006] Recognize characters from the to-be-recognized picture, and determine the character position information of each of the characters; <00…​​​​​​​​​​​​​​​​​​​​​

[0014] The vector conversion module is used to convert the text to be detected into a corresponding text vector.

[0015] The text error detection module is used to input the text vector into a text error detection model determined through training, and obtain the text error detection result of the text to be detected output by the text error detection model.

[0016] A computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program performing the following steps:

[0017] Obtain the image to be recognized;

[0018] Identify characters from the image to be identified, and determine the character position information of each character;

[0019] Based on the position information of each character, the layout of each character is restored to obtain the text to be detected;

[0020] Convert the text to be detected into a corresponding text vector;

[0021] The text vector is input into a text detection model that has been trained, and the text detection result of the text to be detected is obtained from the text detection model.

[0022] A computer-readable storage medium having a computer program stored thereon, the computer program performing the following steps when executed by a processor:

[0023] Obtain the image to be recognized;

[0024] Identify characters from the image to be identified, and determine the character position information of each character;

[0025] Based on the position information of each character, the layout of each character is restored to obtain the text to be detected;

[0026] Convert the text to be detected into a corresponding text vector;

[0027] The text vector is input into a text detection model that has been trained, and the text detection result of the text to be detected is obtained from the text detection model.

[0028] The aforementioned text error detection method, apparatus, computer equipment, and storage medium, after acquiring the image to be recognized, identify characters from it and determine the position of each character. Then, based on the character recognition results, they perform layout reconstruction to obtain the text to be detected. The text to be detected is then vectorized to obtain the corresponding text vector, which is input into a trained text error detection model to obtain the text error detection result output by the model. This method, after recognizing characters in the image, performs layout reconstruction based on the character positions to obtain the text to be detected, then vectorizes the text to be detected, and determines the text error detection result based on the vectorization result and the text error detection model. The text to be detected obtained after layout reconstruction is more suitable for the application scenario, which helps improve the accuracy of text error detection. Attached Figure Description

[0029] Figure 1 This is a diagram illustrating the application environment of a text error detection method in one embodiment.

[0030] Figure 2 This is a flowchart illustrating a text error detection method in one embodiment;

[0031] Figure 3 This is a flowchart illustrating the process of obtaining the text to be detected in one embodiment;

[0032] Figure 4 This is a schematic diagram of the sequence labels output by CRF to the text to be detected in a specific embodiment;

[0033] Figure 5 This describes the training process of a BERT sequence labeling model in one embodiment;

[0034] Figure 6 This is a schematic diagram of the BERT model in a specific embodiment;

[0035] Figure 7 This is a flowchart illustrating a text error detection method in another embodiment;

[0036] Figure 8 Here is a structural diagram of the BERT-CRF model in a specific embodiment;

[0037] Figure 9 This is a structural block diagram of a text error detection device in one embodiment;

[0038] Figure 10 This is a structural block diagram of a text error detection device in another embodiment;

[0039] Figure 11 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation

[0040] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0041] To ensure clarity and conciseness in the description of the following embodiments, a brief introduction to the related technologies is given first:

[0042] Artificial intelligence (AI) is the theory, methods, technology, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to achieve optimal results. In other words, AI is a comprehensive technology within computer science that attempts to understand the essence of intelligence and produce a new kind of intelligent machine that can react in a way similar to human intelligence. AI studies the design principles and implementation methods of various intelligent machines, enabling them to possess the functions of perception, reasoning, and decision-making.

[0043] Artificial intelligence (AI) is a comprehensive discipline encompassing a wide range of fields, including both hardware and software technologies. Fundamental AI technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interactive systems, and mechatronics. AI software technologies primarily include computer vision, speech processing, natural language processing, and machine learning / deep learning.

[0044] Machine Learning (ML) is a multidisciplinary field involving probability theory, statistics, approximation theory, convex analysis, and algorithm complexity theory. It specifically studies how computers can simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental way to endow computers with intelligence; its applications span all areas of artificial intelligence. Machine learning and deep learning typically include techniques such as artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and instructional learning.

[0045] Natural Language Processing (NLP) is an important field within computer science and artificial intelligence. It studies the theories and methods that enable effective communication between humans and computers using natural language.

[0046] ASR (Automatic Speech Recognition) is a technology that converts the lexical content of human speech into computer-readable input, such as keystrokes, binary codes, or character sequences.

[0047] Cloud computing is a computing model that distributes computing tasks across a large pool of computers, enabling various application systems to access computing power, storage space, and information services as needed. The network providing these resources is called the "cloud." From the user's perspective, resources in the "cloud" appear infinitely scalable, readily available, on-demand, and expandable, with payment based on usage.

[0048] As a provider of fundamental cloud computing capabilities, a cloud resource pool (referred to as a cloud platform, generally called an IaaS (Infrastructure as a Service) platform) is established. Various types of virtual resources are deployed in the resource pool for external customers to choose from. The cloud resource pool mainly includes: computing devices (virtualized machines containing operating systems), storage devices, and network devices.

[0049] Based on logical function, a PaaS (Platform as a Service) layer can be deployed on top of the IaaS (Infrastructure as a Service) layer, and a SaaS (Software as a Service) layer can be deployed on top of the PaaS layer. Alternatively, SaaS can be deployed directly on top of IaaS. PaaS is a platform for running software, such as databases and web containers. SaaS refers to various types of business software, such as web portals and bulk SMS senders. Generally speaking, SaaS and PaaS are upper layers compared to IaaS.

[0050] The text error detection method provided in this application can be applied to, for example... Figure 1 In the application environment shown, terminal 102 communicates with terminal 104 via a network. After acquiring the image to be recognized, terminal 104 identifies characters from it, determines the position of each character, and then restores the layout based on the character recognition results to obtain the text to be detected. The text to be detected is then vectorized to obtain the corresponding text vector, which is input into a trained text error detection model to obtain the text error detection result output by the model. In some embodiments, the text to be detected can be extracted from the image acquired by terminal 102. In other embodiments, the text to be detected can also be directly obtained from a database.

[0051] The terminals involved in the embodiments of this application may be smartphones, tablets, laptops, desktop computers, smart speakers, smartwatches, etc., but are not limited to these. The servers involved in the embodiments of this application may be independent physical servers, server clusters or distributed systems composed of multiple physical servers, or cloud servers that provide basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. The terminals and servers can be directly or indirectly connected through wired or wireless communication methods, which is not limited in this application.

[0052] In one embodiment, such as Figure 2 As shown, a text error detection method is provided, which is applied to... Figure 1 The following explanation uses the server as an example, including steps S210 to S240.

[0053] Step S210: Obtain the image to be recognized.

[0054] The image to be recognized refers to the image that requires character recognition.

[0055] Step S220: Identify characters from the image to be identified and determine the character position information of each character.

[0056] Character recognition from an image refers to identifying the text contained in the image and outputting the recognition result. Character recognition in an image can be achieved in any way; for example, OCR (Optical Character Recognition) is a commonly used method for converting images into characters. OCR refers to the process where electronic devices (such as scanners or digital cameras) examine characters printed on paper, determine their shape by detecting dark and light patterns, and then translate the shape into computer text using character recognition methods. In other words, for printed characters, optical methods are used to convert the text in a paper document into a black-and-white dot matrix image file, and recognition software converts the text in the image into text format for further editing by word processing software. In one embodiment, OCR technology is used to recognize characters from an image and determine the position information of each character. In another embodiment, image recognition technology can also be used to recognize and output each character and its position from an image.

[0057] Step S230: Restore the layout of each character based on its position information to obtain the text to be detected.

[0058] Page layout restoration actually refers to restoring the recognized characters according to their positions in the image to be recognized, thereby determining the relationship between the characters, and then combining the characters according to the relationship to obtain the result as the text to be detected.

[0059] In one embodiment, restoring the layout of each character based on its position information includes: combining the layout information of the image to be recognized to identify characters belonging to the same target as the same text to be detected. In one embodiment, the layout information includes table lines, separators, etc., in the image; taking table lines as an example, combining the table lines identified in the image to be recognized to group texts or characters belonging to the same table into the same text to be detected. In other embodiments, characters belonging to the same target can also be identified as the same text to be detected by combining layout information in other ways.

[0060] In one embodiment, such as Figure 3 As shown, the layout of each character is restored according to the position information of each character to obtain the text to be detected, including steps S231 and S232.

[0061] Step S231: Determine the positional relationship between any two characters based on their position information.

[0062] In one embodiment, the character position information includes the position coordinates of the vertices of each character detection box in a preset coordinate system; wherein, the preset coordinate system can be defined according to the actual situation, for example, the preset coordinate system can be defined with the origin at a fixed position (top left corner or bottom left corner, etc.) of the image to be recognized.

[0063] After determining the position of each character in the image to be recognized, the character positions are compared to determine the positional relationship between pairs of characters. The positional relationship between characters includes the distance between characters, whether characters are on the same line, whether characters are adjacent, etc. In a specific embodiment, the character border can be determined based on the character's position coordinates, and the positional relationship between pairs of characters, such as distance, adjacency, and alignment, can be determined based on the border's position. Alternatively, the character center coordinates can be determined based on the character's position coordinates, and then the positional relationship between pairs of characters, such as distance, adjacency, and alignment, can be determined based on the character center coordinates. Characters are considered adjacent if the distance between the character border and the character center is less than a certain threshold.

[0064] Step S232: Based on the positional relationship between pairs of characters, adjacent characters are combined sequentially to obtain the text to be detected.

[0065] In this embodiment, adjacent characters can be obtained by combining the positional relationships of the two pairs of characters determined in the previous step, and the adjacent characters are combined in turn to obtain the text to be detected.

[0066] In another embodiment, the layout of each character can be restored by combining the recognition results of the image to be recognized. For example, the recognition results such as lines in the recognition results can be combined to determine whether the characters belong to the same text, and the characters that belong to the same text can be combined in sequence to obtain the text to be detected.

[0067] In this embodiment, the positional relationship between characters is determined by combining the positional information of the characters, and then adjacent characters are combined in sequence to obtain the text to be detected. When detecting errors in the text, the accuracy of text error detection can be improved.

[0068] For example, in a specific embodiment, in a medical test report, due to layout issues, test results belonging to the same content may be split into different lines. If the characters are combined to obtain the text to be detected based on methods such as determining whether the characters are adjacent, it is very likely that the same test result will be identified as multiple texts to be detected, which is not conducive to text error detection. Therefore, in this embodiment, the layout of the characters is restored by combining the position of each character in the image to be identified, so as to obtain the text to be detected, and a sentence or a word can be regarded as the same text to be detected as much as possible.

[0069] In this embodiment, text recognition is performed on the image to be recognized, the text is extracted and used as the text to be detected, and then text error detection is performed on the text to be detected to determine whether there are any recognition errors in the text obtained from the image to be recognized. If a text error is detected, a prompt can be given, which can improve the recognition accuracy of the image recognition of the text to be recognized.

[0070] The text to be detected refers to the text that needs to be checked for errors. In this embodiment, the text to be detected is the text in the image obtained by performing text recognition on the image. In one embodiment, the characters in the text to be detected are Chinese characters.

[0071] Step S240: Convert the text to be detected into the corresponding text vector.

[0072] A text vector is a vector obtained by vectorizing text. In one embodiment, the text to be detected is converted into a corresponding text vector. This includes: vectorizing the text to be detected to obtain character vectors, fragment vectors, and position vectors. The character vectors of the text to be detected include the vectors corresponding to each character in the text; the fragment vectors refer to the segment vectors corresponding to each character in the text; and the position vectors identify the order of each character in the text, such as the position of the character. In a specific embodiment, the fragment vectors of the text to be detected are equivalent to the character vectors.

[0073] In one embodiment, text vectorization of the text to be detected can be achieved through an Embedding model; where Embedding is a way to convert discrete variables into continuous vector representations.

[0074] Step S250: Input the text vector into the text detection model determined by training, and obtain the text detection result of the text to be detected output by the text detection model.

[0075] Among them, the text error detection model is determined through pre-training and is used to detect errors in the input text to be detected.

[0076] In one embodiment, the text error detection model includes a BERT sequence labeling model. In this embodiment, inputting a text vector into the trained text error detection model and obtaining the text error detection result of the text to be detected output by the text error detection model includes: inputting a text vector into the trained BERT sequence labeling model and obtaining the sequence labeling result of the text to be detected output by the BERT sequence labeling model; and determining the text error detection result of the text to be detected based on the sequence labeling result.

[0077] Among them, BERT (Bidirectional Encoder Representations from Transformers) is a language model (a language model refers to an abstract mathematical model of language based on objective facts of language, and is a correspondence). The purpose of sequence labeling is to output another set of sequence labels corresponding to the input, based on a set of input sequences.

[0078] In this embodiment, the sequence labeling model is determined through pre-training and is used to label the input text vector and output the sequence labeling result corresponding to the text vector, that is, the sequence labeling result of the text to be detected.

[0079] In one embodiment, the sequence labeling of the text to be detected includes the labeling results of whether each character in the text is a correct character; in a specific embodiment, sequence labeling is implemented through a CRF (Conditional Random Field), which is a conditional probability distribution model of another set of output sequences given a set of input sequences. A CRF receives an input sequence such as X = (x1, x2, ..., x...). n ), and output the target sequence Y = (y1, y2, ..., y n In error detection tasks, the input sequence of a CRF is a string of text, and the output sequence is the corresponding sequence of labels indicating whether a point is an error. In other embodiments, sequence labeling can also be implemented in other ways.

[0080] After obtaining the sequence annotation result of the model output, according to the sequence annotation result, it can be determined whether there are incorrect characters in the text to be detected, that is, the text error detection result; it can be understood that if the annotation results of all characters in the sequence annotation result indicate that the characters are correct characters, then it is determined that the text error detection result of the text to be detected is that there are no incorrect characters; if there is an annotation result indicating that the character is an incorrect character in the sequence annotation result, then the text detection result of the text to be detected is that there are incorrect characters, and the position of the incorrect character in the text to be detected. For example, in a specific embodiment, the text to be detected is "one hundred contracts", and the corresponding sequence annotation result output is "OOEOO", where O is an identifier indicating that the character is correct, and E is an identifier indicating that the character is incorrect, as Figure 4 shown in a schematic diagram of the sequence tags output by CRF for the text to be detected in a specific embodiment; according to this sequence annotation result, the text error detection result of the text to be detected can be obtained as follows: the third character in the text to be detected is an incorrect character. In other embodiments, it is also possible to determine the text error detection result of the text to be detected according to the sequence annotation result by other means.

[0081] The above text error detection method, after obtaining the image to be recognized, recognizes the characters therein and determines the character positions of each character, and then restores the layout of the character recognition result according to the character positions to obtain the text to be detected; performs a vectorization operation on the text to be detected to obtain the corresponding text vector to be detected, and inputs the text vector into the trained text error detection model to obtain the text error detection result of the text to be detected. The above method, after character recognition of the image, restores the layout of the characters based on the positions of the characters to obtain the text to be detected, then vectorizes the text to be detected, and determines the text error detection result of the text to be detected based on the vectorization result and the text error detection model; the text to be detected obtained after layout restoration is more in line with the application scenario, which is beneficial to improving the accuracy of text error detection.

[0082] Furthermore, in one embodiment, as Figure 5 shown, the training process of the BERT sequence annotation model includes steps S510 to step S530.

[0083] Step S510, obtain the sample text and the corresponding sample sequence tags; wherein, the sample text contains statements with an error ratio lower than the preset ratio threshold.

[0084] In one embodiment, obtaining sample text and its corresponding sequence labels includes: collecting existing statements; calculating the error percentage for each existing statement; in a specific embodiment, calculating the error percentage includes calculating the ratio of the number of erroneous characters in each existing statement to the total number of characters in the corresponding statement; filtering out existing statements with an error percentage greater than a preset percentage threshold, and using the remaining existing statements as sample text; labeling the sample text with correct and incorrect characters; and merging the labels of each character in a sample text to obtain the sample sequence label corresponding to the sample text. The preset percentage threshold can be set according to actual conditions.

[0085] In one specific embodiment, the sample text and the corresponding sample sequence label are as follows:

[0086]

[0087] The sample sequence label has the same length as the sample text and consists of O and E. E (error) indicates that the character at the current position is an incorrect character, and O (other) indicates that the character at the current position is correct.

[0088] Step S520: Convert the sample text into the corresponding sample text vector.

[0089] The sample text is vectorized to obtain sample text vectors for each sample text. In one embodiment, the sample text vectors include character vectors, fragment vectors, and position vectors. Specifically, the character vectors of the sample text include the vectors corresponding to each character in the sample text; the fragment vectors refer to the fragment vectors corresponding to each character in the sample text; and the position vectors identify the order of each character in the sample text, such as the position of the character within the sample text. In a specific embodiment, the fragment vectors of the sample text are equivalent to the character vectors of the sample text.

[0090] Step S530: Train the pre-trained model based on the sample text vector and sample label sequence to obtain the sequence labeling model.

[0091] The pre-trained model can be trained using any feasible method based on sample text vectors and sample label sequences. The model obtained after training is denoted as the sequence labeling model in this embodiment.

[0092] The pre-trained model is the base model. Based on the pre-trained model, training is performed using sample text vectors and sample label sequences to obtain a model for sequence labeling of input text vectors, i.e., a sequence labeling model. In one embodiment, before training the pre-trained model based on sample text vectors and sample label sequences, the method further includes: obtaining a preset model; and replacing the softmax layer in the preset model with a CRF layer to obtain the pre-trained model.

[0093] In one specific embodiment, the sequence labeling model uses the BERT model. BERT is the encoder of a bidirectional Transformer. The main innovation of the model lies in the pre-training method, which uses Masked LM and Next Sentence Prediction to capture word-level and sentence-level representations respectively, and jointly adjusts the bidirectional Transformers in all layers to pre-train bidirectional deep representations (Embeddings).

[0094] like Figure 6 The diagram shows the structure of the BERT model in a specific embodiment, where E1 to En represent the input quantities and T1 to Tn represent the output results.

[0095] In one embodiment, such as Figure 7 As shown, after obtaining the text error detection result of the text to be detected output by the text error detection model, steps S710 to S730 are also included.

[0096] Step S710: If the text to be detected is determined to contain erroneous characters based on the text error detection results, obtain the candidate text of the correct statement corresponding to the text to be detected.

[0097] In the above embodiments, the text error detection results of the text to be detected will indicate whether there are erroneous characters in the text to be detected. In this embodiment, after determining that there are erroneous characters in the text to be detected, candidate statement texts that may be correct texts will be obtained through some methods and recorded as candidate correct statement texts.

[0098] In one embodiment, obtaining candidate texts of correct statements corresponding to the text to be detected can be achieved by combining a preset corpus with word frequency statistics. Matching is performed in the preset corpus; for example, matching erroneous characters with similar shapes or sounds can be performed to obtain candidate characters corresponding to the erroneous characters, thus obtaining candidate texts of correct statements. In another embodiment, an n-gram model (sometimes called an N-gram model) is used to obtain candidate texts of correct statements corresponding to the text to be detected. In yet another embodiment, candidate texts of correct statements corresponding to the text to be detected can be obtained through various methods. In other embodiments, candidate texts of correct statements corresponding to the text to be detected can also be obtained through other methods.

[0099] Step S720: Select the correct text of the text to be detected from the candidate text of the correct statement.

[0100] Since the candidate text for the correct statement includes multiple candidate texts, it is necessary to filter out the candidate text that is most likely to be the correct text. Therefore, in this embodiment, the correct text is obtained by filtering the candidate text for the correct statement.

[0101] In one embodiment, selecting the correct text from the candidate correct statements includes: calculating a score for each candidate correct statement and determining the candidate correct statement with the highest score as the correct text. In one embodiment, the score calculation for each candidate correct statement can be implemented using an n-gram model. In a specific embodiment, the text to be detected is input into a trained n-gram model to obtain the candidate correct statements and their corresponding scores. Here, n-gram is an algorithm based on a statistical language model. Its basic idea is to perform a sliding window operation of size N on the text content by bytes, forming a sequence of byte segments of length N.

[0102] Step S730: Replace the text to be detected with the correct text to obtain the corrected text.

[0103] After obtaining the correct text, the text to be detected is replaced with the correct text and output, which is the text after character correction, denoted as the corrected text in this embodiment.

[0104] In the above embodiments, after obtaining the text error detection result corresponding to the text to be detected, the text to be detected with errors is further corrected based on the text error detection result, and finally the corrected text can be obtained.

[0105] This application also provides an application scenario in which the above-described text error detection method is applied. Specifically, the text error detection method is applied in this scenario as follows: the text to be detected is text obtained from a ticket image through OCR recognition.

[0106] ① Obtain the text to be detected, and combine and restore the text sentences based on the information of the ticket page (the above image to be recognized) and the position information of each character in the text to be detected.

[0107] ② Use labeled error text and error point labeled sequence data to train the BERT-CRF model.

[0108] The training of the BERT-CRF model includes: collecting sentences with errors in the obtained text, removing samples where the errors and correct sentences differ too much, such as samples with an error rate greater than 50%; obtaining the sample label sequence corresponding to the sample text obtained by annotating the filtered error sentences; the sequence length is the same as the error sentence length and consists of O and E.

[0109] In one specific embodiment, the parameterization form corresponding to CRF is:

[0110]

[0111] Where Z(x) is the normalization factor:

[0112]

[0113] In linear-CRF, feature functions are divided into two categories. The first category is node feature functions defined on the Y node. These feature functions are only related to the current node and are denoted as: s l (y i (x,i),l=1,2,...L;

[0114] Where L is the total number of node feature functions defined at this node, and i is the position of the current node in the sequence.

[0115] The second type is local feature functions defined in the Y context. These feature functions are only related to the current node and the previous node, denoted as t. k (y i-1 ,y i (x,i),k = 1,2,...K;

[0116] Where K is the total number of local feature functions defined at this node, and i is the position of the current node in the sequence. Both node feature functions and local feature functions can only take values ​​of 0 or 1, that is, they either satisfy the feature condition or do not satisfy the feature condition. Furthermore, each feature function can be assigned a weight to express the degree of confidence in that feature function. Assume t... k The weighting coefficient is λ k s l The weighting coefficient is μ l Then the linear-CRF consists of all t k , λ k s l μ l A joint decision.

[0117] Building upon the BERT pre-trained model, the annotation model is fine-tuned by leveraging the correspondence between the original text and sequence labels. During annotation, the original softmax layer is replaced with a CRF layer to perform sequence labeling on the input text, outputting a label corresponding to each character in the text. For example... Figure 8 The diagram shown is a structural diagram of the BERT-CRF model in a specific embodiment.

[0118] ③ Input the text to be detected obtained from the page restoration into the error detection model obtained in step ② to detect error points and output the annotation sequence corresponding to the text to be detected.

[0119] The text to be detected is input into the system, and then the pre-loaded embedding model finds the embedding vector corresponding to each text in the input statement, which is the text vector of the text to be detected, and uses it as the input to the trained BERT-CRF model. The trained BERT-CRF model is loaded, and based on its network structure, it calculates the weights corresponding to each text in the forward pass for the input embedding vector to obtain the final error detection sequence label.

[0120] ④ Correct the detected errors in the text and output correct sentence candidates; this can be achieved using an n-gram model.

[0121] ⑤ Select the text with the highest score among the candidate correct statements as the final corrected text output.

[0122] ⑥ Output the correct text corresponding to the original text.

[0123] The aforementioned text error detection method allows for customizable text domains, offering flexibility and efficiency. By fine-tuning a pre-trained model using a small number of labeled samples within that domain, an effective text error detection model for that domain can be quickly obtained. Incorporating CRF-based text transfer information, it demonstrates excellent performance on complex text error types, overcoming the limitations of simply relying on text co-occurrence probabilities. By employing the BERT model and integrating deep semantic information exploration, it effectively captures long-distance text semantic dependencies, thereby improving error detection accuracy and making the text error detection results more reasonable and reliable.

[0124] When the above text error detection methods are applied to the text identified in invoices, the following characteristics exist: Invoices from different industries and of different types often have different page layouts, resulting in diverse types of erroneous text obtained by OCR. However, most invoices share commonalities in information representation, mainly manifesting as the same error type and repeated occurrences of erroneous characters. The above methods, based on the BERT model and combined with CRF technology, incorporate text transfer information based on CRF, which has a good effect on complex text error types and makes up for the shortcomings of simply relying on text co-occurrence probability. The BERT model, combined with deep semantic information exploration, has a good grasp of long-distance text semantic dependencies, which improves the accuracy of error detection through semantics, making the text error detection results more reasonable and reliable. Errors related to invoice information are closely related to the invoice layout (and spatial location) and non-textual information (such as table lines, separators, etc.). After the text is recognized by OCR, the above method combines the layout information of the invoice (image to be recognized) to restore the recognized text. The restored text is used as the text to be detected, which can yield a more complete text. Subsequently, text error detection is performed using the BERT-CRF model, which can extract richer text information. By utilizing the fact that the input text is a whole ordered sequence, erroneous text can be identified more effectively.

[0125] This application also provides an application scenario in which speech recognition is used to obtain the text to be detected, and then text error detection is performed on the text to be detected. The types of text errors vary significantly across different scenarios and fields. For example, OCR-recognized text has many errors related to similar-looking characters, while ASR-recognized text has many errors related to similar-sounding characters. The text error detection method in this application can be trained with samples from different scenarios to obtain corresponding models. Models for different scenarios can perform targeted error detection, thereby improving the accuracy of text error detection.

[0126] It should be understood that, although Figure 2-7The steps in the flowchart are shown sequentially as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order in which these steps are executed, and they can be performed in other orders. Figure 2-7 At least some of the steps in the process may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but may be executed at different times. The execution order of these steps or stages is not necessarily sequential, but may be executed in turn or alternately with other steps or at least some of the steps or stages in other steps.

[0127] In one embodiment, such as Figure 9 As shown, a text error detection device is provided. This device can be a software module, a hardware module, or a combination of both integrated into a computer device. Specifically, the device includes: an image acquisition module 910, a character recognition module 920, a layout restoration module 930, a vector conversion module 940, and a text error detection module 950, wherein:

[0128] Image acquisition module 910 is used to acquire images to be recognized;

[0129] The character recognition module 920 is used to recognize characters from the image to be recognized and to determine the character position information of each character;

[0130] The layout restoration module 930 is used to restore the layout of each character according to the position information of each character, so as to obtain the text to be detected;

[0131] Vector conversion module 940 is used to convert the text to be detected into a corresponding text vector;

[0132] The text error detection module 950 is used to input a text vector into a text error detection model determined through training, and obtain the text error detection result of the text to be detected output by the text error detection model.

[0133] The aforementioned text error detection device, after acquiring the image to be recognized, identifies characters from it and determines the position of each character. Then, based on the character recognition results, it performs layout reconstruction to obtain the text to be detected. The text to be detected is then vectorized to obtain the corresponding text vector, which is input into a trained text error detection model to obtain the text error detection result output by the model. In this process, after character recognition in the image, the device performs layout reconstruction based on the character positions to obtain the text to be detected. Then, it vectorizes the text to be detected and determines the text error detection result based on the vectorization result and the text error detection model. The text to be detected obtained after layout reconstruction is more suitable for the application scenario, which helps improve the accuracy of text error detection.

[0134] In one embodiment, such as Figure 10 As shown, the above-mentioned text error detection device also includes:

[0135] The candidate text acquisition module 1010 is used to acquire the correct statement candidate text corresponding to the text to be detected if the text to be detected contains erroneous characters based on the text error detection results.

[0136] The filtering module 1020 is used to filter out the correct text of the text to be detected from the candidate text of the correct statement.

[0137] The text replacement module 1030 is used to replace the text to be detected with the correct text to obtain the corrected text.

[0138] In one embodiment, the text error detection model includes a BERT sequence labeling model; the text error detection module 950 includes: a sequence labeling unit, used to input a text vector into a BERT sequence labeling model determined through training, and obtain the sequence labeling result of the text to be detected output by the BERT sequence labeling model; the text error detection module is specifically used to determine the text error detection result of the text to be detected based on the sequence labeling result.

[0139] In one embodiment, the above apparatus further includes a model training module, comprising: a sample acquisition unit for acquiring sample text and sample sequence labels corresponding to the sample text; wherein the sample text contains statements with an error rate lower than a preset threshold; a vectorization unit for converting the sample text into corresponding sample text vectors; and a training unit for training a pre-trained model based on the sample text vectors and sample label sequences to obtain a BERT sequence labeling model.

[0140] Furthermore, in one embodiment, the above-mentioned apparatus further includes: a preset model acquisition unit for acquiring a preset model; and a replacement unit for replacing the softmax layer in the preset model with a CRF layer to obtain a pre-trained model.

[0141] For specific limitations regarding the text error detection device, please refer to the limitations of the text error detection method above, which will not be repeated here. Each module in the aforementioned text error detection device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in the processor of the computer device in hardware form or independent of it, or stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to each module.

[0142] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 11 As shown, the computer device includes a processor, memory, communication interface, display screen, and input devices connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, carrier networks, NFC (Near Field Communication), or other technologies. When executed by the processor, the computer program implements a text error detection method. The display screen can be an LCD screen or an e-ink display. The input devices can be a touch layer covering the display screen, buttons, a trackball, or a touchpad on the computer device's casing, or an external keyboard, touchpad, or mouse.

[0143] Those skilled in the art will understand that Figure 11 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0144] In one embodiment, a computer device is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above method embodiments.

[0145] In one embodiment, a computer-readable storage medium is provided storing a computer program that, when executed by a processor, implements the steps in the above method embodiments.

[0146] In one embodiment, a computer program product or computer program is provided, the computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and executes the computer instructions, causing the computer device to perform the steps in the above method embodiments.

[0147] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the methods described above. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, or optical storage, etc. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc.

[0148] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0149] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.

Claims

1. A text error detection method, characterized in that, The method includes: Obtain the image to be identified; the image to be identified is a ticket image; Identify characters from the image to be identified, and determine the character position information of each character; Determine the positional relationship between any two characters based on the positional information of each character; Based on the positional relationship between pairs of characters, and combined with the table lines of the image to be identified, the layout is restored, and the text or characters belonging to the same table are combined into the same text to be detected. The text to be detected is input into the input layer of the BERT sequence labeling model; the BERT sequence labeling model is obtained by replacing the softmax layer in the pre-trained model with the CRF sequence labeling layer to obtain the pre-trained model, and then fine-tuning the pre-trained model based on the sample text vectors and sample label sequences in the bill domain. The text to be detected is vectorized using the embedding layer of the BERT sequence labeling model to obtain a text vector. The text vector includes character vectors, fragment vectors, and position vectors. The character vectors include vectors corresponding to each character in the text to be detected. The fragment vectors are vectors of character segments corresponding to each character in the text to be detected. The position vectors indicate the order of each character in the text to be detected. The text vector is input into the Transformers encoding layer of the BERT sequence labeling model for encoding, and a string of text is output to the character layer of the BERT sequence labeling model. The string of text is input into the CRF sequence labeling layer of the BERT sequence labeling model, and sequence labeling is achieved through CRF, so that the sequence labeling result of the text to be detected is output through the output layer of the BERT sequence labeling model; The text error detection result of the text to be detected is determined based on the sequence labeling results; Based on the text error detection results, character correction is performed on the text to be detected that contains errors.

2. The text error detection method according to claim 1, characterized in that, Based on the text error detection results, character correction for the text to be detected that contains errors includes: If the text to be detected is determined to contain erroneous characters based on the text error detection results, then the candidate text of the correct statement corresponding to the text to be detected is obtained. The correct text of the text to be detected is selected from the candidate texts of the correct statement; Replace the text to be detected with the correct text to obtain the corrected text.

3. The text error detection method according to claim 1, characterized in that, The training process of the BERT sequence labeling model includes the following steps: Obtain sample text and the corresponding sample sequence labels; the sample text contains statements with an error rate lower than a preset threshold. Convert the sample text into a corresponding sample text vector; The BERT sequence labeling model is obtained by training the pre-trained model based on the sample text vectors and sample label sequences.

4. A text error detection device, characterized in that, The device includes: The image acquisition module is used to acquire an image to be recognized, wherein the image to be recognized is a ticket image; A character recognition module is used to recognize characters from the image to be recognized and to determine the character position information of each character. The layout restoration module is used to restore the layout based on the positional relationship between pairs of characters and the table lines of the image to be identified, and to combine the text or characters belonging to the same table into the same text to be detected. The vector conversion module is used to input the text to be detected into the input layer of the BERT sequence labeling model. The BERT sequence labeling model is obtained by replacing the softmax layer of a pre-trained model with a CRF sequence labeling layer, and then fine-tuning the pre-trained model based on sample text vectors and sample label sequences from the ticket domain. The embedding layer of the BERT sequence labeling model vectorizes the text to be detected, resulting in text vectors containing character vectors, fragment vectors, and position vectors. The character vectors include vectors corresponding to each character in the text to be detected; the fragment vectors are vectors representing character segments corresponding to each character in the text; and the position vectors indicate the order of characters in the text. The text error detection module is used to input the text vector into the Transformers encoding layer of the BERT sequence labeling model for encoding, and output a string of text to the character layer of the BERT sequence labeling model; input the string of text into the CRF sequence labeling layer of the BERT sequence labeling model, and perform sequence labeling through CRF, so as to output the sequence labeling result of the text to be detected through the output layer of the BERT sequence labeling model; and determine the text error detection result of the text to be detected based on the sequence labeling result. The error correction module is used to correct characters in the text to be detected that contain errors based on the text error detection results.

5. The text error detection device according to claim 4, characterized in that, The error correction module is further configured to, if determined by the text error detection result that the text to be detected contains erroneous characters, obtain candidate texts of correct statements corresponding to the text to be detected; filter out the correct text of the text to be detected from the candidate texts of correct statements; and replace the text to be detected with the correct text to obtain the corrected text.

6. The text error detection device according to claim 4, characterized in that, The device further includes a model training module, which is used to acquire sample text and sample sequence labels corresponding to the sample text; the sample text contains statements with an error rate lower than a preset threshold; the sample text is converted into a corresponding sample text vector; and the pre-trained model is trained based on the sample text vector and the sample label sequence to obtain the BERT sequence labeling model.

7. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the method of any one of claims 1 to 3.

8. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the method of any one of claims 1 to 3.

9. A computer program product comprising computer instructions, characterized in that, When the computer instructions are executed by the processor, they implement the method of any one of claims 1 to 3.

Citation Information

Patent Citations

  • Text information processing method, model training method and related devices

    CN110750959A

  • Character error correction method, device and equipment and storage medium

    CN111723791A