A method for constructing a legal event detection model based on a double prototype source and application thereof

CN118445621BActive Publication Date: 2026-08-11HUAZHONG UNIV OF SCI & TECH
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-17
Publication Date
2026-08-11

AI Technical Summary

Technical Problem

[0006]针对现有技术的以上缺陷或改进需求,本发明提供一种基于双原型源的法律事件检测模型构建方法与应用,用以解决现有技术的无法在小样本场景下准确地进行法律事件检测的技术问题

Benefits of technology

[0040]1、本发明提供了一种基于双原型源的法律事件检测模型构建方法,针对样本少,同种事件类型表述各异,相似事件类型难以区分的情况,利用事件标签信息和事件提及作为双原型源,在两个分支同时训练,通过最小化输入法律文本与对应法律事件类型标签下的模板提示文本的特征向量之间的距离,以及法律事件类型标签相同的法律文本之间的特征向量之间的距离,充分利用了有限的训练样本,使模型学习到不同事件类型的细微语义差别和同种事件类型在具体语言表达上的丰富多样性,提高了在小样本场景下法律事件检测的准确性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118445621B_ABST
    Figure CN118445621B_ABST
Patent Text Reader

Abstract

This invention discloses a method and application for constructing a legal event detection model based on dual prototype sources, belonging to the field of artificial intelligence technology. Addressing situations where samples are limited, descriptions of the same event type vary, and similar event types are difficult to distinguish, this invention utilizes event label information and event mentions as dual prototype sources, training simultaneously on two branches. By minimizing the distance between the feature vectors of the input legal text and the template prompt text under the corresponding legal event type label, as well as the distance between the feature vectors of legal texts with the same legal event type label, it fully utilizes the limited training samples, enabling the model to learn the general features of different event types and the rich diversity of linguistic expressions, thus improving the accuracy of legal event detection in small-sample scenarios.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of artificial intelligence technology, and more specifically, relates to a method and application for constructing a legal event detection model based on dual prototype sources. Background Technology

[0002] As a crucial component of my country's modernization of social governance, the construction of smart justice relies on big data and artificial intelligence technologies to conduct in-depth analysis and application of legal data, which is of great significance to the modernization of my country's social governance. While court judgments can better assist legal professionals in their adjudication work, contributing to judicial transparency and promoting fairness in social governance, their main content remains lengthy, unstructured text, requiring practitioners to spend considerable time and effort extracting valuable information. To help judicial professionals quickly obtain key case information and strongly promote downstream research on AI-based smart justice, it is necessary to structure court judgments and extract key information.

[0003] Court judgments present a greater challenge to event detection tasks due to the large number of specialized terms, complex semantic descriptions, and diverse event types contained in their texts, especially the existence of the same event expressed in different ways and similar events with subtle semantic differences.

[0004] In existing legal event detection tasks, current work mostly relies on pre-training and fine-tuning to train legal event detection models, which requires a large amount of labeled supervision data. However, as the judicial process continues to advance, new types of legal events will emerge. In scenarios with few samples, the sparsity of training data will further exacerbate the problems such as limited legal text event features learned by the model, and subtle differences between similar cases leading to misjudgments by the model. As a result, the model cannot accurately detect legal events, which in turn affects downstream related tasks (such as judgment prediction and case retrieval).

[0005] Therefore, research is needed on legal event detection models in scenarios with few samples to better promote the effective use of unstructured data in judgment documents and improve judicial efficiency. Summary of the Invention

[0006] In view of the above-mentioned defects or improvement needs of the existing technology, the present invention provides a method and application for constructing a legal event detection model based on dual prototype sources, so as to solve the technical problem that the existing technology cannot accurately detect legal events in small sample scenarios.

[0007] To achieve the above objectives, in a first aspect, the present invention provides a method for constructing a legal event detection model based on dual prototype sources, comprising:

[0008] S1. Training the legal feature extraction module:

[0009] For each legal text in the pre-collected training set, the feature vector of the legal text and the feature vector of the template prompt text under the corresponding legal event type label are obtained through the legal feature extraction module, and the distance between the two is calculated and denoted as the first distance.

[0010] Two legal texts with the same legal event type label in the training set are formed into a positive sample pair. The distance between the feature vectors of each legal text in each positive sample pair is calculated and denoted as the second distance.

[0011] The legal feature extraction module is trained by minimizing the first distance corresponding to each legal text and the second distance corresponding to each positive sample pair.

[0012] S2. After training, a legal event detection model including a cascaded feature extraction module and a decision maker is constructed to perform legal event detection.

[0013] The decision-maker is used to calculate the distance between the feature vector of the legal text to be detected and each feature vector in the feature vector set, and takes the legal event type corresponding to the minimum distance as the final detection result. The feature vector set includes the feature vectors of template prompt texts under different legal event types obtained by the legal feature extraction module after training.

[0014] More preferably, step S1 further includes:

[0015] Two legal texts with different legal event type labels in the training set are formed into a negative sample pair. The distance between the feature vectors of each legal text in each negative sample pair is calculated and denoted as the third distance.

[0016] While minimizing the first distance corresponding to each legal text and the second distance corresponding to each positive sample pair, the third distance corresponding to each negative sample pair is maximized to train the legal feature extraction module.

[0017] More preferably, the method for constructing the legal event detection model further includes:

[0018] For each legal text in the training set, generate corresponding adversarial samples to form an adversarial sample set; and input the adversarial sample set into the legal feature extraction module for training according to the training method in step S1, so as to realize the adversarial training of the legal feature extraction module.

[0019] More preferably, the legal feature extraction module includes: a cascaded tokenization layer, an embedding layer, a pre-trained language model, a pooling layer, and a normalization layer.

[0020] More preferably, the process of obtaining the legal text feature vector through the legal feature extraction module includes:

[0021] The legal text is input into the legal feature extraction module, and after passing through the tokenization layer, embedding layer, and pre-trained language model, the corresponding high-dimensional feature encoding of the text is obtained, including the high-dimensional features of each token in the legal text. The high-dimensional features of each token contained in the pre-annotated trigger words in the legal text are extracted and input into the pooling layer to obtain the legal text feature vector.

[0022] More preferably, before training the legal feature extraction module, the pre-trained language model therein is pre-trained in a task-oriented manner using the following method:

[0023] Each legal judgment document in the pre-collected legal domain text corpus dataset is tokenized to obtain the corresponding token sequence. The tokens representing the semantic features of legal events in the token sequence are masked and embedded, and then input into the pre-trained language model for MLM pre-training.

[0024] More preferably, the tokens in the token sequence that represent the semantic features of legal events include tokens that are verbs.

[0025] More preferably, the tokens representing the semantic features of legal events in the token sequence include: trigger word tokens obtained after inputting the token sequence into the trigger word detection model;

[0026] The trigger word detection model is obtained through the following methods:

[0027] Each legal text in the training set is tokenized to obtain a corresponding token sequence, which is then input into the first neural network model to detect whether each token in the token sequence is a trigger word token. The first neural network model is trained by minimizing the difference between the detection result and the corresponding trigger word judgment result. The trained first neural network model is then used as the trigger word detection model.

[0028] The trigger word determination result is obtained based on the preset trigger words corresponding to the legal text, including whether each token in the token sequence of the legal text is a real trigger word token.

[0029] More preferably, the tokens representing the semantic features of legal events in the token sequence include: important tokens obtained after inputting the token sequence into the important token detection model;

