Text encoding model training method, case search method, device and electronic equipment

By introducing unsupervised contrastive learning into the text encoding model in the legal field and training the model using case feature relevance scores, the problem of lack of legal knowledge in existing legal pre-trained models is solved, and the accuracy of similar case retrieval is improved.

CN116340464BActive Publication Date: 2025-12-30TSINGHUA UNIVERSITY
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310369775.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-04-07
Publication Date
2025-12-30
Estimated Expiration
2043-04-07

AI Technical Summary

Technical Problem

Existing pre-trained language models in the legal field lack legal knowledge, resulting in low accuracy in case retrieval tasks, and also lack high-quality manually labeled data.

Method used

By acquiring case information from the training dataset, encoding it using a text encoding model, determining the case feature set, and training the model based on the relevance scores of the case features, legal knowledge is introduced for unsupervised comparative learning to improve the model's performance in the legal field.

Benefits of technology

The trained text encoding model can learn legal knowledge from unlabeled datasets, significantly improving performance in case retrieval tasks and outputting high-quality case features.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116340464B_ABST
    Figure CN116340464B_ABST
Patent Text Reader

Abstract

The present disclosure relates to a text encoding model training method, a case search method, a device and an electronic device. The text encoding model training method comprises: obtaining a training data set, the training data set comprising case information of a plurality of query cases and case information of positive cases and negative cases; encoding the case information in the training data set using a text encoding model to obtain a case feature set corresponding to the training data set; determining a first correlation score between each query case and a corresponding positive case and a second correlation score between each query case and a corresponding negative case according to the case feature set; determining a contrast learning loss according to the first correlation score and the second correlation score and training the text encoding model based on the contrast learning loss. According to the present disclosure, the text encoding model can learn legal knowledge from the unannotated training data set, thereby improving the performance of the trained text encoding model in the legal field downstream task.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of computer technology, and in particular to a text encoding model training method, a case retrieval method, an apparatus, and an electronic device. Background Technology

[0002] The definition of case retrieval is: given a case as a query, searching and returning similar cases related to the query from a set of adjudicated cases. Similar cases (classic cases) usually refer to cases with the same or similar essential facts or circumstances. For the modern judicial system, case retrieval is of great significance in ensuring consistent judgments in similar cases and promoting judicial fairness, as similar cases can serve as a reference for adjudicating cases.

[0003] Currently, the retrieval method in the general domain is to use a large language model with hundreds of millions of parameters for retrieval. However, due to the large number of parameters in the large language model, this method requires a massive amount of data for training. However, the data annotation cost in the legal domain is much higher than that in the general domain. Annotators need to have legal knowledge or even expert knowledge to effectively annotate the data. Therefore, the legal domain still lacks high-quality manually annotated data, and the existing data scale is far from sufficient to train a large language model.

[0004] To address the lack of manually labeled data in the legal field, pre-trained language models (PLMs) have become a research hotspot in this area. However, existing pre-trained language models in the legal field completely adopt the pre-training tasks commonly used in the field of natural language processing without making any modifications for the legal domain. Therefore, existing pre-trained language models still lack legal knowledge and perform poorly in downstream tasks in the legal field, such as having low accuracy in case retrieval tasks. Summary of the Invention

[0005] In view of this, this disclosure proposes a text encoding model training method, a case retrieval method, a device, and an electronic device that can train a text encoding model to learn legal knowledge from an unlabeled training dataset, thereby significantly improving the performance of the trained text encoding model in downstream tasks in the legal field (such as case retrieval).

[0006] According to one aspect of this disclosure, a method for training a text encoding model is provided, comprising: acquiring a training dataset, the training dataset including case information of multiple query cases, and case information of positive and negative cases corresponding to each query case, wherein positive and negative cases are determined based on case judgment information and case information, and the correlation between each query case and its corresponding positive case is higher than the correlation between each query case and its corresponding negative case; encoding the case information in the training dataset using a text encoding model to obtain a case feature set corresponding to the training dataset; determining a first correlation score between each query case and its corresponding positive case, and a second correlation score between each query case and its corresponding negative case, based on the case feature set corresponding to the training dataset; determining a contrastive learning loss based on the first correlation score and the second correlation score, and training the text encoding model based on the contrastive learning loss.

[0007] In one possible implementation, obtaining the training dataset includes: obtaining case information and judgment information of multiple cases in a preset case database, wherein the case information includes factual descriptions; taking each case in the preset case database as a query case, and determining a first case set corresponding to each query case from the preset case database based on the text similarity between the case information of each query case and the case information of each case in the preset case database, wherein the first case set includes multiple cases with similar factual descriptions to the query case; for each query case corresponding to the first case set, taking cases in the first case set that have the same judgment information as each query case as positive cases corresponding to each query case, and taking cases in the first case set that have different judgment information from each query case as negative cases corresponding to each query case.

[0008] In one possible implementation, acquiring the training dataset includes: acquiring case information and judgment information of multiple cases in a preset case database; using each case in the preset case database as a query case, and determining a second case set corresponding to each query case from the preset case database based on the overlap between the judgment information of each query case and the judgment information of each case in the preset case database, wherein the second case set includes multiple cases with similar judgments to the query case; and determining positive and negative cases corresponding to each query case from the second case set corresponding to each query case based on the text similarity between the case information of each query case and the case information of each case in the second case set corresponding to each query case, wherein the text similarity corresponding to positive cases is higher than the text similarity corresponding to negative cases.

[0009] In one possible implementation, the judgment information includes the legal provisions and charges involved in the case. The step of determining the second case set corresponding to each queried case from the preset case database based on the overlap between the judgment information of each queried case and the judgment information of each case in the preset case database includes: determining the overlapping legal provisions between each queried case and each case in the preset case database based on the legal provisions involved in each case; determining the overlap between the legal provisions between each queried case and each case in the preset case database based on the frequency of occurrence of the overlapping legal provisions in the preset case database; determining the overlap between the charges between each queried case and each case in the preset case database based on the charges involved in each case; determining a similarity score between each queried case and each case in the preset case database based on the overlap of legal provisions and the overlap of charges; and determining the second case set corresponding to each queried case from the preset case database based on the similarity score.

[0010] In one possible implementation, determining the positive and negative cases corresponding to each query case from the second case set corresponding to each query case based on the text similarity between the case information of each query case and the case information of each case in the second case set corresponding to each query case includes: for any query case and the corresponding second case set, sorting multiple cases in the second case set in reverse or forward order based on the text similarity between the case information of the query case and the case information of each case in the corresponding second case set to obtain a reverse or forward sorting result; taking the first n cases in the reverse sorting result as the positive cases of the query case, and taking the last m cases in the reverse sorting result as the negative cases of the query case, where n and m are positive integers; or, taking the first n cases in the forward sorting result as the negative cases of the query case, and taking the last m cases in the forward sorting result as the positive cases of the query case.

[0011] In one possible implementation, encoding the case information in the training dataset using a text encoding model to obtain a case feature set corresponding to the training dataset includes: inputting the case information of query cases, positive cases, and negative cases in the training dataset into the text encoding model for encoding to obtain case features corresponding to each query case, positive case, and negative case in the training dataset. The case feature set includes the case features corresponding to each query case, positive case, and negative case in the training dataset. The step of determining a first correlation score between each query case and its corresponding positive case, and a second correlation score between each query case and its corresponding negative case, based on the case feature set corresponding to the training dataset, includes: determining a first correlation score between each query case and its corresponding positive case based on the case features of each query case and the case features of the corresponding positive case; and determining a second correlation score between each query case and its corresponding negative case based on the case features of each query case and the case features of the corresponding negative case.

[0012] In one possible implementation, the step of encoding the case information in the training dataset using a text encoding model to obtain a case feature set corresponding to the training dataset includes: inputting the case information of each query case and the case information of the corresponding positive case into the text encoding model for encoding to obtain a first case feature between each query case and the corresponding positive case; inputting the case information of each query case and the case information of the corresponding negative case into the text encoding model for encoding to obtain a second case feature between each query case and the corresponding negative case; wherein the case feature set includes the first case feature between each query case and the corresponding positive case and the second case feature between each query case and the corresponding negative case; wherein, the step of determining a first correlation score between each query case and the corresponding positive case and a second correlation score between each query case and the corresponding negative case based on the case feature set corresponding to the training dataset includes: determining a first correlation score between each query case and the corresponding positive case based on the first case feature between each query case and the corresponding positive case; determining a second correlation score between each query case and the corresponding negative case based on the second case feature between each query case and the corresponding negative case.

[0013] In one possible implementation, the method further includes: pre-training the text encoding model using multiple legal documents in a legal corpus, wherein the legal documents include at least one of the following: official documents in the legal field, judgments; wherein, the pre-training of the text encoding model using the legal corpus includes: based on a preset masking ratio, masking some real words in each legal document to obtain masked legal documents, and encoding the masked legal documents using the text encoding model to obtain document features corresponding to the masked legal documents; predicting the masked real words in the masked legal documents based on the document features corresponding to the masked legal documents to obtain predicted words corresponding to the masked legal documents; determining the masking language loss based on the predicted words corresponding to the masked legal documents and the masked real words in the masked legal documents, and training the text encoding model based on the masking language loss.

[0014] According to another aspect of this disclosure, a method for retrieving similar cases is provided, comprising: obtaining case information of a target case to be retrieved; encoding the case information of the target case using a first text encoding model to obtain case features corresponding to the target case, wherein the first text encoding model is trained by the text encoding model training method; and determining similar cases of the target case from the target case database based on the case features corresponding to the target case and the case features of multiple adjudicated cases in the target case database.

[0015] In one possible implementation, determining similar cases from the target case database based on the case features corresponding to the target case and the case features of multiple adjudicated cases in the target case database includes: determining multiple initial similar cases corresponding to the target case from the target case database based on the case features corresponding to the target case and the case features of multiple adjudicated cases in the target case database; inputting the case information of each initial similar case and the case information of the target case into a second text encoding model for encoding to obtain the case features between each initial similar case and the target case, wherein the second text encoding model is trained using the text encoding model training method; and determining similar cases from the multiple initial similar cases based on the case features between each initial similar case and the target case.

