Method, device and storage medium for extracting text elements from scanned documents

Through the combination of optical character recognition and T5 model, the automation problem of text element extraction from scanned documents in the financial industry is solved, efficient extraction and adaptation of text elements is achieved, and development and maintenance costs are reduced.

CN117593757BActive Publication Date: 2024-10-01CHINA MERCHANTS FUND MANAGEMENT CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311718243.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-12-13
Publication Date
2024-10-01
Estimated Expiration
2043-12-13

AI Technical Summary

Technical Problem

Existing technology makes it difficult to automate the extraction of text elements from scanned documents in the financial industry, resulting in a large number of manual operations. Moreover, due to the diverse styles of file templates, codes need to be developed for each template, which increases development costs and maintenance difficulty.

Method used

The optical character recognition model is used to identify the text content of scanned documents, and through the combination of T5 model and pointer network layer, text format splicing and element extraction are performed, and text elements and positions are output, which reduces the need for development code for each file template.

Benefits of technology

It realizes the automatic extraction of scanned text elements, reduces labor investment and development costs, adapts to new file styles, and avoids errors caused by frequent code modifications, and is widely used in the financial field.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117593757B_ABST
    Figure CN117593757B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, device and storage medium for extracting text elements from scanned documents, and relates to the technical field of information extraction. The method for extracting text elements from scanned documents comprises: identifying the first text content in the scanned document to be extracted by an optical character recognition model; splicing the first text content based on the text format of the first text content in the scanned document to be extracted, wherein the text format is a text paragraph or a table; inputting the spliced ​​first text content into a pre-trained element extraction model, and outputting at least one text element in the first text content and the position of each text element. The method, device and storage medium for extracting text elements disclosed in the present invention can reduce the manpower input and development cost of text element extraction, avoid introducing new problems due to the maintenance of a large amount of code, and can be widely used for extracting text elements from scanned documents in various fields.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of information extraction, and in particular relates to a method, device and storage medium for extracting text elements from a scanned document. Background Art

[0002] In the financial industry, a large number of business interactions are carried out in the form of scanned copies, such as the need to extract key elements from documents for data entry, and to review data based on stamped scanned copies. Due to the unstructured nature of the data, related businesses cannot be automated and can only rely on a large amount of manual operations.

[0003] At present, the common processing solution in the industry is to first use the optical character recognition (OCR) model to extract the text and the table and location information where the text is located, and then analyze each type of file template to find out the location pattern of each element, and write the corresponding rule code to extract the text elements. However, due to the variety of file template styles, this method requires the development of corresponding codes for each template, which increases the development cost, and it is difficult to adapt to newly emerging file templates or small modifications to the original file template. In addition, the cost of daily maintenance is very high, and the code needs to be modified frequently, which is easy to introduce new errors, which brings great inconvenience to the extraction of text elements in scanned documents.

[0004] Therefore, how to provide an effective solution to facilitate the extraction of text elements in scanned documents has become a difficult problem to be solved in the prior art. Summary of the invention

[0005] The purpose of the present invention is to provide a method, device and storage medium for extracting text elements from a scanned document, so as to solve the above-mentioned problems existing in the prior art.

[0006] In order to achieve the above object, the present invention adopts the following technical solutions:

[0007] In a first aspect, the present invention provides a method for extracting text elements from a scanned document, comprising:

[0008] Recognize the first text content in the scanned document to be extracted by using an optical character recognition model;

[0009] splicing the first text content based on the text format of the first text content in the scanned document to be extracted, wherein the text format is a text paragraph or a table;

[0010] Inputting the concatenated first text content into a pre-trained element extraction model, and outputting at least one text element in the first text content and the position of each text element;

[0011] Among them, the feature extraction model includes a T5 model and a pointer network layer, the pointer network layer is connected to the last output layer of the T5 model, the last output layer of the T5 model is used to output at least one text element in the first text content, and the pointer network layer is used to take the at least one text element as input and output the position of each text element in the first text content.