[0030] The important token detection model is obtained through the following methods:

[0031] For each legal text in the training set: tokenize it, and add each token in the resulting token sequence to the initially empty sequence Q in sequence; input the sequence Q after each token addition into the detection model M0 to detect the legal event type and obtain the probability that the detection result is the corresponding legal event type label; for each token, calculate the absolute value of the difference between the probabilities before and after adding the token, and use it as the contribution of the token; tokens with a contribution greater than a preset threshold are used as important token labels corresponding to the legal text.

[0032] Each legal text in the training set is tokenized to obtain a corresponding token sequence, which is then input into the second neural network model to detect whether each token in the token sequence is an important token. The second neural network model is trained by minimizing the difference between the detection result and the corresponding important token judgment result. The trained second neural network model is then used as the important token detection model.

[0033] The detection model M0 is obtained by tokenizing the legal texts in the training set and then inputting them into the third neural network model for training. The true result of important token judgment is obtained based on the important token labels corresponding to the legal texts, including the true information of whether each token in the token sequence of the legal text is an important token.

[0034] Secondly, the present invention provides a legal event detection method, comprising:

[0035] The text to be detected is input into the legal event detection model constructed by the legal event detection model construction method provided in the first aspect of the present invention. The feature vector of the text to be detected is obtained by the feature extraction module in the legal event detection model. The distance between the feature vector of the legal text and each feature vector in the feature vector set is calculated by the decision-maker in the legal event detection model. The legal event type corresponding to the minimum distance is taken as the final detection result.

[0036] The feature vector set includes feature vectors of template prompt texts for different legal event types obtained through the legal feature extraction module.

[0037] Thirdly, the present invention provides an electronic device, a memory, and a processor, comprising: the memory storing a computer program, and the processor executing the computer program to perform the method provided in the first or second aspect of the present invention.

[0038] Fourthly, the present invention also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, performs the method provided in the first or second aspect of the present invention.

[0039] In summary, the above-described technical solutions conceived in this invention can achieve the following beneficial effects:

[0040] 1. This invention provides a method for constructing a legal event detection model based on dual prototype sources. Addressing situations where samples are limited, descriptions of the same event type vary, and similar event types are difficult to distinguish, this method utilizes event tag information and event mentions as dual prototype sources. Training is performed simultaneously on two branches. By minimizing the distance between the feature vectors of the input legal text and the template prompt text under the corresponding legal event type label, as well as the distance between the feature vectors of legal texts with the same legal event type label, the method fully utilizes limited training samples. This allows the model to learn the subtle semantic differences between different event types and the rich diversity of specific linguistic expressions for the same event type, thereby improving the accuracy of legal event detection in small-sample scenarios.

[0041] 2. Furthermore, the legal event detection model construction method provided by this invention introduces a contrastive learning strategy on the event mention branch, which narrows the distance between legal texts with the same legal event type label and further widens the differences between legal texts with different legal event type labels. This reduces the potential negative impact of subtle differences in legal terminology on the few-sample event detection results, better learns the features of subtle semantic differences between similar event types, further improves the model's ability to distinguish similar event types, and enhances the applicability and robustness of the model in few-sample practical applications.

[0042] 3. Furthermore, the legal event detection model construction method provided by this invention introduces adversarial training during joint optimization training, which enables the legal event detection model to have excellent ability to capture and distinguish subtle differences between legal events, thereby further improving the accuracy, generalization and robustness of the legal event detection model.

[0043] 4. Furthermore, the legal event detection model construction method provided by this invention, through the legal feature extraction module, obtains the legal text feature vector. After obtaining the corresponding high-dimensional feature encoding of the text through a pre-trained language model, it extracts the high-dimensional features of each token contained in the pre-annotated trigger words in the legal text, performs pooling processing, and obtains the legal text feature vector. Since the high-dimensional feature vector of each token contains the semantic information of the entire context after pre-training the language model, the high-dimensional feature vector of the token contained in the trigger words contains the richest event information (the event information expressed by the trigger words and the contextual semantic information). Compared with directly pooling the high-dimensional features of the entire text, the feature vector extracted by this invention focuses on the trigger word part related to the event, which is more intuitive and clear, and reduces the interference of irrelevant information, further improving the accuracy of detection.

[0044] 5. Furthermore, the legal event detection model construction method provided by this invention pre-trains the pre-trained language model before training the legal feature extraction module: during the training of the text feature extraction module, the tokens representing the semantic features of legal events in the token sequence corresponding to the factual text of legal judgment documents in the legal domain text corpus dataset are masked and then input into the text feature extraction module for MLM pre-training; this invention achieves task-oriented domain pre-training for legal event detection through a selective masking strategy based on legal event features, thereby associating the training of the pre-trained language model in the text feature extraction module with the legal event detection task, possessing good perception and understanding and feature extraction capabilities for key elements of legal events, and significantly improving the accuracy of legal event detection.

[0045] 6. Furthermore, the legal event detection model construction method provided by this invention proposes a verb-based selective masking strategy. Considering that verbs in text often represent action trigger words for related events, these verbs can be selectively masked during the pre-training stage, which can further achieve close association with downstream legal event detection tasks with lower computational cost.

[0046] 7. Furthermore, the legal event detection model construction method provided by this invention considers that trigger words containing rich legal event feature information are not all verbs, but may also be other parts of speech. Therefore, the selective masking strategy based on verbs may not enable the text feature extraction module to fully understand the event features. Based on this, this invention proposes a selective masking strategy based on trigger words. The trigger word detection model is trained on an event detection task dataset carrying preset trigger words as a selective masking model to selectively mask the text in the legal domain text corpus dataset. This method can further optimize the legal event detection model's ability to understand and process the event features of specific judgment documents.

[0047] 8. Furthermore, the legal event detection model construction method provided by this invention considers that the accuracy of the selective masking model used in a trigger word-based selective masking strategy depends on the setting of trigger words in the training set and is subject to the influence of the subjective judgment of the annotators, especially in the complex and highly specialized legal field. Based on this, this invention proposes a token contribution-based selective masking strategy. By training an important token detection model, important tokens with higher contribution to the downstream legal event detection task in the input text are obtained and masked. This strategy considers not only whether the word itself is a potential trigger word, but also its specific context. It identifies which specific words in which contexts contribute more to the downstream legal event detection task, and then prioritizes masking words in these contexts to further improve the accuracy of legal event detection. Attached Figure Description

[0048] Figure 1 A schematic diagram illustrating the construction process of the legal event detection model provided in this embodiment of the invention;

[0049] Figure 2 A flowchart for obtaining legal text feature vectors through a legal feature extraction module, provided in an embodiment of the present invention;

[0050] Figure 3 Example diagrams for using a large language model to complete the detection of few-sample legal events provided in embodiments of the present invention;

[0051] Figure 4 This is a schematic diagram of the legal event detection process provided in an embodiment of the present invention. Detailed Implementation

[0052] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention. Furthermore, the technical features involved in the various embodiments of this invention described below can be combined with each other as long as they do not conflict with each other.

[0053] To achieve the above objectives, in a first aspect, the present invention provides a method for constructing a legal event detection model based on dual prototype sources, comprising:

[0054] S1. Training the legal feature extraction module:

[0055] For each legal text in the pre-collected training set, the feature vector of the legal text and the feature vector of the template prompt text under the corresponding legal event type label are obtained through the legal feature extraction module, and the distance between the two is calculated and denoted as the first distance.

[0056] Two legal texts with the same legal event type label in the training set are formed into a positive sample pair. The distance between the feature vectors of each legal text in each positive sample pair is calculated and denoted as the second distance.

[0057] The legal feature extraction module is trained by minimizing the first distance corresponding to each legal text and the second distance corresponding to each positive sample pair.

[0058] S2. After training, a legal event detection model, denoted as FLED model, is constructed, which includes a cascaded feature extraction module and a decision maker, for legal event detection.

[0059] The decision-maker is used to calculate the distance between the feature vector of the legal text to be detected and each feature vector in the feature vector set, and takes the legal event type corresponding to the minimum distance as the final detection result. The feature vector set includes the feature vectors of template prompt texts under different legal event types obtained by the legal feature extraction module after training.

[0060] This invention uses both event tag information and event mentions as dual prototype sources, and trains simultaneously on two branches, so that the final event detection model can make full use of the limited training samples.

[0061] It should be noted that the training set in this invention is an event detection task dataset, including legal texts carrying legal event type labels; when measuring distance, Euclidean distance, scaled cosine distance, scaled Euclidean distance, KL divergence, etc., can be used. The loss function used to train the legal feature extraction module can be cross-entropy loss, focusing loss, label smoothing loss, etc., and is not limited here.

[0062] In one optional implementation, step S1 further includes:

[0063] Two legal texts with different legal event type labels in the training set are formed into a negative sample pair. The distance between the feature vectors of each legal text in each negative sample pair is calculated and denoted as the third distance.

[0064] While minimizing the first distance corresponding to each legal text and the second distance corresponding to each positive sample pair, the third distance corresponding to each negative sample pair is maximized to train the legal feature extraction module.

[0065] By incorporating contrastive learning into the event mention branch, the model's ability to distinguish different types of events in a limited number of samples is further enhanced. This results in a better understanding of easily confused events and improves the model's applicability and robustness in real-world applications with limited sample sizes.

[0066] In one optional implementation, the method for constructing the above-mentioned legal event detection model further includes:

[0067] For each legal text in the training set, a corresponding adversarial sample is generated, forming an adversarial sample set. Following the training method in step S1, the adversarial sample set is input into the legal feature extraction module for training, thereby achieving adversarial training of the legal feature extraction module.

[0068] Introducing adversarial training into both branches can significantly improve the robustness and generalization ability of the model against adversarial noise.

[0069] It should be noted that the aforementioned legal feature extraction module can be TF-IDF, bag-of-words model, Word2Vec, etc. Preferably, in one optional implementation, the legal feature extraction module includes: a cascaded tokenization layer, an embedding layer, a pre-trained language model, a pooling layer, and a normalization layer; wherein, the pre-trained language model can be BERT model, RoBERTa model, DeBERTa model, etc., and is not limited here. The pooling layer can be average pooling layer, max pooling layer, random pooling layer, hybrid pooling layer, etc., and is not limited here.

[0070] In one optional implementation, the legal text is pre-annotated with trigger words; the process of obtaining the feature vector of the legal text through the legal feature extraction module includes:

[0071] The legal text is input into the legal feature extraction module, and after passing through the tokenization layer, embedding layer, and pre-trained language model, the corresponding high-dimensional feature encoding of the text is obtained, including the high-dimensional features of each token in the legal text. The high-dimensional features of each token contained in the pre-annotated trigger words in the legal text are extracted and input into the pooling layer to obtain the legal text feature vector.

[0072] Preferably, the pooling layer is an average pooling layer;

[0073] The feature vector of the legal text is:

[0074]

[0075] in, The high-dimensional feature of the k-th token in the legal text; trigger start and trigger end These are the position indices of the first and last tokens contained in the pre-marked trigger words in the legal text.

[0076] In one alternative implementation, before training the legal feature extraction module, the pre-trained language model therein is pre-trained in a task-oriented manner in the following way:

[0077] Each legal judgment document in the pre-collected legal domain text corpus dataset is tokenized to obtain the corresponding token sequence. The tokens representing the semantic features of legal events in the token sequence are masked and embedded, and then input into the pre-trained language model for MLM pre-training.

[0078] In one alternative implementation, the tokens representing the semantic features of legal events in the token sequence include tokens with the part of speech of verbs.

[0079] In one optional implementation, the tokens representing the semantic features of legal events in the token sequence include: trigger word tokens obtained after inputting the token sequence into the trigger word detection model;

[0080] The trigger word detection model is obtained through the following methods:

[0081] Each legal text in the training set is tokenized to obtain a corresponding token sequence, which is then input into the first neural network model to detect whether each token in the token sequence is a trigger word token. The first neural network model is trained by minimizing the difference between the detection result and the corresponding trigger word judgment result. The trained first neural network model is then used as the trigger word detection model.

[0082] The trigger word determination result is obtained based on the preset trigger words corresponding to the legal text, including whether each token in the token sequence of the legal text is a real trigger word token.

[0083] It should be noted that the first neural network model mentioned above can be a CNN, RNN, GNN, Transformer model, etc., and is not limited here. The loss function used to train the first neural network model can be a cross-entropy loss function, a focusing loss function, a label smoothing loss function, etc., and is not limited here.

[0084] In one optional implementation, the tokens representing the semantic features of legal events in the token sequence include: important tokens obtained after inputting the token sequence into the important token detection model;

[0085] The important token detection model is obtained through the following methods:

[0086] For each legal text in the training set: tokenize it, and add each token in the resulting token sequence to the initially empty sequence Q in sequence; input the sequence Q after each token addition into the detection model M0 to detect the legal event type and obtain the probability that the detection result is the corresponding legal event type label; for each token, calculate the absolute value of the difference between the probabilities before and after adding the token, and use it as the contribution of the token; tokens with a contribution greater than a preset threshold are used as important token labels corresponding to the legal text.

[0087] Each legal text in the training set is tokenized to obtain a corresponding token sequence, which is then input into the second neural network model to detect whether each token in the token sequence is an important token. The second neural network model is trained by minimizing the difference between the detection result and the corresponding important token judgment result. The trained second neural network model is then used as the important token detection model.

[0088] The detection model M0 is obtained by tokenizing the legal texts in the training set and then inputting them into the third neural network model for training. The true result of important token judgment is obtained based on the important token labels corresponding to the legal texts, including the true information of whether each token in the token sequence of the legal text is an important token.

[0089] It should be noted that the second neural network model mentioned above can be a CNN, RNN, GNN, Transformer model, etc., without limitation. The third neural network model can be a CNN, RNN, GNN, Transformer-based model, etc.; preferably, the third neural network model includes cascaded embedding layers, a pre-trained language model, and a classification module; wherein, the pre-trained language model can be a BERT model, RoBERTa model, DeBERTa model, etc., and is a pre-trained language model trained on a general domain text corpus dataset. The loss function used to train the second and third neural network models can be the cross-entropy loss function, the focusing loss function, the label smoothing loss function, etc., without limitation.

[0090] In one alternative implementation, the contribution of the i-th token in the token sequence is:

[0091]

[0092] Where, x i Let i be the i-th token in the token sequence; Let Q be the sequence after adding the first i tokens and inputting it into the detection model M0. Let Q be the probability that the detection result is the corresponding legal event type label. Let Q be the sequence after adding the first i-1 tokens and inputting it into the detection model M0. Let Q be the probability that the detection result is the corresponding legal event type label.

