Training method, device and terminal equipment for few-sample relation extraction model

By constructing support sets and query sets for forward and reverse training, the parameters of the few-sample relationship extraction model are adjusted, which solves the problem of low classification accuracy of existing models and improves the accuracy of entity relationship extraction of few-sample training data.

CN115510853BActive Publication Date: 2025-08-12HEBEI UNIV OF ENG
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202211159237.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-22
Publication Date
2025-08-12
Estimated Expiration
2042-09-22

AI Technical Summary

Technical Problem

The existing low-sample relationship extraction model has the problem of low classification accuracy during the training process, and it is impossible to effectively extract entity relationships, especially the inaccurate classification of entity relationships for training data with few samples.

Method used

By constructing the support set and query set for forward and reverse training, the preset low-sample relationship extraction model is trained forward and reversely, and the parameters are adjusted using the forward relationship prototype and the reverse relationship prototype, and the model parameters are optimized in combination with the cross entropy loss value to achieve the update of the model.

Benefits of technology

The classification accuracy of the small sample relationship extraction model is improved, and entity relationships can be extracted from sentences more effectively.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115510853B_ABST
    Figure CN115510853B_ABST
Patent Text Reader

Abstract

The present application is applicable to the field of natural language processing technology, and provides a training method, apparatus and terminal device for a few-sample relationship extraction model. The method includes: constructing a first support set and a first query set to perform forward training on a preset few-sample relationship extraction model, obtaining a forward relationship prototype and a first matching score, and constructing a second support set and a second query set based on the result of the forward training and the first query set to perform reverse training on the preset few-sample relationship extraction model, obtaining a reverse relationship prototype and a second matching score, determining a cross-entropy loss value based on the first matching score and the second matching score, adjusting the parameters of the preset few-sample relationship extraction model based on the forward relationship prototype and the reverse relationship prototype, and obtaining an updated few-sample relationship extraction model based on the cross-entropy loss value. The present application can improve the classification accuracy of the few-sample relationship extraction model, and thereby effectively extract the entity relationship of the sentence.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of natural language processing technology, and specifically to a training method, apparatus, and terminal device for a few-sample relationship extraction model. Background Art

[0002] The amount of data generated by urban public security is increasing day by day. Urban public security data contains a large amount of data on interactions between people and between people and objects. Obtaining the relationships between entities (i.e., entity relationships) from the data helps to make full use of the data and realize its potential value.

[0003] The main technology for obtaining the relationship between entities is entity relationship extraction. The performance of existing relationship extraction models based on distant supervision usually depends on a large amount of high-quality labeled training data. However, in reality, the training data has a long-tail distribution problem, that is, some categories of entity relationships only correspond to a small amount of labeled training data (few-sample training data). This makes it impossible for existing relationship extraction models to accurately classify the entity relationships that only correspond to the few-sample training data.

[0004] To address the above problems, few-shot learning has been introduced into entity relationship extraction. However, the training of existing few-shot relationship extraction models often only considers the forward training of relationship prototypes, resulting in the problem of low classification accuracy in the few-shot relationship extraction models. Summary of the Invention

[0005] In view of this, the embodiments of the present application provide a training method, apparatus and terminal device for a few-sample relationship extraction model to solve the technical problems that the existing few-sample relationship extraction model has low classification accuracy and cannot effectively extract entity relationships.

[0006] In a first aspect, an embodiment of the present application provides a training method for a few-shot relation extraction model, comprising: determining a first support set and a first query set for forward training based on an acquired sentence text set, wherein instances in the sentence text set are annotated with entity pairs and relationship labels, and a first instance set in the first support set is divided into multiple categories according to the relationship labels; forward training a preset few-shot relation extraction model using the first support set and the first query set to obtain a positive relationship prototype between each second instance in the first query set and the first instance set of each category in the first support set, and determining a first matching score between each second instance and the first instance set of each category, and a pseudo relationship label for each second instance based on the positive relationship prototype;

[0007] A second support set for reverse training is constructed based on the pseudo-relationship labels of the first query set and the second instance, and a second query set for reverse training is constructed based on the sentence text set and the second support set. The second support set includes a second instance set divided into multiple categories according to the relationship labels, and the categories of the second instance set correspond to the categories of the first instance set. The preset few-shot relationship extraction model is reversely trained using the second support set and the second query set to obtain a reverse relationship prototype between each fourth instance in the second query set and the second instance set of each category in the second support set, and a second matching score between each fourth instance and the second instance set of each category is determined based on the reverse relationship prototype.

[0008] A cross-entropy loss value is determined according to the first matching score and the second matching score, parameters of the preset few-sample relationship extraction model are adjusted according to the forward relationship prototype and the reverse relationship prototype, and an updated few-sample relationship extraction model is obtained according to the cross-entropy loss value.

[0009] In a possible implementation of the first aspect, the first support set and the first query set for forward training are determined based on the acquired sentence text set, including: determining the first support set and the first query set for forward training based on the acquired sentence text set and a preset task scenario; the preset task scenario determines the category of the first instance set in the first support set and the number of first instances in the first instance set; the category of the second instance in the first query set corresponds to the category of the first instance set.

[0010] In a possible implementation of the first aspect, a second support set for reverse training is constructed based on the pseudo-relationship labels of the first query set and the second instance, and a second query set for reverse training is constructed based on the sentence text set and the second support set, including: constructing the second support set for reverse training based on a preset task scenario, the pseudo-relationship labels of the first query set and the second instance; the second support set includes all the second instances in the first query set; the preset task scenario determines the category of the second instance set in the second support set and the number of third instances in the second instance set; constructing the second query set for reverse training based on the sentence text set and the second support set; the category of the fourth instance in the second query set corresponds to the category of the second instance set.