[0012] Based on the above disclosed content, the present invention identifies the first text content in the scanned copy to be extracted through an optical character recognition model; splices the first text content based on the text format of the first text content in the scanned copy to be extracted, wherein the text format is a text paragraph or a table; inputs the spliced ​​first text content into a pre-trained element extraction model, and outputs at least one text element in the first text content and the position of each text element. In this way, the text elements in the scanned copy to be extracted can be extracted very conveniently, reducing manpower investment. At the same time, there is no need to develop corresponding codes for each file template. Generally, newly emerging file styles can also be well adapted, reducing development costs. In addition, since there is no need to develop corresponding codes for each file template, there is no need to maintain a large amount of code, avoiding the introduction of new problems due to frequent code modifications. It can be widely used in the extraction of text elements in scanned copies in various fields, especially in the extraction of text elements in scanned copies in the financial field.

[0013] Through the above-mentioned design, the present invention can very conveniently extract the text elements in the scanned documents to be extracted, reduce manpower investment, and at the same time, there is no need to develop corresponding codes for each file template. Generally, newly emerging file styles can also be well adapted, reducing development costs. In addition, since there is no need to develop corresponding codes for each file template, there is no need to maintain a large amount of code, avoiding the introduction of new problems due to frequent code modifications. The invention can be widely used in the extraction of text elements in scanned documents in various fields, especially in the extraction of text elements in scanned documents in the financial field.

[0014] In a possible design, the step of splicing the first text content includes:

[0015] If the text format is a text paragraph, two adjacent lines of text content in the first text content are spliced ​​together using a first splicing symbol;

[0016] If the text format is a table, two adjacent columns of text content in the first text content are spliced ​​using the second splicing symbol in a sequence from left to right and from top to bottom, and two adjacent rows of text content in the first text content are spliced ​​using the first splicing symbol.

[0017] In one possible design, the method further includes:

[0018] Recognize the second text content in the sample scan by using the optical character recognition model;

[0019] splicing the second text content based on the text format of the second text content in the sample scanned copy;

[0020] The second text content after the annotated text elements and the spliced ​​text elements is used as the input of the element extraction model for training to obtain a trained element extraction model.

[0021] 4. The method for extracting text elements from scanned documents according to claim 3, wherein the loss function of the element extraction model is Where D Task represents the training sample, s represents the prompt word of the text element, x represents the second text content after the text element is annotated and spliced, y represents the content of the element to be extracted, θ e represents the encoding parameter in the feature extraction model, θ d Represents the decoding parameters in the feature extraction model.

[0022] In a possible design, the file format of the scanned copy to be extracted is JPG or PDF.

[0023] In a second aspect, the present invention provides a device for extracting text elements from a scanned document, the device for extracting text elements from a scanned document comprising:

[0024] A recognition unit, used to recognize the first text content in the scanned document to be extracted by using an optical character recognition model;

[0025] A splicing unit, configured to splice the first text content based on a text format of the first text content in the scanned document to be extracted, wherein the text format is a text paragraph or a table;

[0026] A computing unit, used for inputting the concatenated first text content into a pre-trained element extraction model, and outputting at least one text element in the first text content and the position of each text element;

[0027] Among them, the feature extraction model includes a T5 model and a pointer network layer, the pointer network layer is connected to the last output layer of the T5 model, the last output layer of the T5 model is used to output at least one text element in the first text content, and the pointer network layer is used to take the at least one text element as input and output the position of each text element in the first text content.

[0028] In a third aspect, the present invention provides another device for extracting text elements from a scanned document, comprising a memory, a processor and a transceiver that are communicatively connected in sequence, wherein the memory is used to store a computer program, the transceiver is used to send and receive messages, and the processor is used to read the computer program to execute the method for extracting text elements from a scanned document as described in the first aspect or any possible design of the first aspect.

[0029] In a fourth aspect, the present invention provides a computer-readable storage medium having instructions stored thereon, which, when executed on a computer, executes the method for extracting text elements from a scanned document as described in the first aspect or any possible design of the first aspect.