[0016] According to another aspect of this disclosure, a text encoding model training apparatus is provided, comprising: an acquisition module for acquiring a training dataset, the training dataset including case information of multiple query cases, and case information of positive and negative cases corresponding to each query case, wherein positive and negative cases are determined based on case judgment information and case information, and the correlation between each query case and its corresponding positive case is higher than the correlation between each query case and its corresponding negative case; an encoding module for encoding the case information in the training dataset using a text encoding model to obtain a case feature set corresponding to the training dataset; a determination module for determining a first correlation score between each query case and its corresponding positive case, and a second correlation score between each query case and its corresponding negative case, based on the case feature set corresponding to the training dataset; and a training module for determining a contrastive learning loss based on the first correlation score and the second correlation score, and training the text encoding model based on the contrastive learning loss.

[0017] In one possible implementation, obtaining the training dataset includes: obtaining case information and judgment information of multiple cases in a preset case database, wherein the case information includes factual descriptions; taking each case in the preset case database as a query case, and determining a first case set corresponding to each query case from the preset case database based on the text similarity between the case information of each query case and the case information of each case in the preset case database, wherein the first case set includes multiple cases with similar factual descriptions to the query case; for each query case corresponding to the first case set, taking cases in the first case set that have the same judgment information as each query case as positive cases corresponding to each query case, and taking cases in the first case set that have different judgment information from each query case as negative cases corresponding to each query case.

[0018] In one possible implementation, acquiring the training dataset includes: acquiring case information and judgment information of multiple cases in a preset case database; using each case in the preset case database as a query case, and determining a second case set corresponding to each query case from the preset case database based on the overlap between the judgment information of each query case and the judgment information of each case in the preset case database, wherein the second case set includes multiple cases with similar judgments to the query case; and determining positive and negative cases corresponding to each query case from the second case set corresponding to each query case based on the text similarity between the case information of each query case and the case information of each case in the second case set corresponding to each query case, wherein the text similarity corresponding to positive cases is higher than the text similarity corresponding to negative cases.

[0019] In one possible implementation, the judgment information includes the legal provisions and charges involved in the case. The step of determining the second case set corresponding to each queried case from the preset case database based on the overlap between the judgment information of each queried case and the judgment information of each case in the preset case database includes: determining the overlapping legal provisions between each queried case and each case in the preset case database based on the legal provisions involved in each case; determining the overlap between the legal provisions between each queried case and each case in the preset case database based on the frequency of occurrence of the overlapping legal provisions in the preset case database; determining the overlap between the charges between each queried case and each case in the preset case database based on the charges involved in each case; determining a similarity score between each queried case and each case in the preset case database based on the overlap of legal provisions and the overlap of charges; and determining the second case set corresponding to each queried case from the preset case database based on the similarity score.

[0020] In one possible implementation, determining the positive and negative cases corresponding to each query case from the second case set corresponding to each query case based on the text similarity between the case information of each query case and the case information of each case in the second case set corresponding to each query case includes: for any query case and the corresponding second case set, sorting multiple cases in the second case set in reverse or forward order based on the text similarity between the case information of the query case and the case information of each case in the corresponding second case set to obtain a reverse or forward sorting result; taking the first n cases in the reverse sorting result as the positive cases of the query case, and taking the last m cases in the reverse sorting result as the negative cases of the query case, where n and m are positive integers; or, taking the first n cases in the forward sorting result as the negative cases of the query case, and taking the last m cases in the forward sorting result as the positive cases of the query case.

[0021] In one possible implementation, encoding the case information in the training dataset using a text encoding model to obtain a case feature set corresponding to the training dataset includes: inputting the case information of query cases, positive cases, and negative cases in the training dataset into the text encoding model for encoding to obtain case features corresponding to each query case, positive case, and negative case in the training dataset. The case feature set includes the case features corresponding to each query case, positive case, and negative case in the training dataset. The step of determining a first correlation score between each query case and its corresponding positive case, and a second correlation score between each query case and its corresponding negative case, based on the case feature set corresponding to the training dataset, includes: determining a first correlation score between each query case and its corresponding positive case based on the case features of each query case and the case features of the corresponding positive case; and determining a second correlation score between each query case and its corresponding negative case based on the case features of each query case and the case features of the corresponding negative case.

[0022] In one possible implementation, the step of encoding the case information in the training dataset using a text encoding model to obtain a case feature set corresponding to the training dataset includes: inputting the case information of each query case and the case information of the corresponding positive case into the text encoding model for encoding to obtain a first case feature between each query case and the corresponding positive case; inputting the case information of each query case and the case information of the corresponding negative case into the text encoding model for encoding to obtain a second case feature between each query case and the corresponding negative case; wherein the case feature set includes the first case feature between each query case and the corresponding positive case and the second case feature between each query case and the corresponding negative case; wherein, the step of determining a first correlation score between each query case and the corresponding positive case and a second correlation score between each query case and the corresponding negative case based on the case feature set corresponding to the training dataset includes: determining a first correlation score between each query case and the corresponding positive case based on the first case feature between each query case and the corresponding positive case; determining a second correlation score between each query case and the corresponding negative case based on the second case feature between each query case and the corresponding negative case.

[0023] In one possible implementation, the apparatus further includes: a masked language training module, used to pre-train the text encoding model using multiple legal documents in a legal corpus, wherein the legal documents include at least one of the following: official documents in the legal field, judgments; wherein, the pre-training of the text encoding model using the legal corpus includes: masking some real words in each legal document based on a preset masking ratio to obtain masked legal documents, and encoding the masked legal documents using the text encoding model to obtain document features corresponding to the masked legal documents; predicting the masked real words in the masked legal documents based on the document features corresponding to the masked legal documents to obtain predicted words corresponding to the masked legal documents; determining the masked language loss based on the predicted words corresponding to the masked legal documents and the masked real words in the masked legal documents, and training the text encoding model based on the masked language loss.

[0024] According to another aspect of this disclosure, a case retrieval device is provided, comprising: an information acquisition module for acquiring case information of a target case to be retrieved; an information encoding module for encoding the case information of the target case using a first text encoding model to obtain case features corresponding to the target case, wherein the first text encoding model is trained by the text encoding model training method; and a case determination module for determining similar cases of the target case from the target case database based on the case features corresponding to the target case and the case features of multiple adjudicated cases in the target case database.

[0025] In one possible implementation, determining similar cases from the target case database based on the case features corresponding to the target case and the case features of multiple adjudicated cases in the target case database includes: determining multiple initial similar cases corresponding to the target case from the target case database based on the case features corresponding to the target case and the case features of multiple adjudicated cases in the target case database; inputting the case information of each initial similar case and the case information of the target case into a second text encoding model for encoding to obtain the case features between each initial similar case and the target case, wherein the second text encoding model is trained using the text encoding model training method; and determining similar cases from the multiple initial similar cases based on the case features between each initial similar case and the target case.

[0026] According to another aspect of this disclosure, an electronic device is provided, comprising: a processor; a memory for storing processor-executable instructions; wherein the processor is configured to implement the above-described method when executing instructions stored in the memory.

[0027] According to another aspect of this disclosure, a non-volatile computer-readable storage medium is provided that stores computer program instructions thereon, wherein the computer program instructions, when executed by a processor, implement the above-described method.

[0028] According to another aspect of this disclosure, a computer program product is provided, including computer-readable code, or a non-volatile computer-readable storage medium carrying computer-readable code, wherein when the computer-readable code is run in a processor of an electronic device, the processor in the electronic device performs the above-described method.

[0029] According to embodiments of this disclosure, by determining the contrastive learning loss based on a first relevance score between the query case and positive cases and a second relevance score between the query case and negative cases, the text encoding model can be trained to bring the case features between the query case and positive cases closer together and push the case features between the query case and negative cases further apart. Since positive and negative cases are determined based on the judgment information and case information of the cases, this is equivalent to introducing legal knowledge to train the text encoding model. This enables the text encoding model to learn the relevance between cases in the legal field, that is, to train the text encoding model to learn legal knowledge from unlabeled training datasets, thereby achieving unsupervised contrastive learning as a whole. This allows the trained text encoding model to output high-quality case features, significantly improving the performance of the trained text encoding model in downstream tasks in the legal field (such as case retrieval).

[0030] Other features and aspects of this disclosure will become clear from the following detailed description of exemplary embodiments with reference to the accompanying drawings. Attached Figure Description

[0031] The accompanying drawings, which are included in and form part of this specification, illustrate exemplary embodiments, features, and aspects of this disclosure together with the specification and serve to explain the principles of this disclosure.

[0032] Figure 1 A flowchart illustrating a text encoding model training method according to an embodiment of the present disclosure is shown.

[0033] Figure 2 A schematic diagram illustrating a training dataset acquisition process according to an embodiment of the present disclosure is shown.

[0034] Figure 3 A schematic diagram illustrating another training dataset acquisition process according to an embodiment of the present disclosure is shown.

[0035] Figure 4 A schematic diagram showing a comparison of model performance according to an embodiment of the present disclosure is provided.

[0036] Figure 5 A schematic diagram showing a comparison of model performance according to an embodiment of the present disclosure is provided.

[0037] Figure 6 A schematic diagram showing a comparison of model performance according to an embodiment of the present disclosure is provided.

[0038] Figure 7 A block diagram of a text encoding model training apparatus according to an embodiment of the present disclosure is shown.

[0039] Figure 8 A block diagram of an electronic device 1900 according to an embodiment of the present disclosure is shown. Detailed Implementation

[0040] Various exemplary embodiments, features, and aspects of this disclosure will now be described in detail with reference to the accompanying drawings. The same reference numerals in the drawings denote elements that have the same or similar functions. Although various aspects of the embodiments are shown in the drawings, they are not necessarily drawn to scale unless specifically indicated otherwise.

[0041] The term “exemplary” as used herein means “serving as an example, embodiment, or illustration.” Any embodiment illustrated herein as “exemplary” is not necessarily to be construed as superior to or better than other embodiments.

[0042] Furthermore, to better illustrate this disclosure, numerous specific details are set forth in the following detailed description. Those skilled in the art will understand that this disclosure can be practiced without certain specific details. In some instances, methods, means, components, and circuits well known to those skilled in the art have not been described in detail in order to highlight the main points of this disclosure.

