PDF text extraction method and system based on large language model

By employing a PDF text extraction method based on a large language model and utilizing PyMuPDF and a multi-level text logic reconstruction strategy, the problem of distinguishing between images and text in PDF documents is solved, achieving high-quality text extraction and structured output. This method is suitable for cleaning and preprocessing complex document structures.

CN120599643BActive Publication Date: 2025-10-17NANJING WEISHIDE SOFTWARE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511115421.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-08-11
Publication Date
2025-10-17
Estimated Expiration
2045-08-11

AI Technical Summary

Technical Problem

Existing PDF document parsing technologies struggle to effectively distinguish between images and main text, leading to garbled text parsing and failing to meet the requirements of large language models for high-quality corpus input. Furthermore, they lack structured information such as heading hierarchy, paragraph division, and image-text alignment.

Method used

A PDF text extraction method based on a large language model is adopted. PyMuPDF is used to parse PDF documents, identify image regions and text regions, remove noise interference features, formulate a multi-level text logic reconstruction strategy, and combine the large language model to correct semantic structure. Finally, the output is in a structured format.

Benefits of technology

It significantly improves the accuracy and purity of text extraction, restores the logical order and semantic integrity of documents, and provides a high-quality data foundation for subsequent knowledge extraction and intelligent question answering.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120599643B_ABST
    Figure CN120599643B_ABST
Patent Text Reader

Abstract

The present application relates to the field of document processing and data extraction, and specifically discloses a PDF text extraction method and system based on a large language model, wherein the present application locates and marks the contents of each page of a target PDF document to obtain a first to-be-recognized region and a second to-be-recognized region, and eliminates the noise interference features of the to-be-recognized regions; a multi-level text logical reconstruction strategy is formulated to complete the reconstruction of the logical order of the target PDF document, to preliminarily output a first-level PDF document, and to perform a first degree of correlation analysis of images and texts to output a first correlation strength; through a large language model, intelligent abnormality recognition on the semantic structure of the content of the first-level PDF document is performed, and a second-level PDF document is obtained by correction, and a second correlation strength is output; whether the second-level PDF document is qualified is judged based on the first correlation strength and the second correlation strength; the present application is helpful to restore the logical order and semantic integrity of the document, and to improve the text purity and structural integrity.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of document processing and data extraction, and more particularly, to a PDF text extraction method and system based on a large language model. BACKGROUND

[0002] With the wide application of large language models (such as ChatGPT, DeepSeek, etc.) in the field of natural language processing, they have shown great capabilities in tasks such as document understanding, automatic question answering, and summary generation. However, in practical applications, PDF documents, as one of the most common information carriers, have a complex layout of mixed text and images, which poses significant challenges to the accurate understanding and reasoning of large language models, especially for PDF documents containing a large number of mixed text and images. Such documents are not written continuously in natural paragraphs, but use multi-column and multi-layer layouts, making it difficult for purely linear text extraction tools to restore the original semantics and layout order.

[0003] Currently, when large language models process PDF files containing mixed text and images, the embedded images in the PDF often cause text parsing errors, affecting the accuracy of question answering. Traditional PDF parsing techniques such as direct OCR or pure text extraction cannot effectively distinguish between images and body text, often disrupting the original reading order, resulting in chaotic order of extracted text, and cannot meet the requirements of large models for high-quality corpus input. At the same time, the extraction results lack structured information such as title hierarchy, paragraph division, and image-text alignment, which cannot provide complete context support for large language models.

[0004] Therefore, it is necessary to provide a PDF text extraction method and system based on a large language model to solve the above technical problems. In order to solve the above problems, a technical solution is provided. SUMMARY

[0005] In order to overcome the above-mentioned defects of the prior art, the present application provides a PDF text extraction method and system based on a large language model, which is used to solve the problem that the text extracted by the existing PDF parsing technology has chaotic order and cannot meet the requirements of large models for high-quality corpus input.

[0006] To achieve the above-mentioned purposes, the present application provides the following technical solutions:

[0007] A PDF text extraction method based on a large language model, comprising the following steps:

[0008] Obtain a target PDF document, parse the content of each page of the target PDF document using PyMuPDF, identify and locate image regions and text regions, and obtain first and second regions to be identified;

[0009] The noise interference features of the first to-be-identified region and the second to-be-identified region are identified based on a multi-dimensional identification strategy, the noise interference features are eliminated to obtain a first to-be-processed region and a second to-be-processed region, and spatial position information of the first to-be-processed region and the second to-be-processed region is updated;

[0010] According to the spatial positioning information of the first to-be-processed region and the second to-be-processed region, a multi-level text logical reconstruction strategy is formulated to complete reconstruction of the logical order of the target PDF document, and a primary PDF document is initially output. The first association strength is output by performing a graphic-text correlation degree analysis on the primary PDF document.

[0011] The intelligent abnormality identification and correction of the semantic structure of the content of each page of the primary PDF document are performed by a large language model to obtain a secondary PDF document. The second association strength is output by performing a second graphic-text correlation degree analysis on the secondary PDF document.

[0012] A document reconstruction detection evaluation value is generated based on the first association strength and the second association strength. Whether the secondary PDF document is qualified is determined according to the document reconstruction detection evaluation value. The qualified secondary PDF document is output in a structured format.

[0013] As a further scheme of the present application, the content of each page of the target PDF document is parsed by PyMuPDF, the image region and the text region are identified and positioned and marked to obtain the first to-be-identified region and the second to-be-identified region. The specific process is as follows:

[0014] The content of each page of the target PDF document is parsed by PyMuPDF, and multi-category object elements in the document page are extracted. The multi-category object elements include text blocks, images and drawing elements.

[0015] The multi-category object elements are marked by a rectangular frame to obtain element text boxes. The spatial position information of the element text boxes in the document page is recorded, including the coordinate position, the size and the page number.

[0016] The images and drawing elements in the element text boxes in each page are identified based on an OCR algorithm as initial text content of the image region. The initial text content is associated and marked with the spatial position information of the document page as the first to-be-identified region. The text blocks in the element text boxes are associated and marked with the spatial position information of the document page as the second to-be-identified region.

