Legal clause vector retrieval method based on large language model

By dividing the contract document into chapters and paragraphs, using word frequency vectorization and similarity calculation algorithms, and combining sample clauses for weighted averaging and fusion mechanisms, the problems of insufficient semantic understanding and high consumption of computing resources in the existing technology are solved, and the problem of improved Accuracy and efficiency of legal terms search.

CN119128182AInactive Publication Date: 2024-12-13POWERCHINA HUADONG ENG CORP LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411039710.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-31
Publication Date
2024-12-13
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The prior art has limited semantic understanding when dealing with complex legal terms, which is prone to misunderstanding polysemes, ignore contextual information, and consumes high computing resources, resulting in inaccurate retrieval effects and low efficiency.

Method used

By dividing the contract document into chapters and paragraphs, using word frequency vectorization and similarity calculation algorithms, combining sample clauses for weighted averaging and fusion mechanisms, the chapters and paragraphs that are most relevant to risk descriptions are selected to reduce the computing resource requirements.

Benefits of technology

It improves the accuracy and efficiency of legal clause search, avoids the negative impact of long text and complex content on the search effect of large-scale models, and ensures efficient use of resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119128182A_ABST
    Figure CN119128182A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of retrieval, and discloses a legal clause vector retrieval method based on a large language model, which is specifically executed according to the following steps: firstly, processing an input contract document, and segmenting a contract into a plurality of chapters; each chapter is further subdivided into paragraphs according to rules; performing weighted average processing to determine final chapters, dividing non-table natural chapters according to title features, dividing the table into independent chapters by rows according to header information, and independently storing each segmented chapter to form a plurality of independent text blocks; wherein the natural paragraphs are directly divided into paragraphs, the listing paragraphs need to be integrally taken as a whole, and the option only takes the title of the option and the corresponding selected option as an integral paragraph. The method is simple and high in efficiency, the influence of information irrelevant to risk description is abandoned, and the negative influence on the large model vector retrieval effect due to the fact that the contract text is too long and the content is too complex can be effectively avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of retrieval technology, and in particular to a legal clause vector retrieval method based on a large language model. Background Art

[0002] The technical solution based on full-text vector retrieval of contracts uses natural language processing (NLP) technology to achieve in-depth understanding and rapid retrieval of legal terms of contracts by converting contracts into high-dimensional vectors (i.e., embedding). This method uses an embedding model to map semantically similar terms to similar vector spaces, thereby effectively matching user risk descriptions with corresponding answers in the legal terms question-and-answer system; the usual implementation method is: first, pre-process the text of the contract to clean it up, delete stop words, punctuation marks, HTML tags and other irrelevant information, and divide the contract into phrases; then, use a pre-trained language model (such as BERT, GPT, etc.) or a domain-specific embedding model to convert the entire text into a vector of fixed dimensions, and generate corresponding vector information for each contract, paragraph or sentence; finally, convert the contract risk description entered by the user into vector information, calculate the similarity (such as cosine similarity) between the risk description vector information and the legal terms vector information, sort by similarity, and select the most relevant legal terms in the contract as the knowledge background.

[0003] At present, the existing technology has the following disadvantages:

[0004] 1. Limited semantic understanding

[0005] While existing technologies can capture the semantic relationships between words and phrases, they may not perform well when dealing with complex contexts or contracts that require deep understanding. Models may misunderstand the meaning of polysemous words or complex legal clauses, leading to inaccurate answers.

[0006] 2. Contextual Restrictions

[0007] Large models usually process contracts of fixed length, and may lose some contextual information when processing long text contracts. This may cause the model to ignore important contextual details when looking for answers in long text contracts.

[0008] 3. High computing resource requirements

[0009] Generating full-text search vectors requires a lot of computing resources, especially when processing a large amount of contract text information or real-time queries. This may become a bottleneck for application scenarios with limited resources.

[0010] Therefore, to address the above issues, a legal clause vector retrieval method based on a large language model is needed. Summary of the invention

[0011] The purpose of the present invention is to provide a method for retrieving legal clause vectors based on large language models. The present invention can perform vector calculations based on risk descriptions, sample clauses, and contract chapters, and obtain the legal clause knowledge background of the contract that is most relevant to the risk description and sample clauses, or only to the risk description. This method is concise and efficient, and can effectively avoid the negative impact of overly long and complex contract texts on the vector retrieval effect of large models by eliminating the influence of information irrelevant to the risk description.