[0043] Figure 1 A flowchart illustrating a text encoding model training method according to an embodiment of this disclosure is provided. This text encoding model training method can be executed by an electronic device such as a terminal device or a server. The terminal device can be a user equipment (UE), mobile device, user terminal, terminal, cellular phone, cordless phone, personal digital assistant (PDA), handheld device, computing device, in-vehicle device, wearable device, etc. The method can be implemented by a processor calling computer-readable instructions stored in memory, or it can be executed by a server. Figure 1 As shown, the training method for this text encoding model includes:

[0044] Step S101: Obtain the training dataset. The training dataset includes case information for multiple query cases, as well as case information for positive and negative cases corresponding to each query case. Positive and negative cases are determined based on the judgment information and case information of the cases. The correlation between each query case and its corresponding positive case is higher than the correlation between each query case and its corresponding negative case.

[0045] Step S102: Encode the case information in the training dataset using a text encoding model to obtain the case feature set corresponding to the training dataset;

[0046] Step S103: Based on the case feature set corresponding to the training dataset, determine the first correlation score between each query case and the corresponding positive case, and the second correlation score between each query case and the corresponding negative case;

[0047] Step S104: Determine the contrastive learning loss based on the first relevance score and the second relevance score, and train the text encoding model based on the contrastive learning loss.

[0048] The case information may include, for example, a description of the facts of the case, the cause of action, and other relevant information. The description of the facts may include information describing the subjects, purpose, and outcome of the case. It should be understood that the cases in the training dataset may be adjudicated cases. Therefore, case information for each case can be extracted from the judgment document (such as a legal judgment). It is known that the judgment document summarizes structured information such as the description of the facts, the cause of action, the relevant legal provisions, and the charges in each case. Therefore, the required information can be automatically extracted based on the text structure of the judgment document for each case. This disclosure does not limit the method of obtaining case information.

[0049] It should be understood that each query case can correspond to at least one positive case, which includes cases that are highly relevant to the query case; each query case can correspond to at least one negative case, which includes cases that are less relevant to the query case. The degree of relevance can be reflected by the similarity of the factual descriptions of the cases and / or the degree of overlap in the judgments. For example, the higher the similarity of the factual descriptions and the higher the degree of overlap in the judgments between two cases, the higher the relevance between the two cases. Conversely, the lower the similarity of the factual descriptions and / or the lower the degree of overlap in the judgments, the lower the relevance between the two cases.

[0050] It is known that retrieval tasks in general domains primarily focus on semantic matching between query text and candidate text. However, case retrieval tasks in the legal domain require measuring the relevance of cases at both the legal and semantic levels. To achieve the measurement of relevance between cases at the legal level, this disclosure proposes that among a series of cases with similar factual descriptions, cases with the same judgment are more relevant. Therefore, a model can be trained to select similar cases with the same crime and legal provisions from a series of cases with similar factual descriptions. Based on this, this disclosure proposes an unsupervised comparative learning task, which can be called a legal judgment prediction task. In this legal judgment prediction task, step S101, obtaining the training dataset, may include:

[0051] Step S1011: Obtain case information and judgment information of multiple cases in a preset case database. The case information includes a factual description.

[0052] Step S1012: Take each case in the preset case database as a query case, and determine the first case set corresponding to each query case from the preset case database based on the text similarity between the case information of each query case and the case information of each case in the preset case database. The first case set includes multiple cases with similar factual descriptions to the query case.

[0053] Step S1013: For the first case set corresponding to each query case, cases in the first case set that have the same judgment information as each query case are designated as positive cases corresponding to each query case, and cases in the first case set that have different judgment information from each query case are designated as negative cases corresponding to each query case.

[0054] Among them, the multiple cases in the preset case database can be cases that have been adjudicated. Therefore, in step S1011, the case information and judgment information of each case can be extracted from the judgment text of each adjudicated case. The case information includes a factual description, and the judgment information can include the legal provisions and charges involved in the case.

[0055] Optionally, in step S1012, the BM25 algorithm (a text similarity calculation method based on word matching) can be used to calculate the text similarity (also known as word matching degree) between the case information of each queried case and the case information of each case in the preset case database. A higher text similarity between two cases indicates a higher similarity in the factual descriptions of the two cases. It should be understood that using the BM25 algorithm to calculate text similarity is one possible implementation provided by this embodiment. In fact, those skilled in the art can use known text similarity calculation methods to calculate the text similarity between case information, and this embodiment does not limit this.

[0056] After obtaining the text similarity between the case information of each queried case and the case information of each case in the preset case database, in step S1012, based on the text similarity between the case information of each queried case and the case information of each case in the preset case database, a first case set corresponding to each queried case is determined from the preset case database. For example, this may include: sorting multiple cases in the preset case database in reverse or forward order based on the text similarity; then, selecting the first h cases from the reverse order result to form the first case set, or selecting the last h cases from the forward order result to form the first case set, where h is a positive integer, and the specific value of h is not limited in this embodiment.

[0057] It should be understood that since a higher textual similarity between two cases indicates a higher similarity in factual descriptions between the two cases, multiple cases in the first case set, which consists of the first h cases in the reverse order or the last h cases in the forward order, are cases with similar factual descriptions to the query case.

[0058] As described above, this embodiment of the present disclosure believes that in a series of cases with similar factual descriptions, cases with the same judgment are more relevant. Therefore, in step S1013, based on the judgment information of each case in the preset case database, the positive and negative cases corresponding to each query case can be further determined from the first case set. That is, cases in the first case set that have the same judgment information as each query case are taken as positive cases corresponding to each query case, and cases in the first case set that have different judgment information from each query case are taken as negative cases corresponding to each query case.

[0059] To facilitate understanding of steps S1011 to S1013 above, for example, as follows: Figure 2 The process of obtaining a training dataset is illustrated below. Given a pre-defined case database, the process first extracts information such as factual descriptions, legal provisions, and charges from the judgment documents of each case in the database. Then, the entire database is traversed, and each case is selected as the query case Q. The BM25 algorithm is used to recall the top 200 cases with the highest text similarity, arranged in reverse order. The first 200 cases are formed into the first case set S1. For each case in the first case set S1, it is determined whether the judgment information (i.e., charges and legal provisions) of each case in the first case set S1 is the same as that of the query case Q. If the charges and legal provisions of a case are exactly the same as those of the query case Q, the case is defined as a positive case and added to the positive case set C+. Otherwise, the case is defined as a negative case and added to the negative case set C-. Obviously, the positive cases in the positive case set C+ are more relevant to the query Q than the negative cases in the negative case set C-.

[0060] After obtaining the training dataset through step S101, the text encoding model can be trained using steps S102 to S104. It should be understood that the text encoding model in this embodiment can be any natural language model in the art, such as the BERT model, Longformer model, Transformer model, etc. This embodiment does not limit the model type or structure used in the text encoding model. For example, when the text encoding model uses the Transformer model, the Transformer can generate a vector that incorporates contextual information from the input data. The vector output from the last hidden layer of the Transformer model can be used as a case feature; for example, the [CLS] vector output from the last hidden layer can be used as a case feature.

[0061] Considering that two types of models can be used in the case retrieval task, namely the recall model and the re-ranking model, the main difference between the two models is that the recall model adopts a dual-tower architecture. That is, the input of the recall model is the case information of a single case, and the extraction of the case features of a single case is used. Then, by calculating the feature similarity between any two case features, it can be determined whether two cases are of the same type. The re-ranking model adopts a single-tower cross architecture. That is, the re-ranking model takes the case information of two cases as input at the same time. The case features extracted by the re-ranking model can represent the correlation between the two cases. Then, based on the case features extracted by the re-ranking model, it can be directly used to determine whether two cases are of the same type.

[0062] Based on this, in one possible implementation, when the text encoding model is the aforementioned recall model, step S102, which uses the text encoding model to encode the case information in the training dataset to obtain the case feature set corresponding to the training dataset, may include: step S1021, inputting the case information of the query case, the case information of the positive case, and the case information of the negative case in the training dataset into the text encoding model for encoding to obtain the case features corresponding to the query case, the positive case, and the negative case in the training dataset, and the case feature set includes the case features corresponding to the query case, the positive case, and the negative case in the training dataset.

[0063] Based on the case features corresponding to query cases, positive cases, and negative cases in the aforementioned training dataset, in one possible implementation, step S103 determines a first relevance score between each query case and its corresponding positive case, and a second relevance score between each query case and its corresponding negative case, according to the case feature set corresponding to the training dataset. This includes: step S1031, determining the first relevance score between each query case and its corresponding positive case based on the case features of each query case and the case features of the corresponding positive case; and step S1032, determining the second relevance score between each query case and its corresponding negative case based on the case features of each query case and the case features of the corresponding negative case. This method can effectively determine the aforementioned relevance scores for text encoding models under the recall model type.

[0064] For example, formula (1) can be used to calculate the first relevance score or the second relevance score based on the case characteristics corresponding to the query case, positive case and negative case respectively.

[0065]

