Entity relationship extraction method, device, electronic device and storage medium
Through the deep multi-fork decoding tree and self-attention mechanism, combined with the BERT pre-training model, the problem of entity overlap and incomplete feature extraction in entity relationship extraction is solved, and the ability to accurately identify overlapping entities in complex entities is achieved.
Patent Information
- Application Number
- CN202111602684.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-24
- Publication Date
- 2024-09-06
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing entity relationship extraction methods cannot effectively solve the problem of entity overlap in complex entities, and deep learning models have problems with incomplete feature extraction in recurrent neural networks and convolutional neural networks, making it difficult to accurately identify overlapping entities in the case of overlapping entities. .
Using a deep multi-fork decoding tree for decoding operations, combined with the BERT pre-training model and self-attention mechanism, by extracting sentence features and entity types, calculating long-distance dependencies, and decoding to obtain entity relationship triples, avoiding the model in a single decoding method Memory and overfitting.
It effectively identifies overlapping entities in the case of overlapping entities, avoids the memory and overfitting of the model in the single decoding process, and improves the accuracy and reliability of entity relationship extraction.
Smart Images

Figure CN114490885B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of natural language processing, and in particular to an entity relationship extraction method, device, electronic device and storage medium. Background Art
[0002] As an important task in the field of natural language processing, entity relationship extraction has received extensive attention and research. In the early stage of research, the entity relationship extraction method was mainly based on rules or ontology. However, this method overly relied on large-scale pattern matching rules performed by industry experts, and showed poor portability across fields, which greatly consumed manpower and material resources. Later, with the development of traditional machine learning, the machine learning method based on statistics significantly improved the recall rate and cross-domain ability of entity relationship extraction. Since Hinton G et al. proposed the deep learning method, researchers have applied deep learning to the task of entity relationship extraction and achieved quite excellent results. In 2012, Socher R et al. used recurrent neural networks (RNN) for entity relationship extraction tasks and incorporated sentence features into the task, but ignored the importance of position information; Zhang DX et al. introduced position information when using recurrent neural networks, but the recurrent neural network had a long-distance dependency problem, which was not solved in this method; Zeng et al. used convolutional neural networks (CNN) for relationship extraction for the first time, extracting richer features, but due to the influence of the convolution kernel size, semantic features could not be extracted well. Li Qingqing et al. designed a multi-task model with Attention mechanism to improve the performance of entity relationship extraction by sharing information encoding. Li Weijiang et al. used Bi-RNN to solve the dependency between words and integrated position, grammar, syntax and semantic information for entity relationship extraction. Zheng et al. used Bi-RNN and CNN models to fuse into a joint extraction model, shared the encoding layer of BiLSTM, and used LSTM and CNN for decoding to solve the problem of information redundancy.
[0003] However, existing entity relationship extraction methods cannot solve the problem of entity overlap in complex entities, and recurrent neural networks and convolutional neural networks are mostly used in previous deep learning. Although recurrent neural networks can capture the overall characteristics of the sequence very well, some features will be discarded during the recursive extraction process, resulting in poor extraction of local features; although convolutional neural networks are good at extracting local features, they can easily ignore the global information of the sequence. Summary of the invention
[0004] Based on this, the purpose of the present invention is to provide an entity relationship extraction method, device, electronic device and storage medium, abandoning the previous single decoding method and instead using a deep multi-branch decoding tree for decoding operations, thereby avoiding the phenomenon that the model generated in the single decoding process is easy to memorize and overfit the entities and relationships that frequently appear in the training set, and can well identify overlapping entities in the case of entity overlap.
[0005] In a first aspect, the present invention provides a method for extracting entity relationships, the method comprising the following steps:
[0006] Get the text of the entity relationship to be extracted;
[0007] Input the text into the BERT pre-trained model, extract the sentence features of the text, and obtain the hidden vector corresponding to the word at each position in the text;
[0008] Input the hidden vector into the entity recognition layer to obtain all entities and entity types in the text;
[0009] The tokens obtained by connecting the words in the text and the entities in the text are input into the self-attention layer, and the pairwise similarities of the tokens in the entire sequence are calculated to obtain long-distance dependencies of any distance;
[0010] The output sequence of the self-attention layer is input into a multi-branch decoding tree, and the entity relationship triples of the text are obtained by decoding.
[0011] Furthermore, the BERT pre-training model includes an input layer and a multi-layer Transformer, wherein the input layer includes a position encoding and a word encoding;
[0012] Input the text into the BERT pre-trained model, extract the sentence features of the text, and obtain the hidden vector corresponding to the word at each position in the text, including:
[0013] The text is input into the input layer, and the text is encoded to obtain w=[E1, E2, E3, ..., E n ], where w is the code corresponding to the text, E i is the code corresponding to the word with sequence number i in the text;
[0014] The text encoding is input into the multi-layer Transformer, and the sentence features of the text are extracted to obtain H = [h1, h2, h3, ..., h n ], where H is the hidden vector corresponding to the text, h i is the hidden vector corresponding to the word with sequence number i in the text.
[0015] Further, the entity recognition layer includes a Span representation layer and a Span classifier;
[0016] The hidden vector is input into the entity recognition layer to obtain all entities and entity types in the text, including:
[0017] The hidden vector is input into the Span representation layer to obtain a tag sequence S: = (hi, hi+1, ..., hi+k), where h i is the hidden vector corresponding to the word with sequence number i in the text;
[0018] Use the fusion function g to generate the candidate Span expression E(s): = g(hi, hi+1, ..., hi+k), where E(s) is the candidate Span, h i is the hidden vector corresponding to the word with sequence number i in the text;
[0019] Add the keyword C to the candidate Span to obtain the final expression of the Span Xs:=E(s)o C, where Xs is the final expression of the Span and o represents a connection symbol;
[0020] The final expression of the span is input into the softmax classifier, and the entity type score corresponding to each span is obtained using the following formula:
[0021] ECS=softmax(Xs)
[0022] Among them, ECS represents the entity type score;
[0023] The span classifier outputs the entity type with the highest score corresponding to each span, which is the entity type corresponding to the span;
[0024] Filter out spans of type none, leaving a group of spans that constitute entities, and obtain all entities and entity types in the text.
[0025] Furthermore, the tokens obtained by connecting the words in the text and the entities in the text are input into the self-attention layer, and the pairwise similarities of the tokens in the entire sequence are calculated to obtain long-range dependencies of any distance, including:
[0026] Use the following formula to get the new sequence T:
[0027] T = concat[h; Xs]
[0028] Wherein, concat[[] is used to connect h and Xs, where h is the word expression in the text, and Xs is the entity expression corresponding to the text;
[0029] The concatenated sequence T = [t1, t2, ..., t p ], where p is the number of hidden vectors in the sequence T;
[0030] Take T as the input of the self-attention layer. In the self-attention mechanism, Q, K, and V are linear transformations of the same vector in T. The following formula is used to calculate the pairwise similarity of tokens in the entire sequence and obtain long-distance dependencies of any distance:
[0031] Self-Att(T)=Attention(TQw Q , TKW K , TVw V )=softmax(TVw V )
[0032] Among them, TQ, TK, TV are the linear transformations of the vectors in T, w Q , w K , w V are model parameters, learned during model training;
[0033] The final output of the self-attention layer is obtained through layer normalization and residual connection:
[0034] Self-out=layernorm(Self-Att(T)+T)
[0035] Among them, Self-out is the final output of the self-attention layer, let it be h self , layernorm() is layer normalization and residual connection, and T is the input sequence of the self-attention layer.
[0036] Furthermore, the multi-branch decoding tree includes a first entity decoding layer, a relationship decoding layer, and a second entity decoding layer; wherein the decoding parts share the same input sequence, which is the output of the self-attention layer
[0037] The output sequence of the self-attention layer is input into a multi-branch decoding tree, and the entity relationship triples of the text are obtained by decoding, including:
[0038] The output sequence of the self-attention layer is input into the first entity decoding layer, and the first entity is selected by decoding using the following formula:
[0039] e1=Sig(h self *w e1 +b e1 )
[0040] Among them, w e1 is the weight, b e1 is the partial rank; h self is the output of the self-attention layer;
[0041] The output sequence of the self-attention layer is input into the relationship decoding layer, and the relationship prediction possibility is obtained using the following formula:
[0042] Possible r =Soft(max(h self *w r +b r ))
[0043] Among them, w r is the weight, b r is the partial rank; h self is the output of the self-attention layer;
[0044] The output sequence of the self-attention layer is input into the second entity decoding layer, and the second entity corresponding to the first and relation R is predicted on the entire sequence using the following formula:
[0045]
[0046] Among them, w e2 is the weight, b e2 is the partial rank; h self is the output of the self-attention layer;
[0047] Using the first entity, relation R and the corresponding second entity, an entity relation triple of the text is obtained.
[0048] In a second aspect, the present invention further provides an entity relationship extraction device, comprising:
[0049] A text acquisition module is used to acquire the text of the entity relationship to be extracted;
[0050] A sentence feature extraction module, used to input the text into a BERT pre-trained model, extract sentence features of the text, and obtain a hidden vector corresponding to a word at each position in the text;
[0051] An entity recognition module, used for inputting the hidden vector into an entity recognition layer to obtain all entities and entity types in the text;
[0052] A self-attention module is used to input the tokens obtained by connecting the words in the text and the entities in the text into the self-attention layer, calculate the pairwise similarity of the tokens in the entire sequence, and obtain the long-distance dependency of any distance;
[0053] A decoding module is used to input the output sequence of the self-attention layer into a multi-branch decoding tree to decode and obtain the entity relationship triples of the text.
[0054] In a third aspect, the present invention further provides an electronic device, comprising:
[0055] at least one memory and at least one processor;
[0056] The memory is used to store one or more programs;
[0057] When the one or more programs are executed by the at least one processor, the at least one processor implements the steps of an entity relationship extraction method as described in any one of the first aspects of the present invention.
[0058] In a fourth aspect, the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of an entity relationship extraction method as described in any one of the first aspects of the present invention are implemented.
[0059] The present invention provides an entity relationship extraction method, device, electronic device and storage medium, which uses a self-attention mechanism to obtain the long-distance dependency between entities and sentences, abandons the previous single decoding method, and uses a deep multi-branch decoding tree to perform decoding operations, thereby avoiding the phenomenon that the model generated in the single decoding process is easy to remember and overfit the entities and relationships that frequently appear in the training set. It can effectively solve the problem of multiple relationships for a single entity, and can well identify overlapping entities in the case of entity overlap.
[0060] For better understanding and implementation, the present invention is described in detail below with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] Figure 1 A schematic diagram of a flow chart of an entity relationship extraction method provided by the present invention;
[0062] Figure 2 is a schematic diagram of a relation triple in an exemplary text;
[0063] Figure 3 is a schematic diagram of a decoding sequence in an embodiment;
[0064] Figure 4 A schematic diagram of the sequence of performing relation decoding using a multi-branch decoding tree in one embodiment of the present invention;
[0065] Figure 5 A schematic diagram of the structure of a multi-branch decoding tree used in one embodiment of the present invention;
[0066] Figure 6 A schematic diagram of the structure of an entity relationship extraction model used in one embodiment of the present invention;
[0067] Figure 7A schematic diagram of the structure of an entity relationship extraction device provided by the present invention. DETAILED DESCRIPTION
[0068] In order to make the objectives, technical solutions and advantages of the present application more clear, the embodiments of the present application will be further described in detail below with reference to the accompanying drawings.
[0069] It should be clear that the described embodiments are only 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 creative work are within the scope of protection of the embodiments of the present application.
[0070] The terms used in the embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to limit the embodiments of the present application. The singular forms of "a", "said" and "the" used in the embodiments of the present application and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in the present invention refers to and includes any or all possible combinations of one or more associated listed items.
[0071] When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. On the contrary, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the attached claims. In the description of the present application, it should be understood that the terms "first", "second", "third", etc. are only used to distinguish similar objects, and do not have to be used to describe a specific order or sequence, nor can they be understood as indicating or implying relative importance. For those of ordinary skill in the art, the specific meanings of the above terms in the present application can be understood according to the specific circumstances.
[0072] In addition, in the description of this application, unless otherwise specified, "plurality" means two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the associated objects are in an "or" relationship.
[0073] In view of the problems in the background technology, the present application embodiment provides an entity relationship extraction method, such as Figure 1 As shown, the method comprises the following steps:
[0074] S01: Obtain the text of the entity relationship to be extracted.
[0075] S02: Input the text into the BERT pre-training model, extract the sentence features of the text, and obtain the hidden vector corresponding to the word at each position in the text.
[0076] Traditional deep learning-based relationship extraction uses recurrent neural networks or convolutional neural networks. Although recurrent neural networks can capture the overall features of a sequence very well, they are not good at extracting local features; although convolutional neural networks are good at extracting local features, they easily ignore the global information of the sequence. In view of the lack of functions of the first two and their heavy reliance on manually annotated features, an entity relationship extraction method provided in this application chooses to use the BERT neural network model.
[0077] In a specific embodiment, the BERT pre-training model includes an input layer and a multi-layer Transformer, wherein the input layer includes position encoding and word encoding.
[0078] Input the text into the BERT pre-trained model, extract the sentence features of the text, and obtain the hidden vector corresponding to the word at each position in the text, including the following sub-steps:
[0079] S021: Input the text into the input layer, encode the text, and obtain w=[E1, E2, E3, ..., E n ], where w is the code corresponding to the text, and Ei is the code corresponding to the word with sequence number i in the text;
[0080] S022: Input the text encoding into the multi-layer Transformer, extract the sentence features of the text, and obtain H = [h1, h2, h3, ..., h n ], where H is the hidden vector corresponding to the text, h i is the hidden vector corresponding to the word with sequence number i in the text.
[0081] S03: Input the hidden vector into the entity recognition layer to obtain all entities and entity types in the text.
[0082] After some Span-based entity relationship extraction methods were proposed, the overlapping entity extraction effect of the previous BIO / BILOU tag-based methods was greatly improved. Span-based methods: Any labeled subsequence (Span) is used as a potential entity. For example, in "Xiao Ming was detected with food poisoning", {"Xiao Ming", "Xiao Ming was", ... "food", "food", "food poisoning"} can all be used as potential entities.
[0083] In a preferred embodiment, the entity recognition layer includes a Span representation layer and a Span classifier.
[0084] The hidden vector is input into the entity recognition layer to obtain all entities and entity types in the text, including the following sub-steps:
[0085] S031: Input the hidden vector into the Span representation layer to obtain a tag sequence S: = (hi, hi+1, ..., hi+k), where h i is the hidden vector corresponding to the word with sequence number i in the text;
[0086] S032: Use the fusion function g to generate a candidate Span expression E(s): = g(hi, hi+1, ..., hi+k), where E(s) is the candidate Span, h i is the hidden vector corresponding to the word with sequence number i in the text;
[0087] S033: Add the keyword C to the candidate Span to obtain the final expression of the Span Xs:=E(s)o C, where Xs is the final expression of the Span and o represents a connection symbol;
[0088] S034: Input the final expression of the Span into the softmax classifier, and use the following formula to obtain the entity type score corresponding to each Span:
[0089] ECS=softmax(Xs)
[0090] Among them, ECS represents the entity type score;
[0091] S035: taking the entity type with the highest score corresponding to each span output by the span classifier as the entity type corresponding to the span;
[0092] S036: Filter out spans of the none type, leaving a group of spans constituting entities, and obtain all entities and entity types in the text.
[0093] S04: The tokens obtained by connecting the words in the text and the entities in the text are input into the self-attention layer, and the pairwise similarities of the tokens in the entire sequence are calculated to obtain long-distance dependencies of any distance.
[0094] As a variant of the attention mechanism, the self-attention mechanism can better capture the internal correlation of data or features. The long-distance dependency of any distance is captured by calculating the pairwise similarity of tokens in the entire sequence. The entity relationship extraction method provided by the present invention enhances the mutual dependency between entities and sentences through the self-attention mechanism.
[0095] In a preferred embodiment, step S04 includes the following sub-steps:
[0096] S041: Use the following formula to get the new sequence T:
[0097] T = concat[h; Xs]
[0098] Wherein, concat[[] is used to connect h and Xs, where h is the word expression in the text, and Xs is the entity expression corresponding to the text;
[0099] S042: The connected sequence T = [t1, t2, ..., t p ], where p is the number of hidden vectors in the sequence T;
[0100] S043: Take T as the input of the self-attention layer. In the self-attention mechanism, Q, K, and V are linear transformations of the same vector in T. The following formula is used to calculate the pairwise similarity of the tokens in the entire sequence to obtain the long-distance dependency of any distance:
[0101] Self-Att(T)=Attention(TQw Q , TKW K , TVw V )=softmax(TVw V )
[0102] Among them, TQ, TK, TV are the linear transformations of the vectors in T, w Q , w K , w V are model parameters, learned during model training;
[0103] S044: The final output of the self-attention layer is obtained through layer normalization and residual connection:
[0104] Self-out=layernorm(Self-Att(T)+T)
[0105] Among them, Self-out is the final output of the self-attention layer, let it be h self , layernorm() is layer normalization and residual connection, and T is the input sequence of the self-attention layer.
[0106] S05: Input the output sequence of the self-attention layer into a multi-branch decoding tree, and decode to obtain entity relationship triples of the text.
[0107] The deep multi-branch decoding tree changes the previous single decoding method to a multi-decoding method, which better solves the problem of easy model memorization and overfitting of entities and relationships that frequently appear in the training set caused by single decoding. By decoding triples in parallel, the execution order of triples and the overlap of one-to-many relationships are well solved. For example, Figure 2 As shown, for the text "XXX was born in Shanghai, China, and graduated from MIT and California Institute of Technology.", if the decoding execution order is {triplet 1, triplet 2, triplet 3}, such as Figure 3 . However, {triplet 2, triplet 1, triplet 3} and {triplet 2, triplet 3, triplet 1} are also correct, and only one of the orders can be executed for a single decoding case. And for a single decoding case, if data in an order such as {triplet 2, triplet 3} appears very frequently, the trained model will directly end at a high degree of fitting {triplet 2, triplet 3}, thereby ignoring triple 1, resulting in overfitting in later applications. Therefore, the present invention abandons the previous single decoding method and uses a multi-branch decoding tree method to decode relational triplets, such as Figure 4 shown.
[0108] During decoding, since relations are multi-classified and entities use binary classification, the present invention uses the same input encoding but different output layers.
[0109] In a preferred embodiment, Figure 5 As shown, the multi-branch decoding tree includes a first entity decoding layer, a relation decoding layer and a second entity decoding layer.
[0110] Inputting the output sequence of the self-attention layer into a multi-branch decoding tree, decoding to obtain entity relationship triples of the text, including the following sub-steps:
[0111] S051: Input the output sequence of the self-attention layer into the first entity decoding layer, and use the following formula to decode and select the first entity:
[0112] e1=Sig(h self w e1 +b e1 )
[0113] Among them, w e1 is the weight, b e1 is the partial rank; h self is the output of the self-attention layer;
[0114] S052: Input the output sequence of the self-attention layer into the relationship decoding layer, and use the following formula to obtain the relationship prediction possibility size:
[0115] Possible r =Soft(max(h self w r +b r ))
[0116] Among them, w r is the weight, b ris the partial rank; h self Output of the self-attention layer;
[0117] S053: Input the output sequence of the self-attention layer into the second entity decoding layer, and use the following formula to predict the second entity corresponding to the first and relation R on the entire sequence:
[0118] Posible2=Soft(max(h self w e2 +b e2 ))
[0119] Among them, w e2 is the weight, b e2 is the partial rank; h self Output of the self-attention layer;
[0120] S054: Using the first entity, the relationship R and the corresponding second entity, obtain the entity relationship triple of the text.
[0121] In a specific embodiment, Figure 6 As shown, the entity relationship extraction model used in the present invention is first encoded using the BERT pre-trained model with stronger semantic feature extraction capabilities; then the spans that meet the entity category are extracted from all candidate spans using a span-based method; then the dependency between the entity and the sentence is enhanced using an attention mechanism; finally, the encoding vector of the context encoding that incorporates the dependency information and the entity spans encoding is connected and transmitted to the decoding model, and the relationship triples are decoded through a deep multi-branch decoding tree.
[0122] The present application also provides an entity relationship extraction device, such as Figure 7 As shown, the entity relationship extraction device 400 includes:
[0123] A text acquisition module 401 is used to acquire text of entity relationships to be extracted;
[0124] A sentence feature extraction module 402 is used to input the text into a BERT pre-trained model, extract sentence features of the text, and obtain a hidden vector corresponding to a word at each position in the text;
[0125] An entity recognition module 403 is used to input the hidden vector into an entity recognition layer to obtain all entities and entity types in the text;
[0126] A self-attention module 404 is used to input the tokens obtained by connecting the words in the text and the entities in the text into the self-attention layer, calculate the pairwise similarity of the tokens in the entire sequence, and obtain the long-distance dependency of any distance;
[0127] The decoding module 405 is used to input the output sequence of the self-attention layer into a multi-branch decoding tree to decode and obtain the entity relationship triples of the text.
[0128] The present application also provides an electronic device, including:
[0129] at least one memory and at least one processor;
[0130] The memory is used to store one or more programs;
[0131] When the one or more programs are executed by the at least one processor, the at least one processor implements the steps of the entity relationship extraction method as described above.
[0132] The present application also provides a computer-readable storage medium.
[0133] The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the entity relationship extraction method as described above are implemented.
[0134] The present invention provides an entity relationship extraction method, device, electronic device and storage medium, which uses a self-attention mechanism to obtain the long-distance dependency between entities and sentences, abandons the previous single decoding method, and uses a deep multi-branch decoding tree to perform decoding operations, thereby avoiding the phenomenon that the model generated in the single decoding process is easy to remember and overfit the entities and relationships that frequently appear in the training set. It can effectively solve the problem of multiple relationships for a single entity, and can well identify overlapping entities in the case of entity overlap.
[0135] The above-mentioned embodiments only express several implementation methods of the present invention, and the description is relatively specific and detailed, but it cannot be understood as limiting the scope of the invention patent. It should be pointed out that for ordinary technicians in this field, several modifications and improvements can be made without departing from the concept of the present invention, which all belong to the protection scope of the present invention.
Claims
1. A method for extracting entity relations, characterized in that: The following steps are involved: Get the text of the entity relationship to be extracted; Input the text into the BERT pre-trained model, extract the sentence features of the text, and obtain the hidden vector corresponding to the word at each position in the text; Inputting the hidden vector into an entity recognition layer to obtain all entities and entity types in the text; The tokens obtained by connecting the words in the text and the entities in the text are input into the self-attention layer, and the pairwise similarities of the tokens in the entire sequence are calculated to obtain long-distance dependencies of any distance; Inputting the output sequence of the self-attention layer into a multi-branch decoding tree, and decoding to obtain entity relationship triples of the text; Wherein, the entity recognition layer includes a Span representation layer and a Span classifier; The hidden vector is input into the entity recognition layer to obtain all entities and entity types in the text, including: The hidden vector is input into the Span representation layer to obtain a tag sequence S:=(hi,hi+1,…,hi+k), where h i is the hidden vector corresponding to the word with sequence number i in the text; Use the fusion function g to generate the candidate Span expression E(s): = g(hi,hi+1,…,hi+k), where E(s) is the candidate Span, h i is the hidden vector corresponding to the word with sequence number i in the text; Add the keyword C to the candidate Span to obtain the final expression of the Span Xs:=E(s)o C, where Xs is the final expression of the Span and o represents a connection symbol; The final expression of the span is input into the softmax classifier, and the entity type score corresponding to each span is obtained using the following formula: ECS=softmax(Xs) Among them, ECS represents the entity type score; The entity type with the highest score corresponding to each span output by the span classifier is used as the entity type corresponding to the span; Filter out spans of type none, leaving a group of spans that form entities, and obtain all entities and entity types in the text; Wherein, the multi-branch decoding tree includes a first entity decoding layer, a relation decoding layer, and a second entity decoding layer; The output sequence of the self-attention layer is input into a multi-branch decoding tree, and the entity relationship triples of the text are obtained by decoding, including: The output sequence of the self-attention layer is input into the first entity decoding layer, and the first entity is selected by decoding using the following formula: e1=Sig(h self w e1 + e1 ) Among them, w e1 is the weight, b e1 is the partial rank; h self is the output of the self-attention layer; The output sequence of the self-attention layer is input into the relationship decoding layer, and the relationship prediction possibility is obtained using the following formula: Posible r =oft(max(h self w r +b r )) Among them, w r is the weight, b r is the partial rank; h self is the output of the self-attention layer; The output sequence of the self-attention layer is input into the second entity decoding layer, and the second entity corresponding to the first and relation R is predicted on the entire sequence using the following formula: Posible2=oft(max(h self w e2 + e2 )) Among them, w e2 is the weight, b e2 is the partial rank; h self is the output of the self-attention layer; Using the first entity, relation R and the corresponding second entity, an entity relation triple of the text is obtained.
2. The entity relationship extraction method according to claim 1, characterized in that: The BERT pre-training model includes an input layer and a multi-layer Transformer, wherein the input layer includes position encoding and word encoding; Input the text into the BERT pre-trained model, extract the sentence features of the text, and obtain the hidden vector corresponding to the word at each position in the text, including: The text is input into the input layer, and the text is encoded to obtain w=[E1, E2, E3, ..., E n ], where w is the code corresponding to the text, E i is the code corresponding to the word with sequence number i in the text; The text encoding is input into the multi-layer Transformer, and the sentence features of the text are extracted to obtain H = [h1, h2, h3, ..., h n ], where H is the hidden vector corresponding to the text, h i is the hidden vector corresponding to the word with sequence number i in the text.
3. The entity relationship extraction method according to claim 1, characterized in that: The tokens obtained by connecting the words in the text and the entities in the text are input into the self-attention layer, and the pairwise similarities of the tokens in the entire sequence are calculated to obtain long-distance dependencies of any distance, including: Use the following formula to get the new sequence T: T = concat[h; Xs] Wherein, concat[] is used to connect h and Xs, where h is the word expression in the text, and Xs is the entity expression corresponding to the text; The concatenated sequence T = [t1, t2, ..., t p ], where p is the number of hidden vectors in the sequence T; Take T as the input of the self-attention layer. In the self-attention mechanism, Q, K, and V are linear transformations of the same vector in T. The following formula is used to calculate the pairwise similarity of tokens in the entire sequence and obtain long-range dependencies of any distance: Self–Att(T)=Attention(TQw Q ,TKw K ,TVw V )=softmax(TVw V ) Among them, TQ, TK, TV are linear transformations of vectors in T, w Q ,w K ,w V are model parameters, learned during model training; The final output of the self-attention layer is obtained through layer normalization and residual connection: Self-out=layernorm(Self–Att(T)+T) Among them, Self-out is the final output of the self-attention layer, let it be h self , layernorm() is layer normalization and residual connection, and T is the input sequence of the self-attention layer.
4. An entity relationship extraction device, characterized in that: include: A text acquisition module is used to acquire the text of the entity relationship to be extracted; A sentence feature extraction module, used to input the text into a BERT pre-trained model, extract sentence features of the text, and obtain a hidden vector corresponding to a word at each position in the text; An entity recognition module, used for inputting the hidden vector into an entity recognition layer to obtain all entities and entity types in the text; A self-attention module is used to input the tokens obtained by connecting the words in the text and the entities in the text into the self-attention layer, calculate the pairwise similarity of the tokens in the entire sequence, and obtain the long-distance dependency of any distance; A decoding module, used for inputting the output sequence of the self-attention layer into a multi-branch decoding tree, and decoding to obtain entity relationship triples of the text; Wherein, the entity recognition layer includes a Span representation layer and a Span classifier; The hidden vector is input into the entity recognition layer to obtain all entities and entity types in the text, including: The hidden vector is input into the Span representation layer to obtain a tag sequence S:=(hi,hi+1,…,hi+k), where h i is the hidden vector corresponding to the word with sequence number i in the text; Use the fusion function g to generate the candidate Span expression E(s): = g(hi,hi+1,…,hi+k), where E(s) is the candidate Span, h i is the hidden vector corresponding to the word with sequence number i in the text; Add the keyword C to the candidate Span to obtain the final expression of the Span Xs:=E(s)o C, where Xs is the final expression of the Span and o represents a connection symbol; The final expression of the span is input into the softmax classifier, and the entity type score corresponding to each span is obtained using the following formula: ECS=softmax(Xs) Among them, ECS represents the entity type score; The entity type with the highest score corresponding to each span output by the span classifier is used as the entity type corresponding to the span; Filter out spans of type none, leaving a group of spans that form entities, and obtain all entities and entity types in the text; Wherein, the multi-branch decoding tree includes a first entity decoding layer, a relation decoding layer, and a second entity decoding layer; The output sequence of the self-attention layer is input into a multi-branch decoding tree, and the entity relationship triples of the text are obtained by decoding, including: The output sequence of the self-attention layer is input into the first entity decoding layer, and the first entity is selected by decoding using the following formula: e1=Sig(h self w e1 + e1 ) Among them, w e1 is the weight, b e1 is the partial rank; h self is the output of the self-attention layer; The output sequence of the self-attention layer is input into the relationship decoding layer, and the relationship prediction possibility is obtained using the following formula: Posible r =oft(max(h self w r +b r )) Among them, w r is the weight, b r is the partial rank; h self is the output of the self-attention layer; The output sequence of the self-attention layer is input into the second entity decoding layer, and the second entity corresponding to the first and relation R is predicted on the entire sequence using the following formula: Posible2=oft(max(h self w e2 + e2 )) Among them, w e2 is the weight, b e2 is the partial rank; h self is the output of the self-attention layer; Using the first entity, relation R and the corresponding second entity, an entity relation triple of the text is obtained.
5. An electronic device, characterized in that: include: at least one memory and at least one processor; The memory is used to store one or more programs; When the one or more programs are executed by the at least one processor, the at least one processor implements the steps of an entity relationship extraction method as described in any one of claims 1-3.
6. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of an entity relationship extraction method as described in any one of claims 1-3 are implemented.
