Legal document processing method, computer readable storage medium and electronic device
By using multilingual models to quality check and correct candidate segmentation results, the problem of insufficient semantic segmentation accuracy in legal text processing was solved, achieving automated processing, improved efficiency, and reduced costs, thereby enhancing the data value of the RAG dataset.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HANGZHOU FIVE DIMENSIONAL DATA CO LTD
- Filing Date
- 2026-04-16
- Publication Date
- 2026-07-21
AI Technical Summary
Existing semantic segmentation methods lack accuracy in legal text processing, failing to accurately identify the boundaries of legal clauses, leading to the destruction of semantic integrity and logical units. Furthermore, general models are insufficient in their ability to understand legal texts and cannot fully learn deep semantic and structural features.
By determining a set of candidate semantic blocks and using multiple large language models to perform quality checks and corrections on the candidate semantic block results, the quality check results of multiple large language models are integrated to obtain the final semantic block results and construct the RAG dataset.
It automates, improves efficiency, and reduces costs in legal text processing, while significantly improving the accuracy of semantic segmentation and enhancing the data value of the RAG dataset.
Smart Images

Figure CN122047228B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of natural language processing technology, specifically to legal text processing methods, computer-readable storage media, and electronic devices. Background Technology
[0002] Retrieval-Augmented Generation (RAG) technology aims to combine information retrieval with large language models, providing traceable information source support by retrieving relevant document fragments, thereby effectively mitigating the illusion problem in large language models. RAG technology has demonstrated excellent results in various knowledge-intensive tasks, such as text generation and information extraction tasks from different fields like medicine, law, and finance, from its early stages. In recent years, RAG technology has also been widely applied in natural language processing tasks that require substantial external knowledge support.
[0003] Semantic segmentation of text is a core technique in RAG (Retrieval and Encoding) technology, and the results directly impact the quality of search results. When semantically segmenting legal text, traditional methods typically operate on a fixed length, such as segmenting based on a set number of characters or words. In addition, there are other semantic segmentation methods, such as segmenting by paragraph or sentence and methods based on pre-trained models. Methods based on pre-trained models use a general model to calculate the semantic similarity between sentences, thus segmenting the legal text based on semantic similarity.
[0004] However, due to the close relationship between clauses in legal texts and the highly specialized nature of their language, all of the above-mentioned semantic segmentation methods suffer from insufficient accuracy in semantic segmentation. The application of RAG technology in the legal field still faces serious challenges. Summary of the Invention
[0005] This invention aims to address, to a certain extent, one of the technical problems in related technologies. To this end, this invention provides a legal text processing method, a computer-readable storage medium, and an electronic device, which have the advantages of automatically constructing the legal text to be processed into a RAG dataset, improving the processing efficiency of legal text, reducing the processing cost of legal text, and significantly improving the accuracy of semantic segmentation of legal text, thereby enhancing the data value of the legal text RAG dataset.
[0006] To achieve the above objectives, the present invention adopts the following technical solution:
[0007] A legal text processing method, the method comprising:
[0008] Based on the legal text to be processed, a set of candidate blocks is determined;
[0009] The candidate block set and the pre-built block verification prompts are input into multiple large language models to obtain the block verification results output by the multiple large language models.
[0010] The candidate block set is revised based on multiple block test results to obtain the final block set;
[0011] Based on the final set of blocks, a retrieval-enhanced RAG dataset is constructed.
[0012] The above-mentioned technical solution of the present invention can automatically construct a RAG dataset from legal texts to be processed, improve the processing efficiency of legal texts, reduce the processing cost of legal texts, and significantly improve the accuracy of semantic segmentation of legal texts, thereby enhancing the data value of the RAG dataset of legal texts.
[0013] Optionally, the block verification result includes the judgment result of the initial boundary between any two adjacent blocks in the candidate block set; the step of correcting the candidate block set according to multiple block verification results to obtain the final block set includes:
[0014] Based on multiple judgment results, decisions are made on each initial boundary in the candidate block set to obtain the decision results for each initial boundary;
[0015] Based on the decision results of each initial boundary, the final block set is determined.
[0016] Optionally, the step of making decisions on each initial boundary in the candidate block set based on multiple judgment results to obtain decision results for each initial boundary includes:
[0017] For any of the initial boundaries, if more than a preset proportion of the judgment results determine that it is accurate, the decision result is determined to be retained; if more than a preset proportion of the judgment results determine that it is inaccurate, the decision result is determined to be cancelled.
[0018] Optionally, the block verification result further includes the result of adding new boundaries for blocks in the candidate block set; determining the final block set based on the decision results of each initial boundary includes:
[0019] If the number of identical new boundary results exceeds a preset number, new boundaries are added in the corresponding blocks based on the identical new boundary results to obtain the decision result of the new boundaries;
[0020] The final block set is determined based on the decision results of each initial boundary and the decision results of the newly added boundaries.
[0021] Optionally, determining the candidate block set based on the legal text to be processed includes:
[0022] The legal text to be processed is converted into structured text, and the legal semantic type of the legal text to be processed is identified;
[0023] Based on the legal semantic type and the structured text, the legal structural features and document structural features of the legal text to be processed are identified; wherein, the legal semantic type includes legal regulations type and judicial judgment type, the legal structural features of the legal text to be processed belonging to the legal regulations type include compilation features, chapter features, section features, article features, clause features, item features, and sub-item features; the legal structural features of the legal text to be processed belonging to the judicial judgment type include cause of action features, factual features, reasoning features, and judgment features;
[0024] Based on the structured text, the legal structural features, and the document structural features, a candidate block set is determined.
[0025] Optionally, determining the candidate block set based on the structured text, the legal structural features, and its document structural features includes:
[0026] Based on the structured text, the legal structural features, and the document structural features, an initial set of blocks is constructed;
[0027] For any block in the initial block set whose word count exceeds a preset word count threshold, calculate the semantic similarity of each adjacent sentence pair in the block, and perform a secondary segmentation between any adjacent sentence pair if the semantic similarity of any adjacent sentence pair is less than a preset similarity threshold.
[0028] The candidate block set is obtained by summarizing the secondary segmentation results of the initial block set.
[0029] Optionally, constructing the retrieval-enhanced RAG dataset based on the final chunk set includes:
[0030] Construct question generation prompts; wherein, the question generation prompts are used to prompt a pre-trained data augmentation model to generate legal questions of a specified type, the specified type including those covering direct factual questions, applicable scenario questions, comparative analysis questions, and case application questions;
[0031] The final block set and the prompt words are input into the data augmentation model to obtain a set of data augmentation units output by the data augmentation model for each block in the final block set.
[0032] Integrate the final block set and the data augmentation unit set to obtain a data augmentation block set;
[0033] Based on the data augmentation block set, a retrieval-enhanced RAG dataset is constructed.
[0034] The legal text processing method provided by this invention determines a candidate block set based on the legal text to be processed. The candidate block set and pre-constructed block verification prompts are input into multiple large language models to obtain block verification results output by the multiple large language models. The candidate block set is then corrected based on these block verification results to obtain a final block set. Finally, a RAG dataset is constructed based on the final block set. By first determining candidate semantic block results, then using multiple large language models to perform quality checks on these results, and integrating the quality check results from multiple large language models to correct the candidate semantic block results, a final semantic block result is obtained. Finally, a RAG dataset is constructed based on the final semantic block result. This method can automatically construct a RAG dataset from the legal text to be processed, improve the processing efficiency of legal text, reduce the processing cost of legal text, and significantly improve the accuracy of semantic block segmentation of legal text, thereby enhancing the data value of the RAG dataset of legal text.
[0035] Furthermore, the present invention also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the above-described legal text processing method.
[0036] Meanwhile, an electronic device includes a memory and a processor, the memory storing a computer program that, when executed by the processor, implements the aforementioned legal text processing method.
[0037] These features and advantages of the present invention will be disclosed in detail in the following specific embodiments and accompanying drawings. The preferred embodiments or means of the present invention will be shown in detail in conjunction with the accompanying drawings, but are not intended to limit the technical solutions of the present invention. In addition, each of these features, elements and components appearing in the following text and drawings is a plurality of, and different symbols or numbers are used for convenience of representation, but all represent parts with the same or similar construction or function. Attached Figure Description
[0038] The present invention will be further described below with reference to the accompanying drawings:
[0039] Figure 1 A flowchart illustrating one embodiment of a legal text processing method provided in this invention;
[0040] Figure 2A flowchart illustrating an embodiment of the present invention for correcting an initial block set based on multiple block inspection results;
[0041] Figure 3 This is a flowchart illustrating an implementation method for making decisions on each initial boundary in a candidate block set based on multiple judgment results, as provided in an embodiment of the present invention.
[0042] Figure 4 A flowchart illustrating an implementation method for determining the final block set based on the results of newly added boundaries, as provided in an embodiment of the present invention;
[0043] Figure 5 A flowchart illustrating an implementation method for determining a candidate block set based on legal text to be processed, provided in an embodiment of the present invention;
[0044] Figure 6 A flowchart illustrating an implementation method for determining a candidate block set based on structured text and legal structural features, as provided in this embodiment of the invention.
[0045] Figure 7 A flowchart illustrating one implementation of constructing a RAG dataset based on the final block set provided in this embodiment of the invention;
[0046] Figure 8 A block diagram illustrating one embodiment of the electronic device provided in this invention;
[0047] Figure 9 A schematic diagram of a computer-readable storage medium provided in an embodiment of the present invention;
[0048] Explanation of reference numerals in the attached figures
[0049] 101: Processor, 102: Memory, 103: I / O interface, 104: Bus. Detailed Implementation
[0050] Embodiments of the present invention are described in detail below, examples of which are illustrated in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described are intended to explain the present invention and should not be construed as limiting the invention.
[0051] The terms "an embodiment," "example," or "trademark" used in this specification refer to a particular feature, structure, or characteristic described in connection with the embodiment itself that may be included in at least one embodiment disclosed in this invention. The phrase "in an embodiment" appearing in various places throughout the specification does not necessarily refer to the same embodiment.
[0052] RAG (Related Aspects of Language) technology aims to combine information retrieval with large language models, providing traceable information source support by retrieving relevant document fragments, thereby effectively mitigating the illusion problem in large language models. RAG technology has demonstrated excellent results in various knowledge-intensive tasks, such as text generation and information extraction tasks from different fields like medicine, law, and finance, from its early stages. In recent years, RAG technology has also been widely applied in natural language processing tasks that require substantial external knowledge support.
[0053] Semantic segmentation of text is a core technique in RAG (Retrieval and Encoding) technology, and the results directly impact the quality of search results. When semantically segmenting legal text, traditional methods typically operate on a fixed length, such as segmenting based on a set number of characters or words. In addition, there are other semantic segmentation methods, such as segmenting by paragraph or sentence and methods based on pre-trained models. Methods based on pre-trained models use a general model to calculate the semantic similarity between sentences, thus segmenting the legal text based on semantic similarity.
[0054] However, the inventors of this invention have discovered that due to the close relationship between clauses in legal texts and the highly specialized nature of their language, the aforementioned semantic segmentation methods all suffer from insufficient accuracy in semantic segmentation. Specifically, while traditional semantic segmentation methods are simple and easy to implement, they cannot accurately identify the boundaries of legal clauses, often erroneously truncating key information and thus compromising semantic integrity. While methods that segment semantically by paragraph or sentence can ensure the integrity of the grammatical structure, they cannot fully consider the characteristic that logical units in legal texts typically span multiple paragraphs. Methods based on pre-trained models cannot fully learn the deep semantic and structural features of legal texts due to the insufficient understanding of general models. Therefore, the application of RAG technology in the legal field still faces serious challenges.
[0055] In response, the inventors of this invention propose that by first identifying candidate semantic segmentation results, then using multiple large language models to jointly perform quality checks on the candidate semantic segmentation results, and integrating the quality check results of multiple large language models to correct the candidate semantic segmentation results, a final semantic segmentation result is obtained. Finally, a RAG dataset is constructed based on the final semantic segmentation result. This approach can automatically construct a RAG dataset from the legal text to be processed, improve the processing efficiency of legal text, reduce the processing cost of legal text, and significantly improve the accuracy of semantic segmentation of legal text, thereby enhancing the data value of the RAG dataset of legal text.
[0056] As a first aspect of the present invention, a legal text processing method is provided, such as... Figure 1 As shown, it includes the following steps:
[0057] In step S110, a candidate block set is determined based on the legal text to be processed;
[0058] In step S120, the candidate block set and the pre-constructed block verification prompts are input into multiple large language models to obtain the block verification results output by the multiple large language models.
[0059] In step S130, the candidate block set is corrected based on multiple block test results to obtain the final block set;
[0060] In step S140, the RAG dataset is constructed based on the final set of blocks.
[0061] In this embodiment of the invention, no special limitation is made on how to obtain the legal text to be processed. For example, the legal text to be processed can be received from user input, or the legal text to be processed can be obtained automatically in response to user input instructions or addresses.
[0062] It can be understood that the candidate block set is obtained after processing the legal text to be processed. It is equivalent to the candidate semantic block result, which includes multiple candidate semantic blocks, and there are boundaries between two adjacent semantic blocks.
[0063] Among them, multiple large language models verify the candidate semantic block results to output block verification results. The block verification results carry unreasonable boundaries in the candidate block set determined by the large language models, thereby correcting the candidate block set accordingly.
[0064] By aggregating differentiated correction suggestions from multiple large language models, the candidate segmentation set is corrected. This not only eliminates the bias and noise interference of a single model, but also retains the better decisions of multiple models. It can automatically determine the segmentation scheme without human intervention, thereby improving the quality of semantic segmentation.
[0065] It can be understood that the final set of chunks is equivalent to the final semantic chunking result, which includes multiple final semantic chunks.
[0066] In this embodiment of the invention, no special limitation is made on how to construct the RAG dataset based on the final block set. For example, some or all of the data involved in the execution of the legal text processing method in this embodiment of the invention can be stored in different directories according to a pre-defined standard directory structure.
[0067] The legal text processing method provided in this invention determines a candidate block set based on the legal text to be processed. The candidate block set and pre-constructed block verification prompts are input into multiple large language models to obtain block verification results output by the multiple large language models. The candidate block set is then corrected based on these block verification results to obtain a final block set. Finally, a RAG dataset is constructed based on the final block set. By first determining candidate semantic block results, then using multiple large language models to perform quality checks on these results, and integrating the quality check results from multiple large language models to correct the candidate semantic block results, a final semantic block result is obtained. Finally, a RAG dataset is constructed based on the final semantic block result. This method can automatically construct a RAG dataset from the legal text to be processed, improving the processing efficiency and reducing the processing cost. It can also significantly improve the accuracy of semantic block segmentation of legal text, thereby enhancing the data value of the RAG dataset.
[0068] Furthermore, by replacing and fine-tuning the model, the legal text processing method provided in this embodiment of the invention can also be applied to specific legal fields (such as criminal law, administrative law, and intellectual property law) and other professional fields (such as medical, financial, and technological fields) with low migration costs.
[0069] The inventors of this invention further propose that multiple large language models can provide a block verification result by verifying whether each initial boundary in the candidate block set is accurately divided. Accordingly, in some embodiments, the block verification result includes the judgment result of the initial boundary between any two adjacent blocks in the candidate block set; such as... Figure 2 As shown, the step of revising the candidate block set based on multiple block test results to obtain the final block set (i.e., the one involved in step S130 above) includes the following steps:
[0070] In step S210, based on the multiple judgment results, decisions are made on each of the initial boundaries in the candidate block set to obtain the decision results for each of the initial boundaries;
[0071] In step S220, the final block set is determined based on the decision results of each initial boundary.
[0072] In this embodiment of the invention, the form of the judgment result is not specifically limited. The two types of judgment results, "accurate division" and "inaccurate division", can be distinguished according to the preset fields. For example, the judgment result can be expressed as "0" or "1" ("0" and "1" represent the judgment result as accurate division and inaccurate division, respectively), "Y" or "X" ("Y" and "X" represent the judgment result as accurate division and inaccurate division, respectively), "accurate" or "inaccurate", etc.
[0073] In this embodiment of the invention, there are no special limitations on how step S210 is specifically executed. For example, a voting mechanism can be adopted, and the decision can be made using principles such as veto, majority rule, or absolute majority rule. A veto means that if any of the multiple judgment results is considered inaccurate, the corresponding initial boundary is canceled. Majority rule means that if the number of multiple judgment results considered accurate exceeds the number considered inaccurate, the corresponding initial boundary is retained. Absolute majority rule means that if the number of multiple judgment results considered accurate reaches a certain proportion, the corresponding initial boundary is retained.
[0074] The decision-making mechanism in this embodiment first utilizes the extensive semantic analysis capabilities of multiple large language models, that is, it uses multiple large language models to judge the accuracy of the division of each initial boundary in the candidate block set, and integrates the judgment results of multiple large language models to make decisions on each initial boundary. This can initially achieve effective correction of unreasonable initial boundaries, thereby effectively improving the accuracy of semantic block division and thus improving the delivery quality of RAG datasets for legal texts without human intervention.
[0075] The inventors of this invention further propose that, as one implementation method that is more conducive to improving the accuracy of semantic segmentation, an absolute majority vote can be used to decide on each initial boundary. Accordingly, in some embodiments, such as... Figure 3 As shown, the step of making decisions on each initial boundary in the candidate block set based on multiple judgment results to obtain the decision result of each initial boundary (i.e., the one involved in step S210 above) includes the following steps:
[0076] In step S310, for any of the initial boundaries, if the judgment results exceeding a preset proportion determine that it is accurate, the decision result is determined to be retained; if the judgment results exceeding a preset proportion determine that it is inaccurate, the decision result is determined to be cancelled.
[0077] In this embodiment of the invention, the preset ratio is not specifically limited. For example, the preset ratio can be 2 / 3, 70%, 0.8, etc.
[0078] To illustrate with a specific example, suppose the judgment result is represented as "0" or "1", the number of large language models participating in the verification is 6 and the preset ratio is 70%. For an initial boundary A in the candidate block set, if 5 or more large language models output a judgment result of "1", that is, more than 70% of the judgment results judge it as accurate, then the decision result of the initial boundary A is "retain", that is, maintain the current block boundary; if 5 or more large language models output a judgment result of "0", that is, more than 70% of the judgment results judge it as inaccurate, then the decision result of the initial boundary A is "cancel", that is, delete the current boundary so that the two adjacent blocks originally separated by the initial boundary A are merged into one block.
[0079] During the process of refining the candidate block set, it is necessary to consider that there may still be unidentified reasonable boundaries in the candidate block set. Therefore, in addition to verifying the existing initial boundaries, multiple large language models can be used to identify whether new boundaries need to be added. Accordingly, in some embodiments, such as Figure 4 As shown, the block verification result also includes the result of adding new boundaries to the blocks in the candidate block set; the step of determining the final block set (i.e., the one involved in step S210 above) based on the decision results of each initial boundary includes the following steps:
[0080] In step S410, if the number of identical new boundary results exceeds a preset number, new boundaries are added in the corresponding blocks based on the identical new boundary results to obtain the decision result of the new boundaries;
[0081] In step S420, the final block set is determined based on the decision results of each of the initial boundaries and the decision results of the newly added boundaries.
[0082] In this embodiment of the invention, the representation of the newly added boundary result is not specifically limited. The two types of newly added boundary results, "new boundary" and "no new boundary", are distinguished according to the preset fields, and the position of the newly added boundary is represented. For example, the newly added boundary result can be represented as "0" or "1" ("0" and "1" represent that the newly added boundary result is a newly added boundary and no new boundary, respectively), "Y" or "X" ("Y" and "X" represent that the newly added boundary result is a newly added boundary and no new boundary, respectively), "new boundary" or "no new boundary", etc. The position of the newly added boundary can be represented as "sentence M-sentence N", "Mth character-Nth character", "paragraph M-paragraph N", etc., which respectively indicate that the position of the newly added boundary is between the Mth sentence and the Nth sentence, between the Mth character and the Nth character, and between the Mth paragraph and the Nth paragraph in the current block.
[0083] In this embodiment of the invention, the preset quantity is not specifically limited, and the preset quantity can be determined based on the number of large language models participating in the verification and the set ratio.
[0084] For example, the preset number can be set to a proportion or higher than one-half, two-thirds, or four-fifths of the total number of large language models participating in the validation. For instance, if there are 6 large language models participating in the validation, the preset number is 4; if there are 5 large language models participating in the validation, the preset number is 3, and so on. To illustrate with a specific embodiment, assume the new boundary result is represented as "0" or "1", the number of large language models participating in the verification is 6 and the preset number is 3, and for a candidate block B in the candidate block set; the candidate block B has no initial boundary, after verification by the 6 large language models, if 4 or more large language models all carry "1" and "sentence M-sentence N" in their output new boundary results, that is, more than 3 identical new boundary results, then the decision result for adding a boundary is to add a boundary between the Mth sentence and the Nth sentence of the current block. The subsequent step S420 can split the candidate block B at this position to obtain two new blocks B1 and B2; conversely, if the positions of the new boundary in the output new boundary results of multiple large language models are different, or the number of new boundary results supporting the addition of a boundary does not exceed the preset number, then no boundary is added temporarily, that is, the original structure of the candidate block B is maintained. This invention employs a multi-model validation voting decision to filter out new boundaries, avoiding situations where initial boundaries are insufficient in the candidate block set. This effectively improves the accuracy of semantic block segmentation. By integrating the decision results of all initial boundaries and the decision results of new boundaries, the candidate blocks are corrected, ultimately resulting in a final block set with a reasonable structure and complete semantics, significantly improving the accuracy of semantic block segmentation of legal texts.
[0085] The inventors of this invention have also discovered that there are currently some rule-based semantic segmentation methods in the field, namely, semantic segmentation by identifying document structural features such as titles and numbers. However, there are significant differences in document structure between legal texts from different sources, which makes rule-based semantic segmentation methods less universal. Furthermore, there are also significant differences in legal structure between legal texts of different legal semantic types, which is also detrimental to semantic segmentation of legal texts.
[0086] In response, the inventors of this invention further propose that by uniformly converting the legal text to be processed into structured text and identifying its legal structural features, a more accurate set of candidate blocks can be obtained, thereby further improving the accuracy of semantic block segmentation of legal text. Accordingly, in some embodiments, such as... Figure 5As shown, determining the candidate block set (i.e., the step involved in step S110 above) based on the legal text to be processed includes the following steps:
[0087] In step S510, the legal text to be processed is converted into structured text, and the legal semantic type of the legal text to be processed is identified;
[0088] In step S520, based on the legal semantic type and the structured text, the legal structural features and document structural features of the legal text to be processed are identified; wherein, the legal semantic type includes legal regulations type and judicial judgment type, the legal structural features of the legal text to be processed belonging to the legal regulations type include compilation features, chapter features, section features, article features, clause features, item features, and sub-item features; the legal structural features of the legal text to be processed belonging to the judicial judgment type include cause of action features, factual features, reasoning features, and judgment features;
[0089] In step S530, a candidate block set is determined based on the structured text, the legal structure features, and the document structure features.
[0090] In this embodiment of the invention, the legal text to be processed can be converted into structured text using Vision-Language Model based Optical Character Recognition (VLM-OCR) trained on a legal corpus.
[0091] Specifically, the legal text to be processed is usually in PDF format. Before converting the legal text to be processed into structured text, binary verification can be performed on the legal text to ensure that the legal text to be processed is a complete, undamaged and parseable PDF text.
[0092] The verified PDF version of the legal text to be processed is input into the VLM-OCR model. The VLM-OCR model performs type extraction and preliminary format conversion on the verified PDF version of the legal text to obtain preliminary structured text. Then, unnecessary type structures are removed to obtain the final structured text. For example, unnecessary type structures include footnotes, icons, tables, lists, etc. Then, the embedded large language model identifies the legal semantic type of the final structured text. The legal semantic type includes legal regulations and judicial judgments. The multimodal recognition of the VLM-OCR model can reduce false judgments and achieve refined recognition of complex and non-standard format legal text documents.
[0093] Among them, the VLM-OCR model trained on legal corpus can accurately recognize legal professional terms, special symbols, multi-level clause numbers (such as "Article 103", "(I)", etc.), and complex formats such as tables and lists. The recognition process emphasizes the preservation of the format and retains the original document's paragraph structure, hierarchical relationship, numbering and indentation as much as possible. Finally, the recognition results can be converted into editable structured text (.json format).
[0094] Among them, the legal structural features of the pending legal texts belonging to the category of laws and regulations include section features, chapter features, section features, article features, clause features, item features, and sub-item features; the legal structural features of the pending legal texts belonging to the category of judicial judgments include cause of action features, factual features, reasoning features, and judgment features. In addition, based on the physical typesetting format of structured text, the document structural features corresponding to the legal structural features are also identified, such as paragraph marks, format marks, page number ranges, etc.
[0095] For example, a certain type of legal text to be processed has the following legal structure features: Part One General Provisions, Chapter One General Provisions, Section One Delivery of the Subject Matter and Transfer of Ownership, Article Five Hundred and Ninety-Five, Clauses (I) (II), Items (1.), and headings (1) (2); Document structure features include: Paragraph marks “Title Paragraph (Chapter One General Provisions): on a separate line, bold font, centered; Body Paragraph: complete article-level content, on a separate paragraph, first line indented by 2 characters”, and format marks. "Line breaks and blank lines (one blank line between chapter title and section title, one blank line between section title and the first article, one blank line between different articles), font style (chapter and section titles are bold 12pt, article numbers are bold 12pt, and the article text and subsequent legal structure features are bold 12pt), special marks (legal citations are marked with 《》), page range; a certain type of judicial judgment pending legal text: legal structure features include cause of action "dispute over a house sale contract", factual features "the court finds as follows", reasoning features "the court holds", and judgment features "the judgment is as follows"; document structure features include: paragraph marks "cause of action title paragraph: separate line, bold font, centered, one blank line below", format marks "title format: bold, 12pt, centered; alignment: title, case number, collegial panel member information centered, party information text paragraph left-aligned, page number right-aligned", page range.
[0096] In the extraction process, this invention combines the professionalism and special characteristics of the legal field, and uses special rules based on legal semantic types to identify legal structural features, which can ensure the accuracy of feature identification and extraction, thereby further improving the accuracy of semantic segmentation of legal texts.
[0097] Furthermore, the inventors of this invention propose that the legal text to be processed is usually in PDF format. Before converting the legal text to be processed into structured text, binary verification can be performed on the legal text to be processed to ensure that the legal text to be processed is a complete, undamaged, and parseable PDF text.
[0098] The inventors of this invention further propose that, in determining the candidate block set, an initial block set can first be constructed based on the legal structural features of the structured text and the legal text to be processed. Then, the initial block set can be further adjusted based on semantic similarity to obtain the candidate block set. Correspondingly, in some embodiments, such as... Figure 6 As shown, determining the candidate block set (i.e., involved in step S530 above) based on the structured text, the legal structure features, and the document structure features includes the following steps:
[0099] In step S610, an initial set of blocks is constructed based on the structured text, the legal structural features, and the document structural features.
[0100] In step S620, for any block in the initial block set whose word count exceeds a preset word count threshold, the semantic similarity of each adjacent sentence pair in the block is calculated, and if the semantic similarity of any adjacent sentence pair is less than a preset similarity threshold, a secondary segmentation is performed between any adjacent sentence pair.
[0101] In step S630, the secondary segmentation results of the initial block set are summarized to obtain the candidate block set.
[0102] In this embodiment of the invention, there are no special limitations on how step S610 is specifically executed. For example, a document structure tree can be constructed based on the structured text, the legal structure features, and the document structure features. The legal structure features prioritize locating core block units. For legal and regulatory texts, the "article" is used as the basic block unit. If an article contains multiple clauses, items, or sub-items and the content is logically independent, then the "clause," "item," or "sub-item" is used as the basic block unit, prioritizing the smallest independent legal structure unit as the base for block division. The document structure features verify the rationality of the block boundaries and check the legal structure unit. The distribution of physical paragraphs corresponding to "items", "clauses", "sections", etc.: If all the content of a legal structural unit (such as "section") is within the same physical paragraph and there are no formatting separations such as line breaks or indentation, then the legal structural unit is directly used as the block, and the functional boundary is consistent with the paragraph boundary; if a physical paragraph contains multiple legal structural units (such as "Article 1, Paragraph 1" and "Article 1, Paragraph 2" appearing in a paragraph at the same time, and there are no formatting separations), it is split according to the legal structural unit, and "paragraph 1" and "paragraph 2" are treated as independent blocks, even if they are within the same physical paragraph, the independence of legal semantics is given priority;
[0103] For judicial judgment texts, the basic unit of division is "cause of action, facts, reasons, and judgment." Each unit may contain multiple physical paragraphs, which need to be further divided according to document structure characteristics: if there are logical separations between physical paragraphs within the same unit (e.g., "plaintiff's statement" and "defendant's response" are independent paragraphs in the facts unit), each logical paragraph is considered an independent block under that unit; if multiple physical paragraphs within the same unit revolve around the same core fact (e.g., "I. Return of loan," "II. Payment of interest," and "III. Liability for case acceptance fee" are independent paragraphs in the judgment unit), each independent judgment paragraph is considered an independent block; legal structure characteristics determine the functional boundaries of the blocks, while document structure characteristics determine the physical boundaries. Legal structure characteristics are the core, and document structure characteristics are the auxiliary adjustment basis. By constructing an initial set of blocks based on the logically sound legal structure characteristics of the legal text itself, the core semantics of technical terms or paragraphs can be avoided from being broken down, thus improving the accuracy of semantic segmentation.
[0104] In this embodiment, the preset word count threshold is not specifically limited. For example, the preset word count threshold can be 700 words, 800 words, 900 words, etc.
[0105] For initial blocks whose word count exceeds a preset word count threshold, the semantic similarity of each adjacent sentence pair within the initial block is further calculated, as follows:
[0106] First, each sentence is converted into a vector representation using a pre-trained oracle model (e.g., LawBERT or BERT) fine-tuned with a legal corpus. The calculation formula is as follows:
[0107] …………………………………(2);
[0108] In formula (2), Indicates the first One sentence. This refers to a pre-trained language model that has been fine-tuned with legal corpora. Indicates the first Semantic vector representation of each sentence;
[0109] Then, the semantic similarity is calculated using the cosine similarity algorithm to determine the cosine of the vectors of adjacent sentence pairs in the initial block set. The semantic similarity value falls within the range [0,1]. The closer the value is to 1, the higher the semantic similarity between adjacent sentence pairs; the closer the value is to 0, the lower the semantic similarity between adjacent sentence pairs. The calculation formula is as follows:
[0110] …………………………………………………………(3);
[0111] In formula (3), Indicates the first One sentence. Indicates the ( One sentence. Indicates the first The semantic vector representation of each sentence. Indicates the ( The semantic vector representation of each sentence.
[0112] When the semantic similarity of an adjacent sentence pair is lower than the preset similarity threshold, the adjacent sentence pair is marked as a potential boundary. A second segmentation is performed at the potential boundary, dividing the original block into two sub-blocks. The number of characters in the segmented sub-blocks is checked again. If it still exceeds the preset number of characters threshold, the above semantic similarity calculation and segmentation steps are repeated until the number of characters in all sub-blocks does not exceed the preset number of characters threshold.
[0113] In this embodiment, there is no specific limitation on the preset similarity threshold. For example, the preset similarity threshold is 0.6, 0.7, 0.8, etc. Assuming the preset similarity threshold is 0.7, if the semantic similarity value between adjacent sentences in an initial block that exceeds the preset word count threshold is less than 0.7, then a second segmentation is performed at that point.
[0114] By performing a secondary segmentation operation, the aggregated candidate block set is made semantically complete and logically coherent, thereby further improving the accuracy of semantic segmentation of legal texts.
[0115] The inventors of this invention further propose that cue engineering techniques can be used to augment the final chunk set before constructing the RAG dataset, thereby further enhancing the data value of the RAG dataset. Correspondingly, in some embodiments, such as... Figure 7 As shown, the step of constructing the RAG dataset (i.e., the one involved in step S140 above) based on the final set of blocks includes the following steps:
[0116] In step S710, problem generation prompts are constructed; wherein, the problem generation prompts are used to prompt the pre-trained data augmentation model to generate legal questions of a specified type, the specified type including those covering direct factual questions, applicable scenario questions, comparative analysis questions, and case application questions;
[0117] In step S720, the final block set and the prompt words are input into the data augmentation model to obtain the data augmentation unit set output by the data augmentation model for each block in the final block set;
[0118] In step S730, the final block set and the data augmentation unit set are integrated to obtain a data augmentation block set;
[0119] In step S740, a RAG dataset is constructed based on the data augmentation chunk set.
[0120] In the field of machine learning, cue words refer to instructions or requests described in natural language that are input into a machine learning model during the interaction process.
[0121] In this embodiment, no specific limitation is made on the specific types of legal questions generated. For example, it covers legal questions based on direct facts, such as "Under what circumstances is a contract invalid?", legal questions based on applicable scenarios, such as "Does online shopping fall under the Consumer Rights Protection Law?", legal questions based on comparative analysis, such as "What is the difference between bona fide acquisition and unauthorized disposition?", and legal questions based on case application, such as "Does this behavior constitute a breach of contract?".
[0122] In this embodiment of the invention, a pre-trained data augmentation model (e.g., a large language model) is used to perform multi-dimensional data augmentation on the final blocks, clarifying the type definition of legal issues, expanding background information and key elements, and extracting structured legal entities and relationships, making the semantic representation of the blocks richer and significantly improving the retrieval recall and matching accuracy of the RAG system.
[0123] In this embodiment, no special limitation is made on how to construct the RAG dataset based on the final set of chunks. For example, the data is organized according to the standard directory structure: chunks directory (stores all chunk JSON files), embeddings directory (stores semantic vectors and indexes), metadata directory (stores document information, structure mapping, and statistical data), and enhancements directory (stores the summary of enhancement data).
[0124] The data augmentation unit contains legal questions of a specified type and their corresponding answers. Each block in the final block set and the data augmentation unit set are associated and integrated to form a data augmentation block set. The structure of each data augmentation block includes the basic information of the final block and the corresponding data augmentation unit. The data augmentation block set is stored in a vector database, an index structure is constructed, an appropriate index type is selected according to the vector dimension and data volume, all block vectors are imported, and the RAG dataset is constructed.
[0125] This example enriches the dimensions of the RAG dataset through data augmentation, ensuring the dataset's effectiveness in RAG applications. The vector database-based storage method ensures the efficiency of subsequent retrieval, enabling this invention to play a greater role in a wider range of scenarios.
[0126] In some embodiments, multiple large language models validate the initial boundaries in the candidate chunk set based on the pre-built chunk validation prompts to determine the chunk validation result.
[0127] The pre-built block verification prompts are used to prompt multiple large language models: verifying whether the initial boundaries in the candidate block set affect the main integrity of the legal provisions, verifying the logical coupling between the defining clauses and the applicable clauses in the candidate block set, verifying the semantic integrity of the main rules and their exception clauses in the candidate block set, and verifying whether the semantic entropy of the blocks in the candidate block set is less than the semantic entropy of the candidate block set.
[0128] The purpose of verifying the semantic completeness of the main rules and their exception clauses in the candidate block set is to ensure that the exception clauses are closely associated with each other in the semantic space.
[0129] The purpose of verifying whether the semantic entropy of a block in the candidate block set is less than the semantic entropy of the candidate block set is to prevent the mixing of multiple discrete topics (under-segmentation) or the forced decoupling of strongly related contexts (over-segmentation).
[0130] As a second aspect of the invention, an electronic device is also provided, wherein, as Figure 8 As shown, the electronic device includes:
[0131] One or more processors 101;
[0132] The memory 102 stores one or more computer programs that, when executed by the one or more processors 101, cause the one or more processors 101 to implement the file-based data storage method provided in the first aspect of the embodiments of this application.
[0133] The electronic device may also include one or more I / O interfaces 103 connected between the processor 101 and the memory 102, configured to enable information interaction between the processor 101 and the memory 102.
[0134] The processor 101 is a device with data processing capabilities, including but not limited to a processor (CPU); the memory 102 is a device with data storage capabilities, including but not limited to random access memory (RAM, more specifically SDRAM, DDR, etc.), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), and flash memory (FLASH); the I / O interface (read-write interface) is connected between the processor and the memory, enabling information exchange between the processor and the memory, including but not limited to a data bus (Bus).
[0135] In some embodiments, the processor 101, memory 102, and I / O interface 103 are interconnected via bus 104, and thus connected to other components of the computing device.
[0136] like Figure 9 As shown, this embodiment provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the legal text processing method provided in the first aspect of the present invention.
[0137] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. Accordingly, the computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can implement the methods of any of the above embodiments. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0138] The above are merely specific embodiments of the present invention, but the scope of protection of the present invention is not limited thereto. Those skilled in the art should understand that the present invention includes, but is not limited to, the contents described in the accompanying drawings and the specific embodiments above. Any modifications that do not depart from the functional and structural principles of the present invention will be included within the scope of the claims.
Claims
1. A legal text processing method, characterized in that, include: Based on the legal text to be processed, a set of candidate blocks is determined, including: The legal text to be processed is converted into structured text, and the legal semantic type of the legal text to be processed is identified; Based on the legal semantic type and the structured text, identify the legal structural features and document structural features of the legal text to be processed; Based on the structured text, the legal structure features, and the document structure features, a candidate block set is determined; The candidate block set and the pre-built block verification prompts are input into multiple large language models to obtain the block verification results output by the multiple large language models. The block verification result includes the initial boundary judgment result between any two adjacent blocks in the candidate block set; Based on multiple judgment results, decisions are made on each initial boundary in the candidate block set to obtain decision results for each initial boundary, including: For any of the initial boundaries, if more than a preset proportion of the judgment results determine that it is accurate, the decision result is determined to be retained; if more than a preset proportion of the judgment results determine that it is inaccurate, the decision result is determined to be cancelled. Based on the decision results of each initial boundary, the final block set is determined; Based on the final set of blocks, a retrieval-enhanced RAG dataset is constructed.
2. The legal text processing method according to claim 1, characterized in that, The block verification result also includes the result of adding new boundaries for blocks in the candidate block set; determining the final block set based on the decision results of each initial boundary includes: If the number of identical new boundary results exceeds a preset number, new boundaries are added in the corresponding blocks based on the identical new boundary results to obtain the decision result of the new boundaries; The final block set is determined based on the decision results of each initial boundary and the decision results of the newly added boundaries.
3. The legal text processing method according to claim 1, characterized in that, The process of determining a candidate block set based on the legal text to be processed includes: The legal semantic types include legal regulations and judicial judgments. The legal structural features of the legal texts to be processed that belong to the legal regulations type include chapter features, section features, article features, clause features, item features, and sub-item features. The legal structural features of the legal texts to be processed that belong to the judicial judgment type include cause of action features, factual features, reasoning features, and judgment features.
4. The legal text processing method according to claim 3, characterized in that, The step of determining a candidate block set based on the structured text, the legal structural features, and the document structural features includes: Based on the structured text, the legal structural features, and the document structural features, an initial set of blocks is constructed; For any block in the initial block set whose word count exceeds a preset word count threshold, calculate the semantic similarity of each adjacent sentence pair in the block, and perform a secondary segmentation between any adjacent sentence pair if the semantic similarity of any adjacent sentence pair is less than a preset similarity threshold. The candidate block set is obtained by summarizing the secondary segmentation results of the initial block set.
5. The legal text processing method according to claim 1, characterized in that, The step of constructing the retrieval enhancement generation RAG dataset based on the final block set includes: Construct question generation prompts; wherein, the question generation prompts are used to prompt a pre-trained data augmentation model to generate legal questions of a specified type, the specified type including those covering direct factual questions, applicable scenario questions, comparative analysis questions, and case application questions; The final block set and the prompt words are input into the data augmentation model to obtain a set of data augmentation units output by the data augmentation model for each block in the final block set. Integrate the final block set and the data augmentation unit set to obtain a data augmentation block set; Based on the data augmentation block set, a retrieval-enhanced RAG dataset is constructed.
6. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the legal text processing method according to any one of claims 1 to 5.
7. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the computer program is executed by a processor, it implements the legal text processing method according to any one of claims 1 to 5.