[0066] Where, assume C i C represents the i-th query case. j Represents the j-th positive or negative case, score(C i C j () represents the first or second relevance score. This represents the case information for the i-th queried case. The case features represent the i-th query case output by the Transformer model. The case information representing the j-th positive or negative case. The case feature represents the j-th positive or negative case output by the Transformer model. Formula (1) above represents the inner product of the case features of two cases, which is used as the correlation score between the two cases.

[0067] It should be understood that the method of determining the relevance score by calculating the inner product in the above formula (1) is one possible implementation provided by the embodiments of this disclosure. In fact, the embodiments of this disclosure are not limited to this. For example, the relevance score between two cases can also be determined by calculating the cosine similarity between the two cases. The relevance score mentioned in the embodiments of this disclosure can characterize the degree of relevance between two cases. The higher the relevance score, the higher the degree of relevance. Conversely, the lower the relevance score, the lower the degree of relevance.

[0068] In one possible implementation, when the text encoding model is the aforementioned reordering model, step S102, which uses the text encoding model to encode the case information in the training dataset to obtain the case feature set corresponding to the training dataset, may include: step S1022, inputting the case information of each query case and the case information of the corresponding positive case into the text encoding model for encoding to obtain the first case feature between each query case and the corresponding positive case; step S1023, inputting the case information of each query case and the case information of the corresponding negative case into the text encoding model for encoding to obtain the second case feature between each query case and the corresponding negative case; wherein, the case feature set includes the first case feature between each query case and the corresponding positive case and the second case feature between each query case and the corresponding negative case.

[0069] Based on the first case features between each query case and its corresponding positive case, and the second case features between each query case and its corresponding negative case in the aforementioned case feature set, in one possible implementation, step S103 determines the first relevance score between each query case and its corresponding positive case, and the second relevance score between each query case and its corresponding negative case, according to the case feature set corresponding to the training dataset. This includes: step S1033, determining the first relevance score between each query case and its corresponding positive case based on the first case features; and step S1034, determining the second relevance score between each query case and its corresponding negative case based on the second case features. This method can effectively determine the relevance scores for text encoding models under the re-ranking model type.

[0070] For example, formula (2) can be used to calculate the first correlation score based on the first case characteristics and the second correlation score based on the second case characteristics.

[0071]

[0072] in, The first case feature represents the first case feature between the i-th query case and the j-th positive case, or the second case feature between the i-th query case and the j-th negative case, as output by the Transformer model. MLP stands for Multilayer Perceptron, which is used to map high-dimensional vectors to low-dimensional vectors, that is, to map high-dimensional first case feature or second case feature to low-dimensional first relevance score or second relevance score.

[0073] As described above, the first case feature extracted by the text encoding model between the query case and the corresponding positive case can characterize the correlation between the query case and the positive case, and the second case feature extracted between the query case and the corresponding negative case can characterize the correlation between the query case and the negative case. Therefore, the MLP described above can be directly used to map the first case feature or the second case feature into a first relevance score or a second relevance score, respectively. It should be understood that using MLP is one possible implementation provided by the embodiments of this disclosure. In fact, those skilled in the art can also use other vector mapping methods known in the art to map the high-dimensional first case feature or the second case feature into a low-dimensional first relevance score or second relevance score, and the embodiments of this disclosure do not limit this.

[0074] In one possible implementation, after obtaining the first relevance score and the second relevance score of different text encoding models (such as recall model and re-ranking model) based on the above formula (1) or formula (2), in step S104, the cross-entropy loss function can be used to determine the contrastive learning loss of different text encoding models, and different text encoding models can be trained respectively.

[0075] For example, a cross-entropy loss function shown in Equation (3) can be used to determine the contrastive learning loss based on the first relevance score and the second relevance score.

[0076]

[0077] Where Q represents querying a case, c + C represents the selected positive cases, N represents the set of all negative cases, and c represents the selected positive cases. - Representing a negative case in set N, score(Q,c) + ) represents the first relevance score calculated using formula (1) or formula (2) above, score(Q,c - ) represents the second correlation score calculated by formula (1) or formula (2) above, exp represents the exponential function with the natural constant e as the base, and log represents the logarithmic function.

[0078] It should be understood that using the cross-entropy loss function shown in formula (3) to calculate the contrastive learning loss is one possible implementation provided by the embodiments of this disclosure. In fact, those skilled in the art can also use other known loss functions in the art, such as the circle loss function (CL), to determine the above-mentioned contrastive learning loss. The embodiments of this disclosure do not limit this.

[0079] The contrastive learning loss described above allows the text encoding model to be trained to bring case features of the same category closer together and push case features of different categories further apart. This means that the features of a query case have a higher correlation with those of positive cases, and a lower correlation with those of negative cases. The correlation between case features in the feature space depends on the values ​​of the first and second correlation scores. Furthermore, since positive and negative cases are divided based on case information and judgment information, this is equivalent to introducing legal-level correlation information between different cases into the contrastive learning loss. This allows the text encoding model to learn the correlation between cases at the legal level, which is beneficial for the trained text encoding model to output high-quality case features.

[0080] In step S104, training the text encoding model based on contrastive learning loss may include: optimizing the model parameters of the text encoding model based on contrastive learning loss through backpropagation and gradient descent; wherein, the text encoding model may be iteratively trained using training datasets from multiple training batches until a well-trained text encoding model is obtained.

[0081] According to embodiments of this disclosure, by determining the contrastive learning loss based on a first relevance score between the query case and positive cases and a second relevance score between the query case and negative cases, the text encoding model can be trained to bring the case features between the query case and positive cases closer together and push the case features between the query case and negative cases further apart. Since positive and negative cases are determined based on the judgment information and case information of the cases, this is equivalent to introducing legal knowledge to train the text encoding model. This enables the text encoding model to learn the relevance between cases in the legal field, that is, to train the text encoding model to learn legal knowledge from unlabeled training datasets, thereby achieving unsupervised contrastive learning as a whole. This allows the trained text encoding model to output high-quality case features, significantly improving the performance of the trained text encoding model in downstream tasks in the legal field (such as case retrieval).

[0082] As described above, in step S101, it is considered that among a series of cases with similar factual descriptions, cases with the same judgment are more relevant. Therefore, steps S1011 to S1013 can be used to determine the positive and negative cases corresponding to the query case. In one possible implementation, this embodiment of the disclosure further considers that among a series of cases with similar judgments, cases with more similar factual descriptions are more relevant. Therefore, a model can also be trained to select relevant similar cases from a set of candidate cases with similar legal judgments based on factual descriptions. Based on this, this embodiment of the disclosure proposes another unsupervised comparative learning task, which can be called a factual description similarity matching task. In this factual description similarity matching task, step S101, obtaining the training dataset, may include:

[0083] Step S1015: Obtain case information and judgment information of multiple cases in the preset case database;

[0084] Step S1016: Take each case in the preset case database as a query case, and determine the second case set corresponding to each query case from the preset case database based on the overlap between the judgment information of each query case and the judgment information of each case in the preset case database. The second case set includes multiple cases with similar judgments to the query case.

[0085] Step S1017: Based on the text similarity between the case information of each query case and the case information of each case in the second case set corresponding to each query case, determine the positive and negative cases corresponding to each query case from the second case set corresponding to each query case, wherein the text similarity of the positive cases is higher than that of the negative cases.

[0086] As mentioned above, the multiple cases in the preset case database can be adjudicated cases. Therefore, in step S1015, the case information and judgment information of each case can be extracted from the judgment text of each adjudicated case. The case information includes a factual description, and the judgment information can include the legal provisions and charges involved in the case.

[0087] In one possible implementation, in step S1016, a second case set corresponding to each queried case is determined from the preset case database based on the degree of overlap between the judgment information of each queried case and the judgment information of each case in the preset case database. This includes: determining the overlapping legal provisions between each queried case and each case in the preset case database based on the legal provisions involved in each case; determining the degree of overlap between each queried case and each case in the preset case database based on the frequency of occurrence of the overlapping legal provisions in the preset case database; determining the degree of overlap between each queried case and each case in the preset case database based on the crimes involved in each case; determining the similarity score between each queried case and each case in the preset case database based on the degree of overlap of legal provisions and the degree of overlap of crimes; and determining the second case set corresponding to each queried case from the preset case database based on the similarity score. This method can effectively determine the second case set consisting of multiple cases with similar judgments to the queried case.

[0088] It should be understood that each case may involve at least one legal provision. Given the legal provisions involved in each case in the pre-defined case database, the overlapping legal provisions between any two cases can be determined. The overlapping legal provisions are the intersection between the legal provisions involved in each of the two cases. For example, suppose case c1 involves legal provisions 1, 2, and 3, case c2 involves legal provisions 2, 3, and 4, and case c3 involves legal provisions 4 and 5. Then the overlapping legal provisions between case c1 and case c2 include legal provisions 2 and 3, the overlapping legal provisions between case c1 and case c3 are empty, and the overlapping legal provisions between case c2 and case c3 include legal provision 4.

[0089] Once the overlapping legal clauses between any two cases are known, the number of times the overlapping legal clauses appear in the preset case database can be determined. For example, assuming that the preset case database includes the aforementioned cases c1, c2, and c3, then the number of times overlapping legal clauses 2 and 3 between cases c1 and c2 appear in the preset case database are 2 each, and the number of times overlapping legal clause 4 between cases c2 and c3 appears in the preset case database is also 2.

[0090] Optionally, formula (4) can be used to determine the degree of overlap between each queried case and each case in the preset case database based on the number of times the overlapping legal provisions appear in the preset case database. This can also be called the inverse case frequency.

[0091]

[0092] Where P represents the total number of overlapping legal clauses between two cases, p represents the p-th overlapping legal clause between two cases, |D| represents the total number of cases in the preset case database, and freq(p,D) represents the number of times the p-th overlapping legal clause appears in the preset case database D.

[0093] It should be understood that each case may involve at least one crime. In one possible implementation, after knowing the crimes involved in each case in the preset case database, it can be determined whether there are overlapping crimes between any two cases, that is, whether there are identical crimes. If there are overlapping crimes, the degree of overlap between the two cases can be determined to be 1. If there are no overlapping crimes, the degree of overlap between the two cases can be determined to be 0. For example, if case c1 involves crimes L1, L2, and L3, case c2 involves crimes L2, L3, and L4, and case c3 involves crimes L4 and L5, then there are overlapping crimes L2 and L3 between case c1 and case c2, and the degree of overlap between case c1 and case c2 can be set to 1. There are no overlapping crimes between case c1 and case c3, and the degree of overlap between case c1 and case c3 can be set to 0. If there is overlapping crime L4 between case c2 and case c3, then the degree of overlap between case c2 and case c3 can be set to 1.

[0094] Based on this, determining the degree of overlap between the charges involved in each queried case and the charges in each case in the preset case database can include: if a queried case shares a charge with a case in the preset case database, the degree of overlap between the queried case and that case is set as the first degree of overlap, where the first degree of overlap can be set to 1 or other values; if a queried case does not share a charge with a case in the preset case database, the degree of overlap between the queried case and that case is set as the second degree of overlap, where the second degree of overlap can be 0 or other values. It should be understood that the first degree of overlap and the second degree of overlap are different.

[0095] Optionally, formula (5) can be used to determine the similarity score between each queried case and each case in the preset case database based on the overlap of legal provisions and the overlap of crimes. This can also be called the legal provision-inverse case frequency LP_ICF.

[0096]