[0011] In a possible implementation of the first aspect, determining a cross entropy loss value based on the first matching score and the second matching score includes: calculating a forward cross entropy loss value based on multiple first matching scores corresponding to the second instance; calculating a reverse cross entropy loss value based on multiple second matching scores corresponding to the fourth instance; and calculating the sum of the forward cross entropy loss value and the reverse cross entropy loss value as the cross entropy loss value.

[0012] In a possible implementation of the first aspect, calculating a forward cross entropy loss value based on multiple first matching scores corresponding to the second instance; calculating a reverse cross entropy loss value based on multiple second matching scores corresponding to the fourth instance, including: calculating a probability value of each category corresponding to the second instance based on the multiple first matching scores corresponding to the second instance; calculating a forward cross entropy loss value based on the probability value of each category corresponding to the second instance; calculating a probability value of each category corresponding to the fourth instance based on the multiple second matching scores corresponding to the fourth instance; and calculating a reverse cross entropy loss value based on the probability value of each category corresponding to the fourth instance.

[0013] In a possible implementation of the first aspect, the parameters of a preset few-sample relationship extraction model are adjusted according to the forward relationship prototype and the reverse relationship prototype, and an updated few-sample relationship extraction model is obtained according to the cross-entropy loss value, including: adjusting the parameters of the preset few-sample relationship extraction model according to the forward relationship prototype, the reverse relationship prototype and a preset learning rate to obtain the adjusted few-sample relationship extraction model; performing the next round of forward training and reverse training on the adjusted few-sample relationship extraction model until the cross-entropy loss value is minimized to obtain the updated few-sample relationship extraction model.

[0014] In a possible implementation of the first aspect, the method further includes: determining a pseudo-relationship label for each fourth instance based on a second matching score between each fourth instance and a set of second instances of each category; correspondingly, calculating the model accuracy of the updated few-sample relationship extraction model based on the pseudo-relationship label corresponding to the second instance and the pseudo-relationship label corresponding to the fourth instance corresponding to the updated few-sample relationship extraction model, and the relationship label corresponding to the second instance and the relationship label corresponding to the fourth instance in the sentence text set; determining different first support sets and first query sets based on the sentence text set, and repeating the step of determining the updated few-sample relationship extraction model to obtain multiple updated few-sample relationship extraction models and corresponding model accuracies, and determining the updated few-sample relationship extraction model with the highest model accuracy as the final few-sample relationship extraction model, so that entity relationships are extracted for sentences labeled with entity pairs according to the final few-sample relationship extraction model.

[0015] In a second aspect, an embodiment of the present application provides a training device for a few-sample relationship extraction model, comprising:

[0016] A first determination module is configured to determine a first support set and a first query set for forward training based on the acquired sentence text set, wherein instances in the sentence text set are annotated with entity pairs and relationship labels, and the first support set includes a first instance set divided into multiple categories based on the relationship labels;

[0017] a first training module, configured to perform forward training on a preset few-shot relation extraction model using the first support set and the first query set, obtain a positive relation prototype between each second instance in the first query set and the first instance set of each category in the first support set, and determine a first matching score between each second instance and the first instance set of each category, and a pseudo relation label for each second instance, based on the positive relation prototype;

[0018] A second determination module is configured to construct a second support set for reverse training based on the pseudo-relationship labels between the first query set and the second instance, and to construct the second query set for reverse training based on the sentence text set and the second support set, wherein the second support set includes a second instance set divided into multiple categories based on the relationship labels, and the categories of the second instance set correspond to the categories of the first instance set;

[0019] a second training module, configured to perform reverse training on a preset few-shot relation extraction model using the second support set and the second query set, obtain a reverse relation prototype between each fourth instance in the second query set and the second instance set of each category in the second support set, and determine a second matching score between each fourth instance and the second instance set of each category based on the reverse relation prototype;

[0020] A parameter adjustment module is used to determine the cross entropy loss value based on the first matching score and the second matching score, adjust the parameters of the preset few-sample relationship extraction model according to the forward relationship prototype and the reverse relationship prototype, and obtain the updated few-sample relationship extraction model according to the cross entropy loss value.

[0021] In a third aspect, an embodiment of the present application provides a terminal device comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the processor executes the computer program, the training method of the few-sample relationship extraction model as described in any one of the first aspects is implemented.

[0022] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the training method of the few-sample relationship extraction model as described in any one of the first aspects.

[0023] In a fifth aspect, an embodiment of the present application provides a computer program product, which, when executed on a terminal device, enables the terminal device to execute the training method for the few-sample relationship extraction model described in any one of the above-mentioned first aspects.

[0024] It can be understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here.

[0025] The training method, apparatus and terminal device of the few-sample relationship extraction model provided in the embodiments of the present application perform forward training on the preset few-sample relationship extraction model by constructing a first support set and a first query set to obtain a forward relationship prototype of each second instance in the first query set and the first instance set of each category in the first support set, as well as a first matching score. The second support set and the second query set are constructed based on the results of the forward training and the first query set to perform reverse training on the preset few-sample relationship extraction model to obtain a reverse relationship prototype of each fourth instance in the second query set and the second instance set of each category in the second support set, as well as a second matching score. The cross-entropy loss value is determined based on the first matching score and the second matching score. The parameters of the preset few-sample relationship extraction model are adjusted based on the forward relationship prototype and the reverse relationship prototype. The updated few-sample relationship extraction model is obtained based on the cross-entropy loss value. The classification accuracy of the few-sample relationship extraction model is improved through reverse training, thereby effectively extracting the entity relationship of the sentence.

[0026] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments or descriptions of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0028] Figure 1 1 is a flow chart of a training method for a few-sample relationship extraction model provided in one embodiment of the present application;

[0029] Figure 2 is a schematic diagram of a support set and a query set provided in an embodiment of the present application;

[0030] Figure 3 1 is a flow chart of a training method for a few-sample relationship extraction model provided in one embodiment of the present application;