[0030] In a fifth aspect, the present invention provides a computer program product comprising instructions, which, when executed on a computer, causes the computer to execute the method for extracting text elements from a scanned document as described in the first aspect or any possible design of the first aspect.

[0031] Beneficial effects:

[0032] The text element extraction method, device and storage medium in scanned documents provided by the present invention can very conveniently extract the text elements in the scanned documents to be extracted, reduce manpower investment, and at the same time, there is no need to develop corresponding codes for each file template. Generally, newly emerging file styles can also be well adapted, reducing development costs. In addition, since there is no need to develop corresponding codes for each file template, there is no need to maintain a large amount of code, avoiding new problems introduced due to frequent code modifications. The method, device and storage medium can be widely used for the extraction of text elements in scanned documents in various fields, especially the extraction of text elements in scanned documents in the financial field. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] Figure 1 A flowchart of a method for extracting text elements from a scanned document provided in an embodiment of the present application;

[0034] Figure 2 A schematic block diagram of a device for extracting text elements from a scanned document provided in an embodiment of the present application;

[0035] Figure 3 A block diagram of another apparatus for extracting text elements from a scanned document provided in an embodiment of the present application. DETAILED DESCRIPTION

[0036] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the present invention will be briefly introduced below in combination with the drawings and the description of the embodiments or the prior art. Obviously, the following description of the structure of the drawings is only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. It should be noted that the description of these embodiments is used to help understand the present invention, but does not constitute a limitation of the present invention.

[0037] It should be understood that although the terms first, second, etc. may be used herein to describe various units, these units should not be limited by these terms. These terms are only used to distinguish one unit from another unit. For example, a first unit can be referred to as a second unit, and similarly, a second unit can be referred to as a first unit without departing from the scope of the exemplary embodiments of the present invention.

[0038] It should be understood that the term "and / or" that may appear in this article is merely a description of the association relationship between associated objects, indicating that three relationships may exist. For example, A and / or B can represent three situations: A exists alone, B exists alone, and A and B exist at the same time. The term " / and" that may appear in this article describes another type of association object relationship, indicating that two relationships may exist. For example, A / and B can represent two situations: A exists alone, and A and B exist alone. In addition, the character " / " that may appear in this article generally indicates that the previous and next associated objects are in an "or" relationship.

[0039] In order to facilitate the extraction of text elements in scanned documents, the embodiments of the present application provide a method, device and storage medium for extracting text elements in scanned documents. The method, device and storage medium for extracting text elements in scanned documents can reduce the manpower investment and development cost of text element extraction, avoid the introduction of new problems by maintaining a large amount of code, and can be widely used for the extraction of text elements in scanned documents in various fields.

[0040] The method for extracting text elements from scanned documents provided in the embodiments of the present application can be applied to a user terminal or a server, and the user terminal can be, but is not limited to, a personal computer, a smart phone, a tablet computer, a laptop computer, a personal digital assistant, etc. It is understood that the execution subject does not constitute a limitation on the embodiments of the present application.

[0041] The following is a detailed description of the method for extracting text elements from a scanned document provided in an embodiment of the present application. The method for extracting text elements from a scanned document may include but is not limited to the following steps S101-S103.

[0042] Step S101: Recognize the first text content in the scanned document to be extracted through an optical character recognition model.

[0043] In an embodiment of the present application, the first text content in the scanned copy to be extracted can be identified by an optical character recognition model, the file format of the scanned copy to be extracted can be but not limited to JPG or PDF, etc., the first text content in the scanned copy to be extracted can be but not limited to Chinese characters, letters or numbers, etc., and the first text content in the scanned copy to be extracted can be in the form of a text paragraph or in the form of a table.

[0044] It is a prior art to recognize the first text content in the scanned document to be extracted by using an optical character recognition model, which will not be described in detail here.

[0045] Step S102: splicing the first text content based on the text format of the first text content in the scanned document to be extracted.

[0046] The text format may be a text paragraph or a table. In the embodiment of the present application, the text format of the first text content in the scanned document to be extracted may be directly identified by an optical character recognition model.