[0093] To further illustrate the construction method of the legal event detection model provided by this invention, a specific embodiment is described in detail below:

[0094] The entire construction process of the legal event detection model in this embodiment is as follows: Figure 1 As shown, the training of the legal feature extraction module includes the training of two branches: the event tag prototype branch and the event mention prototype branch.

[0095] 1) For event label prototype branches:

[0096] The names and related explanations of legal event types are highly representative in the prototype space of this type of sample. Using the label information of different event types as the prototype source, the label information includes the name of the legal event type and the meaning of the event. The meaning of the event comes from the explanations in the relevant dataset annotation manual. Therefore, for each legal event type, this information is used to construct a prompt template. Specifically, in this embodiment, the "personal injury" event type is taken as an example. Its meaning is "harming the physical health of others, usually manifested as beating, striking, etc." Three template prompt texts can be designed, as shown in Table 1.

[0097] Table 1

[0098]

[0099] Additionally, events with unknown legal event types, i.e., those labeled "None," are not considered.

[0100] Each type of legal event forms a prototype source after a prototype template is constructed. During training, both the input legal text and the prototype source template prompt text are encoded using a pre-trained language model to obtain their text embedding representations. In this embodiment, the pre-trained language model is the model after task-oriented pre-training; specifically, in this embodiment, the pre-trained language model before task-oriented pre-training uses the RoBERTa model, and after task-oriented pre-training for legal event detection, the resulting pre-trained language model for event detection is denoted as the LED-RoBERTa model. Let X be the input legal text. N is the text length, Y is the corresponding legal event type, and m Y Template prompt text for a certain type of legal event. M is the template length. Let h be... X and Encode the high-dimensional features of these two texts, where This includes the high-dimensional features of each token in the legal text; dim is the dimension of the encoder's hidden layer; then:

[0101] h X =Encoder(X)

[0102]

[0103] h X and Through high-dimensional feature representations, these embeddings capture the semantic information and contextual relationships of the input judgment documents. Furthermore, since the encoder uses the task-oriented pre-trained LED-RoBERTa model, these feature vectors also learn more complex semantic information for the event detection task.

[0104] For the input legal text, based on pre-defined trigger word information, a high-dimensional event feature information is extracted from the text through an average pooling layer to obtain the legal text feature vector; such as Figure 2 As shown:

[0105] Taking the legal text "Villagers believe that Liu has encroached on collective land" as an example, the trigger word is "encroachment". Assuming that for this text, the legal text feature vector extracted by the average pooling layer is f... X Then f X It can be represented as:

[0106]

[0107] in, The high-dimensional feature of the k-th token in the legal text; trigger start and trigger end These are the position indices of the first and last tokens contained in the pre-marked trigger words in the legal text.

[0108] exist Figure 2 In the example, since the trigger word is "embezzlement", the mean of the high-dimensional features corresponding to the two tokens will be calculated to obtain the extracted legal text feature vector f. X .

[0109] For the template prompt text under the legal event type label, the extracted template prompt text feature vector is: Represented as:

[0110]

[0111] in, The high-dimensional feature of the k-th token in the template prompt text; the high-dimensional feature of the i-th token in the legal text; prompt start and prompt end These are the position indices of the first and last tokens contained in the template prompt text, respectively; That is, average pooling is performed on the high-dimensional features of the entire prompt template text to obtain the extracted template prompt text feature vector.

[0112] After obtaining the feature vectors of the legal text and the template prompt text, in order to better perform calculations in the same distance measurement space, ensure that all feature vectors are on a uniform scale, and avoid comparison biases caused by vector lengths when calculating related distance metrics (such as Euclidean distance), f is...X and Normalization is performed to avoid numerical instability during training and accelerate model convergence. Then, a distance metric function d(·,·) is used to calculate the distance between them. The closer the distance between two normalized feature vectors, the more similar the input legal text is to a certain legal event type, and the higher their similarity score. Therefore, the output of the event label prototype branch is:

[0113]

[0114] Among them, logits label This indicates that this is a prediction from the label prototype branch. The negative sign indicates that the smaller the distance between the two feature vectors, the closer the event type of the legal text X is to the corresponding legal event type label Y, and the larger the original prediction value of the model. In this embodiment, the distance metric function uses scaled Euclidean distance, then:

[0115]

[0116] Where τ is the scaling factor, f Xi and f represents the feature vector of the legal text, respectively. X and the corresponding template prompt text feature vector The i-th element in the expression, dim, represents the vector dimension, i.e., the size of the hidden layer in the model encoder. (logits) label The final predicted probability is obtained by applying Softmax to (Y|X):

[0117] P label (Y|X)=Softmax(logits label (Y|X))

[0118] Based on probability P label (Y|X) yields the prediction result of the event label prototype branch.

[0119] 2) For the event mentioning prototype branch:

[0120] In the prototype branch mentioned in the event, this embodiment uses a contrastive learning approach, taking into account physical resource limitations. If the number of training samples is less than a threshold N, ... CL If the training sample size is large, then the intra-batch contrastive learning strategy can be used. If the training sample size is large, then the momentum contrastive learning strategy can be used to make more effective use of the training data.

[0121] During training, the text data input in the current batch is encoded using a pre-trained language model to obtain its text embedding representation. Let X be the input text data and Y be the corresponding legal event type, obtained through formula h. X=Encoder(X) and High-dimensional feature vectors are extracted from the input text embedding, and then legal text feature vectors f are further extracted through average pooling. X Then, at this point, the output logits of the prototype branch mentioned in the event are:

[0122]

[0123] Among them, f X For legal text feature vectors; logits mention (Y|X) represents the prediction of the prototype branch mentioned by the event; in this embodiment, the distance metric function d(·,·) is still the scaled Euclidean distance; S Y (X) = {X'|Y' = Y, X' ≠ X} is the positive sample set; X' is other legal texts in the training set with the same legal type label as legal text X. When using intra-batch contrastive learning, S Y (X) represents other legal texts in the current batch that have the same legal type label as legal text X. When using momentum contrastive learning, the model needs to maintain a dynamic memory queue to overcome the batch size limitation in intra-batch contrastive learning. Therefore, S Y (X) encompasses not only the legal texts within the current batch, but extends to a larger, dynamically updated sample library. This sample library contains feature vectors of legal texts from previous batches and can store a much larger set of samples than the current batch.

[0124] Based on logits mention (Y|X), after applying Softmax, yields the final predicted probability:

[0125] P mention (Y|X)=Softmax(logits mention (Y|X))

[0126] Based on the predicted probability P mention (Y|X) yields the prediction result for the prototype branch mentioned in the event.

[0127] 3) Joint optimization based on adversarial training

[0128] The overall joint optimization objective of the model requires combining the two branches. Therefore, after calculating the loss functions of the two prototype branches, they are weighted and merged. The final loss function is:

[0129] Loss = Loss label +λLoss mention

[0130] Among them, Loss label Cross-entropy loss for the event label prototype branch:

[0131]

[0132] Loss mention The contrast loss of the prototype part mentioned in the event:

[0133]