[0031] Figure 4 1 is a schematic diagram of the structure of a training device for a few-sample relationship extraction model provided in one embodiment of the present application;

[0032] Figure 5 It is a structural diagram of a terminal device provided in one embodiment of the present application. DETAILED DESCRIPTION

[0033] The present application will be described more clearly below with reference to specific embodiments. The following embodiments will help those skilled in the art further understand the function of the present application, but are not intended to limit the present application in any form. It should be noted that those skilled in the art may make a number of modifications and improvements without departing from the concept of the present application. These all fall within the scope of protection of the present application.

[0034] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, integers, steps, operations, elements and / or components, but does not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or collections thereof.

[0035] It will also be understood that the term "and / or" used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.

[0036] In the description of this application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.

[0037] References to "one embodiment" or "some embodiments" in this specification mean that a particular feature, structure, or characteristic described in conjunction with that embodiment is included in one or more embodiments of the present application. Thus, phrases such as "in one embodiment," "in some embodiments," "in other embodiments," and "in other embodiments" appearing in various places in this specification do not necessarily refer to the same embodiment, but rather mean "one or more but not all embodiments," unless otherwise specifically emphasized. The terms "including," "comprising," "having," and variations thereof all mean "including but not limited to," unless otherwise specifically emphasized.

[0038] In addition, the “plurality” mentioned in the embodiments of the present application should be interpreted as two or more.

[0039] The amount of data generated by urban public safety is increasing daily. This data contains a large amount of data on interactions between people and objects. Extracting relationships between entities (i.e., entity relationships) from this data helps fully utilize this data and unlock its potential value. The primary technique for extracting relationships between entities is entity relationship extraction. The performance of existing relationship extraction models based on distant supervision typically relies on a large amount of high-quality labeled training data. However, in reality, training data suffers from a long-tail distribution problem, meaning that certain categories of entity relationships only correspond to a small amount of labeled training data (few-shot training data). This results in existing relationship extraction models being unable to accurately classify these entity relationships that only correspond to few-shot training data.

[0040] To address the above problems, few-shot learning has been introduced into entity relationship extraction. However, the training of existing few-shot relationship extraction models often only considers the forward training of relationship prototypes, resulting in the problem of low classification accuracy in the few-shot relationship extraction models.

[0041] Based on the above problems, the inventors have discovered through research that the query set of forward training can be used to construct a support set for reverse training, and the preset few-sample relationship extraction model can be reversely trained. That is, the symmetry of the data can be used to achieve a balance between forward training and reverse training, so that the preset few-sample relationship extraction model can learn features far away from the classification boundary through reverse training, and then the parameters of the preset few-sample relationship extraction model can be adjusted according to the forward relationship prototype obtained by forward training and the reverse relationship prototype obtained by reverse training to obtain an updated few-sample relationship extraction model.

[0042] That is to say, the training method of the few-sample relationship extraction model provided in the embodiment of the present application constructs a first support set and a first query set to perform forward training on the preset few-sample relationship extraction model, and obtains the forward relationship prototype of each second instance in the first query set and the first instance set of each category in the first support set, as well as the first matching score, and constructs a second support set and a second query set based on the results of the forward training and the first query set to perform reverse training on the preset few-sample relationship extraction model, and obtains the reverse relationship prototype of each fourth instance in the second query set and the second instance set of each category in the second support set, as well as the second matching score, and determines the cross-entropy loss value based on the first matching score and the second matching score, and adjusts the parameters of the preset few-sample relationship extraction model based on the forward relationship prototype, the reverse relationship prototype and the cross-entropy loss value to obtain an updated few-sample relationship extraction model, and improves the classification accuracy of the few-sample relationship extraction model through reverse training, thereby effectively extracting the entity relationship of the sentence.

[0043] Figure 1 FIG. 1 is a flow chart of a training method for a small sample relationship extraction model provided by an embodiment of the present application. Figure 1As shown, the method in the embodiment of the present application may include:

[0044] Step 101: Determine a first support set and a first query set for forward training based on the acquired sentence text set.

[0045] Instances in the sentence text set are annotated with entity pairs and relationship labels, and the first support set is divided into multiple categories of first instance sets based on the relationship labels. For example, an instance in the sentence text set is "Xiao Ming, a famous writer from Shijiazhuang, Hebei Province," which is annotated with the entity pairs "Xiao Ming" and "Shijiazhuang, Hebei Province," and the corresponding relationship label "native place."

[0046] Optionally, step 101 may specifically include: determining a first support set and a first query set for forward training according to the acquired sentence text set and a preset task scenario.

[0047] The preset task scenario determines the category of the first instance set in the first support set and the number of first instances in the first instance set; the category of the second instance in the first query set corresponds to the category of the first instance set.

[0048] Optionally, the type of the preset task scenario is n-way-m-shot, where n represents the number of categories and m represents the number of instances under each category. For example, the dataset of the 3-way-2-shot preset task scenario includes 3 categories, i.e., 3 relationship labels, and there are 2 instances under each category; the dataset of the 5-way-1-shot preset task scenario includes 5 categories, i.e., 5 relationship labels, and there is 1 instance under each category.

[0049] For example, the first support set for forward training is determined based on the instances in the sentence text set that are annotated with entity pairs and relationship labels, and the preset task scenario. For example, for the 3-way-2-shot preset task scenario, see Figure 2 The first support set can include first instance sets of three categories: "nationality," "native place," and "address," with each first instance set including two first instances. Accordingly, the categories of the second instances in the first query set are the same as those in the first instance set. For example, the second instances are classified as "nationality," "native place," and "address," and there can be x second instances in each category, where the value of x is set as needed.

[0050] Step 102: Perform forward training on the preset few-sample relationship extraction model using the first support set and the first query set to obtain a positive relationship prototype between each second instance in the first query set and the first instance set of each category in the first support set, and determine a first matching score between each second instance and the first instance set of each category based on the positive relationship prototype, and a pseudo-relationship label for each second instance.

