Similar law judgment document matching method based on prompt engineering and judgment prediction
By adopting similar case matching methods based on prompt engineering and judgment prediction in judicial document information extraction and case matching, the problem of insufficient accuracy in the prior art is solved, and more efficient and accurate case matching is achieved, and case handling costs are reduced.
Patent Information
- Application Number
- CN202411848216.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-16
- Publication Date
- 2025-04-08
AI Technical Summary
The existing technology has insufficient accuracy in the extraction of judicial document information and matching of similar cases, which has resulted in time-consuming and labor-intensive case handling of case handling and increased case handling costs.
Similar case matching methods based on prompt engineering and judgment prediction are adopted, legal elements are extracted through large language model prompt engineering, case facts and legal elements are encoded in combination with Bert encoding, and model prediction is optimized using joint learning methods and punishment loss function.
It improves the accuracy of judicial document information extraction and the accuracy of case-like matching, significantly reduces the time and energy investment of case handlers in the case trial process, and reduces the cost of case handling.
Smart Images

Figure CN119783655A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of text matching in natural language processing, and in particular relates to a method for matching similar legal judgment documents based on prompt engineering and judgment prediction. Background Art
[0002] With the advancement of the construction of "smart courts", legal AI-assisted tasks have gradually received widespread attention. Among them, similar case matching, as the primary link in the application of legal AI, directly provides support for downstream tasks, such as similar case recommendations, similar case retrieval, and automatic sentencing recommendations. Similar case matching helps judges more accurately grasp the scale and standards of the pending cases by comparing and analyzing the reasons for the judgment, legal basis, and judgment results of similar cases. Through similar case matching, judges can quickly find relevant cases, reduce duplication of work, and improve the efficiency and quality of judgment. At the same time, similar case matching also helps to eliminate differences and uncertainties in judicial practice and maintain the unity and authority of the law.
[0003] In the process of similar case matching, the input query case comes from judicial documents. Judicial documents refer to documents with specific structures and certain effectiveness used by political and legal organs when handling cases. These judicial documents contain a lot of important key information. For example, the content of the "Civil Judgment" found through investigation contains many paragraphs of case facts, and these case facts contain a lot of time, place and people. The entity attribute information of various laws, etc., in order to assist the decision-making of the similar case matching model and improve the accuracy of matching, the matching process is optimized from many aspects. First, natural language processing technology can be used to extract the key information of the case from the judicial documents, and specific parsing schemes can be designed for different types of judicial documents. For example, key information such as the cause of the case, the amount involved, the circumstances, the basis for the ruling, the focus of the dispute, and the reference to legal provisions can be extracted. After these key information is standardized and formatted, the contrast between different cases can be improved. Then, the basic information and element information of the case are spliced together to form a more complete and accurate semantic expression, providing richer semantic support for subsequent similar case matching.
[0004] However, in the process of realizing the present invention, the inventors found that the prior art has the following problems: the data information in the case query is only obtained through the extraction of paragraph fragments, which is not specific to the word level. There is a lack of specific information for semantic matching of the case. At the same time, the extraction of judicial document information in the past is not accurate enough. The general similar case matching is to match keywords through regular technology, but the extraction of such keywords requires more efficient and accurate extraction technology. In the judicial field with professional terminology and rigorous writing, more accurate and applicable extraction algorithms are needed. The efficiency of traditional methods in helping case handlers obtain information is still not high enough. In addition, the previous case matching methods ignored whether the two documents have the same judgment, which is crucial to determine their relevance in legal retrieval. The existence of these problems causes case handlers to waste time and effort in the case handling process, increasing the cost of case handling. Summary of the invention
[0005] In order to solve the problem of inaccurate case matching in similar case retrieval by legal case handlers. In the first aspect, according to some embodiments of the present application, the judgment document similar case matching model training method includes:
[0006] S10. Obtain a training data set; wherein the data set includes case serial number, judgment text and legal elements;
[0007] S20. Using the training data set to train a similar case matching model, the similar case matching model includes a plurality of Bert models with shared weights; wherein the similar case matching model is trained using a joint learning method;
[0008] S30. Predict the similarity of the judgment text contents of several input judgment documents using the trained similar case matching model.
[0009] According to the judgment document case matching model training method of some embodiments of the present application, the judgment text includes case facts, judgment analysis, legal analysis and application, and judgment results, and the legal elements include basic legal elements and specific types of legal elements;
[0010] Among them, the legal elements are obtained through the large language model prompting engineering prompt word framework, and the prompt framework includes tasks (Task), requests (Instructions), case input (Context), precautions (Caveat) and output guidance (OutputIndicator).
[0011] According to the judgment document similar case matching model training method of some embodiments of the present application, the similar case matching model is trained using a joint learning method, including first training, second training and third training;
[0012] The first training comprises the following steps:
[0013] S101. any one of the Bert models with shared weights in the similar case matching model inputs the main content of a judgment for encoding;
[0014] S102. Fusing and outputting the output features of several coding layers in any one of the Bert models;
[0015] S103. Obtain a sentence embedding vector by performing an average pooling operation on the output;
[0016] S104. Connect the sentence embedding vectors of the first Bert model and other Bert models respectively to obtain the interaction results between the sentence embedding vectors;
[0017] S105. Based on the interaction result, the probability of the predicted label is calculated by a multi-layer perceptron to determine the approximation between the judgment document input into the first Bert model and the judgment documents input into other Bert models;
[0018] The second training comprises the following steps:
[0019] S201. Generate corresponding legal article serial numbers with semantic information for the legal clauses involved in the legal analysis and application in the judgment document according to the legal article hierarchy; the legal article serial numbers include serial numbers of different hierarchical structures connected by connectors and case serial numbers;
[0020] S202. For the similar case matching model after the first training, any one of the Bert models with shared weights in the similar case matching model inputs a legal article serial number of a judgment to encode;
[0021] S203. Compare the legal article serial numbers of the first Bert model and other Bert models according to the serial numbers of different hierarchical structures connected by connectors, and reward Bert models with the same serial numbers at the same level, and punish Bert models with different serial numbers at the same level;
[0022] Wherein: the third training comprises the following steps:
[0023] S301. Any one of the three Bert models with shared weights in the similar case matching model inputs the main content of a judgment for encoding; wherein one Bert model inputs the current sample, one Bert model inputs a positive sample of text similar to the current sample, and one Bert model inputs a negative sample of text dissimilar to the current sample;
[0024] S302. Fusing and outputting the output features of several coding layers in any one of the Bert models;
[0025] S303. Obtain a sentence embedding vector by performing an average pooling operation on the output;
[0026] S304. Optimize the semantic representation of the vector space by maximizing the similarity between the sentence embedding vector of the positive sample and the current text and the sentence embedding vector of the positive sample, and minimizing the similarity between the sentence embedding vector of the negative sample and the current text and the sentence embedding vector of the negative sample.
[0027] According to the judgment document case matching model training method of some embodiments of the present application, the main contents include case serial number, case facts and legal elements, judgment analysis, legal analysis and application, and judgment results;
[0028] Among them, in step S102, the output features of several coding layers in any one of the Bert models are fused and output, as shown in the following formula:
[0029]
[0030] In the formula, the hidden layer state vector of the Bert model is i represents the case number; j∈[1,5,9,12], Represents the output of the 1st, 5th, 9th, and 12th layers of the Bert model; represents the output of the first Bert model, represents the output of the second Bert model, represents the output of the third Bert model; where Where m represents the number of input batches, n represents the total number of characters in all sentences contained in a batch, and d represents the hidden layer size of the word embedding layer;
[0031] The output in step S103 is subjected to an average pooling operation to obtain a sentence embedding vector, including the output of the first Bert model being subjected to an average pooling operation to obtain a sentence embedding vector The output of the second Bert model is average pooled to obtain the sentence embedding vector The output of the third Bert model is average pooled to obtain the sentence embedding vector
[0032] Among them, in step S104, the sentence embedding vectors of the first Bert model and other Bert models are respectively connected to obtain the interaction result between the sentence embedding vectors, which is shown in the following formula:
[0033]
[0034] Where U ab Represents the sentence embedding vector The interaction result, U ac Represents the sentence embedding vector The interaction results;
[0035] In step S105, according to the interaction result, the probability value of the predicted label is calculated by a multilayer perceptron, as shown in the following formula:
[0036] p i =MLP(U ab -U ac )
[0037] In the formula, p i Indicates that the predicted label is y i The probability value of .
[0038] According to the judgment document similar case matching model training method in some embodiments of the present application, the first training adopts the cross entropy loss function for training, as shown in the following formula:
[0039]
[0040] Where, L CE represents the cross entropy loss function, y i Represents the predicted label.
[0041] According to the judgment document case matching model training method in some embodiments of the present application, the second training adopts the total penalty loss function for training, as shown in the following formula:
[0042]
[0043] Where, L penalty represents the total penalty loss function;
[0044] Among them, the reward penalty function R t To express the rewards and penalties at each layer t of the Bert model, the following formula is used:
[0045]
[0046] In the formula, μ represents the reward coefficient, Represents the value of the query document ID at level t; i d,t Represents the value of the candidate document ID at level t; Represents the level penalty coefficient, L t Indicates the depth or level value of the current hierarchy.
[0047] According to the judgment document similar case matching model training method in some embodiments of the present application, the third training adopts contrastive learning loss function for training, as shown in the following formula:
[0048]
[0049] Where, L contrastive represents the contrastive learning loss function, τ is a hyperparameter, sim is the similarity calculation function of the main contents of the two judgments, N represents the batch size, i represents the batch number, Indicates that the output of the first Bert model is averaged through the pooling operation to obtain the sentence embedding vector. Indicates that the output of the second Bert model obtains the sentence embedding vector through the average pooling operation. It indicates that the output of the third Bert model is averaged and pooled to obtain the sentence embedding vector.
[0050] In a second aspect, according to some embodiments of the present application, a similar case judgment matching method based on a judgment document similar case matching model includes a plurality of Bert models with shared weights, and the matching method includes the following steps:
[0051] Any one of the Bert models with shared weights in the similar case matching model inputs the main content of a judgment for encoding;
[0052] The output features of several coding layers in any one of the Bert models are merged and output;
[0053] Obtain a sentence embedding vector by performing an average pooling operation on the output;
[0054] Connect the first Bert model and the sentence embedding vectors of other Bert models to obtain the interaction results between the sentence embedding vectors;
[0055] Merging the interaction result with the first Bert model and the legal article serial number encoded by other Bert models;
[0056] According to the fusion result, the probability value of the predicted label is calculated by a multi-layer perceptron to obtain the approximation between the judgment document input into the first Bert model and the judgment documents input into other Bert models.
[0057] According to some embodiments of the present application, a similar case judgment document matching method based on a judgment document similar case matching model, the similar case matching model is trained by any one of the training methods described in the first aspect;
[0058] The judgment text includes case facts, adjudication analysis, legal analysis and application, and judgment results; the legal elements include basic legal elements and specific types of legal elements;
[0059] Among them, the legal elements are obtained through the large language model prompting engineering prompt word framework, and the prompt framework includes tasks (Task), requests (Instructions), case input (Context), precautions (Caveat) and output guidance (OutputIndicator).
[0060] In a third aspect, an embodiment of the present application further provides an electronic device, comprising: one or more processors, a memory, and one or more programs; wherein the one or more programs are stored in the memory, and the one or more programs include instructions, which, when executed by the electronic device, enable the electronic device to execute the first aspect and any possible technical solution of the first aspect.
[0061] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium includes a computer program. When the computer program runs on an electronic device, the electronic device executes the first aspect and any possible technical solution of the first aspect.
[0062] Beneficial effects: The present invention discloses a similar case matching method based on prompt engineering and judgment prediction, which cleans and divides judicial documents, extracts case names, case facts, judgment analysis process, legal analysis and application, and court judgment results that are strongly related to case identification; proposes a TICCO prompt framework, effectively improves the accuracy of extracting key legal elements of a large language model, and obtains the basic legal elements and specific types of legal elements of a case; adopts the Bert encoding method to obtain the encoding of case facts and legal element splicing, judgment analysis process, court judgment results, etc., and judges the similarity of cases from multiple dimensions, which can improve the accuracy of similarity judgment.
[0063] The present invention discloses a similar case matching method based on prompt engineering and judgment prediction, which comprehensively considers the impact of legal application on case matching, constructs legal case numbers with semantic information according to the legal hierarchy of the legal articles, and ensures that multiple legal applications of the same case are assigned valid numbers. Then, a penalty loss function is designed according to the legal hierarchy, and the loss function adjusts the prediction of the model through a reward and penalty mechanism. The loss function penalizes the difference between the serial numbers of two documents layer by layer along the legal structure hierarchy tree. The closer to the root of the tree, the greater the penalty, and the closer to the leaves, the smaller the penalty, thereby enhancing the accuracy of case matching from the perspective of legal application and judgment.
[0064] The present invention discloses a similar case matching method based on prompt engineering and judgment prediction, which inputs the case to be judged into the trained similar case matching model, and the similar case matching model compares the case with the candidate cases respectively, outputs the case number of the case and the more similar case in the candidate pool and returns it, and provides lawyers and judges with efficient case handling reference and intelligent assistance, which can significantly reduce their time consumption and energy investment in the case handling process. Additional aspects and advantages of the present invention will be partially given in the following description, and partially will become obvious from the following description, or will be understood through the practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0065] Figure 1 This is the overall structure diagram of the first-instance judgment.
[0066] Figure 2 This is the overall structure diagram of the second-instance judgment.
[0067] Figure 3 Flowchart of the similar case matching method based on hint engineering and judgment prediction.
[0068] Figure 4 The model structure diagram of the similar case matching method based on prompt engineering and judgment prediction.
[0069] Figure 5 Design diagram of prompt words for similar case matching method based on prompt engineering and judgment prediction. DETAILED DESCRIPTION
[0070] The following describes the embodiments of the present application in detail with reference to the accompanying drawings, examples of which are shown in the accompanying drawings. The present application provides a method and an electronic device. The method and the device are based on the same technical concept. Since the principles of solving problems by the method and the device are similar, the implementation of the device and the method can refer to each other, and the repeated parts will not be repeated.
[0071] The embodiment of the present invention provides a similar case judgment document matching method based on a judgment document similar case matching model, wherein the similar case matching model includes a plurality of Bert models with shared weights. The method for extracting key information from judicial judgment documents of the present invention can improve the matching of different cases in similar case retrieval, thereby improving the accuracy of obtaining information and simplifying the steps of obtaining information. It overcomes the problem of low accuracy of obtaining information caused by inaccurate case matching of case handlers in the past, and effectively reduces the cost of case handling.
[0072] The present invention provides a similar case judgment document matching method based on a judgment document similar case matching model, including:
[0073] S10. Training similar case matching model;
[0074] S20. Use the trained similar case matching model to perform similar case matching.
[0075] In the training step of S10 of the present invention, the large language model prompt engineering technology is specifically used to identify and generate corresponding entity sets from the case facts and case descriptions in the legal judgment documents. The entity recognition prompt is used to generate legal elements, wherein the legal elements include basic legal elements and specific types of legal elements. The prompt is a prompt of the above two entity attributes. The case facts are the statement paragraphs of the case facts in the judicial documents, and the entity set includes at least one entity attribute. Then, by splicing, the key case element information (basic legal elements and specific types of legal elements) is merged with the case facts to obtain richer semantic information. In this step, the present invention introduces a pre-trained language model and conducts an in-depth analysis of the case facts through semantic similarity calculation or vectorized representation, thereby improving the accuracy of the model in the matching process of similar cases and accelerating judicial decision-making.
[0076] The method comprises the following specific steps:
[0077] S101. Download judgments of different causes of action from the China Judgments Online website, select a fixed number of judgments from each cause of action as target cases, and collect judgments of similar cases and judgments of dissimilar cases as the data set for similar case matching.
[0078] All collected judgment documents are summarized and segmented by the split function and strip function in the RE library. The court name and case number at the head of the judgment are removed, and the party information, including the name or name of the appellant, the respondent and the third party, is retained; the court signature and date at the end of the judgment are removed; the main text is retained to describe the facts, reasons and judgment results of the case in detail. The final content is saved as the case name (also used as the case number), case facts, judgment analysis process, legal analysis and application, and court judgment results. The above content is called the judgment text in the present invention.
[0079] Therefore, the judgment text in the present invention includes case facts, judgment analysis, legal analysis and application, and judgment results, and the legal elements include basic legal elements and specific types of legal elements. S102. Design a large language model prompt engineering prompt word framework, and propose a TICCO prompt framework, which includes five parts: task, request, case input, caveat, and output guide. The legal feature elements are obtained from the legal judgment through prompts. The legal feature elements are divided into two categories: basic legal elements and specific types of legal elements. Among them, the basic legal elements include: legal representative or natural person, number of people involved, provincial information, loan scale, loan date, loan interest rate, whether to participate in the trial and entrust an agent; specific types of legal elements include: joint liability guarantee or mortgage or unsecured, loan purpose, repayment certificate, interest rate range, agreed annual interest rate, usury, loan legal effect, debt transfer, financial institution involved, repayment situation and debt collection situation. For elements not involved in the text, no output is performed, and finally the extracted legal elements are saved in JSON format to ensure that the extracted content accurately reflects the case information in the lawsuit. Therefore, the legal elements of the present invention are obtained by performing the above steps through the large language model prompt engineering prompt word framework.
[0080] S103. Integrate basic legal elements, specific types of legal elements and case facts, and encode the content related to case identification, namely, the fusion results of legal elements and case facts, the adjudication analysis process, legal analysis and application, and court judgment results, using the pre-trained Bert model to obtain Bert multi-layer feature vectors, and fuse the multi-layer feature vectors to obtain richer semantic features of the sentence; after passing through the Bert encoding layer, the feature vectors interact with each other, and in addition to the semantic features of the original case information, the semantic features of different cases are subtracted to obtain the different semantic features between different cases, and then similar cases are matched by comparing cosine similarity.
[0081] S104. Compare the comprehensive similarities calculated for the target case and the two candidate cases, use the cross entropy loss function to calculate the loss function of the model, calculate the gradient and then back-propagate to update the parameters. Taking the text structure of the judgment into consideration, and comparing different parts of the case from different aspects, the resulting similar case matching model can effectively improve the accuracy of similar case matching. The value of y is 0 or 1, 0 means that the text similarity between the target case and the positive sample candidate case is greater than the text similarity between the target case and the negative sample candidate case, and 1 means the opposite. The entire model is an end-to-end model, trained using the cross entropy loss function:
[0082]
[0083] Where: pi Indicates that the predicted label is y i The probability value, y i represents the true label and L is the loss function.
[0084] The present invention described above combines the similarity of the factual part of the integrated case elements, the similarity of the judgment analysis process, and the similarity of the court's judgment results, and then outputs them through the fully connected layer to obtain the final comprehensive similarity of the case. The comprehensive similarities calculated for the target case and the two candidate cases are compared, and the loss function of the model is calculated using the cross entropy loss function. The text structure of the judgment is taken into consideration, and different parts of the case are compared from different aspects. The resulting similar case matching model can effectively improve the accuracy of similar case matching.
[0085] S105. Since the decision-making process of determining whether two documents are related is similar to the search in the tree-like hierarchy of legal application, the applicable legal articles of the candidate case and the applicable legal articles in the query case are in the same position in the legal hierarchy. Therefore, the inherent hierarchy of the law is utilized to generate the legal article serial number with semantic information corresponding to each case through the inherent structure of the legal entry.
[0086] For example, Article 165 of Section 2 of Chapter 7 of the Civil Code of the People's Republic of China stipulates that if the authorization of agency is in written form, the authorization letter shall state the name or title of the agent, the agency matters, authority and term, and shall be signed or stamped by the principal. The sequence number with semantic information for this article is 0-7-2-165-x. Among them, 0 represents the root node, - represents the connector, 7 represents Chapter 7, 2 represents Section 2, 165 represents Article 165, and x corresponds to the case sequence number.
[0087] When predicting the classification of documents during the training process, the similarity between two documents is quantified by considering the hierarchical sequence information. In order to improve the classification performance of the model and enhance the model's ability to learn the hierarchical structure, a penalty loss function is designed. The loss function adjusts the model's prediction through a reward and penalty mechanism. The loss function penalizes the difference between the sequence numbers of two documents layer by layer along the legal structure hierarchy tree. The closer to the root of the tree, the greater the penalty, and the closer to the leaves, the smaller the penalty. Define a reward penalty function R t To represent the rewards and penalties at each layer t:
[0088]
[0089] in, Represents the value of the query document number at level t; i d,t represents the value of the candidate document number at level t; μ represents the reward coefficient, which is a constant used to quantify the reward when the model predicts correctly; Represents the level penalty coefficient, which is used to control the intensity of the penalty when the prediction is wrong; L t Indicates the depth of the current level; R t Represents the reward / penalty value of the tth layer.
[0090] Calculate rewards or penalties based on whether the document sequence numbers are the same.
[0091]
[0092] L penalty Represents the total penalty loss function, which is the sum of rewards and penalties at all levels. The model optimizes its performance by minimizing this loss function.
[0093] S106. The present invention also adds a loss based on contrastive learning to calculate the similarity score between texts. The core idea of contrastive learning is to shorten the distance between similar samples and increase the distance between dissimilar samples. The construction of similar samples can be divided into supervised and unsupervised. The present invention adopts supervised contrastive learning, which performs contrastive learning by taking similar samples in the supervised samples as positive samples and dissimilar samples as negative samples: the present invention selects the vector after the pooling layer. To compare the input of the learning framework, it is important to note that Each contains the text in a batch. Respectively represent the A, B, and C texts in a sample, and N represents the batch size. In a sample, A and B texts are similar by default, while A and C are the opposite. The loss function of the contrastive learning part is:
[0094]
[0095] Among them, τ is a hyperparameter, which is a constant greater than 0, and sim is the similarity calculation of two texts. The present invention uses cosine similarity for calculation. The present invention uses a joint learning method to train the model, and the final loss consists of three parts:
[0096] L total =L CE +αL contrastive +λ·L penalty
[0097] In the step of similar case matching of the model in S20 of the present invention, the case to be judged is specifically input into the trained similar case matching model, which compares the case with the candidate cases respectively, outputs the case number of the case and the more similar case in the candidate pool and returns it, and provides lawyers and judges with efficient case handling references and intelligent assistance, which can significantly reduce their time consumption and energy investment in the case trial process. This technical support not only helps to improve judicial efficiency, but also helps judges and lawyers make more accurate decisions when handling complex cases, ensuring that the trial of the case is more efficient and fair.
[0098] The present invention discloses a similar case matching method based on prompt engineering and judgment prediction, which cleans and divides judicial documents, extracts case names, case facts, judgment analysis process, legal analysis and application, and court judgment results that are strongly related to case identification; proposes a TICCO prompt framework, effectively improves the accuracy of extracting key legal elements of a large language model, and obtains the basic legal elements and specific types of legal elements of the case; adopts a Bert encoding method to obtain the encoding of the case facts and core legal elements, judgment analysis process, and court judgment results after splicing, and judges the similarity of cases from multiple dimensions.
[0099] The present invention discloses a similar case matching method based on prompt engineering and judgment prediction, which comprehensively considers the impact of legal application on case matching, constructs legal case numbers with semantic information according to the legal hierarchy of the legal articles, and ensures that multiple legal applications of the same case are assigned valid numbers. Then, a penalty loss function is designed according to the legal hierarchy, and the loss function adjusts the prediction of the model through a reward and penalty mechanism. The loss function penalizes the difference between the serial numbers of two documents layer by layer along the legal structure hierarchy tree. The closer to the root of the tree, the greater the penalty, and the closer to the leaves, the smaller the penalty, thereby enhancing the accuracy of case matching from the perspective of legal application and judgment.
[0100] The present invention discloses a similar case matching method based on prompt engineering and judgment prediction. The case to be judged is input into a trained similar case matching model. The similar case matching model compares the case with the candidate cases respectively, and outputs the case number of the case that is more similar to the case in the candidate pool and returns it. By providing lawyers and judges with efficient case handling references and intelligent assistance, it can significantly reduce their time consumption and energy investment in the case trial process. This technical support not only helps to improve judicial efficiency, but also helps judges and lawyers make more accurate decisions when handling complex cases, ensuring that the case trial is more efficient and fair.
[0101] In a specific example, this example uses a judicial document library related to the lending field to form a case matching data set, and the statistical information of the sorted similar case matching data set is shown in Table 1:
[0102] Table 1 Loan case data set
[0103]
[0104] Evaluation criteria: For test data, the predicted result label is calculated by calculating the similarity between A and B and C. If documents A and B are similar, the label is 0, and if documents A and C are similar, the label is 1. By comparing with the actual labels, the accuracy of the model is calculated, that is, the percentage of consistent labels:
[0105]
[0106] Among them, N t is the number of samples where the relationship prediction is correct; N p is the number of samples for prediction.
[0107] This embodiment discusses a similar case matching method based on the structure of judicial documents and integrated case elements. Figure 1 Schematic diagram of the overall process of the method according to the embodiment. Figure 3 This is a model structure diagram of the similar case matching method based on prompt engineering and judgment prediction of the embodiment. The specific implementation steps are as follows:
[0108] Step 1: Clean and divide the judgment documents, remove the content at the beginning and end that is not strongly related to the case, and save the final content as case name, basic case information, judgment analysis process, and court judgment result.
[0109] like Figure 1 , Figure 2 The structure diagram of the judgment document in the judicial document shown in the figure. The court judgment refers to the formal written document issued to the parties after the judicial organ makes a judgment, and is the final result of the judicial trial procedure. The judgment is a legal document that summarizes and rules the facts, evidence, and application of law during the trial of the case. When processing, according to the writing specifications of the judgment document, the keywords "...case", "found after trial", "this court believes", "in accordance with the provisions of...", "the judgment is as follows", etc. are used to divide the document through the split function and strip function in the RE library to obtain five parts of text content: case name, case facts, evidence review and analysis, legal analysis and application, and court judgment result.
[0110] Step 2: Determine the type of core legal elements to be extracted (basic legal elements, specific types of legal elements), design the prompt substructure, and use the large language model to extract the core legal elements.
[0111] Step 2.1: Before encoding the case text, it is necessary to first extract the feature attributes with legal significance from the case text. These features can help the model better understand and determine the similarities between legal texts. Specifically, these legal feature attributes include information such as the cause of the case, relevant legal provisions, and judicial interpretations. For private lending cases, combined with the judicial interpretations of relevant laws such as the Contract Law, the Guarantee Law, and the Marriage Law, we can summarize the important legal features that affect the judgment.
[0112] Generally speaking, similar cases tend to share some of the same legal features. Therefore, when modeling these cases, it is very important to use their features as model input. For loan cases, we can extract the following two key factors based on the core legal elements involved in the case, which will directly affect the judgment of the case:
[0113] Table 2 List of specific types of legal elements
[0114]
[0115] Table 3 List of basic legal elements
[0116]
[0117] By extracting these legal feature attributes, the model can more effectively judge the similarities between different cases, thereby providing useful reference and decision support for judicial personnel. These features not only help in the determination of cases, but can also serve as important input features in the model training process to enhance the model's expressiveness and predictive capabilities. In this process, the accurate extraction and expression of legal features is crucial to the effectiveness of the model.
[0118] Step 2.2: Use the large language model to prompt the engineering design instruction prompt to identify and extract the corresponding entity set from each case fact in the judicial document. Figure 5The prompt word structure diagram shown in the figure shows that the proposed TICCO prompt framework includes five parts: Task, Request Instructions, Case Input, Caveat, and Output Indicator. The task description is: Please extract the relevant basic legal elements and specific types of legal elements from the following judicial lawsuit. Your task is to analyze the text, identify and extract all relevant information to build a clear legal element data structure. The request instruction is: extract basic legal elements from the text, including: legal representative or natural person, number of people involved, province information, loan scale, loan date, loan interest rate, participation in the trial, and entrusted agent; extract specific types of legal elements from the text, including: joint liability guarantee or mortgage or unsecured, loan purpose, repayment certificate, interest rate range, agreed annual interest rate, usury, loan legal effect, debt transfer, financial institution involved, repayment situation, and debt collection situation. For elements not involved in the text, the output is directly omitted. The final result is saved in JSON format. The precautions are: ensure that the extracted content accurately reflects the information in the lawsuit, taking into account the correctness and completeness of legal terms. The case input part inputs the corresponding case facts that need to be extracted. The output guide is: Please output the extracted legal elements in JSON format. (And give specific output format requirements). Through the above prompts, the big model can generate the core legal elements in the case facts.
[0119] Step 3: Encode the case facts, core legal elements (basic legal elements, specific types of legal elements), legal analysis and application, and court judgment results using the pre-trained model BERT, extract the feature vectors output by the Bert specific (1, 5, 9, 12) encoding layer for fusion, use the attention mechanism for semantic interaction on the fusion features, and take the first layer, the last layer, and the middle layer to increase semantic information. Refer to Sentence-Bert and add an average pooling operation after the Bert encoding layer to obtain a fixed-size sentence vector. Use cosine similarity to calculate the similarity between the factual part of the fused case elements and the factual part of the fused case elements of different cases, the similarity of the judgment analysis process of different cases, the similarity of the legal analysis and application of different cases, and the similarity of the court judgment results of different cases.
[0120] Step 3.1: The present invention uses the Sentence-Bert encoder to generate the word vectors required for downstream tasks. When using the pre-trained model for encoding, the case facts are spliced with the obtained legal elements, and the splicing results, the judgment analysis process, the legal analysis and application, and the court judgment are encoded to obtain the corresponding word vectors. The encoding part of the model is mainly divided into three parts: word embedding layer, segment embedding layer, and position embedding layer, among which the task layer and the encoding layer are universal structures and are applicable to any task. For a specific text a={a 1 ,a 2 ,…,a l}, the feature q of length s = {q 1 ,q 2 ,…,q s}, because the input text of the pre-trained model is limited to a length of no more than 512, the case facts extracted from the file are selected as the main part of the document input. The present invention chooses to splice the document with the feature, adds the "[CLS]" identifier at the beginning of the sentence, and uses "[SEP]" to separate the text and the feature, and uses this as the input of the model. Different Bert models correspond to different input judgments. In order to fully consider the interaction between texts, the present invention uses three Bert models with shared weights. The Bert model can capture rich language information in Transformer encoders at different layers. Studies have shown that similar language knowledge can be learned between similar layers of Bert. Therefore, the output of Bert's specific encoding layer is selected for fusion to obtain richer text features. The 1st, 5th, 9th, and 12th layers of the Bert model are selected as enhanced features, and the hidden layer state vector of the Bert model is defined. i represents text A, B, and C, so the output after Bert is:
[0121]
[0122] where j∈[1,5,9,12], m is the number of input batches, n is the total number of characters in all sentences contained in a batch, and d is the hidden layer size of the word embedding layer.
[0123] Step 3.2: After passing the Bert encoding layer, the present invention adds an average pooling operation after the Bert encoding layer to obtain a fixed-size sentence embedding vector Get sentence embedding vector After that, the present invention selects and Connect them separately to embed the sentence into vector To interact, the specific connection method is as follows:
[0124]
[0125] U ab Represents the sentence embedding vector The result of the interaction, U ac Represents the sentence embedding vector The results of the interaction;
[0126] Through MLP ab and U ac Calculate and get the predicted label as y i The probability value of , to determine whether text A and B are more similar or text A and C are more similar. Being able to learn relevant semantics at the word level helps to make more comprehensive matches, as shown in the following formula:
[0127] p i =MLP(U ab -U ac )
[0128] In the formula, the value of y is 0 or 1, 0 means that the text similarity between the target case and the positive sample candidate case is greater than the text similarity between the target case and the negative sample candidate case, and 1 means the opposite. The entire model is an end-to-end model, trained using the cross entropy loss function:
[0129]
[0130] Where: p i Indicates that the predicted label is y i The probability value, y i represents the true label and L is the loss function.
[0131] Step 3.3: Since the decision-making process of judging whether two documents are related is similar to the search in the tree hierarchy of legal application, the applicable legal articles of the candidate case and the applicable legal articles in the query case are in the same position in the legal hierarchy. Therefore, the inherent hierarchical structure of the law is used to generate the corresponding legal article serial number with semantic information for each case through the inherent structure of the legal entry. For example, Article 165 of Chapter 7, Section 2 of the Civil Code of the People's Republic of China stipulates that the authorization of agency shall be in written form. The authorization letter shall state the name or title of the agent, the agency matters, the authority and the term, and shall be signed or stamped by the principal. The legal application serial number with semantic information corresponding to this case is 0-7-2-165-x, where x corresponds to the case serial number. When classifying and predicting documents during the training process, consider two documents to quantify their similarity through the hierarchical structure. The semantic legal article case association serial number is converted into a vector representation through Bert, and then compared. First, the sequence is input into Bert, and Bert encodes the sequence into a vector representation. The Bert model compares two values at the same level to get rewards if they are the same, and to get penalties if they are different at the same level;
[0132] In order to improve the classification performance of the model and enhance the model's ability to learn hierarchical structures, a penalty loss function is designed. This loss function adjusts the model's prediction through a reward and penalty mechanism. The loss function penalizes the difference between two document numbers layer by layer along the legal structure hierarchy tree. The closer to the root of the tree, the greater the penalty, and the closer to the leaves, the smaller the penalty. Define a reward penalty function R t To represent the rewards and penalties at each layer t:
[0133]
[0134] in, Represents the value of the query document ID at level t; i d,t represents the value of the candidate document ID at level t; μ represents the reward coefficient, which is the given reward value when the document ID is the same. It is usually a constant used to quantify the reward when the model predicts correctly; It represents the level penalty coefficient, which is used to control the intensity of the penalty when the prediction is wrong. Its value is usually between (0,1], which means that the closer to the root node, the greater the penalty, and the closer to the leaf node, the smaller the penalty; L t Represents the depth or level value of the current level. This value indicates the currently predicted level in the document's hierarchy; R t Represents the reward / penalty value of the tth layer. The reward or penalty is calculated based on whether the predicted document ID is the same as the true value.
[0135]
[0136] Lpenalty Represents the total penalty loss function, which is the sum of rewards and penalties at all levels. The model optimizes its performance by minimizing this loss function.
[0137] Step 3.4: The present invention also adds a loss based on contrastive learning to calculate the similarity score between texts. The core idea of contrastive learning is to shorten the distance between similar samples and increase the distance between dissimilar samples. The construction of similar samples can be divided into supervised and unsupervised. The present invention adopts supervised contrastive learning, which performs contrastive learning by taking similar samples in the supervised samples as positive samples and dissimilar samples as negative samples: The present invention selects the vector after the pooling layer. To compare the input of the learning framework, it is important to note that Each contains the text in a batch. Respectively represent the A, B, and C texts in a sample, i represents the batch number, and N represents the batch size (batchsize), which is the number of samples used in each training iteration in deep learning. In a sample, A and B texts are similar by default, while A and C are the opposite. The loss function of the contrastive learning part is:
[0138]
[0139] Among them, τ is a hyperparameter, which is a constant greater than 0, and sim is the similarity calculation of two texts. The present invention uses cosine similarity for calculation. In contrastive learning, three independent encoders are constructed to process the three types of texts of the input samples respectively: the main text A, the positive sample B and the negative sample C, so as to generate the corresponding high-dimensional vector representation Three Bert models with shared parameters learn specific semantic features for different text types. During the training process, the model calculates the cosine similarity sim(a, b) between the main text and the positive sample and the cosine similarity sim(a, c) between the main text and the negative sample. The model maximizes the cosine similarity between the positive sample and the negative sample. Similarity, minimize negative sample pairs The loss function uses a contrast loss function to measure the similarity difference between vectors. By optimizing the encoder parameters through gradient descent, the model gradually learns a semantically consistent vector space, making semantically similar texts closer and semantically different texts farther apart, thereby improving the distinguishing ability and generalization performance of semantic representation.
[0140] The present invention adopts the joint learning method to train the model, and the final loss consists of three parts:
[0141] L total =L CE +αLcontrastive +λ·L penalty
[0142] Step 4: Input the case to be judged into the trained similar case matching model. The similar case matching model will compare the case with the candidate cases respectively, and output the case number of the case that is more similar to the case in the candidate pool and return it. By providing lawyers and judges with efficient case handling references and intelligent assistance, it can significantly reduce their time consumption and energy investment in the case trial process. This technical support not only helps to improve judicial efficiency, but also helps judges and lawyers make more accurate decisions when handling complex cases, ensuring that the case trial is more efficient and fair.
[0143] Experimental data:
[0144]
[0145]
[0146] Compared with all baseline models, the similar case matching method based on prompt engineering and judgment prediction proposed in the present invention fully considers the sequence information of the document, integrates the core elements of the law into the model, increases the penalty loss of the semantic information sequence of the law, and uses the contrastive learning method to further optimize the word vector output by the pre-trained model. Finally, the entire matching process is completed through classification tasks.
[0147] Among the baseline models, the CNN model performed best. Its advantage is that it can fully capture the local features of the text and mine fine-grained information, thereby significantly improving the matching effect. The ESIM model performed better than the baseline model on the validation set, but the effect on the test set was average. This is mainly because although the model focuses on the interaction between texts, it ignores the fine-grained features in the documents, and the differences in legal documents are often reflected in some subtle legal elements. The ERNIE-DOC model ignores the interactive matching characteristics between different texts. The Roformer model expands the input sequence length of the BERT model to 1024 by adjusting the position encoding, which can more fully extract text information, but still fails to pay attention to the interactive information between texts. The Backward team uses the traditional BERT text matching method to calculate text similarity. Although it can better pay attention to the interaction between texts, it is limited by the BERT input length and information is inevitably lost. The AlphaCourt team uses the Rank model to solve the text similarity problem, combines the triple loss as the loss function, and integrates auxiliary information such as legal features for comparison. However, the model only analyzes based on features such as word frequency and word count, and does not fully utilize the semantic information of legal features. The LFESM model is an improvement over the ESIM model. It uses the BERT model for encoding to better mine the contextual information of the text, but its processing of legal feature elements still relies on one-hot encoding, resulting in the loss of some semantic information. Compared with the best performing LFESM model in the baseline model, the results of this method on the validation set and test set were improved by 0.88% and 1.19% respectively.
[0148] Based on the above embodiments, the embodiments of the present application further provide a computer program, which, when executed on a computer, enables the computer to execute the methods provided in the above embodiments.
[0149] Based on the above embodiments, the embodiments of the present application further provide a computer storage medium, in which a computer program is stored. When the computer program is executed by a computer, the computer executes the method provided in the above embodiments.
[0150] The storage medium may be any available medium that can be accessed by a computer. For example, but not limited to, a computer-readable medium may include RAM, ROM, EEPROM, CD-ROM or other optical disk storage, magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer.
[0151] Based on the above embodiments, an embodiment of the present application further provides a chip, which is used to read a computer program stored in a memory to implement the method provided in the above embodiments.
[0152] Based on the above embodiments, an embodiment of the present application provides a computer program product. When the computer program product is run on an electronic device, the method provided in the above embodiments is implemented.
[0153] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0154] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0155] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0156] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0157] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A judgment document case matching model training method, characterized in that: include S10. Obtain a training data set; wherein the data set includes case serial number, judgment text and legal elements; S20. Using the training data set to train a similar case matching model, the similar case matching model includes a plurality of Bert models with shared weights; wherein the similar case matching model is trained using a joint learning method; S30. Predict the similarity of the judgment text contents of several input judgment documents using the trained similar case matching model.
2. The judgment document similar case matching model training method according to claim 1 is characterized in that: The judgment text includes case facts, adjudication analysis, legal analysis and application, and judgment results; the legal elements include basic legal elements and specific types of legal elements; Among them, the legal elements are obtained through the large language model prompting engineering prompt word framework, and the prompt framework includes tasks (Task), requests (Instructions), case input (Context), precautions (Caveat) and output guidance (OutputIndicator).
3. The judgment document similar case matching model training method according to claim 1 or 2, characterized in that: The similar case matching model is trained by a joint learning method, including first training, second training and third training; The first training comprises the following steps: S101. any one of the Bert models with shared weights in the similar case matching model inputs the main content of a judgment for encoding; S102. Fusing and outputting the output features of several coding layers in any one of the Bert models; S103. Obtain a sentence embedding vector by performing an average pooling operation on the output; S104. Connect the sentence embedding vectors of the first Bert model and other Bert models respectively to obtain the interaction results between the sentence embedding vectors; S105. Based on the interaction result, the probability of the predicted label is calculated by a multi-layer perceptron to determine the approximation between the judgment document input into the first Bert model and the judgment documents input into other Bert models; The second training comprises the following steps: S201. Generate corresponding legal article serial numbers with semantic information for the legal clauses involved in the legal analysis and application in the judgment document according to the legal article hierarchy; the legal article serial numbers include serial numbers of different hierarchical structures connected by connectors and case serial numbers; S202. For the similar case matching model after the first training, any one of the Bert models with shared weights in the similar case matching model inputs a legal article serial number of a judgment to encode; S203. Compare the legal article serial numbers of the first Bert model and other Bert models according to the serial numbers of different hierarchical structures connected by connectors, and reward Bert models with the same serial numbers at the same level, and punish Bert models with different serial numbers at the same level; Wherein: the third training comprises the following steps: S301. Any one of the three Bert models with shared weights in the similar case matching model inputs the main content of a judgment for encoding; wherein one Bert model inputs the current sample, one Bert model inputs a positive sample of text similar to the current sample, and one Bert model inputs a negative sample of text dissimilar to the current sample; S302. Fusing and outputting the output features of several coding layers in any one of the Bert models; S303. Obtain a sentence embedding vector by performing an average pooling operation on the output; S304. Optimize the semantic representation of the vector space by maximizing the similarity between the sentence embedding vector of the positive sample and the current text and the sentence embedding vector of the positive sample, and minimizing the similarity between the sentence embedding vector of the negative sample and the current text and the sentence embedding vector of the negative sample.
4. The judgment document similar case matching model training method according to claim 3 is characterized in that: in, The main contents include case number, case facts and legal elements, adjudication analysis, legal analysis and application, and judgment results; Among them, in step S102, the output features of several coding layers in any one of the Bert models are fused and output, as shown in the following formula: In the formula, the hidden layer state vector of the Bert model is i represents the case number; j∈[1,5,9,12], Represents the output of the 1st, 5th, 9th, and 12th layers of the Bert model; represents the output of the first Bert model, represents the output of the second Bert model, represents the output of the third Bert model; where Where m represents the number of input batches, n represents the total number of characters in all sentences contained in a batch, and d represents the hidden layer size of the word embedding layer; The output in step S103 is subjected to an average pooling operation to obtain a sentence embedding vector, including the output of the first Bert model being subjected to an average pooling operation to obtain a sentence embedding vector The output of the second Bert model is average pooled to obtain the sentence embedding vector The output of the third Bert model is average pooled to obtain the sentence embedding vector Among them, in step S104, the sentence embedding vectors of the first Bert model and other Bert models are respectively connected to obtain the interaction result between the sentence embedding vectors, which is shown in the following formula: Where U ab Represents the sentence embedding vector The interaction result, U ac Represents the sentence embedding vector The interaction results; In step S105, according to the interaction result, the probability value of the predicted label is calculated by a multilayer perceptron, as shown in the following formula: p i =MLP(U ab -U ac ) In the formula, p i Indicates that the predicted label is y i The probability value of .
5. The judgment document similar case matching model training method according to claim 3 is characterized in that: The first training adopts the cross entropy loss function for training, which is shown in the following formula: Where, L CE represents the cross entropy loss function, y i Represents the predicted label.
6. The judgment document similar case matching model training method according to claim 3 is characterized in that: The second training adopts the total penalty loss function for training, which is shown in the following formula: Where, L penalty represents the total penalty loss function; Among them, the reward penalty function R t To express the rewards and penalties at each layer t of the Bert model, the following formula is shown: In the formula, μ represents the reward coefficient, Represents the value of the query document ID at level t; i d,t Represents the value of the candidate document ID at level t; Represents the level penalty coefficient, L t Indicates the depth or level value of the current hierarchy.
7. The judgment document similar case matching model training method according to claim 3 is characterized in that: The third training adopts contrastive learning loss function for training, as shown in the following formula: Where, L contrastive represents the contrastive learning loss function, τ is a hyperparameter, sim is the similarity calculation function of the main contents of the two judgments, N represents the batch size, i represents the batch number, Indicates that the output of the first Bert model is averaged through the pooling operation to obtain the sentence embedding vector. Indicates that the output of the second Bert model obtains the sentence embedding vector through the average pooling operation. It indicates that the output of the third Bert model is averaged and pooled to obtain the sentence embedding vector.
8. A similar case judgment matching method based on a judgment document similar case matching model, characterized in that: The similar case matching model includes a plurality of Bert models with shared weights, and the matching method includes the following steps: Any one of the Bert models with shared weights in the similar case matching model inputs the main content of a judgment for encoding; The output features of several coding layers in any one of the Bert models are merged and output; Obtain a sentence embedding vector by performing an average pooling operation on the output; Connect the first Bert model and the sentence embedding vectors of other Bert models to obtain the interaction results between the sentence embedding vectors; Merging the interaction result with the first Bert model and the legal article serial number encoded by other Bert models; According to the fusion result, the probability value of the predicted label is calculated by a multi-layer perceptron to obtain the approximation between the judgment document input into the first Bert model and the judgment documents input into other Bert models.
9. The method for matching similar judgment documents based on the judgment document similar case matching model according to claim 1 is characterized in that: The similar case matching model is obtained by training using any one of the training methods described in claims 1-7; The judgment text includes case facts, adjudication analysis, legal analysis and application, and judgment results; the legal elements include basic legal elements and specific types of legal elements; Among them, the legal elements are obtained through the large language model prompting engineering prompt word framework, and the prompt framework includes tasks (Task), requests (Instructions), case input (Context), precautions (Caveat) and output guidance (OutputIndicator).
10. An electronic device, comprising: One or more processors, a memory, and one or more programs; wherein the one or more programs are stored in the memory, and the one or more programs include instructions, which, when executed by the electronic device, enable the electronic device to perform any one of the methods described in claims 1-9.
Citation Information
Cited By
Full-text retrieval enhancement method, system and equipment for hydraulic power plant knowledge and medium
CN120104777A
A method, system, device and medium for full-text search enhancement of hydroelectric plant knowledge
CN120104777B
Legal system class case retrieval method and system
CN120353922A
Text processing method for financial cases
CN120724414A