[0134] It should be noted that, in calculating the contrastive loss in this embodiment, the third distance corresponding to each negative sample pair is also maximized. A negative sample pair is a pair of legal texts with different legal event type labels in the training set. However, since this embodiment uses the cross-entropy loss function and applies logits... mention (Y|X) has undergone softmax processing, so the final expression is: Loss mention =-∑ (X,Y) Ylog(P mention (Y|X)).

[0135] In this embodiment, adversarial training is introduced simultaneously in the training process of the two branches of the legal feature extraction module. The FGM algorithm is used to generate adversarial perturbation samples for the embedding layer. By considering the original samples and their corresponding adversarial samples at the same time, the model is trained through backpropagation to improve its robustness to adversarial noise.

[0136] Specifically, to address the challenges of model generalization and robustness arising from complex and specialized legal documents and the long-tail distribution of datasets during the application phase, this embodiment introduces an adversarial training strategy during training. Specifically, the Fast Gradient Method (FGM) is used to generate adversarial examples by applying subtle, gradient-based perturbations to the input data at the embedding layer. By simultaneously considering the original samples and their corresponding adversarial examples, the model is trained through backpropagation to improve its robustness against adversarial noise.

[0137] Specifically, for a given input sample X and the corresponding parameter θ in the feature extraction module, the loss function Loss is expressed as Loss(X,Y; θ). FT ), where Y is the true label of X. Next, the gradient of the loss function with respect to the word embedding vector is calculated. Based on this gradient, a small perturbation δ is generated. The direction of this perturbation maximizes the loss, i.e., it moves towards the gradient ascent, increasing the model's output error. The formula for calculating the perturbation δ is as follows:

[0138]

[0139] Here, ε is a small constant used to control the magnitude of the perturbation, ensuring that the generated adversarial sample is perceptually close to the original sample, and the final generated adversarial sample X' = X + δ.

[0140] To enhance the generalization ability and robustness of the event detection model through adversarial training, both the original sample X and adversarial sample X' are incorporated into the training process. The feature extraction module learns to maintain stable predictions even in the face of minor perturbations, thereby improving robustness against potential adversarial attacks. This strategy enables the feature extraction module to identify and correct errors that may be caused by input perturbations during training, thus improving the robustness of the legal event detection model to input perturbations. Especially when dealing with complex legal texts, this adversarial training strategy helps the model generalize better to unseen samples and improves its performance when facing the long-tailed distribution characteristics of the dataset.

[0141] It should be noted that there are many adversarial training strategies, including FGSM, PGD, FreeAT, etc., in addition to the FGM algorithm. In order to balance the computational cost and efficiency of adversarial training, the FGM algorithm was selected in this embodiment.

[0142] To further illustrate the task-oriented pre-training process of the pre-trained language model provided by this invention, a specific embodiment is described in detail below:

[0143] This pre-training process was performed on a medium-sized legal text dataset D. legal The process is carried out on the ground and has a certain degree of domain adaptability. In order to better capture the patterns of event detection tasks in the legal domain, this stage adopts a selective masking strategy, which will selectively mask tokens in a text that are highly relevant to the event detection task. After the masking strategy is designed, task-oriented pre-training of EventPT is completed based on the masking strategy and the MLM task, thereby improving the correlation between pre-training and fine-tuning tasks.

[0144] This embodiment designs a selective masking strategy based on the semantic features of legal events. Three different schemes are designed from the perspectives of verbs, trigger words, and token contribution, each suitable for different application scenarios. This strategy yields a selective masking model, which is then applied to a medium-sized legal text corpus dataset D. legal The event detection task-oriented pre-training was carried out on the platform.

[0145] Based on their computational cost and model complexity, the three selective masking strategies are suitable for scenarios with high-weight verb trigger words, scenarios that balance efficiency and accuracy, and scenarios requiring high accuracy, respectively.

[0146] Option 1: Verb-based selective masking strategy

[0147] Intuitively, verbs in text often represent action triggers for related events; therefore, selective masking of these verbs can be performed during the pre-training phase. The specific strategy and corresponding task-oriented pre-training process are shown in Figure 3. Semantic Role Labeling (SRL) tools can be used to process the legal domain text corpus dataset D. legal The verbs are extracted from the data, and then the verbs are masked to obtain D. legal(masked) The corpus used for pre-training of legal event detection tasks was used to complete MLM pre-training.

[0148] However, analysis of the legal event detection dataset revealed that not all event trigger words are verbs. For example, in the text "The defendant and the victim reached a compensation agreement," "compensation" is tagged as a noun as a trigger word for a "compensation" type event. Another example is "(A document describing theft)...On September 5th, Zhang San was arrested for theft. After being brought to justice, during police interrogation, Zhang San confessed that he had given a bribe of 200,000 yuan two months prior, and therefore had been committing thefts in the city until now." This document describes theft, but the noun "bribe" appears separately at the end of the document. Since there are no other verbs in the document that reflect the "bribery" event implied by "bribe," the noun "bribe" is used as a trigger word for the "bribery" event. Such cases are not uncommon in the dataset.

[0149] Therefore, simply using verb tagging tools as tokens to represent the semantic features of legal events and then selectively masking them may prevent the model from fully understanding the event features. Consequently, it may be unable to comprehensively learn the word meaning, syntactic structure, and contextual information of text for event detection tasks, leaving room for improvement in the accuracy of downstream event detection tasks. Based on this, the present invention further provides a second solution.

[0150] Option 2: Selective masking strategy based on trigger words

[0151] Besides verb-based selective masking strategies, training a neural network to function as a masking tool is also an effective approach. Therefore, this scheme constructs a token-level classification neural network model on the training set D. event The model is trained on a binary classifier to assess whether a token is core content related to an event and needs to be masked. After training, this model can be used as a selective masking model in the pre-training process of legal language models, thereby optimizing the model's understanding and processing of specific court judgments.

[0152] If the fully supervised learning data for this selective masking model comes directly from the training set D event If the trigger words are already labeled, then this selective masking model can actually be used as a trigger word detection model. The training process for the trigger word-based selective masking strategy and the corresponding event detection model is as follows: First, using the downstream training set D... event The trigger word information is annotated in the text, and a selective masking model (i.e., a trigger word detection model) is trained. Then, the model is applied to unsupervised legal text data D. legal Selective masking is performed to obtain pre-trained data D for event detection tasks in the legal field. legal(masked) As a corpus for pre-training oriented towards event detection tasks in the legal field, after completing MLM pre-training, a pre-trained language model oriented towards event detection tasks is obtained.

[0153] In this embodiment, the training process of the selective masking model (i.e., the trigger word detection model) is as follows: Let X = {x1, x2, ..., x...} N Let x be the input text sequence, where each x i This represents a token, where 1 ≤ i ≤ N, and N is the length of the text sequence. The text tokens are embedded and then input into a pre-trained language model. The output of the pre-trained language model is H = {h1, h2, ..., h...} N}, where h i This represents the high-dimensional contextual feature representation learned by the pre-trained language model from the i-th token in the sequence, where dim represents the dimension of the hidden layer. Then, each token output by the pre-trained language model is represented by h. i It uses a fully connected network as a linear classification layer, mapping to a two-dimensional logits vector Z. i =[z i,0 ,z i,1 ], here z i,0 ,z i,1 Let Z represent the prediction scores for the i-th token belonging to the non-trigger word category and the trigger word category, respectively. Then, using the Softmax function, the logits vector Z of each token is... i Transform into a probability distribution P i,j The calculation formula is:

[0154]

