Document segmentation methods, apparatus, computer equipment and storage media

By acquiring the visual features of the document and performing visual penalty correction, the problem of inaccurate segmentation of rich-format unstructured documents in the existing technology is solved, and higher-precision document segmentation is achieved, which conforms to the user's reading logic.

CN121902816BActive Publication Date: 2026-06-30HANGZHOU YOUZAN TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HANGZHOU YOUZAN TECH CO LTD
Filing Date
2026-03-19
Publication Date
2026-06-30

AI Technical Summary

Technical Problem

Existing technologies do not achieve high segmentation accuracy when segmenting rich-format unstructured documents, especially for documents such as PDFs, scanned documents, and images. Segmentation methods based on text symbols are prone to losing structural symbols, resulting in inaccurate segmentation.

Method used

By acquiring visual features of the document to be segmented, such as font size jumps, indentation abrupt changes, and vertical spacing features, visual penalty corrections are performed, and semantic similarity is combined for same-dimensional corrections to determine the segmentation points and improve segmentation accuracy.

Benefits of technology

Without relying on the quality of text extraction, it accurately identifies document structure boundaries, improves the accuracy of document segmentation, conforms to user reading logic, and enhances segmentation precision.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121902816B_ABST
    Figure CN121902816B_ABST
Patent Text Reader

Abstract

This application discloses a document segmentation method, apparatus, computer device, and storage medium. In response to a segmentation command, a document to be segmented is acquired; the document is parsed to obtain multiple text units; visual features related to the document layout are determined based on the text units; a segmentation score is calculated based on the visual features; and segmentation is performed based on the segmentation score. In this application, the visual layout information of the document is referenced from a visual layout perspective, avoiding the text extraction quality defects of treating the document as a plain text stream without relying on OCR. Instead, segmentation is performed by combining the visual geometric layout characteristics of the document when the user browses the text, conforming to the browsing patterns of users reading documents, accurately identifying document structural boundaries, and improving the accuracy of text segmentation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of natural language processing, and in particular to document segmentation methods, apparatus, computer devices, and storage media. Background Technology

[0002] In the fields of natural language processing and retrieval-enhanced generation, document segmentation is a crucial step in building a knowledge base. Current methods for document segmentation include semantic segmentation and rule-based structured segmentation.

[0003] The first method, currently the mainstream semantic segmentation approach, such as Semantic Chunking, uses deep learning models to convert sentences into vectors and determines semantic coherence by calculating the cosine similarity between adjacent sentences. Segmentation occurs when the similarity is below a set threshold. This first method is purely semantic segmentation, which ignores the document's structural features, resulting in low segmentation accuracy. The second method, structured segmentation based on regular text rules, forces segmentation at structural boundaries by matching markers such as the # symbol for titles and the numbering symbol for numbers. While this marker-based approach can extract structural features, it loses explicit structural symbols when segmenting rich-format unstructured documents such as PDFs, scanned documents, and images. For example, PDF titles do not contain the # symbol; in this case, the regular text matching method will be completely ineffective.

[0004] Therefore, the segmentation of rich-format unstructured documents is highly dependent on the quality of text extraction, and the segmentation accuracy is not high. In summary, existing technologies suffer from low document segmentation accuracy. Summary of the Invention

[0005] This application provides a document segmentation method, apparatus, computer equipment, and storage medium, which can solve the technical problem of low document segmentation accuracy.

[0006] In a first aspect, embodiments of this application provide a document segmentation method, the document segmentation method comprising:

[0007] In response to the document splitting instruction, obtain the document to be split;

[0008] The document to be segmented is parsed to obtain multiple text units;

[0009] Based on the text units, document visual features related to document layout are determined, wherein the document visual features are not the text symbols themselves but rather the visual features perceived by the naked eye when browsing the document.

[0010] Based on the document's visual features, the semantic similarity of text units is corrected using the same dimension of visual penalty to obtain the corrected segmentation score of the current text unit.

[0011] The document to be segmented is divided into multiple document blocks based on the segmentation score. Text units in the document to be segmented whose segmentation score is less than a preset segmentation threshold are disconnected from the previous text unit to obtain a new document block. Text units in the document to be segmented whose segmentation score is not less than the segmentation threshold are merged into the current document block.

[0012] In some embodiments, the document visual features include any one of font size jump features, indentation abrupt changes, and vertical spacing features. Determining the document visual features related to document layout based on the text units includes:

[0013] Metadata is extracted from each text unit to obtain the geometric coordinates and style attributes related to document layout for each text unit, wherein the style attributes related to document layout include font size;

[0014] If the font size of the current text unit is greater than the font size of the previous text unit, then first calculate the difference between the font size of the current text unit and the font size of the previous text unit, and then calculate the quotient between the difference and the font size of the previous text unit to obtain the font size jump feature of the current text.

[0015] Calculate the absolute value of the horizontal displacement between the left boundary coordinates of the current text unit and the left boundary coordinates of the previous text unit in the geometric coordinates to obtain the indentation abruptness feature of the current text.

[0016] Calculate the vertical displacement between the upper boundary coordinates of the current text unit and the lower boundary coordinates of the previous text unit in the geometric coordinates to obtain the vertical spacing feature of the current text.

[0017] In some embodiments, the style attributes related to document layout further include font weight, and the step of applying a visual penalty correction to the semantic similarity of text units based on the document's visual features to obtain the corrected segmentation score of the current text unit includes:

[0018] If the font size jump feature exceeds the first threshold or the font weight is bold, then a first visual penalty value is determined to correct the semantic similarity of the text unit by the same dimension of font size jump visual penalty.

[0019] If the indentation mutation feature exceeds the second threshold, then a second visual penalty value is determined to correct the semantic similarity of the text unit by the same-dimensional visual penalty for indentation mutation.

[0020] If the vertical spacing feature exceeds a preset third threshold, a third visual penalty value is determined to correct the semantic similarity of the text units by the same dimension of vertical spacing visual penalty, wherein the first visual penalty value is greater than the second visual penalty value, and the second visual penalty value is greater than the third visual penalty value.

[0021] The first visual penalty value, the second visual penalty value, and the third visual penalty value are summed to obtain the total visual penalty value that corrects the semantic similarity of the text units in the same dimension.

[0022] Based on the total visual penalty value, the semantic similarity of the text units is corrected by visual penalty in the same dimension to obtain the corrected segmentation score of the current text unit.

[0023] In some embodiments, if the font size abruptness feature exceeds a first threshold or the font weight is bold, determining a first visual penalty value for correcting the semantic similarity of text units by applying a visual penalty for font size abruptness in the same dimension includes:

[0024] Based on the distribution of font size jump features for each font unit in all text units, determine the average value and standard deviation of the font size jump features;

[0025] Determine the type parameter corresponding to the document type of the document to be segmented. The first type parameter corresponding to the document type of magazine or brochure is greater than the second type parameter corresponding to the document type of academic paper or law and regulation. The second type parameter is greater than the third type parameter corresponding to the document type of financial research report or intensive report.

[0026] First, multiply the standard deviation by the type parameter corresponding to the document type, and then add it to the average value of the font size jump feature to obtain the first threshold;

[0027] If the font size jump feature exceeds the first threshold or the font weight is bold, then a first visual penalty value is determined to correct the semantic similarity of the text unit by applying the same-dimensional visual penalty for the font size jump.

[0028] In some embodiments, after applying a visual penalty correction of the semantic similarity of text units based on the document's visual features to obtain the corrected segmentation score of the current text unit, the process includes:

[0029] Starting from the first text unit, calculate the sum of the total segmentation scores for multiple text units within the sliding window;

[0030] If the sum of the total segmentation scores exceeds the preset segmentation threshold, then the end of the current sliding window is recorded as a segmentation point, and all text units are traversed to obtain a list of segmentation points composed of multiple segmentation points.

[0031] The document to be segmented is divided into multiple document blocks from the segmentation points indicated by the segmentation point list.

[0032] In some embodiments, the step of applying the same-dimensional visual penalty correction to the semantic similarity of text units based on the total visual penalty value to obtain the corrected segmentation score of the current text unit includes:

[0033] Metadata is extracted from each text unit to obtain the text content corresponding to each text unit;

[0034] The text content is transformed based on a pre-trained language model to obtain a text vector corresponding to each text unit.