[0017] As a further scheme of the present application, the noise interference features of the first to-be-identified region and the second to-be-identified region are identified based on a multi-dimensional identification strategy. The multi-dimensional identification strategy includes a position identification strategy, a text identification strategy, a style identification strategy and a frequency identification strategy.

[0018] As a further scheme of the present application, the position recognition strategy is used to recognize specific elements with repeated edges of the positioned document page and judge as signal interference features; the text recognition strategy is used to match specific keywords by using regular expressions and judge as signal interference features; the style recognition strategy is used to recognize specific texts with abnormal font color transparency, inclination angle or font size and judge as signal interference features; and the frequency recognition strategy is used to recognize non-text information with repeated appearance in all document pages and judge as signal interference features.

[0019] As a further scheme of the present application, according to the spatial positioning information of the first to-be-processed region and the second to-be-processed region, a multi-level text logical reconstruction strategy is formulated to complete the reconstruction of the logical sequence of the target PDF document, and a primary PDF document is initially output, and a first correlation strength is output by performing a graphic-text correlation degree analysis on the primary PDF document, and the specific process is as follows:

[0020] The spatial positioning information of the first to-be-processed region and the second to-be-processed region is extracted, and the first to-be-processed region and the second to-be-processed region in the same document page are initially sorted according to the vertical position first and the horizontal position second in the document page;

[0021] A multi-level text logical reconstruction strategy is formulated to complete the reconstruction of the logical sequence of the target PDF document, wherein the multi-level text logical reconstruction strategy includes a paragraph attribution reconstruction strategy, a title level reconstruction strategy, a list structure reconstruction strategy and a graphic-text relationship reconstruction strategy;

[0022] The reconstructed target PDF document is sorted to output a primary PDF document, and a first correlation strength is output by performing a graphic-text correlation degree analysis on the primary PDF document.

[0023] As a further scheme of the present application, when the initial sorting is performed, the vertical position follows the order from top to bottom, and the horizontal position follows the order from left to right.

[0024] As a further scheme of the present application, a first correlation strength is output by performing a graphic-text correlation degree analysis on the primary PDF document, and the specific process is as follows:

[0025] The first to-be-processed region and the second to-be-processed region in the primary PDF document are extracted, a graphic-text correlation degree analysis model is constructed, a first graphic-text semantic correlation feature of the second to-be-processed region adjacent to the top of the first to-be-processed region in the vertical direction and a second graphic-text semantic correlation feature of the second to-be-processed region adjacent to the bottom of the first to-be-processed region are obtained; the first graphic-text semantic correlation feature includes a first keyword matching feature and a first semantic similarity matching feature; and the second graphic-text semantic correlation feature includes a second keyword matching feature and a second semantic similarity matching feature;

[0026] Then analyze the logical correlation of the text content between the two second areas to be processed that are vertically adjacent to the first area to be processed, and calculate the weighted result of the first image-text semantic correlation feature, the second image-text semantic correlation feature and the logical correlation as the first correlation strength.

[0027] As a further solution of the present invention, the paragraph attribution reconstruction strategy determines whether two text blocks belong to the same paragraph by analyzing the left starting position of the text blocks and the distance between the upper and lower lines in the vertically adjacent second area to be processed; if the two text blocks belong to the same paragraph, paragraph reconstruction is not required; otherwise, paragraph reconstruction is required;

[0028] The title level reconstruction strategy extracts the specific style information of each text block in the second to-be-processed area, combines it with the position to identify the title features, and divides the title features into first-level, second-level, and third-level titles;

[0029] The list structure reconstruction strategy identifies numbers and bullet points, analyzes the list hierarchy and nesting relationship to determine whether reconstruction is necessary;

[0030] The image-text relationship reconstruction strategy extracts images and drawing elements from the first area to be processed and forms separate paragraphs.

[0031] As a further solution of the present invention, a large language model is used to perform intelligent semantic structure anomaly recognition and correction on each page of the first-level PDF document to obtain a second-level PDF document. A second image-text correlation analysis is performed on the second-level PDF document to output a second correlation strength. The specific process is as follows:

[0032] Construct a PDF document training dataset containing various noise samples and manually annotate the signal interference features;

[0033] Fine-tune the pre-trained language model based on the PDF document training dataset, and enable it to distinguish noise through supervised learning or instruction fine-tuning. Input the original PDF document sequence with noise interference and output the reconstructed PDF document sequence.

[0034] By analyzing the first-level PDF document section by section, the signal interference features are automatically identified and eliminated. The pre-trained language model is used to remove residual noise, correct the text sequence, and restore the semantic coherence of the first-level PDF document to obtain the second-level PDF document.

[0035] As a further solution of the present invention, a document reconstruction detection evaluation value is generated based on the first correlation strength and the second correlation strength, and whether the secondary PDF document is qualified is determined according to the document reconstruction detection evaluation value. The specific process includes:

[0036] The difference between the first correlation strength and the second correlation strength is obtained as a document reconstruction detection evaluation value, and the document detection evaluation value is compared with a preset evaluation threshold value, if the document detection evaluation value is greater than or equal to the preset evaluation threshold value, the secondary PDF document is unqualified; if the document detection evaluation value is less than the preset evaluation threshold value, the secondary PDF document is qualified.

[0037] As a further scheme of the application, the secondary PDF document is output in a structured format, and the structured format includes JSON, XML, Markdown or plain text format.

[0038] A PDF text extraction system based on a large language model, the system comprising an image region and text detection module, a noise information identification and elimination module, a text logical sequence rearrangement module, a text abnormality intelligent identification module and a document reconstruction detection evaluation module.

[0039] The image region and text detection module is used to identify noise interference features of the first and second to-be-identified regions based on a multi-dimensional identification strategy, eliminate the noise interference features to obtain the first and second to-be-processed regions, and update the spatial position information of the first and second to-be-processed regions.

[0040] The noise information identification and elimination module is used to obtain a target PDF document, parse the content of each page of the target PDF document using PyMuPDF, identify and position mark image regions and text regions to obtain the first and second to-be-identified regions.

[0041] The text logical sequence rearrangement module is used to formulate a multi-level text logical reconstruction strategy according to the spatial positioning information of the first and second to-be-processed regions to complete the reconstruction of the logical sequence of the target PDF document, and preliminarily output a primary PDF document, and perform a first image-text correlation degree analysis on the primary PDF document to output a first correlation strength.