[0155] The total number of categories is 2, and j represents a specific category. Based on this probability distribution function, the final token label is either 0 or 1 (0 indicates the token is a non-trigger word, 1 indicates the token is a trigger word and can be masked during pre-training). During training, to optimize model parameters, the cross-entropy loss function is used to measure the difference between the model's predicted probability distribution and the true label. The loss L for all tokens in a batch of training samples is... T The calculation formula is:

[0156]

[0157] Here, y i,j y is the true label for whether the i-th token belongs to category j. i,j If the token belongs to the category ∈{0,1}, then y i,j =1 otherwise 0. This strategy enhances the model's ability to identify event trigger words in complex legal documents. After completing this selective masking model (trigger word detection model), it can be used for selective masking in subsequent legal domain pre-training tasks.

[0158] This selective masking strategy may also have certain limitations: training set D event The trigger words annotated in text may be influenced by the subjective judgment of the annotators, leading to inconsistencies in annotation. Different annotators may have different understandings of trigger words, especially in the complex and highly specialized field of law. Furthermore, whether the annotated trigger words comprehensively cover all possible event types in the text, and whether the annotation depth is sufficient to reveal all aspects of complex events, is also a question. If the annotated trigger words do not represent all the important event triggering information in the text, then the model may learn an incomplete set of trigger words.

[0159] Therefore, when performing selective masking, it is necessary not only to consider whether the word itself is a potential trigger word, but also to consider its specific context. Identifying which specific words in which contexts contribute more to the downstream event detection task and then prioritizing masking words in these contexts may yield better results. Based on this, the present invention further provides a third solution.

[0160] Option 3: Token-based selective masking strategy

[0161] This scheme is based on the contribution of tokens to downstream event detection tasks, aiming to identify tokens that make significant contributions to event detection tasks. The relevant steps are as follows:

[0162] ①Based on the downstream training set D eventA detection model M0 is initially fine-tuned. In this embodiment, the structure of model M0 is similar to that of the legal event detection model, including cascaded embedding layers, a pre-trained language model, and a classification module. The difference is that the pre-trained language model used by model M0 is not a pre-trained language model after the EventPT stage of event detection task-oriented pre-training, but a pre-trained language model pre-trained in a general domain.

[0163] ②Based on the calculation formula for token contribution, for D event For each data point, the impact of each token on the accuracy of event type prediction is calculated to dynamically select important tokens, resulting in a masked text corpus data D. event(masked) Event detection uses model M0.

[0164] ③Based on data D event(masked) The important tokens marked in the middle complete the training of the selective masking model (i.e., the important token detection model).

[0165] ④ Using a selective masking model on the legal text corpus dataset D legal Selective masking is performed to obtain pre-trained data D for event detection tasks in the legal field. legal(masked) This serves as corpus for pre-training in the context of event detection tasks in the legal field.

[0166] ⑤ Dataset D after masking legal(masked) Complete task-oriented pre-training for event detection in the legal field; the training task is in the form of MLM.

[0167] The core of this process is the calculation of token contribution in step ②, and the specific implementation process is as follows.

[0168] Consider an input text sequence X = {x1, x2, ..., xn} containing N tokens. N This embodiment introduces a variable-length auxiliary buffer queue Q to iteratively calculate the contribution of each token in the sequence. Initially, at time t0, queue Q is empty. Subsequently, the algorithm iteratively adds each token x... i Add the tokens to the queue and use model M0 to predict the event type of the sentence formed by all tokens in the current queue Q, and calculate the probability P(event|Q) that the sentence is correctly identified as the corresponding legal event type label.

[0169] For the calculation of token contribution, let's assume... For t i-1 At any moment, token x i The predicted probability before adding it to queue Q. For t iAt that moment, join x i The predicted probability after, token x i The contribution to the event detection task is denoted as C(x). i ), then C(x) i Let x be the absolute value of the difference between the two probabilities. i The addition of causes the change in the predicted probability to exceed the preset threshold δ, that is:

[0170]

[0171] Then mark token x i A token is crucial for event detection; that is, if the model understands the token, it is essential for understanding the event type in the text. Here's a specific example: after adding the word "steal" to the queue, the model predicts that the probability of the sentence "Wednesday morning, Li stole in the central parking lot" being the event type "theft" changes from 0.1 to 0.7. If this change is greater than the preset threshold δ (let δ = 0.55), then the token represented by "steal" makes a significant contribution to the event detection task for this sentence and will be replaced with [MASK] during subsequent training of the selective masking model.

[0172] This strategy allows for the dynamic identification and labeling of tokens that significantly contribute to event detection. These tokens are then given special attention during the training of the selective masking model, improving the model's sensitivity to important semantic information and optimizing its performance on complex event detection tasks. Table 2 describes the dataset D obtained after masking in step ②. legal(masked) The process.

[0173] Table 2

[0174]

[0175] After the above process, a set R that needs to be masked is obtained, which serves as the dataset D. event(masked) Then, supervised training of the selective masking model (i.e., the important token detection model) is performed (the specific process can be found in the training methods of both schemes). The selective masking model here differs slightly from Scheme 2 in that, for the same j representing a specific category, 0 indicates that the token is not an element in the important token set R, and 1 indicates that the token is an element in the important token set R. This greatly contributes to the model's understanding of the event detection task.

[0176] Once the token classifier is trained, it can be applied to unsupervised legal text D. legalIn the middle, selective mask annotation is performed, and the D obtained after selective mask annotation is obtained. legal(masked) It can be used as corpus for task-oriented pre-training in this paper.

[0177] This masking strategy takes into account the impact of the token on downstream event detection tasks and aims to eliminate the event detection dataset D. event In this context, the subjective intentions of the annotators when annotating trigger words can have an impact.

[0178] Selectively mask unsupervised text data in the legal field using any masking strategy to obtain an unsupervised masked corpus D in the legal field. legal(masked) Then, based on the pre-trained language model obtained from general training, D is used legal(masked) The dataset is further pre-trained in the legal domain using the MLM task. The model needs to predict the original values ​​of these mask tokens related to the event detection task during pre-training. Given a sequence X = {x1, x2, ..., x...} N}, where N is the sequence length, and some tokens are replaced with special mask markers [MASK] to form a mask sequence X' = {x′1, x′2, ..., x′}. N}

