A method and system for extracting table information in PDF
By using an encoder-decoder structure and a self-attention mechanism to create a table recognition model, combined with YOLOv5 and CTPN algorithms, the problem of time-consuming and labor-intensive table information extraction from PDFs is solved, achieving efficient and accurate table information extraction, especially efficient recognition in complex scenarios.
Patent Information
- Application Number
- CN202210342716.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-31
- Publication Date
- 2025-10-28
- Estimated Expiration
- 2042-03-31
AI Technical Summary
Extracting table information from PDFs using existing technologies requires significant manpower and time, and the accuracy and coverage of existing methods are insufficient in complex scenarios.
A table structure recognition model with an encoder-decoder structure, combined with self-attention mechanism and multi-instance learning, is used to recognize table structure and text content in PDF files through YOLOv5 and CTPN algorithms, generating table extraction results in HTML code format.
It achieves efficient and accurate identification and extraction of table information from PDFs, with better efficiency and accuracy, especially in complex scenarios, reducing manpower and time costs.
Smart Images

Figure CN114821613B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of deep learning technology, and in particular to a method and system for extracting table information from PDFs. Background Technology
[0002] The processing and application of table data in PDFs is widely needed in many practical production scenarios. In recent years, with the rapid development of algorithms for computer vision tasks based on artificial intelligence, using AI technology to extract table information from PDFs is a very valuable and meaningful direction.
[0003] In actual production, we often need to systematically analyze and organize the table data in PDFs. Usually, a PDF file contains multiple tables. If this is done manually, it will consume a lot of manpower and time, and it is an extremely tedious and boring task. Therefore, using technical means to extract PDF table information in an automated or semi-automated manner has become an important research topic. How to provide an efficient and accurate method and system for extracting table information from PDFs has become a technical problem that the industry urgently needs to solve. Summary of the Invention
[0004] This invention provides a method and system for extracting table information from PDFs, which addresses the shortcomings of existing technologies that require high manpower and time costs for extracting table information from PDFs, and achieves more efficient and accurate extraction of table information from PDFs.
[0005] This invention provides a method for extracting table information from a PDF, comprising:
[0006] Obtain a PDF file and identify image pages in the PDF file that include tables;
[0007] The image page is segmented to obtain multiple table units, and a table structure recognition model is run with the table units as input to obtain a target sequence; the target sequence is an HTML sequence based on a table structure framework.
[0008] The text recognition results of the table cells are integrated into the target sequence to obtain the table extraction results in HTML code form;
[0009] The table structure recognition model is a model obtained through sample training.
[0010] According to the present invention, a method for extracting table information from a PDF is provided, wherein the table structure recognition model is an encoder-decoder structure model;
[0011] The encoder can extract the local features, global features, and related features of the table cells, and encode them to obtain the feature extraction results;
[0012] The decoder can obtain a table structure framework based on the feature extraction results.
[0013] According to the present invention, a method for extracting table information from a PDF is provided, wherein the table structure recognition model is a model based on a self-attention mechanism;
[0014] The encoder can extract local features, global features, correlation features, and element sequence features of source sequence elements; the source sequence includes the ordered plurality of table cells; the source sequence element refers to the table cell, or a character or string obtained by splitting the table cell;
[0015] The decoder is capable of:
[0016] The first element feature of the target sequence is obtained based on the local features, global features, correlation features, and element sequence features of the source sequence elements;
[0017] Based on the local features, global features, correlation features, and element sequence features of the source sequence elements, and the 1st to (i-1th)th element features of the target sequence, the i-th element feature of the target sequence is obtained.
[0018] The elements of the target sequence are obtained based on the element characteristics of the target sequence;
[0019] The target sequence element is an HTML character or string.
[0020] According to a method for extracting table information from a PDF provided by the present invention, the steps of obtaining a PDF file and identifying image pages containing tables in the PDF file include:
[0021] Get PDF files;
[0022] Based on preset table recognition rules and / or preset PDF recognition models, identify image pages in the PDF file that include tables;
[0023] The PDF recognition model is trained using samples and labels, with PDF files as input and image pages containing tables in the PDF files as output. It is based on the YOLOv5 algorithm.
[0024] According to a method for extracting table information from a PDF provided by the present invention, the step of integrating the text recognition results of the table cells into the target sequence to obtain the table extraction result in HTML code format includes:
[0025] The text recognition model is run based on the table cell to obtain the text recognition result of the table cell;
[0026] The table structure is determined based on the target sequence, and the text recognition result is filled into the table structure to obtain the table extraction result in HTML code form.
[0027] The text recognition model is a model based on the CTPN algorithm that takes the table cells in image format as input and the text recognition results of the table cells as output, and is trained using samples and labels.
[0028] According to a method for extracting table information from a PDF provided by the present invention, the steps of determining the table structure based on the target sequence and filling the table structure with the text recognition result to obtain the table extraction result in HTML code form include:
[0029] At least one table structure is determined based on the target sequence; the number of table structures is the same as the number of tables included in the PDF file;
[0030] The mapping relationship between the text in the text recognition result and the table structure is determined, and the text is filled into the table structure according to the mapping relationship to obtain the table extraction result in HTML code form; the number of the table extraction results in HTML code form is the same as the number of the table structures.
[0031] This invention also provides a system for extracting table information from a PDF, comprising:
[0032] The acquisition module is used to acquire PDF files and identify image pages in the PDF files that include tables;
[0033] The segmentation module is used to segment the image page into multiple table units, and run a table structure recognition model with the table units as input to obtain a target sequence; the target sequence is an HTML sequence based on a table structure framework.
[0034] The extraction module is used to integrate the text recognition results of the table cells into the target sequence to obtain the table extraction result in HTML code form;
[0035] The table structure recognition model is a model obtained through sample training.
[0036] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of any of the above-described methods for extracting table information from a PDF.
[0037] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method for extracting table information from a PDF as described above.
[0038] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of any of the above-described methods for extracting table information from a PDF.
[0039] The method and system for extracting table information from PDFs provided by this invention recognize the table structure frame by using table units obtained from image segmentation, that is, by using a model trained by multi-instance learning for table structure frame recognition. This can more effectively and accurately identify and extract table information from PDFs. At the same time, the output format of the table structure frame based on HTML sequence is more in line with the model trained by multi-instance learning, and has better efficiency and accuracy for table information extraction tasks, especially table information extraction tasks in complex scenarios. Attached Figure Description
[0040] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0041] Figure 1 This is a flowchart illustrating the method for extracting table information from PDF provided by the present invention.
[0042] Figure 2 This is a schematic diagram of the table extraction architecture provided in an embodiment of the present invention;
[0043] Figure 3 This is a schematic diagram of the table information extraction process provided in an embodiment of the present invention;
[0044] Figure 4 This is a schematic diagram of the table to be extracted in the PDF provided in the embodiments of the present invention;
[0045] Figure 5 This is a schematic diagram of an HTML file containing the table extraction results provided in an embodiment of the present invention;
[0046] Figure 6 This is a schematic diagram of the structure of the electronic device provided by the present invention;
[0047] Figure 7 This is a schematic diagram of the structure of the PDF table information extraction device provided in the embodiment of the present invention;
[0048] Figure 8 This is a flowchart illustrating the implementation of LX-TableOCR provided in this embodiment of the invention.
[0049] Figure label:
[0050] 610: Processor;
[0051] 620: Communication interface;
[0052] 630: Memory;
[0053] 640: Communication bus;
[0054] 701: Get module;
[0055] 702: Segmentation module;
[0056] 703: Extraction module. Detailed Implementation
[0057] To make the objectives, technical solutions, and advantages of the present invention more clear, the technical solutions of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the embodiments described are only some of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.
[0058] The following is combined with Figures 1-5 This invention describes a method for extracting table information from PDFs.
[0059] like Figure 1 As shown, this embodiment of the invention provides a method for extracting table information from a PDF, including:
[0060] Step 102: Obtain the PDF file and identify the image pages in the PDF file that include tables;
[0061] Step 104: Segment the image page to obtain multiple table units, and run the table structure recognition model with the table units as input to obtain the target sequence; the target sequence is an HTML sequence based on a table structure framework;
[0062] Step 106: Integrate the text recognition results of the table units into the target sequence to obtain the table extraction results in HTML code form;
[0063] The table structure recognition model is a model obtained through sample training.
[0064] In a preferred embodiment, the table unit is segmented based on the table structure; for a table with all borders, the table unit can be obtained by segmenting based on horizontal and vertical borders (and in some cases, diagonal borders); for a table that contains only horizontal borders, only vertical borders, or no borders, the table unit can be obtained by segmenting based on character clustering.
[0065] In another preferred embodiment, the table cells are randomly divided or divided into cells of a set size.
[0066] In this embodiment, the input of the table structure recognition model is a table cell in image format, and the output is HTML file code.
[0067] The beneficial effects of this embodiment are as follows:
[0068] By recognizing table structure frames based on table units obtained from image segmentation, i.e., by using a model trained through multi-instance learning, table structure frames can be recognized more effectively and accurately. At the same time, the output format of table structure frames based on HTML sequences is more compatible with the model trained through multi-instance learning, resulting in better efficiency and accuracy for table information extraction tasks, especially for table information extraction tasks in complex scenarios.
[0069] According to the above embodiments, in this embodiment:
[0070] The table structure recognition model is an encoder-decoder structure model;
[0071] The encoder can extract the local features, global features, and related features of the table cells, and encode them to obtain the feature extraction results;
[0072] The decoder can obtain a table structure framework based on the feature extraction results.
[0073] The table structure recognition model is based on a self-attention mechanism.
[0074] The encoder can extract local features, global features, correlation features, and element sequence features of source sequence elements; the source sequence includes the ordered plurality of table cells; the source sequence element refers to the table cell, or a character or string obtained by splitting the table cell;
[0075] The decoder is capable of:
[0076] The first element feature of the target sequence is obtained based on the local features, global features, correlation features, and element sequence features of the source sequence elements;
[0077] Based on the local features, global features, association features, and element sequence features of the source sequence elements, and the 1st to (i-1th)th element features of the target sequence, the i-th element feature of the target sequence is obtained.
[0078] The elements of the target sequence are obtained based on the element characteristics of the target sequence;
[0079] The target sequence element is an HTML character or string.
[0080] In this embodiment, the training process of the table recognition model with the encoder-decoder structure is as follows:
[0081] Combining the principle of multiple instance learning, each image is split into multiple image patches and combined into a set of multiple instance packets. Then, each instance in the multiple instance packet is further split into embedding sequences, forming tokens similar to those in NLP (Natural Language Understanding). These tokens are encoded using a Transformer, and the instances are also encoded using an outer Transformer. The mapping is based on the different combinations of local and global focus, and the information reflected by each instance is spatially summed. At the same time, a distillation token is added to the outer sequence of each instance, so that the newly added distillation token interacts with the original token through a self-attention layer and learns through backpropagation, resulting in an efficient training process.
[0082] In other words, the table recognition model in this embodiment is a self-attention mechanism model based on natural language understanding, and in addition to the table units, the table recognition model also includes distilled tokens for interactively learning the sequence features of the table units.
[0083] The beneficial effects of this embodiment are as follows:
[0084] By using a self-attention mechanism model based on natural language understanding to identify the table structure, the table structure can be constructed through the semantic relationships of table characters without the aid of table borders. This results in higher efficiency and accuracy in recognizing borderless tables (or similar non-full-bordered tables) and complex table structures.
[0085] According to any of the above embodiments, in this embodiment:
[0086] The steps of obtaining a PDF file and identifying the image pages of tables included in the PDF file include:
[0087] Get PDF files;
[0088] Based on preset table recognition rules and / or preset PDF recognition models, identify image pages in the PDF file that include tables;
[0089] The PDF recognition model is trained using samples and labels, with PDF files as input and image pages containing tables in the PDF files as output. It is based on the YOLOv5 algorithm.
[0090] The step of integrating the text recognition results of the table cells into the target sequence to obtain the table extraction results in HTML code form includes:
[0091] The text recognition model is run based on the table cell to obtain the text recognition result of the table cell;
[0092] The table structure is determined based on the target sequence, and the text recognition result is filled into the table structure to obtain the table extraction result in HTML code form.
[0093] The text recognition model is a model based on the CTPN algorithm that takes the table cells in image format as input and the text recognition results of the table cells as output, and is trained using samples and labels.
[0094] The step of determining the table structure based on the target sequence and filling the table structure with the text recognition result to obtain the table extraction result in HTML code format includes:
[0095] At least one table structure is determined based on the target sequence; the number of table structures is the same as the number of tables included in the PDF file;
[0096] The mapping relationship between the text in the text recognition result and the table structure is determined, and the text is filled into the table structure according to the mapping relationship to obtain the table extraction result in HTML code form; the number of the table extraction results in HTML code form is the same as the number of the table structures.
[0097] The beneficial effects of this embodiment are as follows:
[0098] This embodiment identifies tables in PDFs by pre-setting rules. If the rule is successfully identified, the image page containing the table in the PDF file is directly output (in this case, the output efficiency of the image page is higher); if the rule is not identified, the image page containing the table in the PDF file is output through the PDF recognition model based on YOLOv5 (in this case, it is more applicable to input PDFs).
[0099] Furthermore, this embodiment uses a text recognition model based on the CTPN algorithm for text recognition. In some implementations, other text recognition algorithms can be used to achieve similar results.
[0100] Based on the above embodiments, a more complete embodiment will be provided below from the perspective of process implementation.
[0101] This embodiment proposes improvements to address the following shortcomings of the prior art:
[0102] Extracting table information from PDFs is a popular research topic. Based on previous research on technical solutions, they can be roughly divided into two categories: one is to use programming languages such as Python and Java to extract table information from PDFs according to rules, and then use built-in packages of the language to extract the content. This method has high requirements for the type of PDF and table information, and also results in low extraction coverage and poor universality. The other method is to use OCR recognition technology to recognize the table information in PDF images. Although this method solves the problem of low coverage, the recognition accuracy of table information and the recognition of table structure information still need to be improved.
[0103] The purpose of this embodiment is to provide a method for extracting table information from PDFs, which relates to the technical field of PDF table parsing.
[0104] In summary, the implementation scheme of this embodiment is as follows: First, the target detection algorithm YOLOv5 is used to identify each page of the PDF image containing a table in the PDF file. Then, the table structure is trained and recognized by the self-developed image recognition algorithm LX-TableOCR. This algorithm structures the table structure into HTML tags. Then, the CTPN text recognition algorithm is used to identify and extract the text content. Finally, the text content and the structured HTML of the table are integrated to output HTML code that fully expresses the table information.
[0105] Reference Figure 2 The solution of this embodiment will be described in detail below.
[0106] 1. Construct a PDF file table recognition dataset.
[0107] We constructed a PDF file table recognition dataset by annotating the tables in 5000 PDFs.
[0108] 2. Construct the HTML dataset corresponding to the table information.
[0109] This embodiment annotates 3000 medical PDF documents, converts the tables in the relevant PDF documents into HTML, and combines them with the PubTabNet public dataset to construct training data for table structure recognition and table content recognition.
[0110] 3. Setup of each functional module.
[0111] Reference Figure 3 :
[0112] 1) Table Page Splitting Module: By viewing PDF files, certain textual information that can be used to distinguish tables is found. Combined with programming language, rules for splitting table pages in PDF files are formulated. For those that cannot be solved by the rules, the YOLOv5 model is trained on the above dataset for algorithmic recognition.
[0113] 2) Table Structure Recognition Module: In the table structure recognition module, we use our self-developed image recognition algorithm LX-TableOCR to train and fine-tune the table structure to obtain the table structure recognition model. The general principle is as follows: Combining the multi-instance learning principle, each image is split into multiple image blocks and combined into a set of multi-instance packets. Then, each instance in the multi-instance packet is further split and formed into an embedding sequence, forming tokens similar to those in NLP. These tokens are encoded using a Transformer. At the same time, each instance is also encoded using an outer Transformer. The mapping is based on the different combinations of local and global efforts, and the information reflected by each instance is spatially summed. Meanwhile, a distillation token is added to the outer sequence of each instance, so that the newly added distillation token interacts with the original token through a self-attention layer and learns through backpropagation, thus efficiently training the model.
[0114] 3) Text content recognition module: In text content recognition, we used the classic text recognition algorithm CTPN for text content detection.
[0115] 4) Result Integration Module: Finally, we integrate the HTML framework representing the table structure generated by the table structure model with the corresponding text content detected by the text content to form the HTML code representing the table information. Based on the number of tables input in the split PDF table pages, we output the corresponding number of HTML files.
[0116] 4. Validation of table parsing results
[0117] We used some PDF table images that were not included in the training and validation sets for testing, and the results are shown below: Figure 4 This refers to a PDF table. Figure 5 This refers to the generated HTML file code representing the table.
[0118] The key points of this embodiment are as follows:
[0119] 1. By converting PDF table image data into HTML code format, it is easier to extract table image information in complex scenarios;
[0120] 2. The PDF table information extraction method provided in this embodiment adopts a fusion approach of multiple algorithms in the field of AI computer vision, and achieves PDF table information extraction through the collaboration of multiple modules;
[0121] 3. The Transformer structure is combined with multi-instance learning and applied to PDF table image detection. By using a two-layer Transformer, the image processing is more accurate and efficient.
[0122] The beneficial effects of this embodiment are as follows:
[0123] This embodiment trains a method to generate HTML code corresponding to rows and columns of PDF table information by constructing a dataset with corresponding table structures and HTML, and then parses the table content based on HTML tag information. This method can accurately extract corresponding information such as table structure and table content from PDF table information, enabling the table information in PDFs to be more accurately applied to downstream tasks.
[0124] Furthermore, such as Figure 8 As shown, in a preferred embodiment, the use of LX-TableOCR includes:
[0125] First, using rules and YOLOv5, the table pages in the entire PDF file are identified. Then, the table page images are used as input for LX-TableOCR. Combined with the multi-instance learning method, a composite PDF table screenshot and its corresponding HTML structure code (without content) are obtained. Then, both are used as input for the CTPN algorithm to extract content. Finally, the HTML structure and content information are integrated and filled into the HTML to obtain the final HTML file.
[0126] The apparatus for extracting table information from PDF provided by the present invention is described below. The apparatus for extracting table information from PDF described below can be referred to in correspondence with the method for extracting table information from PDF described above.
[0127] like Figure 7 As shown, this embodiment of the invention provides a system for extracting table information from a PDF, including:
[0128] The acquisition module 701 is used to acquire a PDF file and identify image pages in the PDF file that include tables;
[0129] The segmentation module 702 is used to segment the image page to obtain multiple table units, and run a table structure recognition model with the table units as input to obtain a target sequence; the target sequence is an HTML sequence based on a table structure framework.
[0130] Extraction module 703 is used to integrate the text recognition results of the table cells into the target sequence to obtain the table extraction result in HTML code form;
[0131] The table structure recognition model is a model obtained through sample training.
[0132] Further, the acquisition module 701 includes:
[0133] The acquisition unit is used to acquire PDF files;
[0134] The recognition unit is used to recognize image pages containing tables in the PDF file according to preset table recognition rules and / or preset PDF recognition models;
[0135] The PDF recognition model is trained using samples and labels, with PDF files as input and image pages containing tables in the PDF files as output. It is based on the YOLOv5 algorithm.
[0136] The extraction module 703 includes:
[0137] A text unit is used to run a text recognition model based on the table unit to obtain the text recognition result of the table unit;
[0138] A filling unit is used to determine the table structure based on the target sequence and fill the table structure with the text recognition result to obtain the table extraction result in HTML code form;
[0139] The text recognition model is a model based on the CTPN algorithm that takes the table cells in image format as input and the text recognition results of the table cells as output, and is trained using samples and labels.
[0140] Furthermore, the filling unit includes:
[0141] A table structure subunit is used to determine at least one table structure based on the target sequence; the number of table structures is the same as the number of tables included in the PDF file;
[0142] The mapping and filling subunit is used to determine the mapping relationship between the text in the text recognition result and the table structure, and to fill the text into the table structure according to the mapping relationship to obtain the table extraction result in HTML code form; the number of the table extraction results in HTML code form is the same as the number of the table structures.
[0143] The beneficial effects of this embodiment are as follows:
[0144] By recognizing table structure frames based on table units obtained from image segmentation, i.e., by using a model trained through multi-instance learning, table structure frames can be recognized more effectively and accurately. At the same time, the output format of table structure frames based on HTML sequences is more compatible with the model trained through multi-instance learning, resulting in better efficiency and accuracy for table information extraction tasks, especially for table information extraction tasks in complex scenarios.
[0145] Figure 6 An example of a physical structure diagram of an electronic device is shown below. Figure 6 As shown, the electronic device may include a processor 610, a communications interface 620, a memory 630, and a communication bus 640, wherein the processor 610, communications interface 620, and memory 630 communicate with each other via the communication bus 640. The processor 610 can call logical instructions in the memory 630 to execute a method for extracting table information from a PDF. This method includes: acquiring a PDF file and identifying image pages in the PDF file that contain tables; segmenting the image pages to obtain multiple table units, and running a table structure recognition model with the table units as input to obtain a target sequence; the target sequence is an HTML sequence based on a table structure framework; integrating the text recognition results of the table units into the target sequence to obtain a table extraction result in HTML code form; the table structure recognition model is a model obtained through sample training.
[0146] Furthermore, the logical instructions in the aforementioned memory 630 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, essentially, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0147] On the other hand, the present invention also provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can perform the method for extracting table information from a PDF provided by the above methods. The method includes: acquiring a PDF file and identifying image pages in the PDF file that include tables; segmenting the image pages to obtain multiple table units, and running a table structure recognition model with the table units as input to obtain a target sequence; the target sequence is an HTML sequence based on a table structure framework; integrating the text recognition results of the table units into the target sequence to obtain a table extraction result in HTML code form; the table structure recognition model is a model obtained through sample training.
[0148] In another aspect, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon. When executed by a processor, the computer program implements a method for extracting table information from a PDF provided by the methods described above. The method includes: acquiring a PDF file and identifying image pages in the PDF file that include tables; segmenting the image pages to obtain multiple table units, and running a table structure recognition model with the table units as input to obtain a target sequence; the target sequence is an HTML sequence based on a table structure framework; integrating the text recognition results of the table units into the target sequence to obtain a table extraction result in HTML code form; the table structure recognition model is a model obtained through sample training.
[0149] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0150] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0151] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for extracting table information from a PDF, characterized in that, include: Obtain a PDF file and identify image pages in the PDF file that include tables; The image page is segmented to obtain multiple table units, and a table structure recognition model is run with the table units as input to obtain a target sequence; the target sequence is an HTML sequence based on a table structure framework. The text recognition results of the table cells are integrated into the target sequence to obtain the table extraction results in HTML code form; The table structure recognition model is a model obtained through sample training. The table unit is segmented based on the table structure; the segmentation methods for the table unit include: segmenting the table unit based on horizontal and vertical borders; or segmenting the table unit based on character clustering. The table structure recognition model takes as input table cells in image format and outputs as HTML file code as the HTML sequence; the table structure recognition model is an encoder-decoder structure model. The encoder can extract the local features, global features, and related features of the table cells, and encode them to obtain the feature extraction results; The decoder can obtain a table structure framework based on the feature extraction results; The training process of the table structure recognition model of the encoder-decoder structure includes: By combining the principle of multi-instance learning, each image page is split into multiple image blocks and combined into a set of multi-instance packages; Each example in the multi-example package is further split and formed into an embedding sequence to obtain tokens for natural language understanding; The embedding sequence is encoded using a Transformer to obtain a local composite map. An outer Transformer is used to encode between instances to obtain a global composite map. The local and global composite maps are summed in space. A distillation token is added to the outer sequence of each instance. The interaction between distilled tokens and tokens in natural language understanding is studied in the self-attention layer through a self-attention mechanism; the model is trained through backpropagation.
2. The method for extracting table information from a PDF according to claim 1, characterized in that, The table structure recognition model is based on a self-attention mechanism. The encoder can extract local features, global features, correlation features, and element sequence features of source sequence elements; the source sequence includes the ordered plurality of table cells; the source sequence element refers to the table cell, or a character or string obtained by splitting the table cell; The decoder is capable of: The first element feature of the target sequence is obtained based on the local features, global features, correlation features, and element sequence features of the source sequence elements; Based on the local features, global features, correlation features, and element sequence features of the source sequence elements, and the 1st to (i-1th)th element features of the target sequence, the i-th element feature of the target sequence is obtained. The elements of the target sequence are obtained based on the element characteristics of the target sequence; The target sequence element is an HTML character or string.
3. The method for extracting table information from a PDF according to claim 1, characterized in that, The steps of obtaining a PDF file and identifying the image pages of tables included in the PDF file include: Get PDF files; Based on preset table recognition rules and / or preset PDF recognition models, identify image pages in the PDF file that include tables; The PDF recognition model is trained using samples and labels, with PDF files as input and image pages containing tables in the PDF files as output. It is based on the YOLOv5 algorithm.
4. The method for extracting table information from a PDF according to claim 1, characterized in that, The step of integrating the text recognition results of the table cells into the target sequence to obtain the table extraction results in HTML code form includes: The text recognition model is run based on the table cell to obtain the text recognition result of the table cell; The table structure is determined based on the target sequence, and the text recognition result is filled into the table structure to obtain the table extraction result in HTML code form. The text recognition model is a model based on the CTPN algorithm that takes the table cells in image format as input and the text recognition results of the table cells as output, and is trained using samples and labels.
5. The method for extracting table information from a PDF according to claim 4, characterized in that, The step of determining the table structure based on the target sequence and filling the table structure with the text recognition result to obtain the table extraction result in HTML code format includes: At least one table structure is determined based on the target sequence; the number of table structures is the same as the number of tables included in the PDF file; The mapping relationship between the text in the text recognition result and the table structure is determined, and the text is filled into the table structure according to the mapping relationship to obtain the table extraction result in HTML code form; the number of the table extraction results in HTML code form is the same as the number of the table structures.
6. A system for extracting table information from a PDF, characterized in that, include: The acquisition module is used to acquire PDF files and identify image pages in the PDF files that include tables; The segmentation module is used to segment the image page into multiple table units, and run a table structure recognition model with the table units as input to obtain a target sequence; the target sequence is an HTML sequence based on a table structure framework. The extraction module is used to integrate the text recognition results of the table cells into the target sequence to obtain the table extraction result in HTML code form; The table structure recognition model is a model obtained through sample training. The table unit is segmented based on the table structure; the segmentation methods for the table unit include: segmenting the table unit based on horizontal and vertical borders; or segmenting the table unit based on character clustering. The table structure recognition model takes as input table cells in image format and outputs as HTML file code as HTML sequence. The table structure recognition model is an encoder-decoder structure model; The encoder can extract the local features, global features, and related features of the table cells, and encode them to obtain the feature extraction results; The decoder can obtain a table structure framework based on the feature extraction results; The training process of the table structure recognition model of the encoder-decoder structure includes: By combining the principle of multi-instance learning, each image page is split into multiple image blocks and combined into a set of multi-instance packages; Each example in the multi-example package is further split and formed into an embedding sequence, resulting in tokens similar to those in NLP. The embedding sequence is encoded using a Transformer to obtain a local composite map. An outer Transformer is used to encode between instances to obtain a global composite map. The local and global composite maps are then summed spatially. A distillation token is added to the outer sequence of each example, allowing the distillation token to interact with tokens similar to those in NLP through a self-attention layer; the model is trained using backpropagation.
7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the method for extracting table information from a PDF as described in any one of claims 1 to 5.
8. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method for extracting table information from a PDF as described in any one of claims 1 to 5.
9. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method for extracting table information from a PDF as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Table identification method and device, terminal and storage medium
CN113505762A