[0035] Calculate the similarity between two adjacent text units with respect to the text vector to obtain the semantic similarity of the text units;

[0036] The segmentation score of the current text unit is calculated based on the total visual penalty value and the semantic similarity of the text unit. The larger the total visual penalty value, the smaller the segmentation score.

[0037] In some embodiments, parsing the document to be segmented to obtain multiple text units includes:

[0038] The document to be segmented is parsed to obtain multiple text units, wherein each text unit is a line of text or a sentence;

[0039] Metadata extraction is performed on the text unit to obtain the center x-coordinate and center y-coordinate of the text unit;

[0040] If, after performing layout analysis based on the central horizontal and vertical coordinates, it is determined that the layout format of the document to be segmented is a non-single-column layout format, then, based on the central horizontal and vertical coordinates, multiple text units are reordered according to the logical order of reading to obtain a text unit sequence that conforms to the reading logic. The non-single-column layout format includes a two-column layout format or a multi-column layout format.

[0041] Secondly, embodiments of this application also provide a document segmentation device, the document segmentation device comprising:

[0042] The acquisition unit is used to acquire the document to be segmented in response to the document segmentation instruction.

[0043] The parsing unit is used to parse the document to be segmented to obtain multiple text units;

[0044] A determining unit is used to determine document visual features related to document layout based on the text unit, wherein the document visual features are not the text symbols themselves but rather the visual features perceived by the naked eye when browsing the document.

[0045] The calculation unit is used to perform visual penalty correction on the semantic similarity of the text units based on the visual features of the document, and obtain the corrected segmentation score of the current text unit.

[0046] A segmentation unit is used to segment the document to be segmented into multiple document blocks based on the segmentation score, wherein text units in the document to be segmented whose segmentation score is less than a preset segmentation threshold are disconnected from the previous text unit to obtain a new document block, and text units in the document to be segmented whose segmentation score is not less than the segmentation threshold are merged into the current document block.

[0047] Thirdly, embodiments of this application also provide a document segmentation computer device, which includes a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the above-described method.

[0048] Fourthly, embodiments of this application also provide a computer-readable storage medium storing a computer program, the computer program including program instructions that, when executed by a processor, can implement the above-described method.

[0049] This application provides a document segmentation method, apparatus, computer device, and storage medium. In response to a document segmentation instruction, a document to be segmented is obtained; the document to be segmented is parsed to obtain multiple text units; based on the text units, document visual features related to document layout are determined, wherein the document visual features are not the text symbols themselves but rather represent the visual features perceived by the naked eye when browsing the document; based on the document visual features, the semantic similarity of the text units is corrected using a visual penalty of the same dimension to obtain a corrected segmentation score for the current text unit; based on the segmentation score, the document to be segmented is segmented to obtain multiple document blocks, wherein text units in the document to be segmented whose segmentation score is less than a preset segmentation threshold are disconnected from the previous text unit to obtain new document blocks, and text units in the document to be segmented whose segmentation score is not less than the segmentation threshold are merged into the current document block. In this application, the visual layout information of the document is referenced from a visual layout perspective, thus avoiding the text extraction quality defects caused by treating the document as a plain text stream and not relying on OCR. Instead, it segments the text based on the visual geometric layout of the document when users browse it, conforming to the browsing patterns of users reading documents, accurately identifying document structural boundaries, and improving the accuracy of text segmentation. Attached Figure Description

[0050] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0051] Figure 1 A flowchart illustrating the document segmentation method provided in this application embodiment;

[0052] Figure 2 A schematic block diagram of a document segmentation device provided in the embodiments of this application;

[0053] Figure 3 A schematic block diagram of a computer device provided in an embodiment of this application. Detailed Implementation

[0054] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0055] It should be noted that any AI models, software tools, or components not belonging to this company appearing in the embodiments of this application are merely illustrative examples and do not represent actual use. The user personal information involved in the embodiments of this application is obtained by an entity authorized (with the knowledge and consent) or fully authorized by all parties through various legal and compliant means. The collection, storage, use, processing, transmission, provision, and disclosure of the information, data, and signals involved all comply with relevant laws and regulations and do not violate public order and good morals.

[0056] It should be understood that, when used in this specification and the appended claims, the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.

[0057] It should also be understood that the terminology used in this application specification is for the purpose of describing particular embodiments only and is not intended to limit the application. As used in this application specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.

[0058] It should also be further understood that the term “and / or” as used in this application specification and the appended claims means any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.

[0059] In the fields of Natural Language Processing (NLP) and Retrieval-Augmented Generation (RAG), document segmentation is a crucial step in building knowledge bases. Taking RAG as an example, RAG is an advanced framework for enhancing the capabilities of Large Language Models (LLMs). Before the LLM generates the final answer, authoritative information relevant to the question is retrieved from an external knowledge base. This information is then provided to the LLM as context, guiding it to generate more accurate, credible, and factually consistent answers.

[0060] When segmenting documents, traditional semantic segmentation can be used. The current mainstream approach uses deep learning models to convert sentences into vectors and calculates the cosine similarity between adjacent sentences to determine semantic coherence. Segmentation occurs when the similarity is below a set threshold; this traditional semantic segmentation is purely semantic. Another approach is text-rule-based structured segmentation. Existing technologies use penalty mechanisms based on explicit text symbols, matching Markdown tags such as #, list numbers (e.g., 1.), or uppercase words with regular expressions to force segmentation at structural boundaries, addressing the document structure issue that pure semantic segmentation often overlooks. While text-rule-based methods represent an improvement over traditional semantic segmentation, they still have significant limitations in practical industrial applications such as processing rich-format documents like PDFs, scanned documents, images, and complex financial research reports. Many unstructured documents, after being parsed using OCR (Optical Character Recognition) or PDF, often lose explicit structural symbols due to the limitations of OCR. For example, PDF titles lack the # symbol. If the title is highlighted in bold or larger font, it cannot be recognized and cannot be correctly segmented. Document segmentation of such unstructured documents heavily relies on the quality of text extraction. Furthermore, due to limitations in OCR recognition, if a list in a PDF lacks numbering, it cannot identify the actual list items. In this case, structured segmentation based on regular expression matching of text symbols will completely fail. This leads to existing technologies frequently merging titles or list items incorrectly into the main text during document segmentation. The segmentation of rich-format unstructured documents also heavily relies on the quality of text extraction, resulting in low segmentation accuracy. In summary, existing technologies suffer from low document segmentation accuracy.

[0061] In addition, although there are multimodal large models that can understand text layout, their inference costs are extremely high, making them difficult to apply in real time in the large-scale data processing (ETL) stage of the RAG system, resulting in high computational costs.

[0062] To address the aforementioned technical issues, this application adopts a visual layout perspective, referencing the document's visual layout information, and avoids the text extraction quality defects inherent in treating the document as a plain text stream without relying on OCR. Instead, it segments the text based on the visual geometric layout characteristics observed by users while browsing, thereby identifying titles, paragraphs, and chapters. This application's text segmentation based on visual layout is because users subjectively judge text reading based on visual features such as font size variations, line spacing changes, and text indentation variations. Therefore, this application differs from previous methods of processing plain text streams, accurately identifying document structural boundaries and achieving higher text segmentation precision.

[0063] The document segmentation method provided in this application is applied to a document segmentation device. Figure 1 This is a flowchart illustrating the document segmentation method provided in an embodiment of this application. For example... Figure 1 As shown, the method includes the following steps S110-S150:

[0064] S110. In response to the document splitting instruction, obtain the document to be split;

[0065] In response to the document splitting instruction, obtain the document to be split. The document to be split can be in various formats, such as PDF (Portable Document Format) files, document images, or HTML (Hypertext Markup Language) files with style information.

[0066] As an example, in response to a document splitting instruction, the raw HTML string of a webpage can be obtained, or a headless browser can be used to obtain a dynamic webpage.

[0067] S120. The document to be segmented is parsed to obtain multiple text units;

[0068] The document segmentation device in this embodiment has a built-in parsing engine. As an example, this could be a PDF parsing engine or an OCR engine. The built-in parsing engine parses the document to be segmented.

[0069] Since the documents to be segmented can be in various formats, such as PDF, images, or HTML, the ultimate goal of parsing is to convert these documents into high-quality, structured plain text or structured data so that they can be understood by an LLM (Local Management Model), stored in a vector database for use in a RAG-based knowledge base, or incorporated into data analysis processes such as ETL (Extract, Translate, and Load). The choice of parsing engine depends on the document type, accuracy requirements, and budget.