[0042] The text abnormality intelligent identification module is used to perform intelligent abnormality identification and correction on the content of each page of the primary PDF document in terms of semantic structure through a large language model to obtain a secondary PDF document, and perform a second image-text correlation degree analysis on the secondary PDF document to output a second correlation strength.

[0043] The document reconstruction detection evaluation module is used to generate a document reconstruction detection evaluation value based on the first correlation strength and the second correlation strength, determine whether the secondary PDF document is qualified according to the document reconstruction detection evaluation value, and output the qualified secondary PDF document in a structured format.

[0044] The application provides a PDF text extraction method and system based on a large language model.

[0045] The application can integrate key technologies such as image-text positioning, noise identification, multi-level structure reconstruction and semantic intelligent correction, effectively solve the problems of image-text mispositioning, structure confusion, noise interference and semantic rupture in traditional PDF text analysis, build an image-text correlation model, combine keyword matching and semantic similarity features, evaluate the semantic correlation degree between images and context paragraphs, and provide a basis for realizing image annotation, chart attribution determination and content aggregation and other advanced tasks. Through two rounds of image-text correlation analysis, combined with the first correlation strength, the second correlation strength and the document reconstruction detection evaluation value, the quality evaluation and qualified determination mechanism of the extraction result is realized, ensuring that the structured output data is reliable and complete. The application not only significantly improves the accuracy and purity of text extraction, but also restores the logical order and semantic integrity of the document, finally outputs in a structured format, provides a high-quality data basis for subsequent knowledge extraction, search analysis and intelligent question answering and other applications, and has wide applicability and practical value. BRIEF DESCRIPTION OF DRAWINGS

[0046] Figure 1 A flowchart of a PDF text extraction method based on a large language model is provided for the embodiments of the application.

[0047] Figure 2 A system block diagram of a PDF text extraction system based on a large language model is provided for the embodiments of the application. DETAILED DESCRIPTION

[0048] The technical solutions in the present application will be described clearly and completely below in conjunction with the drawings in the present application. Obviously, the described technical solutions are only a part of the present application, not all. Based on the technical solutions in the present application, all other technical solutions obtained by those skilled in the art without creative labor fall within the scope of the present application.

[0049] As Figure 1 shown is a flowchart of a PDF text extraction method based on a large language model provided by an embodiment of the present application, Figure 1 The execution subject of the method shown can be a software and / or hardware device. The execution subject of the present application can include but is not limited to at least one of the following: user equipment, network equipment, etc. Among them, the user equipment can include but is not limited to computers, smart phones, personal digital assistants (Personal Digital Assistant, PDA for short) and the above-mentioned electronic devices, etc. The network equipment can include but is not limited to a single network server, a server group composed of multiple network servers, or a cloud composed of a large number of computers or network servers based on cloud computing, wherein cloud computing is a kind of distributed computing, which is a super virtual computer composed of a group of loosely coupled computers. The present embodiment does not make any limitation. Including steps S1 to S5, as follows:

[0050] S1, obtaining a target PDF document, using PyMuPDF (a PDF document parsing tool) to parse the content of each page of the target PDF document, identifying and positioning the image area and the text area, and obtaining the first to-be-identified area and the second to-be-identified area;

[0051] First, the target PDF document specified by the user is received, and the target PDF document is parsed page by page by PyMuPDF. For each page in the target PDF document, load the document content and extract the text information on the page. The embedded images in the page are extracted and visualized, and the spatial distribution of the images in the page can also be determined through information such as image size, pixel density, and embedding position. Based on the above operations, the system divides the page content into two main areas: the first to-be-identified area, which refers to the area where the images and drawing elements recognized by the image extraction interface are located, usually charts, illustrations, scanned images, and other non-text content; and the second to-be-identified area, which refers to the text block area recognized by the text extraction interface, including the main text, title, page number, etc. The above two areas are respectively spatially positioned and labeled, and their position coordinates on the page are recorded and output in a structured form.

[0052] Finally, the image area and text area in the entire PDF document are recognized and positioned, providing structured input for the next step of noise removal and text semantic rearrangement based on multi-dimensional strategies, effectively improving the processing accuracy of the document, especially suitable for complex structural academic papers, report materials, scanned archives and other types of PDF files.

[0053] S2, based on the multi-dimensional recognition strategy, recognizing the noise interference characteristics of the first and second to-be-recognized areas, removing the noise interference characteristics to obtain the first and second to-be-processed areas, and updating the spatial position information of the first and second to-be-processed areas;

[0054] By loading the image area and text area information obtained in the previous stage, and relying on the preset multi-dimensional recognition strategy, the content inside each to-be-recognized area is analyzed in detail. Under the guidance of the multi-dimensional recognition strategy, the image and drawing elements in the first to-be-recognized area are positioned and excluded from the noise pixel area, such as removing the repeated "DRAFT" watermark layer in the corners of the chart; for the text blocks in the second to-be-recognized area, according to their content and style characteristics, remove prompt information such as "company internal material" and "print time: December 2023".

[0055] After completing the noise interference removal, the boundary area of the retained content is automatically reconstructed, the corresponding first and second to-be-processed areas are updated, and the spatial position coordinates in the page are recalculated. For example, if the original text area shrinks upward after removing the top header content, its position coordinates will be updated to accurately reflect the position of the processed content. The noise in the image and text area of the PDF document is accurately removed and the spatial positioning is updated, ensuring the accuracy and high purity of the subsequent semantic structure recognition and logical order rearrangement stage processing content, and widely applicable to complex structure documents, scanned archives and multi-image-text fusion report cleaning preprocessing scenarios.

[0056] S3, according to the spatial positioning information of the first and second to-be-processed areas, formulating a multi-level text logical reconstruction strategy to complete the reconstruction of the logical order of the target PDF document, and initially outputting a first-level PDF document. The first-level PDF document is analyzed for the degree of association between images and text to output a first association strength.