[0012] The present invention is implemented as follows:

[0013] The present invention provides a method for retrieving legal clause vectors based on large language models, which is specifically executed according to the following steps:

[0014] S1: First, process the input contract document and split the contract into multiple chapters;

[0015] Among them, the natural chapters that are not tables are divided according to the title characteristics, and the tables are divided into independent chapters row by row according to the header information, providing a basis for subsequent similarity matching. Each divided chapter is saved separately to form multiple independent text blocks;

[0016] S 1.1 : Input the contract risk description;

[0017] S 1.2 : Use a similarity calculation algorithm to evaluate the relevance between the text information of each chapter and the risk description. Each chapter will obtain a similarity score score, and the score is used to determine the contract chapter that is most relevant to the risk description; specifically, it is executed according to the following steps:

[0018] S 1.2.1 : Perform word segmentation to decompose the text into words or phrases; remove stop words; remove common meaningless words such as "of", "and", "is", etc.

[0019] S 1.2.2 : Stem extraction or lemmatization to convert words to their basic forms; for example, convert "running" to "run";

[0020] S 1.2.3 : Construct a vocabulary, generating a list containing all unique words based on all the preprocessed text;

[0021] Calculate the word frequency, and for each document, count the number of times each word in the vocabulary appears in the document;

[0022] Perform vectorization to represent each document as a vector, where the length of the vector is equal to the size of the vocabulary, and the value at each position corresponds to the word frequency of the corresponding word.

[0023] As shown in Equation (1)

[0024]

[0025] Where: A and B are the word frequency vectors of the two documents respectively; A i and B i Respectively represent the values ​​of vectors A and B in the i-th dimension, that is, the i-th word in the vocabulary; ||A|‖ and ||B|| are the moduli of vectors A and B respectively, and the calculation formula is the square root of the sum of the squares of the vector components; θ is the angle between vectors A and B, and the cosine value ranges from -1 to 1. The closer the value is to 1, the higher the similarity;

[0026] Wherein: the similarity score results are screened and calculated using formula (2) and formula (3), and the chapters that meet the conditions are selected as candidate chapters. This step is to remove chapters that have a low correlation with the risk description;

[0027] score>mean(scores) Formula (2)

[0028]

[0029] S2: Each chapter is further subdivided into paragraphs according to the rules;

[0030] Please follow the steps below:

[0031] S 2.1 : For natural paragraphs, they are directly divided into paragraphs; for enumeration type, the paragraphs need to be treated as a whole; for selection type, only the title of the selection type and the corresponding selected option are treated as a whole paragraph;

[0032] S 2.2 :Select sample legal clauses as references. The sample clauses are specific paragraphs in the contract document or pre-defined standard legal clause texts for subsequent comparison and analysis; calculate the similarity score for each one. Match each paragraph with the sample clauses one by one and perform fusion processing to calculate the similarity score between them; as shown in Table 1;

[0033] Table 1 Fusion mechanism

[0034]

[0035] After calculating the similarity, each paragraph performs softmax processing on the similarity values ​​of these sample legal clauses; and determines the candidate paragraphs, which are the paragraphs with the highest similarity to the sample clauses, as shown in formula (4);

[0036] weight=softmax(scorce1,scorce2....scorcen ) Formula (4)

[0037] According to the weighted average result, all chapters are sorted and the top 15 chapters with the highest scores are selected. These chapters are considered to be the ones that best meet the specific conditions or standards. After selecting the top 15 chapters, condition screening is performed, as shown in formula (5);

[0038]

[0039] According to the results of the conditional screening of formula (1) and formula (5), the final relevant chapters are determined.

[0040] S3: Perform weighted average processing to determine the final chapter.

[0041] Furthermore, the present invention provides a computer-readable storage medium, wherein the storage medium stores a computer program, and when the computer program is executed by a main controller, the method described in any one of the above is implemented.

[0042] Compared with the prior art, the present invention has the following beneficial effects:

[0043] 1. Perform vector calculations based on risk descriptions, sample clauses, and contract chapters to obtain the legal terms knowledge background of the contract that is most relevant to the risk description and sample clauses. This method is concise and efficient, and eliminates the influence of information irrelevant to the risk description. It can effectively avoid the negative impact of long contract texts and overly complex content on large model vector retrieval effects.

