A statute recommendation method based on multi-level matching and pre-training language model
By combining multi-level matching and pre-trained language models with BERT, BiLSTM, TF-IDF, and BERT-CRF, information fusion at the sentence, keyword, and four elements of crime levels is achieved, solving the problem of inaccurate legal provision recommendations and improving the accuracy and efficiency of judicial decisions.
Patent Information
- Application Number
- CN202410621333.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-20
- Publication Date
- 2026-11-20
- Estimated Expiration
- 2044-05-20
AI Technical Summary
Existing methods for recommending legal provisions are insufficient to fully utilize information at the sentence, keyword, and four elements of a crime level when processing legal documents. This results in inaccurate recommendations and affects the efficiency and precision of judicial decisions.
A legal provision recommendation method based on multi-level matching and pre-trained language models is adopted. Sentence-level information is extracted by BERT model and BiLSTM, legal provision keywords are extracted by TF-IDF, keyword information is fused by interactive attention mechanism, and the four elements of crime are extracted by BERT-CRF model to achieve multi-level matching and recommendation.
It improves the accuracy of legal provisions recommendations and the efficiency of judicial decisions, enabling more comprehensive use of information in legal documents and providing more precise legal provisions suggestions.
Smart Images

Figure CN118427306B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of natural language processing, and specifically relates to a method for recommending legal provisions based on multi-level matching and pre-trained language models. Background Technology
[0002] Natural Language Processing (NLP) technology accomplishes the task of building a bridge between humans and machines. These methods specifically include Chinese word segmentation, part-of-speech tagging, lexical semantics, and syntactic parsing, aiming to transform semi-structured human language into structured information that machines can process. The legal field, as a subfield of artificial intelligence applications, relies heavily on the fundamental role of NLP technology. Most legal documents, such as judgments, rulings, contracts, and opinions, are presented in text form. Furthermore, the legal field, due to its pursuit of rigorous expression, possesses a strict system of legal concepts, and many tasks require legal practitioners with specialized legal knowledge and a thorough understanding of various laws and regulations. Because legal knowledge and case databases are vast, retrieving relevant legal knowledge and documents takes considerable time, even for seasoned professionals. Currently, courts have accumulated a large number of judicial judgments through long-term judicial practice, characterized by clear structure, rich professional terminology, and rigorous logic. Based on the special structure of judicial documents, the important parts of judicial documents can be divided into four parts: facts, reasoning, judgment, and basis. The legal provisions recommendation focuses on the relationship between facts and basis, and studies how to provide specific provisions in a particular legal code to support the given facts.
[0003] Traditional legal provision recommendation tasks are treated as multi-label classification methods. Wang Haoran et al. selected legal provisions matching the target event through keyword-based legal provision retrieval and historical event retrieval matching. However, keyword-based matching discards other texts containing much information, thus ignoring some details. Ge Jidong et al. used LDA topic models to extract similar judgment documents to construct a candidate legal provision set, but this method often relies on the accuracy of LDA itself and is easily prone to pitfalls. Xiong Xi et al. transformed the multi-label legal provision classification problem into a binary classification problem of whether facts correspond to legal provisions, but did not accurately recommend legal provisions from multiple perspectives. Therefore, transforming the classification task into a matching task, and realizing a legal provision recommendation method that matches from multiple levels—integrating overall sentence information, keyword information, and criminal behavior chains—is highly necessary. Summary of the Invention
[0004] To address the problems described in the background section, the present invention aims to provide a legal provision recommendation method based on multi-level matching and pre-trained language models. This method can measure the relevance between facts and legal provisions from multiple levels and perspectives, including sentence level, keyword level, and the four elements of a crime level, thereby achieving accurate legal provision recommendation through multi-level matching and helping to improve the accuracy and efficiency of judicial judgment prediction.
[0005] The objective of this invention is achieved through the following technical solution:
[0006] This invention discloses a method for recommending legal provisions based on multi-level matching and a pre-trained language model, comprising the following steps:
[0007] S1: Obtain the database of judgment documents, perform structured processing on the judgment documents, separate the facts and the basis into two parts, perform data cleaning and Chinese word segmentation, remove stop words, and construct training set, validation set, and test set.
[0008] S1.1 Collect different types of judgment documents to form a case library. Judgment documents have a fixed structure and terminology. The fixed terminology includes phrases such as "accusation", "this court holds", and "the judgment is as follows". Based on the fixed terminology, the judgment documents are divided into the following parts: procedure, facts, reasoning, judgment, and basis. The facts and basis parts are retained.
[0009] S1.2, based on the legal provisions mentioned in the basis section, extract the specific content corresponding to the legal provisions from the legal code, and form a legal provision library for all the specific content corresponding to the legal provision names. Match the specific content of the legal provisions corresponding to the fact section with the legal provisions corresponding to the basis section one-to-one, forming a fact section-corresponding legal provision matching pair as a positive sample. Extract legal provisions from the legal provision library that are not present in the basis section and match them with the fact section, forming a fact section-non-corresponding legal provision matching pair as a negative sample.
[0010] S1.3, use the jieba library to segment the obtained facts and legal provisions, load the stop word library to remove stop words from the segmented results, and then save the results after removing stop words to obtain the preprocessed facts and evidence, and construct the training set, validation set, and test set.
[0011] S2 concatenates facts and legal provisions to obtain a fact-legal provision vector. The pre-trained model BERT encodes the fact-legal provision vector into a vector. BERT's powerful language learning ability is used to learn multi-dimensional semantic information in sentences. The last layer vector of the BERT model is extracted and further processed by BiLSTM to extract complete information of the sentence, thus strengthening the BERT model's learning of bidirectional semantic information.
[0012] S2.1, the facts and legal provisions are concatenated to obtain a fact-legal provision vector. The BERT model is then used to encode the fact-legal provision vector to obtain the joint representation T. o ={[CLS],F o1 ,F o2 ,……F om [SEP],L o1 ,L o2 ,……L on ,[SEP]]},F oi L represents the i-th word in the fact. oi This represents the j-th character in the data. Instead of directly using the [CLS] flag for classification, we choose to extract the output T of the last layer of the BERT model. BERT =BERT(T) o )
[0013] S2.2, the obtained output T BERT By further extracting contextual information through BiLSTM, the connection between facts and legal provisions is further established, enhancing the BERT model's ability to learn bidirectional semantic information, and thus obtaining T. BiLSTM =BERT(T) BERT This is output as a sentence level.
[0014] S3 utilizes the crime characteristics corresponding to the legal provisions and judicial interpretations to extract keywords for each legal provision using TF-IDF technology. The extracted keywords are then encoded into vectors using a BERT model. The text representations of the legal provisions' keywords, facts, and legal provisions are input into an interactive attention module. This module uses an interactive attention mechanism to integrate the legal provisions' keywords into the text vectors of the facts and legal provisions, ensuring that the facts and legal provisions focus on information related to the keywords. Max pooling is then used to retain the most critical features in both the fact vectors and the legal provision vectors incorporating the keywords.
[0015] S3.1, retrieve crime characteristics and judicial interpretations related to legal provisions from the Zhaofa website. Based on these characteristics and interpretations, use the TF-IDF algorithm to extract keywords for each legal provision. Establish a corpus Y based on the crime characteristics and judicial interpretations. Perform word segmentation on legal provisions L to obtain a word set W = {W1, W2, ... W...}. g}, where W i Let W be the i-th word, and g be the number of words. Assume there are A documents in total, for word W... i It appears in a total of B documents. Calculate the word frequency. Among them, times(W) i ) for W i The number of times it appears, calculate the inverse document frequency. Calculate the weight of the word by tf*idf, and then sort and filter the words with the highest importance (TOPK) as the keywords of the legal provision.
[0016] S3.2, the obtained keywords are modeled using the BERT model to obtain the text representation K = {K1, K2, ..., K}. p}, where p is the length of the keyword. The text representations of the keywords, facts, and legal provisions are input into the interactive attention module. The interactive attention mechanism integrates the keyword information into the facts and legal provisions. The similarity matrix S between the keywords and the facts and legal provisions is calculated respectively. KF and S KL The calculation formula is as follows:
[0017]
[0018]
[0019] in: It is a similarity matrix between keyword text representations and fact text representations. This is the similarity matrix between keyword text representations and legal provision text representations. Normalizing the similarity matrix yields:
[0020]
[0021]
[0022] in: It is the normalized attention weight of legal keywords in the factual text direction. This represents the normalized attention weights of legal provision keywords in the textual direction of the legal provision. The fact vector F, which incorporates the legal provision keyword vectors, is obtained by multiplying the similarity matrix and the keyword vectors. K And normal vector L K :
[0023]
[0024]
[0025] Wherein: F K It is K i The weighted sum model selects content related to the factual text from the legal keyword text to form the relative semantic F. K L K It is K i The weighted sum model selects content related to the factual text in the legal provision keyword text to form the relative semantic L. K .
[0026] S3.3, the obtained vector is processed through a max pooling layer to extract the most critical factual information F. Kmax =Maxpooling(F K ) and legal information L Kmax =Maxpooling(L K ), where Maxpooling is the maximum pooling function.
[0027] S4. Construct a labeled dataset of case descriptions from judicial documents, consisting of the factual text of the judicial documents and the corresponding four elements of a crime. Using the pre-trained language models BERT and CRF, a BERT-CRF model is trained on the dataset to automatically extract the four elements of a crime from the factual text. The four elements of a crime are extracted and matched from the factual portion, including the subject, object, subjective aspect, and objective aspect. This allows for the extraction of the more important four elements of a crime from the rules of judgment, providing more perspectives on the guidance of facts and legal provisions from a legal standpoint. The four elements of a crime are integrated into the text vectors of the facts and legal provisions, ensuring that the facts and legal provisions focus on the information related to the four elements of a crime. Max pooling is used to retain the most critical features in the factual vectors and legal provision vectors incorporating the four elements of a crime.
[0028] S4.1 Construct a labeled dataset of case descriptions from court judgments, consisting of the factual text of the judgments and the corresponding four elements of a crime. The factual text is encoded using a BERT model to obtain vectors with bidirectional semantic information. CRF technology is then used to label and predict the four elements of a crime from these factual text vectors. The predicted results are compared with the actual results in the labeled dataset to train a BERT-CRF model capable of extracting the four elements of a crime from the factual text. This achieves automated extraction of the four elements of a crime and leverages the powerful text representation capabilities of the pre-trained language to improve the accuracy of the extracted four elements of a crime.
[0029] S4.3, using the trained BERT-CRF model to extract the four elements of a crime from the factual part, concatenating the obtained four elements of a crime using the [SEP] symbol, and then encoding them using the BERT model to obtain the text representation of the four elements of a crime Z = {Z1, Z2, ... Z...} d}, where d is the length of the four elements of a crime. An interactive attention mechanism is used to integrate the information of the four elements of a crime into the facts and legal provisions. The similarity matrix S between the four elements of a crime and the facts and legal provisions is calculated respectively. ZF and S ZL The calculation formula is as follows:
[0030]
[0031]
[0032] The similarity matrix contains both positive and negative values. Negative values may affect subsequent gradient calculations in the model. The softmax function is used to normalize the similarity matrix to the range (0, 1), as shown in the following formula:
[0033]
[0034]
[0035] in: It is the normalized attention weight of the four elements of a crime in the direction of factual text. This is the normalized attention weight of the four elements of a crime in the direction of the legal text. The fact vector F, which incorporates the factual elements of the crime, is obtained by multiplying the similarity matrix and the vector of the four elements of the crime. Z And normal vector L Z :
[0036]
[0037]
[0038] Wherein: F Z It is Z i The weighted sum of the data is used by the model to select relevant content from the text of the four elements of a crime to form the relative semantic F. K L Z It is Z i The weighted sum model selects content related to the factual text from the four elements of a crime to form relative semantic L. K .
[0039] S4.4, the obtained vector is processed through a max pooling layer to extract the most critical factual information F. Zmax =Maxpooling(F Z ) and legal information L Zmax =Maxpooling(L z ), where Maxpooling is the maximum pooling function.
[0040] S5, the sentence-level, keyword-level, and crime-related four-element-level information obtained above are concatenated to obtain the fused information I = {T} BiLSTM ,F Kmax ,L Kmax ,F zmax ,L ZmaxThe system predicts the output through a fully connected layer to obtain the result of whether the fact matches the legal provision. It measures the correspondence between the fact and the legal provision from multiple levels and perspectives, including sentence level, keyword level, and the four elements of a crime level. This more comprehensively takes into account relevant information from the legal field, achieves accurate recommendation of legal provisions through multi-level matching, and helps improve the accuracy and efficiency of the legal provision recommendation task.
[0041] It also includes S6, which inputs the case fact text for which reference legal provisions need to be found into the multi-level matching model of facts and legal provisions. The multi-level matching model of facts and legal provisions will compare the case with the legal provisions in the legal code one by one, output the similarity score between the case and the legal provisions in the legal code, and return the 10 legal provisions with the highest similarity scores. This provides lawyers and judges with relevant legal provisions quickly, saving judicial staff time in searching various legal provision databases. Moreover, the method of using this model can make full use of the information of the four elements of crime in legal provisions and fact text, comprehensively considering the information at the sentence level of fact text, the keyword level of legal provisions, and the level of the four elements of crime in fact text, effectively assisting in improving the accuracy and efficiency of judicial decision-making.
[0042] Beneficial effects:
[0043] 1. This invention discloses a legal provision recommendation method based on multi-level matching and pre-trained language models. It comprehensively uses the vector output by the last layer of the BERT model and further extracts contextual information through BiLSTM, which enhances the model's learning of bidirectional semantic information and completes the aggregation of textual information at the sentence level, thereby supporting the improvement of the accuracy and efficiency of judicial decision-making.
[0044] 2. This invention discloses a legal provision recommendation method based on multi-level matching and a pre-trained language model. It utilizes the crime features corresponding to each legal provision and judicial interpretations, employing TF-IDF technology to extract keywords for each provision. The extracted keywords are then encoded into vectors using a BERT model. The text representations of the legal provision keywords, the facts, and the legal provisions are input into an interactive attention module. This interactive attention mechanism integrates the legal provision keywords into the text vectors of the facts and the legal provisions, ensuring that the facts and the legal provisions focus on information related to the keywords. Max pooling is used to retain the most critical features in the fact vectors and the legal provision vectors incorporating the keywords, achieving textual information fusion at the level of legal provision knowledge keywords. This effectively utilizes legal provision-related knowledge to support and improve the accuracy and efficiency of judicial decision-making.
[0045] 3. This invention discloses a legal provision recommendation method based on multi-level matching and a pre-trained language model. It utilizes BERT+CRF to extract the four elements of a crime, including the subject, object, subjective aspect, and objective aspect. These four elements are then integrated into the text vectors of facts and legal provisions, ensuring that the facts and legal provisions focus on information related to these four elements. Max pooling is employed to retain the most critical features in the fact vectors and legal provision vectors incorporating the four elements of the crime. This provides more perspectives and focuses on more information from a legal perspective, effectively improving the accuracy of the legal provision recommendation task. Attached Figure Description
[0046] Figure 1 A flowchart of a legal provision recommendation method based on multi-level matching and pre-trained language models.
[0047] Figure 2 This is a model structure diagram of a legal provision recommendation method based on multi-level matching and a pre-trained language model.
[0048] Figure 3 This is a flowchart for data acquisition and text preprocessing.
[0049] Figure 4 This is a diagram of the structure of a court judgment document. Detailed Implementation
[0050] The present invention will now be described in detail with reference to the accompanying drawings and embodiments, while also discussing the technical problems solved by the present invention and its beneficial effects. It should be noted that the described embodiments are intended to facilitate understanding of the present invention and do not constitute any limitation thereof.
[0051] Example
[0052] This embodiment describes a method for recommending legal provisions based on multi-level matching and a pre-trained language model. Figure 1 This is a schematic diagram of the overall process of the method. Figure 2 This is a schematic diagram of the multi-level matching legal provision recommendation model used in this embodiment.
[0053] Step 1: Obtain the dataset and perform text preprocessing operations, including web scraping, module segmentation, word segmentation, and stop word removal. Related operations are detailed in the attached document. Figure 3 As shown. The structure of a court judgment document is attached. Figure 4 As shown.
[0054] Step 2: Encode the factual part and the legal provision part using the BERT model, and then concatenate the output of BiLSTM.
[0055] Step 3: Extract keywords using TF-IDF by analyzing the crime characteristics and judicial interpretations corresponding to the legal provisions on the FindLaw website. Then, use the interactive attention mechanism to integrate the keyword information into the legal provisions and facts, and finally concatenate the max pooling layer.
[0056] Step 4: Extract the four elements of a crime from the factual part using a combination of BERT model and CRF technology, integrate the information of the four elements of a crime into the legal provisions and facts using an interactive attention mechanism, and then splice them together with a max pooling layer.
[0057] Step 5: After concatenating sentence-level information, keyword-level information, and crime element-level information, output the prediction result through a fully connected layer.
[0058] Step 1.1: Using Scrapy, a dataset of 268,585 criminal case judgments was obtained from the China Judgments Online website, covering multiple charges and legal provisions. These different types of judgments were integrated into a case library. Based on the fixed structure of the judgments, the text was divided using the split function of the string library in Python, using formats including phrases such as "ascertained after trial," "this court holds," and "in accordance with." The second paragraph was taken as the factual text, and the last paragraph as the legal provision text.
[0059] Step 1.2: Create an Excel document based on authoritative legal provisions from the national website. Each row in the document should contain the relevant article from a specific legal code. Extract each legal provision from the obtained basis through string segmentation, and map the legal provisions to the Excel document using string matching. Then, replace the basis section with the specific legal provision. Match the facts with the replaced legal provisions one by one to form fact-legal provision data pairs as positive samples. Then, randomly select unused legal provisions from the Excel document and match them one by one with the same number of other legal provisions as the positive samples to form negative samples, thus maintaining a 1:1 ratio of positive to negative samples. Use the jieba tool library to segment the obtained facts and legal provisions into words. Load the Harbin Institute of Technology stop word library and the Baidu stop word library to remove stop words from the facts and legal provisions. Finally, construct training, validation, and test sets and save them as JSON files.
[0060] Step 2.1 Read the dataset, concatenate the facts and evidence, and add [CLS], [SEP], and [SEP] markers at the beginning, the separation between facts and evidence, and the end, respectively. Encode the concatenated result using the BERT model. By leveraging the powerful language learning capabilities of the BERT model to model the combination, a joint text representation capable of reading higher-dimensional semantics using the BERT model can be obtained. o ={[CLS],F o1 ,F o2 ,……Fom [SEP],L o1 ,L o2 ,……L on ,[SEP]]},F oi L represents the i-th word in the fact. oi This represents the j-th character in the data. Instead of using the [CLS] flag for direct classification in traditional classification tasks, we choose to extract the output T from the last layer of the BERT model. BERT =BERT(T) o The sentence vector is used as a whole, and further learning is performed on the sentence vector.
[0061] Step 2.2 further extracts bidirectional text information from the obtained output using BiLSTM to obtain T. BiLSTM =BERT(T) BERT This is output as a sentence level.
[0062] Step 3.1 The online legal database contains information on the concepts, constituent characteristics, identification standards, and judicial interpretations of the crimes corresponding to each legal provision. Based on this information, the TF-IDF algorithm can be used to extract keywords for each legal provision. A corpus Y is built based on the concepts, constituent characteristics, identification standards, and judicial interpretations of all legal provisions and their corresponding crimes on the online legal database. Legal provisions L are then segmented to obtain a word set W = {W1, W2, ... W...}. g}, where W i Let W be the i-th word, and g be the number of words. Assume there are A documents in total, for word W... i It appeared in a total of B types of documents, and its word frequency was calculated to be... Among them, times(W) i ) for W i The number of times it appears, and then the inverse document frequency is calculated. The weight of a word is obtained by calculating tf*idf. Words are then sorted by weight, and the top K most important words are selected as keywords for that legal provision. Table 1 shows some of the extracted keywords for the legal provisions.
[0063] Table 1 contains keywords for some legal provisions.
[0064]
[0065] Step 3.2: Model the obtained keywords using the BERT model, extracting the vectors from the first layer (embedding layer) as the text representations of the keywords, K = {K1, K2, ..., K}. p}, where p is the length of the keyword. A variant of the attention mechanism, the interactive attention mechanism, guides the text output obtained in S2.1 to segment the text, resulting in the factual text F represented by the BERT model, using the text representation of the keywords. BERT ={F BERT1,F BERT2 ,……F BERTm} and legal text L BERT ={L BERT1 ,L BERT2 ,……L BERTm First, calculate the similarity matrix S between the keywords and the facts and legal provisions respectively. KF and S KL This is achieved through matrix multiplication, and the calculation formula is as follows:
[0066]
[0067]
[0068] Then, normalize the similarity matrix using the softmax function to obtain:
[0069]
[0070]
[0071] Then, by multiplying the similarity matrix and the keyword vector, we obtain the fact vector F that incorporates the keyword vector of the legal provisions. K And normal vector L K This is equivalent to reconstructing the vector of legal provisions or facts using keyword vectors and the weights of the keywords:
[0072]
[0073]
[0074] Step 3.4: Extract the most critical factual information F from the facts and legal provisions from the obtained vector using a max pooling layer. Kmax =Maxpooling(F K ) and legal information L Kmax =Maxpooling(L K ).
[0075] Step 4.1 Utilize a pre-trained model to identify and extract relevant words related to the four elements of a crime: subject, subjective aspect, object, and objective aspect. The dataset uses annotated data sets of case descriptions from court documents, including the extraction results of the four elements of a crime. The factual text is split into individual characters, and each character is tagged with its part of speech, i.e., labeled as a noun, verb, auxiliary word, etc. This is achieved using BERT+CRF, and the part of speech is a prerequisite for the four elements of a crime.
[0076] Step 4.2 Obtain the original fact text F from S2.1 o ={F o1 ,Fo2 ,......F om}are input into the pre-trained model, and the model will correspondingly output the property of the four elements of crime corresponding to each word in the fact text. The subject of crime refers to the person who commits the criminal act; the subjective aspect of crime refers to the psychological state of the subject of crime towards the committed criminal act and its consequences, including intent and negligence. The objective aspect of crime refers to the specific manifestation of the criminal act, such as robbery, fraud and the like. The object of crime is the object directly targeted by the criminal act, such as a person, an article and the like. The subject further describes the prediction process of the four elements of crime in combination with an example "Out of hunger, Zhao snatched Shen's noodles". The present patent adopts BERT+CRF to complete part-of-speech prediction, and the output of the model is the predicted part-of-speech corresponding to each character, that is, "Out O of O hun B-SUBA ger E-SUBA, O Zhao B-SUB某 E-SUB snat B-PRE ch I-PRE ed E-PRE Shen B-OBJA某 I-OBJA 's I-OBJA walle I-OBJA t E-OBJA". Due to the use of the "BIOES" system for word segmentation, wherein "B" indicates that the Chinese character is the starting character of a word or a single character; "I" indicates that the Chinese character is the middle character of a word; "E" indicates that the Chinese character is the ending character of a word; "O" indicates that the Chinese character is not in a word, and S indicates that the word itself is an entity. The following are the set labels, wherein "SUB" represents the subject; "SUBA" represents the subjective aspect; "OBJA" represents the object, and "PRE" represents the objective aspect. Finally, the part-of-speech prediction result "Out O of O hunger SUBA, O Zhao SUB snatched PRE Shen's noodles OBJA" is obtained.
[0077] Step 4.3 Encode the obtained four elements of crime through the BERT model, and take the vector of the first layer, that is, the embedding layer, as the text representation of the four elements of crime Z={Z1,Z2,......Z d}, where d is the length of the four elements of crime. The interactive attention mechanism is used to align the text representation of the four elements of crime with the text output obtained in S2.1 for segmentation to obtain the fact text F represented by the BERT model BERT ={F BERT1 ,F BERT2 ,......F BERTm} and the legal provision text L BERT ={L BERT1 ,L BERT2 ,......L BERTm}, firstly, the similarity matrix S between the four elements of crime and the fact as well as the legal provision is calculated respectively ZF and S ZL , which is realized by matrix multiplication, and the calculation formula is as follows:
[0078]
[0079]
[0080] Then, normalize the similarity matrix to obtain:
[0081]
[0082]
[0083] Then, by multiplying the similarity matrix and the vector of the four elements of crime, we obtain the fact vector F, which incorporates the vector of the four elements of crime. Z And normal vector L Z This is equivalent to reconstructing the vector of legal provisions or facts using the vector of the four elements of a crime and the weights of the legal provisions or facts on the keywords:
[0084]
[0085]
[0086] Step 4.4 extracts the most crucial factual information F from the obtained vector using a max pooling layer. Zmax =Maxpooling(F Z ) and legal information L Zmax =Maxpooling(L z ).
[0087] Step 5.1: By concatenating the text representations obtained above at the sentence level, keyword level, and crime four-element level using the concat function, the final fused information I = {T} containing multiple levels can be obtained. BiLSTM ,F Kmax ,L Kmax ,F zmax ,L Zmax Then, the output is predicted through a fully connected layer.
[0088] Matters not covered in this invention are common knowledge.
[0089] The above embodiments are only for illustrating the technical concept and features of the present invention, and are intended to enable those skilled in the art to understand the content of the present invention and implement it accordingly. They should not be construed as limiting the scope of protection of the present invention. All equivalent changes or modifications made in accordance with the spirit and essence of the present invention should be covered within the scope of protection of the present invention.
Claims
1. A method for recommending legal provisions based on multi-level matching and a pre-trained language model, characterized in that: Includes the following steps: S1. Obtain the database of judgment documents, perform structured processing on the judgment documents, separate the facts and the basis into two parts, and perform data cleaning, Chinese word segmentation, and removal of stop words to build training set, validation set and test set; S2: Concatenate facts and legal provisions to obtain a fact-legal provision vector. Use the pre-trained model BERT to encode the fact-legal provision vector into a vector. Utilize the powerful language learning ability of the BERT model to learn the multi-dimensional semantic information in the sentence. Extract the last layer vector of the BERT model and use BiLSTM to further extract the complete information of the sentence, thereby strengthening the BERT model's learning of bidirectional semantic information. S3 utilizes the crime characteristics corresponding to the legal provisions and judicial interpretations to extract keywords for each legal provision using TF-IDF technology. The extracted legal provisions keywords are then encoded into vectors using the BERT model. The text representations of the legal provisions keywords, the facts, and the legal provisions are input into the interactive attention module. The interactive attention mechanism is used to integrate the legal provisions keywords into the text vectors of the facts and the legal provisions, respectively, so that the facts and the legal provisions pay attention to the information related to the legal provisions keywords. Max pooling is used to retain the most critical features in the fact vector and the legal provision vector incorporating legal provision keywords; S4. Construct a labeled dataset of case descriptions in judgment documents, namely, the factual text of the judgment documents and the corresponding four elements of a crime; use the pre-trained language models BERT and CRF to learn and train a BERT-CRF model to automatically extract the four elements of a crime from the factual text; extract and match the four elements of a crime in the factual part, including the subject, object, subjective aspect, and objective aspect, which can extract the more important four elements of a crime in the judgment rules and provide more perspectives on the guidance of facts and legal provisions from a legal point of view; The four elements of a crime are incorporated into the text vectors of facts and legal provisions, so that the facts and legal provisions focus on information related to the four elements of a crime. Max pooling is used to retain the most critical features in the factual vector and the legal provision vector of the four elements of crime. S5 combines the information obtained at the sentence level, keyword level, and crime four elements level to obtain fused information, and performs prediction output through a fully connected layer to obtain the result of whether the fact matches the legal provision. This achieves the measurement of the correspondence between the fact and the legal provision from multiple levels and angles, including sentence level, keyword level, and crime four elements level, and takes into account relevant information from the legal field more comprehensively. This enables accurate recommendation of legal provisions through multi-level matching, and helps to improve the accuracy and efficiency of the legal provision recommendation task.
2. The method for recommending legal provisions based on multi-level matching and a pre-trained language model as described in claim 1, characterized in that: It also includes S6, which inputs the case fact text for which reference legal provisions need to be found into the multi-level fact-legal provision matching model. The multi-level fact-legal provision matching model will compare the case with the legal provisions in the legal code one by one, output the similarity score between the case and the legal provisions in the legal code, and return the 10 legal provisions with the highest similarity scores. This provides lawyers and judges with relevant legal provisions quickly, saving judicial staff time in searching various legal provision databases. Furthermore, the method of using this model can make full use of the information of the four elements of crime in the legal provisions knowledge and the fact text, comprehensively taking into account the information at the sentence level of the fact text, the keyword level of the legal provisions knowledge, and the level of the four elements of crime in the fact text, effectively assisting in improving the accuracy and efficiency of judicial decision-making.
3. A method for recommending legal provisions based on multi-level matching and a pre-trained language model as described in claim 1 or 2, characterized in that: The method for implementing step S1 is as follows: S1.1 Collect different types of judgment documents to form a case library. According to the fixed structure and terminology of judgment documents, the fixed terminology includes "accusation", "this court believes" and "the judgment is as follows". Based on the fixed terminology, the judgment documents are divided into the procedure part, the fact part, the reasoning part, the judgment part and the basis part by using the split function of the string library in Python. The fact part and the basis part are retained. S1.2, extract the specific content corresponding to the legal provisions mentioned in the basis section from the legal code, and form a legal provision library for all the specific content corresponding to the legal provisions; match the specific content of the legal provisions corresponding to the fact section with the legal provisions corresponding to the basis section one by one, that is, form a matching pair of fact section - corresponding legal provision as a positive sample; take out the legal provisions in the legal provision library that do not exist in the basis section and match them with the fact section to form a matching pair of fact section - non-corresponding legal provisions as a negative sample; S1.3, use the jieba library to segment the obtained facts and legal provisions, load the stop word library to remove stop words from the segmented results, and then save the results after removing stop words to obtain the preprocessed facts and evidence, and construct the training set, validation set, and test set.
4. The method for recommending legal provisions based on multi-level matching and a pre-trained language model as described in claim 3, characterized in that: The implementation method for step S2 is as follows: S2.1, the facts and legal provisions are concatenated to obtain a fact-legal provision vector. The BERT model is then used to encode the fact-legal provision vector to obtain the joint representation T. o ={[CLS],F o1 ,F o2 ,……F om [SEP],L o1 ,L o2 ,……L on ,[SEP]]},F oi L represents the i-th word in the fact. oi The j-th character represents the basis; instead of directly using the [CLS] flag for classification, the output T of the last layer of the BERT model is extracted. BERT =BERT(T) o ) S2.2, the resulting output T BERT By further extracting contextual information through BiLSTM, the connection between facts and legal provisions is further established, enhancing the BERT model's ability to learn bidirectional semantic information, and thus obtaining T. BiLSTM =BERT(T) BERT This is output as a sentence level.
5. The method for recommending legal provisions based on multi-level matching and a pre-trained language model as described in claim 4, characterized in that: The implementation method for step S3 is as follows: S3.1, retrieve crime characteristics and judicial interpretations related to legal provisions from the Zhaofa website, and extract keywords for each legal provision using the TF-IDF algorithm based on these characteristics and interpretations; construct a corpus Y based on the crime characteristics and interpretations, and perform word segmentation on legal provisions L to obtain a word set W = {W1, W2, ... W...} g }, where W i It is the i-th word, and g is the number of words; Suppose there are A documents in total, for word W i It appears in a total of B documents. Calculate the word frequency. Among them, times(W) i ) for W i The number of times it appears, calculate the inverse document frequency. Calculate the weight of the word by tf*idf, and then sort and filter the words with the highest importance (TOPK) as the keywords of the legal provision. S3.2, the obtained keywords are modeled using the BERT model to obtain the text representation K = {K1, K2, ..., K}. p }, where p is the length of the keyword; the text representations of the keyword, the facts, and the legal provisions are input into the interactive attention module, and the interactive attention mechanism is used to integrate the keyword information into the facts and legal provisions; the similarity matrix S between the keyword and the facts and legal provisions is calculated respectively. KF and S KL The calculation formula is as follows: in: It is a similarity matrix between keyword text representations and fact text representations. This is a similarity matrix between keyword text representations and legal provision text representations; normalizing the similarity matrix yields: in: It is the normalized attention weight of legal keywords in the factual text direction. It is the normalized attention weight of legal provision keywords in the direction of legal provision text; the fact vector F, which is incorporated into the legal provision keyword vector, is obtained by multiplying the similarity matrix and the keyword vector. K And normal vector L K : Wherein: F K It is K i The weighted sum model selects content related to the factual text from the keyword text of legal provisions to form the relative semantic F. K L K It is K i The weighted sum model selects content related to the factual text in the legal provision keyword text to form the relative semantic L. K ; S3.3, the obtained vector is processed through a max pooling layer to extract the most critical factual information F. Kmax =Maxpooling(F K ) and legal information L Kmax =Maxpooling(L K ), where Maxpooling is the maximum pooling function.
6. The method for recommending legal provisions based on multi-level matching and a pre-trained language model as described in claim 5, characterized in that: Step S is implemented as follows: S4.1 Construct a labeled dataset of case descriptions in judgment documents, namely, the factual text of the judgment documents and the corresponding four elements of the crime; encode the factual text using the BERT model to obtain vectors with bidirectional semantic information, and use CRF technology to label and predict the four elements of the crime on the factual text vectors; compare the prediction results with the real results in the labeled dataset, and train a BERT-CRF model that can extract the four elements of the crime from the factual text, realize the automatic extraction of the four elements of the crime, and use the powerful text representation capabilities of the pre-trained language to improve the accuracy of the extraction of the four elements of the crime; S4.3, using the trained BERT-CRF model to extract the four elements of a crime from the factual part, concatenating the obtained four elements of a crime using the [SEP] symbol, and then encoding them using the BERT model to obtain the text representation of the four elements of a crime Z = {Z1, Z2, ... Z...} d }, where d is the length of the four elements of a crime; the interactive attention mechanism is used to integrate information about the four elements of a crime into the facts and legal provisions; Calculate the similarity matrix S between the four elements of a crime and the facts and legal provisions respectively. ZF and S ZL The calculation formula is as follows: The similarity matrix contains both positive and negative values. Negative values may affect subsequent gradient calculations in the model. The softmax function is used to normalize the similarity matrix to the range (0, 1), as shown in the following formula: in: It is the normalized attention weight of the four elements of a crime in the direction of factual text. It is the normalized attention weight of the four elements of a crime in the direction of the legal text; the fact vector F, which incorporates the factual elements of the crime, is obtained by multiplying the similarity matrix and the vector of the four elements of the crime. Z And normal vector L Z : Wherein: F Z It is Z i The weighted sum of the data is used by the model to select relevant content from the text of the four elements of a crime to form the relative semantic F. K L Z It is Z i The weighted sum model selects content related to the factual text from the four elements of a crime to form relative semantic L. K ; S4.4, the obtained vector is processed through a max pooling layer to extract the most critical factual information F. Zmax =Maxpooling(F Z ) and legal information L Zmax =Maxpooling(L z ), where Maxpooling is the maximum pooling function.
Citation Information
Patent Citations
Legal provision recommendation processing method based on bert model and legal provision knowledge
CN111414454A
Bidirectional attention text keyword matching law article recommendation model and method
CN117271732A
