Entity relationship extraction method, device, electronic device and storage medium
By semantic coding and label prediction of relational instance text and relationship prediction combined with preset relationship sets, the problem of low accuracy of entity relationship extraction is solved, and higher accuracy of extraction and information sharing effect is achieved.
Patent Information
- Application Number
- CN202111552323.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-17
- Publication Date
- 2025-02-14
- Estimated Expiration
- 2041-12-17
AI Technical Summary
In the prior art, the accuracy of entity relationship extraction is not high, especially when dealing with multiple relationships and overlapping relationships, insufficient error transmission and information sharing lead to poor results.
By obtaining the relationship instance text, semantic encoding is used to perform semantic coding models, and a semantic vector sequence is obtained. Then, label prediction and entity annotation are performed on the semantic vector sequence to obtain the standard label sequence and entity annotation results. Based on the preset relationship set, relationship prediction is performed on the semantic vector sequence to obtain the relationship prediction result. Finally, the entity annotation results and the relationship prediction results are spliced and combined, and the standard entity relationship pair is selected through the probability identification of the head entity and the tail entity.
The accuracy of entity annotation is improved. By limiting the size of the relationship set, excessive duplication of the relationship is avoided and the accuracy of entity relationship extraction is improved. At the same time, by sharing information about entity recognition and relationship classification, it is more accurate to deal with relationship overlap.
Smart Images