[0047] When splicing the first text content, if the text format is a text paragraph, two adjacent lines of text content in the first text content can be spliced ​​together using the first splicing symbol. If the text format is a table, two adjacent columns of text content in the first text content can be spliced ​​together using the second splicing symbol in a left-to-right and top-to-bottom order, and two adjacent lines of text content in the first text content can be spliced ​​together using the first splicing symbol. The first splicing symbol and the second splicing symbol can be set according to actual conditions. For example, the first splicing symbol can be " ", and the second splicing symbol may be "\\". It can be understood that in some other embodiments, the first splicing symbol and the second splicing symbol may also use other symbols.

[0048] Step S103: Input the spliced ​​first text content into a pre-trained feature extraction model, and output at least one text element in the first text content and the position of each text element.

[0049] Among them, the feature extraction model adopts the improved T5 (Text to Text Transfer Transformer) model, which includes the T5 model and the pointer network layer. The pointer network layer is connected to the last output layer of the T5 model. The last output layer of the T5 model is used to output at least one text element (entity) in the first text content. The pointer network layer is used to take at least one text element as input and output the position of each text element in the first text content. In this way, by inputting the spliced ​​first text content into the feature extraction model, at least one text element in the first text content and the position of each text element can be output.

[0050] For example, in a fund confirmation form, required elements can be extracted according to business needs, such as fund name, fund code, application share, application amount, confirmed share, confirmed amount and other text elements and the position of each text element. Extracting the position of each text element can facilitate relevant personnel to check the extracted text elements.

[0051] In the embodiment of the present application, the T5 model is used as the initialization training model, and fine-tuning training is performed on the basis of the model to achieve unified modeling of different information extraction tasks. The basic idea is to model each text-related problem as a "text to text" problem. The advantage of doing so is that each NLP (Natural Language Processing) task can be treated with the same model, objective function, training and decoding process, with high flexibility. In addition, the T5 model has good migration and generalization capabilities, supports key information extraction without limiting industry fields and extraction targets, can achieve zero-sample fast cold start, and has excellent small sample fine-tuning capabilities, and low-cost adaptation to the extraction targets of specific fields. Thus, in the financial field, efficient extraction of text elements can be achieved with small samples.

[0052] Before training the feature extraction model, the second text content in the sample scan can be identified by the optical character recognition model, and the second text content can be spliced ​​based on the text format of the second text content in the sample scan. During training, the spliced ​​second text content can be used as a training sample, and the text elements to be extracted in the spliced ​​second text content can be annotated, and then the spliced ​​second text content with the annotated text elements can be used as the input of the feature extraction model for training to obtain the trained feature extraction model. The annotated text elements can be, for example, the fund name, fund code, application share, application amount, confirmed share, and confirmed amount in the fund confirmation form.

[0053] The second text content after the text elements are marked and spliced ​​can be expressed as [CLS] Prompt [SEP] Content [SEP], where Prompt is the prompt word (i.e., text element) to tell the model which text elements need to be extracted, and Content is the content from which the elements need to be extracted (i.e., the second text content after splicing). For example, if you need to extract the fund category element from the text paragraph "Categories of asset management plans, this plan is a fixed-income product", you can use the fund category as the prompt word Prompt, followed by the text content, connected by a separator in the middle.

[0054] In an embodiment of the present application, fine-tuning can be performed based on the training element extraction model for specific task scenarios, and the amount of sample data for training can be selected according to the complexity of the task (the more text elements extracted, the more complex the task). The selected amount of sample data for training can be divided into training set, validation set and test set according to a certain ratio, such as setting the training set, validation set and test set in a ratio of 7.5:1.5:1.

[0055] In the embodiment of the present application, the loss function of the factor extraction model can be Where D Task represents the training sample, s represents the prompt word of the text element, x represents the second text content after the text element is annotated and spliced, y represents the content of the element to be extracted, θ e represents the encoding parameter in the feature extraction model, θ d Represents the decoding parameters in the feature extraction model.

