A similar case determination method based on context of legal provisions
By constructing a hybrid retrieval strategy based on legal context and a multi-level semantic representation generation mechanism, the problem of insufficient legal context recognition in existing technologies has been solved, achieving efficient and accurate determination of similar cases and improving the accuracy and transparency of legal judgments.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- GUIZHOU UNIV
- Filing Date
- 2026-03-12
- Publication Date
- 2026-06-05
AI Technical Summary
Existing technologies for identifying similar cases in the legal field struggle to accurately identify the context of legal provisions, lack effective legal provision-driven information filtering mechanisms and the ability to generate structured dispute summaries, resulting in weak ability to identify legal disputes, insufficient interpretability, and high data computation costs.
This paper adopts a similar case determination method based on legal context, and performs legal provision matching by constructing a hybrid retrieval strategy. It generates disputed points and summary generation prompt templates, uses a pre-trained large language model to generate descriptions of disputed legal issues and key fact summaries, and calculates similarity scores through a cross encoder to achieve efficient and accurate case retrieval in legal context.
It improves the accuracy and interpretability of similar case determination, reduces interference from redundant information, significantly enhances the transparency and efficiency of legal adjudication, and reduces reasoning delays when data is scarce.
Smart Images

Figure CN122155898A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of intelligent legal retrieval and case adjudication assistance technology, and in particular to a method for determining similar cases based on the context of legal provisions. Background Technology
[0002] Legal texts are characterized by complex structures, dense terminology, and strong contextual dependence, making it difficult to directly apply general natural language processing models to the legal field. Their low interpretability also limits their application in legal adjudication assistance. Similarity case determination based on legal context aims to retrieve examples from historical cases that are highly similar to the case at the level of legal application, thereby providing judicial personnel with accurate references, improving trial efficiency and consistency of judgments, and thus has significant practical implications.
[0003] Currently, methods for determining similar cases mainly fall into two categories: the first is the traditional retrieval method based on keywords and statistical features, which relies on techniques such as inverted indexes to calculate the surface similarity of texts. However, it is difficult to identify legal disputes and key facts, is easily influenced by irrelevant narratives, and cannot distinguish between semantically similar cases but with different applicable legal provisions. The second is the method based on deep learning semantic vectors, which uses pre-trained models to generate case representations and calculate similarity. Although it introduces legal information to some extent, it usually only merges texts through simple splicing and fails to explicitly guide the model to focus on legal elements, resulting in a large amount of noise in the representation vectors.
[0004] Existing methods generally suffer from deficiencies such as a lack of precise focus on legal context, weak ability to extract points of contention, insufficient interpretability, and high data and computational costs. The root cause lies in the lack of an effective legal provision-driven information filtering mechanism and the ability to generate structured dispute summaries. The core challenge is how to achieve efficient, accurate, and interpretable case retrieval and judgment under the constraints of legal provisions. Summary of the Invention
[0005] The purpose of this invention is to provide a method for determining similar cases based on the context of legal provisions, thereby solving the problems existing in the prior art.
[0006] To achieve the above objectives, this invention provides a method for determining similar cases based on the context of legal provisions, comprising the following steps: Step 100: Receive the query request for the case to be judged, and extract the case fact text of the case to be judged from the query request; Cases pending judgment include anchor cases and candidate cases; Step 200: Construct a hybrid retrieval strategy to match legal provisions with the case fact text. By calculating the weighted fusion result of keyword matching score and semantic similarity score, retrieve the set of target legal provisions corresponding to the case fact text from the legal provision database. Step 300: Construct a dispute generation prompt template based on the target legal provisions set and case fact text, and call a pre-trained large language model to generate a description of the disputed legal issues corresponding to the case fact text; Step 400: Construct a summary generation prompt template based on the target legal provisions set and case fact text, and call a pre-trained large language model to generate a summary of key facts corresponding to the case fact text; Step 500: The description of the disputed legal issues and the summary of key facts are concatenated in a preset structured format to generate a fused semantic representation corresponding to the case fact text; Step 600: Input the fused semantic representations of the anchor case and candidate cases into the cross-encoder model, calculate the similarity score, and determine the candidate case most similar to the anchor case as the judgment result based on the similarity score.
[0007] Furthermore, anchor cases specifically refer to target cases that serve as the basis for similarity determination. Candidate cases are specifically one or more candidate cases that are compared with anchor cases in terms of similarity; The case fact text specifically refers to the original case description text that forms the basis of anchor cases and candidate cases, including the identity information of the parties, the case background, the disputed facts, and the course of action.
[0008] Furthermore, the calculation process for the weighted fusion result of keyword matching score and semantic similarity score is as follows: The keyword matching score is calculated using the following expression: ; in, Indicates the first The case fact text and the first Keyword matching score of each legal provision text Indicates the first in the query 1 term, Indicates the total number of query terms. Indicates terms Inverse document frequency, Indicates terms In the document word frequency in Document Length, This represents the average length of documents in the corpus. and These are the parameters for adjusting the matching scores of the first and second keywords; The semantic similarity score is calculated using the following expression: ; in, Indicates the first Vector representation of the factual text of each case. Indicates the first Vector representation of each legal provision text Represents the vector dimension. and They represent the first The case fact text vector and the first The first legal text vector Each dimension component; Finally, a weighted fusion is performed, expressed as: ; in, This represents the weighting coefficient for keyword matching scores, with a value range of [0, 1]. The weighting coefficient represents the semantic similarity score.
[0009] Furthermore, the set of target legal provisions corresponding to the case fact text is retrieved from the legal provisions database by sorting all legal provisions in the database according to the comprehensive similarity score, and selecting the top K legal provisions with the highest scores as the set of target legal provisions, where K is a preset threshold for the number of legal provisions.
[0010] Furthermore, the process of constructing the dispute generation prompt template includes: The server organizes the legal provisions in the target legal provisions set according to the preset legal provisions context format to generate the legal provisions context part; The server will combine the case facts, legal context, and task instructions according to a preset format to generate a complete dispute generation prompt template.
[0011] Furthermore, the process of generating a description of the disputed legal issues corresponding to the factual text of the case includes: Build a complete dispute generation prompt template; The server takes the pre-constructed dispute generation prompt template as input, calls the pre-trained large language model to generate text, and automatically generates a description of the disputed legal issues that meets the requirements. The server performs post-processing on the output of the large language model, including removing redundant formatting marks, limiting the output length to a preset range, and filtering out content that does not conform to legal terminology standards, to obtain a standardized description of the disputed legal issues.
[0012] Furthermore, the process of constructing the summary generation prompt template is as follows: The server combines the case facts, legal context, and summary task instructions according to a preset format to generate a summary generation prompt template.
[0013] Furthermore, the process of generating a summary of key facts corresponding to the case fact text includes: Build a complete summary generation prompt template; The server inputs the summary generation prompt template into the large language model. The model compresses and refines the case facts based on the legal context, automatically identifies key factual elements related to the application of the legal provisions, filters irrelevant descriptions, and generates a key fact summary that meets the requirements. The server performs quality checks on the generated key fact summaries, including checking whether the summaries are within a preset length, whether they contain information about key parties, whether they contain core disputed facts, and whether the language used is objective and neutral.
[0014] Furthermore, the default structured format allows the server to explicitly distinguish different types of semantic information using field identifiers. The default structured format is: "Issue: {Description of the disputed legal issue} \n Summary: {Summary of key facts}"; The "Issue:" section indicates the disputed legal issues, while the "Summary:" section indicates the summary of key facts. The two sections are separated by a newline character "\n".
[0015] Furthermore, determining the candidate case most similar to the anchor case as the judgment result specifically includes the following steps: The server will integrate the semantic representation of anchor cases. Fusion semantic representation of candidate cases The input sequence is concatenated according to the input format of the BERT model to form: "[CLS] { } [SEP] { } [SEP]” Here, [CLS] is the category marker and [SEP] is the separator marker, used to distinguish between two different text inputs; The server feeds the constructed input sequence into a pre-trained cross-encoder model. The model performs deep semantic encoding on the input through a multi-layer Transformer encoder, and finally outputs a representation vector that fuses the interaction information of the two texts at the [CLS] position. ; The server maps the representation vector at the [CLS] position to a similarity score using a linear classifier, calculated as follows: ; in, This represents the representation vector output by the cross encoder at position [CLS], which incorporates the interaction information from the two texts. Represents the weight matrix. This represents the bias vector. The similarity probability distribution is represented by a two-dimensional vector. , This represents the probability that two cases are dissimilar. This represents the probability that two cases are similar. express function; For queries containing multiple candidate cases, the server calculates the similarity score between the anchor case and each candidate case, resulting in a set of similarity scores { ,in The number of candidate cases; The server sorts the candidate cases in descending order based on their similarity scores and selects the candidate case with the highest similarity score as the case most similar to the anchor case.
[0016] Furthermore, a system used in a method for determining similar cases based on the context of legal provisions includes: Legal provision retrieval module: It is used to receive case texts, construct a hybrid retrieval strategy to match legal provisions with the case fact texts, and retrieve the set of target legal provisions corresponding to the case fact texts from the legal provision database by calculating the weighted fusion result of keyword matching score and semantic similarity score.
[0017] The dispute generation module is used to construct dispute generation prompt templates based on the target legal provisions set and case fact texts, and call a pre-trained large language model to generate descriptions of the disputed legal issues corresponding to the case fact texts. The fact summary generation module is used to construct a summary generation prompt template based on the target legal provisions set and case fact text, and call a pre-trained large language model to generate key fact summaries corresponding to the case fact text; The fusion module is used to concatenate the description of the disputed legal issues and the summary of key facts according to a preset structured format to generate a fused semantic representation of the case facts. Similarity determination module: It is used to input the fused semantic representations of the anchor case and candidate cases into the cross-encoder model, calculate the similarity score, and determine the candidate case most similar to the anchor case as the determination result based on the similarity score.
[0018] Therefore, the present invention employs the aforementioned method for determining similar cases based on the context of legal provisions, which has the following beneficial effects: By introducing legal provision retrieval and context constraint generation mechanisms, the case representation automatically focuses on facts and legal elements highly relevant to the judgment outcome, effectively reducing the interference of redundant information on the model's judgment and improving the accuracy of similarity determination.
[0019] By generating a description of the dispute under the constraints of legal provisions, the model can explicitly extract and utilize the core legal disputes of a case, significantly improving the comparability of different cases at the level of key legal issues and solving the technical problem that traditional methods cannot accurately identify legal disputes.
[0020] By outputting structured intermediate results (description of the disputed legal issues and summary of key facts), the system provides a complete chain of reasoning and traceable justification for the final similarity determination, significantly improving the transparency of the system and the trust of legal practitioners.
[0021] By compressing case facts and retaining key factors during the generation stage, the input to the subsequent similarity model is shorter and more focused, reducing inference latency and maintaining good generalization ability even when data is scarce.
[0022] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description
[0023] Figure 1 This is an overall flowchart of a method for determining similar cases based on the context of legal provisions, according to the present invention. Detailed Implementation
[0024] The following detailed description of embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.
[0025] Please see Figure 1 A method for determining similar cases based on the context of legal provisions includes the following steps: Step 100: Receive the query request for the case to be judged, and extract the case fact text of the case to be judged from the query request; It should be noted that the cases to be judged include anchor cases and candidate cases.
[0026] Anchor cases refer to the target cases used as the benchmark for similarity determination, while candidate cases refer to one or more candidate cases that need to be compared with the anchor cases. Case factual text refers to the original case description text that forms the basis of anchor cases and candidate cases, and usually includes the identity information of the parties, case background, disputed facts, and behavioral process, serving as the core input for legal provision matching and dispute summary generation.
[0027] Specifically, the server receives a query request from the user terminal, which contains the identification information and basic information of the case to be judged. Based on the case identification in the query request, the server retrieves the corresponding full text of the case from a pre-set case database, and cleans and standardizes the full text of the case through a pre-set text preprocessing module, extracting the factual text of the case after removing formatting marks, special symbols, and redundant information.
[0028] In one embodiment of the present invention, the process of extracting case fact text includes: segmenting the original case document to identify different paragraphs such as the fact section, the procedural section, and the judgment section; extracting core case fact information from the fact section and filtering out procedural and formal content; denoising the extracted fact text to remove irrelevant citation information, case number, judge's name, and other interfering information; and finally obtaining a standardized text containing the core disputed facts of the case as the case fact text.
[0029] To further ensure the privacy and security of the aforementioned case data, the case database can also be stored in blockchain nodes.
[0030] Step 200: Construct a hybrid retrieval strategy to match legal provisions with the case fact text. By calculating the weighted fusion result of keyword matching score and semantic similarity score, retrieve the set of target legal provisions corresponding to the case fact text from the legal provision database. It should be noted that the embodiments of the present invention include a pre-built legal provision database containing relevant legal articles. This database stores the text content, article number, scope of application, and other information of various legal provisions. The hybrid retrieval strategy refers to a comprehensive retrieval strategy that combines keyword matching and semantic similarity calculation.
[0031] Specifically, the server performs word segmentation and vectorization on the case fact text to obtain its lexical and vector representations. The server then calculates the keyword matching score and semantic similarity score between the case fact text and each legal provision in the legal provisions database, and obtains a comprehensive similarity score through a pre-defined weighted fusion algorithm.
[0032] In one embodiment of the present invention, the calculation process of the hybrid retrieval strategy is as follows: First, the keyword matching score is calculated. The server uses the BM25 algorithm to calculate the keyword matching score between the case fact text and the legal provision text. The calculation formula is as follows: ; in, Indicates the first The case fact text and the first Keyword matching score of each legal provision text Indicates the first in the query 1 term, Indicates the total number of query terms. Indicates terms Inverse document frequency, Indicates terms In the document word frequency in Document Length, This represents the average length of documents in the corpus. and These are the parameters for adjusting the matching score of the first and second keywords, usually... The value is 1.2. The value is 0.75.
[0033] Secondly, semantic similarity scores are calculated. The server uses a pre-trained text vectorization model to encode the case fact text and legal provision text into high-dimensional vectors, and calculates the cosine similarity between the two vectors using the following formula: ; in, Indicates the first Vector representation of the factual text of each case. Indicates the first Vector representation of each legal provision text Represents the vector dimension. and They represent the first The case fact text vector and the first The first legal text vector Each dimension component.
[0034] Finally, a weighted fusion is performed. The server weights and fuses the keyword matching score and semantic similarity score according to preset weights to obtain a comprehensive similarity score. The calculation formula is as follows: ; in, This represents the weighting coefficient for keyword matching scores, with a value ranging from [0, 1], typically 0.3. The weighting coefficient represents the semantic similarity score.
[0035] The server sorts all legal provisions in the legal provisions library according to the comprehensive similarity score, and selects the top K legal provisions with the highest scores as the target legal provisions set, where K is a preset threshold for the number of legal provisions, usually ranging from 5 to 10.
[0036] Step 300: Construct a dispute generation prompt template based on the target legal provisions set and case fact text, and call a pre-trained large language model to generate a description of the disputed legal issues corresponding to the case fact text; It should be noted that the dispute generation prompt template refers to a structured input template used to guide the large language model in generating disputed legal issues. The description of the disputed legal issues refers to a concise summary of the core legal dispute points in the case based on the legal context, used to highlight the key issues in the application of law in the case.
[0037] Specifically, the server concatenates the texts of each legal provision in the target legal provision set according to a preset format to form legal provision context information. The server constructs a dispute generation prompt template containing case factual text, legal provision context information, and task instructions, and sends this template as input to a pre-trained large language model.
[0038] In one embodiment of the present invention, the process of constructing the dispute generation prompt template is as follows: First, the legal context section is constructed. The server organizes the legal provisions in the target legal provision set according to the following format: Relevant legal provisions: Article 1: [Article Number] [Article Content]\n Article 2: [Article Number] [Article Content]\n … \n Article K: [Article Number] [Article Content] Secondly, the server will combine the case factual text, legal context, and task instructions according to the following template format to construct a complete dispute generation prompt template: Case Facts: {Case Fact Text}; {Legal Context} Task: Based on the facts of the above case and relevant legal provisions, please generate the core legal issues in dispute in this case. Requirements: 1) Highlight the legal issues in the case; 2) Be concise and accurate in expression; 3) Do not exceed 100 words. Then, the large language model is invoked. The server takes the pre-constructed dispute generation prompt template as input and calls the pre-trained large language model to generate the text. Based on the input legal context and case facts, the large language model automatically generates a description of the disputed legal issue that meets the requirements.
[0039] Finally, post-processing is performed. The server performs post-processing on the output of the large language model, including removing redundant formatting marks, limiting the output length to a preset range (usually 50-100 characters), and filtering content that does not conform to legal terminology standards, ultimately obtaining a standardized description of the disputed legal issues.
[0040] In a preferred embodiment, the server can also control the output quality of the large language model by setting generation parameters, including setting a temperature parameter to control the randomness of the generated text, setting a maximum length parameter to control the length of the output text, and setting a duplicate penalty parameter to avoid outputting duplicate content.
[0041] Step 400: Construct a summary generation prompt template based on the target legal provisions set and case fact text, and call a pre-trained large language model to generate a summary of key facts corresponding to the case fact text; It should be noted that the summary generation prompt template refers to a structured input template used to guide the large language model in generating key fact summaries. A key fact summary is a concise description of facts formed by extracting and compressing the core factual elements directly related to the legal determination from the case text, under the constraints of the legal context, and removing redundant information.
[0042] Specifically, the server reuses the legal context information constructed in step 300, organizes the target legal provision set, case fact text, and summary generation task instructions according to the preset summary generation prompt template format, constructs the summary generation prompt template, and calls the pre-trained large language model to generate key fact summaries.
[0043] In one embodiment of the present invention, the process of constructing the summary generation prompt template is as follows: First, the legal context information is reused. The server uses the legal context portion already constructed in step 300 to ensure that the description of the disputed legal issue and the summary of key facts are based on the same legal background.
[0044] Secondly, the server will combine the case fact text, legal context, and summary task instructions according to the following template format to construct a complete summary generation prompt template: Case Facts: {Case Fact Text}; {Legal Context} Task: Based on the facts of the above case and relevant legal provisions, please extract a summary of the key facts of this case. Requirements: 1) Retain only the core facts relevant to the legal determination; 2) Remove procedural and background information; 3) Be objective and accurate in expression; 4) Do not exceed 200 words. Then, a summary is generated. The server inputs the summary generation prompt template into the large language model. Based on the legal context, the model performs targeted compression and refinement of the case facts, automatically identifies key factual elements related to the application of the legal provisions, filters irrelevant descriptions, and generates a key fact summary that meets the requirements.
[0045] Next, quality control is performed. The server performs quality checks on the generated summary of key facts, including checking whether the summary length is within the preset range (usually 100-200 words), whether it contains information about key parties, whether it contains core disputed facts, and whether the language is objective and neutral.
[0046] Finally, optimization is performed. For summaries that do not meet quality requirements, the server can optimize them by adjusting generation parameters or regenerating the summary to ensure that the final output of key fact summaries retains the core information of the case while maintaining good conciseness and relevance.
[0047] In a specific application scenario, for a contract dispute case, the original case factual text may contain a large amount of content such as the background of the contract signing, detailed information of the parties, and the performance process, while the key fact summary constrained by the legal context highlights the core facts directly related to the contract law, such as the breach of contract, the extent of the loss, and the points of contention.
[0048] Step 500: The description of the disputed legal issues and the summary of key facts are concatenated in a preset structured format to generate a fused semantic representation corresponding to the case fact text; It should be noted that fusion semantic representation refers to a unified text representation that combines the description of disputed legal issues processed by legal provisions and the summary of key facts in a specific structured format. This representation contains both the disputed focus information of the case and the core factual information, providing high-quality input for subsequent similarity calculation.
[0049] Specifically, the server obtains the description of the disputed legal issues generated in step 300 and the summary of key facts generated in step 400, and concatenates the two parts in an orderly manner according to a preset structured format to form a fused semantic representation containing clear field identifiers.
[0050] In one embodiment of the present invention, the process of generating the fused semantic representation is as follows: First, define the structured format. The server uses field identifiers to explicitly distinguish different types of semantic information. The default structured format is: "Issue: {Description of the disputed legal issue} \n Summary: {Summary of key facts}" The "Issue:" section indicates the disputed legal issues, while the "Summary:" section indicates the summary of key facts. The two sections are separated by a newline character "\n".
[0051] Next, text concatenation is performed. The server replaces the description of the disputed legal issue obtained in step 300 with the {description of disputed legal issue} placeholder in the format template, and replaces the key fact summary obtained in step 400 with the {key fact summary} placeholder, forming a complete fused semantic representation.
[0052] Next, format validation is performed. The server performs format validation on the generated merged semantic representation to ensure that field identifiers are correct, delimiters are standardized, content is complete, and checks whether the total length after merging is within the preset range (usually 300-500 characters).
[0053] Next, quality optimization is performed. The server performs quality optimization on the merged semantic representation, including removing redundant whitespace characters, standardizing punctuation formats, and checking language coherence, to ensure that the merged text has good structure and readability.
[0054] Finally, the final representation is generated. The server uses the format-validated and quality-optimized text as the final fused semantic representation of the case. This representation combines the focus of the dispute with the completeness of the factual content, providing a high-quality semantic foundation for subsequent case similarity comparisons.
[0055] In one embodiment of the present invention, for an infringement case, the fused semantic representation may be: "Issue: Does the actor constitute a direct infringement of another's intellectual property rights, and how is the liability for damages determined? The defendant produced and sold products identical to the plaintiff's patented product without authorization, obtaining sales revenue of 500,000 yuan. The plaintiff suffered economic losses of 300,000 yuan as a result. The two parties have no dispute over the facts of the infringement but disagree on the amount of compensation." This fusion semantic representation clearly reflects the legal disputes (infringement determination and damages) and key facts (infringement and economic loss) of the case, laying the foundation for accurate matching of similar cases.
[0056] Step 600: Input the fused semantic representations of the anchor case and candidate cases into the cross-encoder model, calculate the similarity score, and determine the candidate case most similar to the anchor case as the judgment result based on the similarity score.
[0057] It should be noted that the cross-encoder model is a dual-text encoding model based on a pre-trained Transformer architecture, capable of processing two text inputs simultaneously and directly outputting similarity scores. Compared to methods that calculate similarity after independent encoding, the cross-encoder, through its attention mechanism, can better model the interactive semantics between the two texts.
[0058] Specifically, the server obtains the fused semantic representation of the anchor case and each candidate case, uses the fused semantic representation of each pair of anchor cases and candidate cases as input to the cross encoder, calculates the similarity score between each candidate case and the anchor case, and determines the most similar candidate case based on the score ranking.
[0059] In one embodiment of the present invention, the cross encoder similarity calculation process is as follows: First, the input sequence is constructed. The server then constructs the fused semantic representation of the anchor cases. Fusion semantic representation of candidate cases The input sequence is concatenated according to the input format of the BERT model to form: "[CLS] { } [SEP] { }[SEP]” Here, [CLS] is the category marker and [SEP] is the separator marker, used to distinguish between two different text inputs.
[0060] Next, encoding is performed. The server feeds the constructed input sequence into a pre-trained cross-encoder model. The model performs deep semantic encoding on the input through a multi-layer Transformer encoder, and finally outputs a representation vector that fuses the interaction information of the two texts at the [CLS] position. .
[0061] Then, the similarity score is calculated. The server maps the representation vector of the [CLS] position to a similarity score using a linear classifier, calculated as follows: ; in, This represents the representation vector output by the cross encoder at position [CLS], which incorporates the interaction information from the two texts. Represents the weight matrix. This represents the bias vector. Representing the similarity probability distribution, it is usually a two-dimensional vector. ,in This represents the probability that two cases are dissimilar. This represents the probability that two cases are similar. express function.
[0062] Next, pairwise comparisons are performed. For queries containing multiple candidate cases, the server calculates the similarity score between the anchor case and each candidate case, resulting in a set of similarity scores. ,in This represents the number of candidate cases.
[0063] Then, a sorting and selection process is performed. The server sorts the candidate cases in descending order based on their similarity scores and selects the candidate case with the highest similarity score as the case most similar to the anchor case.
[0064] Finally, the server outputs the judgment result. It returns the candidate case with the highest similarity score and its corresponding similarity score as the final judgment result to the user, while also providing a sorted list of candidate cases for reference.
[0065] A specific embodiment of the present invention is as follows: Application Scenario: A court is hearing a loan contract dispute case. The presiding judge wants to search the existing legal case database for historical cases with the most similar application of law to this case, in order to aid in the consistency of the judgment. The system will input the case (anchor case) and compare it with two historical cases (candidate cases) to determine which is more similar.
[0066] In this embodiment, the case group to be determined consists of one anchor case and two candidate cases, which together form an input triplet for similarity judgment.
[0067] System processing flow: Step 100: Receive the query request and extract the case fact text of the case to be judged, as follows: Anchor Case (A): Zhang borrowed 200,000 yuan from Li without signing a written IOU; only WeChat transfer records and chat logs documenting the loan exist. After the loan term expired, Zhang failed to repay the loan, and Li filed a lawsuit, claiming a loan relationship existed. Zhang argued that the funds were a gift. The key issues in dispute are: whether a loan agreement existed, and whether the electronic evidence is sufficient to prove a creditor-debtor relationship.
[0068] Candidate Case B: Wang transferred 150,000 yuan to Zhao without signing a written IOU. The plaintiff provided bank transfer receipts and WeChat chat records between the two parties. The court held that, based on the evidence, a de facto loan had been established and ordered Wang to repay the loan. Candidate Case C: Liu sued Zhou for the return of a loan of 300,000 yuan, providing only transfer records and no supporting evidence such as loan agreements or chat logs. The court deemed the evidence insufficient and dismissed the plaintiff's claim.
[0069] Step 200: The system performs text analysis on the anchor case and retrieves the most relevant legal provisions, such as: Article 679 of the Civil Code (loan contracts between natural persons); Article 17 of the Supreme People's Court's Judicial Interpretation on Private Lending (the probative value of electronic evidence); Article 64 of the Civil Procedure Law (allocation of the burden of proof), etc. Step 300: The system calls the large language model, generates a prompt template based on the constructed dispute points, and generates a description of the disputed legal issues. Issue: The central issue in this case is whether there was a genuine agreement to lend and borrow, and whether electronic evidence can prove the existence of a lending relationship.
[0070] Step 400: The system calls the large language model, generates a prompt template based on the constructed summary, and generates a summary of key facts: Summary: The plaintiff transferred 200,000 yuan via WeChat without signing a loan agreement, but the plaintiff has a complete chat history showing words such as "borrowing money" and "repayment time"; the defendant argued that it was a gift.
[0071] Step 500: For case A, the system generates a structured representation: Issue: Whether a genuine loan relationship exists and the probative value of electronic evidence; Summary: A WeChat transfer of 200,000 yuan was made without a written agreement. The chat history contained expressions such as "borrowing money," which the defendant referred to as a gift.
[0072] Candidate cases B and C also generated similar representations.
[0073] Step 600: Similarity Determination Input (A, B) yields a similarity score of 0.92. Input (A, C) yields a similarity score of 0.61. The system determined that candidate case B is more similar to anchor case A and recommended it to the judge as a reference case.
[0074] In this embodiment of the invention, a query request for a case to be judged is received, and the case fact text of the case to be judged is extracted from the query request; a hybrid retrieval strategy is constructed to match the case fact text with legal provisions, and a set of target legal provisions corresponding to the case fact text is retrieved from the legal provision database by calculating the weighted fusion result of keyword matching score and semantic similarity score; a dispute generation prompt template is constructed based on the target legal provision set and the case fact text, and a pre-trained large language model is called to generate a description of the disputed legal issue corresponding to the case fact text; a summary generation prompt template is constructed based on the target legal provision set and the case fact text, and a pre-trained large language model is called to generate a summary of key facts corresponding to the case fact text; the description of the disputed legal issue and the summary of key facts are concatenated according to a preset structured format to generate a fused semantic representation corresponding to the case fact text; the fused semantic representations in the anchor case and candidate cases are input into a cross-encoder model to calculate the similarity score, and the candidate case most similar to the anchor case is determined as the judgment result based on the similarity score. This invention significantly improves the accuracy and interpretability of legal case similarity determination through a multi-level semantic representation generation mechanism constrained by legal provision context.
[0075] To verify the effectiveness of the method of the present invention, systematic experiments were conducted on multiple publicly available legal case datasets, as detailed below: 1. Dataset Introduction: 1) CAIL2019-SCM Dataset. The CAIL2019-SCM dataset comes from the 2019 "Chinese Artificial Intelligence and Law Challenge" and is one of the earliest standard evaluation datasets in China for similar case matching tasks. This dataset contains 8,964 case triplets. Each sample consists of an anchor case A and two candidate cases B and C. The task is to determine which candidate case is more similar to A. The cases are from the Supreme People's Court of China, covering civil and criminal disputes, and all texts are in Chinese. This invention uses the official partitioning: 5,102 training cases, 1,500 validation cases, and 1,536 test cases.
[0076] 2) The LeCaRD dataset. LeCaRD (Legal Case Retrieval Dataset) is a Chinese dataset for similar case retrieval tasks, containing 107 query cases and 10,700 candidate cases, all of which are criminal cases published by the Supreme People's Court of China. Each query case yields 100 candidate cases through an initial search, of which up to 30 are labeled as similar cases by legal experts. This study rewrites LeCaRD into a pairwise decision format, training and evaluating by constructing triples between the query and two candidate cases, constructing approximately 3,000 training triples in total. This dataset emphasizes fine-grained distinction of legal relevance between similar cases, making it highly challenging.
[0077] 3) LeCaRDv2 Dataset. LeCaRDv2 is an upgraded version of LeCaRD and is one of the largest Chinese legal similarity case retrieval datasets currently available, covering a wider range of criminal charge types. The dataset contains approximately 800 query cases, each with 30 candidate cases manually labeled by legal professionals, totaling 24,000 query-candidate pairs. This invention uses a training set consisting of 720 query cases (approximately 21,600 pairs) and tests it on 80 held-out query cases. This dataset offers greater diversity in case types and broader coverage of legal provisions, making it suitable for evaluating the model's generalization ability in large-scale, cross-topic scenarios.
[0078] 4) Contract-SCM Dataset. To test the adaptability of the method in civil case scenarios, this invention constructs a similar case matching dataset for the field of contract law. This dataset is derived from public legal databases, and the case types include sales contracts, lease contracts, loan contracts, etc. This invention filters out case pairs that cite the same contract law provisions and have similar judgment conclusions, and constructs 3,200 triplet samples. Each sample contains an anchor case, a candidate case on the same legal issue, and a comparative case on different legal issues. The labels were manually verified by two law graduate students. The average length of the cases in this dataset is approximately 300 words. The text is shorter, but the contract terms are more professionally worded and the reasoning is more detailed, posing a challenge for cross-domain transfer of the model.
[0079] 2. Evaluation indicators: To evaluate the performance of this invention in the similarity case judgment task, standard evaluation metrics were adopted. The main evaluation metric is accuracy (ACC), which measures the model's correctness in identifying more similar cases in the triplet judgment task.
[0080] The specific definition is as follows: In each triplet sample (A, B, C), the model needs to determine which candidate case B or C is more similar to the anchor case A. If the model selects the candidate case labeled "more similar," it is considered to have made a correct judgment. Accuracy is the proportion of triplets correctly judged by the model in the test set.
[0081] This metric directly reflects the model's ability to make correct judgments in the "pair comparison" task. The higher the value, the better the performance, with 100% being the optimal ideal value.
[0082] 3. Main experimental results: This invention presents a systematic comparative experiment between the proposed method and several mainstream baseline models on four legal domain datasets. Table 1 shows the accuracy performance of the model on the CAIL2019-SCM, LeCaRD, LeCaRDv2, and Contract-SCM datasets, respectively. The experimental results are shown in Table 1: Table 1 Main Experiment Results ;
[0083] 1) Results on the CAIL2019-SCM dataset. This dataset is an evaluation set for similar case determination criteria in the field of criminal law. The model of this invention achieved a top accuracy of 76.15% on the test set, significantly outperforming the strongest existing baseline models, such as T5-LARGE (74.84%) and GPT-2 (74.31%), by 1.31% and 1.84%, respectively. Traditional neural network models such as TextCNN (67.40%) and TextRNN (68.77%) performed far worse than models based on the Transformer architecture. Even among Transformer models, large-scale versions (such as RoBERTa-LARGE) significantly outperformed their base version (RoBERTa-BASE), indicating the impact of model size on representational power. While models incorporating knowledge augmentation or domain adaptation (such as KnowBERT, Lawformer, and LEFSM) have certain advantages, they still have limitations in capturing the semantic details of criminal law. The significantly superior performance of the model in this invention is attributed to its introduction of a multi-level semantic representation mechanism for legal provisions and points of contention, which effectively enhances the semantic comparison capability in legal scenarios.
[0084] 2) Results on the LeCaRD dataset. This dataset emphasizes fine-grained similarity discrimination, testing the model's ability to discriminate within a criminal legal context. The method of this invention achieved an accuracy of 82.35%, significantly higher than all comparable models. Compared to T5-BASE (79.84%) and T5-LARGE (79.44%), it represents improvements of 2.51% and 2.91%, respectively. Other high-performing models such as GPT-2 (79.34%) and KALM (77.95%) were also surpassed by this invention, indicating its superior ability in modeling structured legal information. Although the Transformer model generally outperforms traditional methods (such as TextCNN and TextRNN), it is still insufficient to compensate for the lack of deep modeling capabilities for "legal disputes" and "key facts." This invention effectively fills this gap through legal provision-guided generation.
[0085] 3) Results on the LeCaRDv2 dataset. This dataset is larger and covers a wider range of legal topics. Our invention also achieved a top accuracy of 82.93% on this dataset, surpassing T5-BASE (80.31%) and T5-LARGE (79.94%) by 2.62% and 3.49%, respectively. Other mainstream models such as RoBERTa-LARGE (75.58%) and Lawformer (75.87%) showed weaknesses in handling generalized legal topics, indicating insufficient versatility. Our solution maintains a stable leading advantage even under large-scale and diverse legal tasks, demonstrating its robustness and scalability.
[0086] 4) Results on the Contract-SCM dataset. This dataset focuses on civil law scenarios, with shorter texts but more detailed reasoning. The method described in this invention achieved an accuracy of 79.05% on this dataset, outperforming GPT-2 (76.33%) and T5-BASE (75.86%), with advantages of 2.72% and 3.19%, respectively. Despite the specialized terminology and complex reasoning inherent in contract law, traditional models struggle to accurately model the logic between clauses. This invention's model, by introducing a contract clause and legal point compression strategy, effectively models the key connections between cases, demonstrating excellent cross-domain transfer capabilities.
[0087] The experimental results from the four datasets show that the method proposed in this invention exhibits consistent performance advantages in similar case determination tasks in the legal field, particularly in: demonstrating significant statistical advantages in improving accuracy; showing robustness to multiple types of legal tasks (criminal / civil); adapting to challenges such as large-scale queries and diverse legal topics; and effectively integrating explicit legal provisions, points of contention, and factual elements to enhance legal semantic modeling capabilities.
[0088] These results fully verify the application value of the core technical strategies of this invention, such as multi-level fusion, legal provision guidance, and structured representation, in legal practice, and provide higher-performance underlying algorithm support for intelligent judicial systems.
[0089] 4. Ablation test results: To further analyze the role of each module in the proposed model, an ablation experiment was conducted on a dataset. This experiment involved progressively removing or replacing key components of the model and observing their impact on the final performance, thereby verifying the effectiveness and necessity of each part. The corresponding experimental results are shown in Table 2.
[0090] This invention designs the following four ablation variants: Remove controversial issues: Remove controversial legal issues generated by the large language model from the fusion representation, and retain only the case fact summary.
[0091] Remove fact summary: Remove the case fact summary generated by the Large Language Model (LLM) in the fused representation, and retain only the disputed points.
[0092] Dispute and summary removal: Completely skip the large language model generation stage and directly use the original full text of the case as input, which is equivalent to a traditional baseline model.
[0093] Remove legal context: When generating the focus of the dispute and the summary of facts, no legal text is provided as input; it is generated solely based on the facts of the case to assess the role of legal context input.
[0094] Table 2 Ablation Experiment Results
[0095] The following conclusions can be drawn from the experimental results in Table 2: 1) The importance of the issue to the model. After removing the issue module, the accuracy dropped by about 3 percentage points on all datasets (e.g., from 76.15% to 73.12% on CAIL2019-SCM), indicating that the extraction of legal issues is of great significance for guiding case comparison.
[0096] 2) The fact summary is the most critical part of information compression. The reduction in accuracy is even more pronounced after removing the fact summary, with the accuracy rate further decreasing to 72.08% (CAIL2019-SCM), indicating that concise case facts are the foundation for supporting semantic comparison and legal logical reasoning.
[0097] 3) Skipping the generation stage entirely results in the lowest performance. If the dispute and summary are completely removed, and the original case text is used as input, the accuracy further drops to 71.29%, approaching the level of traditional text matching models. This indicates that the structured representation strategy of this invention greatly improves the expression efficiency and comparison ability.
[0098] 4) The legal context provides key legal constraints. After removing the legal text as contextual input, the accuracy rate dropped by about 1–2 percentage points (e.g., CAIL2019-SCM dropped from 76.15% to 74.16%), indicating that although large language models can learn semantics from case facts, explicit guidance from legal text can improve the professionalism and consistency of the generated content.
[0099] This ablation experiment demonstrates that the sub-modules in the multi-level representation mechanism proposed in this invention are complementary and irreplaceable: the fact summary is the most influential component and the basis for accurate comparison; the dispute extraction provides interpretability and judgment direction; and the legal context input further enhances the legal professionalism of semantic alignment.
[0100] This experiment verifies the rationality and effectiveness of the "structured generation + law-driven + pairwise judgment" strategy adopted in this invention, and also provides a technical basis for subsequent model optimization and system implementation.
[0101] 5. Other experimental results: 1) Generalization to Unseen Laws. This invention constructs a special test subset in the Contract-SCM dataset to verify the model's generalization ability to legal provisions not present in the training set. This subset contains 100 triplet samples, where the key legal provisions involved in each anchor case are not present in the training set (such as certain environmental protection provisions). On this subset, the accuracy of the model in this invention reaches 76%, while the BERT-Base baseline model only achieves 63%. This result demonstrates that the method of this invention possesses strong "generalization ability to new legal provisions" and is applicable to constantly updated legal systems. The general legal knowledge introduced by LLM in dispute generation helps the model perform semantic reasoning on new regulations, enabling reasonable modeling through dispute text even if the provisions are unseen. In contrast, traditional models (such as BERT-Base) rely on word embeddings and lack the ability to handle unseen legal terms (especially low-frequency or OOV terms), leading to a significant performance drop.
[0102] This experiment demonstrates that the introduction of a large language model and a legal provision guidance mechanism provides the invention with "open-world generalization capability," making it applicable to real-world application scenarios where legal provisions are frequently revised and added.
[0103] 2) Cross-domain transferability. To test the model's transferability across different legal domains, this invention conducted a zero-shot cross-domain evaluation: the model trained on the criminal law dataset LeCaRD was directly applied to the contract law dataset Contract-SCM without fine-tuning. Under this setting, the accuracy of this invention's model was 71%, while BERT-Base only achieved 62% under the same conditions, a performance difference of nearly 9 percentage points. This invention also conducted reverse testing: the model trained on Contract-SCM was tested on a subset of criminal case samples. The accuracy of this invention's model was 74%, while BERT-Base achieved 68%.
[0104] These experiments demonstrate that the "dispute point + key point summary" representation method adopted in this invention possesses cross-domain generalization capabilities. The model captures common legal concepts such as "fraud," "breach of contract," and "liable party" through semantic abstraction, enabling semantic transfer between criminal and civil cases. In contrast, traditional models often only capture surface features (such as amounts and names), resulting in a high misjudgment rate in cross-domain tasks.
[0105] 3) Efficiency Analysis. This invention also evaluates the computational efficiency of the method, mainly divided into two stages: LLM generation stage (offline or cached): The process of generating the dispute and summary is time-consuming. For example, performing this process on 5000 cases in the CAIL2019-SCM dataset takes about 2 hours (API method). However, this process can be completed as an offline preprocessing step, suitable for non-real-time scenarios such as legal retrieval systems and judgment document management. For real-time applications, a caching mechanism or model distillation scheme can be adopted: This invention fine-tunes a medium-sized model with 6 billion parameters (using 1000 LLM-generated data as the training set), reducing the generation time to only 0.5 seconds per data point, with an accuracy decrease of only about 1%, achieving a balance between speed and performance. Judgment stage (real-time response): The judgment model uses BERT-Base, performing cross-coding once on two fused text inputs (about 300 tokens), with each pair of inferences requiring only a few milliseconds, possessing real-time processing capabilities. Even if two predictions need to be performed separately for candidate cases B and C, it can still meet the response requirements of online judgment support systems. In summary, although the method of the present invention introduces additional generation steps, it can optimize deployment strategies through preprocessing, model compression, and other methods, thereby maintaining high performance while meeting the efficiency requirements of practical engineering systems.
[0106] Other aspects fully demonstrate the advantages of this invention in the following aspects: strong generalization ability to unseen legal provisions, adapting to new legal provisions, obscure clauses and regulatory evolution; cross-legal domain transferability, supporting transfer from criminal law to contract law and vice versa, indicating that the model learns semantic abstraction rather than surface matching; possessing engineering-friendly efficiency characteristics, supporting offline processing, high-speed inference and model compression, adapting to various practical system deployment needs.
[0107] These advantages further enhance the versatility, practicality, and forward-looking nature of the present invention's solution in the scenario of "semantic modeling of complex legal tasks".
[0108] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit them. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the technical solutions of the present invention, and these modifications or equivalent substitutions cannot cause the modified technical solutions to deviate from the spirit and scope of the technical solutions of the present invention.
Claims
1. A method of determining a similar case based on a context of a statute, characterized by, Includes the following steps: Step 100: Receive the query request for the case to be judged, and extract the case fact text of the case to be judged from the query request; Cases pending judgment include anchor cases and candidate cases; Step 200: Construct a hybrid retrieval strategy to match legal provisions with the case fact text. By calculating the weighted fusion result of keyword matching score and semantic similarity score, retrieve the set of target legal provisions corresponding to the case fact text from the legal provision database. Step 300: Construct a dispute generation prompt template based on the target legal provisions set and case fact text, and call a pre-trained large language model to generate a description of the disputed legal issues corresponding to the case fact text; Step 400: Construct a summary generation prompt template based on the target legal provisions set and case fact text, and call a pre-trained large language model to generate a summary of key facts corresponding to the case fact text; Step 500: The description of the disputed legal issues and the summary of key facts are concatenated in a preset structured format to generate a fused semantic representation corresponding to the case fact text; Step 600: Input the fused semantic representations of the anchor case and candidate cases into the cross-encoder model, calculate the similarity score, and determine the candidate case most similar to the anchor case as the judgment result based on the similarity score.
2. The method of claim 1, wherein: Anchor cases are specifically target cases used as benchmarks for similarity determination; Candidate cases are specifically one or more candidate cases that are compared with anchor cases in terms of similarity; The case fact text specifically refers to the original case description text that forms the basis of anchor cases and candidate cases, including the identity information of the parties, the case background, the disputed facts, and the course of action.
3. The method for determining similar cases based on the context of legal provisions according to claim 2, characterized in that, The calculation process for the weighted fusion result of keyword matching score and semantic similarity score is as follows: The keyword matching score is calculated using the following expression: ; in, Indicates the first The case fact text and the first Keyword matching score of each legal provision text Indicates the first in the query 1 term, Indicates the total number of query terms. Indicates terms Inverse document frequency, Indicates terms In the document word frequency in Document Length, This represents the average length of documents in the corpus. and These are the parameters for adjusting the matching scores of the first and second keywords; The semantic similarity score is calculated using the following expression: ; in, Indicates the first Vector representation of the factual text of each case. Indicates the first Vector representation of each legal provision text Represents the vector dimension. and They represent the first The case fact text vector and the first The first legal text vector Each dimension component; Finally, a weighted fusion is performed, expressed as: ; in, This represents the weighting coefficient for keyword matching scores, with a value range of [0, 1]. The weighting coefficient represents the semantic similarity score.
4. The method for determining similar cases based on the context of legal provisions according to claim 3, characterized in that: The set of target legal provisions corresponding to the case facts is retrieved from the legal provisions database by sorting all legal provisions in the database according to the comprehensive similarity score, and selecting the top K legal provisions with the highest scores as the target legal provisions set, where K is a preset threshold for the number of legal provisions.
5. The method for determining similar cases based on the context of legal provisions according to claim 4, characterized in that, The process of constructing the dispute generation hint template includes: The server organizes the legal provisions in the target legal provisions set according to the preset legal provisions context format to generate the legal provisions context part; The server will combine the case facts, legal context, and task instructions according to a preset format to generate a complete dispute generation prompt template.
6. The method for determining similar cases based on the context of legal provisions according to claim 5, characterized in that, The process of generating a description of the disputed legal issues corresponding to the factual text of a case includes: Build a complete dispute generation prompt template; The server takes the pre-constructed dispute generation prompt template as input, calls the pre-trained large language model to generate text, and automatically generates a description of the disputed legal issues that meets the requirements. The server performs post-processing on the output of the large language model, including removing redundant formatting marks, limiting the output length to a preset range, and filtering out content that does not conform to legal terminology standards, to obtain a standardized description of the disputed legal issues.
7. The method for determining similar cases based on the context of legal provisions as described in claim 6, characterized in that, The process of building the summary generation prompt template is as follows: The server combines the case facts, legal context, and summary task instructions according to a preset format to generate a summary generation prompt template.
8. The method for determining similar cases based on the context of legal provisions according to claim 7, characterized in that, The process of generating a summary of key facts corresponding to the case fact text includes: Build a complete summary generation prompt template; The server inputs the summary generation prompt template into the large language model. The model compresses and refines the case facts based on the legal context, automatically identifies key factual elements related to the application of the legal provisions, filters irrelevant descriptions, and generates a key fact summary that meets the requirements. The server performs quality checks on the generated key fact summaries, including checking whether the summaries are within a preset length, whether they contain information about key parties, whether they contain core disputed facts, and whether the language used is objective and neutral.
9. The method for determining similar cases based on the context of legal provisions according to claim 8, characterized in that: The default structured format is for the server to explicitly distinguish different types of semantic information using field identifiers. The default structured format is: "Issue: {Description of the disputed legal issue} \n Summary: {Summary of key facts}"; The "Issue:" section identifies the legal issues in dispute, while the "Summary:" section identifies the key facts summary. The two sections are separated by a newline character "\n".
10. The method for determining similar cases based on the context of legal provisions according to claim 9, characterized in that, The process of identifying the candidate case most similar to the anchor case as the determination result includes the following steps: The server will integrate the semantic representation of anchor cases. Fusion semantic representation of candidate cases The input sequence is concatenated according to the input format of the BERT model to form: "[CLS] { } [SEP] { } [SEP]” Here, [CLS] is the category marker and [SEP] is the separator marker, used to distinguish between two different text inputs; The server feeds the constructed input sequence into a pre-trained cross-encoder model. The model performs deep semantic encoding on the input through a multi-layer Transformer encoder, and finally outputs a representation vector that fuses the interaction information of the two texts at the [CLS] position. ; The server maps the representation vector at the [CLS] position to a similarity score using a linear classifier, calculated as follows: ; in, This represents the representation vector output by the cross encoder at position [CLS], which incorporates the interaction information from the two texts. Represents the weight matrix. This represents the bias vector. The similarity probability distribution is represented by a two-dimensional vector. , This represents the probability that two cases are dissimilar. This represents the probability that two cases are similar. express function; For queries containing multiple candidate cases, the server calculates the similarity score between the anchor case and each candidate case, resulting in a set of similarity scores { ,in The number of candidate cases; The server sorts the candidate cases in descending order based on their similarity scores and selects the candidate case with the highest similarity score as the case most similar to the anchor case.