[0051] For example, the process of forward training the preset few-sample relation extraction model is as follows:

[0052] S1. Encode the first instance in the first support set and the second instance in the first query set to obtain a feature vector corresponding to the first instance and a feature vector corresponding to the second instance.

[0053] S2. Based on the feature vector corresponding to the first instance and the feature vector corresponding to the second instance, a matching calculation is performed on each second instance in the first query set and the first instance set of each category in the first support set to obtain a positive relationship prototype between each second instance in the first query set and the first instance set of each category in the first support set.

[0054] S3. Determine a first matching score between each second instance and the first instance set of each category, and a pseudo relation label of each second instance according to the positive relation prototype.

[0055] Specifically, a convolutional neural network (CNN) is used to encode each first instance and second instance to obtain the feature vector corresponding to the first instance and the feature vector corresponding to the second instance. Based on the feature vectors of the first instance and the feature vectors of the second instance in the first instance set, a multi-level matching aggregation network (MLMAN) is used to match each second instance in the first query set with the first instance set of each category in the first support set to obtain the second instance matching representation. Matching representation of the first instance in the first instance of the i-th category Where k = 1, ..., m (m ≥ 1), i = 1, ..., n (n ≥ 2). The linear rectifier function ReLU is used to calculate the matching degree between the second instance and the first instance in the first instance set of the i-th category. Match The formula is:

[0056]

[0057] Where, v T and W2 are known parameter matrices.

[0058] By matching The first instance matching representation for the weighted aggregation first instance set Get the positive relationship prototype between the second instance and the first instance set of the i-th category in the first support set The prototype formula of the positive relationship is:

[0059]

[0060] The first matching score formula is:

[0061]

[0062] Execute the above S1 to S3 for each second instance in the first query set and the first instance set of each category in the first support set to obtain a positive relationship prototype of each second instance in the first query set and the first instance set of each category in the first support set, and then determine the first matching score between each second instance and the first instance set of each category and the pseudo relationship label of each second instance based on the positive relationship prototype. That is to say, based on the positive relationship prototype, obtain the score of the second instance corresponding to each category, that is, the score of the second instance corresponding to each relationship label, and then select the relationship label with the highest score as the pseudo relationship label of the second instance, that is, the pseudo relationship label of the second instance after forward training.

[0063] Step 103: construct a second support set for reverse training based on the pseudo relation labels of the first query set and the second instance, and construct a second query set for reverse training based on the sentence text set and the second support set.

[0064] The second support set includes a second instance set divided into multiple categories according to the relationship labels, and the categories of the second instance set correspond to the categories of the first instance set.

[0065] Optionally, step 103 may specifically include: constructing a second support set for reverse training based on a preset task scenario, the pseudo-relationship labels of the first query set and the second instance; and constructing a second query set for reverse training based on the sentence text set and the second support set.

[0066] Exemplarily, the second support set includes all second instances in the first query set, the preset task scenario determines the category of the second instance set in the second support set and the number of third instances in the second instance set. The category of the fourth instance in the second query set corresponds to the category of the second instance set.

[0067] Specifically, to ensure that the scale and range of relation labels in forward training and backward training are consistent, the categories of the second instance set in the second support set correspond to the categories of the first instance set in the first support set. For example, for the 3-way-2-shot pre-set task scenario, see Figure 2 The first support set includes the first instance sets of the three categories of "nationality", "native place" and "address", and each first instance set includes two first instances. Correspondingly, the second support set also includes the second instance sets of the three categories of "nationality", "native place" and "address", and each second instance set includes two third instances.

[0068] It should be noted that in order to ensure sufficient connection between forward training and reverse training, the second support set of reverse training is constructed based on the pseudo-relationship labels of the first query set and the second instance. That is, the second support set must include all second instances in the first query set. For example, if the pseudo-relationship label of a second instance in the first query set is "native place", then the second instance is divided into the second instance set of the category "native place" in the second support set of reverse training. For example, if the pseudo-relationship label of another second instance in the first query set is "nationality", then the second instance is divided into the second instance set of the category "nationality" in the second support set of reverse training. All second instances in the first query set are divided into the second instance set of the corresponding category in the second support set according to their corresponding pseudo-relationship labels.

[0069] It should be noted that since the number of second instances in the first query set may be greater than the number of third instances in the second support set, to ensure that the second support set includes all second instances in the first query set, the second instance sets in the second support set are grouped. For example, for a 3-way-2-shot pre-set task scenario, the first support set includes first instance sets of the three categories of "nationality," "native place," and "address." Accordingly, the second support set can include multiple groups, each of which also includes second instance sets of the three categories of "nationality," "native place," and "address." The number of groups G in the second support set can be set based on the number of second instances in the first query set and the pseudo-relationship labels, where G ≥ 1.

[0070] In addition, it should be noted that when constructing the second support set for reverse training based on the pseudo-relationship labels of the first query set and the second instance, there may be a situation where there are fewer second instances corresponding to the pseudo-relationship labels of a certain category. At this time, the second instances corresponding to the pseudo-relationship labels are reused to construct the second support set for reverse training; in addition, there may be a situation where the pseudo-relationship labels of a certain category are missing. At this time, the first instance is selected from the first instance set of the category in the first support set as the third instance in the second instance set of the category in the second support set. For example, the pseudo-relationship labels of all second instances in the first query set are only "nationality" and "native place", then the third instance in the second instance set of the "address" category can be selected from the first instance set of the "address" category in the first support set.