[0056] In one or more embodiments, it may be necessary to extract text elements from only part of the text content in the scanned document to be extracted (e.g., extract only the text elements of a specified chapter or a specified page), so some negative samples may be added for training by adding text elements to other places in the text except for the file elements to be extracted. During the training process, the training process may be stopped when the number of training rounds reaches a set number or the loss function converges.

[0057] In summary, the method for extracting text elements from scanned copies provided by the embodiment of the present application, identifies the first text content in the scanned copy to be extracted through an optical character recognition model; splices the first text content based on the text format of the first text content in the scanned copy to be extracted, wherein the text format is a text paragraph or a table; inputs the spliced ​​first text content into a pre-trained element extraction model, and outputs at least one text element in the first text content and the position of each text element. In this way, the text elements in the scanned copy to be extracted can be extracted very conveniently, reducing manpower investment. At the same time, there is no need to develop corresponding codes for each file template. Generally, newly emerging file styles can also be well adapted, reducing development costs. In addition, since there is no need to develop corresponding codes for each file template, there is no need to maintain a large amount of code, avoiding the introduction of new problems due to frequent code modifications. It can be widely used in the extraction of text elements in scanned copies in various fields, especially in the financial field.

[0058] See also Figure 2 According to a second aspect of an embodiment of the present application, a device for extracting text elements from a scanned document is provided. The device for extracting text elements from a scanned document comprises:

[0059] A recognition unit, used to recognize the first text content in the scanned document to be extracted by using an optical character recognition model;

[0060] A splicing unit, configured to splice the first text content based on a text format of the first text content in the scanned document to be extracted, wherein the text format is a text paragraph or a table;

[0061] A computing unit, used for inputting the concatenated first text content into a pre-trained element extraction model, and outputting at least one text element in the first text content and the position of each text element;

[0062] Among them, the feature extraction model includes a T5 model and a pointer network layer, the pointer network layer is connected to the last output layer of the T5 model, the last output layer of the T5 model is used to output at least one text element in the first text content, and the pointer network layer is used to take the at least one text element as input and output the position of each text element in the first text content.

[0063] The working process, working details and technical effects of the text element extraction device in a scanned document provided in the second aspect of this embodiment can be referred to the first aspect of the embodiment and will not be repeated here.

[0064] like Figure 3 As shown, the third aspect of an embodiment of the present application provides another device for extracting text elements from a scanned document, comprising a memory, a processor and a transceiver that are communicatively connected in sequence, wherein the memory is used to store a computer program, the transceiver is used to send and receive messages, and the processor is used to read the computer program to execute the method for extracting text elements from a scanned document as described in the first aspect of the embodiment.

[0065] For specific examples, the memory may include but is not limited to random access memory (RAM), read-only memory (ROM), flash memory, first-in-first-out memory (FIFO) and / or first-in-last-out memory (FILO), etc.; the processor may be but is not limited to a microprocessor of the STM32F105 series, an ARM (Advanced RISC-Machines), an X86 or other architecture processor, or a processor with an integrated NPU (neural-network processing units); the transceiver may be but is not limited to a WiFi (Wireless Fidelity) wireless transceiver, a Bluetooth wireless transceiver, a General Packet Radio Service (GPRS) wireless transceiver, a ZigBee protocol (a low-power local area network protocol based on the IEEE802.15.4 standard, ZigBee) wireless transceiver, a 3G transceiver, a 4G transceiver and / or a 5G transceiver, etc.

[0066] The fourth aspect of this embodiment provides a computer-readable storage medium storing instructions for the method for extracting text elements from a scanned document as described in the first aspect of the embodiment, that is, the computer-readable storage medium stores instructions, and when the instructions are run on a computer, the method for extracting text elements from a scanned document as described in the first aspect is executed. The computer-readable storage medium refers to a carrier for storing data, which may include but is not limited to a floppy disk, an optical disk, a hard disk, a flash memory, a USB flash drive, and / or a memory stick, etc., and the computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices.