[0070] As an example, PDF parsing engines can be used to parse PDF files. PDFs can be further categorized into text-based PDFs and image-based PDFs. For instance, text-based PDFs can be parsed using engines like PyMuPDF Fitz or pdfplumber. The first two engines are powerful and extremely fast, accurately extracting text, position, and font information, and handling complex layouts. pdfplumber excels at extracting tabular data and more detailed text blocks or line information, making it ideal for data analysis. Besides parsing text-based PDFs, image-based PDFs can also be parsed using OCR engines. Specifically, this involves using an OCR engine combined with PDF image extraction, such as using PaddleOCR to convert PDF pages into images, and then using an OCR engine for recognition.

[0071] The process of a PDF parsing engine parsing a text-based PDF file can be roughly divided into five steps: First, decoding and decompression; because PDF files are in binary format and may be compressed, the parser first decodes the file and decompresses the internal stream. Second, parsing the object graph; because a PDF consists of a series of mutually referencing objects such as a font dictionary, content stream, and page tree, the PDF parsing engine constructs a graph of these objects. Third, processing the content stream; the content stream of each page is a series of drawing instructions, such as drawing the string "Hello" in a certain font at coordinates (x, y). The PDF parsing engine needs to simulate the execution of these instructions. Fourth, text extraction and positioning; during the simulation, the content of all text drawing instructions and their precise coordinates on the page are recorded. This yields the text with its position. Fifth, layout analysis; some parsing engines can analyze the positional relationships of these text blocks, inferring the document's logical structure by calculating line spacing, indentation, alignment, etc.: which are headings, which are paragraphs, which text belongs to the same table, etc. This is the most difficult part because the PDF itself does not contain semantic tags indicating "this is a heading." Step 6: Table recognition; by detecting horizontal and vertical lines or virtual lines, the text in a specific area is classified into cell content, and the table structure is reconstructed.

[0072] As an example, the parsing process for image-based PDFs differs from that for text-based PDFs. First, the PDF pages are converted into high-resolution bitmaps through rendering. Then, image preprocessing performs denoising, skew correction, and binarization to improve OCR recognition accuracy. Next, the OCR parsing engine analyzes the image, identifying individual characters and combining them into words and text lines. Finally, layout analysis and post-processing are performed, similar to the process for text-based PDFs, analyzing the layout of the identified text boxes to infer their structure. Furthermore, the OCR results may contain recognition errors, requiring post-processing correction.

[0073] As an example, the image parsing process can begin with preprocessing. After loading the image, operations such as grayscale conversion, binarization, noise reduction, angle correction, and perspective transformation are performed to create optimal input conditions for OCR. Next, text detection is performed, using computer vision techniques to locate the positions (bounding boxes) of all text regions in the image. Then, text recognition is performed, cropping each detected text region and feeding it into a recognition model (such as a CNN+RNN+CTC / Attention architecture) to convert the image pixel sequence into a character sequence. Finally, layout analysis and post-processing are performed. Layout analysis can output text simply from top to bottom and left to right based on the detected bounding boxes, or a layout analysis model such as PaddleOCR's layout analysis model can be used to identify which regions are titles, paragraphs, lists, tables, images, etc., and reconstruct the reading order, performing spell checking and dictionary-based correction.

[0074] As an example, HTML itself is a markup language designed to express structure and content, so parsing it is relatively straightforward; the core is understanding its tree structure. For instance, using the HTML parsing engine BeautifulSoup, the HTML parsing process involves BeautifulSoup reading the original HTML string, performing lexical analysis (converting tags, attributes, and text), and then performing syntax analysis. Based on HTML's nesting rules, it constructs a Document Object Model (DOM) tree, where each HTML element is a node, clearly representing the parent-child and sibling relationships between tags. BeautifulSoup is then used to locate and extract specific nodes, extracting the element's text content and attribute values. Finally, cleanup and normalization are performed. The extracted text may contain a large number of whitespace characters, scripts, and style content, requiring cleanup to retain only meaningful text.

[0075] S120 is the step of parsing the document to be segmented to obtain multiple text units, including steps S1201-S1203:

[0076] Step S1201: Parse the document to be segmented to obtain multiple text units, wherein each text unit is a line of text or a sentence;

[0077] The parsed text unit can be a line of text or a sentence.

[0078] Step S1202: Extract metadata from the text unit to obtain the center x-coordinate and center y-coordinate of the text unit;

[0079] Metadata extraction is performed on text blocks to obtain the center x-coordinate and center y-coordinate of each text unit. In fact, metadata extraction from text blocks can yield text content, geometric coordinates, and style attributes. The extracted geometric coordinates include the left, right, top, and bottom boundary coordinates. The center x-coordinate of a text unit is calculated based on its left and right boundary coordinates, and the center y-coordinate is calculated based on its top and bottom boundary coordinates. Besides the four types of geometric coordinates mentioned above, extracted style attributes can include font size, font weight, and font color.

[0080] Step S1203: If, after performing layout analysis based on the central horizontal coordinate and the central vertical coordinate, it is determined that the layout format of the document to be segmented is a non-single-column layout format, then, based on the central horizontal coordinate and the central vertical coordinate, the multiple text units are reordered according to the logical order of reading to obtain a text unit sequence that conforms to the reading logic. The non-single-column layout format includes a two-column layout format or a multi-column layout format.

[0081] Existing technologies suffer from inaccurate segmentation granularity when processing documents with complex layouts. They treat the document to be segmented merely as a plain text stream, ignoring the structural features of the text. This application takes into account documents with different layout formats, classifying page layout types into single-column layout formats and non-single-column layout formats.

[0082] As an example, after extracting the above four coordinates from the metadata, the center x-coordinate and center y-coordinate of the text unit can be determined. Based on the center x-coordinate and center y-coordinate, the layout of the document to be segmented is analyzed to determine the layout type of the document. The layout type can be divided into single-column layout and non-single-column layout. Among them, the non-single-column layout can be a two-column layout, a multi-column layout, or a complex layout between two-column and multi-column, such as a newspaper layout, where multiple text blocks are distributed in a staggered manner, resulting in a more complex layout.

[0083] As an example, after analyzing the layout based on the center x-coordinate and center y-coordinate, it is determined that the document to be segmented is a two-column format. Therefore, multiple text units are reordered based on the center x-coordinate and center y-coordinate, following the logical order of reading the left column content first, then the right column content, resulting in a text unit sequence that conforms to reading comprehension logic. Specifically, the rows in the left and right columns are sorted according to their vertical position (y-coordinate). The sorted list of rows in the left and right columns is then merged. In practice, two-column reading usually involves reading the left column first, then the right column. Therefore, the left column is read first, followed by the right column, and the rows are merged in vertical order. The entire page is divided into two vertical regions (left and right columns), and each region is processed separately. The rows in each region are sorted according to their y-coordinate, and then the results from the two regions are concatenated according to the region order. First, determine which column (left or right) each row belongs to. Sort the rows in the left column in ascending order of y-coordinate, and sort the rows in the right column in ascending order of y-coordinate. Connect the sorted rows in the left column and the sorted rows in the right column, with the left column first and the right column last, to obtain a text unit sequence that conforms to the logic of reading comprehension.

[0084] The reordering is as follows: Row 1: ("First row of the left column", 10, 100) Row 2: ("Second row of the left column", 10, 120) Row 3: ("First row of the right column", 400, 100) Row 4: ("Second row of the right column", 400, 120). In Row 1: ("First row of the left column", 10, 100), 10 is the center x-coordinate and 100 is the center y-coordinate. The coordinates of the other rows are similar.

[0085] S130. Based on the text unit, determine the document visual features related to the document layout, wherein the document visual features are not the text symbols themselves but rather the image features perceived by the naked eye when browsing the document.

[0086] Existing technologies treat documents as plain text streams, while this application segments text from a visual layout perspective. This aligns with the subjective visual patterns of users actually reading documents, utilizing the visual features of a document—not the text symbols themselves—but rather the visual characteristics perceived by the naked eye when browsing the document. For rich-format documents such as PDFs and images, this avoids the problem of lost visual layout information leading to decreased segmentation accuracy.