[0071] Optionally, a second query set for reverse training is constructed based on the sentence text set and the second support set, where the categories of the fourth instances in the second query set correspond to the categories of the second instance set. At the same time, the groups in the second query set correspond to the groups in the second support set. For example, if the second support set includes two groups, each group includes a second instance set of three categories: "nationality," "native place," and "address," and each second instance set includes two third instances, then the second query set also includes two groups, each group includes three categories: "nationality," "native place," and "address," and there can be y fourth instances in each category, where the value of y is set as needed.

[0072] Step 104: Use the second support set and the second query set to reversely train the preset few-sample relationship extraction model to obtain a reverse relationship prototype between each fourth instance in the second query set and the second instance set of each category in the second support set, and determine a second matching score between each fourth instance and the second instance set of each category based on the reverse relationship prototype.

[0073] Optionally, the specific implementation process and principle of reverse training the preset few-sample relationship extraction model in step 104 can refer to the specific implementation process and principle of forward training the preset few-sample relationship extraction model in step 102 in the aforementioned embodiment, which will not be repeated here.

[0074] It should be noted that, since the second support set and the second query set may include multiple corresponding groups, when using the second support set and the second query set to reversely train the preset few-sample relationship extraction model, the preset few-sample relationship extraction model is reversely trained using the second instance set of the first group and the fourth instance of the first group, and the preset few-sample relationship extraction model is reversely trained using the second instance set of the next group and the fourth instance of the corresponding group, until the preset few-sample relationship extraction model is reversely trained using all groups in the second support set and the second query set.

[0075] Step 105: Determine a cross entropy loss value based on the first matching score and the second matching score, adjust the parameters of the preset few-sample relationship extraction model based on the forward relationship prototype and the reverse relationship prototype, and obtain an updated few-sample relationship extraction model based on the cross entropy loss value.

[0076] In one possible implementation, see Figure 3 In step 105, the following steps may be specifically included:

[0077] Step 1051: Calculate a forward cross entropy loss value based on the multiple first matching scores corresponding to the second instance; and calculate a reverse cross entropy loss value based on the multiple second matching scores corresponding to the fourth instance.

[0078] Step 1052: Calculate the sum of the forward cross entropy loss value and the reverse cross entropy loss value as the cross entropy loss value.

[0079] Step 1053: Adjust the parameters of the preset few-sample relation extraction model according to the forward relation prototype, the reverse relation prototype and the preset learning rate to obtain the adjusted few-sample relation extraction model.

[0080] Step 1054: Perform the next round of forward training and reverse training on the adjusted few-shot relation extraction model until the cross-entropy loss value is minimized, thereby obtaining an updated few-shot relation extraction model.

[0081] Optionally, step 1051 may specifically include:

[0082] According to the multiple first matching scores corresponding to the second instance, the probability value of the second instance corresponding to each category is calculated; according to the probability value of the second instance corresponding to each category, the forward cross entropy loss value is calculated.

[0083] According to the multiple second matching scores corresponding to the fourth instance, a probability value of the fourth instance corresponding to each category is calculated; according to the probability value of the fourth instance corresponding to each category, a reverse cross entropy loss value is calculated.

[0084] For example, the probability formula for forward training is:

[0085]

[0086] Where, is the first instance set S of the i-th category i The kth first instance, q is the second instance, P(S i ,q) is the second instance q corresponding to the first instance set S of the i-th category i The probability value of , that is, the probability value of the second instance q corresponding to the i-th category, The second instance q and the first instance set S of the i-th category i The first matching score between can be converted into the corresponding function

[0087] It should be noted that the second support set and the second query set may include G groups. For the second instance set and the fourth instance in each group, the probability formula for reverse training is:

[0088]

[0089] Where, is the second instance set S of the i-th category ′i The kth third instance, q′ is the fourth instance, P(S ′i ,q′) is the fourth instance q′ corresponding to the second instance set S of the i-th category′i The probability value of , that is, the probability value of the fourth instance q′ corresponding to the i-th category, The fourth instance q′ and the second instance set S of the i-th category i′ The second matching score between can be converted into the corresponding function is the second matching score between the fourth instance q′ and the second instance set of the i-th category.

[0090] Optionally, the forward cross entropy loss formula is:

[0091]

[0092] Where, J forward is the forward cross entropy loss, Q is the first query set, and R is the number of second instances in the first query set.

[0093] It should be noted that the second support set and the second query set may include G groups. For the second instance set and the fourth instance in each group, the inverse cross entropy loss formula is:

[0094]

[0095] Where, J reverse is the inverse cross entropy loss, Q′ is the second query set, and M is the number of fourth instances in each group in the second query set. According to the above inverse cross entropy loss formula, the second instance set and the fourth instance in each group are calculated to obtain Where g=1,…,G(G≥1). g is the weight corresponding to the g-th group.

[0096] The cross entropy loss formula is:

[0097]

[0098] Where, J total is the cross entropy loss, and G is the number of groups in the second support set.

[0099] Optionally, the model parameters of the preset few-shot relation extraction model are adjusted based on the calculated forward relation prototype, reverse relation prototype, and preset learning rate, and the next round of forward training and reverse training is performed on the few-shot relation extraction model after parameter adjustment based on the first support set and the first query set, and the cross-entropy loss value of the few-shot relation extraction model after parameter adjustment is calculated, that is, steps 102 to 105 are repeated for the few-shot relation extraction model after parameter adjustment based on the first support set and the first query set until the cross-entropy loss value is minimized, thereby obtaining an updated few-shot relation extraction model. The preset learning rate can be set as needed, for example, it can be set to 0.2.

[0100] Exemplarily, when judging whether the cross entropy loss value is the smallest, gradient calculation is performed on all the obtained cross entropy loss values to determine whether the cross entropy loss value of the few-sample relationship extraction model after this round of parameter adjustment is the smallest.

[0101] In another possible implementation, the training method for the few-sample relationship extraction model provided in the embodiment of the present application may further include:

[0102] S11. Determine a pseudo relation label for each fourth instance according to a second matching score between each fourth instance and a second instance set of each category.

