Original text element identification method, system and device and storage medium
By combining the OCR and KIE models and using the attention-weighted Kronecker product to fuse image and text features, the problem of insufficient recognition content and low accuracy of traditional OCR under diverse document templates is solved, and more efficient original text element recognition is achieved. .
Patent Information
- Application Number
- CN202411073265.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-06
- Publication Date
- 2024-09-03
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
When existing traditional optical character recognition (OCR) technology processes diverse document templates, it automatically recognizes less content and has lower accuracy, and cannot effectively understand the relationship between the recognized words.
By inputting the original file into the pre-trained OCR model, the image information and text sequence are obtained, and input into the key information extraction (KIE) model to extract the image feature vector and text feature vector, combined with attention weighting Kronecker product is used for fusion, and finally input into the graph reasoning network for node feature classification.
It improves the accuracy and comprehensiveness of recognition of multiple types of documents, enhances the accuracy of original text element recognition, dynamically adjusts feature weights through the attention mechanism, and captures the correlation and importance between features.
Smart Images

Figure CN118587724A
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a method, system, device and storage medium for identifying original text elements. Background Art
[0002] With the acceleration of digitalization, the demand for extracting structured information from document images in automated office is increasing. At present, traditional optical character recognition (OCR) only has the functions of text detection and recognition, and cannot understand the relationship between the recognized texts. For the extraction of structured information from document images, the template matching method is adopted. That is, the template is calibrated in advance, the anchor point and the area to be recognized are determined, and the transformation matrix is calculated according to their relative positions, so as to obtain the relationship between the recognized texts and extract structured information. Because it strongly depends on the spatial position relationship of the text, the template matching method has poor generalization effect for unknown templates, and the layout and content structure are diverse, resulting in less automatically recognized content and low recognition accuracy. Summary of the invention
[0003] In view of this, the embodiments of the present application are committed to providing a method, system, device and storage medium for identifying original text elements, which are used to solve the problem that when the original file templates are diversified, the content of the original file that can be automatically identified is small and the accuracy of the identified content is low.
[0004] According to a first aspect of the present invention, the present invention provides a method for identifying original text elements, comprising: Inputting the original document into a pre-trained OCR model to obtain image information and text sequence, wherein the OCR model is trained by document data in various formats; Input the image information and the text sequence into a pre-trained KIE model to obtain an image feature vector and a text feature vector; The image feature vector and the text feature vector are fused by using an attention-weighted Kronecker product to obtain a weighted dual-feature vector matrix; Inputting the weighted dual eigenvector matrix into a graph reasoning network to obtain node features; The node features are classified according to pre-set field categories.
[0005] Preferably, the step of inputting the original document into a pre-trained OCR model to obtain image information and text sequence includes: Preprocessing the original file through an OCR model; Performing layout analysis on the pre-processed original document and performing a second text area detection to obtain image information; Based on the second text area detection, text recognition is performed on the original document to obtain a text sequence.
[0006] Preferably, the preprocessing of the original document by using an OCR model includes: The first step is to detect the text area, detect the text direction and segment the original file into regions using a convex hull algorithm.
[0007] Preferably, the training of the KIE model includes: A variety of image information and text sequences are used as inputs of the KIE model, and image feature vectors and text feature vectors are used as outputs of the KIE model.
[0008] Preferably, the step of inputting the image information and the text sequence into a pre-trained KIE model to obtain an image feature vector and a text feature vector comprises: Performing region segmentation on the image information through U-Net and performing feature extraction on the segmented image information through ROI-Pooling to obtain an image feature vector; The text sequence is subjected to feature extraction through Bi-LSTM to obtain a text feature vector.
[0009] Preferably, the image feature vector and the text feature vector are fused by using an attention-weighted Kronecker product to obtain a weighted dual-feature vector matrix, including: Calculate an attention score using the image feature vector and the text feature vector; Normalizing the attention score through a softmax function to obtain an attention weight; weighting the Kronecker product by the attention weights; The image feature vector and the text feature vector are subjected to the weighted Kronecker product to obtain the weighted dual feature vector matrix; The weighted Kronecker product is given by the following formula: ; Where: is the weighted Kronecker product matrix of the nth pair of eigenvectors; The attention weight of the nth pair of feature vectors; is the text feature vector n; is the image feature vector n; is the Kronecker product operator.
[0010] Preferably, after the classification based on the node features according to the preset field categories, the process further includes result processing: Check the classified content for text errors.
[0011] According to a third aspect of the present invention, there is also provided a system for identifying original text elements, comprising: Training module: used to input the original document into a pre-trained OCR model to obtain image information and text sequence. The OCR model is trained by document data in various formats. Feature vector module: used to input the image information and the text sequence into a pre-trained KIE model to obtain an image feature vector and a text feature vector; Fusion module: used for fusing the image feature vector and the text feature vector through attention weighted Kronecker product to obtain a weighted dual feature vector matrix; Reasoning module: used to obtain node features based on the weighted dual eigenvector matrix input into the graph reasoning network; Classification module: used to classify the node features according to pre-set field categories.
[0012] According to a fourth aspect of the present invention, there is also provided an electronic device, comprising a processor and a memory, wherein the memory stores computer executable instructions that can be executed by the processor, and the processor executes the computer executable instructions to implement the original text element recognition method.
[0013] According to the fifth aspect of the present invention, a computer-readable storage medium is also provided, which stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the original text element recognition method.
[0014] According to the first aspect of the present invention, the image information and text sequence of the original document are obtained through the OCR model and input into the KIE model to extract the image feature vector and the text feature vector. The image feature vector and the text feature vector are fused through the weighted Kronecker product to obtain the weighted dual-model matrix. The node features are then obtained through the graph reasoning network to simultaneously identify the image part and the text part. Since the importance of dynamic text features and image features is different, the weighted Kronecker product is used through the attention mechanism to adjust the weights in the fusion process, so as to better capture the correlation and importance between features, further improve the accuracy and comprehensiveness of recognition, and finally classify through node features, so as to realize the recognition of various types of files, and comprehensively identify the content, thereby improving the accuracy of original text element recognition. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 A schematic flow chart of a method for identifying original text elements according to an embodiment of the present invention is shown; Figure 2 Shows Figure 1 The schematic flow chart of the method for obtaining image information and text sequence in step S100 is shown; Figure 3 Shows Figure 1 A schematic flow chart of the method for obtaining the image feature vector and the weighted text feature vector in step S200 is shown; Figure 4 Shows Figure 1 A schematic flow chart of the method for obtaining a weighted dual eigenvector matrix in step S300 is shown; Figure 5 A schematic flow chart of a system for identifying original text elements according to an embodiment of the present invention is shown; Figure 6 It shows a principle flow chart of a method for identifying original text elements according to an embodiment of the present invention; Figure 7 A technical flow chart of a method for identifying original text elements according to an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0016] In order to make the above-mentioned purposes, characteristic vectors and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are described in detail below in conjunction with the accompanying drawings. It is understandable that the specific embodiments described herein are only used to explain the present application, rather than to limit the present application. It should also be noted that, for ease of description, only part of the structure related to the present application is shown in the accompanying drawings, rather than all of the structures. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0017] The terms "including" and "having" and any variations thereof in this application are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products or devices.
[0018] Reference to "embodiment" herein means that a particular feature vector, structure or characteristic described in conjunction with the embodiment may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0019] Figure 1FIG. 2 shows a schematic flow chart of a method for identifying original text elements according to an embodiment of the present invention. Figure 1 As shown, a method for identifying original text elements includes: Step S100: inputting the original document into a pre-trained OCR model to obtain image information and text sequence, the OCR model is trained by using document data in various formats; Step S200: inputting the image information and text sequence into a pre-trained Key Information Extraction (KIE) model to obtain an image feature vector and a text feature vector; Step S300: fusing the image feature vector and the text feature vector through the attention weighted Kronecker product to obtain a weighted dual feature vector matrix; Step S400: input the weighted dual eigenvector matrix into the graph reasoning network to obtain node features; Step S500: Classify the node features according to pre-set field categories.
[0020] The problem of low efficiency of manual text input is solved by combining the OCR model and the KIE model, and the weighted Kronecker product of the attention mechanism is used to adjust the weights in the fusion process to better capture the correlation and importance between features, further improving the accuracy and comprehensiveness of recognition, and also improving the performance of the model.
[0021] Figure 2 Shows Figure 1 The schematic flow chart of the method for obtaining image information and text sequence in step S100 is shown as follows. Figure 2 As shown, in step S100, the original document is input into a pre-trained OCR model to obtain image information and text sequence, including: Step S110: pre-processing the original document through the OCR model; Step S120: performing layout analysis on the pre-processed original document and performing a second text area detection to obtain image information; Step S130: performing text recognition on the original document based on the second text region detection to obtain a text sequence.
[0022] The first text area detection divides the input file into text areas, but errors in area division may occur. For example, to recognize "Name: Zhang San" in an image, the ideal situation is to have two text boxes of "Name" and "Zhang San" instead of a whole text box of "Name: Zhang San". Or, if redundant text blocks are detected in some images, the second text area detection can be used to re-detect the text detection model that has been trained specifically for a certain type of certificate.
[0023] Wherein, in step S110, the document is preprocessed through the OCR model, including the first text area detection, text direction detection and region segmentation of the original document through the convex hull algorithm.
[0024] The first text detection generally uses general text detection, that is, all text blocks in the image will be directly detected, which can facilitate a judgment on the orientation of all text in the image, confirm whether the image is deflected by 90 degrees, 180 degrees or 270 degrees, and if so, deflect it back, and prepare for file area segmentation through the convex hull algorithm.
[0025] Figure 3 Shows Figure 1 The schematic flow chart of the method for obtaining the image feature vector and the text feature vector in step S200 is shown as follows. Figure 3 As shown, in step S200, the training of the KIE model includes taking a variety of image information and text sequences as inputs of the KIE model, and the image feature vector and the text feature vector as outputs of the KIE model.
[0026] In step S200, the image information and the text sequence are input into the pre-trained KIE model to obtain the image feature vector and the text feature vector, including: Step S210: performing region segmentation on the image information through U-Net (convolutional neural network) and extracting feature vectors from the segmented image information through ROI-Pooling (Region of Interest Pooling) to obtain an image feature vector; Step S220: extract feature vectors from the text sequence using a Bi-LSTM (bidirectional long short-term memory network) to obtain a text feature vector.
[0027] Figure 4 Shows Figure 1 The schematic flow chart of the method for obtaining the weighted dual eigenvector matrix in step S300 is shown as follows. Figure 4 As shown, the image feature vector and the text feature vector are fused through the attention weighted Kronecker product to obtain a weighted dual feature vector matrix, including: Step S310: Calculate the attention score through the image feature vector and the text feature vector; Step S320: normalize the attention score through the softmax function to obtain the attention weight; Step S330: weighting the Kronecker product by the attention weight; Step S340: Obtain a weighted dual eigenvector matrix by performing a weighted Kronecker product on the image eigenvector and the text eigenvector; Weighted Kronecker product, the formula is as follows: ; Where: is the weighted Kronecker product matrix of the nth pair of eigenvectors; The attention weight of the nth pair of feature vectors; is the text feature vector n; is the image feature vector n; is the Kronecker product operator.
[0028] By introducing the attention mechanism, the weight of the feature can be dynamically adjusted according to the importance of the input data, that is, for the fusion of each pair of elements, the similarity and importance of image and text features are weighted using the attention weight, which can make the fused features more accurate and effective.
[0029] After classifying the node features according to the preset field categories in step S500, the following further processing is included: Step S600: Check the classified content to see if there are any text errors.
[0030] Manually check the classified content to avoid text recognition errors in the content.
[0031] Figure 6 FIG. 4 shows a flow chart of the principle of a method for identifying original text elements according to an embodiment of the present invention. Figure 6 As shown in the figure, the user inputs the original file information through the APIManager interface, including text images, tables and certificates; first, the certificate classification (ImgClassifier) is performed, and the classified source file is preprocessed (ETPreprocess), which includes text area detection (TextDec), text direction detection (TextDirection) and convex hull algorithm (Convex hull). After the image preprocessing, the layout analysis (ETStructure) is performed, and then the second text area detection (TextDirection) is performed. If there is no problem with the file after the text area detection, text recognition (TextRec) is performed to obtain image information and text sequence. Key information extraction (TextKIE) is performed on the image information and text sequence, and finally the result processing is performed, mainly text error correction (TextFix).
[0032] Figure 7 FIG. 4 shows a technical flow chart of a method for identifying original text elements according to an embodiment of the present invention. Figure 7As shown in the figure, starting from the mandatory items for basic information entry, by sorting out the basic information fields, and then using different algorithm models for training respectively, combined with actual project data test feedback, optimization, and closed loop, the model recognition accuracy is continuously improved. The entire recognition process includes three parts: Part 1: Use OCR recognition technology to recognize the text on the first page of the file.
[0033] Standard field sorting: The original text is an important document. In order to understand the actual situation of the project and collect data for model training, it is necessary to obtain standard fields and detailed classification of each field. Field type analysis uses OCR recognition.
[0034] The text at the beginning of the original file may be a picture and cannot be directly converted into text. The fields that can be extracted through OCR recognition are: name, file number, publication level, and applicable area.
[0035] In actual use, there are multiple types of templates in the file. At this time, the accuracy of the image classification model restricts the bottleneck of the template matching algorithm. Only when the classification is correct can it be successfully matched and the key information can be correctly extracted. Therefore, this embodiment replaces the template classification model and the template matching model as a whole with the key information extraction (KIE) model. According to the input text detection and text recognition information, the text information can be directly classified into the defined category without the need for a pre-classification model.
[0036] KIE first obtains an image feature vector {vi} through U-Net and ROI-Pooling, and obtains a weighted text feature vector {ti} through Bi-LSTM. The two feature vectors are combined through the weighted Kronecker product to obtain a bimodal fusion model, which is then sent to the graph reasoning network. Each node represents a document field that combines the image feature vector and the text feature vector. Finally, the node features are classified into the defined field category, thereby realizing the extraction of key information from the document image.
[0037] The two feature vectors are fused through the weighted Kronecker product of the attention mechanism. The specific steps are as follows: First, input the text feature matrix T and image feature matrix I; Secondly, the attention score is calculated by the text feature matrix and the image feature matrix. The methods for calculating the attention score include but are not limited to dot product attention, multi-head attention, etc.; ; Where: is the attention score; is the text feature vector n; is the image feature vector n; Normalize the attention score through the softmax function to obtain the attention weight ; ; Where: The attention weight of the nth pair of feature vectors; is the attention score; N is the number of samples.
[0038] Finally, for each pair of eigenvectors , perform weighted Kronecker product operation; ; Where: is the weighted Kronecker product matrix of the nth pair of eigenvectors; The attention weight of the nth pair of feature vectors; is the text feature vector n; is the image feature vector n; is the Kronecker product operator.
[0039] Part 2: Use entity recognition algorithm to extract field information from the body text.
[0040] Read the text content in text format and extract the entity information corresponding to the standard fields. The fields that can be extracted are: release date, effective date, consultant, and consultation phone number.
[0041] Part 3: Identify multi-category fields based on matching keywords in the original text with the classification vocabulary.
[0042] After the original content is segmented and matched, it is matched with the classification vocabulary for similarity, and the results with high similarity are given as multi-classification content. The identifiable fields are: applicable object and subject.
[0043] The model is trained using different algorithm models based on the collected sample data and tuned based on the accuracy. In the subsequent continuous operation optimization, when there is new data in the actual project, the field information is first extracted through the feature recognition model. After review and correction by the operation staff, the problems encountered in the actual project (such as the content format and location changes of the new file, etc.) are fed back; based on the business, the mapping relationship between multiple classification fields is sorted out, the field discrimination rules are formed, the feature recognition model is optimized, and the accuracy of feature recognition and the user experience of the information entry platform are gradually improved.
[0044] Figure 5 FIG. 4 shows a schematic flow chart of a system for identifying original text elements according to an embodiment of the present invention; Figure 5 As shown, in particular, a system for identifying original text elements is also provided, including: Training module 510: used to input the original document into a pre-trained OCR model to obtain image information and text sequence. The OCR model is trained by document data in various formats; Feature vector module 520: used to input image information and text sequence into a pre-trained KIE model to obtain image feature vectors and text feature vectors; Fusion module 530: used to fuse the image feature vector and the text feature vector through attention weighted Kronecker product to obtain a weighted dual feature vector matrix; Reasoning module 540: used to obtain node features based on the weighted dual eigenvector matrix input to the graph reasoning network; Classification module 550: used to classify node features according to pre-set field categories.
[0045] In particular, an electronic device is also provided, the electronic device includes a processor and a memory, the memory stores computer executable instructions that can be executed by the processor, and the processor executes the computer executable instructions to implement the original text element recognition method, for example, to execute the above-described Figure 1 Steps S100 to S500 of the method described above are also performed. Figure 2 The method comprises steps S110 to S130.
[0046] In particular, a computer-readable storage medium is also provided, wherein the computer-readable storage medium stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions cause the processor to implement a method for identifying original text elements, for example, executing the above-described Figure 1 Steps S100 to S500 of the method described above are also performed. Figure 2 The method comprises steps S110 to S130.
[0047] The processor is used to complete various control logics of the device, which can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), a single-chip microcomputer, an ARM (Acorn RISCMachine) or other programmable logic device, a discrete gate or transistor logic, a discrete hardware component, or any combination of these components. In addition, the processor can also be any traditional processor, microprocessor or state machine. The processor can also be implemented as a combination of computing devices, for example, a combination of a DSP and a microprocessor, a plurality of microprocessors, one or more microprocessors combined with a DSP and / or any other such configuration.
[0048] The memory may include a program storage area and a data storage area, wherein the program storage area may store an operating system and applications required for at least one function; the data storage area may store data created according to the use of the device, etc. In addition, the memory may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory may optionally include a memory remotely arranged relative to the processor, and these remote memories may be connected to the device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0049] As an example, non-volatile storage media can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) as external cache memory. By way of illustration and not limitation, RAM can be obtained in many forms such as synchronous RAM (SRAM), dynamic RAM, (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), Synchlink DRAM (SLDRAM), and direct Rambus RAM (DRRAM). The disclosed memory components or memories of the operating environment described herein are intended to include one or more of these and / or any other suitable types of memory.
[0050] Of course, those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing related hardware (such as a processor, a controller, etc.) through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium, and the computer program can include the processes of the above-mentioned method embodiments when executed. The storage medium can be a memory, a disk, a floppy disk, a flash memory, an optical storage device, etc.
[0051] The above are only some specific implementation methods of the present application, and any other improvements made based on the concept of the present application are deemed to be within the protection scope of the present application.
Claims
1. A method for identifying original text elements, characterized in that: include: Inputting the original document into a pre-trained OCR model to obtain image information and text sequence, wherein the OCR model is trained by document data in various formats; Input the image information and the text sequence into a pre-trained KIE model to obtain an image feature vector and a text feature vector; The image feature vector and the text feature vector are fused by using an attention-weighted Kronecker product to obtain a weighted dual-feature vector matrix; Inputting the weighted dual eigenvector matrix into a graph reasoning network to obtain node features; The node features are classified according to pre-set field categories.
2. The method according to claim 1, characterized in that: The process of inputting the original document into a pre-trained OCR model to obtain image information and text sequence includes: Preprocessing the original file through an OCR model; Performing layout analysis on the pre-processed original document and performing a second text area detection to obtain image information; Based on the second text area detection, text recognition is performed on the original document to obtain a text sequence.
3. The method according to claim 2, characterized in that The preprocessing of the original file by the OCR model includes: The first step is to detect the text area, detect the text direction and segment the original file into regions using a convex hull algorithm.
4. The method according to claim 1, characterized in that: The training of the KIE model includes: A variety of image information and text sequences are used as inputs of the KIE model, and image feature vectors and text feature vectors are used as outputs of the KIE model.
5. The method according to claim 1, characterized in that The step of inputting the image information and the text sequence into a pre-trained KIE model to obtain an image feature vector and a weighted text feature vector includes: Performing region segmentation on the image information through U-Net and performing feature extraction on the segmented image information through ROI-Pooling to obtain an image feature vector; The text sequence is subjected to feature extraction through Bi-LSTM to obtain a text feature vector.
6. The method according to claim 1, characterized in that The image feature vector and the text feature vector are fused by using the attention weighted Kronecker product to obtain a weighted dual feature vector matrix, including: Calculate an attention score using the image feature vector and the text feature vector; Normalizing the attention score through a softmax function to obtain an attention weight; weighting the Kronecker product by the attention weights; The image feature vector and the text feature vector are subjected to the weighted Kronecker product to obtain the weighted dual feature vector matrix; The weighted Kronecker product is given by the following formula: ; Where: is the weighted Kronecker product matrix of the nth pair of eigenvectors; The attention weight of the nth pair of feature vectors; is the text feature vector n; is the image feature vector n; is the Kronecker product operator.
7. The method according to claim 1, characterized in that After the node features are classified according to the preset field categories, the method further includes: Check the classified content for text errors.
8. A text element recognition system, characterized in that: include: Training module: used to input the original document into a pre-trained OCR model to obtain image information and text sequence. The OCR model is trained by document data in various formats. Feature vector module: used to input the image information and the text sequence into a pre-trained KIE model to obtain an image feature vector and a text feature vector; Fusion module: used for fusing the image feature vector and the text feature vector through attention weighted Kronecker product to obtain a weighted dual feature vector matrix; Reasoning module: used to obtain node features based on the weighted dual eigenvector matrix input into the graph reasoning network; Classification module: used to classify the node features according to pre-set field categories.
9. An electronic device, characterized in that: The electronic device includes a processor and a memory, the memory stores computer-executable instructions that can be executed by the processor, and the processor executes the computer-executable instructions to implement the original text element recognition method described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions. When the computer-executable instructions are called and executed by the processor, the computer-executable instructions prompt the processor to implement the original text element recognition method described in any one of claims 1 to 7.
Citation Information
Patent Citations
Image character recognition method and system based on deep learning and medium
CN112016547A
OCR method and system based on bankbook and bill characters
CN112507914A
Method and device for generating graph neural network model, equipment and storage medium
CN114418124A
Key information extraction method and model for identifying text semantics in scene
CN117079288A
Image processing method using artificial neural network and neural processing unit
CN117396913A