[0057] The text blocks, images and drawing elements remaining in each page of the document are scanned to extract their spatial position parameters, including the upper left and lower right coordinates, relative position in the page, page number, etc. At the same time, the basic style characteristics of each text block are identified, such as font size, bold attribute, indentation, alignment, etc., which are used for subsequent structure level inference. After the above strategy processing, the entire document content is rearranged and reorganized according to the logical level and semantic flow sequence, a unified logical paragraph sequence is constructed, and structure labels such as chapter number, paragraph level, image-text block identification, etc. are labeled. A primary structured PDF document is generated, which eliminates interference noise in content, has clear title classification, paragraph division and image-text correspondence in structure, and retains the spatial positioning information of each paragraph content, facilitating further semantic understanding, knowledge extraction or format reprocessing. Finally, by constructing an image-text correlation model, combining keyword matching and semantic similarity features, the semantic correlation degree between images and context paragraphs is evaluated, providing a basis for implementing image annotation, chart attribution determination, content aggregation and other advanced tasks.

[0058] S4, by a large language model, the semantic structure of each page of the primary PDF document is intelligently recognized and corrected to obtain a secondary PDF document, and the secondary PDF document is used for secondary image-text correlation degree analysis to output a second correlation strength;

[0059] Load the primary PDF document that has been constructed, and divide the document content by page. The text content and its structure labels of each page are input into a large language model. The model has been pre-trained or fine-tuned with a large amount of document corpus, and has good paragraph attribution judgment, context understanding, text reorganization and logical correction capabilities. The document content is coherent and structurally complete, with continuous paragraph semantics, natural context connection, accurate title level, clear logical structure, complete image-text description, no content skipping or misplacement, no redundant residual noise content, and pure text. Secondary image-text correlation analysis of the secondary PDF text can identify previously misattributed image paragraphs, merge incorrectly split image-text content, and determine whether an image is a core component of the context, thereby providing stronger support for image-text extraction, image annotation generation and other applications.

[0060] S5, based on the first correlation strength and the second correlation strength, a document reconstruction detection evaluation value is generated, and whether the secondary PDF document is qualified is determined according to the document reconstruction detection evaluation value. The qualified secondary PDF document is output in a structured format.

[0061] By establishing a document reconstruction detection evaluation value with the graphic-text correlation strength as the core, the whole process quality control from structure reconstruction, semantic correction to structured output is realized, the output PDF result has verifiable guarantee in logical integrity, graphic-text consistency and data structure accuracy, and stable and reliable technical support is provided for intelligent analysis and understanding of documents in multiple fields.

[0062] Preferably, the content of each page of the target PDF document is parsed using PyMuPDF, the image area and the text area are recognized and positioned to obtain the first to-be-recognized area and the second to-be-recognized area, and the specific process is as follows:

[0063] By parsing the content of each page of the target PDF document through PyMuPDF, multi-category object elements in the document page are extracted, including text blocks, images and drawing elements;

[0064] The drawing elements include paths, shading (control surface interaction with light) objects and vector graphics; the path is composed of straight lines, Bezier curves, rectangles and other geometric shapes, and can be filled or outlined; the shading object is a color gradient or texture filling area, which depends on a mathematical function to describe the color and position relationship; the vector graphics is a pixel-independent graphics, such as chart outline, line art, and complex graphics composed of path combinations or special instructions.

[0065] The multi-category object elements are marked by rectangular boxes to obtain element text boxes, and the spatial position information of the element text boxes in the document page is recorded, including coordinate position, size and page number;

[0066] It should be noted that the coordinate position determination method of the spatial position information specifically includes: first, adjust the document page to a fixed size and divide it into MxM cells, take the top left corner of the document page as the origin, establish a two-dimensional rectangular coordinate system according to the width direction of the document page as the x-axis and the height direction as the y-axis, determine the predicted position coordinates and the number of cells in each element text box, and each element text box contains four predicted values: x, y, w, h, wherein x is the midpoint horizontal coordinate of the element text box, y is the midpoint vertical coordinate of the element text box, w is the width of the document page, and h is the height of the document page; calculate the offset values of x and y relative to the current cell, so that x and y belong to ∈[0, 1]; then normalize w and h, i.e. divide the width and height of the image respectively, so that w and h belong to ∈[0, 1]. Based on the above, the predicted position coordinates of each cell in the document page are obtained Based on the predicted position coordinates, the area position coordinates of the element text box are integrated, and the predicted position coordinates of the top left corner cell of each element text box are taken as the coordinate position of the element text box.

[0067] The image and drawing elements in the element text box in each page are recognized based on an OCR algorithm as initial text content of the image area, and the initial text content is associated with the spatial position information of the document page and labeled as a first to-be-recognized area, and the text block in the element text box is associated with the spatial position information of the document page and labeled as a second to-be-recognized area.

[0068] Preferably, noise interference features of the first to-be-recognized area and the second to-be-recognized area are recognized based on a multi-dimensional recognition strategy, and the multi-dimensional recognition strategy includes a position recognition strategy, a text recognition strategy, a style recognition strategy, and a frequency recognition strategy.

[0069] Preferably, the position recognition strategy is used to recognize specific elements that repeatedly appear at the edge of the document page and judge as signal interference features; the text recognition strategy is used to match specific keywords by using regular expressions and judge as signal interference features; the style recognition strategy is used to recognize specific text with abnormal font color transparency, inclination angle, or font size and judge as signal interference features; and the frequency recognition strategy is used to recognize non-text information that repeatedly appears in all document pages and judge as signal interference features.

[0070] It should be noted that the specific elements that repeatedly appear at the edge of the document page in the position recognition strategy include page numbers, page headers, page footers, and scan numbers, and specific examples include “Internal Training Materials, For Internal Use Only” located in the middle of the top of the page; the page number “Page 3 of 25” located in the lower right corner of the bottom of the page; and the scan barcode or scan timestamp in the fixed position in the lower left corner. The specific keywords in the text recognition strategy include non-text prompt words, advertisement identifiers, and copyright declarations, and specific examples include copyright-related words such as “Copyright All” “Confidential” “Scanned from www.xxx.com” and the like; web links such as “https: / / ...” or “www.xxx.com”; and prompt words such as “Advertisement Hotline” “For Reference Only” “Print Time: 20XX”. The specific text mentioned in the style recognition strategy includes image background watermarks, annotations, or layer residues, and specific examples can be specific text with extremely low font transparency that is almost impossible to identify with the naked eye; specific text with abnormal font inclination angle (such as rotation of 30° or more), such as the specific text of the “DRAFT” diagonal watermark; and specific text with excessively small font size (such as font height < 6px), such as the specific text of the small footer that is almost unreadable. The non-text information mentioned in the frequency recognition strategy includes template page headers, footers, or explanatory fixed sentences, and specific examples include the same text “Report generated automatically by XX system” appearing at the bottom of each page; “Report Number: AB-2023-XYZ” appearing at the beginning of each page with exactly the same text; and the fixed phrase “Scanned from XXX library” appearing on each page.