[0067] The fifth aspect of this embodiment provides a computer program product comprising instructions, which, when executed on a computer, causes the computer to execute the method for extracting text elements from a scanned document as described in the first aspect of the embodiment, wherein the computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device.

[0068] It should be understood that certain details are provided in the following description to facilitate a complete understanding of the example embodiments. However, it should be understood by those of ordinary skill in the art that the example embodiments can be implemented without these certain details. For example, the system can be shown in a block diagram to avoid obscuring the example with unnecessary details. In other examples, well-known processes, structures, and techniques may not be shown in unnecessary detail to avoid obscuring the example embodiments.

[0069] Finally, it should be noted that the above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for extracting text elements from a scanned document, characterized in that: include: Recognize the first text content in the scanned document to be extracted by using an optical character recognition model; splicing the first text content based on the text format of the first text content in the scanned document to be extracted, wherein the text format is a text paragraph or a table; Inputting the spliced ​​first text content into a pre-trained element extraction model, and outputting at least one text element in the first text content and the position of each text element; The element extraction model includes a T5 model and a pointer network layer, the pointer network layer is connected to the last output layer of the T5 model, the last output layer of the T5 model is used to output at least one text element in the first text content, and the pointer network layer is used to take the at least one text element as input and output the position of each text element in the first text content; The step of splicing the first text content includes: If the text format is a text paragraph, two adjacent lines of text content in the first text content are spliced ​​together using a first splicing symbol; If the text format is a table, two adjacent columns of text content in the first text content are spliced ​​using the second splicing symbol in a sequence from left to right and from top to bottom, and two adjacent rows of text content in the first text content are spliced ​​using the first splicing symbol.

2. The method for extracting text elements from a scanned document according to claim 1, characterized in that: The method further comprises: Recognize the second text content in the sample scan by using the optical character recognition model; splicing the second text content based on the text format of the second text content in the sample scanned copy; The second text content after the annotated text elements and the spliced ​​text elements is used as the input of the element extraction model for training to obtain a trained element extraction model.

3. The method for extracting text elements from a scanned document according to claim 2, characterized in that: The loss function of the factor extraction model is Where D T ask represents the training sample, s represents the prompt word of the text element, x represents the second text content after the annotated text element, y represents the content of the element to be extracted, θ e represents the encoding parameter in the feature extraction model, θ d Represents the decoding parameters in the feature extraction model.

4. The method for extracting text elements from a scanned document according to claim 1, characterized in that: The file format of the scanned document to be extracted is JPG or PDF.

5. A device for extracting text elements from a scanned document, characterized in that: include: A recognition unit, used to recognize the first text content in the scanned document to be extracted by using an optical character recognition model; A splicing unit, configured to splice the first text content based on a text format of the first text content in the scanned document to be extracted, wherein the text format is a text paragraph or a table; A computing unit, used for inputting the concatenated first text content into a pre-trained element extraction model, and outputting at least one text element in the first text content and the position of each text element; The element extraction model includes a T5 model and a pointer network layer, the pointer network layer is connected to the last output layer of the T5 model, the last output layer of the T5 model is used to output at least one text element in the first text content, and the pointer network layer is used to take the at least one text element as input and output the position of each text element in the first text content; When the splicing unit is used to splice the first text content, it is specifically used to: If the text format is a text paragraph, two adjacent lines of text content in the first text content are spliced ​​together using a first splicing symbol; If the text format is a table, two adjacent columns of text content in the first text content are spliced ​​using the second splicing symbol in a sequence from left to right and from top to bottom, and two adjacent rows of text content in the first text content are spliced ​​using the first splicing symbol.

6. A device for extracting text elements from a scanned document, characterized in that: It comprises a memory, a processor and a transceiver which are communicatively connected in sequence, wherein the memory is used to store a computer program, the transceiver is used to send and receive messages, and the processor is used to read the computer program to execute the method for extracting text elements from a scanned document as described in any one of claims 1 to 4.

7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, and when the instructions are executed on a computer, the method for extracting text elements from a scanned document as claimed in any one of claims 1 to 4 is executed.