Figure CN114510939B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to an entity relationship extraction method, device, electronic device and computer-readable storage medium. Background Art
[0002] The structure of the joint extraction model of entities and their relations is generally divided into two types, one is pipeline type (pipeline), and the other is end-to-end structure. The former generally extracts entities first, determines the categories of entities at the same time, and then classifies the relations of each pair of candidate entities to obtain the result of relation extraction triples. An obvious disadvantage of the pipeline type is the problem of error propagation, because the two tasks of entity recognition and relation extraction are completed independently, resulting in the inability to fully share the two parts of information, and the accuracy of entity relation extraction is low. The end-to-end model is generally designed to use the result of entity recognition as the hidden layer result of the model, and add the loss of entity recognition and the loss of relation classification as the loss function of the entire model. The end-to-end model can effectively reduce the error propagation problem between the entity recognition (NER) and relation extraction (RE) models of the pipeline model and make full use of the useful information between the two tasks of NER and RE to improve the final extraction effect. However, in actual applications, there are often multiple relations in a sentence instance, and multiple relations may overlap, that is, the same entity may appear in different relation categories, which will also make the accuracy of entity relation extraction low. Summary of the invention
[0003] The present application provides an entity relationship extraction method, device, electronic device and storage medium to solve the problem of low accuracy in entity relationship extraction.
[0004] In a first aspect, the present application provides a method for extracting entity relationships, the method comprising:
[0005] Acquire relation instance text, and use a pre-trained encoding model to semantically encode the relation instance text to obtain a semantic vector sequence;
[0006] Performing label prediction on the semantic vector sequence, obtaining a standard label sequence according to the prediction result, and performing entity labeling on the standard label sequence to obtain an entity labeling result;
[0007] Acquire a preset relationship set, and perform relationship prediction on the semantic vector sequence based on the relationship set to obtain a relationship prediction result;
[0008] The entity labeling results and the relationship prediction results are spliced and combined to obtain an entity relationship pair set, the head entity and the tail entity probability recognition is performed on the entity relationship pair set, and a standard entity relationship pair is selected from the entity relationship pair set according to the recognition result.
[0009] In detail, the semantic encoding of the relation instance text using the pre-trained encoding model to obtain a semantic vector sequence includes:
[0010] Segmenting the relation instance text to obtain an original segmentation sequence, and adding interval markers to the original segmentation sequence to obtain a standard segmentation sequence;
[0011] Generate a combined vector of each word in the standard word segmentation sequence using the embedding vector representation layer in the encoding model;
[0012] The encoder layer in the encoding model is used to encode the semantic features of the combined vector of each word segment to obtain the semantic feature vectors of all word segments, and the pooling layer in the encoding model is used to arrange the semantic feature vectors and the interval markers into vectors to obtain the semantic vector sequence.
[0013] In detail, the step of generating a combined vector of each word in the standard word segmentation sequence by using the embedded vector representation layer in the encoding model includes:
[0014] Using the embedding vector representation layer, each word in the standard word segmentation sequence is converted into a token vector, a position vector and a sequence marker vector;
[0015] The token vector, the position vector and the sequence tag vector of each word segment are combined using the following formula to obtain the combined vector embedding of each word segment:
[0016] embedding=embedding tokens +embedding position +embedding seg type
[0017] Among them, embedding tokens is the token vector, embedding position is the position vector, embedding seg type is the sequence label vector.
[0018] In detail, performing label prediction on the semantic vector sequence and obtaining a standard label sequence according to the prediction result includes:
[0019] Performing label prediction on the semantic feature vector corresponding to each word segment in the semantic vector sequence to obtain multiple label sequences, wherein each label sequence includes a predicted label of each word segment and a predicted score corresponding to the predicted label;
[0020] Using the prediction scores, screening and sorting the predicted labels in the multiple label sequences to obtain an original label sequence set;
[0021] A preset objective function is used to select a target sequence from the original label sequence set as the standard label sequence.
[0022] In detail, the selecting a target sequence from the original label sequence set as the standard label sequence by using a preset objective function includes:
[0023] Probabilistically optimizing the original label set using the objective function, and selecting a target sequence that maximizes the objective function as the standard label sequence;
[0024] The objective function is as follows:
[0025]
[0026] Among them, y X is the original label sequence set, s(h, y) represents the score of one sequence y in the original label sequence set, and p(y|h) represents the conditional probability of sequence y.
[0027] In detail, performing relationship prediction on the semantic vector sequence based on the relationship set to obtain a relationship prediction result includes:
[0028] Extracting the identification vector corresponding to the interval identification in the semantic vector sequence, and using a preset classification function to obtain the predicted relationship existing in the relationship set of the identification vector and the probability of the predicted relationship;
[0029] Based on the probability of the predicted relationship, the predicted relationship is classified using a preset label function to obtain the relationship prediction result.
[0030] In detail, the entity labeling result and the relationship prediction result are combined to obtain an entity relationship pair set, the head entity and the tail entity probability recognition is performed on the entity relationship pair set, and a standard entity relationship pair is selected from the entity relationship pair set according to the recognition result, including:
[0031] Converting the relations in the relation prediction results into embedded relations according to the relation set;
[0032] Randomly combining the embedded relationships and entities in the entity annotation results to obtain the entity relationship pair set;
[0033] The probabilities of the head entity and the tail entity in the entity relationship pair set are calculated using a preset entity probability formula, and an entity relationship pair that meets preset conditions is selected as the standard entity relationship pair according to the probabilities.
[0034] In a second aspect, the present application provides an entity relationship extraction device, the device comprising:
[0035] A semantic encoding module, used to obtain a relation instance text, and semantically encode the relation instance text using a pre-trained encoding model to obtain a semantic vector sequence;
[0036] An entity labeling module is used to perform label prediction on the semantic vector sequence, obtain a standard label sequence according to the prediction result, and perform entity labeling on the standard label sequence to obtain an entity labeling result;
[0037] A relationship prediction module, used to obtain a preset relationship set, perform relationship prediction on the semantic vector sequence based on the relationship set, and obtain a relationship prediction result;
[0038] The entity relationship pair extraction module is used to splice and combine the entity labeling results and the relationship prediction results to obtain an entity relationship pair set, perform head entity and tail entity probability recognition on the entity relationship pair set, and select standard entity relationship pairs from the entity relationship pair set according to the recognition results.
[0039] In a third aspect, an entity relationship extraction device is provided, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;
[0040] Memory, used to store computer programs;
[0041] The processor is used to implement the steps of the entity relationship extraction method described in any embodiment of the first aspect when executing the program stored in the memory.
[0042] In a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the entity relationship extraction method as described in any embodiment of the first aspect are implemented.
[0043] The above technical solution provided by the embodiment of the present application has the following advantages compared with the prior art:
[0044] The present invention can improve the accuracy of entity annotation by first predicting labels on the semantic vector sequence and then performing entity annotation. At the same time, the relationship prediction is performed through a preset relationship set. Since the preset relationship set limits the number of predictable relationships, the excessive duplication of relationships can be effectively avoided by limiting the size of the relationship set, thereby improving the accuracy of entity relationship extraction. In addition, the entity annotation results and the relationship prediction results are spliced and combined to obtain a set of all possible entity relationship pairs. Since the entity annotation results and the relationship prediction results are obtained from the same semantic vector, the information of the two parts of entity recognition and relationship classification can be shared. Finally, by probabilistically identifying the entity relationship pair set, for entities with overlapping relationships, the probabilities of the head entity and the tail entity are considered at the same time, further improving the accuracy of entity relationship extraction. Therefore, the entity relationship extraction method, device, electronic device and computer-readable storage medium proposed by the present invention can solve the problem of low accuracy of entity relationship extraction. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0046] In order to more clearly illustrate the embodiments of the present invention 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.
[0047] Figure 1 A flowchart of an entity relationship extraction method provided in an embodiment of the present application;
[0048] Figure 2 A schematic diagram of a module of an entity relationship extraction device provided in an embodiment of the present application;
[0049] Figure 3 A schematic diagram of the structure of an electronic device for implementing an entity relationship extraction method provided in an embodiment of the present application. DETAILED DESCRIPTION
[0050] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0051] Figure 1A flow chart of an entity relationship extraction method provided in an embodiment of the present application. In this embodiment, the entity relationship extraction method includes:
[0052] S1. Obtain relationship instance text, and use a pre-trained encoding model to semantically encode the relationship instance text to obtain a semantic vector sequence.
[0053] In the embodiment of the present invention, the relationship instance text may be text of the relationship to be extracted captured from a portal website or a professional website (including: finance, law, medical, education, entertainment, sports, etc.). For example, the relationship instance text extracted from Baidu Encyclopedia is: "Xiao Ding is one of the original actual controllers of First Electric and the ex-wife of Xiao Xia".
[0054] In an optional embodiment of the present invention, the pre-trained encoding model can be a pre-trained BERT-base-Chinese model, which is used to perform vector encoding on the input relational instance text to capture the semantics of the text. The BERT-base-Chinese model includes an embedding vector representation layer, an encoder layer and a pooling layer, wherein the embedding vector representation layer is used to encode text features into vectors, the encoder layer is used to perform non-linear representation on the results output by the embedding vector representation layer and extract feature vectors therefrom, and the pooling layer is used to arrange the extracted feature vectors to obtain a semantic vector sequence.
[0055] In detail, the semantic encoding of the relation instance text using the pre-trained encoding model to obtain a semantic vector sequence includes:
[0056] Segmenting the relation instance text to obtain an original segmentation sequence, and adding interval markers to the original segmentation sequence to obtain a standard segmentation sequence;
[0057] Generate a combined vector of each word in the standard word segmentation sequence using the embedding vector representation layer in the encoding model;
[0058] The encoder layer in the encoding model is used to encode the semantic features of the combined vector of each word segment to obtain the semantic feature vectors of all word segments, and the pooling layer in the encoding model is used to arrange the semantic feature vectors and the interval markers into vectors to obtain the semantic vector sequence.
[0059] In an optional embodiment of the present invention, the spacing mark includes [CLS] and [SEP], [CLS] is a classification mark, which is placed at the beginning of a sentence and used to indicate the entire sequence, and the [SEP] mark is used to separate sentence texts and is placed at the end of a sentence to indicate the end of a sentence. For example, the standard word segmentation sequence of "Xiao Ding is one of the original actual controllers of the First Electric, and Xiao Xia's ex-wife" is "[CLS] Xiao Ding / is / one of / the / original actual controllers / of / the First Electric / Xiao Xia / is / the / ex-wife[SEP]"
[0060] For example, given a relation instance text with n tokens (i.e., word segmentations), the standard word segmentation sequence is x = [c, x1, x2, ..., xn, s], c represents [CLS], s represents [SEP], xi represents each token (i.e., word segmentation) in x, 0≤i≤n, and the corresponding semantic vector sequence is h = [h0, h1, h2, ..., hn, hn+1], where h0 is the output corresponding to c, hn+1 is the output corresponding to s, hi corresponds to the output of xj (1≤j≤n), and n represents that the text contains n tokens, that is, [h1, h2, ..., hn] is the semantic vector corresponding to the relation instance text x = [x1, x2, ..., xn].
[0061] In detail, the step of generating a combined vector of each word in the standard word segmentation sequence by using the embedded vector representation layer in the encoding model includes:
[0062] Using the embedding vector representation layer, each word in the standard word segmentation sequence is converted into a token vector, a position vector and a sequence marker vector;
[0063] The token vector, the position vector and the sequence tag vector of each word segment are combined using the following formula to obtain the combined vector embedding of each word segment:
[0064] embedding=embedding tokens +embedding position +embedding seg_type
[0065] Among them, embedding tokens is the token vector, embedding position is the position vector, embedding seg type is the sequence label vector.
[0066] In the embodiment of the present invention, the pre-trained BERT-base-Chinese model is used to semantically encode the relational instance text, thereby improving the encoding efficiency. For example, the embedding vector representation layer is used to convert each word segment into a 768-dimensional word vector (sequence tag vector), a position vector and a token vector, and the three vectors of each word segment are added as an intermediate result and input into the LayerNormer layer and the Dropout layer for processing to obtain the combined vectors of all word segments; the encoder layer includes 12 encoders (hidden layers), and each encoder nonlinearly represents the combined vector output by the embedding vector representation layer through linear transformation, activation function, multi-head self-attention, skip connection, LayerNormer layer and Dropout layer to obtain the semantic feature vectors of all word segmentation texts; the pooling layer extracts the [CLS] tag and performs certain transformations as the representation of the entire sequence, and at the same time, all the semantic feature vectors are arranged intactly according to the order of the original word segmentation sequence to obtain the semantic vector sequence.
[0067] S2. Perform label prediction on the semantic vector sequence, obtain a standard label sequence according to the prediction result, and perform entity labeling on the standard label sequence to obtain an entity labeling result.
[0068] In an embodiment of the present invention, the label prediction refers to predicting the category of the semantic feature vector in the semantic vector sequence, including: people, places, time, etc. The Linear layer + CRF model can be used for label prediction. The Linear layer predicts the label of the semantic feature vector of each word segment in the semantic vector sequence based on the BIOS annotation method, and gives a prediction score for each predicted label. The predicted labels are then screened and sorted by the CRF model until the sorted sequence meets the preset objective function to obtain a standard label sequence. The BIOS annotation method labels words that may be mentioned by entities as B or I, and non-entities as O, to obtain multiple predicted label sequences. The CRF model can learn some constraints through the transfer matrix to screen and arrange the predicted labels corresponding to the predicted scores, and obtain the probability of occurrence of the predicted label sequence.
[0069] Specifically, performing label prediction on the semantic vector sequence and obtaining a standard label sequence according to the prediction result includes:
[0070] Performing label prediction on the semantic feature vector corresponding to each word segment in the semantic vector sequence to obtain multiple label sequences, wherein each label sequence includes a predicted label of each word segment and a predicted score corresponding to the predicted label;
[0071] Using the prediction scores, screening and sorting the predicted labels in the multiple label sequences to obtain an original label sequence set;
[0072] A preset objective function is used to select a target sequence from the original label sequence set as the standard label sequence.
[0073] Optionally, the CRF model can filter out predicted labels whose prediction scores are greater than a preset threshold, and sort the predicted labels according to some constraints learned from the transfer matrix (for example, label B- is always before label I-), to obtain a set of original label sequences.
[0074] In an optional embodiment of the present invention, for example, a text vector sequence [h1, h2, ..., hm] of a text x = [x1, x2, ..., xn] is obtained from a semantic vector sequence, where m represents m tokens (word segmentation) contained in the text, hi (1≤i≤m) represents the encoding vector corresponding to the i-th token, and then an original label sequence y = (y1, ..., ym) in the original label sequence set obtained by label prediction and CRF model, yi∈{1, ..., K} has a score of:
[0075] K is the number of label categories, A yi,yi+1 is the transfer score from label i to label i+1, where y0 and ym+1 are the start and end labels, P i,yi is the prediction score of label i.
[0076] In an optional embodiment of the present invention, the step of selecting a target sequence from the original label sequence set as the standard label sequence by using a preset target function includes:
[0077] Probabilistically optimizing the original label set using the objective function, and selecting a target sequence that maximizes the objective function as the standard label sequence;
[0078] The objective function is as follows:
[0079]
[0080] Among them, y X is the original label sequence set, s(h, y) represents the score of one sequence y in the original label sequence set, and p(y|h) represents the conditional probability of sequence y.
[0081] In an optional embodiment of the present invention, each sequence in the original label sequence set is calculated using the objective function, and the sequence that maximizes the objective function is used as the standard label sequence.
[0082] Specifically, performing entity labeling on the standard tag sequence to obtain an entity labeling result includes:
[0083] The text corresponding to the predicted label in the standard label sequence is used as the predicted entity to obtain the entity labeling result.
[0084] In an optional embodiment of the present invention, for example, for the relation instance text: "Xiao Ding is the ex-wife of Xiao Xia, one of the original actual controllers of First Electric", the obtained standard label sequence is:
[0085] “B-PER / I-PER / O / B-ORG / I-ORG / I-ORG / I-ORG / O / O / O / O / O / O / O / O / O / B-PER / I-PER / O / O / O” then the predicted entities corresponding to the predicted labels “B-PER, I-PER”, “B-ORG, I-ORG, I-ORG, I-ORG” and “B-PER, I-PER” include “Xiao Ding”, “First Electric” and “Xiao Xia”, which are the entity labeling results.
[0086] S3. Obtain a preset relationship set, and perform relationship prediction on the semantic vector sequence based on the relationship set to obtain a relationship prediction result.
[0087] In the embodiment of the present invention, the preset relationship set is predefined by the user and corresponds to the relationship instance text. For example, for the relationship instance text "Xiao Ding is one of the original actual controllers of First Electric and the ex-wife of Xiao Xia", the preset relationship set may include "husband and wife", "actual controller", "shareholder", etc. By giving a set of predefined relationship sets R = r1, r2, ..., r K (K is the size of R, that is, the category of the relationship), the vector h0 at the [CLS] position of the BERT encoding output result is used as input to identify all predicted relationships of the semantic vector sequence in the relationship set R, and then the sigmoid function is used to generate the probability of each predicted relationship, and the predicted relationship is screened according to the probability to obtain the relationship prediction result.
[0088] In detail, performing relationship prediction on the semantic vector sequence based on the relationship set to obtain a relationship prediction result includes:
[0089] Extracting the identification vector corresponding to the interval identification in the semantic vector sequence, and using a preset classification function to obtain the predicted relationship existing in the relationship set of the identification vector and the probability of the predicted relationship;
[0090] Based on the probability of the predicted relationship, the predicted relationship is classified using a preset label function to obtain the relationship prediction result.
[0091] In an optional embodiment of the present invention, the preset classification function is a sigmoid classification function.
[0092]
[0093] in, is the probability of the predicted i-th prediction relationship ri, W is the weight term in the sigmoid classification function, b r is the bias term in the sigmoid classification function, and h0 is the identification vector.
[0094] In an optional embodiment of the present invention, for example, in the example where the relationship instance text is "Xiao Ding is one of the original actual controllers of First Electric and the ex-wife of Xiao Xia", the probabilities of generating predicted relationships "shareholder relationship", "husband and wife relationship" and "actual controller relationship" through the sigmoid function are 0.8, 0.9 and 0.95 respectively.
[0095] In the embodiment of the present invention, the preset label function is as follows:
[0096]
[0097] Wherein, p(r|X) is the conditional probability distribution of the relationship prediction result relative to the entire relationship instance text X, K is the category of the classification relationship, is the probability of the predicted i-th prediction relationship ri, is the label of the i-th predicted relationship ri.
[0098] In an optional embodiment of the present invention, by maximizing the conditional probability distribution of the relationship prediction result, the combined probability of different predicted relationships in the entire relationship instance text can be obtained, and the relationship prediction result (r i1 ,...,r ik ). For example, for "shareholder relationship", "husband and wife relationship" and "actual controller relationship", by randomly combining different predicted relationships and solving the conditional probability distribution of each combination, the combination of "husband and wife relationship" and "actual controller relationship" that maximizes the conditional probability distribution is obtained as the relationship prediction result.
[0099] S4. Concatenate and combine the entity labeling results and the relationship prediction results to obtain an entity relationship pair set, perform head entity and tail entity probability recognition on the entity relationship pair set, and select a standard entity relationship pair from the entity relationship pair set according to the recognition results.
[0100] In detail, the entity labeling result and the relationship prediction result are combined to obtain an entity relationship pair set, the head entity and the tail entity probability recognition is performed on the entity relationship pair set, and a standard entity relationship pair is selected from the entity relationship pair set according to the recognition result, including:
[0101] Converting the relations in the relation prediction results into embedded relations according to the relation set;
[0102] Randomly combining the embedded relationships and entities in the entity annotation results to obtain the entity relationship pair set;
[0103] The probabilities of the head entity and the tail entity in the entity relationship pair set are calculated using a preset entity probability formula, and an entity relationship pair that meets preset conditions is selected as the standard entity relationship pair according to the probabilities.
[0104] In an optional embodiment of the present invention, the relationship set R=r1, r2, ..., r K Convert to a set of embedded expressions Then directly replace the relationship in the relationship prediction result with the corresponding embedded relationship. For example, the relationship r in the relationship prediction result i1 The corresponding embedding relationship is
[0105] In an optional embodiment of the present invention, the preset condition is the entity relationship pair that maximizes the argmax function, that is, the entity relationship pair with the maximum possible probability is found using the argmax function.
[0106] In the embodiment of the present invention, the method of calculating the probability of the head entity and the tail entity in the entity relationship pair set by using a preset entity probability formula includes:
[0107] The head entity probability and the tail entity probability of the i-th combination in the entity relationship pair set are calculated using the following formula:
[0108]
[0109]
[0110] Among them, sent is the text vector sequence, is the embedding relationship, and Represents entity E i Corresponds to The probability of the head entity or tail entity of the classification, W(·) is the trainable weight matrix, b(·) is the bias corresponding to the weight matrix, and σ is the sigmoid activation function.
[0111] In an embodiment of the present invention, for example, for an example in which the relationship instance text is "Xiao Ding is one of the original actual controllers of First Electric and the ex-wife of Xiao Xia", three entities "Xiao Ding", "First Electric" and "Xiao Xia" are obtained from the entity annotation results, and two relationship prediction results "actual controller relationship" and "husband and wife relationship" are obtained. The entities and relationship prediction results are randomly combined to obtain a set of entity relationship pairs of the "head entity-relationship-tail entity" type, including: "Xiao Ding-husband and wife-Xiao Xia", "Xiao Xia-actual controller-First Electric", "First Electric-husband and wife-Xiao Xia" and "Xiao Xia-husband and wife-First Electric", etc. The probability of the head entity and the tail entity in the entity relationship pair set is calculated, and the argmax function is used to find the entity relationship pair with the maximum possible probability: "Xiao Ding-husband and wife-Xiao Xia" and "Xiao Xia-actual controller-First Electric".
[0112] The present invention can improve the accuracy of entity annotation by first predicting labels on the semantic vector sequence and then performing entity annotation. At the same time, the relationship prediction is performed through a preset relationship set. Since the preset relationship set limits the number of predictable relationships, the excessive duplication of relationships can be effectively avoided by limiting the size of the relationship set, thereby improving the accuracy of entity relationship extraction. In addition, the entity annotation results and the relationship prediction results are spliced and combined to obtain all possible entity relationship pair sets. Since the entity annotation results and the relationship prediction results are obtained from the same semantic vector, the information of the two parts of entity recognition and relationship classification can be shared. Finally, by probabilistically identifying the entity relationship pair set, for entities with overlapping relationships, the probabilities of the head entity and the tail entity are considered at the same time, thereby further improving the accuracy of entity relationship extraction. Therefore, the entity relationship extraction method proposed by the present invention can solve the problem of low accuracy of entity relationship extraction.
[0113] like Figure 2 As shown, an embodiment of the present application provides a module schematic diagram of an entity relationship extraction device 10, and the entity relationship extraction device 10 includes: the semantic encoding module 11, the entity labeling module 12, the relationship prediction module 13 and the entity relationship pair extraction module 14.
[0114] The semantic encoding module 11 is used to obtain the relationship instance text, and use the pre-trained encoding model to semantically encode the relationship instance text to obtain a semantic vector sequence;
[0115] The entity labeling module 12 is used to perform label prediction on the semantic vector sequence, obtain a standard label sequence according to the prediction result, and perform entity labeling on the standard label sequence to obtain an entity labeling result;
[0116] The relationship prediction module 13 is used to obtain a preset relationship set, and perform relationship prediction on the semantic vector sequence based on the relationship set to obtain a relationship prediction result;
[0117] The entity relationship pair extraction module 14 is used to splice and combine the entity labeling results and the relationship prediction results to obtain an entity relationship pair set, perform head entity and tail entity probability recognition on the entity relationship pair set, and select a standard entity relationship pair from the entity relationship pair set according to the recognition results.
[0118] In detail, each module in the entity relationship extraction device 10 described in the embodiment of the present application adopts the same method as above when used. Figure 1 The entity relationship extraction method described in the text is the same technical means and can produce the same technical effects, so I will not go into details here.
[0119] like Figure 3 As shown, an embodiment of the present application provides an electronic device, including a processor 111, a communication interface 112, a memory 113 and a communication bus 114, wherein the processor 111, the communication interface 112, and the memory 113 communicate with each other through the communication bus 114;
[0120] Memory 113, used for storing computer programs;
[0121] In one embodiment of the present application, the processor 111 is used to execute the program stored in the memory 113 to implement the entity relationship extraction method provided by any of the above method embodiments, including:
[0122] Acquire relation instance text, and use a pre-trained encoding model to semantically encode the relation instance text to obtain a semantic vector sequence;
[0123] Performing label prediction on the semantic vector sequence, obtaining a standard label sequence according to the prediction result, and performing entity labeling on the standard label sequence to obtain an entity labeling result;
[0124] Acquire a preset relationship set, and perform relationship prediction on the semantic vector sequence based on the relationship set to obtain a relationship prediction result;
[0125] The entity labeling results and the relationship prediction results are spliced and combined to obtain an entity relationship pair set, the head entity and the tail entity probability recognition is performed on the entity relationship pair set, and a standard entity relationship pair is selected from the entity relationship pair set according to the recognition result.
[0126] The communication bus 114 may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus 114 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0127] The communication interface 112 is used for communication between the above electronic device and other devices.
[0128] The memory 113 may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Optionally, the memory 113 may also be at least one storage device located away from the processor 111 .
[0129] The above-mentioned processor 111 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components.
[0130] An embodiment of the present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the entity relationship extraction method provided in any of the aforementioned method embodiments are implemented.
[0131] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loading and executing computer program instructions on a computer, the process or function according to the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, a computer, a server or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server, a data center, etc. that contains one or more available media integrated. The available medium can be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk SolidStateDisk (SSD)), etc.
[0132] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0133] The foregoing is merely a specific embodiment of the present invention, which enables those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A method for extracting entity relations, characterized in that: The method comprises: Acquire a relation instance text, and use a pre-trained encoding model to semantically encode the relation instance text to obtain a semantic vector sequence, including: segmenting the relation instance text to obtain an original segmentation sequence, adding interval markers to the original segmentation sequence to obtain a standard segmentation sequence; using an embedded vector representation layer in the encoding model to generate a combination vector of each segmentation in the standard segmentation sequence; using an encoder layer in the encoding model to perform semantic feature encoding on the combination vector of each segmentation to obtain semantic feature vectors of all segmentations, and using a pooling layer in the encoding model to perform vector arrangement on the semantic feature vectors and the interval markers to obtain the semantic vector sequence; Perform label prediction on the semantic vector sequence, obtain a standard label sequence according to the prediction results, and perform entity annotation on the standard label sequence to obtain an entity annotation result, wherein the label prediction on the semantic vector sequence and the standard label sequence according to the prediction results include: performing label prediction on the semantic feature vector corresponding to each word segment in the semantic vector sequence to obtain multiple label sequences, each label sequence including a predicted label of each word segment and a predicted score corresponding to the predicted label; using the predicted score to filter and sort the predicted labels in the multiple label sequences to obtain an original label sequence set; using a preset objective function to select a target sequence from the original label sequence set as the standard label sequence; Acquire a preset relationship set, and perform relationship prediction on the semantic vector sequence based on the relationship set to obtain a relationship prediction result; The entity labeling results and the relationship prediction results are spliced and combined to obtain an entity relationship pair set, the head entity and the tail entity probability recognition is performed on the entity relationship pair set, and a standard entity relationship pair is selected from the entity relationship pair set according to the recognition result.
2. The entity relationship extraction method according to claim 1, characterized in that: The step of using the embedding vector representation layer in the encoding model to generate a combination vector of each word in the standard word segmentation sequence includes: Using the embedding vector representation layer, each word in the standard word segmentation sequence is converted into a token vector, a position vector and a sequence marker vector; The token vector, the position vector and the sequence tag vector of each word segment are combined using the following formula to obtain the combined vector embedding of each word segment: embeeing=embedding tokens +embedding position +embedding segtype Among them, embedding tokens is the token vector, embedding position is the position vector, embedding segtype is the sequence label vector.
3. The entity relationship extraction method according to claim 1, characterized in that: The selecting a target sequence from the original label sequence set as the standard label sequence by using a preset objective function includes: Probabilistically optimizing the original tag sequence set using the objective function, and selecting a target sequence that maximizes the objective function as the standard tag sequence; The objective function is as follows: Among them, y X is the original label sequence set, s(h, y) represents the score of one sequence y in the original label sequence set, and p(y|h) represents the conditional probability of sequence y.
4. The entity relationship extraction method according to claim 1, characterized in that: The performing relationship prediction on the semantic vector sequence based on the relationship set to obtain a relationship prediction result includes: Extracting the identification vector corresponding to the interval identification in the semantic vector sequence, and using a preset classification function to obtain the predicted relationship existing in the relationship set of the identification vector and the probability of the predicted relationship; Based on the probability of the predicted relationship, the predicted relationship is classified using a preset label function to obtain the relationship prediction result.
5. The entity relationship extraction method according to claim 4, characterized in that: The step of combining the entity labeling results and the relationship prediction results to obtain an entity relationship pair set, performing head entity and tail entity probability recognition on the entity relationship pair set, and selecting a standard entity relationship pair from the entity relationship pair set according to the recognition result includes: Converting the relations in the relation prediction results into embedded relations according to the relation set; Randomly combining the embedded relationships and entities in the entity annotation results to obtain the entity relationship pair set; The probabilities of the head entity and the tail entity in the entity relationship pair set are calculated using a preset entity probability formula, and an entity relationship pair that meets preset conditions is selected as the standard entity relationship pair according to the probabilities.
6. An entity relationship extraction device, characterized in that: The device comprises: A semantic encoding module is used to obtain a relation instance text, and to perform semantic encoding on the relation instance text using a pre-trained encoding model to obtain a semantic vector sequence, including: performing word segmentation on the relation instance text to obtain an original word segmentation sequence, and adding interval markers to the original word segmentation sequence to obtain a standard word segmentation sequence; using an embedded vector representation layer in the encoding model to generate a combination vector of each word segmentation in the standard word segmentation sequence; using an encoder layer in the encoding model to perform semantic feature encoding on the combination vector of each word segmentation to obtain semantic feature vectors of all word segmentations, and using a pooling layer in the encoding model to perform vector arrangement on the semantic feature vectors and the interval markers to obtain the semantic vector sequence; An entity labeling module is used to perform label prediction on the semantic vector sequence, obtain a standard label sequence according to the prediction results, and perform entity labeling on the standard label sequence to obtain an entity labeling result, wherein the label prediction on the semantic vector sequence and the acquisition of the standard label sequence according to the prediction results include: performing label prediction on the semantic feature vector corresponding to each word segment in the semantic vector sequence to obtain multiple label sequences, each label sequence including a predicted label for each word segment and a predicted score corresponding to the predicted label; using the predicted score to filter and sort the predicted labels in the multiple label sequences to obtain an original label sequence set; using a preset objective function to select a target sequence from the original label sequence set as the standard label sequence; A relationship prediction module, used to obtain a preset relationship set, perform relationship prediction on the semantic vector sequence based on the relationship set, and obtain a relationship prediction result; The entity relationship pair extraction module is used to splice and combine the entity labeling results and the relationship prediction results to obtain an entity relationship pair set, perform head entity and tail entity probability recognition on the entity relationship pair set, and select standard entity relationship pairs from the entity relationship pair set according to the recognition results.
7. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; Memory, used to store computer programs; A processor is used to implement the steps of the entity relationship extraction method described in any one of claims 1 to 5 when executing a program stored in a memory.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the entity relationship extraction method as described in any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Deep neural network based biomedical text serialization labeling system and method
CN105404632A
Entity and semantic relationship recognition method and device, electronic equipment and storage medium
CN111539211A