Method and device for recommending legal provisions
By constructing and training multiple legal models and using the Lora method for efficient fine-tuning, the problems of limited natural language processing capabilities and large data volume of existing legal recommendation methods are solved, and automated search and recommendation of the basis for punishment in legal cases is realized, and processing efficiency and accuracy are improved.
Patent Information
- Application Number
- CN202411588058.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-08
- Publication Date
- 2025-03-14
AI Technical Summary
When the existing legal recommendation method uses deep learning algorithms, the natural language processing capability is limited, the indicators are difficult to exceed 60%, and the amount of case data required during training of a single model is large.
By building and training multiple models, including label model, case summary model and embedding_model model, the Lora method is used for efficient fine-tuning, combining regular expression slicing legal provisions, and using SimHash algorithm to deduplicate and denoising data, the legal recommendation is achieved.
It improves the efficiency and accuracy of handling legal cases, and realizes the automated search and recommendation of the basis for punishment in legal cases.
Smart Images

Figure CN119621952A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the intersection of legal technology and artificial intelligence, and specifically provides a method and device for recommending legal provisions. Background Art
[0002] In legal practice, case handling involves searching and citing a large number of legal provisions, precedents, and regulations. This process traditionally relies on manual work, which is time-consuming, labor-intensive, and prone to errors. The legal industry has accumulated a massive amount of legal data resources, including legal provisions, precedents, and cases, which make it possible to use advanced technologies such as deep learning for automated processing.
[0003] The existing legal recommendation method has the following disadvantages:
[0004] (1) Although deep learning algorithms are used, the natural language processing capabilities of a single model are limited, and the final indicator is unlikely to exceed 60%;
[0005] (2) When using a single model for training, a large amount of case data is required. Summary of the invention
[0006] The present invention aims at solving the above-mentioned deficiencies of the prior art and provides a method for recommending legal provisions with strong practicability.
[0007] A further technical task of the present invention is to provide a legal provision recommendation device that is reasonably designed, safe and applicable.
[0008] The technical solution adopted by the present invention to solve its technical problem is:
[0009] A method for recommending a legal provision comprises the following steps:
[0010] S1. Clean the data;
[0011] S2, construct training data;
[0012] S3, training and evaluating the embedding_model model;
[0013] S4. Application model.
[0014] Furthermore, in step S1, it further includes:
[0015] S1-1. Collect complete laws, divide the laws into chapters, sections, and articles using regular expressions, and append the current legal name to the beginning of each chapter, section, and article after division;
[0016] S1-2. Build a label model, manually annotate the correspondence between laws and labels, and use Lora to train a general large model to obtain a legal label model: bq_model;
[0017] S1-3. All collected laws are labeled according to bq_model. The labels are dynamic and changeable, including the number of labels and the label content.
[0018] Furthermore, in step S2, it further includes:
[0019] S2-1, remove duplication and noise from the collected data using the SimHash algorithm;
[0020] S2-2, build a case summary model;
[0021] S2-3, construct a model corresponding to summaries and labels;
[0022] S2-4, construct embedding_model model training data based on the legal data segmented in step S1;
[0023] S2-5. Extract part of the constructed data as embedding_model model evaluation data.
[0024] Furthermore, in step S2-1, information on cases that have been completed in a certain region is collected, and each case includes case description information and information on the legal provisions for case punishment;
[0025] In step S2-2, the case and case summary data are manually annotated, and the summary includes: a description of the illegal facts of the case; variable and redundant data are removed, and the case summary model zy_model is obtained by training the general large model using Lora.
[0026] Furthermore, in step S2-3, by manually annotating the summary and label correspondence data, the general large model is trained using Lora to obtain the summary and label correspondence model: zy_bq_model;
[0027] In step S2-4, the embedding_model model structure is as follows: {query: case summary information, positive: [relevant article 1, relevant article 2, relevant article 3], nagtive: [irrelevant article 1, irrelevant article 2, irrelevant article 3]}.
[0028] Furthermore, in step S3, the general large language model is used in combination with the training data constructed in step S2 to perform efficient fine-tuning through the Lora method, and the embedding_model is obtained by training. The case summary and any segmented legal provision are input into the embedding_model to obtain the dependency correlation value X between the two. A threshold is used to filter X, and the value range of X is 0 to 1. The smaller the threshold, the higher the correlation between the two. Finally, the legal provision corresponding to the case summary is obtained.
[0029] Furthermore, the embedding_model model includes a dense vector, a sparse vector, and a combination vector, a multi vector;
[0030] When the embedding_model model inputs the training data constructed in step S2, each query will form a pair of (X, Y) data with each of the positive or nagtive items for the model to learn. The dense vector and sparse vector are constructed separately through the multi-head attention mechanism, and the multi vector is obtained by combining the dense vector and sparse vector through knowledge distillation.
[0031] Furthermore, the evaluation data constructed in step S2 is used to evaluate the embedding_model to obtain model indicators. If the indicators are insufficient, the data types constructed in step S2 are enriched and retrained to ensure that the constructed data covers all case types; through the generalization ability of the large model, the penalty-dependent clauses of new cases are found.
[0032] Furthermore, in step S4, the user inputs a new case, and first obtains its summary content through zy_model; according to the summary content, the zy_bq_model model in step S2 is used to find the label corresponding to the summary, and combined with the label in step S1, the legal scope is narrowed;
[0033] Input the summary content to the embedding_model model fine-tuned in step S3 to derive the most relevant penalty dependency clauses; check whether the derived clauses are within the label range of the law, if so, retain them; otherwise, discard them;
[0034] Through multi-model collaborative computing, the legal article recommendation task is broken down into four subtasks: model labeling, model summary extraction, model label matching, and model legal article recommendation. These subtasks are finally combined together to improve the legal article recommendation effect.
[0035] A legal article recommendation device includes: at least one memory and at least one processor;
[0036] The at least one memory is used to store a machine-readable program;
[0037] The at least one processor is used to call the machine-readable program to execute a legal provision recommendation method.
[0038] Compared with the prior art, the method and device for recommending legal provisions of the present invention have the following outstanding beneficial effects:
[0039] The present invention realizes a method for automatically searching and recommending the basis for punishment in legal cases by constructing and training models, thereby improving the efficiency and accuracy of legal case handling. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0041] Attached Figure 1 It is a flowchart of a method for recommending a legal provision;
[0042] Attached Figure 2 It is a schematic diagram of the model workflow in the legal provision recommendation method. DETAILED DESCRIPTION
[0043] In order to enable those skilled in the art to better understand the solution of the present invention, the present invention is further described in detail below in conjunction with specific implementation methods. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0044] A best embodiment is given below:
[0045] like Figure 1-2 As shown, a method for recommending legal provisions in this embodiment has the following steps:
[0046] S1. Clean the data;
[0047] Further including:
[0048] S1-1. Collect complete laws, divide the laws into chapters, sections, and articles using regular expressions, and append the current legal name to the beginning of each chapter, section, and article after division;
[0049] S1-2. Build a label model, manually annotate the correspondence between laws and labels, and use Lora to train a general large model to obtain a legal label model: bq_model;
[0050] S1-3. All collected laws are labeled according to bq_model. The labels are dynamic and changeable, including the number of labels and the label content.
[0051] For example:
[0052] Collect complete laws, divide them into chapters, sections, and articles, and add the current legal name to the beginning of each chapter and article data. Train the legal labeling model bq_model. Use bq_model to label complete laws according to their applicable scope. For example, the labels of the Labor Law are: labor rights, labor relations, labor protection, social insurance, labor order, etc. At the same time, as the system is applied, the labels will be dynamically adjusted, such as adding labor contracts and deleting social insurance.
[0053] S2, construct training data;
[0054] Further including:
[0055] 2-1. Due to the strong generalization ability of the model, it is only necessary to collect information on completed cases in a certain area. Each law corresponds to about 20 cases, and each case contains: case description information; case punishment based on legal provisions. The collected data is deduplicated and denoised using the SimHash algorithm to ensure that the case information in each document is complete and the punishment-dependent clauses are clear, complete, and correct.
[0056] 2-2. Build a case summary model by manually annotating case and case summary data. The summary includes: description of the illegal facts of the case. Remove variable and redundant data such as location, time, and people. Use Lora to train the general large model to obtain the case summary model: zy_model.
[0057] Construct the case summary model zy_model. Extract the summary of each case information, remove redundant description information, and finally keep the summary information within 15-20 words.
[0058] 2-3. Build a summary and label correspondence model. By manually annotating the summary and label correspondence data, use Lora to train the general large model to obtain the summary and label correspondence model: zy_bq_model.
[0059] 2-4. Combine the legal article data segmented in step S1 to construct the embedding_model model training data, the structure of which is as follows: {query: case summary information, positive: [relevant legal article 1, relevant legal article 2, relevant legal article 3], nagtive: [irrelevant legal article 1, irrelevant legal article 2, irrelevant legal article 3]}.
[0060] 2-5. Randomly select 15%-20% of the data from the training data set as the embedding_model model evaluation data. At the same time, build a summary and label correspondence model zy_bq_model to infer the corresponding law of the case based on the case summary and narrow the search scope.
[0061] S3, training and evaluating the embedding_model model;
[0062] Use the general large language model combined with the training data constructed in step S2 to perform efficient fine-tuning through the Lora method to obtain embedding_model. Input the case summary and any legal provision into the embedding_model to calculate the correlation value X between the two, and filter X using thresholds 0.3 and 0.4 to obtain the legal provision corresponding to the case summary.
[0063] Use the evaluation data constructed in step S2 to evaluate the model and obtain the model index. If the index is insufficient, enrich the types of data constructed in step S2 and retrain to ensure that the constructed data covers the types of cases. Through the generalization ability of the large model, find the penalty-dependent clauses of similar cases until the index meets the requirements.
[0064] Model evaluation formula. This scenario is applicable to recall evaluation. The total number of evaluation samples is: TP+FP+FN+TN;
[0065] TP: The legal provisions should be recommended and are actually recommended;
[0066] FP: The legal provision should not be recommended, but it is actually recommended;
[0067] TN: The law should not be recommended, and it was not actually recommended;
[0068] FN: The law should be recommended, but it was not recommended;
[0069] Recall = TP / (TP+FN).
[0070] S4, application model;
[0071] The user inputs a new case, and first obtains its summary content through zy_model; according to the summary content, the zy_bq_model model in step S2 searches for the label corresponding to the summary, and combines the label in step S1 to narrow the scope of the law; the summary content is input to the embedding_model model fine-tuned in step S3 to derive the most relevant penalty-dependent clauses; check whether the derived clauses are in the law within the label range, if so, retain them, otherwise discard them. Through multi-model collaborative computing, the legal article recommendation task is decomposed into four subtasks: model labeling, model abstract extraction, model label matching, and model legal article recommendation, and finally combined together to improve the legal article recommendation effect.
[0072] Based on the above method, a legal article recommendation device in this embodiment includes: at least one memory and at least one processor;
[0073] The at least one memory is used to store a machine-readable program;
[0074] The at least one processor is used to call the machine-readable program to execute a legal provision recommendation method.
[0075] The above-mentioned specific implementations are only specific cases of the present invention. The patent protection scope of the present invention includes but is not limited to the above-mentioned specific implementations. Any technical solutions that conform to the above-mentioned specific implementations of the present invention and any appropriate changes or substitutions made by ordinary technicians in the relevant technical field shall fall within the patent protection scope of the present invention.
[0076] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.
Claims
1. A method for recommending legal provisions, characterized in that: The steps are as follows: S1. Clean the data; S2, construct training data; S3, training and evaluating the embedding_model model; S4. Application model.
2. A method for recommending legal provisions according to claim 1, characterized in that: In step S1, further comprising: S1-1. Collect complete laws, divide the laws into chapters, sections, and articles using regular expressions, and append the current legal name to the beginning of each chapter, section, and article after division; S1-2. Build a label model, manually annotate the correspondence between laws and labels, and use Lora to train a general large model to obtain a legal label model: bq_model; S1-3. All collected laws are labeled according to bq_model. The labels are dynamic and changeable, including the number of labels and the label content.
3. A method for recommending legal provisions according to claim 2, characterized in that: In step S2, further comprising: S2-1, remove duplication and noise from the collected data using the SimHash algorithm; S2-2, build a case summary model; S2-3, construct a model corresponding to summaries and labels; S2-4, construct embedding_model model training data based on the legal data segmented in step S1; S2-5. Extract part of the constructed data as embedding_model model evaluation data.
4. A method for recommending legal provisions according to claim 3, characterized in that: In step S2-1, information on cases that have been completed in a certain region is collected, and each case includes case description information and case punishment based legal provisions; In step S2-2, the case and case summary data are manually annotated, and the summary includes: a description of the illegal facts of the case; variable and redundant data are removed, and the case summary model zy_model is obtained by training the general large model using Lora.
5. A method for recommending legal provisions according to claim 4, characterized in that: In step S2-3, by manually annotating the summary and label correspondence data, Lora is used to train the general large model to obtain the summary and label correspondence model: zy_bq_model; In step S2-4, the embedding_model model structure is as follows: {query: case summary information, positive: [relevant article 1, relevant article 2, relevant article 3], nagtive: [irrelevant article 1, irrelevant article 2, irrelevant article 3]}.
6. A method for recommending legal provisions according to claim 5, characterized in that: In step S3, the general large language model is used in combination with the training data constructed in step S2 to perform efficient fine-tuning through the Lora method to obtain the embedding_model through training. The case summary and any segmented legal provision are input into the embedding_model to obtain the dependency correlation value X between the two. A threshold is used to filter X, and the value range of X is 0 to 1. The smaller the threshold, the higher the correlation between the two. Finally, the legal provision corresponding to the case summary is obtained.
7. A method for recommending legal provisions according to claim 6, characterized in that: The embedding_model model includes a dense vector, a sparse vector, and a combination vector, a multi vector; When the embedding_model model inputs the training data constructed in step S2, each query will form a pair of (X, Y) data with each of the positive or nagtive items for the model to learn. The dense vector and sparse vector are constructed separately through the multi-head attention mechanism, and the multi vector is obtained by combining the dense vector and sparse vector through knowledge distillation.
8. A method for recommending legal provisions according to claim 7, characterized in that: Use the evaluation data constructed in step S2 to evaluate the embedding_model and obtain the model indicators. If the indicators are insufficient, enrich the data types constructed in step S2 and retrain to ensure that the constructed data covers all case types; through the generalization ability of the large model, find the penalty-dependent clauses for new cases.
9. A method for recommending legal provisions according to claim 8, characterized in that: In step S4, the user inputs a new case and first obtains its summary content through zy_model; according to the summary content, the zy_bq_model model in step S2 is used to find the label corresponding to the summary, and combined with the label in step S1, the legal scope is narrowed; Input the summary content to the embedding_model model fine-tuned in step S3 to derive the most relevant penalty dependency clauses; check whether the derived clauses are within the label range of the law, and if so, retain them; Otherwise, discard; Through multi-model collaborative computing, the legal article recommendation task is broken down into four subtasks: model labeling, model summary extraction, model label matching, and model legal article recommendation. These subtasks are finally combined together to improve the legal article recommendation effect.
10. A device for recommending legal provisions, characterized in that: include: at least one memory and at least one processor; The at least one memory is used to store a machine-readable program; The at least one processor is configured to call the machine-readable program to execute the method according to any one of claims 1 to 9.