[0087] In some embodiments, the document visual features include any one of font size jump features, indentation abruptness features, and vertical spacing features. Step S130, based on the text units, determines the document visual features related to the document layout, including steps S1301-S1304:

[0088] S1301. Extract metadata for each text unit to obtain the geometric coordinates and style attributes related to document layout for each text unit, wherein the style attributes related to document layout include font size;

[0089] S1302. If the font size of the current text unit is greater than the font size of the previous text unit, first calculate the difference between the font size of the current text unit and the font size of the previous text unit, and then calculate the quotient between the difference and the font size of the previous text unit to obtain the font size jump feature of the current text.

[0090] Metadata is extracted from each text unit to obtain the geometric coordinates of each text unit and the style attributes related to the document layout, including the font size.

[0091] When humans read documents, they rely on visual features such as changes in font size, line spacing, and left-side indentation to identify paragraphs and chapters. By extracting visual layout features of a document, such as abrupt changes in font size, indentation shifts, and vertical spacing, and quantifying them as "visual penalty items" of the same dimension as semantic similarity, the document's structural boundaries can be accurately identified without relying on explicit text symbols.

[0092] Existing technologies often lose explicit structural symbols such as the # symbol or list sorting numbers, causing solutions based on regular expression matching of text symbols to fail. This application does not rely on text extraction quality. It determines titles or list items by calculating visual differences between adjacent units. Titles are determined by font size (larger and bolder), and lists are determined by text indentation.

[0093] Let FontSizei represent the font size of the current text unit, and FontSizei-1 represent the font size of the previous text unit. If the font size FontSizei of the current text unit is greater than the font size FontSizei-1 of the previous text unit, it means that the font size has increased. If the trend of increasing font size exceeds a preset threshold, it indicates that the font size has increased significantly, and it is highly likely to be a title.

[0094] Specifically, let Fsize be the font size jump feature, and calculate the font size ratio of the current line to the previous line:

[0095] Fsize=FontSizei-FontSizei-1FontSizei-1

[0096] First, calculate the difference between the font size FontSizei of the current text unit and the font size FontSizei-1 of the previous text unit. Then, calculate the quotient between the difference FontSizei-FontSizei-1 and the font size FontSizei-1 of the previous text unit to obtain the font size jump feature Fsize of the current text.

[0097] If Fsize > 0 and exceeds the preset threshold, it indicates that the font size has increased significantly, and it is highly likely to be a title.

[0098] S1303. Calculate the absolute value of the horizontal displacement between the left boundary coordinate of the current text unit and the left boundary coordinate of the previous text unit in the geometric coordinates to obtain the indentation abruptness feature of the current text.

[0099] As an example, the extracted metadata includes text content (Texti), geometric coordinates (Boxi), and style attribute (Stylei). Here, x0 represents the left boundary coordinate, y0 the top boundary coordinate, x1 the right boundary coordinate, and y1 the bottom boundary coordinate. Boxi = (x0, y0, x1, y1).Stylei = {FontSize, FontWeight, Color}.

[0100] As an example, let the indentation abrupt change feature of the current text be Findent. Calculate the absolute value of the horizontal displacement of the left boundary. Specifically, calculate the absolute value of the horizontal displacement between the left boundary coordinate x0 of the current text unit and the left boundary coordinate x0,i-1 of the previous text unit in geometric coordinates. The resulting indentation abrupt change feature of the current text is Findent = |x0,i-x0,i-1|.

[0101] If the indentation mutation feature Findent changes significantly, it usually means the beginning of a list item or the end of a reference block.

[0102] S1304. Calculate the vertical displacement between the upper boundary coordinates of the current text unit and the lower boundary coordinates of the previous text unit in the geometric coordinates to obtain the vertical spacing feature of the current text.

[0103] As an example, let's denote the vertical spacing feature as Fgap. Specifically, it's calculated by determining the vertical displacement between the upper boundary coordinates (y0, i) of the current text unit and the lower boundary coordinates (y1, i-1) of the previous text unit in geometric coordinates, resulting in the vertical spacing feature Fgap = y0, i - y1, i-1. The spacing between paragraphs or chapters is typically significantly greater than the line spacing.

[0104] S140. Based on the document's visual features, the semantic similarity of the text units is corrected by visual penalty in the same dimension to obtain the corrected segmentation score of the current text unit.

[0105] In some embodiments, the document's visual features are used to determine whether the current text is a specific title, list, paragraph, or chapter, or other special text. If it is special text, a visual penalty is applied to these text units to accurately identify document structure boundaries. This prominent visual penalty is used as the basis for subsequent segmentation to improve segmentation accuracy. The segmentation score corresponding to the current text unit is obtained based on the visual penalty, and the segmentation points for the document are determined based on the segmentation score.

[0106] In some embodiments, the style attributes related to document layout further include font weight. Step S140, which involves applying a visual penalty correction to the semantic similarity of text units based on the document's visual features to obtain the corrected segmentation score for the current text unit, includes steps S1401-S1405:

[0107] S1401. If the font size jump feature exceeds the first threshold or the font thickness is bold, then determine the first visual penalty value for correcting the semantic similarity of the text unit by the same-dimensional font size jump visual penalty.

[0108] Specifically, the segmentation score for a text unit is calculated as follows: if the font size increases significantly based on the font size jump feature, the text unit is considered a title, and a first visual penalty value corresponding to the title is added. The first threshold is used to determine whether the font size has increased significantly. If the font size jump feature exceeds the preset first threshold, it is determined to be a title, and a first visual penalty value is determined to correct the semantic similarity of the text unit using the same dimension as the font size jump visual penalty. This first visual penalty value is used for strong structure penalty of the title.

[0109] In addition to text with abrupt font size changes potentially being a title, text in bold font can also be a title. Therefore, besides determining the first visual penalty value for semantic similarity of text units based on font size abrupt changes, a first visual penalty value can also be applied to the semantic similarity of text units when the font weight attribute is determined to be bold. The logic here is to determine whether the current text unit is bold; if true, it usually indicates that the line is a title or important content, and a visual penalty should be applied.

[0110] S1401 If the font size abruptness feature exceeds the first threshold or the font weight is bold, then the step of determining the first visual penalty value for correcting the semantic similarity of the text units by applying the same-dimensional visual penalty for font size abruptness includes steps A1-A4:

[0111] A1. Based on the distribution of font size jump features for each font size unit in all text units, determine the average value and standard deviation of the font size jump features;

[0112] The first threshold is used to determine whether the font size has increased significantly; however, the definition of "significant" is somewhat ambiguous. Since different document types have different granularities, the segmentation granularity should also be adapted accordingly. Therefore, the first threshold differs for different document types. The first threshold affecting the segmentation granularity adapts to different document types.

[0113] Based on the specific document content, the distribution of font size jump features between adjacent lines in the entire document is obtained. Based on the distribution of font size jump features across the entire document, the mean value μsize and the standard deviation σsize of the font size jump features are determined.

[0114] As an example, the type parameter α is set to characterize the segmentation sensitivity for different document types.

[0115] In some embodiments, the first threshold is a dynamic threshold based on document statistics. The first threshold Tsize is calculated as Tsize = μsize + α·σsize.

[0116] A2. Determine the type parameter corresponding to the document type of the document to be segmented. The first type parameter corresponding to the document type of magazine or brochure is greater than the second type parameter corresponding to the document type of academic paper or law and regulation. The second type parameter is greater than the third type parameter corresponding to the document type of financial research report or intensive report.

[0117] The type parameter corresponding to the document type is α.

[0118] Document types are broadly categorized into three types: Type I, Type II, and Type III. Type I documents, such as magazines or brochures, have messy layouts and arbitrary font variations. These documents are noisy and contain numerous unstructured decorative font size variations. To avoid mistakenly segmenting decorative text into chapters, a larger α value is set for Type I documents, generally higher than the standard value, to raise the segmentation threshold, considering only the most statistically significant abrupt changes as structural boundaries. Type II documents, such as academic papers or legal regulations, typically have titles significantly larger than the body text. The standard α value is set for Type II documents because the title feature is statistically significant and easily detected. Type III documents, such as financial research reports or densely formatted reports, have compact layouts and minimal hierarchical differences, with titles only slightly larger than the body text. If the α value is too large, it may lead to missed detections; therefore, the α value for Type III documents should be reduced to lower the segmentation threshold and more accurately capture subtle font variations.

