Entity relationship extraction method and device, equipment, storage medium and product
By using vector encoding and entity type mapping to construct a label embedding matrix, the problem of low accuracy of entity relationship extraction in the prior art is solved, and higher extraction accuracy and capture of entity types and relationship connections are achieved.
Patent Information
- Application Number
- CN202510006851.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-02
- Publication Date
- 2025-05-06
AI Technical Summary
The existing entity relationship extraction method has low accuracy and fails to effectively capture the connection between entity types and relationships.
By vector encoding of the target text, determine the entity position and type, map the entity type into a preset real vector, and build a label embedding matrix, and input it into the relationship extraction model to obtain the entity relationship extraction result.
Improve the accuracy of entity relationship extraction and can more effectively capture the connection between entity types and entity relationships.
Smart Images

Figure CN119940516A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of entity relationship extraction, and in particular to entity relationship extraction methods, devices, equipment, storage media and products. Background Art
[0002] In the tide of new infrastructure, artificial intelligence, big data and 5G applications are the beacons that people are chasing. When depicting the grand blueprint of the digital economy era, knowledge graphs and natural language processing have become popular. How to extract valuable information from massive text or web page raw data is a key factor in the construction of industry knowledge graphs. Knowledge graph is a structured knowledge representation method. Through the organic combination of entities and their relationships, a complex knowledge network is formed to provide support for applications such as information retrieval, question-answering systems and recommendation systems. In the process of building a knowledge graph, entity relationship extraction is one of the key steps. Its task is to identify entities from unstructured text and extract the relationships between entities. Traditional entity relationship extraction methods only focus on the intrinsic connection between entities and relationships, fail to capture the connection between entity types and relationships, and do not consider the difficulty of predicting entities and relationships, resulting in a decrease in the accuracy of entity relationship extraction. Summary of the invention
[0003] The main purpose of this application is to provide an entity relationship extraction method, device, equipment, storage medium and product, aiming to solve the technical problem of low accuracy of existing entity relationship extraction.
[0004] To achieve the above objectives, the present application proposes an entity relationship extraction method, which includes:
[0005] Performing vector encoding on the target text, and determining the entity position and entity type corresponding to the entity in the target text based on the generated encoding vector;
[0006] Mapping the entity type to a preset real number vector;
[0007] Constructing a label embedding matrix based on the encoding vector, the preset real number vector and the entity position;
[0008] The label embedding matrix and the encoding vector are input into a relation extraction model to obtain an entity relation extraction result output by the relation extraction model.
[0009] Optionally, the step of constructing a label embedding matrix based on the encoding vector, the preset real number vector and the entity position includes:
[0010] Constructing an initial label embedding matrix based on the encoding vector;
[0011] The preset real number vector is filled into the corresponding position of the initial label embedding matrix according to the entity position to obtain a label embedding matrix.
[0012] Optionally, the step of filling the preset real number vector into the corresponding position of the initial label embedding matrix according to the entity position to obtain the label embedding matrix includes:
[0013] Determining the starting and ending positions of the entity according to the position of the entity;
[0014] Determining an entity type embedding position in the initial label embedding matrix according to the start and end positions of the entity;
[0015] Determine a non-entity type vector filling position based on the entity type embedding position and the initial label embedding matrix;
[0016] The preset real number vector is filled into the entity type embedding position, and the preset non-entity type vector is filled into the non-entity type vector filling position to obtain a label embedding matrix.
[0017] Optionally, the step of performing vector encoding on the target text and determining the entity position and entity type corresponding to the entity in the target text based on the generated encoding vector includes:
[0018] Perform vector encoding on the target text to obtain an encoding vector;
[0019] Identify entities in the encoding vector to obtain entity recognition results;
[0020] Determine a category score for each entity based on the entity recognition result;
[0021] The entity position and entity type corresponding to the entity in the target text are determined according to the category score and the entity recognition result.
[0022] Optionally, the step of inputting the label embedding matrix and the encoding vector into a relation extraction model to obtain an entity relation extraction result output by the relation extraction model comprises:
[0023] Concatenating the label embedding matrix and the encoding vector to obtain a concatenated result;
[0024] The concatenation result is input into the relation extraction model to obtain the entity relation extraction result output by the relation extraction model.
[0025] Optionally, the step of determining the entity position and entity type corresponding to the entity in the target text based on the generated encoding vector includes:
[0026] Inputting the encoding vector into a preset entity recognition model to obtain the entity position and entity type corresponding to the entity in the target text;
[0027] Before the step of inputting the encoding vector into a preset entity recognition model to obtain the entity position and entity type corresponding to the entity in the target text, the method further includes:
[0028] Obtaining an entity recognition loss value of a preset entity recognition model during training and a relationship extraction loss value of the relationship extraction model during training;
[0029] Determine a target relationship extraction loss value and a target entity recognition loss value based on the relationship extraction loss value, the entity recognition loss value, and the number of entity samples and the number of relationship samples in the sample data;
[0030] The relationship extraction model is trained according to the target relationship extraction loss value, and the preset entity recognition model is trained according to the target entity recognition loss value.
[0031] In addition, to achieve the above purpose, the present application also proposes an entity relationship extraction device, the entity relationship extraction device comprising:
[0032] A vector encoding module, used to perform vector encoding on the target text, and determine the entity position and entity type corresponding to the entity in the target text based on the generated encoding vector;
[0033] A mapping module, used for mapping the entity type into a preset real number vector;
[0034] A label embedding matrix construction module, used to construct a label embedding matrix based on the encoding vector, the preset real number vector and the entity position;
[0035] The relationship extraction module is used to input the label embedding matrix and the encoding vector into the relationship extraction model to obtain the entity relationship extraction result output by the relationship extraction model.
[0036] In addition, to achieve the above-mentioned purpose, the present application also proposes an entity relationship extraction device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the entity relationship extraction method described above.
[0037] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by the processor, the steps of the entity relationship extraction method described above are implemented.
[0038] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the entity relationship extraction method described above are implemented.
[0039] The present application performs vector encoding on the target text, determines the entity position and entity type corresponding to the entity in the target text based on the generated encoding vector; maps the entity type to a preset real number vector; constructs a label embedding matrix based on the encoding vector, the preset real number vector and the entity position; inputs the label embedding matrix and the encoding vector into a relationship extraction model to obtain the entity relationship extraction result output by the relationship extraction model. Since the present application maps the entity type to a preset real number vector and constructs a label embedding matrix for entity relationship extraction during entity relationship extraction, compared to the existing method of relationship extraction that only focuses on the intrinsic connection between entities and relationships, the above method of the present application can capture the connection between entity types and entity relationships, and improve the accuracy of entity relationship extraction. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0041] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0042] Figure 1 A flowchart of the first embodiment of the entity relationship extraction method of the present application is provided;
[0043] Figure 2 A flowchart of the second embodiment of the entity relationship extraction method of the present application is provided;
[0044] Figure 3 A schematic diagram of the overall architecture provided for the second embodiment of the entity relationship extraction method of the present application;
[0045] Figure 4 A flowchart of the third embodiment of the entity relationship extraction method of the present application is provided;
[0046] Figure 5 This is a schematic diagram of the module structure of the entity relationship extraction device according to an embodiment of the present application;
[0047] Figure 6 This is a schematic diagram of the device structure of the hardware operating environment involved in the entity relationship extraction method in the embodiment of the present application.
[0048] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0049] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0050] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0051] The main solution of the embodiment of the present application is: vector encoding the target text, determining the entity position and entity type corresponding to the entity in the target text based on the generated encoding vector; mapping the entity type to a preset real number vector; constructing a label embedding matrix based on the encoding vector, the preset real number vector and the entity position; inputting the label embedding matrix and the encoding vector into the relationship extraction model to obtain the entity relationship extraction result output by the relationship extraction model. Since the present application maps the entity type to a preset real number vector during entity relationship extraction, and constructs a label embedding matrix for entity relationship extraction, compared to the existing method of relationship extraction that only focuses on the intrinsic connection between entities and relationships, the above method of the present application can capture the connection between entity types and entity relationships, and improve the accuracy of entity relationship extraction.
[0052] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, a relationship extraction device, etc. The following takes the relationship extraction device as an example to illustrate this embodiment and the following embodiments.
[0053] Based on this, the present application embodiment provides an entity relationship extraction method, referring to Figure 1 , Figure 1 A flowchart of the first embodiment of the entity relationship extraction method of the present application is provided.
[0054] In this embodiment, the entity relationship extraction method includes the following steps:
[0055] Step S10, performing vector encoding on the target text, and determining the entity position and entity type corresponding to the entity in the target text based on the generated encoding vector;
[0056] It should be noted that the target text may be a text input by a user and requires entity relationship extraction. The vector encoding of the target text may be performed by an encoder (e.g., a bidirectional encoder (BidirectionalEncoder Representations from Transformers, BERT)) to vector encode the target text to obtain an encoding vector. The determination of the entity position and entity type corresponding to the entity in the target text based on the generated encoding vector may be performed by processing the encoding vector using an entity recognition model, identifying the entity in the target text, and determining the starting position and ending position (i.e., entity position) of each entity, and generating the entity type of the entity at the same time. The entity type may include: physical entity, legal entity, virtual entity, conceptual entity, commercial entity, cultural entity, and other types.
[0057] Furthermore, in order to accurately determine the category of the entity, the step S10 may include: performing vector encoding on the target text to obtain an encoding vector;
[0058] Identify entities in the encoding vector to obtain entity recognition results;
[0059] Determine a category score for each entity based on the entity recognition result;
[0060] The entity position and entity type corresponding to the entity in the target text are determined according to the category score and the entity recognition result.
[0061] It should be noted that the vector encoding of the target text to obtain the encoding vector can be performed by an encoder, such as a BERT encoder, to generate a high-dimensional encoding vector sequence containing each word in the target text (hereinafter referred to as token). These encoding vectors retain the semantic information of the target text and lay the foundation for subsequent entity recognition and type determination. Among them, token is used to represent each word in the target text. The identification of entities in the encoding vector to obtain entity recognition results can be performed by an entity decoder to identify the entities in the encoding vector and extract the positions of the identified entities to obtain entity recognition results. At the same time, the entity decoder also determines the possibility that the entity belongs to each entity category, that is, the entity category score. The category with the highest score is the type of the entity.
[0062] In the specific implementation, the target text is first processed by the BERT encoder to generate a high-dimensional encoding vector sequence for each token. These encoding vectors retain the semantic information of the text, laying the foundation for subsequent entity recognition and type determination. The encoded vector sequence is then input into the entity decoder, which uses a multi-head annotation decoding method to construct a feature representation for each pair of tokens for entity recognition and entity type annotation. The decoder uses multiple independent annotation heads, each of which corresponds to a specific entity type, including N predefined entity types and a non-entity type 'O', and each type has an independent multi-head annotation matrix. In this way, each token pair can process the classification of multiple entity types in parallel when decoding. For each token pair, the entity decoder outputs the score of the token on each entity category based on the N+1 multi-head annotation matrices, which reflects the possibility that the token belongs to each entity category. By post-processing the classification results of all tokens, the starting and ending positions of each entity are determined. Finally, the decoder outputs N+1 probability distributions for each token pair, and selects the entity category with the highest probability as the final classification result. This output process ensures that the entity recognition model can not only effectively identify entities but also accurately classify their types.
[0063] Step S20, mapping the entity type to a preset real number vector;
[0064] It should be noted that the mapping of the entity type to a preset real number vector can be to predefine several entity types, such as names of people, places, names of organizations, etc. For each predefined entity type, a corresponding real-valued vector (embedding vector) will be pre-generated, that is, a preset real number vector. Each embedding vector is a high-dimensional vector that aims to represent the semantic features of the entity type. Each entity type is assigned a unique label for mapping the corresponding entity type embedding vector, and there is an additional label for representing non-entity categories, which can be represented by "O".
[0065] Step S30, constructing a label embedding matrix based on the encoding vector, the preset real number vector and the entity position;
[0066] It should be noted that the construction of the label embedding matrix based on the encoding vector, the preset real number vector and the entity position can be to construct a label embedding matrix of an entity type based on the encoding vector, the number of rows of the matrix is the same as the number of rows of the encoding vector, and then according to the starting position and the ending position of the entity in the entity position, the positions in the label embedding matrix corresponding to the starting position and the ending position are mapped to the preset real number vector, and the remaining positions are mapped to the non-entity category vector to obtain the label embedding matrix.
[0067] Step S40, inputting the label embedding matrix and the encoding vector into a relation extraction model to obtain an entity relation extraction result output by the relation extraction model.
[0068] It should be noted that the step of inputting the label embedding matrix and the encoding vector into the relation extraction model to obtain the entity relationship extraction result output by the relation extraction model may be inputting the label embedding matrix and the encoding vector into the relation extraction model at the same time to perform relation extraction to obtain the entity relationship extraction result output by the relation extraction model.
[0069] Further, in order to improve the accuracy of entity relationship extraction, the step S40 may include: concatenating the label embedding matrix and the encoding vector to obtain a concatenated result;
[0070] The concatenation result is input into the relation extraction model to obtain the entity relation extraction result output by the relation extraction model.
[0071] It should be noted that the concatenation of the label embedding matrix and the encoding vector to obtain the concatenation result may be concatenating the label embedding matrix and the encoding vector through the following algorithm:
[0072] C = Concat(E, T)∈R L*d+d '
[0073] Among them, C is used to represent the splicing result, that is, the spliced matrix, and E is used to represent the encoding vector E∈R L*d , L is the length of the text, d is the dimension of the encoding vector, and T is used to represent the label embedding matrix T∈R L*d ', d' is the dimension of the preset real number vector. In the concatenated matrix C, each row contains the semantic information of a token (provided by the encoding vector) and the entity type information of the token (provided by the entity type embedding).
[0074] This embodiment performs vector encoding on the target text, determines the entity position and entity type corresponding to the entity in the target text based on the generated encoding vector; maps the entity type to a preset real number vector; constructs a label embedding matrix based on the encoding vector, the preset real number vector and the entity position; inputs the label embedding matrix and the encoding vector into the relationship extraction model to obtain the entity relationship extraction result output by the relationship extraction model. Since this embodiment maps the entity type to a preset real number vector and constructs a label embedding matrix for entity relationship extraction during entity relationship extraction, compared to the existing method of relationship extraction that only focuses on the internal connection between entities and relationships, the above method of this embodiment can capture the connection between entity types and entity relationships, and improve the accuracy of entity relationship extraction.
[0075] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction, and will not be repeated in the following. Figure 2 , Figure 2 The flowchart of the second embodiment of the entity relationship extraction method of the present application is provided, wherein the step S30 further includes the following steps:
[0076] Step S301: constructing an initial label embedding matrix based on the encoding vector;
[0077] It should be noted that constructing the initial label embedding matrix based on the encoding vector may be constructing an initial label embedding matrix having the same number of rows as the number of rows of the encoding vector.
[0078] Step S302: filling the preset real number vector into the corresponding position of the initial label embedding matrix according to the entity position to obtain a label embedding matrix.
[0079] It should be noted that, by filling the preset real number vector into the corresponding position of the initial label embedding matrix according to the entity position, the label embedding matrix can be obtained by determining the starting and ending positions of each entity according to the entity position, filling the preset real number vector corresponding to the type of the entity at the starting and ending positions in the initial label embedding matrix, and filling the pre-set non-entity category vector at other positions of the initial label embedding matrix.
[0080] Further, in order to make the relationship extraction model perform relationship extraction based on the type of entity and improve the relationship extraction efficiency, the step S302 may include: determining the starting and ending positions of the entity according to the entity position;
[0081] Determining an entity type embedding position in the initial label embedding matrix according to the start and end positions of the entity;
[0082] Determine a non-entity type vector filling position based on the entity type embedding position and the initial label embedding matrix;
[0083] The preset real number vector is filled into the entity type embedding position, and the preset non-entity type vector is filled into the non-entity type vector filling position to obtain a label embedding matrix.
[0084] It should be noted that the starting and ending positions of the entity may be the positions of the entity in the encoding vector. Determining the entity type embedding position in the initial label embedding matrix based on the starting and ending positions of the entity may be to make a one-to-one correspondence between the initial label embedding matrix and the positions of the encoding vector, and the entity type embedding position in the initial label embedding matrix is the starting and ending position of the entity in the encoding vector. Determining the non-entity type vector filling position based on the entity type embedding position and the initial label embedding matrix may be that all positions in the initial label embedding matrix except the entity type embedding position are non-entity type vector filling positions.
[0085] In the specific implementation, please refer to Figure 3 , Figure 3 The overall architecture diagram provided for the second embodiment of the entity relationship extraction method of the present application is as follows: the target text is first encoded by BERT to obtain a BERT output vector, i.e., the encoding vector; an initial label embedding matrix is constructed based on the encoding vector; and then the initial label embedding matrix is filled based on the preset real number vector corresponding to the position of the entity in the encoding vector and the entity type to obtain a label embedding matrix, i.e. Figure 3The entity type vector in the text is concatenated with the encoding vector, and the concatenated vector is input into the value relationship prediction model for entity relationship extraction. Construct the label, embedding matrix of the entity type, that is, the label embedding matrix. The specific steps are as follows: First, according to the requirements of the entity extraction task, predefine several entity types (for example, names of people, places, names of institutions, etc.). Each entity type is assigned a unique label for subsequent mapping of entity type embedding vectors. In addition, there is a label for non-entity categories, namely "O". Generate entity type embedding: For each predefined entity type, a corresponding embedding vector is generated. Each embedding is a high-dimensional vector designed to represent the semantic features of the entity type. Construct the label embedding matrix: After identifying the entities and their types in the text, these entity types are mapped to the corresponding embedding vectors. Specifically: For the start and end positions of each entity, its label will be mapped to the corresponding entity type embedding vector. For non-entity areas, its label is mapped to the embedding vector of "O". Matrix generation and filling: By filling the corresponding entity type embedding at each token position in the text, a label embedding matrix with the same length as the original text is generated. Each position in the matrix corresponds to the vector representation of the entity type information of the token, which is used to combine with the semantic vector of the original text.
[0086] This embodiment constructs an initial label embedding matrix based on the encoding vector; fills the preset real number vector into the corresponding position of the initial label embedding matrix according to the entity position to obtain a label embedding matrix. This embodiment fills the preset real number vector into the corresponding position of the initial label embedding matrix according to the entity position, and when performing subsequent entity relationship extraction, the influence of entity type on entity relationship can be fully considered, thereby improving the accuracy of entity relationship extraction.
[0087] Based on the above embodiments of the present application, in the third embodiment of the present application, the same or similar contents as those in the above embodiments can be referred to the above introduction, and will not be described in detail later. Figure 4 , Figure 4 The flowchart of the third embodiment of the entity relationship extraction method of the present application is provided. Before step S10, the following steps are also included:
[0088] Step S001: obtaining an entity recognition loss value of a preset entity recognition model during training and a relationship extraction loss value of the relationship extraction model during training;
[0089] It should be noted that the preset entity recognition model may be the model used for entity recognition in step S10 of the above embodiment. The entity recognition loss value may be the Loss value of the preset entity recognition model in the previous training round. The relationship extraction loss value may be the Loss value of the relationship extraction model in the previous training round.
[0090] Step S002: determining a target relationship extraction loss value and a target entity recognition loss value based on the relationship extraction loss value, the entity recognition loss value, and the number of entity samples and the number of relationship samples in the sample data;
[0091] It should be noted that the target relation extraction loss value may be entity recognition loss value / relation extraction loss value*number of relation samples. The target entity recognition loss value may be relation extraction loss value / entity recognition loss value*number of entity samples.
[0092] Step S003: training the relationship extraction model according to the target relationship extraction loss value, and training the preset entity recognition model according to the target entity recognition loss value.
[0093] It should be noted that the training of the relationship extraction model according to the target relationship extraction loss value may be iterative training of the relationship extraction model until the loss value of the trained relationship extraction model is less than the target relationship extraction loss value. Similarly, the training steps of the preset entity recognition model are the same.
[0094] In the specific implementation, the initial Loss weight is first determined by analyzing the complexity of the entity recognition and relationship extraction tasks. Generally speaking, relationship extraction is more complex than entity recognition, so the weight of each Loss can be dynamically calculated based on the following method: In the entity relationship extraction task, the distribution ratio of entities and relationships may be significantly different for different fields (such as medicine, office, and law). Therefore, it is necessary to dynamically adjust the Loss weights of entities and relationships through the analysis of domain data, so as to improve the adaptability and prediction accuracy of the model to specific fields. For example, in the medical field, authoritative public data sets in the field can be used to obtain entity types such as "disease", "drug", "symptom", and relationships such as "drug treatment of disease"; in the office field, data sets such as company internal management methods and official documents can be used, involving entity types such as "employee", "department", "task", and relationships such as "employee completes task". Data cleaning is performed on the acquired data, which includes removing noise and irrelevant information. Then the entities and relationships in the text are manually or automatically annotated. The number of entity and relationship samples is counted. Specifically: For each field of data set, the number of entity samples and relationship samples is counted: The number of entities can be expressed as N entity, which is the total number of occurrences of each entity type. The number of relationships can be expressed as N relation , which is the total number of occurrences of each relationship type. Ratio of entities to relationships ER : R ER =N entity / N relation Please refer to Table 1 - Entity and relationship statistics example:
[0095] Table 1 - Example of entity and relationship statistics
[0096] field Number of entities Number of relationships Proportion medicine 10,000 2,000 5 Office 5,000 800 62.5
[0097] According to Table 1, in the medical field: the ratio of the number of entities (such as "symptoms") to the number of relations (such as "drugs to treat diseases") is 5, and the difference between the two ratios is not large. In the office field: the ratio of the number of entities (such as "employees") to the number of relations (such as "employees complete tasks") is 62.5. The number of entities is much larger than the number of relations, and the difference between the two ratios is large. By analyzing the distribution of entities and relations in different fields, it is found that in the medical and office fields, the number of relationship samples is far less than that of entity samples, especially in the office field. This sparsity requires the model to pay more attention to the relationship extraction task. Therefore, the Loss weight can be dynamically adjusted by calculating the sample ratio of entities and relations. The specific formula is as follows:
[0098]
[0099] Among them, N entity and N relation are the number of samples of entities and relations respectively. Since relation samples are scarce, we can increase the weight of relation Loss (WeightSample relation ), which can guide the model to focus more on the relationship extraction task and improve its performance in this aspect.
[0100] In order to enable the model to adapt to the importance of different tasks during training, this embodiment adopts a dynamic adjustment mechanism to gradually adjust the weights based on the changes in the losses of entity and relationship tasks in each epoch (training round). This dynamic adjustment mechanism adjusts the weights based on the current entity loss and relationship loss at the end of each epoch, using the following update formula:
[0101]
[0102] Among them, t represents the current epoch, They represent the Loss values of the entity and relationship tasks at the tth epoch respectively. When the Loss of a task is large, it means that the task is difficult to complete, and the model will automatically increase the weight of the task.
[0103] In each back propagation, the total Loss is calculated using the dynamically updated weights:
[0104]
[0105] Among them, the total loss can be the loss value of the large model constructed by the relationship extraction model and the preset entity recognition model. In this embodiment, through this dynamic weight method, the large model including the relationship extraction model and the preset entity recognition model can automatically adjust the attention of each task according to the difficulty of different tasks, ensuring that the relationship extraction results are more accurate. Based on the TPLinker model, this embodiment has made two major improvements: one is to improve the relationship extraction task by splicing the entity type vector and the original encoding vector; the other is to perform weighted calculation on the loss of entities and relationships to enhance the focus on the relationship extraction task. For details, please refer to the following Table 2-Entity Relationship Extraction Experiment Comparison Table:
[0106] Table 2-Comparison table of entity relationship extraction experiments
[0107]
[0108]
[0109] In the experiment, the model performance was evaluated through five different configurations. The following conclusions can be drawn from the above experimental comparison: the addition of entity type information has a significant effect on improving the performance of relationship extraction. Whether it is 64-dimensional or 128-dimensional label embedding (i.e., label embedding matrix), the Precision and F1 scores of the model can be improved; adjusting the loss ratio between entities and relationships is particularly critical to improving the relationship prediction ability of the model. Precision is significantly improved by adjusting the unbalanced sample weights of entity and relationship losses and dynamic weight adjustment; the best configuration is to combine 128-dimensional label embedding and entity relationship loss weighted calculation. Under this configuration, the Precision and F1 scores of the model are both optimal, showing higher accuracy and stability. This shows that the improvements in this embodiment can significantly improve the performance of the TPLinker model in entity relationship extraction tasks and provide stronger technical support for applications in related fields.
[0110] This embodiment obtains the entity recognition loss value of the preset entity recognition model during training and the relationship extraction loss value of the relationship extraction model during training; determines the target relationship extraction loss value and the target entity recognition loss value based on the relationship extraction loss value, the entity recognition loss value and the number of entity samples and the number of relationship samples in the sample data; trains the relationship extraction model according to the target relationship extraction loss value, and trains the preset entity recognition model according to the target entity recognition loss value. This embodiment can optimize model performance and improve the prediction accuracy of the model by calculating and adjusting the loss value through the number of entity samples and the number of relationship samples in the sample data.
[0111] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the entity relationship extraction method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.
[0112] This application also provides an entity relationship extraction device, please refer to Figure 5 , the entity relationship extraction device comprises:
[0113] A vector encoding module 10, configured to perform vector encoding on a target text, and determine an entity position and an entity type corresponding to an entity in the target text based on a generated encoding vector;
[0114] A mapping module 20, used for mapping the entity type into a preset real number vector;
[0115] A label embedding matrix construction module 30, used to construct a label embedding matrix based on the encoding vector, the preset real number vector and the entity position;
[0116] The relationship extraction module 40 is used to input the label embedding matrix and the encoding vector into the relationship extraction model to obtain the entity relationship extraction result output by the relationship extraction model.
[0117] This embodiment performs vector encoding on the target text, determines the entity position and entity type corresponding to the entity in the target text based on the generated encoding vector; maps the entity type to a preset real number vector; constructs a label embedding matrix based on the encoding vector, the preset real number vector and the entity position; inputs the label embedding matrix and the encoding vector into the relationship extraction model to obtain the entity relationship extraction result output by the relationship extraction model. Since this embodiment maps the entity type to a preset real number vector and constructs a label embedding matrix for entity relationship extraction during entity relationship extraction, compared to the existing method of relationship extraction that only focuses on the internal connection between entities and relationships, the above method of this embodiment can capture the connection between entity types and entity relationships, and improve the accuracy of entity relationship extraction.
[0118] The entity relationship extraction device provided by the present application adopts the entity relationship extraction method in the above embodiment, which can solve the technical problem of low accuracy of existing entity relationship extraction. Compared with the prior art, the beneficial effects of the entity relationship extraction device provided by the present application are the same as the beneficial effects of the entity relationship extraction method provided by the above embodiment, and other technical features in the entity relationship extraction device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0119] The present application provides an entity relationship extraction device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the entity relationship extraction method in the above-mentioned embodiment one.
[0120] Reference below Figure 6 , which shows a schematic diagram of the structure of an entity relationship extraction device suitable for implementing the embodiment of the present application. The entity relationship extraction device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 6 The entity relationship extraction device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0121] like Figure 6As shown, the entity relationship extraction device may include a processing device 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Me mory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. Various programs and data required for the operation of the entity relationship extraction device are also stored in RAM1004. The processing device 1001, ROM1002, and RAM1004 are connected to each other via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to the I / O interface 1006: input devices 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 1003 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 1009. The communication device 1009 can allow the entity relationship extraction device to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows an entity relationship extraction device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems may be implemented or have instead.
[0122] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0123] The entity relationship extraction device provided by the present application adopts the entity relationship extraction method in the above embodiment, which can solve the technical problem of low accuracy of existing entity relationship extraction. Compared with the prior art, the beneficial effects of the entity relationship extraction device provided by the present application are the same as the beneficial effects of the entity relationship extraction method provided by the above embodiment, and the other technical features in the entity relationship extraction device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0124] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0125] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0126] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the entity relationship extraction method in the above-mentioned embodiment.
[0127] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0128] The above-mentioned computer-readable storage medium may be included in the entity relationship extraction device; or it may exist independently without being assembled into the entity relationship extraction device.
[0129] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0130] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0131] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0132] The readable storage medium provided by the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned entity relationship extraction method, and can solve the technical problem of low accuracy of existing entity relationship extraction. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as the beneficial effects of the entity relationship extraction method provided by the above-mentioned embodiment, and will not be repeated here.
[0133] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned entity relationship extraction method when executed by a processor.
[0134] The computer program product provided by this application can solve the technical problem of low accuracy of existing entity relationship extraction. Compared with the prior art, the beneficial effects of the computer program product provided by this application are the same as those of the entity relationship extraction method provided by the above embodiment, which will not be repeated here.
[0135] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A method for extracting entity relations, characterized in that: The entity relationship extraction method comprises the following steps: Performing vector encoding on the target text, and determining the entity position and entity type corresponding to the entity in the target text based on the generated encoding vector; Mapping the entity type to a preset real number vector; Constructing a label embedding matrix based on the encoding vector, the preset real number vector and the entity position; The label embedding matrix and the encoding vector are input into a relation extraction model to obtain an entity relation extraction result output by the relation extraction model.
2. The entity relationship extraction method according to claim 1, characterized in that: The step of constructing a label embedding matrix based on the encoding vector, the preset real number vector and the entity position comprises: Constructing an initial label embedding matrix based on the encoding vector; The preset real number vector is filled into the corresponding position of the initial label embedding matrix according to the entity position to obtain a label embedding matrix.
3. The entity relationship extraction method according to claim 2, characterized in that: The step of filling the preset real number vector into the corresponding position of the initial label embedding matrix according to the entity position to obtain the label embedding matrix includes: Determining the starting and ending positions of the entity according to the position of the entity; Determining an entity type embedding position in the initial label embedding matrix according to the start and end positions of the entity; Determine a non-entity type vector filling position based on the entity type embedding position and the initial label embedding matrix; The preset real number vector is filled into the entity type embedding position, and the preset non-entity type vector is filled into the non-entity type vector filling position to obtain a label embedding matrix.
4. The entity relationship extraction method according to claim 1, characterized in that: The step of performing vector encoding on the target text and determining the entity position and entity type corresponding to the entity in the target text based on the generated encoding vector includes: Perform vector encoding on the target text to obtain an encoding vector; Identify entities in the encoding vector to obtain entity recognition results; Determine a category score for each entity based on the entity recognition result; The entity position and entity type corresponding to the entity in the target text are determined according to the category score and the entity recognition result.
5. The entity relationship extraction method according to any one of claims 1 to 4, characterized in that: The step of inputting the label embedding matrix and the encoding vector into a relation extraction model to obtain an entity relation extraction result output by the relation extraction model comprises: Concatenating the label embedding matrix and the encoding vector to obtain a concatenated result; The concatenation result is input into the relation extraction model to obtain the entity relation extraction result output by the relation extraction model.
6. The entity relationship extraction method according to claim 5, characterized in that: The step of determining the entity position and entity type corresponding to the entity in the target text based on the generated encoding vector comprises: Inputting the encoding vector into a preset entity recognition model to obtain the entity position and entity type corresponding to the entity in the target text; Before the step of inputting the encoding vector into a preset entity recognition model to obtain the entity position and entity type corresponding to the entity in the target text, the method further includes: Obtaining an entity recognition loss value of a preset entity recognition model during training and a relationship extraction loss value of the relationship extraction model during training; Determine a target relationship extraction loss value and a target entity recognition loss value based on the relationship extraction loss value, the entity recognition loss value, and the number of entity samples and the number of relationship samples in the sample data; The relationship extraction model is trained according to the target relationship extraction loss value, and the preset entity recognition model is trained according to the target entity recognition loss value.
7. An entity relationship extraction device, characterized in that: The entity relationship extraction device comprises: A vector encoding module, used to perform vector encoding on the target text, and determine the entity position and entity type corresponding to the entity in the target text based on the generated encoding vector; A mapping module, used for mapping the entity type into a preset real number vector; A label embedding matrix construction module, used to construct a label embedding matrix based on the encoding vector, the preset real number vector and the entity position; The relationship extraction module is used to input the label embedding matrix and the encoding vector into the relationship extraction model to obtain the entity relationship extraction result output by the relationship extraction model.
8. An entity relationship extraction device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the entity relationship extraction method according to any one of claims 1 to 6.
9. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the entity relationship extraction method according to any one of claims 1 to 6 are implemented.
10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the entity relationship extraction method according to any one of claims 1 to 6 are implemented.