[0179] Next, a pre-trained language model is used to encode the processed mask sequence. The encoder outputs H = {h1, h2, ..., h...} N}, where h i This represents the high-dimensional contextual feature representation learned by the model from the i-th token in the sequence. dim represents the dimension of the hidden layer. Then, each token output by the model is represented by h. i It uses a fully connected network as a linear classification layer, mapping to a logits vector of dimension |V|. Used to indicate that the mask part is a possible token. i The score is calculated, where |V| is the size of the vocabulary. Then, the logits vector is processed using the Softmax function. Transform into a probability distribution P(x) i |x'1,x'2,…,x' N ;θ MLM ), representing a given mask sequence X' = {x'1, x'2, ..., x' N} and model parameters θ MLM In the case of predicting the original token x i The probability of is calculated using the following formula:

[0180]

[0181] This probability is used to predict the real tag corresponding to the masked token.

[0182] The goal during model training is to minimize the sum of the negative log-likelihoods of the predicted probabilities of all masked tokens, i.e., the loss function L. EventPT :

[0183]

[0184] Here, R is the set of all masked tokens.

[0185] Through the task-oriented pre-training process described above, the resulting pre-trained language model will have a deeper understanding of legal texts, especially in identifying and processing key information related to event detection tasks.

[0186] In summary, this invention provides a method for constructing a legal event detection model based on a dual-prototype branch. By introducing two prototype sources—event label information and event mentions—the distance metric between the input text and the prototype sources is calculated to obtain the predicted event information. This allows the model to learn subtle semantic differences between different event types and the rich diversity of specific linguistic expressions for the same event type. Furthermore, through a contrastive learning strategy on the event mention branch, the distance between positive sample pairs with the same label is narrowed, while the differences between negative sample pairs are amplified. This reduces the potential negative impact of subtle differences in legal terminology on the detection results of few-sample events, better learns the semantic features of similar event types, and further improves the model's ability to distinguish similar event types. The model achieves excellent results in differentiating easily confused events, improving its applicability and robustness in few-sample practical applications. In addition, this invention introduces adversarial training during joint optimization training to enhance the model's generalization ability and robustness. In addition, before training the legal feature extraction module, the pre-trained language model within it underwent task-oriented pre-training. A selective masking strategy based on legal event features was used to achieve domain-oriented pre-training for legal event detection, thus linking the training of the pre-trained language model in the text feature extraction module with the legal event detection task. This results in a strong ability to perceive, understand, and extract key elements of legal events, significantly improving the accuracy of legal event detection. Based on this, the present invention improves the understanding and processing of judicial documents and the ability to distinguish similar events, and possesses strong generalization capabilities, enabling effective learning and recognition of legal events even under conditions of scarce training data.

[0187] To further illustrate the performance of the legal event detection model FLED provided by this invention, comparative experiments were conducted on the legal event detection dataset LEVEN. Since this involves event detection in a few-shot scenario, this invention employs a K-shot sampling strategy to perform few-shot sampling on the LEVEN dataset, resulting in a few-shot LEVEN dataset. Because the comparative experiments involve evaluating large language models, this experiment adopts the approach of LawBench, a leading large language model evaluation platform in OpenCompass, to process the few-shot LEVEN dataset into a form recognizable by large language models. The evaluation process is as follows: Figure 3 As shown. The evaluation metric used in this patent experiment is the Micro-F1 score, which considers both micro-precision and micro-recall, and comprehensively reflects the model's performance on the few-shot LEVEN dataset.

[0188] First, for the detection of legal events with few samples, the FLED model in the invention is compared with representative models of other methods. Then, for the event label prototype branch of the FLED model, comparative experiments are conducted on different prompt templates. Next, comparative experiments are conducted on the FLED model using different distance metric functions. Finally, comparative experiments are conducted on the FLED model using different contrastive learning strategies, thereby obtaining the optimal selection strategy for each component of the FLED model.

[0189] (1) Comparative experiment on few-sample event detection

[0190] For legal event detection in scenarios with few samples, in addition to the FLED model proposed in this invention, the following representative methods and corresponding models were also selected.

[0191] 1) Fine-tuning-based methods

[0192] This method is based on the basic idea of ​​pre-training and fine-tuning. It treats event detection as a text classification task, uses the LED-RoBERTa model mentioned above as the encoder for text embedding, and obtains the final event type prediction through a fully connected layer, i.e., Fine-tuning LED-RoBERTa in the table.

[0193] 2) Context-based learning methods

[0194] This type of method is based on large language models, using natural language to describe the task input and the model outputting the result. This experiment selected several top-ranked typical models based on the rankings on OpenCompass, a leading platform for evaluating large language models: GPT4 Turbo, GLM4, Qwen-Max, GPT3.5, and Tongyi Farui. All models were invoked using API interfaces provided on their official websites.

[0195] 3) Prompt-based learning methods

[0196] This experiment selected two representative cue-based learning methods. The EEQA model transforms event detection into a cue-based question-and-answer format, while the P4E model performs event detection through a typical MLM prediction task and a tag word mapping.

[0197] 4) Prototype network-based methods

[0198] In few-shot event detection, FSLS and Container were selected. The FSLS model uses label names as the prototype source, while Container uses other training samples as the prototype source.

[0199] The results of the comparative experiment are shown in Table 3. The results of all models are from the experimental environment provided by this patent. All data in the table are percentages rounded to two decimal places.

[0200] Table 3

[0201]

[0202] Based on the data in the table, the following conclusions can be drawn:

[0203] Overall, compared to other models, the FLED model proposed in this invention achieves the highest performance in 2-shot, 5-shot, and 10-shot tests. Compared to the best-performing model FSLS, micro-f1 is 2.58%, 3.18%, and 3.18% higher, respectively.

[0204] The FLED model proposed in this invention combines event label information and event mentions as dual prototype sources. Through contrastive learning, the model can learn multiple complex semantic representations of the same event type and the differences in semantic expression between different events, reducing the potential negative impact of subtle differences in legal terminology on event detection results. This model shows a significant improvement compared to the FSLS model that only uses labels as prototype sources, especially compared to the Container model that only uses event mentions as prototype sources, achieving improvements of 13.33%, 18.12%, and 18.05% in 2-shot, 5-shot, and 10-shot scenarios, respectively, demonstrating a very significant improvement.

[0205] While most studies demonstrate the superiority of cue-based learning methods over few-shot natural language processing tasks, experimental results on event detection tasks have fallen far short of expectations. Prototype network-based methods generally outperform cue-based learning methods, especially with very limited training samples. This illustrates that designing effective cue templates for event detection tasks using limited training samples remains a significant challenge. The P4E model performs well, presumably because it uses the MLM task to predict event types, a task consistent with the pre-training task of the pre-trained language model, exhibiting strong downstream task adaptability.

[0206] Context-based large language model methods generally lag far behind the FLED model proposed in this invention, even though these large language models often have a much larger number of parameters than the encoder part of other models (e.g., RoBERTa has only 125M parameters). This corroborates the viewpoints of some papers in the current research: large language models do not achieve good results in tasks involving few-shot information extraction. Sometimes, with the increase in the number of samples (e.g., at 10-shot), some models (e.g., GPT4Turbo and GLM4) cannot fully enhance their understanding of specific events, leading to model confusion and performance degradation. The performance of large language models in event detection tasks is affected to some extent by the number of parameters, training corpus, and prompt templates. For example, Qwen-Max and GPT4 Turbo, which have a large number of parameters, generally outperform other large language models, while Tongyi FaRui, which has a relatively small number of parameters, has achieved performance on par with GPT3.5 and GLM4 because it is trained on legal domain data.

[0207] Compared to the prototype network-based method of this invention, the fine-tuning-based method generally performs worse. Although the model encoder is LED-RoBERTa pre-trained for legal domain event detection tasks, and the high-dimensional feature vectors output by the model have fully learned the event structure of the context, its performance on few-shot tasks is still unsatisfactory. Although it performs well on few-shot training / validation datasets with gradient descent optimization of the loss function and numerous training steps, it is very prone to overfitting on very large test sets with many unseen samples. This also proves the argument that fine-tuning tasks based on pre-trained language models require a certain scale of fully supervised data.

[0208] In summary, the FLED model proposed in this invention, based on contrastive learning, uses event labels and event mentions as dual prototype sources and performs adversarial training. Compared with other single-prototype methods, cue-based learning methods, fine-tuning methods, and large language model-based context learning methods, it has advantages in the task of detecting legal events with few samples.

