A bidirectional attention text keyword matching legal article recommendation model and method

Through the bidirectional attention text keyword matching legal article recommendation model, the semantic information and keyword information of the case facts and legal articles are integrated, and the problem of insufficient accuracy of legal article recommendation in the prior art is solved, and more efficient legal article recommendation and judgment support are achieved.

CN117271732BActive Publication Date: 2025-08-26CHINA UNIV OF MINING & TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311238076.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-09-25
Publication Date
2025-08-26
Estimated Expiration
2043-09-25

AI Technical Summary

Technical Problem

The existing legal recommendation technology ignores the semantic information of the legal article itself, making it difficult for judges to accurately match the facts of the case and the legal articles in the actual trial process, affecting the efficiency and accuracy of the judgment.

Method used

The bidirectional attention text keyword matching legal recommendation model is adopted, and the keyword extraction layer, BERT semantic representation layer, feature splicing layer and output layer are combined with the bidirectional attention mechanism and keyword attention transformer layer, and the semantic information and keyword information of case facts and legal provisions are integrated to convert the legal recommendation task into the text matching task.

Benefits of technology

The accuracy and interpretability of legal recommendations are improved, and the matching effect of legal provisions is improved by capturing character-level alignment features and key information differences characteristics, and the interpretability of the model is enhanced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117271732B_ABST
    Figure CN117271732B_ABST
Patent Text Reader

Abstract

The present invention relates to a two-way attention text keyword matching legal article recommendation model and method, and belongs to the field of artificial intelligence technology. First, a legal article matching data set is constructed, and then keywords are extracted for both case facts and legal articles. The case facts and legal articles are spliced ​​and input into the pre-trained model BERT for semantic representation. An additional keyword attention transformer layer is stacked in parallel with the last layer of transformer of BERT to obtain the key semantic representation of case facts and the key semantic representation of legal articles. Finally, the BERT matching pair features, alignment features, key semantic representations and key difference features are fused through a fully connected layer to perform linear transformation and use a softmax activation function to obtain the matching value of the case facts and the legal articles. The values ​​greater than the matching threshold are all legal articles involved in the case facts. The present invention integrates the keyword information of both case facts and legal articles, has good interpretability, and provides convenient help to legal professionals and non-professionals.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a two-way attention text keyword matching legal provision recommendation model and method, belonging to the field of artificial intelligence technology. Background Art

[0002] Legal Artificial Intelligence (LegalAI), which aims to leverage AI technology to handle various legal tasks, has become a growing research hotspot. Because legal documents are often presented in textual form, LegalAI extensively utilizes natural language processing (NLP) technology to enhance automation. This can, to a certain extent, reduce the workload of legal practitioners and improve the efficiency of legal affairs processing. It also lowers the barrier to entry for judicial applications and can provide legal assistance to non-professionals.

[0003] Typical applications of LegalAI include legal judgment prediction (LJP), similar case matching, and legal question-answering. The legal judgment prediction task primarily focuses on predicting judgment outcomes based on factual descriptions and legal provisions, with legal provision recommendation being a key subtask.

[0004] With the development of neural networks, researchers in recent years have increasingly leveraged text classification to solve the task of recommending legal provisions, treating the legal provisions involved in a case as classification labels. Since most cases involve more than one legal provision, this task has been transformed into a multi-label text classification task. Other researchers have also integrated legal expertise to assist in adjudication. For example, Luo et al. jointly modeled the task of charge prediction and related legal provision extraction; Zhong et al. used a topological structure to model the three subtasks of legal judgment prediction and mined the relationships between them; and Hu et al. integrated charge attributes to improve the prediction of low-frequency and easily confused charges. Existing research on legal provision recommendation has largely treated legal provisions as discrete labels, extracting only the textual features of the case facts as input to predict the corresponding legal provision labels, while ignoring the semantic information inherent in the legal provision. However, in actual trials, judges typically analyze the case facts based on the content of the legal provision and then determine the specific legal provision that matches the suspect's behavior. Therefore, the semantic information contained in the legal provision is a crucial basis for conviction and sentencing and needs to be fully utilized. Summary of the Invention