[0103] S12. Calculate the model accuracy of the updated few-sample relation extraction model based on the pseudo-relationship label corresponding to the second instance and the pseudo-relationship label corresponding to the fourth instance corresponding to the updated few-sample relation extraction model, and the relationship label corresponding to the second instance and the relationship label corresponding to the fourth instance in the sentence text set.

[0104] S13. Determine different first support sets and first query sets based on the sentence text set, and repeat the step of determining the updated few-sample relationship extraction model to obtain multiple updated few-sample relationship extraction models and corresponding model accuracies, and determine the updated few-sample relationship extraction model with the highest model accuracy as the final few-sample relationship extraction model, so that entity relationships can be extracted from sentences marked with entity pairs according to the final few-sample relationship extraction model.

[0105] Optionally, in each group of the second query set and the second support set, based on the second matching score between each fourth instance and the second instance set of each category, that is, the score of each fourth instance corresponding to each category, that is, the score of each fourth instance corresponding to each relationship label, the relationship label with the highest score is selected as the pseudo relationship label of the fourth instance.

[0106] Exemplarily, for the second and fourth instances corresponding to the updated few-shot relation extraction model, each second instance corresponds to the relation label of the second instance annotated in the sentence text set, that is, the true label corresponding to the second instance, and each fourth instance corresponds to the relation label of the fourth instance annotated in the sentence text set, that is, the true label corresponding to the fourth instance. If the pseudo-relation label corresponding to the second instance is the same as the true label corresponding to the second instance, then the second instance is confirmed to be the correct instance. If the pseudo-relation label corresponding to the fourth instance is the same as the true label corresponding to the fourth instance, then the fourth instance is also confirmed to be the correct instance. The ratio of the number of correct instances in all second and fourth instances to the total number of instances of all second and fourth instances is used as the model accuracy of the updated few-shot relation extraction model.

[0107] Optionally, different first support sets and first query sets are determined based on the sentence text set, and steps 102 to 105 and S11 to S13 are repeated a preset number of times to obtain multiple updated few-sample relationship extraction models and corresponding model accuracies, and the updated few-sample relationship extraction model with the highest model accuracy is selected as the final few-sample relationship extraction model.

[0108] Determining multiple updated few-shot relation extraction models and their corresponding model accuracies, and selecting the updated few-shot relation extraction model with the highest model accuracy as the final few-shot relation extraction model can further improve the classification accuracy of the few-shot relation extraction model, thereby achieving effective extraction of entity relations in sentences.

[0109] An embodiment of the present application provides a training method for a few-sample relationship extraction model, which constructs a first support set and a first query set to perform forward training on a preset few-sample relationship extraction model, obtains a forward relationship prototype of each second instance in the first query set and the first instance set of each category in the first support set, and a first matching score, and constructs a second support set and a second query set based on the result of the forward training and the first query set to perform reverse training on the preset few-sample relationship extraction model, obtains a reverse relationship prototype of each fourth instance in the second query set and the second instance set of each category in the second support set, and a second matching score, determines a cross-entropy loss value based on the first matching score and the second matching score, adjusts the parameters of the preset few-sample relationship extraction model based on the forward relationship prototype and the reverse relationship prototype, and obtains an updated few-sample relationship extraction model based on the cross-entropy loss value, improves the classification accuracy of the few-sample relationship extraction model through reverse training, and effectively extracts the entity relationship of the sentence.

[0110] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0111] Figure 4 Schematic diagram of the structure of the training device of the few-sample relationship extraction model provided by one embodiment of the present application. Figure 4 As shown, the training device for the few-sample relationship extraction model provided in this embodiment may include: a first determination module 201, a first training module 202, a second determination module 203, a second training module 204 and a parameter adjustment module 205.

[0112] Among them, the first determination module 201 is used to determine the first support set and the first query set for forward training based on the acquired sentence text set, the instances in the sentence text set are annotated with entity pairs and relationship labels, and the first support set has a first instance set divided into multiple categories according to the relationship labels.

[0113] The first training module 202 is used to perform forward training on a preset few-sample relationship extraction model using the first support set and the first query set, to obtain a positive relationship prototype between each second instance in the first query set and the first instance set of each category in the first support set, and to determine a first matching score between each second instance and the first instance set of each category, and a pseudo-relationship label for each second instance based on the positive relationship prototype.

[0114] The second determination module 203 is used to construct a second support set for inverse training based on the pseudo relationship labels of the first query set and the second instance, and to construct a second query set for inverse training based on the sentence text set and the second support set. The second support set includes a second instance set divided into multiple categories according to the relationship labels, and the categories of the second instance set correspond to the categories of the first instance set.

[0115] The second training module 204 is used to use the second support set and the second query set to reversely train the preset few-sample relationship extraction model, obtain the reverse relationship prototype between each fourth instance in the second query set and the second instance set of each category in the second support set, and determine the second matching score between each fourth instance and the second instance set of each category based on the reverse relationship prototype.

[0116] The parameter adjustment module 205 is used to determine the cross entropy loss value based on the first matching score and the second matching score, adjust the parameters of the preset few-sample relationship extraction model according to the forward relationship prototype and the reverse relationship prototype, and obtain the updated few-sample relationship extraction model according to the cross entropy loss value.

[0117] Optionally, the first determination module 201 is specifically used to: determine the first support set and the first query set for forward training based on the acquired sentence text set and the preset task scenario; the preset task scenario determines the category of the first instance set in the first support set and the number of first instances in the first instance set; the category of the second instance in the first query set corresponds to the category of the first instance set.

[0118] Optionally, the second determination module 203 is specifically used to: construct a second support set for reverse training based on a preset task scenario, pseudo-relationship labels of the first query set and the second instance; the second support set includes all second instances in the first query set; the preset task scenario determines the category of the second instance set in the second support set and the number of third instances in the second instance set; construct a second query set for reverse training based on the sentence text set and the second support set; the category of the fourth instance in the second query set corresponds to the category of the second instance set.