[0097] Among them, Q x C represents the xth query case. y LP_ICF(Q) represents the y-th case in the preset case database. x C y () represents the similarity score between the x-th query case and the y-th case; crime x,y The crime represents the degree of overlap in charges between the x-th query case and the y-th case. x,y Defined as: if there is an overlap in charges between the x-th query case and the y-th case, then crime x,y=1, if there is no overlapping crime between the x-th query case and the y-th case, then crime x,y =0; P represents the degree of overlap in legal provisions between the x-th query case and the y-th case. x,y p represents the total number of duplicate legal clauses between the x-th query case and the y-th query case. x,y freq(p) represents the p-th overlapping legal clause between the x-th query case and the y-th case. x,y ,D) represents the number of times the p-th overlapping legal clause between the x-th queried case and the y-th case appears in the preset case database D. The above formula (5) can be used to recall cases with similar legal judgments.

[0098] In one possible implementation, after calculating the similarity score between each query case and each case in the preset case database using the above formula (5), the above-mentioned determination of the second case set corresponding to each query case from the preset case database based on the similarity score may include: arranging multiple cases in the preset case database in reverse or forward order based on the similarity score; then, selecting the first k cases from the reverse order result to form the second case set, or selecting the last k cases from the forward order result to form the second case set, where k is a positive integer. This embodiment of the present disclosure does not limit the specific value of k, for example, k can be set to 200.

[0099] It should be understood that since a higher similarity score between two cases indicates a higher similarity in legal judgments between the two cases, multiple cases in the second case set, which consists of the first h cases in the reverse order or the last h cases in the forward order, are cases with similar legal judgments to the query case.

[0100] As described above, this embodiment of the present disclosure considers that in a series of cases with similar judgments, cases with more similar factual descriptions are more relevant. Therefore, in step S1017, the positive and negative cases corresponding to the query case can be further determined from the second case set based on the text similarity between the query case and the case information of each case in the second case set. In one possible implementation, the positive and negative cases corresponding to each query case are determined from the second case set corresponding to each query case based on the text similarity between the case information of each query case and the case information of each case in the second case set corresponding to each query case, including:

[0101] For any query case and its corresponding second case set, based on the text similarity between the case information of the query case and the case information of each case in the corresponding second case set, the multiple cases in the second case set are sorted in reverse or forward order to obtain the reverse or forward sorting results.

[0102] The first n cases in the reverse-order result are taken as the positive cases of the query case, and the last m cases in the reverse-order result are taken as the negative cases of the query case, where n and m are positive integers; or,

[0103] The first n cases in the ascending order are taken as negative cases of the query case, and the last m cases in the ascending order are taken as positive cases of the query case.

[0104] Optionally, the BM25 algorithm can be used to calculate the text similarity between the case information of the queried case and the case information of each case in the corresponding second case set. A higher text similarity between two cases indicates a higher similarity in the factual descriptions of the two cases. It should be understood that using the BM25 algorithm to calculate text similarity is one possible implementation provided by this disclosure embodiment. In fact, those skilled in the art can use text similarity calculation methods known in the art to calculate the text similarity between case information, and this disclosure embodiment does not limit this.

[0105] It should be understood that since a higher textual similarity between two cases indicates a higher similarity in factual descriptions between the two cases, the first n cases in the reverse-order results can be used as positive cases for the query case, and the last m cases in the reverse-order results as negative cases for the query case; alternatively, the first n cases in the forward-order results can be used as negative cases for the query case, and the last m cases in the forward-order results as positive cases for the query case. The values ​​of m and n can be customized, for example, n can be set to 5 and m to 50, and this disclosure does not impose any limitations on this embodiment.

[0106] To facilitate understanding of steps S1015 to S1017 above, for example, as follows: Figure 3The process of obtaining a training dataset is shown in the following steps: Given a preset case database, the entire preset case database is traversed, and each case is selected as the query case Q in turn. First, the LP-ICF method shown in the above formula (5) is used to recall the top 200 cases with the reverse similarity scores. The top 200 cases are used to form the second case set S2. For each case in the second case set S2, the text similarity between it and the query case Q is calculated using the BM25 algorithm. Based on the text similarity between it and the query case Q, the multiple cases in the second case set S2 are reversed. Then, the top 5 cases are selected as positive cases, and the bottom 50 cases are selected as negative cases.

[0107] It should be understood that after obtaining the training dataset through steps S1015 to S1017, steps S102 to S104 can be executed again to train the text encoding model. The training process of the text encoding model using the training dataset obtained through steps S1015 to S1017 is the same as the training process using the training dataset obtained through steps S1011 to S1013, and will not be described again here.

[0108] According to embodiments of this disclosure, positive and negative cases corresponding to a query case can be determined based on case information and judgment information, i.e., the aforementioned training dataset can be determined. Thus, when the text encoding model is trained using the aforementioned training dataset, it is equivalent to introducing legal knowledge to train the text encoding model, enabling the text encoding model to learn the correlation between cases in the legal field. Not only does the text encoding model learn legal knowledge from the unlabeled training dataset, achieving unsupervised comparative learning as a whole, but the trained text encoding model can also output high-quality case features, thereby significantly improving the performance of the trained text encoding model in downstream tasks in the legal field (such as case retrieval).

[0109] As we know, the purpose of case retrieval in the legal field is to return similar cases related to a given query case. Therefore, an ideal model should understand the natural language meaning of legal documents. However, general-domain PLMs sometimes fail to correctly understand legal documents because the legal field has its unique terminology and expressions, which rarely appear in general domains. These unique terminology, expressions, and writing structures in the legal field can be considered legal language. Clearly, understanding legal language is a prerequisite for achieving the task of case retrieval.

[0110] To enable text encoding models to understand legal language, one possible implementation is through Mask Language Modeling (MLM) tasks. This involves pre-training the text encoding model on official legal documents (such as various codes and judicial interpretations) using a dynamic masking strategy. These official documents possess rigorous linguistic organization and reliable content, covering most legal terminology and expressions. Therefore, pre-training the text encoding model on MLM tasks using official documents allows the model to effectively learn the meaning of context-based legal terminology and expressions.

[0111] To further enhance the text encoding model's legal knowledge and adapt it to the unique writing structure of the legal field, it can be pre-trained for MLM tasks using officially published legal judgments. Legal judgments integrate rich legal knowledge, such as basic factual descriptions, legal provisions, and criminal acts. Therefore, training the text encoding model using legal judgments allows it to adapt to the unique writing structure of the legal field and learn legal knowledge. Through this MLM task pre-training, the text encoding model can learn unique legal terminology, expressions, and writing structures, thereby better understanding the natural language meaning of legal documents and ultimately performing better in downstream legal tasks.

[0112] Based on this, in one possible implementation, the method further includes: pre-training a text encoding model using multiple legal documents from a legal corpus, wherein the legal documents include at least one of the following: official documents in the legal field, judgments; wherein pre-training the text encoding model using a legal corpus includes:

[0113] Based on a preset masking ratio, some real words in each legal document are masked to obtain the masked legal document. The masked legal document is then encoded using a text encoding model to obtain the document features corresponding to the masked legal document.

[0114] Based on the document features corresponding to the blocked legal documents, predict the real words that are blocked in the blocked legal documents, and obtain the predicted words corresponding to the blocked legal documents.

[0115] Based on the predicted words corresponding to the blocked legal documents and the blocked real words in the blocked legal documents, the blocking language loss is determined, and the text encoding model is trained based on the blocking language loss.

[0116] In this process, a portion of the real words in a legal document can be randomly blocked based on a preset blocking ratio (e.g., 15%). Then, the blocked legal document is input into a text encoding model for encoding to obtain the document features corresponding to the blocked legal document.

[0117] Specifically, a text decoding model can be used to predict the true words that are blocked in the blocked legal document based on the document features corresponding to the blocked legal document, thereby obtaining the predicted words corresponding to the blocked legal document. In other words, the text decoding model can predict the blocked words based on the remaining words in the legal document. It should be understood that those skilled in the art can use text decoding models known in the art to predict the true words that are blocked in the blocked legal document, and the embodiments of this disclosure do not limit the model type, model structure, etc. of the text decoding model.

[0118] Optionally, the masking language loss can be determined based on the difference or similarity between the predicted words and the masked real words. For example, the BM25 algorithm described above can be used to determine the similarity between the predicted words and the real words. This disclosure does not limit this aspect.

[0119] Optionally, the blocking language loss can also be determined by formula (6) based on the predicted words corresponding to the blocked legal documents and the blocked real words; of course, other known loss functions in the art can also be used to determine the blocking language loss based on the predicted words and real words, and this disclosure does not limit this.

[0120]

[0121] Where w represents the blocked legal document, and m(w) represents the predicted blocked words, i.e., the predicted words. This represents a specific predicted term, and w\m(w) represents the remaining terms in the legal document. Representative predictive words The probability relative to the remaining words in legal documents.

[0122] Training a text encoding model based on masked language loss can be understood as optimizing the model parameters of the text encoding model through backpropagation and gradient descent, based on the masked language loss.

[0123] According to embodiments of this disclosure, training a text encoding model using the aforementioned masked language loss helps the text encoding model learn unique legal terminology, expressions, and writing structures, thereby enabling it to better understand the natural language meaning of legal documents and perform better in downstream tasks in the legal field.

[0124] It should be noted that, in the embodiments of this disclosure, the text encoding model can be trained first using the masked language loss determined by the MLM task, and then the text encoding model can be trained using the contrastive learning loss determined by steps S101 to S104; of course, the text encoding model can also be trained first using the contrastive learning loss determined by steps S101 to S104, and then the text encoding model can be trained using the masked language loss determined by the MLM task; or, the text encoding model can be trained simultaneously using the contrastive learning loss determined by steps S101 to S104 and the masked language loss determined by the MLM task, and this embodiment of the disclosure does not limit this.

