Relationship extraction model training method, relation extraction method, equipment and storage medium
The training method for relationship extraction models addresses the challenge of distinguishing similar relationships by integrating historical samples and data augmentation, enhancing performance and robustness through continuous learning and data exposure.
Patent Information
- Application Number
- CN202510351878.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-24
- Publication Date
- 2025-07-15
AI Technical Summary
Existing relationship extraction models will deteriorate performance when processing data of similar relationships, resulting in insufficient robustness.
By adding replay samples of historical training tasks and enhanced samples generated based on them during the training process, the model's understanding and generalization ability of similar relational data is improved, including adding current batch training samples, current batch replay samples and current batch enhancement samples marked with entity relationship categories in the training data, and using data enhancement technology to generate samples.
It effectively improves the performance and robustness of the model when processing similar relational data, ensuring that the model can accurately identify various types of entity relationships.
Smart Images

Figure CN120317339A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and in particular, to a method for training a relation extraction model, a relation extraction method, a device, and a storage medium. Background Art
[0002] Relation Extraction (RE) is a natural language processing (NLP) task whose purpose is to automatically identify the types of relationships between entities in text. With the development of the Internet, a large amount of text information has been generated and stored. It has become increasingly important to extract structured information from these unstructured text data. Relation extraction is exactly such a process that can automatically extract the relationships between entities from text, and then assist in constructing a knowledge graph or other forms of structured databases.
[0003] However, the current relation extraction models perform poorly when dealing with data of similar relationships. For example, "kinship" and "employment relationship" belong to relatively similar relationships. When data of such similar relationships appears, it is unable to accurately distinguish between "employment relationship" and "kinship", thereby resulting in poor robustness of the model. Summary of the Invention
[0004] The present invention provides a method for training a relation extraction model, a relation extraction method, a device, and a storage medium, so as to solve the problem that the performance of the existing relation extraction model deteriorates when dealing with data of similar relationships.
[0005] The present invention provides a method for training a relation extraction model, including the following steps: Obtain training data corresponding to the current training batch, where the training data includes current batch training samples, current batch replay samples, and current batch augmented samples labeled with entity relation categories under the current training task; the current batch replay samples are randomly selected from a first replay sample set of the current training task, the first replay sample set is screened from a second replay sample set of the previous training task, and the third replay sample set of the first training task is constructed based on the training samples of the first training task; the current batch augmented samples are obtained by performing data augmentation on the current batch replay samples; Use the training data corresponding to the current training batch to train the relation extraction model in the current training stage to obtain a trained target relation extraction model.
[0006] According to the method for training a relation extraction model provided by the present invention, obtaining the first replay sample set of the current training task includes: Input the replay samples in the second replay sample set of the previous training task into the relation extraction model of the current training stage to obtain the relation extraction prediction results of the second replay sample set; Based on the true relation extraction results and the relation extraction prediction results of the second replay sample set, divide the second replay sample set into at least one first replay sample with correct prediction and at least one second replay sample with incorrect prediction; Determine the distance score of each first replay sample and the distance score of each second replay sample; Arrange the first replay samples and the second replay samples in ascending order of distance scores respectively to obtain the replay sample sorting result; among them, the second replay sample with the smallest distance score is located after the first replay sample with the largest distance score; Based on the replay sample sorting result, select the replay samples with the replay upper limit number of the current training task as the first replay sample set of the current training task.
[0007] According to a relation extraction model training method provided by the present invention, the method further includes: In the case where the data volume of the training samples of the first training task is greater than the replay upper limit number of the first training task, select the first training samples with the replay upper limit number of the first training task from the training samples of the first training task as candidate replay samples; Select second training samples other than the first training samples from the training samples of the first training task, and in the case where the distance score of the second training samples is less than the distance score of the first training samples, use the second training samples to replace the first training samples to obtain the third replay sample set of the first training task.
[0008] According to a relation extraction model training method provided by the present invention, it further includes: For each sample, determine the first distance between the sample and the first category samples, and determine the second distance between the sample and the second category samples; the first category samples are the original samples of the entity relation category of the sample in the original sample set, and the second category samples are the original samples other than the first category samples in the original sample set; Based on the first distance and the second distance, obtain the distance score of the sample.
[0009] According to a relation extraction model training method provided by the present invention, it further includes: Determine the number of replay samples of the previous training task and the number of entity relation categories of the current training task; Determine the replay upper limit number of the current training task based on the number of replay samples and the number of entity relationship categories.
[0010] According to a method for training a relationship extraction model provided by the present invention, obtaining current batch augmented samples corresponding to the current training batch includes: Select at least one pair of replay sample pairs from the current batch of replay samples; Obtain the head and tail entities and entity relationships in one replay sample of each replay sample pair, and multiple keywords other than the head and tail entities from the other replay sample of each replay sample pair; Based on the prompt template, convert the head and tail entities, entity relationships, and multiple keywords of each replay sample pair into prompt information, and input them into a pre-trained data augmentation large language model to obtain augmented samples for each replay sample pair.
[0011] According to a method for training a relationship extraction model provided by the present invention, the method further includes: Obtain a relationship extraction training set, where the relationship extraction training set includes text data of multiple entity relationship categories; Divide the relationship extraction training set into training samples corresponding to multiple training tasks; the entity relationship categories of the text data in the training samples corresponding to each training task are different.
[0012] The present invention provides a method for training a relationship extraction model, including the following steps: Obtain text data to be extracted; Input the text data to be extracted into the target relationship extraction model to obtain the entities and entity relationships output by the target relationship extraction model; Wherein, the target relationship extraction model is obtained based on any one of the above-mentioned relationship extraction model training methods.
[0013] The present invention further provides a device for training a relationship extraction model, including: A first relationship extraction module for obtaining training data corresponding to the current training batch, where the training data includes current batch training samples, current batch replay samples, and current batch augmented samples labeled with entity relationship categories under the current training task; the current batch of replay samples is randomly selected from the first replay sample set of the current training task, the first replay sample set is screened from the second replay sample set of the previous training task, and the third replay sample set of the first training task is constructed based on the training samples of the first training task; the current batch of augmented samples is obtained by performing data augmentation on the current batch of replay samples; The second relation extraction module is used to train the relation extraction model in the current training stage by using the training data corresponding to the current training batch, so as to obtain a trained target relation extraction model.
[0014] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored on the memory and running on the processor. When the processor executes the program, the method for training a relation extraction model as described in any one of the above is implemented.
[0015] The present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the method for training a relation extraction model as described in any one of the above is implemented.
[0016] The present invention also provides a computer program product, including a computer program. When the computer program is executed by a processor, the method for training a relation extraction model as described in any one of the above is implemented.
[0017] The method for training a relation extraction model, the relation extraction method, the device, and the storage medium provided by the present invention obtain the training data corresponding to the current training batch. The training data includes the current batch of training samples, the current batch of replay samples, and the current batch of augmented samples labeled with the entity relation categories of the current training batch. Then, the relation extraction model in the current training stage is trained by using the training data corresponding to the current training batch, so as to obtain a trained target relation extraction model. By adding the replay samples of historical training tasks and the augmented samples generated based on them to the original training samples, in the training process, the model can not only learn the data features of the current training task, but also continuously contact the data features in the training tasks. At the same time, with the help of the augmented samples, the understanding and generalization ability of similar relation data are further improved, so as to effectively solve the problems of poor performance and insufficient robustness of the relation extraction model when processing similar relation data, and improve the overall performance and robustness of the model. Description of the Drawings
[0018] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0019] Figure 1 It is a schematic flowchart of the method for training a relation extraction model provided by the present invention.
[0020] Figure 2 It is a schematic structural diagram of the device for training a relation extraction model provided by the present invention.
[0021] Figure 3 This is a schematic structural diagram of the electronic device provided by the present invention. Specific Embodiments
[0022] To make the objectives, technical solutions and advantages of the present invention clearer, the technical solutions in the present invention will be clearly and completely described below with reference to the accompanying drawings in the present invention. Apparently, the described embodiments are some but not all of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present invention without creative efforts shall fall within the protection scope of the present invention.
[0023] The method for training the relationship extraction model according to the embodiment of the present invention is as Figure 1 shown, and includes Step 110 and Step 120.
[0024] Step 110: Obtain training data corresponding to the current training batch, where the training data includes current batch training samples, current batch replay samples, and current batch augmented samples labeled with entity relationship categories under the current training task.
[0025] Here, the entity relationship category refers to different types of relationships existing between entities in the text, such as kinship, employment relationship, organizational relationship, etc.
[0026] The current batch training samples under the current training task refer to samples labeled with entity relationship categories of the current training batch under the current training task. It can be a batch of original samples labeled with entity relationship categories randomly sampled from the new sample set of the current training task, so that the model can learn newly emerging entity relationship categories.
[0027] The current batch replay samples refer to samples of old batches sampled from the training samples of historical tasks during the training process to enhance the generalization ability and stability of the model, so as to prevent the model from forgetting the entity relationship categories it has learned.
[0028] The current batch augmented samples refer to samples generated by data augmentation of the current batch of original data (such as new training samples or replay samples), such as samples generated by data augmentation through methods such as synonym replacement, random insertion, deletion, or replacement of words, so as to improve data diversity and enhance the generalization ability and robustness of the model for identifying similar relationships.
[0029] In this embodiment, the current batch replay samples are randomly selected from the first replay sample set of the current training task, the first replay sample set is screened from the second replay sample set of the previous training task, and the third replay sample set of the first training task is constructed based on the training samples of the first training task.
[0030] In this embodiment, the replay samples in each training batch under each training task are randomly selected from the replay sample set under this training task.
[0031] It should be further understood that in the first training task, only the training samples of the first training task are used to train the model. After the first training task is completed, the third replay sample set of the first training task is constructed from the training samples of the first training task. Then, in the second training task, the second replay sample set of the second training task is screened out using the third replay sample set of the first training task, so as to train the model by combining the replay samples in the second replay sample set under the second training task. And so on, in subsequent multiple training tasks, the replay sample set under the current training task is sequentially screened out from the replay sample set of the previous training task.
[0032] In this embodiment, the current batch of augmented samples is obtained by data augmentation based on the current batch of replay samples.
[0033] It should be understood that since the replay samples are representative and important samples screened from previous training tasks, they usually contain some key features. Therefore, the augmented samples after data augmentation of the replay samples not only retain the key features of the original replay samples, but also increase the diversity and complexity of the data through data augmentation techniques, improve the sensitivity and recognition ability of the model to key features, and thus improve the performance of the model in practical applications.
[0034] Step 120: Use the training data corresponding to the current training batch to train the relation extraction model in the current training stage, and obtain the trained target relation extraction model.
[0035] In this embodiment, the Bert-base model can be used as the base model of the relation extraction model. The Bert-base model is a pre-trained natural language processing model based on the Transformer architecture. It contains 12 Transformer encoder layers, and each encoder layer contains a self-attention mechanism and a feed-forward neural network. The dimension of the input embedding vector of the Bert-base model is 768, and the dimension of the hidden layer is also 768. That is to say, for an input text, the Bert-base model can transform it into a 768-dimensional vector.
[0036] Here, the training data composed of the above three types of samples is input into the relation extraction model in the current training stage. The difference between the output of the model and the entity relation categories annotated in the samples is compared, and the value of the loss function is calculated. According to the value of the loss function, the parameters of the model are updated through the backpropagation algorithm to minimize the loss function. By continuously training with the training data in each training batch of each training task, the parameters of the model are adjusted so that the model can accurately extract the relations between entities, and the trained target relation extraction model is obtained.
[0037] In the relation extraction model training method of this embodiment, by adding replay samples of historical training tasks and augmented samples generated based on them to the original training samples, during the training process, the model can not only learn the data features of the current training task, but also continuously be exposed to the data features in the training tasks. At the same time, with the help of the augmented samples, the understanding and generalization ability of similar relation data are further improved, thereby effectively solving the problems of poor performance and insufficient robustness of the relation extraction model when dealing with similar relation data, and improving the overall performance and robustness of the model.
[0038] It should be noted that each embodiment of this application can be freely combined, the order can be swapped, or each can be executed independently, and does not need to rely on or depend on a fixed execution order.
[0039] In some embodiments, it further includes: Obtain a relation extraction training set, where the relation extraction training set includes text data of multiple entity relation categories; Divide the relation extraction training set into training samples corresponding to multiple training tasks; the entity relation categories of the text data in the training samples corresponding to each training task are different.
[0040] The relation extraction training set contains text data of multiple entity relation categories. These text data can be sentences, paragraphs or documents, and the relation categories between entities are annotated in each text data.
[0041] In this embodiment, the entire relation extraction training set is divided into multiple training tasks, and the parameters of the model are gradually updated through multiple training tasks during the training process. Usually, the relation extraction training set is randomly divided into multiple training tasks, and each training task contains a certain number of training samples. In this way, it is ensured that the model is exposed to different types of samples during the training process, improving the generalization ability of the model.
[0042] Furthermore, in this embodiment, by ensuring that each training task contains training samples of different entity relation categories, it is prevented that the model overfits to a certain type of entity relation during the training process, and the robustness and generalization ability of the model are improved.
[0043] For example, in one example, the relation extraction training set contains 80 entity relation categories, and each entity relation category has 700 training samples. Then, the relation extraction training set is divided into training samples corresponding to 10 training tasks. Each training task contains training samples of 8 entity relation categories.
[0044] In the relation extraction model training method of this embodiment, by dividing the relation extraction training set into multiple training tasks, and each training task contains relation samples of different categories, the generalization ability and robustness of the model can be effectively improved, overfitting can be avoided, and it is ensured that the model can accurately extract various types of entity relations in actual applications.
[0045] In some embodiments, obtaining the first replay sample set of the current training task includes: Inputting the replay samples in the second replay sample set of the previous training task into the relation extraction model of the current training stage to obtain the relation extraction prediction results of the second replay sample set; Based on the true relation extraction results and the relation extraction prediction results of the second replay sample set, dividing the second replay sample set into at least one first replay sample with correct prediction and at least one second replay sample with incorrect prediction; Determining the distance score of each first replay sample and the distance score of each second replay sample; Respectively arranging the first replay samples and the second replay samples in ascending order of the distance score to obtain the replay sample sorting result; among them, the second replay sample with the smallest distance score is located after the first replay sample with the largest distance score; Based on the replay sample sorting result, selecting the replay samples with the replay upper limit number of the current training task as the first replay sample set of the current training task.
[0046] In this embodiment, first, it is judged whether the replay samples in the second replay sample set of the previous training task can be correctly classified by the relation extraction model of the current training stage. According to the classification result of the relation extraction model of the current training stage on the second replay sample set of the training task, the replay samples in the second replay sample set of the training task are divided into first replay samples with correct prediction and second replay samples with incorrect prediction.
[0047] Next, calculate the distance score of each replay sample. Here, the distance score is used to measure the similarity between the replay sample and the original sample corresponding to this replay sample. For example, by calculating the Euclidean distance, cosine similarity, Manhattan distance, etc. between the replay sample and the original sample corresponding to this replay sample, the distance score of the replay sample is determined. Generally, the smaller the distance score, the more similar the two samples are; the larger the distance score, the more different the two samples are.
[0048] After calculating the distance scores of each first replay sample with correct prediction and each second replay sample with incorrect prediction, they are rearranged in the order of correct classification samples first and incorrect classification samples second, and in ascending order of distance scores to obtain the replay sample sorting result. Finally, the first n samples in the replay sample sorting result are retained as the replay samples for the current training task. Here, n is the replay upper limit number of the first replay sample set of the current training task.
[0049] In the method for training the relation extraction model of this embodiment, reorganizing the priorities of the replay samples according to the classification results can ensure that the retained replay samples can better retain knowledge and help the relation extraction model better overcome catastrophic forgetting.
[0050] In some embodiments, it further includes: When the data volume of the training samples of the first training task is greater than the replay upper limit number of the first training task, the replay upper limit number of first training samples of the first training task is selected from the training samples of the first training task as candidate replay samples; The second training samples other than the first training samples are selected from the training samples of the first training task, and when the distance score of the second training sample is less than the distance score of the first training sample, the second training sample is used to replace the first training sample to obtain the third replay sample set of the first training task.
[0051] In this embodiment, the replay samples of the first training task are selected from the training samples of the first training task. Therefore, when the data volume of the training samples of the first training task is greater than the replay upper limit number of the first training task, the replay upper limit number of training samples of the first training task can be randomly selected from the training samples of the first training task as candidate replay samples first.
[0052] Then, a first training sample is randomly selected from the candidate replay samples , and a second training sample other than the first training sample is randomly selected from the training samples of the first training task . Then, the distance scores of these two samples are calculated respectively. If the distance score of the second training sample is less than the distance score of the first training sample , then the second training sample is used to replace this first training sample . The above process is repeated until there are no optional second training samples, and the third replay sample set of the first training task can be constructed.
[0053] Here, the distance score of each sample is used to measure the similarity between the sample and the original sample corresponding to this sample. For example, by calculating the Euclidean distance, cosine similarity, Manhattan distance, etc. between the sample and the original sample corresponding to this sample, the distance score of the sample is determined. Generally, the smaller the distance score, the more similar the two samples are; the larger the distance score, the more different the two samples are.
[0054] In the method for training the relationship extraction model of this embodiment, during the construction of the replay samples of the first training task, by comparing the distance scores of the samples to screen the replay samples, it can be ensured that the replay samples are all clustered near the classification surface, helping the relationship extraction model to better overcome catastrophic forgetting.
[0055] In some embodiments, it further includes: For each sample, determine the first distance between the sample and the first category samples, and determine the second distance between the sample and the second category samples; the first category samples are the original samples of the entity relationship category of the sample in the original sample set, and the second category samples are the original samples in the original sample set except the first category samples; Based on the first distance and the second distance, obtain the distance score of the sample.
[0056] Specifically, the first category samples refer to the samples in the original sample set that have the same entity relationship category as the current sample. For example, if the entity relationship category of the current sample is an organizational relationship, then the first category samples are the samples labeled as organizational relationships in the original sample set.
[0057] The second category samples refer to all the samples in the original sample set except the first category samples. That is, the samples with different entity relationship categories from the current sample.
[0058] In this embodiment, various distance metric methods can be used, such as Euclidean distance, cosine similarity, etc. to calculate the first distance between the current sample and the first category samples, and the second distance between the current sample and the second category samples respectively. Finally, the first distance and the second distance are added as the distance score of the current sample.
[0059] In some embodiments, it further includes: Determine the number of replay samples of the previous training task, and the number of entity relationship categories of the current training task; Based on the number of replay samples and the number of entity relationship categories, determine the replay upper limit number of the current training task.
[0060] It should be understood that as the training tasks increase, the model can gradually learn more features and patterns. Therefore, in this embodiment, by dynamically adjusting the upper limit number of replay samples, it can better adapt to the requirements of the model for different training tasks.
[0061] Specifically, determine the number of replay samples corresponding to the previous training task and the number of entity relationship categories of the current training task. Then, divide the number of replay samples of the previous task by the number of entity relationship categories of the current training task to obtain the upper limit number of replay samples for the current training task.
[0062] In some embodiments, obtaining the current batch of augmented samples corresponding to the current training batch includes: Select at least one pair of replay sample pairs from the current batch of replay samples; Obtain the head and tail entities and the entity relationship in one replay sample of each replay sample pair, and obtain multiple keywords other than the head and tail entities from the other replay sample of each replay sample pair; Based on the prompt template, convert the head and tail entities, entity relationship, and multiple keywords of each replay sample pair into prompt information, and input it into the pre-trained data augmentation large language model to obtain the augmented sample of each replay sample pair.
[0063] Specifically, for the data augmentation large language model, the following prompt template is sampled in this embodiment: Prompt: The relationship between [head entity] and [tail entity] is [relationship label], and the three keywords are [keyword 1], [keyword 2], and [keyword 3]; Question: Please generate a sentence based on the given entities: [head entity], [tail entity] and [keyword 1], [keyword 2], and [keyword 3], and use at least one keyword during the generation process; Answer: [Generated sentence].
[0064] Here, each keyword is randomly selected from three words in the text, and it is ensured that the head and tail entities will not be selected.
[0065] In this embodiment, during the process of generating the current batch of augmented samples corresponding to the current training batch, the replay samples are combined in pairs. For the sake of easy understanding, take the replay sample and the replay sample as an example. Extract the head and tail entities and the entity relationship from the replay sample , and extract multiple keywords from the replay sample , and the head and tail entities of this sample are not included in the multiple keywords.
[0066] Then, take the replay sample The head and tail entities and entity relationships, as well as the replay samples Multiple keywords of are combined into Knowledge and Question according to the above prompt template, the Knowledge and Question are concatenated into the input prompt information, and finally the prompt information is input into the pre-trained data augmentation large language model to obtain the augmented samples for each of the replay sample pairs.
[0067] Here, the ChatGLM3-6b model can be used as the base model of the data augmentation large language model. The ChatGLM3-6b model is based on the GLM (Gated Linear Units) architecture and adopts the Transformer Encoder structure.
[0068] In the relationship extraction model training method of this embodiment, the similarity relationship of the augmented samples is improved in the above manner, and then the understanding and generalization ability of the model for the similarity relationship data is further enhanced by means of the augmented samples.
[0069] In addition, the present invention also provides a relationship extraction method, including the following steps: Obtain the text data to be extracted; Input the text data to be extracted into the target relationship extraction model to obtain the entities and entity relationships output by the target relationship extraction model.
[0070] Here, the target relationship extraction model is obtained based on the relationship extraction model training method described above, and will not be specifically elaborated here.
[0071] Next, the relationship extraction model training device provided by the present invention will be described. The relationship extraction model training device described below can be correspondingly referred to the relationship extraction model training method described above.
[0072] The relationship extraction model training device according to an embodiment of the present invention, as Figure 2 shown, includes the following modules: The first relationship extraction model training module 210 is used to obtain the training data corresponding to the current training batch. The training data includes the current batch of training samples, the current batch of replay samples, and the current batch of augmented samples labeled with the entity relationship categories under the current training task. The current batch of replay samples is randomly selected from the first replay sample set of the current training task. The first replay sample set is screened from the second replay sample set of the previous training task, and the third replay sample set of the first training task is constructed based on the training samples of the first training task. The current batch of augmented samples is obtained by data augmentation based on the current batch of replay samples; The second relation extraction model training module 220 is used to train the relation extraction model in the current training stage by using the training data corresponding to the current training batch, and obtain a trained target relation extraction model.
[0073] The relation extraction model training device of this embodiment obtains the training data corresponding to the current training batch. The training data includes the current batch of training samples, the current batch of replay samples, and the current batch of augmented samples labeled with the entity relation categories of the current training batch. Then, it trains the relation extraction model in the current training stage by using the training data corresponding to the current training batch, and obtains a trained target relation extraction model. In the present invention, by adding the replay samples of historical training tasks and the augmented samples generated based on them to the original training samples, during the training process, the model can not only learn the data features of the current training task, but also continuously come into contact with the data features in the training tasks. At the same time, with the help of the augmented samples, it can further improve the understanding and generalization ability of similar relation data, thus effectively solving the problems of poor performance and insufficient robustness of the relation extraction model when dealing with similar relation data, and improving the overall performance and robustness of the model.
[0074] Figure 3 An example of the entity structure diagram of an electronic device is shown as Figure 3 shown. The electronic device may include: a processor 310, a communication interface 320, a memory 330, and a communication bus 340. Among them, the processor 310, the communication interface 320, and the memory 330 complete mutual communication through the communication bus 340. The processor 310 can call the logical instructions in the memory 330 to execute the relation extraction model training method, and the method includes: Obtain the training data corresponding to the current training batch. The training data includes the current batch of training samples, the current batch of replay samples, and the current batch of augmented samples labeled with the entity relation categories under the current training task. The current batch of replay samples is randomly selected from the first replay sample set of the current training task. The first replay sample set is screened from the second replay sample set of the previous training task, and the third replay sample set of the first training task is constructed based on the training samples of the first training task. The current batch of augmented samples is obtained by data augmentation based on the current batch of replay samples; Train the relation extraction model in the current training stage by using the training data corresponding to the current training batch, and obtain a trained target relation extraction model.
[0075] In addition, when the logical instructions in the above-mentioned memory 330 are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as USB flash drives, mobile hard disks, read-only memories (ROMs, Read-Only Memories), random access memories (RAMs, Random Access Memories), magnetic disks, or optical discs.
[0076] On the other hand, the present invention also provides a computer program product. The computer program product includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the relationship extraction model training method provided by the above-mentioned various methods. The method includes: Obtain training data corresponding to the current training batch. The training data includes current batch training samples, current batch replay samples, and current batch enhanced samples labeled with entity relationship categories under the current training task. The current batch replay samples are randomly selected from a first replay sample set of the current training task. The first replay sample set is screened from a second replay sample set of the previous training task, and a third replay sample set of the first training task is constructed based on the training samples of the first training task. The current batch enhanced samples are obtained by performing data enhancement on the current batch replay samples. Use the training data corresponding to the current training batch to train the relationship extraction model in the current training stage to obtain a trained target relationship extraction model.
[0077] In yet another aspect, the present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it is implemented to execute the relationship extraction model training method provided by the above-mentioned various methods. The method includes: Obtain the training data corresponding to the current training batch. The training data includes the current batch of training samples, the current batch of replay samples, and the current batch of augmented samples that are labeled with entity relationship categories under the current training task. The current batch of replay samples is randomly selected from the first replay sample set of the current training task. The first replay sample set is screened from the second replay sample set of the previous training task, and the third replay sample set of the first training task is constructed based on the training samples of the first training task. The current batch of augmented samples is obtained by performing data augmentation on the current batch of replay samples. Use the training data corresponding to the current training batch to train the relationship extraction model in the current training stage, and obtain a trained target relationship extraction model.
[0078] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated. The components shown as units may or may not be physical units, that is, they may be located in one place, or they may be distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art can understand and implement it without creative labor.
[0079] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence, or the part that contributes to the prior art can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disc, etc., and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0080] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements for some of the technical features. And these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for training a relationship extraction model, characterized in that, Including: Obtain training data corresponding to the current training batch, where the training data includes current batch training samples, current batch replay samples, and current batch augmented samples labeled with entity relationship categories under the current training task; the current batch replay samples are randomly selected from a first replay sample set of the current training task, the first replay sample set is screened from a second replay sample set of the previous training task, and a third replay sample set of the first training task is constructed based on the training samples of the first training task; The current batch augmented samples are obtained by augmenting the current batch replay samples; Use the training data corresponding to the current training batch to train the relationship extraction model in the current training stage to obtain a trained target relationship extraction model.
2. The relationship extraction model training method according to claim 1, wherein Obtain the first replay sample set of the current training task, including: Input the replay samples in the second replay sample set of the previous training task into the relationship extraction model in the current training stage to obtain the relationship extraction prediction results of the second replay sample set; Based on the true relationship extraction results and the relationship extraction prediction results of the second replay sample set, divide the second replay sample set into at least one first replay sample with correct prediction and at least one second replay sample with incorrect prediction; Determine the distance score of each first replay sample and the distance score of each second replay sample; Arrange the first replay samples and the second replay samples in ascending order of distance scores respectively to obtain a replay sample sorting result; among them, the second replay sample with the smallest distance score is located after the first replay sample with the largest distance score; Based on the replay sample sorting result, select the replay samples with the replay upper limit number of the current training task as the first replay sample set of the current training task.
3. The relationship extraction model training method according to claim 1, wherein The method further includes: In the case where the data volume of the training samples of the first training task is greater than the replay upper limit number of the first training task, select the replay upper limit number of first training samples of the first training task from the training samples of the first training task as candidate replay samples; Select second training samples other than the first training samples from the training samples of the first training task, and use the second training samples to replace the first training samples when the distance score of the second training samples is less than the distance score of the first training samples to obtain a third replay sample set of the first training task.
4. The method for training a relationship extraction model according to claim 2 or 3, wherein It further includes: For each sample, determine the first distance between the sample and the first category samples, and determine the second distance between the sample and the second category samples; The first category samples are the original samples of the entity relationship category of the sample in the original sample set, and the second category samples are the original samples other than the first category samples in the original sample set; Based on the first distance and the second distance, obtain the distance score of the sample.
5. The relationship extraction model training method according to claim 2, wherein It further includes: Determine the number of replay samples of the previous training task and the number of entity relationship categories of the current training task; Determine the replay upper limit number of the current training task based on the number of replay samples and the number of entity relationship categories.
6. The relationship extraction model training method according to claim 1, characterized in that, Obtain the current batch of augmented samples corresponding to the current training batch, including: Select at least one pair of replay sample pairs from the current batch of replay samples; Obtain the head and tail entities and the entity relationship in one replay sample of each replay sample pair, and obtain multiple keywords other than the head and tail entities from the other replay sample of each replay sample pair; Based on the prompt template, convert the head and tail entities, the entity relationship, and the multiple keywords of each replay sample pair into prompt information, and input the prompt information into the pre-trained data augmentation large language model to obtain the augmented sample of each replay sample pair.
7. The method for training a relationship extraction model according to claim 1, wherein The method further includes: Obtain a relation extraction training set, where the relation extraction training set includes text data of multiple entity relationship categories; Divide the relation extraction training set into training samples corresponding to multiple training tasks; the entity relationship categories of the text data in the training samples corresponding to each training task are different.
8. A relation extraction method, characterized in that, Including: Obtain the text data to be extracted; Input the text data to be extracted into the target relation extraction model to obtain the entities and entity relationships output by the target relation extraction model; Wherein, the target relation extraction model is obtained based on the relation extraction model training method described in any one of claims 1 to 7.
9. An electronic device, comprising a memory, a processor, and a computer program stored on the memory and running on the processor, characterized in that, When the processor executes the computer program, the relation extraction model training method described in any one of claims 1 to 7 or the relation extraction method described in claim 8 is implemented.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, the relation extraction model training method described in any one of claims 1 to 7 or the relation extraction method described in claim 8 is implemented.