[0119] In summary, the rule for setting document type parameters is: the first type parameter is greater than the second type parameter, and the second type parameter is greater than the third type parameter. As an example, the first type parameter is set to 2.0, the second type parameter to 1.5, and the third type parameter to 1.0. α determines the sensitivity of the judgment. The larger the α value, the higher the difference threshold required to determine a sudden change in font size (heading); the smaller the α value, the lower the threshold for judgment.

[0120] A3. First, multiply the standard deviation by the type parameter corresponding to the document type, and then add it to the average value of the font size jump feature to obtain the first threshold;

[0121] The first threshold is calculated as Tsize = μsize + α·σsize, where μsize is the average value of the font size jump feature, σsize is the standard deviation of the font size jump feature, and α is the type parameter corresponding to the document type.

[0122] A4. If the font size jump feature exceeds the first threshold or the font weight is bold, then determine a first visual penalty value for correcting the semantic similarity of the text unit by applying the same-dimensional visual penalty for font size jump.

[0123] If the font size jump feature exceeds the first threshold or the font weight is bold, then a first visual penalty value is determined to correct the semantic similarity of the text unit by applying the same-dimensional visual penalty for the font size jump.

[0124] S1402. If the indentation mutation feature exceeds the second threshold, then determine the second visual penalty value for visual penalty correction of indentation mutation in the same dimension for the semantic similarity of the text unit.

[0125] The second threshold is used to determine whether it is a list item. A significant change in indentation usually indicates the start of a list item or the end of a quoted block. If the abrupt change in indentation exceeds the second threshold, it indicates a significant change in indentation, and a preset second visual penalty value is applied to the semantic similarity of the text units to characterize the list item feature.

[0126] S1403. If the vertical spacing feature exceeds a preset third threshold, a third visual penalty value is determined to correct the semantic similarity of the text unit by the same dimension of vertical spacing visual penalty, wherein the first visual penalty value is greater than the second visual penalty value, and the second visual penalty value is greater than the third visual penalty value.

[0127] The third threshold is used to determine whether it is a paragraph or a chapter. Because paragraph spacing or chapter spacing is usually significantly greater than line spacing, if the vertical spacing significantly exceeds the threshold, it indicates that it is a new paragraph or a new chapter.

[0128] If the vertical spacing feature exceeds a preset third threshold, then a third visual penalty value is determined to correct the semantic similarity of the text units by applying a visual penalty to the vertical spacing in the same dimension.

[0129] As an example, the third threshold is Hline + Hpara2. This involves calculating the vertical spacing features Fgap of all adjacent text units within the document to obtain a set Ygap composed of multiple vertical spacing features. Cluster analysis or histogram analysis of Ygap is then performed to identify the primary peak Hline for line spacing and the secondary peak Hpara for paragraph spacing. Based on this third threshold, line breaks and paragraph breaks can be accurately distinguished, improving document segmentation accuracy.

[0130] Regarding the quantification of weights, to reflect the differences in the impact of different visual features on document structure, the first visual penalty value is greater than the second visual penalty value, and the second visual penalty value is greater than the third visual penalty value. For strong structures like headings, where abrupt changes in font size or bolding typically represent H1 / H2 headings, implying absolute semantic blockage, the first visual penalty value is set relatively high, between 1.0 and 2.0. For list structures like list items, the second visual penalty value is set to a median value, such as 0.5, to handle the segmentation of enumerated content. The third visual penalty value corresponding to paragraph spacing is set to a low to medium value, such as 0.3 to 0.5, because paragraph spacing sometimes only represents natural segmentation, and semantic connections may still exist.

[0131] S1404. The first visual penalty value, the second visual penalty value, and the third visual penalty value are summed to obtain the total visual penalty value for visual penalty correction of the semantic similarity of the text unit in the same dimension.

[0132] As an example, the total visual penalty value Pvisual, which is a visual penalty correction applied to the semantic similarity of text units in the same dimension, consists of a first visual penalty value W1, a second visual penalty value W2, and a third visual penalty value W3. Pvisual = W1 + W2 + W3.

[0133] S1405. Based on the total visual penalty value, the semantic similarity of the text unit is corrected by visual penalty in the same dimension to obtain the corrected segmentation score of the current text unit.

[0134] The document segmentation method presented in this application does not ignore visual layout information when processing rich-format documents, thus avoiding the problem of decreased segmentation accuracy caused by discarding visual layout information. This document segmentation method is a lightweight multimodal fusion segmentation scheme. It applies a same-dimensional visual penalty fusion correction to semantic similarity based on the total visual penalty value, transforming visual distance into a penalty value for semantic similarity. For example, a weighted fusion strategy can be used to calculate the segmentation boundary by combining the semantic score and the visual penalty term. The corrected segmentation score combines the semantic similarity of the text and the visual layout features of the document object.

[0135] The step in S1405, which corrects the semantic similarity of text units based on the total visual penalty value to obtain the corrected segmentation score of the current text unit, includes steps B1-B4:

[0136] B1. Extract metadata from each text unit to obtain the text content corresponding to each text unit;

[0137] To further improve segmentation accuracy, document visual features are fused on top of semantic features, and a weighted fusion strategy is adopted to combine semantic scores and visual penalty terms.

[0138] In some embodiments, document segmentation is achieved by constructing a dual-stream feature extraction and fusion framework. The dual-stream feature extraction originates from both semantic and visual streams. Specifically, the semantic stream is used to calculate the vector similarity of the text content. The visual stream is used to parse the coordinates and style attributes of document objects and calculate the visual distance between adjacent text blocks. The visual distance is then converted into a penalty value for semantic similarity and fused, using the penalty value generated from the visual features to correct the semantic similarity score. Based on the final score after penaltying, the document is dynamically segmented.

[0139] Metadata is extracted from each text unit to obtain the text content corresponding to each text unit.

[0140] In some embodiments, the semantic similarity Simsemi is obtained by calculating the text similarity between adjacent text units of the document to be segmented through the text content extracted from the metadata; and the total visual penalty value Pvisual is calculated based on the visual features to correct the semantic similarity of the text units by parsing the coordinates and style attributes of the document object based on the visual flow.

[0141] B2. Based on a pre-trained language model, the text content is transformed to obtain a text vector corresponding to each text unit;

[0142] In some embodiments, the pre-trained language model can be BERT, RoBERTa, or various open-source embedding models, and is not limited to a specific model architecture. The text content is transformed based on the pre-trained language model to obtain a text vector corresponding to each text unit. The pre-trained language model is used to transform the text content Texti into vector Vi.

[0143] B3. Calculate the similarity between two adjacent text units with respect to the text vector to obtain the semantic similarity of the text units;

[0144] As an example, semantic coherence is determined by calculating the cosine similarity of the text vectors of adjacent sentences, resulting in the semantic similarity Simsemi of the text units. The cosine similarity between adjacent units ui-1 and ui is calculated as: Simsemi = Cos(Vi-1, Vi), where Vi is the vector of the current text unit and Vi-1 is the vector of the previous text unit.

[0145] B4. Calculate the corrected segmentation score of the current text unit based on the total visual penalty value and the semantic similarity of the text unit. The larger the total visual penalty value, the smaller the segmentation score.

[0146] The total visual penalty value calculated based on the document's visual features is used as the penalty value for visual correction of the current text unit.

[0147] The semantic similarity Simsemi of the text unit is weighted and fused with the total visual penalty value Pvisual(i) to obtain the corrected segmentation score of the current text unit. The larger the total visual penalty value, the smaller the segmentation score.

[0148] There are many types of weighted fusion strategies, such as:

[0149] The fusion strategy for linear subtraction is: Score = Simsemi - λ·Pvisual(i);

[0150] An alternative is the multiplicative decay fusion strategy: Score = Simsemi·(1- α·Pvisual(i));

[0151] An alternative is the exponential decay fusion strategy: Score = Simsemi·e-Pvisual(i).

[0152] Alternatively, a gated fusion strategy can be used, which avoids direct addition and subtraction operations and instead uses visual features as gating coefficients. Score = Simsemi × σ(LinearFeaturevisual), where σ is the sigmoid function, i.e., a decay coefficient between 0 and 1 is trained using visual features and directly affects the similarity score.

