A legal case retrieval method based on multi-task deep learning
Through multi-task deep learning methods, combined with cross-attention, bidirectional attention and loss function to optimize legal case retrieval, the interpretability and accuracy problems of existing methods are solved, and more efficient and accurate legal case retrieval is achieved.
Patent Information
- Application Number
- CN202510872920.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-27
- Publication Date
- 2025-09-12
- Estimated Expiration
- 2045-06-27
AI Technical Summary
Existing legal case retrieval methods have poor interpretability, are time-consuming and labor-intensive, and the retrieval results are not very accurate.
A multi-task deep learning-based method is adopted to fuse text and event information through a cross-attention mechanism, capture word-level interaction information using a bidirectional attention layer, aggregate word-level features through a convolutional neural network, and optimize retrieval results by combining Triple Loss and InfoNCE loss functions.
It improves the interpretability and efficiency of legal case retrieval, and enhances the accuracy of retrieval results and the interpretability of the model.
Smart Images

Figure CN120429429B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of legal case retrieval, and in particular to a legal case retrieval method based on multi-task deep learning. Background Art
[0002] Traditional judicial case retrieval relies primarily on two approaches: norm-driven retrieval, which searches legal provisions and related crimes; and keyword-driven retrieval, which requires users to translate case facts into professional legal and regulatory terms. Both models have significant limitations: the former is constrained by the abstract nature of the legal normative system, while the latter is limited by the precise translation requirements of legal terminology. The process requires multiple manual steps, such as deconstructing factual elements and constructing keyword systems, leading to a loss of judicial efficiency and the shifting of litigation costs. In recent years, the rapid development of artificial intelligence technology has provided new solutions for similar legal case retrieval. Neural networks, particularly deep learning models and natural language processing technologies, with their powerful feature extraction and semantic understanding capabilities, can better handle complex and lengthy legal case texts, and are gradually becoming a key tool for legal text analysis. Neural network technology can automatically extract key information such as case facts, applicable law, and controversial issues from massive legal texts, and calculate similarities between cases, significantly improving retrieval efficiency and accuracy. Despite this, deep learning-based similar case retrieval still faces numerous challenges. For example, the specialized nature and complexity of legal texts necessitate extensive amounts of labeled data for model training, a fact often scarce and costly in the legal field. Furthermore, neural networks suffer from poor interpretability, making it difficult to meet the transparency and credibility requirements of judicial practice. Exploring more efficient and interpretable deep learning models has become a key research priority. Therefore, a multi-task deep learning-based legal similar case retrieval method is urgently needed to address the technical challenges of existing retrieval methods, including their poor interpretability, time-consuming and labor-intensive nature, and limited accuracy of search results. Summary of the Invention
[0003] The main purpose of this invention is to propose a legal case retrieval method based on multi-task deep learning, aiming to solve the technical problems of existing retrieval methods such as poor interpretability, time-consuming and labor-intensive, and low accuracy of retrieval results.
[0004] To achieve the above objectives, the present invention provides a method for retrieving similar legal cases based on multi-task deep learning, wherein the method comprises the following steps:
[0005] S1. Data acquisition: constructing a legal case retrieval dataset, extracting the factual descriptions of legal documents in the dataset as text information, and the events described in the factual descriptions as event information;
[0006] S2, information fusion, encodes text information and event information separately to obtain text sequence and event sequence, uses the cross-attention mechanism to take the event sequence as the query and the text sequence as the key and value, calculates the attention score, and fuses the event information and text information to output the fusion feature;
[0007] S3. Similar case retrieval: Based on the fusion features, the word-level interaction information of the query case and the candidate case is captured based on the bidirectional attention layer, and the bidirectional attention of the query case and the candidate case is calculated respectively; the convolutional neural network is used to aggregate the word-level features and generate the final feature representation.
[0008] In one preferred solution, step S2 is specifically as follows:
[0009] A pre-trained language model is used as the basic encoder to encode text information and event information to obtain text sequences and event sequences, and the token representations of the text sequences and event sequences are calculated respectively;
[0010] The text sequence is:
[0011]
[0012] in, is a text sequence, The process of encoding text information using a pre-trained language model. It is uncoded text information;
[0013] The sequence of events is:
[0014]
[0015] in, is a sequence of events, It is the event information that is not encoded;
[0016] Through cross attention, the event sequence is used as the query Q, the text sequence is used as the key K and the value V, and the attention score between the query Q and the key K is calculated;
[0017] The attention score between the query Q and the key K, that is, the attention weight of the query Q and the key K, is applied to the value V to obtain the fusion feature after the event information and the text information are fused.
[0018] In one preferred solution, the attention score between the query Q and the key K is:
[0019]
[0020] in, is the attention score between query Q and key K calculated using cross attention, is the dimension of key K.
[0021] In one preferred solution, step S3 captures word-level interaction information between the query case and the candidate case based on the fusion feature and the bidirectional attention layer, and calculates the bidirectional attention of the query case and the candidate case respectively, specifically:
[0022] S31. Calculate the scaled dot product of the query case and the candidate case based on the fused features;
[0023] S32. Normalize the scaled dot product to obtain a first attention score and a second attention score, and obtain semantic information of the query case and the candidate case based on the first attention score and the second attention score;
[0024] S33. Based on the fusion features and semantic information of the original input, the output of the bidirectional attention layer is obtained.
[0025] In one preferred solution, the scaled dot product of the query case and the candidate case is:
[0026]
[0027] in, is the scaled dot product of the query case and the candidate case, To query the features of position i in the case sequence, is the feature of position j in the positive instance sequence of the candidate case.
[0028] In one preferred solution, the first attention score is:
[0029]
[0030] in, is the first attention score, is the length of the sequence, for, is the first scaled dot product from the query case to the candidate case;
[0031] The second attention score is:
[0032]
[0033] in, is the second attention score, is the first scaled dot product of the candidate case to the query case.
[0034] In one preferred solution, step S32 obtains semantic information of the query case and the candidate case according to the first attention score and the second attention score, specifically:
[0035] For the query case, the first attention score is used to identify and aggregate similar words in the candidate case, and the semantic information related to the query case in the candidate case is obtained as follows:
[0036]
[0037] in, is the semantic information related to the query case in the candidate case, ;
[0038] For candidate cases, the second attention score is used to identify and aggregate similar words in the query case, and the semantic information related to the candidate case in the query case is obtained as follows:
[0039]
[0040] in, It is the semantic information related to the query case and the candidate case.
[0041] One of the preferred solutions, after step S3, further includes:
[0042] The Triple Loss function is used in combination with cosine similarity to classify candidate cases into positive and negative instances; specifically:
[0043]
[0044] in, is the Triple Loss loss function, is the margin parameter, is the similarity calculation function between feature vectors, is the final feature representation of the query case, is the final feature representation of the candidate case positive instance, is the final feature representation of the negative instance of the candidate case.
[0045] One of the preferred solutions, after step S3, further includes:
[0046] S4, contrastive learning, dynamically adjusts the feature aggregation weights through the pooling layer, projects the features into a low-dimensional space, and uses the InfoNCE loss function to maximize the similarity of positive sample pairs and minimize the similarity of negative sample pairs, thereby screening out the candidate cases that are most similar to the query case.
[0047] In one preferred solution, the InfoNCE loss function is:
[0048]
[0049] in, is the InfoNCE loss function, is the temperature hyperparameter, is the similarity calculation function between feature vectors, is the query case representation after projection, is the positive instance representation of the candidate case after projection, is the negative instance representation of the candidate case after projection.
[0050] In the above technical solution of the present invention, the legal case retrieval method based on multi-task deep learning includes the following steps: data acquisition, constructing a legal case retrieval dataset, extracting the factual descriptions of legal documents in the dataset as text information, and the events described as event information; information fusion, encoding the text information and event information respectively to obtain a text sequence and an event sequence, using a cross-attention mechanism to use the event sequence as a query and the text sequence as a key and value, calculating the attention score, and fusing the event information and text information to output a fusion feature; similar case retrieval, based on the fusion feature, capturing the word-level interaction information of the query case and the candidate case based on a bidirectional attention layer, and calculating the bidirectional attention of the query case and the candidate case respectively; using a convolutional neural network to aggregate word-level features and generate a final feature representation. The present invention solves the technical problems of existing retrieval methods, such as poor interpretability, time-consuming and labor-intensive, and low accuracy of retrieval results.
[0051] In the present invention, a pre-trained language model is used for encoding, cross-attention is used to achieve the fusion of event and text information, and then the interactive information between texts is captured through a bidirectional attention layer. The convolutional neural network aggregates word-level similarities and then performs similar case retrieval tasks. The retrieval results are optimized through comparative learning, so that the generated similar cases are closer to the query cases. The present invention reduces the influence of redundant information and improves the training speed of the model through cross-attention. Comparative learning shortens the distance between positive sample pairs. Based on bidirectional attention, the interactive information between different case texts is captured, and the visualization of attention scores can verify the interpretability of the model. At the same time, two different loss functions are used for training, which is more flexible and can achieve good interpretability and robustness under different types of data sets. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the structures shown in these drawings without paying any creative work.
[0053] Figure 1Schematic diagram of a legal case retrieval method based on multi-task deep learning according to an embodiment of the present invention;
[0054] Figure 2 Schematic diagram of information fusion according to an embodiment of the present invention;
[0055] Figure 3 A schematic diagram of similar case search according to an embodiment of the present invention;
[0056] Figure 4 Schematic diagram of comparative learning according to an embodiment of the present invention.
[0057] The realization of the objectives, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0058] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making any creative efforts are within the scope of protection of the present invention.
[0059] It should be noted that all directional indications (such as up, down, etc.) in the embodiments of the present invention are only used to explain the relative position relationship, movement status, etc. between the various components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication will also change accordingly.
[0060] In addition, the terms "first," "second," and so on, used in this disclosure are for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Therefore, features specified as "first" or "second" may explicitly or implicitly include at least one of these features.
[0061] Moreover, the technical solutions between the various embodiments of the present invention may be combined with each other, but this must be based on the fact that ordinary technicians in this field can implement them. When the combination of technical solutions is mutually contradictory or cannot be implemented, it should be deemed that such a combination of technical solutions does not exist and is not within the scope of protection required by the present invention.
[0062] See also Figure 1 According to one aspect of the present invention, a method for retrieving similar legal cases based on multi-task deep learning is provided, wherein the method for retrieving similar legal cases based on multi-task deep learning comprises the following steps:
[0063] S1. Data acquisition: constructing a legal case retrieval dataset, extracting the factual descriptions of legal documents in the dataset as text information, and the events described in the factual descriptions as event information;
[0064] S2, information fusion, encodes text information and event information separately to obtain text sequence and event sequence, uses the cross-attention mechanism to take the event sequence as the query and the text sequence as the key and value, calculates the attention score, and fuses the event information and text information to output the fusion feature;
[0065] S3. Similar case retrieval: Based on the fusion features, the word-level interaction information of the query case and the candidate case is captured based on the bidirectional attention layer, and the bidirectional attention of the query case and the candidate case is calculated respectively; the convolutional neural network is used to aggregate the word-level features and generate the final feature representation.
[0066] Specifically, in this embodiment, the data set is a data set in triple form, including fact descriptions of query cases and candidate cases respectively; the event information is extracted from events in the fact description through an event extraction model as event information.
[0067] Specifically, in this embodiment, see Figure 2 , the step S2 is specifically as follows:
[0068] A pre-trained language model is used as the basic encoder to encode text information and event information to obtain text sequences and event sequences, and the token representations of the text sequences and event sequences are calculated respectively;
[0069] The text sequence is:
[0070]
[0071] in, is a text sequence, The process of encoding text information using a pre-trained language model. It is uncoded text information;
[0072] The sequence of events is:
[0073]
[0074] in, is a sequence of events, It is the event information that is not encoded;
[0075] Through cross-attention, the event sequence is used as the query Q, the text sequence as the key K and the value V, and the attention score between the query Q and the key K is calculated. The event sequence is used as the query vector, and the text sequence as the key and value. Cross-attention is used to integrate the text sequence into the case elements, thereby reducing the impact of redundant text information and focusing more on text information related to the case elements. At the same time, it can significantly reduce the length of the output feature vector and improve the subsequent training speed of the model.
[0076] The attention score between the query Q and the key K, that is, the attention weight of the query Q and the key K, is applied to the value V to obtain the fusion feature after the event information and the text information are fused; the fusion feature includes the event and text fusion feature of the query case and the event and text fusion feature of the candidate case.
[0077] Specifically, in this embodiment, the attention score between the query Q and the key K is:
[0078]
[0079] in, is the attention score between query Q and key K calculated using cross attention, is the transpose of the text sequence, is the dimension of key K, which serves as a scaling factor to avoid excessively large values. The similarity is converted into a probability distribution through the softmax function, which represents the attention weight of the query on each key.
[0080] Specifically, in this embodiment, the entire process of information fusion is to use legal events as the key elements of similar case retrieval, represent event information and text information through the encoder, extract text information matching the event through cross-attention, further enhance the information contained in the event features, reduce the impact of redundant text information, and thus improve the accuracy of the model.
[0081] Specifically, in this embodiment, see Figure 3 , an interaction-based deep learning model is used to capture the interaction information between different cases. When predicting the relevance of two case files, not only the sentence information is used, but also more fine-grained information such as words and phrases. These interaction information can be regarded as the relationship between texts. With the interaction information, the model can more accurately judge the similarity between texts. Contrastive learning is designed as an auxiliary task. The process of contrastive learning is the optimization process of the final feature representation. In contrastive learning, parameterized attention pooling is used to process the features, so that contrastive learning can pay more attention to important event elements; step S3 captures the word-level interaction information of the query case and the candidate case based on the bidirectional attention layer according to the fusion feature, and calculates the bidirectional attention of the query case and the candidate case respectively, specifically:
[0082] S31. Calculate the scaled dot product of the query case and the candidate case based on the fusion feature; the fusion feature is: ;Use the bidirectional attention layer to capture the interactive information between the query case and the candidate case, and calculate the bidirectional attention of the query case and the candidate case separately, which makes it easier to identify the word-level similarity between the cases;
[0083] S32. Normalize the scaled dot product to obtain a first attention score and a second attention score, and obtain semantic information of the query case and the candidate case based on the first attention score and the second attention score;
[0084] S33. According to the fusion features and semantic information of the original input, the output of the bidirectional attention layer is obtained, that is, the fusion features of the original input and the obtained semantic information are multiplied to obtain the output of the bidirectional attention layer. is a two-dimensional tensor; specifically:
[0085]
[0086]
[0087] in, is the output of the bidirectional attention layer for the query case, is the output of the bidirectional attention layer for the candidate case positive instance, To query cases, is a positive instance of a candidate case. The positive instance of a candidate case is a case that is more similar to the query case, and the ultimate goal is to identify the positive instance. is the semantic information related to the query case in the candidate case, It is the semantic information related to the query case and the candidate case.
[0088] Specifically, in this embodiment, the scaled dot product of the query case and the candidate case is:
[0089]
[0090] in, is the scaled dot product of the query case and the candidate case, To query the features of position i in the case sequence, is the feature of position j in the positive instance sequence of the candidate case.
[0091] Specifically, in this embodiment, the first attention score is:
[0092]
[0093] in, is the first attention score, is the length of the sequence, for, is the first scaled dot product from the query case to the candidate case;
[0094] The second attention score is:
[0095]
[0096] in, is the second attention score, is the first scaled dot product of the candidate case to the query case.
[0097] Specifically, in this embodiment, step S32 obtains semantic information of the query case and the candidate case according to the first attention score and the second attention score, specifically:
[0098] For the query case, the first attention score is used to identify and aggregate similar words in the candidate case, and the semantic information related to the query case in the candidate case is obtained as follows:
[0099]
[0100] in, is the semantic information related to the query case in the candidate case, ;
[0101] For candidate cases, the second attention score is used to identify and aggregate similar words in the query case, and the semantic information related to the candidate case in the query case is obtained as follows:
[0102]
[0103] in, It is the semantic information related to the query case and the candidate case.
[0104] Specifically, in this embodiment, step S3 uses a convolutional neural network to aggregate word-level features and generate a final feature representation, specifically:
[0105] The convolutional neural network shared by the query and candidate cases aggregates word-level features and combines them with pooling operations to generate the final feature representation, including the query and candidate case final feature representations. By using different pooling operations, the model focuses more on the representation of important event elements, and all pooling results are concatenated to obtain the final feature representation.
[0106] ,
[0107]
[0108]
[0109] in, is the convolutional layer output of the query case, is the convolutional layer output of the candidate case positive instance, is the final feature representation of the query case, is the final feature representation of the candidate case positive instance, is the average pooling operation for the query case, For the maximum pooling operation of the query case, is the average pooling operation of the candidate positive instance, The maximum pooling operation of the candidate positive instance is performed. The above method can obtain the final feature representation of the query case and the positive instance of the candidate case, and encode it as and Similarly, we can get , are both two-dimensional tensors;
[0110] The dataset is constructed as Therefore, the triple loss function is used to classify the candidate cases into positive and negative instances in combination with cosine similarity; specifically:
[0111]
[0112] in, is the Triple Loss loss function, is the margin parameter, The cosine distance is used to calculate the similarity between feature vectors. Perform calculations, is the final feature representation of the query case, is the final feature representation of the candidate case positive instance, is the final feature representation of the candidate negative instance, To query cases , Candidate case or .
[0113] Specifically, in this embodiment, see Figure 4 , after step S3, further comprising:
[0114] S4. Contrastive learning dynamically adjusts the feature aggregation weights through the pooling layer, projects the features into a low-dimensional space, and uses the InfoNCE loss function to maximize the similarity of positive sample pairs and minimize the similarity of negative sample pairs, thereby screening out the candidate cases most similar to the query cases; Contrastive learning, as an auxiliary task of similar case retrieval tasks, helps the information fusion step output similar features for similar cases. The goal of contrastive learning is to learn an encoder that encodes similar data similarly and makes the encoding results of different types of data as different as possible, so as to output similar representations for similar cases during information fusion, thereby optimizing the performance of the model on similar case retrieval tasks, maximizing the similarity of positive sample pairs, and minimizing the similarity of negative sample pairs; Attention pooling is a pooling operation combined with the attention mechanism, which is commonly used in deep learning models, especially when processing sequence data such as text, speech, or spatial data such as images. Its core idea is to perform weighted aggregation on different parts of the input by dynamically calculating weights, so as to capture important information more flexibly. Average pooling only pays attention to the output but not the input, so a better idea is proposed to weight the output according to the position of the input:
[0115]
[0116] in, is a function of weighted operation, which is a standard attention score calculation. is the prediction point, is the i-th sample point, is the jth sample point during normalization, is the unweighted output value, This is the theoretical derivation of attention pooling, known as Nadaraya-Watson kernel regression. The formula can be simplified from the perspective of the attention mechanism framework to obtain a more general attention pooling formula, which is also the attention pooling formula used in the pooling layer of this invention:
[0117]
[0118] in, is the attention weight, and obviously the attention pooling is The weighted average of and key The relationship between ; It is easy to know that for any query, all key-value pairs of attention weights in the model are valid probability distributions, they are non-negative, and the sum is 1. The attention pooling with parameters integrates the learnable parameters into the attention pooling. Unlike before, in the following query and key The distance between them is multiplied by the learnable parameter ;
[0119]
[0120] in, are learnable parameters;
[0121] Contrastive learning maps representations to a lower-dimensional space. Projection networks reduce data complexity and redundancy, helping to better separate similar and dissimilar instances. However, not all events contribute equally to the meaning of a case. Using a parameterized attention pooling layer to project the encoded feature representations into a lower-dimensional space, dynamically adjusting the way information is aggregated helps enhance the discriminative power of the learned representations. This is as follows:
[0122]
[0123]
[0124] in, To obtain the normalized attention weights through the softmax function, To query the features of position i in the case sequence, is an adjustable parameter, is the output of the attention pooling layer; As an adjustable parameter to guide the learning of attention weights, it can dynamically adjust the way of information aggregation. After obtaining the normalized attention weights through the softmax function, the output of the attention pooling layer is calculated. During the training process, it is randomly initialized and jointly learned, that is, the attention pooling layer will select more important events by allocating better attention. The attention pooling layer is the pooling layer mentioned above;
[0125] In order to maximize the similarity of positive sample pairs, minimize the similarity of negative sample pairs, and improve the performance of the model in similar case retrieval, the InfoNCE loss function is used for training. The InfoNCE loss function is:
[0126]
[0127] in, is the InfoNCE loss function, is the temperature hyperparameter, is the similarity calculation function between feature vectors, which is to calculate the cosine similarity. is the query case representation after projection, is the positive instance representation of the candidate case after projection, It is the negative instance representation of the candidate case after projection; through comparative learning, it helps to output similar feature representations for similar cases during information fusion, and makes the model pay more attention to event information that has a greater impact on the case facts, achieving a deeper understanding of the case.
[0128] Specifically, in this embodiment, multi-task learning: similar case retrieval is the main task, contrastive learning is the auxiliary task, and the loss function is used to optimize the accuracy of the main task. The model uses two different loss functions to optimize the model performance to better solve different similar case retrieval tasks. Triple loss, also known as Triple Loss, is aimed at similar case retrieval and classification tasks. In high-quality legal triple files, the model is forced to learn a feature space so that the distance between the query case and the positive sample is at least less than a set threshold than the distance between the negative sample, thereby improving the accuracy of the classification task. The InfoNCE loss function is aimed at similar case retrieval and case ranking tasks. In a dataset containing multiple types of cases, the model is also forced to learn a feature space, minimize the distance between similar cases, maximize the distance between heterogeneous cases, and optimize the performance of the model in case ranking tasks. Similar case retrieval and contrastive learning give loss functions respectively. and , therefore, the final loss function is the weighted sum of these two loss functions, which is:
[0129]
[0130] in, is the weighted sum of the Triple Loss loss function and the InfoNCE loss function, The weight of the contrastive learning loss function can be adjusted to adjust the impact of contrastive learning on similar case retrieval.
[0131] Specifically, in this embodiment, the present invention uses the three steps of information fusion, similar case retrieval and comparative learning as the specific implementation method of the model for realizing legal similar case retrieval, accurately associates legal events with text information through feature fusion, captures the deep semantics of the case in combination with the two-way attention mechanism, and optimizes feature representation using comparative learning; the first module of the model is the information fusion module, which is responsible for feature extraction and using cross-attention to fuse features, so as to associate event information with text information, and uses the attention mechanism to strengthen key text information and weaken the influence of redundant text information on model accuracy. The output sequence length is significantly shorter, which reduces the computational burden of subsequent modules and improves the training speed; the second module is the similar case retrieval module, which uses the two-way attention layer to close the Pay attention to the interactive information between different texts and strengthen the feature representation. Finally, each case file is represented as a two-dimensional tensor. The cosine distance is used to calculate the similarity between the query sample and the positive and negative instances. If the similarity between the query case and the positive instance is greater than that between the negative instance, the classification is correct, and the classification task of similar case retrieval is realized. The final representation of all cases is stored in the test set, and the ranking of the positive instance among all candidate cases is calculated to evaluate the performance of the model in the sorting problem; the third module is the contrastive learning module, which serves as an auxiliary task of the similar case retrieval task. It helps the information fusion module to output similar features for similar cases, which can not only improve the accuracy of the similar case retrieval task, but also minimize the cosine distance between similar samples, thereby improving the ranking of the positive instance in the candidate cases.
[0132] The above are only preferred embodiments of the present invention and are not intended to limit the patent scope of the present invention. All equivalent structural transformations made using the contents of the present description and drawings under the inventive concept of the present invention, or direct / indirect applications in other related technical fields, are included in the patent protection scope of the present invention.
Claims
1. A legal case retrieval method based on multi-task deep learning, characterized by: The following steps are involved: S1. Data acquisition: constructing a legal case retrieval dataset, extracting the factual descriptions of legal documents in the dataset as text information, and the events described in the factual descriptions as event information; S2, information fusion, encodes text information and event information separately to obtain text sequence and event sequence, uses the cross-attention mechanism to take the event sequence as the query and the text sequence as the key and value, calculates the attention score, and fuses the event information and text information to output the fusion feature; S3. Similar case retrieval: Based on the fusion features, the word-level interaction information of the query case and the candidate case is captured based on the bidirectional attention layer, and the bidirectional attention of the query case and the candidate case is calculated respectively; the convolutional neural network is used to aggregate the word-level features and generate the final feature representation.
2. The method for retrieval of similar legal cases based on multi-task deep learning according to claim 1, characterized in that: The step S2 is specifically as follows: A pre-trained language model is used as the basic encoder to encode text information and event information to obtain text sequences and event sequences, and the token representations of the text sequences and event sequences are calculated respectively; The text sequence is: ; in, is a text sequence, The process of encoding text information using a pre-trained language model. It is uncoded text information; The sequence of events is: ; in, is a sequence of events, It is the event information that is not encoded; Through cross attention, the event sequence is used as the query Q, the text sequence is used as the key K and the value V, and the attention score between the query Q and the key K is calculated; The attention score between the query Q and the key K, that is, the attention weight of the query Q and the key K, is applied to the value V to obtain the fusion feature after the event information and the text information are fused.
3. The method for retrieval of similar legal cases based on multi-task deep learning according to claim 2, characterized in that: The attention score between the query Q and the key K is: ; in, is the attention score between query Q and key K calculated using cross attention, is the dimension of key K.
4. A method for retrieval of similar legal cases based on multi-task deep learning according to any one of claims 1 to 3, characterized in that: The step S3 captures the word-level interaction information of the query case and the candidate case based on the bidirectional attention layer according to the fusion features, and calculates the bidirectional attention of the query case and the candidate case respectively, specifically: S31. Calculate the scaled dot product of the query case and the candidate case based on the fused features; S32. Normalize the scaled dot product to obtain a first attention score and a second attention score, and obtain semantic information of the query case and the candidate case based on the first attention score and the second attention score; S33. Based on the fusion features and semantic information of the original input, the output of the bidirectional attention layer is obtained.
5. The method for retrieval of similar legal cases based on multi-task deep learning according to claim 4 is characterized in that: The scaled dot product of the query case and the candidate case is: ; in, is the scaled dot product of the query case and the candidate case, To query the features of position i in the case sequence, is the feature of position j in the candidate case positive instance sequence, for and The dimension of .
6. The method for retrieval of similar legal cases based on multi-task deep learning according to claim 5, characterized in that: The first attention score is: ; in, is the first attention score, is the length of the sequence, , is the first scaled dot product from the query case to the candidate case; The second attention score is: ; in, is the second attention score, is the first scaled dot product of the candidate case to the query case.
7. The method for retrieval of similar legal cases based on multi-task deep learning according to claim 6, characterized in that: The step S32 obtains semantic information of the query case and the candidate case according to the first attention score and the second attention score, specifically: For the query case, the first attention score is used to identify and aggregate similar words in the candidate case, and the semantic information related to the query case in the candidate case is obtained as follows: ; in, is the semantic information related to the query case in the candidate case, ; For candidate cases, the second attention score is used to identify and aggregate similar words in the query case, and the semantic information related to the candidate case in the query case is obtained as follows: ; in, It is the semantic information related to the query case and the candidate case.
8. The method for retrieval of similar legal cases based on multi-task deep learning according to any one of claims 1 to 3, characterized in that: After step S3, the method further includes: The Triple Loss function is used in combination with cosine similarity to classify candidate cases into positive and negative instances; specifically: ; in, is the Triple Loss loss function, is the margin parameter, is the similarity calculation function between feature vectors, is the final feature representation of the query case, is the final feature representation of the candidate case positive instance, is the final feature representation of the negative instance of the candidate case.
9. The method for retrieval of similar legal cases based on multi-task deep learning according to any one of claims 1 to 3, characterized in that: After step S3, the method further includes: S4, contrastive learning, dynamically adjusts the feature aggregation weights through the pooling layer, projects the features into a low-dimensional space, and uses the InfoNCE loss function to maximize the similarity of positive sample pairs and minimize the similarity of negative sample pairs, thereby screening out the candidate cases that are most similar to the query case.
10. The method for retrieving similar legal cases based on multi-task deep learning according to claim 9, characterized in that: The InfoNCE loss function is: ; in, is the InfoNCE loss function, is the temperature hyperparameter, is the similarity calculation function between feature vectors, is the query case representation after projection, is the positive instance representation of the candidate case after projection, is the negative instance representation of the candidate case after projection.
Citation Information
Patent Citations
Case retrieval method and device, electronic equipment and storage device
CN113535933A
Long text retrieval model based on comparative learning
CN114201581A