[0125] For example, the masked language loss L can be used MLM and contrastive learning loss (L LJP L FDM Linear combination L total =L MLM +L LJP +L FDM Train a text encoding model, where L LJP L represents the contrastive learning loss obtained using the training dataset determined in steps S1011 to S1013 in the aforementioned legal judgment prediction task. FDM The above-described factual description refers to the contrastive learning loss obtained using the training dataset determined in steps S1015 to S1017 in the similarity matching task. It should be understood that L LJP With L FDM All of them can be calculated using the above formula (3).

[0126] In practical applications, the text encoding model trained by the text encoding model training method of the present disclosure embodiments described above can be deployed on various electronic devices (such as terminal devices or servers) to realize downstream tasks in the legal field, such as case retrieval tasks. Based on this, the present disclosure embodiments also provide a case retrieval method, which includes:

[0127] Obtain case information of the target case to be searched;

[0128] The case information of the target case is encoded using the first text encoding model to obtain the case features corresponding to the target case. The first text encoding model is obtained by training the first relevance score and the second relevance score determined by steps S1021 and S1031 to S1032 in the above text encoding model training method.

[0129] Based on the case characteristics corresponding to the target case and the case characteristics of multiple adjudicated cases in the target case database, similar cases to the target case are identified from the target case database.

[0130] Among them, adjudicated cases can be understood as cases with existing judgments. The characteristics of adjudicated cases can be obtained by pre-encoding the case information of each adjudicated case in the target case database using the first text encoding model mentioned above. This enables a dual-tower architecture for case retrieval, which has a fast retrieval speed. The first text encoding model can be a kind of recall model.

[0131] In one possible implementation, the above-mentioned determination of similar cases to the target case from the target case database based on the case features corresponding to the target case and the case features of multiple adjudicated cases in the target case database may include: calculating the feature similarity between the case features corresponding to the target case and the case features of each adjudicated case in the target case database, and taking the adjudicated case with the highest feature similarity as a similar case to the target case; or, taking the adjudicated cases with feature similarity exceeding a preset threshold as similar cases to the target case; or, taking the z adjudicated cases arranged in reverse order of feature similarity as the z similar cases to the target case, where z is a positive integer, and this disclosure embodiment does not limit this.

[0132] Those skilled in the art can use similarity calculation methods known in the art to calculate the feature similarity between the case features of two cases, such as cosine similarity, or they can directly use the inner product between the features of two cases as the feature similarity. This disclosure does not limit this.

[0133] According to the embodiments of this disclosure, the high-quality case features output by the above-mentioned text encoding model can be used to retrieve more accurate similar cases, thereby improving the accuracy of similar case retrieval. In particular, a dual-tower architecture similar case retrieval process can be implemented, which is conducive to improving the speed of similar case retrieval.

[0134] In practical applications, the aforementioned first text encoding model can be applied to the recall stage of a case retrieval task, equivalent to preliminary rapid screening. Although the retrieval speed is fast, the accuracy of case retrieval may not be high. To further improve the accuracy of case retrieval, that is, to retrieve more precise similar cases, in one possible implementation, the above-mentioned method of determining similar cases from the target case database based on the case characteristics corresponding to the target case and the case characteristics of multiple adjudicated cases in the target case database can include:

[0135] Based on the case characteristics corresponding to the target case and the case characteristics of multiple adjudicated cases in the target case database, multiple initial similar cases corresponding to the target case are identified from the target case database;

[0136] The case information of each initial similar case and the case information of the target case are input into the second text encoding model for encoding to obtain the case features between each initial similar case and the target case. The second text encoding model is obtained by training the first relevance score and the second relevance score determined in steps S1022 to S1023 and steps S1033 to S1034 of the above text encoding model training method.

[0137] Based on the case characteristics between each initial similar case and the target case, similar cases to the target case are identified from multiple initial similar cases.

[0138] In this process, based on the case characteristics corresponding to the target case and the case characteristics of multiple adjudicated cases in the target case database, multiple initial similar cases corresponding to the target case are determined from the target case database. For example, this may include: calculating the feature similarity between the case characteristics corresponding to the target case and the case characteristics of each adjudicated case in the target case database, and taking multiple adjudicated cases whose feature similarity exceeds a preset threshold as initial similar cases of the target case. Alternatively, the z adjudicated cases that are arranged in reverse order of feature similarity may be taken as initial similar cases of the target case. This disclosure does not limit this process.

[0139] The second text encoding model can be a reordering model, which can be used in the reordering stage of case retrieval tasks and has a high retrieval accuracy. By inputting the case information of an initial similar case and the case information of a target case into the second text encoding model for encoding, the resulting case features between the initial similar case and the target case can characterize the correlation between them.

[0140] Based on this, according to the case characteristics between each initial similar case and the target case, similar cases of the target case are determined from multiple initial similar cases. For example, this may include: using the above-mentioned multilayer perceptron (MLP) to map the case characteristics between each initial similar case and the target case into a correlation score between each initial similar case and the target case; then, at least one initial similar case with a correlation score exceeding a preset score threshold may be used as a similar case of the target case, or the v initial similar cases arranged in reverse order of correlation score may be used as similar cases of the target case, where v is a positive integer and v is less than z. This disclosure embodiment does not limit this.

[0141] According to the embodiments of this disclosure, it is equivalent to first using a first text encoding model to recall multiple initial similar cases from the target cases, and then using a second text encoding model to determine more accurate similar cases from the multiple initial similar cases, which is beneficial to improving the accuracy of the similar case retrieval task.

[0142] According to embodiments of this disclosure, combining legal expertise with artificial intelligence technology, a series of unsupervised learning tasks are designed based on unlabeled legal documents, including unsupervised comparative learning tasks and MLM tasks. This enables the trained text encoding model to possess natural language understanding capabilities, legal document understanding capabilities, legal fact understanding capabilities, and the ability to measure case similarity. A pre-trained text encoding model for judicial scenarios with low application cost and good application effect is proposed, solving the current problems of lack of citation relationships and lack of manually labeled data in the judicial field.

[0143] Various experimental results show that the text encoding model trained by the text encoding model training method of this disclosure can more accurately measure the similarity between cases at the legal level. Especially in scenarios without training data for downstream tasks, the similarity retrieval performance is significantly stronger than existing retrieval methods based on word matching and pre-trained models in general domains. Furthermore, the text encoding model training method of this disclosure can be adapted to various language texts and has a strong generalization ability.

[0144] Figure 4 This diagram illustrates the performance of a re-ranking model (Caseformer Re-ranker) obtained using the text encoding model training method of this disclosure, and other existing pre-trained models (i.e., BM25, QL, Roberta, BERT, PROP, BERT-XS, Lawformer) on two Chinese case retrieval datasets (i.e., LeCaRD and CAIL-LCR). N@5, N@10, and N@15 are performance metrics. The left area of ​​the diagram shows performance data in the zero-sample scenario, and the right area shows performance data in the full-sample scenario. Figure 4 As shown, Caseformer Re-ranker significantly outperforms the aforementioned existing pre-trained models in both zero-shot and full-shot scenarios. In the zero-shot scenario, Caseformer is the only pre-trained model that surpasses BM25. In the zero-shot scenario, it achieves an 11% performance improvement compared to BM25; in the full-shot scenario, it achieves a 20% performance improvement compared to BM25.

[0145] Figure 5This diagram illustrates the performance of a recall model (Caseformer Retriever) trained using the text encoding model training method of this disclosure, and other existing pre-trained models (i.e., BM25, BERT, RoBERTa, SEED, coCondenser, BERT-XS, Lawformer) on two Chinese case retrieval datasets (i.e., LeCaRD and CAIL-LCR). R@100, R@200, and R@500 represent recall metrics. The left area of ​​the diagram shows performance data in the zero-sample scenario, and the right area shows performance data in the full-sample scenario. Figure 5 As shown, CaseformerRetriever has the best recall rate in both zero-sample and full-sample scenarios compared to the existing pre-trained models mentioned above, demonstrating that CaseformerRetriever has excellent performance in case retrieval and recall tasks.

[0146] Figure 6 This diagram illustrates the performance of a text encoding model (Caseformer) trained using the text encoding model training method of this disclosure, and other existing pre-trained models (BERT, BERT-XS, PROP) on a Chinese legal document relevance matching dataset (including a validation set and a test set). This task involves predicting which of two candidate cases is more similar to the query case, and accuracy is used to evaluate its performance. The upper area of ​​the diagram shows the performance data in a zero-sample scenario, and the lower area shows the performance data in a full-sample scenario. Figure 6 As shown, experiments tested the relevance matching ability of Caseformer with three pre-trained models, including a general domain pre-trained model (BERT), an IR-customized pre-trained model (PROP), and a legal domain pre-trained model (BERT-XS). Experimental results show that Caseformer outperforms the three pre-trained models in both validation and test sets, in both zero-shot and full-shot scenarios. This demonstrates Caseformer's strong relevance matching ability among legal cases and the effectiveness of the text encoding model training method proposed in this embodiment.

[0147] Figure 7 A block diagram of a text encoding model training apparatus according to an embodiment of the present disclosure is shown. Figure 7 As shown, the text encoding model training device includes:

[0148] The acquisition module 701 is used to acquire a training dataset, which includes case information of multiple query cases, and case information of positive and negative cases corresponding to each query case. The positive and negative cases are determined based on the judgment information and case information of the cases. The correlation between each query case and the corresponding positive case is higher than the correlation between each query case and the corresponding negative case.

[0149] The encoding module 702 is used to encode the case information in the training dataset using a text encoding model to obtain the case feature set corresponding to the training dataset;

[0150] The determination module 703 is used to determine, based on the case feature set corresponding to the training dataset, a first correlation score between each query case and the corresponding positive case, and a second correlation score between each query case and the corresponding negative case;

[0151] Training module 704 is used to determine the contrastive learning loss based on the first relevance score and the second relevance score, and to train the text encoding model based on the contrastive learning loss.

[0152] In one possible implementation, obtaining the training dataset includes: obtaining case information and judgment information of multiple cases in a preset case database, wherein the case information includes factual descriptions; taking each case in the preset case database as a query case, and determining a first case set corresponding to each query case from the preset case database based on the text similarity between the case information of each query case and the case information of each case in the preset case database, wherein the first case set includes multiple cases with similar factual descriptions to the query case; for each query case corresponding to the first case set, taking cases in the first case set that have the same judgment information as each query case as positive cases corresponding to each query case, and taking cases in the first case set that have different judgment information from each query case as negative cases corresponding to each query case.

[0153] In one possible implementation, acquiring the training dataset includes: acquiring case information and judgment information of multiple cases in a preset case database; using each case in the preset case database as a query case, and determining a second case set corresponding to each query case from the preset case database based on the overlap between the judgment information of each query case and the judgment information of each case in the preset case database, wherein the second case set includes multiple cases with similar judgments to the query case; and determining positive and negative cases corresponding to each query case from the second case set corresponding to each query case based on the text similarity between the case information of each query case and the case information of each case in the second case set corresponding to each query case, wherein the text similarity corresponding to positive cases is higher than the text similarity corresponding to negative cases.

[0154] In one possible implementation, the judgment information includes the legal provisions and charges involved in the case. The step of determining the second case set corresponding to each queried case from the preset case database based on the overlap between the judgment information of each queried case and the judgment information of each case in the preset case database includes: determining the overlapping legal provisions between each queried case and each case in the preset case database based on the legal provisions involved in each case; determining the overlap between the legal provisions between each queried case and each case in the preset case database based on the frequency of occurrence of the overlapping legal provisions in the preset case database; determining the overlap between the charges between each queried case and each case in the preset case database based on the charges involved in each case; determining a similarity score between each queried case and each case in the preset case database based on the overlap of legal provisions and the overlap of charges; and determining the second case set corresponding to each queried case from the preset case database based on the similarity score.

[0155] In one possible implementation, determining the positive and negative cases corresponding to each query case from the second case set corresponding to each query case based on the text similarity between the case information of each query case and the case information of each case in the second case set corresponding to each query case includes: for any query case and the corresponding second case set, sorting multiple cases in the second case set in reverse or forward order based on the text similarity between the case information of the query case and the case information of each case in the corresponding second case set to obtain a reverse or forward sorting result; taking the first n cases in the reverse sorting result as the positive cases of the query case, and taking the last m cases in the reverse sorting result as the negative cases of the query case, where n and m are positive integers; or, taking the first n cases in the forward sorting result as the negative cases of the query case, and taking the last m cases in the forward sorting result as the positive cases of the query case.

[0156] In one possible implementation, encoding the case information in the training dataset using a text encoding model to obtain a case feature set corresponding to the training dataset includes: inputting the case information of query cases, positive cases, and negative cases in the training dataset into the text encoding model for encoding to obtain case features corresponding to each query case, positive case, and negative case in the training dataset. The case feature set includes the case features corresponding to each query case, positive case, and negative case in the training dataset. The step of determining a first correlation score between each query case and its corresponding positive case, and a second correlation score between each query case and its corresponding negative case, based on the case feature set corresponding to the training dataset, includes: determining a first correlation score between each query case and its corresponding positive case based on the case features of each query case and the case features of the corresponding positive case; and determining a second correlation score between each query case and its corresponding negative case based on the case features of each query case and the case features of the corresponding negative case.

[0157] In one possible implementation, the step of encoding the case information in the training dataset using a text encoding model to obtain a case feature set corresponding to the training dataset includes: inputting the case information of each query case and the case information of the corresponding positive case into the text encoding model for encoding to obtain a first case feature between each query case and the corresponding positive case; inputting the case information of each query case and the case information of the corresponding negative case into the text encoding model for encoding to obtain a second case feature between each query case and the corresponding negative case; wherein the case feature set includes the first case feature between each query case and the corresponding positive case and the second case feature between each query case and the corresponding negative case; wherein, the step of determining a first correlation score between each query case and the corresponding positive case and a second correlation score between each query case and the corresponding negative case based on the case feature set corresponding to the training dataset includes: determining a first correlation score between each query case and the corresponding positive case based on the first case feature between each query case and the corresponding positive case; determining a second correlation score between each query case and the corresponding negative case based on the second case feature between each query case and the corresponding negative case.

[0158] In one possible implementation, the apparatus further includes: a masked language training module, used to pre-train the text encoding model using multiple legal documents in a legal corpus, wherein the legal documents include at least one of the following: official documents in the legal field, judgments; wherein, the pre-training of the text encoding model using the legal corpus includes: masking some real words in each legal document based on a preset masking ratio to obtain masked legal documents, and encoding the masked legal documents using the text encoding model to obtain document features corresponding to the masked legal documents; predicting the masked real words in the masked legal documents based on the document features corresponding to the masked legal documents to obtain predicted words corresponding to the masked legal documents; determining the masked language loss based on the predicted words corresponding to the masked legal documents and the masked real words in the masked legal documents, and training the text encoding model based on the masked language loss.

[0159] According to embodiments of this disclosure, by determining the contrastive learning loss based on a first relevance score between the query case and positive cases and a second relevance score between the query case and negative cases, the text encoding model can be trained to bring the case features between the query case and positive cases closer together and push the case features between the query case and negative cases further apart. Since positive and negative cases are determined based on the judgment information and case information of the cases, this is equivalent to introducing legal knowledge to train the text encoding model. This enables the text encoding model to learn the relevance between cases in the legal field, that is, to train the text encoding model to learn legal knowledge from unlabeled training datasets, thereby achieving unsupervised contrastive learning as a whole. This allows the trained text encoding model to output high-quality case features, significantly improving the performance of the trained text encoding model in downstream tasks in the legal field (such as case retrieval).

[0160] According to an embodiment of this disclosure, a case retrieval device is also provided, comprising: an information acquisition module for acquiring case information of a target case to be retrieved; an information encoding module for encoding the case information of the target case using a first text encoding model to obtain case features corresponding to the target case, wherein the first text encoding model is trained using the text encoding model training method; and a case determination module for determining similar cases to the target case from the target case database based on the case features corresponding to the target case and the case features of multiple adjudicated cases in the target case database.

[0161] In one possible implementation, determining similar cases from the target case database based on the case features corresponding to the target case and the case features of multiple adjudicated cases in the target case database includes: determining multiple initial similar cases corresponding to the target case from the target case database based on the case features corresponding to the target case and the case features of multiple adjudicated cases in the target case database; inputting the case information of each initial similar case and the case information of the target case into a second text encoding model for encoding to obtain the case features between each initial similar case and the target case, wherein the second text encoding model is trained using the text encoding model training method; and determining similar cases from the multiple initial similar cases based on the case features between each initial similar case and the target case.

[0162] According to embodiments of this disclosure, the high-quality case features output by the above-described text encoding model can be used to retrieve more accurate similar cases, thereby improving the accuracy and efficiency of similar case retrieval.

[0163] In some embodiments, the functions or modules of the apparatus provided in this disclosure can be used to perform the methods described in the above method embodiments. The specific implementation can be referred to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.

[0164] This disclosure also proposes a computer-readable storage medium storing computer program instructions that, when executed by a processor, implement the above-described method. The computer-readable storage medium can be volatile or non-volatile.

[0165] This disclosure also proposes an electronic device, including: a processor; and a memory for storing processor-executable instructions; wherein the processor is configured to implement the above method when executing the instructions stored in the memory.

[0166] This disclosure also provides a computer program product, including computer-readable code, or a non-volatile computer-readable storage medium carrying computer-readable code, wherein when the computer-readable code is run in a processor of an electronic device, the processor in the electronic device performs the above-described method.

[0167] Figure 8 A block diagram of an electronic device 1900 according to an embodiment of the present disclosure is shown. For example, the electronic device 1900 may be provided as a server or a terminal device. (Refer to...) Figure 8 The electronic device 1900 includes a processing component 1922, which further includes one or more processors, and memory resources represented by memory 1932 for storing instructions, such as application programs, that can be executed by the processing component 1922. The application programs stored in memory 1932 may include one or more modules, each corresponding to a set of instructions. Furthermore, the processing component 1922 is configured to execute instructions to perform the methods described above.

[0168] Electronic device 1900 may also include a power supply component 1926 configured to perform power management of electronic device 1900, a wired or wireless network interface 1950 configured to connect electronic device 1900 to a network, and an input / output interface 1958 (I / O interface). Electronic device 1900 can operate on an operating system, such as Windows Server, stored in memory 1932. TM Mac OS X TM Unix TM Linux TM FreeBSD TM Or similar.

[0169] In an exemplary embodiment, a non-volatile computer-readable storage medium is also provided, such as a memory 1932 including computer program instructions that can be executed by a processing component 1922 of an electronic device 1900 to perform the above-described method.

[0170] This disclosure can be a system, method, and / or computer program product. A computer program product may include a computer-readable storage medium having computer-readable program instructions loaded thereon for causing a processor to implement various aspects of this disclosure.

[0171] Computer-readable storage media can be tangible devices capable of holding and storing instructions for use by an instruction execution device. Computer-readable storage media can be, for example—but not limited to—electrical storage devices, magnetic storage devices, optical storage devices, electromagnetic storage devices, semiconductor storage devices, or any suitable combination of the foregoing. More specific examples (a non-exhaustive list) of computer-readable storage media include: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), static random access memory (SRAM), portable compact disc read-only memory (CD-ROM), digital multifunction disc (DVD), memory sticks, floppy disks, mechanical encoding devices, such as punch cards or recessed protrusions storing instructions thereon, and any suitable combination of the foregoing. The computer-readable storage media used herein are not to be construed as transient signals themselves, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through waveguides or other transmission media (e.g., light pulses through fiber optic cables), or electrical signals transmitted through wires.