[0153] Any monotonic function that satisfies the condition that the higher the total visual penalty value, the lower the segmentation score will be. Alternatively, an alternative to the fusion approach is to use machine learning classifiers such as XGBoost (eXtreme Gradient Boosting) or MLP (Multi-Layer Perceptron), taking semantic similarity and visual features as input feature vectors, and training a binary classification model (segment / no segmentation) to output the segmentation decision.

[0154] S150. The document to be segmented is segmented based on the segmentation score to obtain multiple document blocks, wherein text units in the document to be segmented whose segmentation score is less than a preset segmentation threshold are disconnected from the previous text unit to obtain a new document block, and text units in the document to be segmented whose segmentation score is not less than the segmentation threshold are merged into the current document block.

[0155] After calculating the segmentation score based on document visual features or obtaining the total segmentation score by fusing document visual features and semantic similarity, the document to be segmented is divided into multiple document blocks based on the segmentation score. During segmentation, text units in the document to be segmented whose segmentation score is less than a preset segmentation threshold are disconnected from the previous text unit to obtain new document blocks, while text units in the document to be segmented whose segmentation score is not less than the segmentation threshold are merged into the current document block.

[0156] As an example, the overall process of this application is as follows: [Start] -> [Input PDF / Image] -> [Parse Text and Coordinates] -> [Parallel Branch A: Calculate Semantic Vector -> Calculate Semantic Similarity] / [Parallel Branch B: Extract Visual Features (Font Size / Indentation / Spacing) -> Calculate Visual Penalty Value (Total Visual Penalty Value)] -> [Data Fusion] -> [Threshold Determination for Segmentation] -> [Output] -> [End].

[0157] [Document Parsing Unit] --> [Feature Extraction Unit (including Semantic / Visual Sub-modules)] --> [Fusion Computation Unit] --> [Segmentation Execution Unit] --> [Knowledge Base Storage].

[0158] In some embodiments, in addition to the segmentation method in step S150, after step S140, which involves applying a visual penalty correction of the semantic similarity of text units based on the document's visual features to obtain the corrected segmentation score of the current text unit, steps C1-C3 are included:

[0159] C1. Starting from the first text unit, calculate the sum of the total segmentation scores for multiple text units within the sliding window;

[0160] Initialize the list of split points to be empty. Starting from the first text unit, iterate through each potential split point i between text units and calculate the sum of the total split scores of multiple text units within the sliding window.

[0161] C2. If the sum of the total number of segments exceeds the preset segmentation threshold, then the end of the current sliding window is recorded as a segmentation point, and all text units are traversed to obtain a list of segmentation points composed of multiple segmentation points.

[0162] If the sum of the total number of segments exceeds the preset segmentation threshold, the end of the current sliding window is recorded as a segmentation point. All text units are traversed to obtain a list of segmentation points composed of multiple segmentation points.

[0163] C3. The document to be segmented is segmented into multiple document blocks from the segmentation points indicated by the segmentation point list.

[0164] The document to be segmented is divided into multiple document blocks from the segmentation points indicated by the segmentation point list.

[0165] This method does not rely on explicit text symbols such as Markdown tags. Even if the OCR result loses the # symbol or list number, as long as the document retains visual layout features such as large font size, bolding, and indentation, this method can still accurately segment the document, demonstrating strong robustness.

[0166] By accurately identifying visual chapter boundaries, the phenomenon of incorrectly merging "titles" into "previous paragraph" is avoided, significantly improving the retrieval recall and accuracy of the knowledge base and enhancing RAG retrieval precision.

[0167] This method employs rule-based visual feature extraction. Compared to segmentation using large visual models such as LayoutLM (Layout Language Model), the computational cost of this method is negligible, making it suitable for real-time processing of large-scale documents and computationally efficient.

[0168] This application provides a document segmentation method, apparatus, computer device, and storage medium. In response to a document segmentation instruction, a document to be segmented is obtained; the document to be segmented is parsed to obtain multiple text units; based on the text units, document visual features related to document layout are determined, wherein the document visual features are not the text symbols themselves but rather represent the visual features perceived by the naked eye when browsing the document; based on the document visual features, the semantic similarity of the text units is corrected using a visual penalty of the same dimension to obtain a corrected segmentation score for the current text unit; based on the segmentation score, the document to be segmented is segmented to obtain multiple document blocks, wherein text units in the document to be segmented whose segmentation score is less than a preset segmentation threshold are disconnected from the previous text unit to obtain new document blocks, and text units in the document to be segmented whose segmentation score is not less than the segmentation threshold are merged into the current document block. In this application, the visual layout information of the document is referenced from a visual layout perspective, thus avoiding the text extraction quality defects caused by treating the document as a plain text stream and not relying on OCR. Instead, it segments the text based on the visual geometric layout of the document when users browse it, conforming to the browsing patterns of users reading documents, accurately identifying document structural boundaries, and improving the accuracy of text segmentation.

[0169] Figure 2 This is a schematic block diagram of a document segmentation device provided in an embodiment of this application. Figure 2 As shown, corresponding to the above document segmentation method, this application also provides a document segmentation apparatus 600. The document segmentation apparatus 600 includes a unit for performing the above document segmentation, and can be configured in terminals such as desktop computers, tablet computers, and laptops. Specifically, please refer to... Figure 2 The document segmentation device 600 includes an acquisition unit 601, a parsing unit 602, a determination unit 603, a calculation unit 604, and a segmentation unit 605, wherein:

[0170] The acquisition unit 601 is used to acquire the document to be segmented in response to the document segmentation instruction.

[0171] Parsing unit 602 is used to parse the document to be segmented to obtain multiple text units;

[0172] The determining unit 603 is used to determine document visual features related to document layout based on the text unit, wherein the document visual features are not the text symbols themselves but rather the screen features perceived by the naked eye when browsing the document.

[0173] The calculation unit 604 is used to perform the same-dimensional visual penalty correction on the semantic similarity of the text units based on the document's visual features, and obtain the corrected segmentation score of the current text unit.

[0174] The segmentation unit 605 is used to segment the document to be segmented into multiple document blocks based on the segmentation score, wherein text units in the document to be segmented whose segmentation score is less than a preset segmentation threshold are disconnected from the previous text unit to obtain a new document block, and text units in the document to be segmented whose segmentation score is not less than the segmentation threshold are merged into the current document block.

[0175] In some embodiments, the document visual features include any one of font size jump features, indentation abrupt changes, and vertical spacing features. The determining unit 603 is configured to perform the text-based unit to determine document visual features related to document layout, specifically for:

[0176] Metadata is extracted from each text unit to obtain the geometric coordinates and style attributes related to document layout for each text unit, wherein the style attributes related to document layout include font size;

[0177] If the font size of the current text unit is greater than the font size of the previous text unit, then first calculate the difference between the font size of the current text unit and the font size of the previous text unit, and then calculate the quotient between the difference and the font size of the previous text unit to obtain the font size jump feature of the current text.

[0178] Calculate the absolute value of the horizontal displacement between the left boundary coordinates of the current text unit and the left boundary coordinates of the previous text unit in the geometric coordinates to obtain the indentation abruptness feature of the current text.

[0179] Calculate the vertical displacement between the upper boundary coordinates of the current text unit and the lower boundary coordinates of the previous text unit in the geometric coordinates to obtain the vertical spacing feature of the current text.

[0180] In some embodiments, the style attributes related to document layout further include font weight. The calculation unit 604, after performing the same-dimensional visual penalty correction on the semantic similarity of text units based on the document's visual features to obtain the corrected segmentation score of the current text unit, is specifically used for:

[0181] If the font size jump feature exceeds the first threshold or the font weight is bold, then a first visual penalty value is determined to correct the semantic similarity of the text unit by the same dimension of font size jump visual penalty.

[0182] If the indentation mutation feature exceeds the second threshold, then a second visual penalty value is determined to correct the semantic similarity of the text unit by the same-dimensional visual penalty for indentation mutation.

[0183] If the vertical spacing feature exceeds a preset third threshold, a third visual penalty value is determined to correct the semantic similarity of the text units by the same dimension of vertical spacing visual penalty, wherein the first visual penalty value is greater than the second visual penalty value, and the second visual penalty value is greater than the third visual penalty value.

[0184] The first visual penalty value, the second visual penalty value, and the third visual penalty value are summed to obtain the total visual penalty value that corrects the semantic similarity of the text units in the same dimension.