[0071] Through the cooperative application of the above four identification strategies, the embodiment of the present application can identify the non-text interference content in the document from multiple dimensions such as spatial distribution, semantic rules, style features and document global frequency, and realize accurate removal. On this basis, the text content with semantic continuity and clear structure is retained, providing high-quality corpus support for subsequent document analysis, information extraction and knowledge reconstruction.

[0072] Preferably, according to the spatial positioning information of the first to-be-processed region and the second to-be-processed region, a multi-level text logical reconstruction strategy is formulated to complete reconstruction of the logical order of the target PDF document, and a primary PDF document is initially output. The first correlation strength is output by performing a graphic-text correlation degree analysis on the primary PDF document. The specific process is as follows:

[0073] The spatial positioning information of the first to-be-processed region and the second to-be-processed region is extracted. For the first to-be-processed region and the second to-be-processed region in the same document page, a preliminary sorting is performed in the order of vertical position first and horizontal position second in the document page.

[0074] It should be noted that the preliminary sorting is performed in the order of vertical position first and horizontal position second, wherein the vertical position refers to the specific coordinates of the first to-be-processed region and the second to-be-processed region in the vertical direction. If the coordinates of the first to-be-processed region and the second to-be-processed region in the vertical direction are the same in the same document page, the preliminary sorting is determined according to the coordinates in the horizontal direction. If the coordinates of the first to-be-processed region and the second to-be-processed region in the vertical direction are different in the same document page, the preliminary sorting is determined according to the coordinates in the vertical direction.

[0075] A multi-level text logical reconstruction strategy is formulated to complete reconstruction of the logical order of the target PDF document, wherein the multi-level text logical reconstruction strategy includes a paragraph attribution reconstruction strategy, a title level reconstruction strategy, a list structure reconstruction strategy, and a graphic-text relationship reconstruction strategy.

[0076] The reconstructed target PDF document is sorted to output a primary PDF document, and the first correlation strength is output by performing a graphic-text correlation degree analysis on the primary PDF document.

[0077] Preferably, when the preliminary sorting is performed, the vertical position follows the order from top to bottom, and the horizontal position follows the order from left to right.

[0078] The first correlation strength is output by performing a graphic-text correlation degree analysis on the primary PDF document. The specific process is as follows:

[0079] Extracting a first to-be-processed area and a second to-be-processed area in a first-level PDF document, constructing a graphic-text association degree analysis model, obtaining a first graphic-text semantic association feature of the second to-be-processed area vertically adjacent to the upper portion of the first to-be-processed area, and a second graphic-text semantic association feature of the second to-be-processed area vertically adjacent to the lower portion of the first to-be-processed area; the first graphic-text semantic association feature includes a first keyword matching feature and a first semantic similarity matching feature; the second graphic-text semantic association feature includes a second keyword matching feature and a second semantic similarity matching feature;

[0080] It should be noted that the calculation steps for the first keyword matching feature and the second keyword matching feature are:

[0081] Obtaining the first text content of the first to-be-processed area and the second text content of the second to-be-processed area adjacent thereto, obtaining a first keyword based on the first text content, and then obtaining a second keyword based on the second text content, verifying whether the first keyword appears in the second keyword one by one, and counting the number of first repeated keywords. Calculating the ratio of the number of first repeated keywords to the first keyword to obtain a first keyword matching feature;

[0082] Obtain the first text content of the first area to be processed and the third text content of the second area to be processed below. Obtain the first keyword based on the first text content, and then obtain the third keyword based on the third text content. Verify whether the first keyword appears in the third keyword one by one, and count the number of second repeated keywords. Use the ratio of the number of second repeated keywords to the first keyword to obtain the second keyword matching feature. The first keyword is obtained by extracting nouns, technical terms, and verb phrases from the first text content using a word segmentation tool. The second and third keywords are obtained in the same way and will not be repeated here.

[0083] The calculation steps of the first semantic similarity matching feature and the second semantic similarity matching feature are as follows:

[0084] Obtaining first text content of a first area to be processed and second text content of a second area to be processed adjacent thereto, performing text cleaning on the first and second text contents, including removing redundant symbols, spaces, and formatting marks, encoding the first and second text contents into fixed-dimensional semantic vectors using a pre-trained model, and calculating cosine similarity based on the obtained semantic vectors as a first semantic similarity matching feature;

[0085] The first text content of the first to-be-processed region and the third text content of the second to-be-processed region below are obtained, the first text content and the third text content are text cleaned, including removing redundant symbols, spaces and format marks, the first text content and the third text content are encoded into semantic vectors of fixed dimensions through a pre-training model, and a cosine similarity is calculated based on the obtained semantic vectors as a second semantic similarity matching feature.

[0086] The logical correlation degree of the text content between the two second to-be-processed regions vertically adjacent to the first to-be-processed region is analyzed again, and a weighted result of the first image-text semantic correlation feature, the second image-text semantic correlation feature and the logical correlation degree is calculated as the first correlation strength.

[0087] It should be noted that the calculation process of the logical correlation degree of the text content between the two second to-be-processed regions is as follows:

[0088] The second text content of the second to-be-processed region above the first to-be-processed region and the third text content of the second to-be-processed region below the first to-be-processed region are obtained, the second text content and the third text content are text cleaned, including removing redundant symbols, spaces and format marks, the second text content and the third text content are encoded into semantic vectors of fixed dimensions through a pre-training model, and a cosine similarity is calculated based on the obtained semantic vectors as a logical correlation degree.

[0089] Based on the above, the first image-text semantic correlation feature, the second image-text semantic correlation feature and the logical correlation degree are weighted to obtain the first correlation strength, and the calculation formula is:

[0090] In the formula, is the first correlation strength, is a weight coefficient of the first image-text semantic correlation feature, is the first image-text semantic correlation feature, is a weight coefficient of the second image-text semantic correlation feature, is the second image-text semantic correlation feature, is a weight coefficient of the logical correlation degree, is the logical correlation degree, is an influence factor.

[0091] Preferably, the paragraph attribution reconstruction strategy analyzes the left starting position of the text block of the vertically adjacent second to-be-processed region and the line spacing between the upper and lower lines to determine whether the two text blocks belong to the same paragraph; if the two text blocks belong to the same paragraph, paragraph reconstruction is not needed; otherwise, paragraph reconstruction is needed.

[0092] It should be noted that if the left starting position coordinates of the two text blocks are basically aligned, the line spacing is within a reasonable range, and the two text blocks belong to the same paragraph; if the left starting position (indentation value) of the two text blocks is obviously indented or the line spacing is obviously greater than the average paragraph spacing, it is judged as the start of a new paragraph; for cases such as hanging indentation, alignment error, etc., a certain range of tolerance is allowed for merging judgment.

[0093] The title level reconstruction strategy distinguishes the title features into first, second and third level titles by extracting the specific style information of each text block in the second to-be-processed area and combining the position recognition title features.

[0094] It should be noted that text blocks with obviously larger font, bold, and centered alignment are determined as first level titles; text with relatively smaller font, still bold but left-aligned, is determined as second level titles; text with smaller font or no bold but with numbered identifiers, such as 3.1, 3.1.1, can be determined as third level titles.

[0095] The list structure reconstruction strategy analyzes the list level and nesting relationship by recognizing numbers and bullets to determine whether reconstruction is needed.

[0096] It should be noted that the number format (numbers, letters, mixed) and indentation level are analyzed to identify the list nesting level; if adjacent text blocks have uniform number format and progressive relationship in indentation, they belong to the same multi-level list structure, and reconstruction is not needed; otherwise, reconstruction is needed; however, for items with broken or abnormal number sequences, a certain range of tolerance is allowed for fault handling and number repair, and reconstruction is not needed.

[0097] The image-text relationship reconstruction strategy forms a separate paragraph by extracting images and drawing elements in the first to-be-processed area.

[0098] It should be noted that for adjacent first to-be-processed areas and second to-be-processed areas, the vertically adjacent second to-be-processed areas are first merged and arranged, and then the text in the first to-be-processed area is attached as an independent paragraph after the second to-be-processed area.

[0099] Preferably, the large language model is used to perform intelligent abnormality recognition and correction on the semantic structure of each page content of the first level PDF document to obtain a second level PDF document, and a second correlation strength is output according to the second level PDF document, and the specific process is as follows:

[0100] A PDF document training data set containing various noise samples is constructed, and the signal interference features are manually labeled.

[0101] The pre-trained language model is fine-tuned based on a PDF document training data set, and has noise discrimination ability through supervised learning or instruction fine-tuning. The pre-trained language model can identify the logical structure of the context information, and judge and correct the abnormal paragraph order or semantic jump problem.

[0102] It should be noted that the OCR recognized text of each page or each paragraph is input as the original PDF document sequence to the pre-trained language model, and the original PDF document sequence is further semantically discriminated and structurally rearranged by calling the fine-tuned pre-trained language model to obtain the reconstructed PDF document sequence.

[0103] By analyzing the first-level PDF document paragraph by paragraph, the signal interference features are automatically identified and removed, and the pre-trained language model is used to remove residual noise, correct the text order, and restore the semantic coherence of the first-level PDF document to obtain the second-level PDF document. According to the second-level PDF document, a second correlation strength is output by performing secondary image-text correlation degree analysis.

[0104] It should be noted that the residual noise removal is performed by the pre-trained language model to analyze the first-level PDF document paragraph by paragraph, automatically identify the remaining watermark characters, repeated page numbers, invalid phrases and other non-text content, and remove them.

[0105] It should be noted that the second correlation strength is obtained in the same way as the first correlation strength, and will not be described here.

[0106] The paragraph order correction uses the context understanding ability of the pre-trained language model to correct the order of the identified paragraphs. If it is found that the paragraph arrangement order does not match the logical structure, such as "conclusion" appearing before "method", the pre-trained language model will automatically adjust the order.

[0107] The semantic coherence recovery is used for semantic rupture caused by disordered or misaligned layout. The pre-trained language model can intelligently complete the text, merge sentences, or rewrite the beginning / end phrases to enhance the semantic fluency.

[0108] Based on the first correlation strength and the second correlation strength, a document reconstruction detection evaluation value is generated, and whether the second-level PDF document is qualified is determined according to the document reconstruction detection evaluation value. The qualified second-level PDF document is output in a structured format.

[0109] Based on the first correlation strength and the second correlation strength, a document reconstruction detection evaluation value is generated, and whether the second-level PDF document is qualified is determined according to the document reconstruction detection evaluation value. The specific process includes:

[0110] The difference between the first correlation strength and the second correlation strength is obtained as a document reconstruction detection evaluation value, and the document detection evaluation value is compared with a preset evaluation threshold value. If the document detection evaluation value is greater than or equal to the preset evaluation threshold value, the secondary PDF document is unqualified; if the document detection evaluation value is less than the preset evaluation threshold value, the secondary PDF document is qualified.

[0111] The secondary PDF document is output in a structured format, including JSON, XML, Markdown or plain text format, which can be directly used for document summary, content retrieval, structured database storage or other information processing systems.

[0112] A PDF text extraction system based on a large language model, the system comprising an image region and text detection module, a noise information identification and elimination module, a text logical sequence rearrangement module, a text abnormality intelligent identification module, and a document reconstruction detection evaluation module;

[0113] The image region and text detection module is used to identify the noise interference features of the first and second to-be-identified regions based on a multi-dimensional identification strategy, eliminate the noise interference features to obtain the first and second to-be-processed regions, and update the spatial position information of the first and second to-be-processed regions;

[0114] The noise information identification and elimination module is used to obtain a target PDF document, parse the content of each page of the target PDF document using PyMuPDF, identify and position mark the image region and the text region to obtain the first and second to-be-identified regions;

