Class case retrieval method and device, electronic equipment and storage medium
By using two major language models to analyze the factor information and the probability of combination correctness of the case, the degree of fit between cases is calculated, and the problem of low accuracy of existing case search methods is solved, and a higher search accuracy is achieved.
Patent Information
- Application Number
- CN202411480118.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-22
- Publication Date
- 2025-02-28
AI Technical Summary
The accuracy of the existing case search methods is low, mainly because the pre-trained language model only performs text matching, and the matched cases are only semantically similar.
Two major language models are used for analysis: the first major language model is used to reason about the element information of the pending query case, and select relevant target candidate cases from the candidate cases; the second major language model calculates the probability of the combination correctness based on the information of the query case and the target candidate cases, and then calculates the first degree of fit between cases, and finally selects the case with the highest degree of fit as the related case.
By integrating the unique characteristics and deep understanding of the case, the accuracy of similar case searches is improved, and the relevant cases selected are more accurate.
Smart Images

Figure CN119537563A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a similar case retrieval method, device, electronic device and storage medium. Background Art
[0002] With the successful application of pre-trained language models in the field of natural language processing, some studies in the field of information retrieval have also explored the use of pre-trained language models to solve the downstream task of document retrieval.
[0003] In similar case retrieval tasks, pre-trained language models are currently commonly used to perform similar case retrieval. The purpose of similar case retrieval is to be able to find related cases of the query case in the case library based on the case information of the query case when a query case that has not yet been judged is given. In the current similar case retrieval method, a pre-trained language model is used to compare the case information of the query case with the case information of the candidate cases in the case library, so as to obtain the related cases of the query case. However, the pre-trained language model only performs text matching on the case information of the query case and the case information of the candidate cases in the case library, and the matched cases are only semantically similar. Therefore, the accuracy of the current similar case retrieval method is low. Summary of the invention
[0004] In view of the above problems, the embodiments of the present application propose a similar case retrieval method, device, electronic device and storage medium to solve the problem of low accuracy of the current similar case retrieval method.
[0005] According to one aspect of an embodiment of the present application, a similar case retrieval method is provided, the method comprising: using a first large language model to analyze based on case information of a pending query case and first prompt information to obtain element information of the pending query case; based on the element information of the pending query case and the case information of the pending query case, selecting a target candidate case related to the pending query case from candidate cases; for each target candidate case, using a second large language model to analyze based on the case information of the pending query case, the case information of the target candidate case and the second prompt information to obtain a combined correct probability of the pending query case and the target candidate case, and calculating a first degree of fit between the pending query case and the target candidate case based on the combined correct probability; selecting at least one target candidate case with the highest first degree of fit as a related case of the pending query case.
[0006] According to another aspect of an embodiment of the present application, a similar case retrieval device is provided, the device comprising: a first analysis module, used to use a first large language model to perform analysis based on case information of a pending query case and first prompt information to obtain element information of the pending query case; a first selection module, used to select target candidate cases related to the pending query case from candidate cases based on the element information of the pending query case and the case information of the pending query case; a second analysis module, used to use a second large language model to perform analysis based on the case information of the pending query case, the case information of the target candidate case and the second prompt information for each target candidate case to obtain a combined correct probability of the pending query case and the target candidate case, and calculate a first degree of fit between the pending query case and the target candidate case based on the combined correct probability; a second selection module, used to select at least one target candidate case with the highest first degree of fit as a related case of the pending query case.
[0007] According to another aspect of an embodiment of the present application, an electronic device is provided, comprising a processor and a computer-readable storage medium, wherein a computer program is stored on the computer-readable storage medium; when the computer program is executed by the processor, the processor executes a similar case retrieval method as described in any one of the above items.
[0008] According to another aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the processor executes the similar case retrieval method as described in any one of the above items.
[0009] In the embodiment of the present application, considering that the element information of the case belongs to the unique characteristics of the case and can make a summary description of the case, the first large language model (Large Language Models, LLM) is first used to infer the element information of the query case to be processed, and then based on the element information of the query case to be processed and the case information of the query case to be processed, the target candidate case related to the query case to be processed is selected from the candidate cases. Compared with the method of simply using the case information for comparison, the unique characteristics of the case are incorporated, so that the accuracy of similar case retrieval can be improved; and, the second largest language model is used to infer the first degree of fit between the query case to be processed and the target candidate case, and the related cases of the query case to be processed are selected according to the first degree of fit, and the deep understanding ability of the second largest language model is further used to select more accurate related cases, thereby further improving the accuracy of similar case retrieval. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] In order to more clearly illustrate the technical solution of the embodiment of the present application, the drawings required for use in the description of the embodiment of the present application will be briefly introduced below. Obviously, the drawings described below are only some drawings of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0011] Figure 1 is a flowchart of the steps of a similar case retrieval method according to an embodiment of the present application;
[0012] Figure 2 is a structural diagram of a recall model in an embodiment of the present application;
[0013] Figure 3 It is a structural schematic diagram of a sorting model in an embodiment of the present application;
[0014] Figure 4 is a schematic diagram of a sorting model training process in an embodiment of the present application;
[0015] Figure 5 is a structural block diagram of a similar case retrieval device according to an embodiment of the present application;
[0016] Figure 6 is a structural block diagram of an electronic device according to an embodiment of the present application;
[0017] Figure 7 It is a structural block diagram of a computer-readable storage medium in an embodiment of the present application. DETAILED DESCRIPTION
[0018] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0019] Reference Figure 1 , showing a step flow chart of a similar case retrieval method according to an embodiment of the present application.
[0020] like Figure 1 As shown, the similar case retrieval method may include the following steps:
[0021] Step 101, using the first language model, based on the case information of the query case to be processed and the first prompt information, analyze to obtain the element information of the query case to be processed.
[0022] In order to enable the large language model to have the ability to infer the element information of the case based on the case information of the case, the first large language model for inferring the element information of the case can be pre-trained.
[0023] Prompt refers to an instruction or prompt given a task or question. As part of the model input, it is used to guide the model to generate text or answers related to the task. Therefore, in order to enable the first language model to more accurately infer the element information of the case, the first prompt information for the first language model is set, and the first prompt information is used to guide the first language model to analyze the case information of the case and obtain the element information of the case. The specific content of the first prompt information can be set according to actual experience, and this embodiment does not limit this.
[0024] Exemplarily, the element information may include but is not limited to first element information and second element information. The first element information includes but is not limited to violation type information and applicable rule information (such as legal application information). The second element information includes but is not limited to dispute focus information and keywords.
[0025] For example, the first prompt message may be "You are now a case consultant, please help infer the violation type information, applicable rules information, dispute focus information and keywords of the case."
[0026] In the embodiment of the present application, the training process of the first language model includes the following steps A1 to A3:
[0027] Step A1: Acquire third sample data, wherein the third sample data includes case information of sample candidate cases and actual element information of the sample candidate cases.
[0028] In the embodiment of the present application, an open source case library is used as a data source. The case library includes multiple query cases and multiple candidate cases. The query case includes a case identifier, case information of the case, etc. Each query case has a corresponding related case. The candidate case includes a case identifier, case information of the case, basic facts of the case, reasoning process of the case, judgment result of the case, element information of the case, etc.
[0029] A plurality of candidate cases are obtained from the case database as sample candidate cases, and data of the sample candidate cases are annotated to obtain third sample data. The third sample data includes case information of the sample candidate cases and actual element information (annotation) of the sample candidate cases.
[0030] In the embodiment of the present application, for the sake of convenience, the third sample data may be saved in JSON (JavaScript Object Notation) data format.
[0031] Step A2: using the first initial large language model, analyzing based on the case information of the sample candidate case and the first prompt information to obtain prediction factor information of the sample candidate case.
[0032] The first prompt information and the case information of the sample candidate case are concatenated to obtain the first input information, and the first input information is input into the first initial large language model. Under the guidance of the first prompt information, the first initial large language model analyzes the case information of the sample candidate case and outputs the first output information, which includes the prediction factor information of the sample candidate case.
[0033] In the embodiment of the present application, the first initial large language model can be trained by LoRA (Low-Rank Adaptation) fine-tuning. LoRA fine-tuning improves the performance of the model by fine-tuning the model parameters. It is a low-rank adaptation technology that is used to fine-tune a small number of parameters while keeping most of the model parameters unchanged, thereby improving the performance of the model on a specific task. By performing LoRA fine-tuning on the first initial large language model, its ability to reason about the element information of the case is enhanced.
[0034] The LoRA fine-tuning process is as follows: Update the parameters of the first initial large language model, the formula is as follows: W0+ΔW, where W0 is the initial parameter of the first initial large language model, and ΔW is the update parameter of the first initial large language model. Assume W0∈R d×k , its update can be expressed as: W0+ΔW=W0+BA,B∈R d×r ,A∈R r×k , where d represents the first dimension of W0, k represents the second dimension of W0, r represents the rank, rank r<<min(d,k), and A and B are trainable parameters. During the training process, W0 is fixed, and parameters A and B are variable. During the forward reasoning process, W0 and ΔW are multiplied by the same input information x, and finally added together to obtain the output information h=W0x+ΔWx=W0x+BAx.
[0035] Step A3, based on the actual element information and the predicted element information, determine whether the first initial large language model has been trained; when the training is not completed, adjust the parameters of the first initial large language model to continue training; after the training is completed, use the trained model as the first large language model.
[0036] Based on the actual element information and the predicted element information, a loss function of the first initial large language model can be calculated. When the loss function of the first initial large language model does not meet the first preset condition, it is determined that the training is not completed; when the loss function of the first initial large language model meets the first preset condition, it is determined that the training is completed.
[0037] The first preset condition may be that the loss function of the first initial large language model is less than a first preset threshold, or that the loss function of the first initial large language model reaches a minimum value, etc. The loss function of the first initial large language model may be a cross entropy loss function, a logarithmic loss function, an exponential loss function, etc.
[0038] By using the first language model obtained through training and analyzing based on the case information of the query case to be processed and the first prompt information, element information of the query case to be processed can be obtained.
[0039] Specifically, the first prompt information and the case information of the query case to be processed are concatenated to obtain the second input information, and the second input information is input into the first large language model. Under the guidance of the first prompt information, the first large language model analyzes the case information of the query case to be processed and outputs the second output information. The second output information includes the element information of the query case to be processed.
[0040] Step 102: Based on the element information of the query case to be processed and the case information of the query case to be processed, a target candidate case related to the query case to be processed is selected from the candidate cases.
[0041] Based on the element information of the query case to be processed and the case information of the query case to be processed, the element information of the candidate cases and the case information of the candidate cases in the case library are compared, so as to select multiple candidate cases related to the query case to be processed from the candidate cases as target candidate cases.
[0042] In an optional implementation, based on the element information of the query case to be processed and the case information of the query case to be processed, the process of selecting a target candidate case related to the query case to be processed from the candidate cases may include the following steps B1 to B3:
[0043] Step B1, based on the first element information of the query case to be processed, multiple candidate cases related to the query case to be processed are selected from the candidate cases as first candidate cases.
[0044] In the embodiment of the present application, an element coincidence evaluation mechanism is designed for the first element information, which can accurately measure the similarity of judgments between different cases.
[0045] Exemplarily, based on the first element information of the query case to be processed, a process of selecting multiple candidate cases related to the query case to be processed from the candidate cases as the first candidate cases includes: for each candidate case, based on the first element information of the query case to be processed and the first element information of the candidate cases, calculating the first element overlap between the query case to be processed and the candidate cases; and selecting multiple candidate cases from the candidate cases as the first candidate cases according to the first element overlap. In this method, the similarity between the query case to be processed and the candidate cases can be accurately measured through the first element overlap between the query case to be processed and the candidate cases, so as to select multiple candidate cases related to the case to be processed.
[0046] In the case where the first element information includes violation type information and applicable rule information, the process of calculating the first element overlap between the pending query case and the candidate case based on the first element information of the pending query case and the first element information of the candidate case may include: calculating the violation type overlap between the pending query case and the candidate case based on the violation type information of the pending query case and the violation type information of the candidate case; calculating the applicable rule overlap between the pending query case and the candidate case based on the applicable rule information of the pending query case and the applicable rule information of the candidate case; and taking the product of the violation type overlap and the applicable rule overlap as the first element overlap between the pending query case and the candidate case. In this method, by cleverly designing the element overlap (also called judgment overlap) and calculating the overlap between two cases in violation type and applicable rules, cases with similar judgments can be found in a short time.
[0047] Exemplarily, the violation type overlap between the query case to be processed and the candidate case is calculated by the following formula 1:
[0048]
[0049] Among them, COD represents the overlap of the violation types, C i Indicates the violation type information of the pending query case, C j Indicates the violation type information of the candidate case, |C i ∩C j | means C i and C j The number of violation type information in the intersection of |C i ∪C j | means C i and C jThe number of violation type information in the union of . For example, if the violation type information of the pending query case is A and B, and the violation type information of the candidate case is B and C, then the violation type overlap between the pending query case and the candidate case is 1 / 3.
[0050] Exemplarily, the degree of overlap of applicable rules between the query case to be processed and the candidate case is calculated by the following formula 2:
[0051]
[0052] Among them, SOD represents the overlap degree of applicable rules, T represents the number of applicable rule information that overlaps the query case to be processed with the candidate case, D represents the total number of all candidate cases, and freq(t,D) represents the number of times the tth applicable rule information appears in all candidate cases. The fewer times a certain applicable rule information appears in all candidate cases, the greater the inverse document frequency, which means that the applicable rule information is more important.
[0053] Exemplarily, the first factor overlap between the query case to be processed and the candidate case is calculated by the following formula 3:
[0054] CJO=COD×SOD Formula 3
[0055] Among them, CJO represents the overlap of the first element, COD represents the overlap of the violation type, and SOD represents the overlap of the applicable rules.
[0056] After calculating the first element overlap between the query case to be processed and each candidate case, the candidate cases are sorted in descending order of the first element overlap, and multiple candidate cases ranked first are selected as the first candidate cases.
[0057] Step B2: Based on the second element information of the query case to be processed, multiple first candidate cases related to the query case to be processed are selected from the first candidate cases as second candidate cases.
[0058] In the embodiment of the present application, not only the first factor information is used to compare and identify similar cases, but the second factor information is also an important criterion for identifying similar cases. Therefore, a factor similarity evaluation mechanism is designed for the second factor information, which can accurately measure the correlation between the dispute focuses between different cases.
[0059] Exemplarily, based on the second element information of the pending query case, the process of selecting multiple first candidate cases related to the pending query case from the first candidate cases as the second candidate cases includes: for each first candidate case, based on the second element information of the pending query case and the second element information of the first candidate case, calculating the first element similarity between the pending query case and the first candidate case; and selecting multiple first candidate cases from the first candidate cases as the second candidate cases according to the first element similarity. In this method, starting from the second element information (such as dispute focus information, etc.), the case characteristics are deeply analyzed, so as to provide more accurate matching standards for similar case retrieval and judgment reference.
[0060] Exemplarily, the process of calculating the first element similarity between the query case to be processed and the first candidate case based on the second element information of the query case to be processed and the second element information of the first candidate case includes: using the second element information of the query case to be processed and the second element information of the first candidate case as inputs of a recall model in a pre-trained retrieval model, and obtaining the first element similarity between the query case to be processed and the first candidate case output by the recall model. In this way, the first element similarity is calculated using the recall model, which can take advantage of the recall model in calculating similarity and improve the accuracy of the first element similarity.
[0061] In the embodiment of the present application, the recall model may adopt any applicable model that can perform independent analysis and calculate a similarity score.
[0062] For example, the recall model can adopt the structure of a BERT (Bidirectional Encoder Representations from Transformers) model. The BERT model is a deep bidirectional model based on the Transformer architecture that learns language representation through large-scale unsupervised training.
[0063] Figure 2 Schematic diagram of a recall model in an embodiment of the present application. Figure 2As shown, the recall model includes multiple first encoders (Encoders) connected in series and multiple second encoders connected in series. The second element information of the query case (such as the query case to be processed mentioned above) is encoded by multiple first encoders connected in series to generate a vector representation of the second element information of the query case. The second element information of the candidate case (such as the first candidate case mentioned above) is encoded by multiple second encoders connected in series to generate a vector representation of the second element information of the candidate case. Based on the vector representation of the second element information of the query case and the vector representation of the second element information of the first candidate case, the element similarity is calculated (depending on the actual scenario, the element similarity can be the first element similarity or the second element similarity), and the element similarity can specifically be in the form of a similarity score.
[0064] When using the BERT model to represent the content of a text, the output vector of the [CLS] marker is usually used. The [CLS] marker is the beginning of the BERT model input sequence, which aggregates the information of the entire input sequence in all layers. Therefore, the hidden state of the [CLS] position can be considered as a representation of the entire sentence or document. In this embodiment, the second element information of the query case and the second element information of the candidate case are respectively input into the BERT model, the vector corresponding to the [CLS] marker is taken as the vector representation of the corresponding second element information, and then the element similarity is judged.
[0065] This embodiment performs word segmentation processing on the text fragment of the second element information. Special identifiers [CLS] and [SEP] are added before and after the word segmentation results, and the results of the above word segmentation conversion are mapped to the word embedding matrix X. The word embedding matrix X will be sent to the superimposed multi-layer encoder to generate a vector representation of the context. The formula involved is as follows:
[0066]
[0067]
[0068]
[0069] FFN(x)=max(0,xW1+b1)W2+b2 Formula 7
[0070] Among them, Q i represents the query matrix of the i-th attention head, K i represents the key matrix of the i-th attention head, V i represents the value matrix of the i-th attention head, X n-1 represents the output of the previous layer (n-1 layer), represents the query weight matrix of the i-th attention head, represents the key weight matrix of the i-th attention head, Represents the value weight matrix of the i-th attention head, head i represents the output of the i-th attention head, softmax represents the normalization function, K i The transpose of k represents the dimension of the key vector, Z represents the concatenation of the outputs of u attention heads, and u represents the number of attention heads. represents the weight matrix of the output layer, FFN(x) represents the output of the feedforward neural network (FFN), x represents the input, W1 represents the first weight matrix of the feedforward neural network, W2 represents the second weight matrix of the feedforward neural network, b1 represents the first bias term of the feedforward neural network, and b2 represents the second bias term of the feedforward neural network.
[0071] The BERT model usually uses the output vector z0 corresponding to the [CLS] identifier Z[0] at the first position as the representation of the input sequence, as shown in Formula 8:
[0072] z0=Z[0] Formula 8
[0073] Assume that the vector representation of the query case q output by the encoder is z q , the vector representation of candidate case d output by the encoder is z d , then the element similarity s(q,d) is calculated by calculating the vector dot product, as shown in Formula 9:
[0074] s(q,d)=(z q ) T × d Formula 9
[0075] Among them, (z q ) T Indicates z q , × represents the vector dot product operation, and s(q,d) represents the element similarity between the query case q and the candidate case d (depending on the actual scenario, the element similarity can be the first element similarity or the second element similarity).
[0076] After calculating the first element similarity between the query case to be processed and each first candidate case, the first candidate cases are sorted in descending order of the first element similarity, and multiple first candidate cases ranked first are selected as the second candidate cases.
[0077] Step B3: sorting the second candidate cases based on the case information of the query case to be processed, and selecting a plurality of second candidate cases ranked first as the target candidate cases.
[0078] In an embodiment of the present application, after the second candidate cases are recalled, in order to further improve the accuracy, the second candidate cases are sorted based on the case information of the query cases to be processed, and multiple second candidate cases ranked first are selected as target candidate cases.
[0079] Exemplarily, the process of sorting the second candidate cases based on the case information of the pending query case includes: for each second candidate case, based on the case information of the pending query case and the case information of the second candidate case, calculating the first content similarity between the pending query case and the second candidate case; sorting the second candidate cases in descending order of the first content similarity. In this way, the relevance between cases can be measured more accurately based on the content similarity between the cases.
[0080] Exemplarily, based on the case information of the pending query case and the case information of the second candidate case, the process of calculating the first content similarity between the pending query case and the second candidate case includes: splicing the case information of the pending query case and the case information of the second candidate case to obtain spliced case information, using the spliced case information as the input of the ranking model in the pre-trained retrieval model, and obtaining the first content similarity between the pending query case and the second candidate case output by the ranking model. In this way, the first content similarity is calculated using the ranking model, which can take advantage of the ranking model in calculating similarity and improve the accuracy of the first content similarity.
[0081] The above recall model uses the dual encoder representation model of DPR (Dense Passage Retrieval), in which the vector representations corresponding to the query cases and candidate cases are generated independently without attention interaction. This method allows efficient retrieval by pre-calculating the vectors of the corpus and using ANN (Approximate Nearest Neighbor). However, the vector representations corresponding to the query cases and candidate cases in the recall model are independent of each other and do not interact. Therefore, in order to improve the accuracy of retrieval, the ranking model (interactive model) is further used for interactive analysis.
[0082] In the embodiment of the present application, the ranking model may adopt any applicable model that can perform interactive analysis and calculate similarity scores.
[0083] Exemplarily, the ranking model may adopt the structure of a BERT model.
[0084] Figure 3 Schematic diagram of a sorting model in an embodiment of the present application. Figure 3 As shown, the sorting model includes a plurality of third encoders (Encoders) and MLPs (Multilayer Perceptrons) connected in series. The case information of the query case (such as the query case to be processed mentioned above) and the case information of the candidate case (such as the second candidate case mentioned above) are spliced to obtain spliced case information, and the spliced case information is encoded by a plurality of third encoders connected in series to generate a vector representation of the spliced case information. The vector representation of the case information is mapped using MLP to obtain content similarity (depending on the actual scenario, the content similarity can be the first content similarity or the second content similarity), and the content similarity can be in the form of a similarity score.
[0085] The case information of the query case is concatenated with the case information of the candidate case. According to the BERT model tagging rules, the [CLS] and [SEP] tags are added to the input sentence. After that, each word segmentation is input into the model to generate a vector representation of the corresponding context embedding. Finally, MLP is used to map the interactive vector representation between the query case and the candidate case corresponding to the [CLS] tag to the content similarity. The formula involved is as follows:
[0086] X q,d =[CLS]tokenizer(q)[SEP]tokenizer(d)[SEP] Formula 10
[0087] f(q,d)=BERT [CLS] (X q,d ) Formula 11
[0088] sim(q,d)=MLP(f(q,d)) Formula 12
[0089] Where q represents the query case, d represents the candidate case, [CLS] represents the beginning mark, [SEP] represents the ending mark, tokenizer(q) represents the word segmentation of the query case, tokenizer(d) represents the word segmentation of the candidate case, and X q,d Represents the concatenation of query cases and candidate cases, BERT [CLS] [CLS] of the BERT model represents the corresponding output vector representation, and f(q,d) represents the q,d[CLS] of the BERT model represents the corresponding output vector representation, MLP(f(q,d)) represents the processing operation of f(q,d) using a multi-layer perceptron, and sim(q,d) represents the content similarity between the query case and the candidate case (depending on the actual scenario, the content similarity can be the first content similarity or the second content similarity).
[0090] Step 103, for each target candidate case, using the second largest language model, based on the case information of the query case to be processed, the case information of the target candidate case and the second prompt information, an analysis is performed to obtain the combined correct probability of the query case to be processed and the target candidate case, and based on the combined correct probability, a first degree of fit between the query case to be processed and the target candidate case is calculated.
[0091] In order to enable the second largest language model to more accurately infer the probability of correct combination between cases, second prompt information for the second largest language model is set, and the second prompt information is used to guide the second largest language model to compare and analyze the case information of the query case to be processed and the case information of the target candidate case, and obtain the correct probability of combination between the query case to be processed and the target candidate case. The specific content of the second prompt information can be set according to actual experience, and this embodiment does not limit this.
[0092] For each target candidate case, the second prompt information, the case information of the query case to be processed, and the case information of the target candidate case are concatenated to obtain the third input information, and the third input information is input into the second largest language model. Under the guidance of the second prompt information, the second largest language model compares and analyzes the case information of the query case to be processed and the case information of the target candidate case, and then outputs the third output information. The third output information includes the correct probability of the combination of the query case to be processed and the target candidate case.
[0093] Exemplarily, the process of calculating the first degree of fit between the query case to be processed and the target candidate case based on the combined correct probability may include: calculating the combined weight of the query case to be processed and the target candidate case based on the first content similarity between the query case to be processed and the target candidate case; and taking the product of the combined correct probability and the combined weight as the first degree of fit between the query case to be processed and the target candidate case.
[0094] The calculation formula for the probability of a correct combination is as follows:
[0095]
[0096] Among them, q represents the query case, d represents the candidate case, Indicates that the query case and the candidate case are spliced together. represents the probability of outputting the correct case when the query case and the candidate case are combined, that is, the correct probability of the combination of the query case and the candidate case, λ(d,q) represents the combined weight of the query case and the candidate case, P LM (y|d,q) represents the degree of fit between the query case and the candidate case (depending on the actual scenario, the degree of fit may be the first degree of fit or the second degree of fit).
[0097] The calculation formula of the combined weight is as follows:
[0098]
[0099] Where q represents the query case, d represents the candidate case, sim(q, d) represents the content similarity between the query case and the candidate case (calculated by the above formula 12), D′ represents the set of target candidate cases selected after the sorting model, and λ(d, q) represents the combined weight of the query case and the candidate case.
[0100] Next, the training process of the retrieval model is introduced.
[0101] In an optional implementation, the retrieval model is trained through the following steps C1 to C5:
[0102] Step C1, obtaining first sample data, wherein the first sample data includes second element information of a first sample query case, second element information of a positive sample case corresponding to the first sample query case, and second element information of a negative sample case corresponding to the first sample query case.
[0103] A plurality of query cases are obtained from an open source case library as first sample query cases, and the candidate cases most relevant to the first sample query cases are obtained as positive sample cases corresponding to the first sample query cases, and a plurality of candidate cases irrelevant to the first sample query cases are obtained as negative sample cases corresponding to the first sample query cases. Among them, the positive sample cases corresponding to the first sample query cases and the negative sample cases corresponding to the first sample query cases can be obtained by selection. The second element information of the first sample query case, the second element information of the positive sample cases corresponding to the first sample query cases, and the second element information of the negative sample cases corresponding to the first sample query cases are known data, or are obtained through the first large language model.
[0104] Step C2: adopting a comparative learning method, using the first sample data to train the initial recall model in the initial retrieval model, and calculating the loss function of the initial recall model.
[0105] In the process of training the initial recall model in the initial retrieval model using the first sample data, the second element information of the first sample query case and the second element information of the positive sample case are independently used as inputs of the initial recall model in the initial retrieval model to obtain the second element similarity between the first sample query case output by the initial recall model and the positive sample case. For each negative sample case, the second element information of the first sample query case and the second element information of the negative sample case are independently used as inputs of the initial recall model in the initial retrieval model to obtain the second element similarity between the first sample query case output by the initial recall model and the negative sample case.
[0106] The loss function of the initial recall model can be any applicable loss function, such as cross entropy loss function, classification loss function, etc.
[0107] For example, when the cross entropy loss is used to optimize the initial recall model, the loss function of the initial recall model can be calculated by the following formula 15:
[0108]
[0109] Among them, L re represents the loss function of the initial recall model, d + represents a positive sample case, d - Denotes negative sample cases, D - represents the set of negative sample cases, s(q,d + ) represents the similarity of the second factor between the first sample query case and the positive sample case, s(q,d - ) represents the similarity of the second factor between the first sample query case and the negative sample case, exp(s(q,d + ) represents the index of the similarity of the second factor between the first sample query case and the positive sample case, exp(s(q,d - ) represents the index of the similarity of the second factor between the first sample query case and the negative sample case.
[0110] Step C3, obtaining second sample data, where the second sample data includes case information of a second sample query case.
[0111] A plurality of query cases are obtained from an open source case library as second sample query cases, and case information of the second sample query cases is known data. The second sample query cases may be the same as or different from the first sample query cases.
[0112] Step C4: Use the second sample data to train the initial ranking model in the initial retrieval model, and calculate the loss function of the initial model.
[0113] Exemplarily, the process of training the initial ranking model in the initial retrieval model using the second sample data and calculating the loss function of the initial ranking model includes the following steps D1 to D4:
[0114] Step D1, using the second sample data to train an initial ranking model in an initial retrieval model to obtain sample target candidate cases related to the second sample query case.
[0115] In the process of training the initial ranking model in the initial retrieval model using the second sample data, element information of the second sample query case is obtained (the element information is known data, or obtained through the first language model), and based on the element information of the second sample query case and the case information of the second sample query case, a target candidate case related to the second sample query case is selected from the candidate cases.
[0116] Specifically, based on the first element information of the second sample query case, multiple candidate cases related to the second sample query case are selected from the candidate cases as the third candidate case; based on the second element information of the second sample query case, multiple third candidate cases related to the second sample query case are selected from the third candidate case using the initial recall model as the fourth candidate case; based on the case information of the second sample query case, the fourth candidate case is sorted using the initial sorting module, and multiple fourth candidate cases ranked first are selected as the sample target candidate cases. The specific process is basically the same as the above-mentioned processing process for the query case to be processed, and the relevant description above can be referred to.
[0117] Step D2, for each sample target candidate case, using the initial ranking model in the initial retrieval model, calculate the second content similarity between the second sample query case and the sample target candidate case, and calculate the first likelihood probability of the sample target candidate case based on the second content similarity.
[0118] The process of calculating the second content similarity between the second sample query case and the sample target candidate case using the initial ranking model in the initial retrieval model can refer to the relevant processing process for the query case to be processed above, and this embodiment will not be discussed in detail here.
[0119] The first likelihood probability of the sample target candidate case can be calculated by the following formula 16:
[0120]
[0121] Among them, P R(d|q) represents the first likelihood probability of the sample target candidate case corresponding to the second sample query case, sim(q,d) represents the second content similarity between the second sample query case and the sample target candidate case, γ represents the first temperature coefficient controlling the softmax function, and D′ represents the set of sample target candidate cases.
[0122] Step D3, for each sample target candidate case, using the second large language model, calculate the second degree of fit between the second sample query case and the sample target candidate case, and calculate the second likelihood probability of the sample target candidate case based on the second degree of fit.
[0123] The process of calculating the second degree of fit between the second sample query case and the sample target candidate case using the second largest language model can refer to the above-mentioned relevant processing process for the query case to be processed, which will not be discussed in detail in this embodiment.
[0124] The second likelihood probability of the sample target candidate case is calculated by the following formula 17:
[0125]
[0126] Among them, Q LM (d|q,y) represents the second likelihood probability of the sample target candidate case corresponding to the second sample query case, P LM (y|d,q) represents the second degree of fit between the second sample query case and the sample target candidate case, β represents the second temperature coefficient controlling the softmax function, and D′ represents the set of sample target candidate cases.
[0127] Step D4, calculating the divergence between the first likelihood probability and the second likelihood probability, and calculating the loss function of the initial sorting model based on the divergence.
[0128] In the embodiment of the present application, in order to improve the accuracy of the calculation results, KL (Kullback-Leibler) divergence can be used. KL divergence is a parameter that measures the difference between two probability distributions and is used to quantify the amount of information lost when one probability distribution is used to approximate another probability distribution.
[0129] The loss function of the initial sorting model can be calculated by the following formula 18:
[0130]
[0131] Among them, L rank represents the loss function of the initial sorting model, P R(d|q) represents the first likelihood probability of the sample target candidate case corresponding to the second sample query case, Q LM (d|q,y) represents the second likelihood probability of the sample target candidate case corresponding to the second sample query case, D′ represents the set of sample target candidate cases, KL(P R (d|q)||Q LM (d|q,y)) represents the KL divergence between the first likelihood probability and the second likelihood probability.
[0132] Figure 4 Schematic diagram of a sorting model training process in an embodiment of the present application. Figure 4 As shown, during the training of the sorting model, the element information of the second sample query case is obtained through the first language model. Through the processing of the recall model and the sorting model in the retrieval model, the sample target candidate cases (including sample target candidate case 1, sample target candidate case 2, sample target candidate case 3, etc.) can be obtained. The first likelihood probability and the second likelihood probability (calculated based on the second language model) are calculated for the sample target candidate cases respectively, and the KL divergence is calculated based on the first likelihood probability and the second likelihood probability. Finally, the loss function of the sorting model is calculated based on the KL divergence.
[0133] Step C5, taking the sum of the loss function of the initial recall model and the loss function of the initial sorting model as the comprehensive loss function of the initial retrieval model, and when the comprehensive loss function meets the preset conditions, taking the trained model as the retrieval model.
[0134] The comprehensive loss function of the initial retrieval model is calculated by the following formula 19:
[0135] L final =L rank +L re Formula 19
[0136] Among them, L final represents the comprehensive loss function of the initial retrieval model, L re represents the loss function of the initial recall model, L rank Represents the loss function of the initial ranking model.
[0137] When the comprehensive loss function of the initial retrieval model does not meet the second preset condition, it is determined that the training is not completed, and the parameters of the initial retrieval model are adjusted to continue training; when the comprehensive loss function of the initial retrieval model meets the second preset condition, it is determined that the training is completed, and the trained model is used as the retrieval model.
[0138] The second preset condition mentioned above may be that the comprehensive loss function of the initial retrieval model is less than a second preset threshold, or that the comprehensive loss function of the initial retrieval model reaches a minimum value, and so on.
[0139] Step 104 , selecting at least one target candidate case with the highest first degree of fit as a related case of the query case to be processed.
[0140] After obtaining the first degree of fit between the query case to be processed and each target candidate case, the target candidate cases are sorted in descending order of the first degree of fit, and at least one target candidate case ranked first is selected as a related case of the query case to be processed.
[0141] In the embodiment of the present application, compared with the method of simply using case information for comparison, the unique characteristics of the case are incorporated, so that the accuracy of similar case retrieval can be improved; and, based on the first degree of fit, related cases of the query case to be processed are selected, and the deep understanding ability of the second largest language model is further utilized to select more accurate related cases, thereby further improving the accuracy of similar case retrieval.
[0142] In an optional implementation, after obtaining the related cases of the pending query case, the third language model can be used to analyze the case information of the pending query case, the case information of the related cases of the pending query case and the third prompt information to obtain a similarity analysis report between the pending query case and the related cases. The similarity analysis report can more clearly and accurately show the similarity between the pending query case and the related cases, aiming to provide professionals with in-depth insights into the case.
[0143] In order to enable the third language model to more accurately infer the similarity analysis report between cases, a third prompt information for the third language model is set, and the third prompt information is used to guide the third language model to compare and analyze the case information of the query case to be processed and the case information of the related cases of the query case to be processed, so as to obtain the similarity analysis report of the query case to be processed and the target candidate case. The specific content of the third prompt information is not limited in this embodiment.
[0144] By constructing the third prompt information, the third language model can focus on the comparison of case elements and effectively compare the similarities and differences between the query case and related cases in key case elements.
[0145] For example, a possible third prompt information may be shown in the following table:
[0146] Prompt information table
[0147]
[0148]
[0149] Among them, the case's charge (cause), article (applicable rules), focus (dispute focus), result (judgment result), and fact (basic facts) information are inferred by the third language model, and the relevant case itself has these attributes.
[0150] For each related case of the query case to be processed, the third prompt information, the case information of the query case to be processed, and the case information of the related case are spliced to obtain fourth input information, and the fourth input information is input into the third largest language model. Under the guidance of the fourth prompt information, the third largest language model compares and analyzes the case information of the query case to be processed and the case information of the related case, and then outputs fourth output information. The fourth output information includes a similarity analysis report between the query case to be processed and the target candidate case.
[0151] On the one hand, in the embodiments of the present application, a large language model is innovatively used to infer the element information of the case before the retrieval process. This information is applied to the retrieval process as a basis for auxiliary matching. Compared with the method of relying solely on case information for retrieval, this strategy greatly enhances the matching degree and relevance of the retrieval results and optimizes the retrieval process. The similar case retrieval process is designed around the element information and case information of the case, and the accuracy and efficiency of case retrieval are improved by constructing a recall model and a re-ranking model. The recall model is responsible for retrieving candidate cases with similar judgments from the case library based on the element information of the query case. The sorting model analyzes the semantic information between the retrieved candidate cases and the query case and performs deep learning to sort the candidate cases to ensure that the candidate cases with higher relevance are ranked first.
[0152] On the other hand, in the embodiment of the present application, considering the input length limitation of the large language model, it is impossible to add too many documents at one time, and a new integration solution is proposed: use the large language model to evaluate the contribution of each candidate case to reducing the model perplexity, so as to select the candidate case that is most helpful to the retrieval results, and solve the problem of limited context length of the large language model.
[0153] On the other hand, in an embodiment of the present application, a training scheme is introduced, which uses the supervisory signal provided by the large language model to further adjust the retrieval model. Different from the previous method of adapting the large language model to the retrieval model, the present application aims to adapt the retrieval model to the large language model so that the model can make better predictions.
[0154] Reference Figure 5 , showing a structural block diagram of a similar case retrieval device according to an embodiment of the present application.
[0155] like Figure 5 As shown, the similar case retrieval device may include the following modules:
[0156] The first analysis module 501 is used to use the first language model to analyze the case information of the query case to be processed and the first prompt information to obtain the element information of the query case to be processed;
[0157] A first selection module 502, configured to select a target candidate case related to the query case to be processed from candidate cases based on the element information of the query case to be processed and the case information of the query case to be processed;
[0158] The second analysis module 503 is used to analyze each target candidate case using the second largest language model based on the case information of the query case to be processed, the case information of the target candidate case and the second prompt information, obtain the combined correct probability of the query case to be processed and the target candidate case, and calculate the first degree of fit between the query case to be processed and the target candidate case based on the combined correct probability;
[0159] The second selection module 504 is used to select at least one target candidate case with the highest first degree of fit as a related case of the query case to be processed.
[0160] Optionally, the device also includes: a third analysis module, which is used to use a third language model to perform analysis based on the case information of the query case to be processed, the case information of the related cases and the third prompt information to obtain a similarity analysis report between the query case to be processed and the related cases.
[0161] Optionally, the element information includes first element information and second element information; the first selection module 502 includes: a first selection submodule, used to select multiple candidate cases related to the query case to be processed from the candidate cases as first candidate cases based on the first element information of the query case to be processed; a second selection submodule, used to select multiple first candidate cases related to the query case to be processed from the first candidate cases as second candidate cases based on the second element information of the query case to be processed; a third selection submodule, used to sort the second candidate cases based on the case information of the query case to be processed, and select multiple second candidate cases ranked first as the target candidate cases.
[0162] Optionally, the first selection submodule includes: a first calculation unit, used to calculate, for each candidate case, the first element overlap between the query case to be processed and the candidate case based on the first element information of the query case to be processed and the first element information of the candidate case; and a first determination unit, used to select multiple candidate cases from the candidate cases as the first candidate cases according to the first element overlap.
[0163] Optionally, the first element information includes violation type information and applicable rule information; the first calculation unit is specifically used to calculate the violation type overlap between the query case to be processed and the candidate case based on the violation type information of the query case to be processed and the violation type information of the candidate case; calculate the applicable rule overlap between the query case to be processed and the candidate case based on the applicable rule information of the query case to be processed and the applicable rule information of the candidate case; and use the product of the violation type overlap and the applicable rule overlap as the first element overlap between the query case to be processed and the candidate case.
[0164] Optionally, the second selection submodule includes: a second calculation unit, used to calculate, for each first candidate case, the first element similarity between the query case to be processed and the first candidate case based on the second element information of the query case to be processed and the second element information of the first candidate case; a second determination unit, used to select multiple first candidate cases from the first candidate cases as the second candidate cases according to the first element similarity.
[0165] Optionally, the second computing unit is specifically used to independently use the second element information of the query case to be processed and the second element information of the first candidate case as inputs of a recall model in a pre-trained retrieval model, and obtain the first element similarity between the query case to be processed and the first candidate case output by the recall model.
[0166] Optionally, the third selection submodule includes: a third calculation unit, used to calculate, for each second candidate case, the first content similarity between the query case to be processed and the second candidate case based on the case information of the query case to be processed and the case information of the second candidate case; and a sorting unit, used to sort the second candidate cases in descending order of the first content similarity.
[0167] Optionally, the third computing unit is specifically used to splice the case information of the query case to be processed and the case information of the second candidate case to obtain spliced case information, and use the spliced case information as the input of the sorting model in the pre-trained retrieval model to obtain the first content similarity between the query case to be processed and the second candidate case output by the sorting model.
[0168] Optionally, the retrieval model is trained in the following manner: obtaining first sample data, the first sample data including the second element information of the first sample query case, the second element information of the positive sample case corresponding to the first sample query case, and the second element information of the negative sample case corresponding to the first sample query case; adopting a comparative learning method, using the first sample data to train the initial recall model in the initial retrieval model, and calculating the loss function of the initial recall model; obtaining second sample data, the second sample data including the case information of the second sample query case; using the second sample data to train the initial ranking model in the initial retrieval model, and calculating the loss function of the initial ranking model; taking the sum of the loss function of the initial recall model and the loss function of the initial ranking model as the comprehensive loss function of the initial retrieval model, and when the comprehensive loss function meets the preset conditions, taking the trained model as the retrieval model.
[0169] Optionally, the using the second sample data to train the initial ranking model in the initial retrieval model and calculating the loss function of the initial ranking model includes: using the second sample data to train the initial ranking model in the initial retrieval model to obtain sample target candidate cases related to the second sample query case; for each sample target candidate case, using the initial ranking model in the initial retrieval model, calculating the second content similarity between the second sample query case and the sample target candidate case, and calculating the first likelihood probability of the sample target candidate case based on the second content similarity; for each sample target candidate case, using the second large language model, calculating the second degree of fit between the second sample query case and the sample target candidate case, and calculating the second likelihood probability of the sample target candidate case based on the second degree of fit; calculating the divergence between the first likelihood probability and the second likelihood probability, and calculating the loss function of the initial ranking model based on the divergence.
[0170] Optionally, the second analysis module 503 is specifically used to calculate the combined weight of the query case to be processed and the target candidate case based on the first content similarity between the query case to be processed and the target candidate case; and use the product of the combined correct probability and the combined weight as the first degree of fit between the query case to be processed and the target candidate case.
[0171] Optionally, the first large language model is trained in the following manner: obtaining third sample data, the third sample data including case information of a sample candidate case and actual element information of the sample candidate case; using the first initial large language model, analyzing based on the case information of the sample candidate case and the first prompt information to obtain predicted element information of the sample candidate case; judging whether the training of the first initial large language model is completed based on the actual element information and the predicted element information, and after the training is completed, using the trained model as the first large language model.
[0172] In the embodiment of the present application, considering that the element information of a case belongs to the unique characteristics of a case, the element information of a case can provide a summary description of the case. Therefore, the first largest language model is first used to infer the element information of the query case to be processed, and then based on the element information of the query case to be processed and the case information of the query case to be processed, a target candidate case related to the query case to be processed is selected from the candidate cases. Compared with the method of simply using case information for comparison, the unique characteristics of the case are incorporated, so that the accuracy of similar case retrieval can be improved; and, the second largest language model is used to infer the first degree of fit between the query case to be processed and the target candidate case, and the related cases of the query case to be processed are selected according to the first degree of fit, and the deep understanding ability of the second largest language model is further used to select more accurate related cases, thereby further improving the accuracy of similar case retrieval.
[0173] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0174] In an embodiment of the present application, an electronic device is also provided. The electronic device may include a processor and a computer-readable storage medium, wherein a computer program is stored on the computer-readable storage medium; when the computer program is executed by the processor, the processor executes the similar case retrieval method of any of the above embodiments.
[0175] Reference Figure 6 , shows a structural block diagram of an electronic device according to an embodiment of the present application. Figure 6 As shown, the electronic device 60 includes a processor 601 and a computer-readable storage medium 602 , on which a computer program 6021 is stored.
[0176] Processor 601 is used to execute computer program 6021 stored on computer-readable storage medium 602. When executing computer program 6021, processor 601 implements the similar case retrieval method of any of the above-mentioned embodiments and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0177] The processor 601 mentioned above may include but is not limited to: a central processing unit (CPU), a network processor (NP), a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
[0178] The computer-readable storage medium 602 mentioned above may include but is not limited to: read-only memory (ROM), random access memory (RAM), compact disc read-only memory (CD-ROM), electronic erasable programmable read-only memory (EEPROM), hard disk, floppy disk, flash memory, etc.
[0179] In an embodiment of the present application, a computer-readable storage medium is further provided, on which a computer program is stored. The computer program can be executed by a processor of an electronic device. When the computer program is executed by the processor, the processor executes the similar case retrieval method described in any of the above embodiments.
[0180] Reference Figure 7 , shows a block diagram of a computer-readable storage medium according to an embodiment of the present application. Figure 7 As shown, a computer program 701 is stored on a computer-readable storage medium 70. When the computer program 701 is executed by a processor, the processor executes a similar case retrieval method as described in any of the above embodiments and can achieve the same technical effect. To avoid repetition, it will not be described here.
[0181] The various embodiments in this specification are interrelated, and each embodiment is described in a progressive manner. Each embodiment focuses on the differences from other embodiments, and the same or similar parts between the various embodiments can be referenced to each other.
[0182] It should be noted that all actions to obtain signals, information or data in this application are carried out in compliance with the relevant data protection laws and policies of the location and with the authorization given by the owner of the corresponding device.
[0183] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise one..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0184] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application.
[0185] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
[0186] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed in the present application can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0187] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0188] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0189] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0190] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. In summary, the content of this specification should not be understood as limiting the present application.
Claims
1. A similar case retrieval method, characterized in that: The method comprises: Using the first language model, analyzing based on the case information of the query case to be processed and the first prompt information, to obtain element information of the query case to be processed; Based on the element information of the query case to be processed and the case information of the query case to be processed, selecting a target candidate case related to the query case to be processed from the candidate cases; For each target candidate case, using the second largest language model, based on the case information of the query case to be processed, the case information of the target candidate case and the second prompt information, an analysis is performed to obtain a combined correct probability of the query case to be processed and the target candidate case, and a first degree of fit between the query case to be processed and the target candidate case is calculated based on the combined correct probability; At least one target candidate case with the highest first degree of fit is selected as a related case of the query case to be processed.
2. The method according to claim 1, characterized in that The method further comprises: By using the third language model, an analysis is performed based on the case information of the query case to be processed, the case information of the related cases and the third prompt information to obtain a similarity analysis report between the query case to be processed and the related cases.
3. The method according to claim 1, characterized in that The element information includes first element information and second element information; the selecting a target candidate case related to the query case to be processed from the candidate cases based on the element information of the query case to be processed and the case information of the query case to be processed includes: Based on the first element information of the query case to be processed, selecting multiple candidate cases related to the query case to be processed from the candidate cases as first candidate cases; Based on the second element information of the query case to be processed, selecting a plurality of first candidate cases related to the query case to be processed from the first candidate cases as second candidate cases; Based on the case information of the query case to be processed, the second candidate cases are ranked, and a plurality of second candidate cases ranked first are selected as the target candidate cases.
4. The method according to claim 3, characterized in that The selecting, based on the first element information of the query case to be processed, a plurality of candidate cases related to the query case to be processed from the candidate cases as first candidate cases includes: For each candidate case, based on the first element information of the query case to be processed and the first element information of the candidate case, calculate the first element overlap between the query case to be processed and the candidate case; A plurality of candidate cases are selected from the candidate cases according to the first element overlap degree as the first candidate cases.
5. The method according to claim 4, characterized in that The first element information includes violation type information and applicable rule information; the first element overlap degree between the query case to be processed and the candidate case is calculated based on the first element information of the query case to be processed and the first element information of the candidate case, including: Based on the violation type information of the pending query case and the violation type information of the candidate case, calculating the degree of violation type overlap between the pending query case and the candidate case; Based on the applicable rule information of the query case to be processed and the applicable rule information of the candidate case, calculating the applicable rule overlap between the query case to be processed and the candidate case; The product of the violation type overlap degree and the applicable rule overlap degree is used as the first element overlap degree between the query case to be processed and the candidate case.
6. The method according to claim 3, characterized in that The selecting, based on the second element information of the query case to be processed, a plurality of first candidate cases related to the query case to be processed from the first candidate cases as second candidate cases includes: For each first candidate case, based on the second element information of the query case to be processed and the second element information of the first candidate case, calculating the first element similarity between the query case to be processed and the first candidate case; A plurality of first candidate cases are selected from the first candidate cases according to the first factor similarity as the second candidate cases.
7. The method according to claim 6, characterized in that The calculating the first element similarity between the query case to be processed and the first candidate case based on the second element information of the query case to be processed and the second element information of the first candidate case includes: The second element information of the query case to be processed and the second element information of the first candidate case are independently used as inputs of a recall model in a pre-trained retrieval model to obtain the first element similarity between the query case to be processed and the first candidate case output by the recall model.
8. The method according to claim 3, characterized in that The step of sorting the second candidate cases based on the case information of the pending query cases includes: For each second candidate case, based on the case information of the query case to be processed and the case information of the second candidate case, calculating a first content similarity between the query case to be processed and the second candidate case; The second candidate cases are sorted in descending order of the first content similarity.
9. The method according to claim 8, characterized in that The calculating, based on the case information of the query case to be processed and the case information of the second candidate case, the first content similarity between the query case to be processed and the second candidate case includes: The case information of the query case to be processed and the case information of the second candidate case are spliced to obtain spliced case information, and the spliced case information is used as the input of the ranking model in the pre-trained retrieval model to obtain the first content similarity between the query case to be processed and the second candidate case output by the ranking model.
10. The method according to claim 7 or 9, characterized in that: The retrieval model is trained in the following way: Acquire first sample data, the first sample data including second element information of a first sample query case, second element information of a positive sample case corresponding to the first sample query case, and second element information of a negative sample case corresponding to the first sample query case; Using a contrastive learning method, the first sample data is used to train an initial recall model in an initial retrieval model, and a loss function of the initial recall model is calculated; Acquire second sample data, where the second sample data includes case information of a second sample query case; Using the second sample data to train an initial ranking model in the initial retrieval model, and calculating a loss function of the initial ranking model; The sum of the loss function of the initial recall model and the loss function of the initial ranking model is used as the comprehensive loss function of the initial retrieval model. When the comprehensive loss function meets the preset conditions, the trained model is used as the retrieval model.
11. The method according to claim 10, characterized in that The using the second sample data to train an initial ranking model in the initial retrieval model and calculating a loss function of the initial ranking model includes: Using the second sample data to train an initial ranking model in an initial retrieval model, to obtain sample target candidate cases related to the second sample query case; For each sample target candidate case, using the initial ranking model in the initial retrieval model, calculate the second content similarity between the second sample query case and the sample target candidate case, and calculate the first likelihood probability of the sample target candidate case based on the second content similarity; For each sample target candidate case, using the second largest language model, calculate a second degree of fit between the second sample query case and the sample target candidate case, and calculate a second likelihood probability of the sample target candidate case based on the second degree of fit; A divergence between the first likelihood probability and the second likelihood probability is calculated, and a loss function of the initial sorting model is calculated based on the divergence.
12. The method according to claim 1, characterized in that The calculating the first degree of fit between the query case to be processed and the target candidate case based on the combined correct probability includes: Calculating a combined weight of the query case to be processed and the target candidate case based on a first content similarity between the query case to be processed and the target candidate case; The product of the combined correct probability and the combined weight is used as the first degree of fit between the query case to be processed and the target candidate case.
13. The method according to claim 1, characterized in that The first language model is trained as follows: Acquire third sample data, wherein the third sample data includes case information of sample candidate cases and actual element information of the sample candidate cases; Using the first initial large language model, analyzing based on the case information of the sample candidate case and the first prompt information, to obtain prediction factor information of the sample candidate case; Based on the actual element information and the predicted element information, it is determined whether the first initial large language model has been trained. After the training is completed, the trained model is used as the first large language model.
14. A similar case retrieval device, characterized in that: The device comprises: A first analysis module, configured to use a first language model to analyze the case information of the query case to be processed and the first prompt information to obtain element information of the query case to be processed; A first selection module, configured to select a target candidate case related to the query case to be processed from the candidate cases based on the element information of the query case to be processed and the case information of the query case to be processed; A second analysis module is used to analyze, for each target candidate case, using the second largest language model based on the case information of the query case to be processed, the case information of the target candidate case and the second prompt information, to obtain a combined correct probability of the query case to be processed and the target candidate case, and calculate a first degree of fit between the query case to be processed and the target candidate case based on the combined correct probability; The second selection module is used to select at least one target candidate case with the highest first degree of fit as a related case of the query case to be processed.
15. An electronic device, characterized in that: The electronic device comprises a processor and a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program; When the computer program is executed by the processor, the processor executes the similar case retrieval method according to any one of claims 1 to 13.
16. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor executes the similar case retrieval method according to any one of claims 1 to 13.
Citation Information
Cited By
Class case retrieval method, device and equipment based on large language model and vector retrieval
CN122262205A