[0209] Secondly, the present invention provides a legal event detection method, comprising:

[0210] The text to be detected is input into the legal event detection model constructed by the legal event detection model construction method provided in the first aspect of the present invention. The feature vector of the text to be detected is obtained by the feature extraction module in the legal event detection model. The distance between the feature vector of the legal text and each feature vector in the feature vector set is calculated by the decision-maker in the legal event detection model. The legal event type corresponding to the minimum distance is taken as the final detection result.

[0211] The feature vector set includes feature vectors of template prompt texts for different legal event types obtained through the legal feature extraction module.

[0212] The relevant technical solutions are the same as the legal event detection model construction method provided in the first aspect of this invention, and will not be repeated here.

[0213] The following example further illustrates this point. Figure 4 As shown, the input text is "Defendants Wang and Li conspired to rob a store at knifepoint." In a few-sample scenario, this text is easily classified into the following three legal event types: "robbery of property," "theft of property," and "embezzlement of property." The feature vectors of these texts after passing through the legal feature extraction module are used to measure the distance in the feature space. Assuming that the feature vector of the final input text is closest to the template prompt text of the "robbery of property" event type, it will eventually be classified as the "robbery of property" event.

[0214] Thirdly, the present invention provides an electronic device, a memory, and a processor, comprising: the memory storing a computer program, and the processor executing the computer program to perform the method provided in the first or second aspect of the present invention.

[0215] The relevant technical solutions are the same as the legal event detection model construction method provided in the first aspect of this invention and the legal event detection method provided in the second aspect of this invention, and will not be described in detail here.

[0216] Fourthly, the present invention also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, performs the method provided in the first or second aspect of the present invention.

[0217] The relevant technical solutions are the same as the legal event detection model construction method provided in the first aspect of this invention and the legal event detection method provided in the second aspect of this invention, and will not be described in detail here.

[0218] Those skilled in the art will readily understand that the above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A method for constructing a legal event detection model based on dual prototype sources, characterized in that, include: S1. Training the legal feature extraction module: For each legal text in the pre-collected training set, the feature vector of the legal text and the feature vector of the template prompt text corresponding to the legal event type label are obtained through the legal feature extraction module, and the distance between the two is calculated and denoted as the first distance. Two legal texts with the same legal event type label in the training set are formed into a positive sample pair. The distance between the feature vectors of each legal text in each positive sample pair is calculated and denoted as the second distance. The legal feature extraction module is trained by minimizing the first distance corresponding to each legal text and the second distance corresponding to each positive sample pair. S2. After training, a legal event detection model including the cascaded feature extraction module and the decision-maker is constructed to perform legal event detection. The decision-maker is used to calculate the distance between the feature vector of the legal text to be detected and each feature vector in the feature vector set, and takes the legal event type corresponding to the minimum distance as the final detection result; the feature vector set includes: feature vectors of template prompt text under different legal event types obtained by the legal feature extraction module after training; Step S1 further includes: Two legal texts with different legal event type labels in the training set are formed into a negative sample pair. The distance between the feature vectors of each legal text in each negative sample pair is calculated and denoted as the third distance. While minimizing the first distance corresponding to each legal text and the second distance corresponding to each positive sample pair, the third distance corresponding to each negative sample pair is maximized in order to train the legal feature extraction module. The legal feature extraction module includes: a cascaded tokenization layer, an embedding layer, a pre-trained language model, a pooling layer, and a normalization layer; The process of obtaining legal text feature vectors through the legal feature extraction module includes: The legal text is input into the legal feature extraction module, and after passing through the tokenization layer, embedding layer and pre-trained language model in sequence, the corresponding high-dimensional feature encoding of the text is obtained, including the high-dimensional features of each token in the legal text. The high-dimensional features of each token contained in the pre-annotated trigger words in the legal text are extracted from it and input into the pooling layer to obtain the legal text feature vector.

2. The method for constructing a legal event detection model according to claim 1, characterized in that, Also includes: For each legal text in the training set, generate a corresponding adversarial sample to form an adversarial sample set; Following the training method in step S1, the adversarial sample set is input into the legal feature extraction module for training, thereby achieving adversarial training of the legal feature extraction module.

3. The method for constructing a legal event detection model according to claim 1, characterized in that, Before training the legal feature extraction module, the pre-trained language model within it is pre-trained in a task-oriented manner using the following method: Each legal judgment document in the pre-collected legal domain text corpus dataset is tokenized to obtain a corresponding token sequence. The tokens representing the semantic features of legal events in the token sequence are masked and embedded, and then input into the pre-trained language model for MLM pre-training.

4. The method for constructing a legal event detection model according to claim 3, characterized in that, The tokens representing the semantic features of legal events in the token sequence are determined by method one, method two, or method three. In the aforementioned manner, the tokens representing the semantic features of legal events in the token sequence include: tokens whose part of speech is a verb; In the second method, the tokens representing the semantic features of legal events in the token sequence include: trigger word tokens obtained after inputting the token sequence into the trigger word detection model; The trigger word detection model is obtained through the following method: Each legal text in the training set is tokenized to obtain a corresponding token sequence, which is then input into the first neural network model to detect whether each token in the token sequence is a trigger word token. The first neural network model is trained by minimizing the difference between the detection result and the corresponding trigger word judgment result. The trained first neural network model is then used as the trigger word detection model. The trigger word determination result is obtained based on the preset trigger word corresponding to the legal text, including whether each token in the token sequence of the legal text is a trigger word token. In the third method, the tokens representing the semantic features of legal events in the token sequence include: important tokens obtained after inputting the token sequence into the important token detection model; The important token detection model is obtained through the following method: For each legal text in the training set: tokenize it, and add each token in the resulting token sequence to the initially empty sequence in chronological order. Q In the middle; the sequence after each added token. Q Input to detection model The system performs legal event type detection and obtains the probability that the detection result is the corresponding legal event type label. For each token, the absolute value of the difference between the probabilities before and after adding the token is calculated as the contribution of the token. Tokens with a contribution greater than a preset threshold are designated as important token labels corresponding to the legal text. Each legal text in the training set is tokenized to obtain a corresponding token sequence, which is then input into a second neural network model to detect whether each token in the token sequence is an important token. The second neural network model is trained by minimizing the difference between the detection result and the corresponding important token judgment result. The trained second neural network model is then used as the important token detection model. The detection model The method is to tokenize the legal texts in the training set and input them into a third neural network model for training. The true result of the important token judgment is obtained based on the important token labels corresponding to the legal texts, including the true information of whether each token in the token sequence of the legal text is an important token.

5. A method for detecting legal events, characterized in that, include: The text to be detected is input into the legal event detection model constructed by the legal event detection model construction method according to any one of claims 1-4. The feature vector of the text to be detected is obtained by the feature extraction module in the legal event detection model. The distance between the feature vector of the legal text and each feature vector in the feature vector set is calculated by the decision-maker in the legal event detection model. The legal event type corresponding to the minimum distance is taken as the final detection result. The feature vector set includes feature vectors of template prompt texts for different legal event types obtained through the legal feature extraction module.

6. An electronic device, characterized in that, A memory and a processor, comprising: the memory storing a computer program, and the processor executing the computer program to perform the method according to any one of claims 1-5.

7. A computer-readable storage medium, characterized in that, It stores a computer program, which, when executed by a processor, performs the method described in any one of claims 1-5.