[0005] Purpose of the invention: To address the shortcomings of the existing technology, a bidirectional attention text keyword matching legal provision recommendation model and method is provided, which transforms the legal provision recommendation task into a text matching task. In addition to matching the case facts and the semantic information of the legal provisions themselves, the keyword semantic information of both is also taken into account, so that the legal provisions that match the case facts can be accurately obtained.

[0006] In order to achieve the above technical objectives, the present invention adopts the following technical solutions:

[0007] A bidirectional attention text keyword matching legal article recommendation model includes a keyword extraction layer, a BERT semantic representation layer, a feature splicing layer, a linear transformation layer, and an output layer. The BERT semantic representation layer is a traditional pre-trained BERT model with multiple transformer layers connected in sequence. A keyword attention transformer layer is added in parallel to the last transformer layer. The input of the keyword attention transformer layer is the output of the penultimate transformer layer of BERT. The keyword sequence extracted by the keyword extraction layer indicates the keyword position in the case facts and legal article sequence. The non-keyword positions are then masked using an attention mask to prevent the information in the non-keyword positions from being noticed. The outputs of the traditional last transformer layer and the keyword attention transformer layer are both connected to the feature splicing layer, which is sequentially connected to the fully connected layer and the output layer. The output of the original transformer in the last layer of BERT is the matching pair feature CLS vector, the case fact semantic representation matrix, and the legal article semantic representation matrix. The keyword attention transformer layer outputs the key semantic representation of the case facts and the key semantic representation of the legal article.

[0008] A two-way attention text keyword matching law article recommendation method of a two-way attention text keyword matching law article recommendation model includes the following steps:

[0009] S1. Construct a legal article matching dataset, combining each case fact and each legal article in the legal article database into a binary tuple, with labels as either match or mismatch.

[0010] S2. Use the keyword extraction layer to extract keywords from the case facts and the legal provisions related to the case field to obtain a text sequence of case fact keywords and a text sequence of legal provisions keywords;

[0011] S3: Concatenate the case fact text sequence and the legal text sequence, and input the concatenation result into the BERT semantic representation layer for semantic representation;

[0012] S4, the BERT semantic representation layer uses the original last layer of transformer based on the bidirectional attention mechanism to align the semantic representation of the case facts with the semantic representation of the legal provisions, thereby obtaining the legal provisions alignment feature that integrates the case facts;

[0013] S4. Based on the case fact keyword text sequence and the legal provision keyword text sequence, the semantic representation of the traditional transformer layer of the BERT semantic representation layer is finally output using a bidirectional attention mechanism to obtain alignment features. The keyword attention transformer layer outputs the key semantic representation of the case fact and the key semantic representation of the legal provision, and the semantic dissimilarity feature is obtained by subtracting the key semantic representation of the case fact from the key semantic representation of the legal provision.

[0014] S5. The CLS vector, legal provision alignment features, key semantic representations of case facts, key semantic representations of legal provisions, and key difference features are concatenated through the feature concatenation layer, and the matching value is obtained through linear transformation and softmax activation function processing in the fully connected layer. An activation function is added after the fully connected layer for subsequent downstream task classification. Legal provisions with a matching threshold greater than 0.5 are considered to be legal provisions involved in the facts.

[0015] Furthermore, the KeyBERT algorithm is used to extract keywords from the case facts and legal provisions, and the keyword sequence of the case facts {Kf1, Kf2…} and the keyword sequence of the legal provisions {Kl1, Kl2…} are obtained.