[0044] 2. Improve accuracy: Through scoring mechanisms and candidate selection, ensure that only the most relevant chapters and paragraphs are used as background knowledge for contract risk descriptions.

[0045] 3. Enhanced efficiency: Through weighted averaging and fusion mechanisms, the chapter and paragraph information most likely to contain the correct answer can be quickly determined, removing the interference of redundant and irrelevant information. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments will be briefly introduced below. It is understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.

[0047] Figure 1 is a flow chart of the method of the present invention;

[0048] Figure 2 It is a calculation flow chart similar to the contract risk description and legal elements chapter of the present invention;

[0049] Figure 3 It is a flow chart of the sample legal clause and paragraph fusion mechanism of the present invention. DETAILED DESCRIPTION

[0050] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work belong to the scope of protection of the present invention. Therefore, the following detailed description of the embodiments of the present invention provided in the drawings is not intended to limit the scope of the invention claimed for protection, but is only for selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work belong to the scope of protection of the present invention.

[0051] See also Figure 1-Figure 3 The present invention provides a legal clause vector retrieval method based on a large language model, which is specifically performed in the following steps:

[0052] S1: First, the input contract document is processed and the contract is divided into multiple chapters;

[0053] The non-table natural chapters are divided according to the title features, and the table is divided into independent chapters by row according to the header information, which provides a basis for subsequent similarity matching. Each divided chapter is saved separately to form multiple independent text blocks;

[0054] S 1.1 :Enter the contract risk description;

[0055] S 1.2 : A similarity calculation algorithm is used to evaluate the correlation between the text information of each chapter and the risk description. Each chapter will receive a similarity score, which is used to determine the contract chapter that is most relevant to the risk description; as shown in formula (1):

[0056]

[0057] Where: A and B are the word frequency vectors of the two documents respectively; A i and B irespectively represent the values of vectors A and B in the i-th dimension, that is, the value of the i-th word in the vocabulary; ||A|| and ||B|| are the norms of vectors A and B respectively, and the calculation formula is the square root of the sum of the squares of each component of the vector; θ is the angle between vectors A and B, and the cosine value ranges from -1 to 1. The closer the value is to 1, the higher the similarity;

[0058] Among them: for the similarity scoring results, perform screening calculations according to formulas (2) and (3), and select the chapters that meet the conditions as candidate chapters. This step aims to remove the chapters with relatively low relevance to the risk description;

[0059] score>mean(scores) Formula (2)

[0060]

[0061] Specifically, it is executed according to the following steps:

[0062] S 1.2.1 : Perform word segmentation to break the text into words or phrases; remove stop words;

[0063] Remove common meaningless words, such as "de", "he", "shi", etc.

[0064] S 1.2.2 : Stemming or lemmatization to convert words to their basic forms; for example, convert "running" to "run";

[0065] S 1.2.3 : Build a vocabulary, generate a list containing all unique words based on all the preprocessed texts;

[0066] Calculate the word frequency, for each document, count the number of times each word in the vocabulary appears in the document;

[0067] Perform vectorization to represent each document as a vector. The length of the vector is equal to the size of the vocabulary, and the value at each position corresponds to the word frequency of the corresponding word.

[0068] Match each paragraph with the sample clauses one by one for the fusion mechanism processing, and calculate the similarity score score between them; as shown in Table 1;

[0069] Table 1 Fusion mechanism

[0070]

[0071] S2: Each chapter is further subdivided into paragraphs according to the rules;

[0072] Specifically, it is executed according to the following steps:

[0073] S2.1 : For natural paragraphs, they are directly divided into paragraphs. For enumeration type, the paragraphs need to be treated as a whole. For selection type, only the title of the selection type and the corresponding selected option are treated as a whole paragraph.

[0074] S 2.2 : Select sample legal terms as reference. The sample terms are specific paragraphs in the contract document or pre-defined standard legal terms texts for subsequent comparison and analysis; calculate the similarity score for each.

[0075] After calculating the similarity, each paragraph performs softmax processing on the similarity values ​​of these sample legal clauses; and determines the candidate paragraphs, which are the paragraphs with the highest similarity to the sample clauses, as shown in formula (4);