[0172] The computer-readable program instructions described herein can be downloaded from computer-readable storage media to various computing / processing devices, or downloaded via a network, such as the Internet, local area network, wide area network, and / or wireless network, to an external computer or external storage device. The network may include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers, and / or edge servers. A network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards them to the computer-readable storage media in the respective computing / processing device.

[0173] Computer program instructions used to perform the operations of this disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, status setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Smalltalk, C++, etc., and conventional procedural programming languages ​​such as the "C" language or similar programming languages. The computer-readable program instructions may execute entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or may be connected to an external computer (e.g., via the Internet using an Internet service provider). In some embodiments, electronic circuitry, such as programmable logic circuitry, field-programmable gate arrays (FPGAs), or programmable logic arrays (PLAs), is personalized by utilizing the status information of the computer-readable program instructions to implement various aspects of this disclosure.

[0174] Various aspects of this disclosure are described herein with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this disclosure. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer-readable program instructions.

[0175] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus to produce a machine such that, when executed by the processor of the computer or other programmable data processing apparatus, they create means for implementing the functions / actions specified in one or more blocks of the flowchart and / or block diagram. These computer-readable program instructions can also be stored in a computer-readable storage medium that causes a computer, programmable data processing apparatus, and / or other device to operate in a particular manner; thus, the computer-readable medium storing the instructions comprises an article of manufacture that includes instructions for implementing aspects of the functions / actions specified in one or more blocks of the flowchart and / or block diagram.