[0115] The text logical sequence rearrangement module is used to develop a multi-level text logical reconstruction strategy to complete the reconstruction of the logical sequence of the target PDF document according to the spatial positioning information of the first and second to-be-processed regions, and preliminarily output a primary PDF document. The first correlation strength is output by performing a first image-text correlation degree analysis on the primary PDF document;

[0116] The text abnormality intelligent identification module is used to perform intelligent abnormality identification and correction on the content of each page of the primary PDF document based on a large language model to obtain a secondary PDF document, and perform a second image-text correlation degree analysis on the secondary PDF document to output a second correlation strength;

[0117] The document reconstruction detection evaluation module is used to generate a document reconstruction detection evaluation value based on the first correlation strength and the second correlation strength, determine whether the secondary PDF document is qualified according to the document reconstruction detection evaluation value, and output the qualified secondary PDF document in a structured format.

[0118] As Figure 2As shown is a system block diagram of a PDF text extraction system based on a large language model according to an embodiment of the present application, which can be used to execute Figure 1 The steps in the method embodiment have similar implementation principles and technical effects, and will not be described here.

[0119] Through the introduction of the above embodiments, the present application uses PyMuPDF to parse the content of each page of the target PDF document and locate the markers to obtain the first and second to-be-recognized regions; based on a multi-dimensional recognition strategy, the noise interference features of the first and second to-be-recognized regions are recognized and eliminated to obtain the first and second to-be-processed regions; a multi-level text logical reconstruction strategy is formulated to complete the reconstruction of the logical order of the target PDF document, and a primary PDF document is initially output; the first correlation strength is output by performing a degree of image-text correlation analysis on the primary PDF document; through a large language model, intelligent anomaly recognition and correction are performed on the semantic structure of each page of the primary PDF document to obtain a secondary PDF document, and a second correlation strength is output by performing a second degree of image-text correlation analysis on the secondary PDF document; a document reconstruction detection evaluation value is generated based on the first and second correlation strengths, and whether the secondary PDF document is qualified is determined according to the document reconstruction detection evaluation value, and the qualified secondary PDF document is output in a structured format.

[0120] The present application can integrate key technologies such as image-text positioning, noise recognition, multi-level structure reconstruction and semantic intelligent correction, effectively solve the problems of image-text mispositioning, structure confusion, noise interference and semantic rupture in traditional PDF text parsing; by constructing an image-text correlation degree model, combining keyword matching and semantic similarity features, the semantic correlation degree between the image and the context paragraph is evaluated, which provides a basis for realizing image annotation, chart attribution determination and content aggregation; through two rounds of image-text correlation analysis, the first and second correlation strengths and the document reconstruction detection evaluation value are used to realize the quality evaluation and qualification determination mechanism of the extraction result, ensuring the reliability and completeness of the structured output data; the present application not only significantly improves the accuracy and purity of text extraction, but also restores the logical order and semantic integrity of the document, and finally outputs in a structured format, providing a high-quality data basis for subsequent knowledge extraction, search analysis and intelligent question answering applications, and has wide applicability and practical value.

[0121] The above is only a specific embodiment of the present application, but the protection scope of the present application is not limited thereto, and any person skilled in the art can easily think of changes or replacements within the technical scope disclosed in the present application, which should be covered within the protection scope of the present application.

[0122] Finally: the above only is the preferred scheme of the present application, and is not used to limit the present application, any modification, equivalent replacement, improvement, etc. that is made within the spirit and principle of the present application, should be included in the protection scope of the present application.

Claims

1. A PDF text extraction method based on a large language model, characterized in that: The following steps are involved: Obtain the target PDF document, use PyMuPDF to parse the content of each page of the target PDF document, identify the image area and text area, and perform positioning marks to obtain the first area to be identified and the second area to be identified; Identify noise interference features of the first area to be identified and the second area to be identified based on a multi-dimensional recognition strategy, remove the noise interference features to obtain the first area to be processed and the second area to be processed, and update spatial position information of the first area to be processed and the second area to be processed; Based on the spatial positioning information of the first and second areas to be processed, a multi-level text logic reconstruction strategy is formulated to complete the reconstruction of the logical order of the target PDF document, and a first-level PDF document is initially output. An image-text correlation analysis is performed on the first-level PDF document to output a first correlation strength. The large language model is used to intelligently identify and correct semantic structural anomalies on each page of the first-level PDF document to obtain a second-level PDF document. A second-level image-text correlation analysis is performed on the second-level PDF document to output a second correlation strength. A document reconstruction detection evaluation value is generated based on the first association strength and the second association strength, whether the secondary PDF document is qualified is determined according to the document reconstruction detection evaluation value, and the qualified secondary PDF document is output in a structured format.

2. A PDF text extraction method based on a large language model according to claim 1, characterized in that: Use PyMuPDF to parse the contents of each page of the target PDF document, identify the image area and text area, and perform positioning marks to obtain the first area to be identified and the second area to be identified. The specific process is as follows: Use PyMuPDF to parse the contents of each page of the target PDF document and extract multiple categories of object elements in the document page, including text blocks, images, and drawing elements; Marking multiple categories of object elements with rectangular boxes to obtain element text boxes, and recording the spatial position information of the element text boxes in the document page, the spatial position information including coordinate position, size and page number; Based on the OCR algorithm, the images and drawing elements in the element text box of each page are identified as the initial text content of the image area, the initial text content is associated with the spatial position information of the document page and marked as the first area to be identified, and the text block in the element text box is associated with the spatial position information of the document page and marked as the second area to be identified.

3. The PDF text extraction method based on a large language model according to claim 1, characterized in that: The noise interference features of the first area to be identified and the second area to be identified are identified based on a multi-dimensional recognition strategy, where the multi-dimensional recognition strategy includes a position recognition strategy, a text recognition strategy, a style recognition strategy, and a frequency recognition strategy.

4. The PDF text extraction method based on a large language model according to claim 3 is characterized in that: The position recognition strategy is used to identify and locate specific elements that appear repeatedly on the edges of document pages and determine them as signal interference features; the text recognition strategy is used to match specific keywords using regular expressions and determine them as signal interference features; the style recognition strategy is used to identify specific text with abnormal font color transparency, tilt angle or font size and determine them as signal interference features; the frequency recognition strategy is used to identify and count non-text information that appears repeatedly on all document pages and determine it as a signal interference feature.