[0185] Based on the total visual penalty value, the semantic similarity of the text units is corrected by visual penalty in the same dimension to obtain the corrected segmentation score of the current text unit.

[0186] In some embodiments, the calculation unit 604, when performing the step of determining a first visual penalty value for correcting the semantic similarity of text units by applying a visual penalty for font size abrupt changes in the same dimension if the font size abrupt feature exceeds a first threshold or the font weight is bold, specifically uses the following:

[0187] Based on the distribution of font size jump features for each font unit in all text units, determine the average value and standard deviation of the font size jump features;

[0188] Determine the type parameter corresponding to the document type of the document to be segmented. The first type parameter corresponding to the document type of magazine or brochure is greater than the second type parameter corresponding to the document type of academic paper or law and regulation. The second type parameter is greater than the third type parameter corresponding to the document type of financial research report or intensive report.

[0189] First, multiply the standard deviation by the type parameter corresponding to the document type, and then add it to the average value of the font size jump feature to obtain the first threshold;

[0190] If the font size jump feature exceeds the first threshold or the font weight is bold, then a first visual penalty value is determined to correct the semantic similarity of the text unit by applying the same-dimensional visual penalty for the font size jump.

[0191] In some embodiments, after applying a visual penalty correction of the semantic similarity of the text units based on the document's visual features to obtain the corrected segmentation score of the current text unit, the segmentation unit 605 is further specifically used for:

[0192] Starting from the first text unit, calculate the sum of the total segmentation scores for multiple text units within the sliding window;

[0193] If the sum of the total segmentation scores exceeds the preset segmentation threshold, then the end of the current sliding window is recorded as a segmentation point, and all text units are traversed to obtain a list of segmentation points composed of multiple segmentation points.

[0194] The document to be segmented is divided into multiple document blocks from the segmentation points indicated by the segmentation point list.

[0195] In some embodiments, the calculation unit 604, while performing the same-dimensional visual penalty correction on the semantic similarity of the text units based on the total visual penalty value to obtain the corrected segmentation score of the current text unit, is further specifically used for:

[0196] Metadata is extracted from each text unit to obtain the text content corresponding to each text unit;

[0197] The text content is transformed based on a pre-trained language model to obtain a text vector corresponding to each text unit.

[0198] Calculate the similarity between two adjacent text units with respect to the text vector to obtain the semantic similarity of the text units;

[0199] The segmentation score of the current text unit is calculated based on the total visual penalty value and the semantic similarity of the text unit. The larger the total visual penalty value, the smaller the segmentation score.

[0200] In some embodiments, the parsing unit 602, when performing the parsing of the document to be segmented to obtain multiple text units, is specifically used for:

[0201] The document to be segmented is parsed to obtain multiple text units, wherein each text unit is a line of text or a sentence;

[0202] Metadata extraction is performed on the text unit to obtain the center x-coordinate and center y-coordinate of the text unit;

[0203] If, after performing layout analysis based on the central horizontal and vertical coordinates, it is determined that the layout format of the document to be segmented is a non-single-column layout format, then, based on the central horizontal and vertical coordinates, multiple text units are reordered according to the logical order of reading to obtain a text unit sequence that conforms to the reading logic. The non-single-column layout format includes a two-column layout format or a multi-column layout format.

[0204] This application provides a document segmentation method, apparatus, computer device, and storage medium. In response to a document segmentation instruction, a document to be segmented is obtained; the document to be segmented is parsed to obtain multiple text units; based on the text units, document visual features related to document layout are determined, wherein the document visual features are not the text symbols themselves but rather represent the visual features perceived by the naked eye when browsing the document; based on the document visual features, the semantic similarity of the text units is corrected using a visual penalty of the same dimension to obtain a corrected segmentation score for the current text unit; based on the segmentation score, the document to be segmented is segmented to obtain multiple document blocks, wherein text units in the document to be segmented whose segmentation score is less than a preset segmentation threshold are disconnected from the previous text unit to obtain new document blocks, and text units in the document to be segmented whose segmentation score is not less than the segmentation threshold are merged into the current document block. In this application, the visual layout information of the document is referenced from a visual layout perspective, thus avoiding the text extraction quality defects caused by treating the document as a plain text stream and not relying on OCR. Instead, it segments the text based on the visual geometric layout of the document when users browse it, conforming to the browsing patterns of users reading documents, accurately identifying document structural boundaries, and improving the accuracy of text segmentation.

[0205] It should be noted that those skilled in the art can clearly understand that the specific implementation process of the above document segmentation device and each unit can be referred to the corresponding description in the foregoing method embodiments. For the sake of convenience and brevity, it will not be repeated here.

[0206] The aforementioned document segmentation device can be implemented as a computer program, which can, for example... Figure 3 It runs on the computer device shown.

[0207] Please see Figure 3 , Figure 3 This is a schematic block diagram of a computer device provided in an embodiment of this application. The computer device 700 can be a terminal or a server. The terminal can be an electronic computer device with communication functions, such as a smartphone, tablet, laptop, desktop computer, personal digital assistant, or wearable computer device. The server can be a standalone server or a server cluster composed of multiple servers.

[0208] See Figure 3 The computer device 700 includes a processor 702, a memory, and a network interface 705 connected via a system bus 701. The memory may include a non-volatile storage medium 703 and internal memory 704.

[0209] The non-volatile storage medium 703 may store an operating system 7031 and a computer program 7032. The computer program 7032 includes program instructions that, when executed, cause the processor 702 to perform a document splitting.

[0210] The processor 702 provides computing and control capabilities to support the operation of the entire computer device 700.

[0211] The internal memory 704 provides an environment for the execution of the computer program 7032 in the non-volatile storage medium 703. When the computer program 7032 is executed by the processor 702, the processor 702 can perform a document splitting.

[0212] This network interface 705 is used for network communication with other computer devices. Those skilled in the art will understand that... Figure 3 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device 700 to which the present application is applied. The specific computer device 700 may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0213] The processor 702 is used to run the computer program 7032 stored in the memory to perform the following steps:

[0214] In response to the document splitting instruction, obtain the document to be split;

[0215] The document to be segmented is parsed to obtain multiple text units;

[0216] Based on the text units, document visual features related to document layout are determined, wherein the document visual features are not the text symbols themselves but rather the visual features perceived by the naked eye when browsing the document.

[0217] Based on the document's visual features, the semantic similarity of text units is corrected using the same dimension of visual penalty to obtain the corrected segmentation score of the current text unit.

[0218] The document to be segmented is divided into multiple document blocks based on the segmentation score. Text units in the document to be segmented whose segmentation score is less than a preset segmentation threshold are disconnected from the previous text unit to obtain a new document block. Text units in the document to be segmented whose segmentation score is not less than the segmentation threshold are merged into the current document block.

[0219] It should be understood that in the embodiments of this application, the processor 702 may be a central processing unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.

[0220] It will be understood by those skilled in the art that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program includes program instructions and can be stored in a storage medium, which is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the process steps of the embodiments of the above methods.

[0221] Therefore, this application also provides a storage medium. This storage medium can be a computer-readable storage medium. The storage medium stores a computer program, wherein the computer program includes program instructions. When executed by a processor, the program instructions cause the processor to perform the following steps:

[0222] In response to the document splitting instruction, obtain the document to be split;

[0223] The document to be segmented is parsed to obtain multiple text units;

[0224] Based on the text units, document visual features related to document layout are determined, wherein the document visual features are not the text symbols themselves but rather the visual features perceived by the naked eye when browsing the document.

[0225] Based on the document's visual features, the semantic similarity of text units is corrected using the same dimension of visual penalty to obtain the corrected segmentation score of the current text unit.

[0226] The document to be segmented is divided into multiple document blocks based on the segmentation score. Text units in the document to be segmented whose segmentation score is less than a preset segmentation threshold are disconnected from the previous text unit to obtain a new document block. Text units in the document to be segmented whose segmentation score is not less than the segmentation threshold are merged into the current document block.

[0227] The storage medium can be any computer-readable storage medium that can store program code, such as a USB flash drive, external hard drive, read-only memory (ROM), magnetic disk, or optical disk.

[0228] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this application.

[0229] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For example, the division of each unit is merely a logical functional division, and there may be other division methods in actual implementation. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed.