[0176] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to perform the functions / actions specified in one or more boxes of a flowchart and / or block diagram.

[0177] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of an instruction containing one or more executable instructions for implementing a specified logical function. In some alternative implementations, the functions marked in the blocks may occur in a different order than those shown in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

[0178] The various embodiments of this disclosure have been described above. These descriptions are exemplary and not exhaustive, nor are they limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is chosen to best explain the principles, practical application, or technical improvements to the embodiments in the market, or to enable others skilled in the art to understand the embodiments disclosed herein.

Claims

1. A method for training a text encoding model, characterized in that, The method comprises the following steps: obtaining a training data set, wherein the training data set comprises case information of a plurality of query cases and case information of positive cases and negative cases corresponding to each query case, wherein the positive cases and the negative cases are determined according to judgment information and case information of the cases, the judgment information comprises law articles and charges involved in the cases, a similarity score between each query case and each case in a preset case library is determined according to law article coincidence degree and charge coincidence degree between the judgment information of each query case and the judgment information of each case in the preset case library, the second case set corresponding to each query case is determined from the preset case library according to the similarity score, the second case set comprises a plurality of cases having similar judgments with the query case, the positive case and the negative case corresponding to each query case are determined from the second case set corresponding to each query case, and the relevance between each query case and the corresponding positive case is higher than the relevance between each query case and the corresponding negative case; encoding the case information in the training data set by using a text encoding model to obtain a case feature set corresponding to the training data set; and training the text encoding model based on a mask language loss, wherein the model parameters of the text encoding model are optimized by back propagation and gradient descent based on the mask language loss; determining a first relevance score between each query case and the corresponding positive case and a second relevance score between each query case and the corresponding negative case according to the case feature set corresponding to the training data set; determining a contrast learning loss according to the first relevance score and the second relevance score, and training the text encoding model based on the contrast learning loss.

2. The method of claim 1, wherein, The method comprises the following steps: obtaining case information and judgment information of a plurality of cases in a preset case library, wherein the case information comprises fact descriptions; taking each case in the preset case library as a query case, and determining a first case set corresponding to each query case from the preset case library according to text similarity between the case information of each query case and the case information of each case in the preset case library, wherein the first case set comprises a plurality of cases having similar fact descriptions with the query case; for the first case set corresponding to each query case, taking the cases having the same judgment information as each query case in the first case set as the positive case corresponding to each query case, and taking the cases having different judgment information from each query case in the first case set as the negative case corresponding to each query case.

3. The method of claim 1, wherein, The method comprises the following steps: obtaining case information and judgment information of a plurality of cases in a preset case library; taking each case in the preset case library as a query case; determining the positive case and the negative case corresponding to each query case from the second case set corresponding to each query case according to text similarity between the case information of each query case and the case information of each case in the second case set corresponding to each query case.

4. The method of claim 3, wherein, The similarity score between each query case and each case in the preset case library is determined according to the law article coincidence degree and the charge coincidence degree between the judgment information of each query case and the judgment information of each case in the preset case library, and the similarity score between each query case and each case in the preset case library is determined according to the law article coincidence degree and the charge coincidence degree between the judgment information of each query case and the judgment information of each case in the preset case library, comprising: According to the law articles involved in each case in the preset case library, the coincidence law articles between each query case and each case in the preset case library are determined; According to the number of times of the coincidence law articles appearing in the preset case library, the law article coincidence degree between each query case and each case in the preset case library is determined; According to the charges involved in each case in the preset case library, the charge coincidence degree between each query case and each case in the preset case library is determined; According to the law article coincidence degree and the charge coincidence degree, the similarity score between each query case and each case in the preset case library is determined.

5. The method of claim 3, wherein, According to the text similarity between the case information of each query case and the case information of each case in the second case set corresponding to each query case, the positive case and the negative case corresponding to each query case are determined from the second case set corresponding to each query case, comprising: For any query case and the corresponding second case set, according to the text similarity between the case information of the query case and the case information of each case in the corresponding second case set, the multiple cases in the second case set are arranged in descending order or ascending order to obtain the descending order result or the ascending order result; The first n cases in the descending order result are taken as the positive cases of the query case, and the last m cases in the descending order result are taken as the negative cases of the query case, n and m are positive integers; or, The first n cases in the ascending order result are taken as the negative cases of the query case, and the last m cases in the ascending order result are taken as the positive cases of the query case.

6. The method of claim 1, wherein, The case information in the training data set is encoded by using a text encoding model to obtain the case feature set corresponding to the training data set, comprising: The case information of the query case, the case information of the positive case and the case information of the negative case in the training data set are respectively input into the text encoding model for encoding to obtain the case features corresponding to the query case, the positive case and the negative case in the training data set, and the case feature set comprises the case features corresponding to the query case, the positive case and the negative case in the training data set; According to the case features of each query case and the case features of the positive case corresponding to each query case, the first correlation score between each query case and the corresponding positive case is determined; According to the case features of each query case and the case features of the negative case corresponding to each query case, the second correlation score between each query case and the corresponding negative case is determined. ​ 7. The method of claim 1, wherein, The case information in the training data set is encoded by using the text encoding model to obtain a case feature set corresponding to the training data set, including: The case information of each query case and the case information of the corresponding positive case are jointly input into the text encoding model for encoding to obtain the first case feature between each query case and the corresponding positive case; The case information of each query case and the case information of the corresponding negative case are jointly input into the text encoding model for encoding to obtain the second case feature between each query case and the corresponding negative case; The case feature set includes the first case feature between each query case and the corresponding positive case, and the second case feature between each query case and the corresponding negative case; The first relevance score between each query case and the corresponding positive case, and the second relevance score between each query case and the corresponding negative case are determined according to the case feature set corresponding to the training data set, including: The first relevance score between each query case and the corresponding positive case is determined according to the first case feature between each query case and the corresponding positive case; The second relevance score between each query case and the corresponding negative case is determined according to the second case feature between each query case and the corresponding negative case.

8. The method according to any one of claims 1 to 7, characterized in that, The method further includes: The text encoding model is pre-trained by using a plurality of legal documents in a legal corpus, the legal documents including at least one of the following: official documents in the legal field, judgment documents; The text encoding model is pre-trained by using a legal corpus, including: Based on a preset shielding ratio, a part of real words in each legal document is shielded to obtain a shielded legal document, and the text encoding model is used to encode the shielded legal document to obtain a document feature corresponding to the shielded legal document; Based on the document feature corresponding to the shielded legal document, the shielded real words in the shielded legal document are predicted to obtain predicted words corresponding to the shielded legal document; According to the predicted words corresponding to the shielded legal document and the shielded real words in the shielded legal document, a shielding language loss is determined, and the text encoding model is trained according to the shielding language loss.

9. A case search method characterized by comprising: Including: Obtain the case information of the target case of the case to be searched; The case information of the target case is encoded by using a first text encoding model to obtain a case feature corresponding to the target case, wherein the first text encoding model is trained by the text encoding model training method of any one of claims 1-6 or 8; Based on the case feature corresponding to the target case and the case features of a plurality of judged cases in the target case library, the same type case of the target case is determined from the target case library.

10. The method of claim 9, wherein, The same case of the target case is determined from the target case library based on the case characteristics corresponding to the target case and the case characteristics of a plurality of judged cases in the target case library, and the same case of the target case is determined from the target case library based on the case characteristics corresponding to the target case and the case characteristics of a plurality of judged cases in the target case library, comprising: Determine a plurality of initial same cases corresponding to the target case from the target case library based on the case characteristics corresponding to the target case and the case characteristics of a plurality of judged cases in the target case library; Input the case information of each initial same case and the case information of the target case into a second text coding model to code, to obtain the case characteristics between each initial same case and the target case, wherein the second text coding model is trained by the text coding model training method in any one of claims 1-5, 7-8; Determine the same case of the target case from the plurality of initial same cases according to the case characteristics between each initial same case and the target case. 11.A text encoding model training apparatus, characterized by comprising: Comprising: An acquisition module is configured to acquire a training data set, wherein the training data set includes case information of a plurality of query cases, and case information of positive cases and negative cases corresponding to each query case, wherein the positive cases and the negative cases are determined according to judgment information and case information of the cases, the judgment information includes law articles and charges involved in the cases, a similarity score between each query case and each case in a preset case library is determined according to a law article coincidence degree and a charge coincidence degree between the judgment information of each query case and the judgment information of each case in the preset case library, a second case set corresponding to each query case is determined from the preset case library according to the similarity score, the second case set includes a plurality of cases having similar judgments with the query case, and the positive cases and the negative cases corresponding to each query case are determined from the second case set corresponding to each query case, and the relevance between each query case and the corresponding positive case is higher than the relevance between each query case and the corresponding negative case; An encoding module is configured to code the case information in the training data set by using a text coding model to obtain a case feature set corresponding to the training data set, and train the text coding model based on a masking language loss, wherein the model parameters of the text coding model are optimized by back propagation and gradient descent based on the masking language loss; A determination module is configured to determine a first relevance score between each query case and the corresponding positive case, and a second relevance score between each query case and the corresponding negative case according to the case feature set corresponding to the training data set; A training module is configured to determine a contrastive learning loss according to the first relevance score and the second relevance score, and train the text coding model based on the contrastive learning loss.

12. A case search apparatus characterized by comprising: Comprising: An information acquisition module is configured to acquire case information of a target case of a case to be searched. An information encoding module is configured to encode case information of the target case by using a first text encoding model to obtain case features corresponding to the target case, wherein the first text encoding model is trained by the text encoding model training method in any one of claims 1 to 6 or 8. A case determination module is configured to determine a similar case of the target case from a target case library based on the case features corresponding to the target case and case features of a plurality of judged cases in the target case library.

13. An electronic device, comprising: comprising: a processor; a memory for storing processor-executable instructions; wherein the processor is configured to implement the method of any one of claims 1 to 10 when executing the instructions stored in the memory.

14. A non-transitory computer readable storage medium having stored thereon computer program instructions, wherein, The computer program instructions, when executed by the processor, implement the method of any one of claims 1 to 10. The computer program instructions, when executed by the processor, implement the method of any one of claims 1 to 10.

Citation Information

Patent Citations

  • Semantic matching model training method and system, retrieval system and device and medium

    CN112395426A

  • Long text retrieval model based on comparative learning

    CN114201581A