5. The PDF text extraction method based on a large language model according to claim 1, characterized in that: Based on the spatial positioning information of the first and second areas to be processed, a multi-level text logic reconstruction strategy is formulated to complete the reconstruction of the logical order of the target PDF document. A first-level PDF document is initially output. A graphic-text correlation analysis is performed on the first-level PDF document to output the first correlation strength. The specific process is as follows: Extracting spatial positioning information of the first area to be processed and the second area to be processed, and preliminarily sorting the first area to be processed and the second area to be processed on the same document page in a manner that prioritizes vertical position on the document page and takes a lower order of horizontal position; Formulate a multi-level text logic reconstruction strategy to reconstruct the logical order of the target PDF document. The multi-level text logic reconstruction strategy includes paragraph attribution reconstruction strategy, title level reconstruction strategy, list structure reconstruction strategy, and image-text relationship reconstruction strategy. The reconstructed target PDF document is sorted and reconstructed to output a first-level PDF document, and a graphic-text correlation analysis is performed on the first-level PDF document to output a first correlation strength.

6. The PDF text extraction method based on a large language model according to claim 5, characterized in that: Perform an image-text correlation analysis on the first-level PDF document to output the first correlation strength. The specific process is as follows: Extracting a first to-be-processed region and a second to-be-processed region from a first-level PDF document, constructing a graphic-text association degree analysis model, and obtaining a first graphic-text semantic association feature of the second to-be-processed region vertically adjacent to the upper portion of the first to-be-processed region, and a second graphic-text semantic association feature of the second to-be-processed region vertically adjacent to the lower portion of the first to-be-processed region; Then analyze the logical correlation of the text content between the two second areas to be processed that are vertically adjacent to the first area to be processed, and calculate the weighted result of the first image-text semantic correlation feature, the second image-text semantic correlation feature and the logical correlation as the first correlation strength.

7. The PDF text extraction method based on a large language model according to claim 5, characterized in that: The paragraph attribution reconstruction strategy determines whether two text blocks belong to the same paragraph by analyzing the left starting position of the text blocks and the distance between the upper and lower lines in the vertically adjacent second processing area. If the two text blocks belong to the same paragraph, paragraph reconstruction is not required; otherwise, paragraph reconstruction is required. The title level reconstruction strategy extracts the specific style information of each text block in the second to-be-processed area, combines it with the position to identify the title features, and divides the title features into first-level, second-level, and third-level titles; The list structure reconstruction strategy identifies numbers and bullet points, analyzes the list hierarchy and nesting relationship to determine whether reconstruction is necessary; The image-text relationship reconstruction strategy extracts images and drawing elements from the first area to be processed and forms separate paragraphs.

8. The PDF text extraction method based on a large language model according to claim 1, characterized in that: The large language model is used to intelligently identify and correct semantic structural anomalies on each page of the first-level PDF document to obtain a second-level PDF document. A second-level image-text correlation analysis is performed on the second-level PDF document to output the second correlation strength. The specific process is as follows: Construct a PDF document training dataset containing various noise samples and manually annotate the signal interference features; Fine-tune the pre-trained language model based on the PDF document training dataset, and enable it to distinguish noise through supervised learning or instruction fine-tuning. Input the original PDF document sequence with noise interference and output the reconstructed PDF document sequence. By analyzing the first-level PDF document section by section, the signal interference features are automatically identified and eliminated. The pre-trained language model is used to remove residual noise, correct the paragraph order, and restore the semantic coherence of the first-level PDF document to obtain the second-level PDF document. A secondary image-text correlation analysis is performed on the second-level PDF document to output the second correlation strength.

9. The PDF text extraction method based on a large language model according to claim 1, characterized in that: A document reconstruction detection evaluation value is generated based on the first correlation strength and the second correlation strength, and whether the secondary PDF document is qualified is determined based on the document reconstruction detection evaluation value. The specific process includes: The difference between the first association strength and the second association strength is obtained as a document reconstruction detection evaluation value, and the document detection evaluation value is compared with a preset evaluation threshold. If the document detection evaluation value is greater than or equal to the preset evaluation threshold, the secondary PDF document is unqualified; if the document detection evaluation value is less than the preset evaluation threshold, the secondary PDF document is qualified.

10. A PDF text extraction system based on a large language model, applied to a PDF text extraction method based on a large language model as claimed in any one of claims 1 to 9, characterized in that: The system includes an image area and text detection module, a noise information identification and elimination module, a text logical sequence rearrangement module, a text anomaly intelligent identification module, and a document reconstruction detection and evaluation module; The image region and text detection module is used to identify the noise interference features of the first area to be identified and the second area to be identified based on a multi-dimensional recognition strategy, eliminate the noise interference features to obtain the first area to be processed and the second area to be processed, and update the spatial position information of the first area to be processed and the second area to be processed; The noise information identification and elimination module is used to obtain the target PDF document, use PyMuPDF to parse the content of each page of the target PDF document, identify the image area and text area, and perform positioning marks to obtain the first area to be identified and the second area to be identified; The text logical order rearrangement module is used to formulate a multi-level text logic reconstruction strategy based on the spatial positioning information of the first and second areas to be processed to complete the reconstruction of the logical order of the target PDF document, initially output a first-level PDF document, and perform a text-image correlation analysis on the first-level PDF document to output a first correlation strength; The text anomaly intelligent recognition module is used to use a large language model to perform intelligent semantic structural anomaly recognition and correction on each page of the first-level PDF document to obtain a second-level PDF document. Based on the second-level PDF document, a secondary image-text correlation analysis is performed to output a second correlation strength. The document reconstruction detection and evaluation module is used to generate a document reconstruction detection evaluation value based on the first association strength and the second association strength, determine whether the secondary PDF document is qualified according to the document reconstruction detection evaluation value, and output the qualified secondary PDF document in a structured format.

Citation Information

Patent Citations

  • Method for structuring PDF file based on OCR and large model

    CN119003465A

  • Method for creating structured document based on deep learning model

    CN119558307A