[0230] The steps in the methods of this application embodiment can be adjusted, merged, or deleted according to actual needs. The units in the apparatus of this application embodiment can be merged, divided, or deleted according to actual needs. Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0231] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or 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, a terminal, or a network computer device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application.

[0232] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and these modifications or substitutions should all be covered within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A method of document segmentation, characterized by, The document segmentation method includes: In response to the document splitting instruction, obtain the document to be split; The document to be segmented is parsed to obtain multiple text units; Based on the text units, document visual features related to document layout are determined. These visual features include any one of font size jump features, indentation abrupt changes, and vertical spacing features. Metadata is extracted from each text unit to obtain its corresponding geometric coordinates and document layout-related style attributes, including font size and font weight. If the font size of the current text unit is greater than that of the previous text unit, the difference between the current and previous text unit font sizes is first calculated, and then the quotient between this difference and the previous text unit font size is calculated to obtain the font size jump feature of the current text. The absolute value of the horizontal displacement between the left boundary coordinates of the current text unit and the left boundary coordinates of the previous text unit in the geometric coordinates is calculated to obtain the indentation abrupt change feature of the current text. The vertical displacement between the top boundary coordinates of the current text unit and the bottom boundary coordinates of the previous text unit in the geometric coordinates is calculated to obtain the vertical spacing feature of the current text. Based on the document's visual features, the semantic similarity of text units is corrected using a visual penalty of the same dimension to obtain the corrected segmentation score of the current text unit. Specifically, if the font size jump feature exceeds a first threshold or the font weight is bold, a first visual penalty value is determined for the same-dimensional font size jump visual penalty correction of the text unit's semantic similarity. If the indentation abruptness feature exceeds a second threshold, a second visual penalty value is determined for the same-dimensional indentation abruptness visual penalty correction of the text unit's semantic similarity. If the vertical spacing feature exceeds a preset third threshold, a third visual penalty value is determined for the same-dimensional vertical spacing visual penalty correction of the text unit's semantic similarity, wherein the first visual penalty value is greater than the second visual penalty value, and the second visual penalty value is greater than the third visual penalty value. The first, second, and third visual penalty values ​​are summed to obtain the total visual penalty value for the same-dimensional visual penalty correction of the text unit's semantic similarity. Based on the total visual penalty value, the semantic similarity of the text unit is corrected using a visual penalty of the same dimension to obtain the corrected segmentation score of the current text unit. The document to be segmented is divided into multiple document blocks based on the segmentation score. Text units in the document to be segmented whose segmentation score is less than a preset segmentation threshold are disconnected from the previous text unit to obtain a new document block. Text units in the document to be segmented whose segmentation score is not less than the segmentation threshold are merged into the current document block.

2. The method of claim 1, wherein, If the font size abrupt change feature exceeds a first threshold or the font weight is bold, then a first visual penalty value is determined to correct the semantic similarity of the text units by applying a visual penalty for font size abrupt change in the same dimension, including: Based on the distribution of font size jump features for each font unit in all text units, determine the average value and standard deviation of the font size jump features; Determine the type parameter corresponding to the document type of the document to be segmented. The first type parameter corresponding to the document type of magazine or brochure is greater than the second type parameter corresponding to the document type of academic paper or law and regulation. The second type parameter is greater than the third type parameter corresponding to the document type of financial research report or intensive report. First, multiply the standard deviation by the type parameter corresponding to the document type, and then add it to the average value of the font size jump feature to obtain the first threshold; If the font size jump feature exceeds the first threshold or the font weight is bold, then a first visual penalty value is determined to correct the semantic similarity of the text unit by applying the same-dimensional visual penalty for the font size jump.

3. The method of claim 1, wherein, The step of applying the same-dimensional visual penalty correction to the semantic similarity of text units based on the total visual penalty value to obtain the corrected segmentation score of the current text unit includes: Metadata is extracted from each text unit to obtain the text content corresponding to each text unit; The text content is transformed based on a pre-trained language model to obtain a text vector corresponding to each text unit. Calculate the similarity between two adjacent text units with respect to the text vector to obtain the semantic similarity of the text units; The segmentation score of the current text unit is calculated based on the total visual penalty value and the semantic similarity of the text unit. The larger the total visual penalty value, the smaller the segmentation score.

4. The method of claim 1, wherein, After applying the same-dimensional visual penalty correction to the semantic similarity of text units based on the document's visual features to obtain the corrected segmentation score for the current text unit, the process includes: Starting from the first text unit, calculate the sum of the total segmentation scores for multiple text units within the sliding window; If the sum of the total segmentation scores exceeds the preset segmentation threshold, then the end of the current sliding window is recorded as a segmentation point, and all text units are traversed to obtain a list of segmentation points composed of multiple segmentation points. The document to be segmented is divided into multiple document blocks from the segmentation points indicated by the segmentation point list.

5. The method of claim 1, wherein, The document to be segmented is parsed to obtain multiple text units, including: The document to be segmented is parsed to obtain multiple text units, wherein each text unit is a line of text or a sentence; Metadata extraction is performed on the text unit to obtain the center x-coordinate and center y-coordinate of the text unit; If, after performing layout analysis based on the central horizontal and vertical coordinates, it is determined that the layout format of the document to be segmented is a non-single-column layout format, then, based on the central horizontal and vertical coordinates, multiple text units are reordered according to the logical order of reading to obtain a text unit sequence that conforms to the reading logic. The non-single-column layout format includes a two-column layout format or a multi-column layout format.

6. A document segmentation apparatus characterized by comprising: The document segmentation device includes: The acquisition unit is used to acquire the document to be segmented in response to the document segmentation instruction. The parsing unit is used to parse the document to be segmented to obtain multiple text units; A determining unit is used to determine document visual features related to document layout based on the text units. These visual features include any one of font size jump features, indentation abrupt changes, and vertical spacing features. Metadata extraction is performed on each text unit to obtain its corresponding geometric coordinates and document layout-related style attributes, including font size and font weight. If the font size of the current text unit is greater than that of the previous text unit, the difference between the current and previous text unit font sizes is first calculated, and then the quotient between this difference and the previous text unit font size is calculated to obtain the font size jump feature of the current text. The absolute value of the horizontal displacement between the left boundary coordinates of the current text unit and the left boundary coordinates of the previous text unit in the geometric coordinates is calculated to obtain the indentation abrupt change feature of the current text. The vertical displacement between the upper boundary coordinates of the current text unit and the lower boundary coordinates of the previous text unit in the geometric coordinates is calculated to obtain the vertical spacing feature of the current text. A calculation unit is used to perform visual penalty correction on the semantic similarity of text units based on the document's visual features, obtaining the corrected segmentation score of the current text unit. Specifically, if the font size jump feature exceeds a first threshold or the font weight is bold, a first visual penalty value is determined for the same-dimensional font size jump visual penalty correction of the text unit's semantic similarity; if the indentation abruptness feature exceeds a second threshold, a second visual penalty value is determined for the same-dimensional indentation abruptness visual penalty correction of the text unit's semantic similarity; if the vertical spacing feature exceeds a preset third threshold, a third visual penalty value is determined for the same-dimensional vertical spacing visual penalty correction of the text unit's semantic similarity, wherein the first visual penalty value is greater than the second visual penalty value, and the second visual penalty value is greater than the third visual penalty value; the first visual penalty value, the second visual penalty value, and the third visual penalty value are summed to obtain a total visual penalty value for the same-dimensional visual penalty correction of the text unit's semantic similarity; based on the total visual penalty value, the same-dimensional visual penalty correction is performed on the semantic similarity of the text unit to obtain the corrected segmentation score of the current text unit. A segmentation unit is used to segment the document to be segmented into multiple document blocks based on the segmentation score, wherein text units in the document to be segmented whose segmentation score is less than a preset segmentation threshold are disconnected from the previous text unit to obtain a new document block, and text units in the document to be segmented whose segmentation score is not less than the segmentation threshold are merged into the current document block.

7. A document segmentation computer device, comprising: The document includes a memory, a processor, and a document segmentation program stored in the memory and executable on the processor, wherein the processor executes the document segmentation program to implement the steps of the document segmentation method according to any one of claims 1 to 5.

8. A storage medium, characterized by The storage medium stores a program that implements a document segmentation method, which is executed by a processor to implement the steps of the document segmentation method as described in any one of claims 1 to 5.