[0119] Optionally, the parameter adjustment module 205 is specifically used to: calculate a forward cross entropy loss value based on multiple first matching scores corresponding to the second instance; calculate a reverse cross entropy loss value based on multiple second matching scores corresponding to the fourth instance; and calculate the sum of the forward cross entropy loss value and the reverse cross entropy loss value as the cross entropy loss value.

[0120] Optionally, the parameter adjustment module 205 is further specifically used to: calculate the probability value of each category corresponding to the second instance based on the multiple first matching scores corresponding to the second instance; calculate the forward cross entropy loss value based on the probability value of each category corresponding to the second instance; calculate the probability value of each category corresponding to the fourth instance based on the multiple second matching scores corresponding to the fourth instance; calculate the reverse cross entropy loss value based on the probability value of each category corresponding to the fourth instance.

[0121] Optionally, the parameter adjustment module 205 is also specifically used to: adjust the parameters of the preset few-sample relationship extraction model according to the forward relationship prototype, the reverse relationship prototype and the preset learning rate to obtain the few-sample relationship extraction model after parameter adjustment; perform the next round of forward training and reverse training on the few-sample relationship extraction model after parameter adjustment until the cross-entropy loss value is minimized, thereby obtaining the updated few-sample relationship extraction model.

[0122] Optionally, the parameter adjustment module 205 is also specifically used to: determine the pseudo relationship label of each fourth instance based on the second matching score between each fourth instance and the second instance set of each category; accordingly, calculate the model accuracy of the updated few-sample relationship extraction model based on the pseudo relationship label corresponding to the second instance and the pseudo relationship label corresponding to the fourth instance corresponding to the updated few-sample relationship extraction model, and the relationship label corresponding to the second instance and the relationship label corresponding to the fourth instance in the sentence text set; determine different first support sets and first query sets based on the sentence text set, and repeat the step of determining the updated few-sample relationship extraction model to obtain multiple updated few-sample relationship extraction models and corresponding model accuracies, and determine the updated few-sample relationship extraction model with the highest model accuracy as the final few-sample relationship extraction model, so that entity relationships are extracted for sentences marked with entity pairs according to the final few-sample relationship extraction model.

[0123] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of this application. Their specific functions and technical effects can be found in the method embodiment section and will not be repeated here.

[0124] Figure 5 This is a schematic diagram of the structure of a terminal device provided by an embodiment of the present application. Figure 5As shown, the terminal device 300 of this embodiment includes: a processor 310 and a memory 320, wherein the memory 320 stores a computer program 321 that can be run on the processor 310. When the processor 310 executes the computer program 321, the steps in any of the above-mentioned method embodiments are implemented, such as Figure 1 Alternatively, when the processor 310 executes the computer program 321, the functions of the modules / units in the above-mentioned device embodiments are realized, for example Figure 4 Functions of modules 201 to 205 are shown.

[0125] Exemplarily, the computer program 321 may be divided into one or more modules / units, one or more of which are stored in the memory 320 and executed by the processor 310 to complete the present application. The one or more modules / units may be a series of computer program instruction segments capable of completing specific functions, and the instruction segments are used to describe the execution process of the computer program 321 in the terminal device 300.

[0126] Those skilled in the art will understand that Figure 5 These are merely examples of terminal devices and do not constitute a limitation on the terminal devices. The terminal devices may include more or fewer components than shown in the figure, or a combination of certain components, or different components, such as input and output devices, network access devices, buses, etc.

[0127] The processor 310 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.

[0128] The memory 320 can be an internal storage unit of the terminal device, such as the terminal device's hard drive or memory, or an external storage device of the terminal device, such as a plug-in hard drive, a SmartMedia Card (SMC), a Secure Digital (SD) card, a flash memory card, etc. The memory 320 can also include both the internal storage unit of the terminal device and an external storage device. The memory 320 is used to store computer programs and other programs and data required by the terminal device. The memory 320 can also be used to temporarily store data that has been output or is about to be output.

[0129] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0130] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant description of other embodiments.

[0131] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present invention.

[0132] In the embodiments provided by the present invention, it should be understood that the disclosed devices / terminal equipment and methods can be implemented in other ways. For example, the device / terminal equipment embodiments described above are merely illustrative. For example, the division of the modules or units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0133] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.

[0134] In addition, the functional units in the various embodiments of the present invention may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.

[0135] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and when the computer program is executed by the processor, it can implement the steps of the above-mentioned various method embodiments. . Wherein, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form, etc. The computer-readable medium can include: any entity or device that can carry the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc.

[0136] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention, and should all be included in the scope of protection of the present invention.

Claims

1. A training method for a few-sample relation extraction model, characterized in that: include: Determining a first support set and a first query set for forward training based on the acquired sentence text set, wherein instances in the sentence text set are annotated with entity pairs and relationship labels, and the first support set includes a first instance set divided into multiple categories according to the relationship labels; Performing forward training on a preset few-shot relationship extraction model using the first support set and the first query set to obtain a positive relationship prototype between each second instance in the first query set and the first instance set of each category in the first support set, and determining a first matching score between each second instance and the first instance set of each category and a pseudo relationship label for each second instance based on the positive relationship prototype; Constructing a second support set for reverse training based on the pseudo-relationship labels between the first query set and the second instance, and constructing a second query set for reverse training based on the sentence text set and the second support set, wherein the second support set includes a second instance set divided into multiple categories based on the relationship labels, and the categories of the second instance set correspond to the categories of the first instance set; performing reverse training on a preset few-shot relationship extraction model using the second support set and the second query set to obtain a reverse relationship prototype between each fourth instance in the second query set and the second instance set of each category in the second support set, and determining a second matching score between each fourth instance and the second instance set of each category based on the reverse relationship prototype; A cross-entropy loss value is determined according to the first matching score and the second matching score, parameters of the preset few-sample relationship extraction model are adjusted according to the forward relationship prototype and the reverse relationship prototype, and an updated few-sample relationship extraction model is obtained according to the cross-entropy loss value.