[0016] Furthermore, following the original BERT semantic similarity method, the character [SEP] is used to connect the case facts {f1,f2…f p} and legal provisions {l1,l2…l q Two paragraphs of text, where p represents the number of characters in the fact and q represents the number of characters in the legal provision. The symbols [CLS] and [SEP] are inserted at the beginning and end respectively. The format of the concatenated text is "[CLS] fact sequence [SEP] legal provision sequence [SEP]". The concatenated text is then input into the pre-trained BERT model to obtain semantic representation:

[0017] (e(CLS),e F ,e L )=BERT(fact,law)

[0018] where e(CLS)∈R d As a matching feature, d is the BERT hidden layer dimension, e F ∈R p×d is the semantic representation of the fact description, e L ∈R q×dis the semantic representation of the legal provision, where p and q represent the number of characters of the fact and the legal provision respectively.

[0019] Furthermore, step S3 specifically includes the following steps:

[0020] Step 3-1: First, use the semantic representation of case facts and legal provisions to perform attention calculation using the following formula:

[0021]

[0022] where M∈R p×q The result is obtained by multiplying the semantic representation matrices of the facts and legal provisions, M i,j Represents the correlation between the characters at position i of the case fact and position j of the legal provision. The larger the value, the more correlation there is.

[0023] Step 3-2: Since the attention matrix M i,j The values ​​are positive and negative. Use the softmax function to normalize the matrix values ​​between 0 and 1:

[0024]

[0025]

[0026] Among them, α represents the attention weight of the legal provisions, and β represents the attention weight of the case facts.

[0027] Step 3-3: Sum and compress the attention weight matrix of β in the direction of the law to obtain the total weight vector δ∈R in the direction of the case facts p :

[0028]

[0029] Then δ is fused with the legal direction attention weight α to obtain the comprehensive weight vector χ∈R q :

[0030] χ i =δ·α i ,i∈[1,...,q]

[0031] Reuse χ Align the semantic representation of the legal clauses to obtain the character-level alignment feature e FL ∈R q×d :

[0032] e FL =χ*e L

[0033] Step 3-4: Use the following formula to align features eFL Use the maximum pooling strategy to retain important features u∈R d:

[0034] u=max_pool(e FL )

[0035] Furthermore, based on the keyword sequences of both case facts and legal provisions, an additional keyword attention transformer layer is stacked in parallel with the last transformer layer of BERT.

[0036] The transformer self-attention calculation formula is:

[0037]

[0038] Where mask represents the attention mask matrix of the transformer layer. When calculating the self-attention score, when mask ij =1 means that the character at position i in the text sequence can pay attention to the character information at position j, mask ij =0 means that the character at position i cannot pay attention to the character information at position j.

[0039] The keyword attention transformer layer has the same architecture as the regular transformer, but the attention mask matrix as the transformer part is different. By changing the attention mask matrix, the model can make character information at certain positions visible or invisible when understanding the semantics of the entire sentence.

[0040] When calculating the key semantic representation of case facts, only the case facts themselves and the keyword information of legal provisions are considered. When calculating the key semantic information of legal provisions, only the legal provisions themselves and the keyword information of case facts are considered. The output of the penultimate transformer layer of BERT is input into the keyword attention transformer layer to obtain the key semantic representation of case facts and the key semantic representation of legal provisions, and the average pooling strategy is used to obtain the key semantic vector F of case facts. kw ∈R d and the key semantic vector L of the legal text kw ∈R d , subtract the two to get the key difference feature vector diff_kw∈R d .

[0041] Beneficial Effects: This paper converts the legal article recommendation task into the calculation of the semantic matching degree between criminal facts and legal articles, and proposes a two-way attention text matching method that integrates keywords. Through the two-way text keyword attention mechanism, character-level alignment features and key information difference features are captured, and multiple matching features are integrated at the output end, which improves the legal article matching effect. In addition, due to the two-way integration of the respective keywords of the legal article text and the case facts, which serve as an important basis for the recommendation results, the legal article recommendation method in this paper has good interpretability. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 This is a schematic diagram of the law recommendation model for bidirectional attention text keyword matching in the present invention;

[0043] Figure 2 Schematic diagram of the keyword attention mask matrix in an embodiment of the present invention. DETAILED DESCRIPTION

[0044] The embodiments of the present invention are further described below with reference to the amplitude:

[0045] like Figure 1 As shown, the present invention provides a two-way attention text keyword matching law recommendation model, which transforms the law recommendation task into a text matching task. It includes a keyword extraction layer, a BERT semantic representation layer, a feature splicing layer, a linear transformation layer and an output layer; the BERT semantic representation layer is a traditional pre-trained model BERT, which has multiple transformer layers connected in sequence. A keyword attention transformer layer is added side by side to the last transformer layer. The input of the keyword attention transformer layer is the output of the penultimate transformer layer of BERT. The keyword sequence extracted by the keyword extraction layer indicates the keyword position in the case facts and legal article sequence, and then the non-keyword positions are masked by the attention mask so that the information of the non-keyword positions cannot be noticed. The outputs of the traditional last transformer layer and the keyword attention transformer layer are both connected to the feature splicing layer, and the feature splicing layer is sequentially connected to the fully connected layer and the output layer; the original transformer output of the last layer of BERT is the matching pair feature CLS vector, the case fact semantic representation matrix and the legal article semantic representation matrix, and the keyword attention transformer layer outputs the key semantic representation of the case facts and the key semantic representation of the legal article.

[0046] A method for recommending legal provisions by using two-way attention text keyword matching includes the following steps:

[0047] Step 1: Obtain the legal article matching dataset, which comes from the criminal judgment documents published on the China Judgments Online website;

[0048] This paper selects two common cases, traffic accidents and intentional injury cases, as research objects, and downloads about 600 documents for each type of case;

[0049] Pre-process the downloaded documents to extract criminal facts and legal provisions and establish corresponding relationships;

[0050] Then, the two types of case data sets are divided into training set, validation set and test set according to 8:1:1. The distribution of the data sets is shown in Table 1;

[0051] Table 1 Dataset distribution information

[0052]

[0053] Step 2: The keyword extraction layer extracts keywords from the case facts and legal provisions related to the case field to obtain keyword sequences for both the case facts and legal provisions;

[0054] Step 3: Concatenate the text sequences of case facts and legal provisions, and then input the concatenated results into the BERT semantic representation layer for semantic representation;

[0055] Step 4: The original transformer output of the last layer of BERT matches the feature CLS vector, the case fact semantic representation matrix, and the legal provision semantic representation matrix. Based on the bidirectional attention mechanism, the case fact semantic representation is used to align the legal provision semantic representation to obtain the legal provision alignment feature that integrates the case facts.

[0056] Step 5: Based on the keyword sequences of both the case facts and the legal text, an additional keyword attention transformer layer is stacked in parallel with the last transformer layer of BERT to obtain the key semantic representations of the case facts and the legal text. The input of the keyword attention transformer layer is the output of the penultimate transformer layer of BERT. The keyword attention transformer layer is used to obtain the key semantic representations of the case facts and the legal text. The key semantic representations of the case facts and the legal text are subtracted from each other to obtain the key difference features.

[0057] Step 6: Concatenate the output CLS vector of the original transformer in the last layer of BERT, the legal article alignment feature, the key semantic representation of the case facts, the key semantic representation of the legal article, and the key difference feature to obtain the fusion feature. Perform a linear transformation through the fully connected layer and then pass it through the softmax activation function to obtain the matching value. The value greater than the matching threshold of 0.5 is the legal article involved in the fact.

[0058] Furthermore, step 2 uses the KeyBERT algorithm to extract keywords from the case facts and legal provisions, and obtains the keyword sequences {Kf1, Kf2…} and {Kl1, Kl2…} for both.

[0059] Furthermore, step 3 uses the character [SEP] to connect the case facts {f1,f2…f p} and legal provisions {l1,l2…l q}Two paragraphs of text, where p represents the number of characters of the fact and q represents the number of characters of the legal provision. The symbols [CLS] and [SEP] are inserted at the beginning and end respectively. Then the concatenated text is input into the pre-trained model BERT to obtain semantic representation:

[0060] (e(CLS),e F ,e L )=BERT(fact,law)

[0061] where e(CLS)∈R d As a matching feature, d is the BERT hidden layer dimension, e F ∈R p×d is the semantic representation of the fact description, e L ∈R q×d is the semantic representation of the legal provision, where p represents the number of fact characters and q represents the number of legal provision characters.

[0062] Step 4 includes:

[0063] Step 4-1: First, use the semantic representation of case facts and legal provisions to perform attention calculation:

[0064]

[0065] where M∈R p×q The result is obtained by multiplying the two semantic representation matrices, M i,j Represents the correlation between the characters at position i of the case fact and position j of the legal provision. The larger the value, the greater the correlation.

[0066] Step 4-2: Use the softmax function to normalize the attention matrix M i,j The value is between 0-1:

[0067]

[0068]

[0069] Among them, α is the attention weight in the direction of legal provisions, and β is the attention weight in the direction of case facts.

[0070] Step 4-3: Sum and compress the attention weight matrix of β in the direction of the law to obtain the total weight vector δ∈R in the direction of the case facts p :

[0071]

[0072] Then δ is fused with the legal direction attention weight α to obtain the comprehensive weight vector χ∈R q :

[0073] χ i =δ·α i ,i∈[1,...,q]

[0074] Reuse χ Align the semantic representation of the legal clauses to obtain the character-level alignment feature e FL ∈R q×d :

[0075] e FL =χ*e L

[0076] Step 4-4: Align Features eFL Use the maximum pooling strategy to retain important features u∈R d :

[0077] u=max_pool(e FL )

[0078] Furthermore, in step 5, based on the keyword sequences of both case facts and legal provisions, an additional keyword attention transformer is stacked in parallel with the last layer of BERT transformer. The transformer self-attention calculation formula is:

[0079]

[0080] Where mask represents the attention mask matrix of the transformer layer. When calculating the self-attention score, when mask ij =1 means that the character at position i in the text sequence can pay attention to the character information at position j, mask ij =0 means that the character at position i cannot pay attention to the character information at position j.

[0081] The keyword attention transformer layer has the same structure as the regular transformer, except for the attention mask matrix. Based on the keyword sequence extracted by the keyword extraction layer, the attention mask matrix is ​​changed. The keyword attention mask matrix is ​​as follows: Figure 2As shown, assuming that the case facts have 4 characters, namely f1, Kf2, Kf3 and f4, of which Kf2 and Kf3 are keyword characters, and the legal provisions have 3 characters, namely f1, Kl2 and Kl3, Kl2 and Kl3 are keyword characters. The attention mask of the keyword attention transformer layer is changed based on the case fact keyword text sequence and the legal provision keyword text sequence. The position of 1 in the attention mask matrix represents visible information, and the position of 0 represents invisible information. When calculating the key semantic representation of the case facts, only the case facts themselves and the legal provision keyword information are paid attention to. When calculating the key semantic representation of the legal provision, only the legal provision itself and the case fact keyword information are paid attention to. The output of the penultimate transformer layer of BERT is input into the keyword attention transformer layer to obtain the case facts and legal provision key semantic representations and the average pooling strategy is used to obtain the case facts key semantic vector F kw ∈R d and the key semantic vector L of the legal text kw ∈R d , subtract the two to get the key difference feature vector diff_kw∈R d .

[0082] Furthermore, step 6 combines all features to obtain H∈R 5d :

[0083] H=CAT(e(CLS),u,F kw ,L kw ,diff_kw)

[0084] The fusion feature H is linearly transformed through the fully connected layer and the matching value is obtained through the softmax activation function. The value greater than the matching threshold of 0.5 is the legal provision involved in the fact.

[0085] To illustrate the effectiveness of the present invention, this method was compared with two mainstream models: text classification and text matching. The experimental results are shown in Tables 2 and 3:

[0086] Table 2 Comparison of experimental results between this method and the comparative model

[0087]

[0088] Table 3 Ablation experiment results of this method

[0089]

[0090] Experimental results show that this method achieves the best results compared to the comparison model in terms of precision (P), recall (R), and comprehensive evaluation index (F1). On the traffic accident dataset, the F1 evaluation index improved by 3.74% compared to the second-best performing XS-BERT model, and on the intentional injury dataset, the F1 evaluation index improved by 3.43%. The addition of bidirectional attention and keyword attention modules has a positive impact on this method. This method has a stronger ability to identify differences between case facts and key information in legal provisions. The bidirectional attention mechanism obtains deeper interactive features between matching pairs. The injection of keyword information enables the model to filter out interference information and focus more on the key semantic information in the matching pairs, thereby improving the effectiveness of legal provision matching.

[0091] Since the two-way integration of keywords from legal texts and case facts serves as an important basis for recommendation results, the legal article recommendation method in this paper has good interpretability. Specific examples are shown in Table 4:

[0092] Table 4 Analysis of examples of legal article recommendation based on two-way attention text keyword matching

[0093]

[0094] The case facts in Table 4 involve two legal provisions, namely Article 72 and Article 234 of the Criminal Law. The victim's "degree of injury" is "minor injury", which meets the "intentional injury" behavior in Article 234 of the Criminal Law and the "less serious circumstances" in Article 72 of the Criminal Law. The keywords of both the case facts and the legal provisions can help users focus on key information more quickly and clearly explain why this fact involves the legal provision.

Claims

1. A law recommendation method based on a two-way attention text keyword matching law recommendation model, characterized in that: The steps include: S1. Construct a legal article matching dataset, concatenate each case fact and each legal article in the legal article database into a binary tuple, and label it as either a match or a mismatch. S2. Use the keyword extraction layer to extract keywords from the case facts and the legal provisions related to the case field to obtain a text sequence of case fact keywords and a text sequence of legal provisions keywords; S3: Concatenate the case fact text sequence and the legal provision text sequence, and input the concatenated result into the BERT semantic representation layer for semantic representation; S4, the BERT semantic representation layer uses the original last transformer layer based on the bidirectional attention mechanism to align the semantic representation of the case facts with the semantic representation of the legal provisions, thereby obtaining the legal provision alignment feature that integrates the case facts. S5. Based on the case fact keyword text sequence and the legal provision keyword text sequence, the keyword attention transformer layer outputs the case fact key semantic representation and the legal provision key semantic representation, and subtracts the case fact key semantic representation from the legal provision key semantic representation to obtain the key difference feature; S6. The CLS vector, legal article alignment features, case fact key semantic representation, legal article key semantic representation, and key difference features are concatenated through the feature concatenation layer, and the matching value is obtained through linear transformation and softmax activation function processing in the fully connected layer. An activation function is added after the fully connected layer for subsequent downstream task classification. Legal provisions with a matching threshold greater than 0.5 are considered to be relevant to the facts. The bidirectional attention text keyword matching legal article recommendation model includes a keyword extraction layer, a BERT semantic representation layer, a feature splicing layer, a fully connected layer and an output layer; the BERT semantic representation layer is a pre-trained model BERT, which has multiple transformer layers connected in sequence. A keyword attention transformer layer is added side by side to the last transformer layer. The input of the keyword attention transformer layer is the output of the penultimate transformer layer of BERT. The keyword sequence extracted by the keyword extraction layer is used to indicate the keyword position in the case facts and legal article sequence, and then the non-keyword positions are masked by the attention mask so that the information of the non-keyword positions cannot be noticed. The outputs of the last transformer layer and the keyword attention transformer layer are both connected to the feature splicing layer, and the feature splicing layer is sequentially connected to the fully connected layer and the output layer; the last transformer layer of BERT outputs a CLS vector, a semantic representation of case facts and a semantic representation of legal article, and the keyword attention transformer layer outputs a key semantic representation of case facts and a key semantic representation of legal article.

2. The method for recommending legal provisions by using two-way attention text keyword matching according to claim 1, characterized in that: Keyword extraction of case facts and legal provisions is performed using the KeyBERT algorithm to obtain the case fact keyword sequence {Kf1, Kf2…} and the legal provision keyword sequence {Kl1, Kl2…}.

3. The method for recommending legal provisions by using two-way attention text keyword matching according to claim 1, characterized in that: Use the character [SEP] to connect the case facts {f1,f2…f p } and the law {l1,l2…l q }Two paragraphs of text, where p represents the number of fact characters and q represents the number of legal characters. The symbols [CLS] and [SEP] are inserted at the beginning and end respectively. The format of the concatenated text is "[CLS] fact sequence [SEP] legal sequence [SEP]". The concatenated text is then input into the pre-trained BERT model to obtain semantic representation: (e(CLS),e F ,e L )=BERT(fact,law) where e(CLS)∈R d As a matching feature, d is the BERT hidden layer dimension, e F ∈R p×d is the semantic representation of the fact description, e L ∈R q×d is the semantic representation of the legal provision, where p and q represent the number of characters of the fact and the legal provision respectively.

4. The method for recommending legal provisions by using two-way attention text keyword matching according to claim 3, characterized in that: Step S3 specifically includes the following steps: Step 3-1: First, use the following formula to calculate attention using the semantic representation of case facts and legal provisions: Among them, M i,j ∈R p×q The semantic representation matrix M is obtained by multiplying the case facts and the legal provisions. i,j Represents the correlation between the characters at position i of the case fact and position j of the legal provision. The larger the value, the more correlation there is. Step 3-2: Since the attention matrix M i,j The values ​​are positive and negative. Use the softmax function to normalize the matrix values ​​between 0 and 1: Among them, α represents the attention weight of the legal provisions, and β represents the attention weight of the case facts. Step 3-3: Sum β in the direction of the law, compress the attention weight matrix, and obtain the total weight vector δ∈R in the direction of the case facts p : Then δ and the law direction attention weight α i The comprehensive weight vector χ∈R of the legal direction is obtained by fusion q : x i =d·a i ,i∈[1,...,q] Then use χ to align the semantic representation of the law to obtain the character-level alignment feature e FL ∈R q×d : And FL =χ*e L ,χ∈R q ,And L ∈R d Step 3-4: Use the following formula to align feature e FL Use the maximum pooling strategy to retain important features u∈R d : u=max_pool(e FL )。 5. The method for recommending legal provisions by using two-way attention text keyword matching according to claim 4, characterized in that: Based on the keyword sequences of both case facts and legal provisions, an additional keyword attention transformer layer is stacked in parallel with the last transformer layer of BERT. The transformer self-attention calculation formula is: Where mask represents the attention mask matrix of the transformer layer. When calculating the self-attention score, when mask i,j =1 means that the character at position i in the text sequence can pay attention to the character information at position j, mask i,j =0 means that the character at position i cannot pay attention to the character information at position j; When calculating the key semantic representation of case facts, only the case facts themselves and the key word information of the legal provisions are considered. When calculating the key semantic information of the legal provisions, only the legal provisions themselves and the key word information of the case facts are considered. The output of the penultimate transformer layer of BERT is input into the keyword attention transformer layer to obtain the key semantic representation of case facts and the key semantic representation of legal provisions, and the average pooling strategy is used to obtain the key semantic vector F of case facts. kw ∈R d and the key semantic vector L of the legal article kw ∈R d , subtract the two to get the key difference feature vector diff_kw∈R d .

Citation Information

Patent Citations

  • Text abstract generation method based on keyword information and multi-head attention mechanism

    CN116010590A

  • Generating conversation topics using neural networks

    US20230281235A1