[0076] weight=softmax(scorce1,scorce2....scorce n ) Formula (4)

[0077] According to the weighted average result, all chapters are sorted and the top 15 chapters with the highest scores are selected. These chapters are considered to be the ones that best meet the specific conditions or standards. After selecting the top 15 chapters, condition screening is performed, as shown in formula (5);

[0078]

[0079] According to the results of the conditional screening of formula (1) and formula (5), the final relevant chapters are determined.

[0080] S3: Perform weighted average processing to determine the final chapter.

[0081] In this embodiment, the present invention provides a computer-readable storage medium, wherein the storage medium stores a computer program, and when the computer program is executed by a main controller, the method described in any one of the above is implemented.

[0082] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention has various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A legal clause vector retrieval method based on a large language model, characterized by: Please follow the steps below: S1: First, process the input contract document and divide the contract into multiple chapters; S2: Each chapter is further subdivided into paragraphs according to the rules; S3: Perform weighted average processing to determine the final chapter.

2. According to claim 1, a legal clause vector retrieval method based on a large language model is characterized in that: In step S1, non-table natural chapters are divided according to title features, and tables are divided into independent chapters by row according to header information, and each divided chapter is saved separately to form multiple independent text blocks; S 1.1 : Enter the contract risk description; S 1.2 :A similarity calculation algorithm is used to evaluate the correlation between the text information of each chapter and the risk description. Each chapter will receive a similarity score, which is used to determine the contract chapter that is most relevant to the risk description; as shown in formula (1): Where: A and B are the word frequency vectors of the two documents respectively; A i and B i Respectively represent the values ​​of vectors A and B in the i-th dimension, that is, the i-th word in the vocabulary; ‖|A|| and ||B|| are the moduli of vectors A and B, respectively, and the calculation formula is the square root of the sum of the squares of the vector components; θ is the angle between vectors A and B, and the cosine value ranges from -1 to 1. The closer the value is to 1, the higher the similarity. Wherein: the similarity score results are screened and calculated using formula (2) and formula (3), and the chapters that meet the conditions are selected as candidate chapters. score>mean(scores) Formula (2) 3. The method for retrieving legal clause vectors based on a large language model according to claim 2, characterized in that: In step S 1.2 , follow these steps: S 1.2.1 : Perform word segmentation to break the text into words or phrases; remove stop words; S 1.2.2 : Stemming or lemmatization, converting words to their base form; S 1.2.3 : Build a vocabulary, generate a list of all unique words based on all preprocessed text; Calculate word frequency. For each document, count the number of times each word in the vocabulary appears in the document. Vectorize and represent each document as a vector. The length of the vector is equal to the size of the vocabulary, and the value of each position corresponds to the frequency of the corresponding vocabulary.

4. The method for retrieving legal clause vectors based on a large language model according to claim 1, characterized in that: In step S2, the following steps are specifically performed: S 2.1 : For natural paragraphs, they are directly divided into paragraphs. For enumeration type, the paragraphs need to be treated as a whole. For selection type, only the title of the selection type and the corresponding selected option are treated as a whole paragraph. S 2.2 :Select sample legal terms as reference. The sample terms are specific paragraphs in the contract document or pre-defined standard legal terms texts. The similarity score is calculated for each.

5. The method for retrieving legal clause vectors based on a large language model according to claim 4, characterized in that: After calculating the similarity, each paragraph performs softmax processing on the similarity values ​​of these sample legal clauses; and determines the candidate paragraphs, which are the paragraphs with the highest similarity to the sample clauses, as shown in formula (4); weight=softmax(scorce1,scorce2....scorce n ) Equation (4) According to the weighted average result, all chapters are sorted and the top 15 chapters with the highest scores are selected. These chapters are considered to be the ones that best meet the specific conditions or standards. After selecting the top 15 chapters, condition screening is performed, as shown in formula (5); According to the results of the conditional screening of formula (1) and formula (5), the final relevant chapters are determined.

6. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by the main controller, the method according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Class case retrieval method and system based on legal elements

    CN114547245A

  • Contract term risk check method, system and device and storage medium

    CN116843175A

  • Intelligent archiving system for legal documents

    CN117407360A

  • Intelligent self-service contract review method based on large language model

    CN118379165A