2. The training method for a few-sample relationship extraction model according to claim 1, characterized in that: The step of determining a first support set and a first query set for forward training based on the acquired sentence text set includes: The first support set and the first query set for forward training are determined based on the acquired sentence text set and the preset task scenario; the preset task scenario determines the category of the first instance set in the first support set and the number of first instances in the first instance set; the category of the second instance in the first query set corresponds to the category of the first instance set.

3. The training method for a few-sample relationship extraction model according to claim 2, characterized in that: The step of constructing a second support set for reverse training based on the pseudo relationship labels of the first query set and the second instance, and constructing a second query set for reverse training based on the sentence text set and the second support set, includes: A second support set for reverse training is constructed based on the preset task scenario, the pseudo-relationship labels of the first query set and the second instance; the second support set includes all the second instances in the first query set; the preset task scenario determines the category of the second instance set in the second support set and the number of third instances in the second instance set; A second query set for reverse training is constructed based on the sentence text set and the second support set; the category of the fourth instance in the second query set corresponds to the category of the second instance set.

4. The training method for a few-sample relationship extraction model according to claim 1, wherein: Determining a cross entropy loss value according to the first matching score and the second matching score includes: Calculating a forward cross entropy loss value based on the plurality of first matching scores corresponding to the second instance; Calculating a reverse cross entropy loss value based on the plurality of second matching scores corresponding to the fourth instance; The sum of the forward cross entropy loss value and the reverse cross entropy loss value is calculated as the cross entropy loss value.

5. The training method for a few-sample relationship extraction model according to claim 4, characterized in that: calculating a forward cross entropy loss value based on the plurality of first matching scores corresponding to the second instance; Calculating a reverse cross entropy loss value according to the plurality of second matching scores corresponding to the fourth instance includes: Calculating a probability value of each category corresponding to the second instance based on the multiple first matching scores corresponding to the second instance; and calculating a forward cross entropy loss value based on the probability value of each category corresponding to the second instance; According to the multiple second matching scores corresponding to the fourth instance, a probability value of the fourth instance corresponding to each category is calculated; according to the probability value of the fourth instance corresponding to each category, a reverse cross entropy loss value is calculated.

6. The training method for a few-sample relationship extraction model according to claim 1, characterized in that: The step of adjusting parameters of the preset few-sample relation extraction model according to the forward relation prototype and the reverse relation prototype, and obtaining an updated few-sample relation extraction model according to the cross entropy loss value, includes: Adjusting the parameters of the preset few-sample relation extraction model according to the forward relation prototype, the reverse relation prototype, and a preset learning rate to obtain a few-sample relation extraction model after parameter adjustment; The next round of forward training and reverse training is performed on the adjusted few-sample relationship extraction model until the cross entropy loss value is minimized, thereby obtaining an updated few-sample relationship extraction model.

7. The training method for a few-sample relationship extraction model according to any one of claims 1 to 6, characterized in that: The method further includes: determining a pseudo relationship label of each fourth instance according to a second matching score between each fourth instance and a second instance set of each category; Accordingly, the model accuracy of the updated few-shot relation extraction model is calculated based on the pseudo-relationship label corresponding to the second instance and the pseudo-relationship label corresponding to the fourth instance corresponding to the updated few-shot relation extraction model, and the relationship label corresponding to the second instance and the relationship label corresponding to the fourth instance in the sentence text set; Different first support sets and first query sets are determined based on the sentence text set, and the step of determining the updated few-sample relationship extraction model is repeated to obtain multiple updated few-sample relationship extraction models and corresponding model accuracies. The updated few-sample relationship extraction model with the highest model accuracy is determined as the final few-sample relationship extraction model, so that entity relationships are extracted from sentences marked with entity pairs according to the final few-sample relationship extraction model.

8. A training device for a few-sample relationship extraction model, characterized in that: include: A first determination module is configured to determine a first support set and a first query set for forward training based on an acquired sentence text set, wherein instances in the sentence text set are annotated with entity pairs and relationship labels, and the first support set includes a first instance set divided into multiple categories according to the relationship labels; a first training module, configured to perform forward training on a preset few-shot relation extraction model using the first support set and the first query set, to obtain a positive relation prototype between each second instance in the first query set and the first instance set of each category in the first support set, and to determine, based on the positive relation prototype, a first matching score between each second instance and the first instance set of each category, and a pseudo relation label for each second instance; a second determining module, configured to construct a second support set for reverse training based on the pseudo relation labels between the first query set and the second instance, and to construct a second query set for reverse training based on the sentence text set and the second support set, wherein the second support set includes a second instance set divided into a plurality of categories based on the relation labels, and the categories of the second instance set correspond to the categories of the first instance set; a second training module, configured to perform reverse training on a preset few-shot relationship extraction model using the second support set and the second query set, to obtain a reverse relationship prototype between each fourth instance in the second query set and the second instance set of each category in the second support set, and to determine a second matching score between each fourth instance and the second instance set of each category based on the reverse relationship prototype; A parameter adjustment module is used to determine a cross-entropy loss value based on the first matching score and the second matching score, adjust the parameters of the preset few-sample relationship extraction model based on the forward relationship prototype and the reverse relationship prototype, and obtain an updated few-sample relationship extraction model based on the cross-entropy loss value.

9. A terminal device comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, characterized in that: When the processor executes the computer program, it implements the training method of the few-sample relationship extraction model as described in any one of claims 1 to 7.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the training method of the few-sample relationship extraction model according to any one of claims 1 to 7 is implemented.