A joint extraction method of entity relations based on entity pair attention mechanism

Through the joint extraction method of entity relationships based on the entity pair attention mechanism, the problems of entity redundancy and triple overlap in the existing technology are solved, efficient entity and relationship extraction is achieved, and the training efficiency and extraction effect of the model are improved.

CN115062109BActive Publication Date: 2024-08-27SHENYANG AEROSPACE UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210677466.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-16
Publication Date
2024-08-27
Estimated Expiration
2042-06-16

AI Technical Summary

Technical Problem

Existing technologies have problems such as entity redundancy, error propagation, excessive parameters leading to time-consuming training, and triple overlap problems in entity relationship extraction, making it difficult to effectively extract high-quality entity relationships from unstructured text.

Method used

The joint extraction method of entity relationships based on the entity pair attention mechanism is adopted. By constructing a joint model of entity recognition and relationship extraction, and using the entity pair attention mechanism and loss function, the joint extraction of entities and relationships is realized, which solves the problem of entity redundancy and triple Tuple overlap problem improves model training efficiency and interaction.

Benefits of technology

It effectively solves the problem of entity redundancy and triple overlap, speeds up model training, improves model training efficiency, enhances the interaction between entities and relationships, and improves the extraction effect.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115062109B
    Figure CN115062109B
Patent Text Reader

Abstract

The present invention discloses a method for joint extraction of entity relations based on entity pair attention mechanism, and relates to the technical field of natural language processing; specifically: processing a data set to obtain entities and relations between entities; constructing an entity relationship joint extraction model based on entity pair attention mechanism, wherein the encoding layer uses embedded representation to represent the features of three different granularities of character level, word level and part of speech in a sentence, obtains the initial encoding of the sentence, the entity recognition layer uses a Bi-LSTM neural network in combination with a CRF layer to extract entities, the relationship extraction layer pairs the extracted entities, and uses a sentence encoding module based on the entity pair attention mechanism to extract relations between entities; by training the entity relationship joint extraction model, and testing the model, and then updating the model according to the test results. The present invention can extract entity relationship triples from unstructured text, realize the knowledge of unstructured text, and is suitable for the automatic construction of large-scale knowledge graphs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of computer natural language processing, and in particular to a method for jointly extracting entity relations based on an entity pair attention mechanism. Background Art

[0002] With the continuous development of the Internet, cloud computing and communication technologies, massive amounts of data are currently generated in various fields. At the same time, these data show characteristics such as multi-source, heterogeneous, high-dimensional, low-quality, and fragmented. In the era of big data, efficient organization of massive data is one of the effective technologies to achieve multi-heterogeneous data fusion. Therefore, how to quickly and accurately extract high-quality, structured, and valuable information that can be directly used by computers from computer-generated data so that it can automatically construct knowledge graphs is a hot topic in current research.

[0003] In order to efficiently utilize the valuable information in unstructured text, researchers have proposed the entity relationship extraction technology, which is a combination of named entity recognition and relationship extraction tasks. The purpose is to extract entities and their relationships from unstructured text. In order to solve the entity relationship extraction task, researchers have proposed a variety of solutions, which are currently divided into two categories: pipeline extraction model and joint extraction model.

[0004] The pipeline extraction model can be described as follows: This method divides entity relationship extraction into two subtasks: named entity recognition and relationship extraction. The two subtasks are performed in sequence without any interaction. The pipeline model is easy to implement, simple to operate, and highly flexible, but it also has problems such as entity redundancy, error propagation, and lack of interaction.

[0005] To this end, researchers have proposed a joint extraction model, which can effectively utilize the close connection between entities and relations, alleviate error propagation, strengthen the interaction between the two subtasks, and effectively improve the performance of the model. The model can be described as: through the joint learning of the two tasks of entity recognition and relationship extraction, triples are directly obtained. Generally, joint models can be divided into parameter sharing, sequence labeling and other methods. The joint model can further utilize the potential information between the two subtasks and enhance the interaction between tasks, but there are the following problems:

[0006] (1) Although the parameter sharing method enables the two subtasks to exchange information at the bottom level, it will cause the model parameters to be too large and the training time will be too time-consuming;

[0007] (2) The advantage of the sequence labeling method is that it introduces a unified label for joint decoding, which solves the problem of information redundancy in the parameter sharing method. However, it can only give each word a unique label and cannot solve the problem of triple overlap.

[0008] Therefore, how to better extract valuable information from massive unstructured texts has attracted the attention of many researchers, and with the development of deep learning, it has further promoted the rapid development of this field. Summary of the invention

[0009] In view of the problems existing in the prior art, the present invention provides a method for joint extraction of entity relations based on entity pair attention mechanism. By processing the data set, entities and relationships between entities are obtained, and an entity relation joint extraction model based on entity pair attention mechanism is constructed to complete the task of extracting entity relation triplets from unstructured text and realize the joint extraction of entity relations.

[0010] To achieve the above purpose, the technical solution adopted is:

[0011] A method for joint extraction of entity relations based on entity pair attention mechanism, comprising the following steps:

[0012] S1: Sentence segmentation, deduplication, word segmentation, dictionary construction, and entity and entity relationship acquisition;

[0013] S2: construct an entity relationship joint extraction model based on entity pair attention mechanism, wherein the entity relationship joint extraction model includes: an encoding layer for obtaining an initial encoding of a sentence, an entity recognition layer for extracting entities from a sentence, and a relationship extraction layer for extracting relationships between entities;

[0014] S3: Set the loss function for entity recognition and relationship extraction, combine the loss function for entity recognition and the loss function for relationship extraction, complete the training and testing of the entity-relationship joint extraction model, and update the entity-relationship joint extraction model according to the test results.

[0015] The S1 specifically includes the following steps:

[0016] S1.1: Sentence the dataset, delete duplicate sentences, use the word segmentation tool in NLTK (Natural Language Toolkit, Natural Language Processing Toolkit) to process the sentences, obtain the target word segmentation, and build a dictionary of word mapping IDs;

[0017] S1.2: For the sentences in the dataset that have been processed by word segmentation, use the part-of-speech tagging tool in NLTK to complete the part-of-speech tagging of the sentences and build a dictionary of part-of-speech mapping IDs;

[0018] S1.3: For each word in the sentence, build a dictionary of character mapping IDs;

[0019] S1.4: Count the entity categories that appear in the data set, and build a dictionary of entity category label mapping IDs based on the "BIESO" annotation method;

[0020] S1.5: Count the entity relationship categories that appear in the data set and build a dictionary of entity relationship category mapping IDs;

[0021] S1.6: Pad or truncate the sentences according to the set length, and divide the processed dataset into training set, validation set, and test set.

[0022] The S2 specifically includes the following steps:

[0023] S2.1: The encoding layer uses embedded representation to represent the features of each word in the sentence at three different granularities: character level, word level, and part of speech. By splicing, a composite feature representation is formed to obtain the initialization code X of the sentence;

[0024] S2.2: The entity recognition layer inputs the initial code X of the sentence into the Bi-LSTM neural network, uses the Bi-LSTM neural network to achieve deep extraction of sentence features, outputs the hidden state h corresponding to each word, and combines with the CRF layer to complete the prediction of the entity label sequence. By parsing the entity label sequence, the entity extracted from the sentence is obtained;

[0025] S2.3: The relation extraction layer pairs the extracted entities and uses the sentence encoding module based on the entity pair attention mechanism to generate sentence representations S under the entity pair attention mechanism, and then fuses the information of the entity pair to obtain the enhanced sentence representation S * , input into the feedforward neural network to extract the relationship between entities.

[0026] The S2.1 specifically includes the following steps:

[0027] S2.1.1: Use embedded representation to represent the words and parts of speech in each sentence into vectors x w and x pos ;

[0028] S2.1.2: For each word in a sentence, use a convolutional neural network to obtain the character-level vector representation x corresponding to the word c ;

[0029] S2.1.3: The obtained x w 、x pos and x c Concatenate to get the composite feature representation of each word Represents vector concatenation, and obtains the initial encoding of the sentence X = [x 1 ,x 2 ,…,x n ].

[0030] The S2.2 specifically includes the following steps:

[0031] S2.2.1: For each sentence, the initial encoding of the sentence is X = [x 1 ,x 2 ,…,x n ] is input into the Bi-LSTM neural network and the hidden state corresponding to each word is output represents vector concatenation, and the complete hidden state sequence is recorded as H = [h 1 ,h 2 ,…,h n ];

[0032] S2.2.2: Input the complete hidden state sequence H into the fully connected layer and output a set of vector representations h with the same length as the entity category. s ;

[0033] S2.2.3: Connect the vector representation output by S2.2.2 to the CRF layer, use the CRF layer to perform structured prediction of entity labels, and obtain a set of globally optimal label sequences y s ;

[0034] S2.2.4: Through the global optimal label sequence y s Parse the entities in the sentence and complete entity recognition.

[0035] The S2.3 specifically includes the following steps:

[0036] S2.3.1: Pair the extracted entities and set the hidden states h corresponding to the paired entities i Perform splicing and filling to obtain entity e 1 and entity e 2 The initial representation of and Among them, a and b represent the components of entity e 1 and entity e 2 The word corresponds to the starting position of the hidden state, and p and q represent the entities e 1 and entity e 2 The number of words, m represents the length of the word after entity filling, Represents vector concatenation;

[0037] S2.3.2: e 1 and e 2 The fully connected layer is introduced to output the embedded representation of the paired entities. and Splicing and Get the embedded representation u of the entity pair ep ;

[0038] S2.3.3: The hidden state h corresponding to each word obtained in S2.2.1 i The embedded representation u ep , as the basis for the calculation of the entity attention mechanism, according to the formula α i =Attention(h i ,u ep ),i∈[1,n] calculates the entity pair attention weight α=[α 1 ,α 2 ,…,α n ];

[0039] S2.3.4: The hidden state h corresponding to each word obtained according to S2.2.1 i and entity pair attention weight α i ,i∈[1,n], according to the formula Calculate the sentence’s embedded representation S, and then compare S with the entity’s embedded representation u ep Fusion enhances the sentence embedded representation S * ;

[0040] S2.3.5: The obtained enhanced sentence embedded representation S * Input the feedforward neural network to predict the relationship between paired entities, thereby completing the extraction of the relationship.

[0041] The entity pair attention mechanism formula α i =Attention(h i ,u ep ),i∈[1,n] are as follows:

[0042] Calculate the importance w of the entity to the i-th word in the sentence under attention i , as shown in formula (1):

[0043] w i =V T tanh(W h h i +W u u ep ) (1)

[0044] Among them, W h , W u and V represents the weight matrix parameters, V T Represents the transpose of V.

[0045] The importance of each word in the sentence is calculated by softmax w = [w 1 ,w 2 ,…,w n ] to perform normalization operation and obtain the entity pair attention weight α corresponding to the sentence = [α1 ,α 2 ,…,α n ], where the attention weight α of the i-th word i The calculation is shown in formula (2):

[0046]

[0047] The S3 specifically includes the following steps:

[0048] S3.1: Based on the entities extracted in S2.2 and the actual labels of the entities, the loss function of entity recognition is set to the negative log-likelihood function form L ner =-Σ s∈S log(P(y s |h s ;θ)), where h s represents the vector representation obtained from S2.2.2 with the same length as the entity category, y s represents the globally optimal label sequence obtained from S2.2.3 through the CRF layer, and θ represents the parameters involved in the CRF layer;

[0049] S3.2: According to the relationship y between entities extracted in S2.3 j , combined with the true labels of the relationship between entities, the negative log-likelihood loss function is used to calculate the loss value of relationship extraction, denoted as Where P represents y j and equal probability;

[0050] S3.3: Calculate the total loss value L = L using the joint loss function ner +L rel ;

[0051] S3.4: Use the test set to test the entity relationship joint extraction model based on the entity pair attention mechanism, record the model's accuracy, recall rate and F1 value as evaluation indicators for detecting the model effect, and save them;

[0052] S3.5: Repeat the test on the entity relationship joint extraction model based on the entity pair attention mechanism by modifying the hyperparameters, and save the hyperparameter with the highest F1 value in the test result as the final hyperparameter of the model; the hyperparameters include the learning rate and the number of iterations;

[0053] S3.6: Analyze the results of the entity relationship joint extraction model based on the entity pair attention mechanism, and verify the effectiveness of the model through the set F1 value.

[0054] Beneficial technical effects

[0055] 1. The present invention proposes a joint entity relationship extraction method based on entity pair attention mechanism, which realizes the extraction of entities and inter-entity relationships in unstructured text by effectively utilizing valuable information in the text.

[0056] 2. The present invention adopts an entity relationship joint extraction model based on the entity pair attention mechanism, which can effectively solve the problem of entity redundancy, speed up the model training speed, improve the model training efficiency, and enhance the interaction between the two tasks by combining the entity loss function and the entity relationship loss function.

[0057] 3. The sentence encoding module based on the entity pair attention mechanism adopted by the present invention can generate different sentence representations for different entity pairs, thus effectively solving the triple overlap problem. BRIEF DESCRIPTION OF THE DRAWINGS

[0058] Figure 1 A flow chart of a method for joint extraction of entity relations based on an entity pair attention mechanism provided in an embodiment of the present invention.

[0059] Figure 2 A specific example diagram of the entity relationship joint extraction method based on the entity pair attention mechanism provided in an embodiment of the present invention.

[0060] Figure 3 A framework diagram of an entity relationship joint extraction model based on an entity pair attention mechanism provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0061] The specific implementation of the present invention is further described in detail below with reference to the accompanying drawings and embodiments. This embodiment provides an entity relationship joint extraction method based on an entity pair attention mechanism, which effectively extracts entities and entity relationships from unstructured text by constructing an entity relationship joint extraction model based on an entity pair attention mechanism. Figure 1 As shown, the following steps are included:

[0062] S1: Sentence segmentation, deduplication, word segmentation, dictionary construction, and entity and entity relationship acquisition;

[0063] In this embodiment, the NYT dataset and the WebNLG dataset are obtained by sentence segmentation and deduplication of the dataset; the NYT dataset contains 56195 training data, 5000 verification data, and 5000 test data; the WebNLG dataset contains 5019 training data, 500 verification data, and 703 test data; the dataset is further processed to construct a dictionary of word mapping IDs, a dictionary of part-of-speech mapping IDs, and a dictionary of character mapping IDs; and entity category information and inter-entity relationship category information are obtained, including the following steps:

[0064] S1.1: Sentence the dataset, delete duplicate sentences, use the word segmentation tool in NLTK (Natural Language Toolkit, Natural Language Processing Toolkit) to process the sentences, obtain the target word segmentation, and build a dictionary of word mapping IDs;

[0065] S1.2: For the sentences in the dataset that have been processed by word segmentation, use the part-of-speech tagging tool in NLTK to complete the part-of-speech tagging of the sentences and build a dictionary of part-of-speech mapping IDs;

[0066] S1.3: For each word in the sentence, build a dictionary of character mapping IDs;

[0067] S1.4: Count the entity categories that appear in the data set, and build a dictionary of entity category label mapping IDs based on the "BIESO" annotation method;

[0068] S1.5: Count the entity relationship categories that appear in the data set and build a dictionary of entity relationship category mapping IDs;

[0069] S1.6: Pad or truncate the sentences according to the set length, and divide the processed dataset into training set, validation set, and test set.

[0070] The entity category label is represented by the "BIESO" annotation method combined with the entity category method, and can also represent the position of the word in the entity, such as B-PER, I-PER, E-PER, S-PER, etc.; for multi-word entities: "B": begin, indicating the starting position of the entity, "I": inside, indicating the middle position of the entity, "E": end, indicating the end position of the entity; for single-word entities: "S": single, indicating that the entity consists of only one word; "O": other, indicating that the word is not an entity; "X": unknown, indicating the word used to fill the part of the sentence that is less than the maximum length of the sentence.

[0071] In this embodiment, the datasets used are the NYT dataset and the WebNLG dataset, which are classic public datasets for entity-relationship joint extraction; the NYT dataset is generated by remote supervision and has certain noise; the WebNLG dataset was originally created for natural language processing tasks. The statistics of the two are shown in Table 1:

[0072] Table 1 Information statistics of the data set

[0073] Dataset Relationship Type Number of sentences in the training set Number of sentences in the validation set Number of sentences in the test set NYT 24 56195 5000 5000 WebNLG 246 5019 500 703

[0074] S2: Construct an entity relationship joint extraction model based on entity pair attention mechanism, such as Figure 2As shown, the entity relationship joint extraction model includes: an encoding layer for obtaining the initial encoding of the sentence, an entity recognition layer for extracting entities from the sentence, and a relationship extraction layer for extracting the relationship between entities, including the following steps:

[0075] S2.1: The encoding layer uses embedded representation to represent the features of each word in the sentence at three different granularities: character level, word level, and part of speech. By splicing, a composite feature representation is formed to obtain the initial encoding of the sentence.

[0076] In this embodiment, the encoding layer combines the features of three different granularities, namely, character level, word level and part of speech of each word, and performs feature fusion on each sentence to obtain the initial encoding X of the sentence, including the following steps:

[0077] S2.1.1: Use embedded representation to represent the words and parts of speech in each sentence into vectors x w and x pos ;

[0078] S2.1.2: For each word in a sentence, use a convolutional neural network to obtain the character-level vector representation x corresponding to the word c ;

[0079] S2.1.3: The obtained x w 、x pos and x c Concatenate to get the composite feature representation of each word Represents vector concatenation, and obtains the initial encoding of the sentence X = [x 1 ,x 2 ,…,x n ].

[0080] S2.2: The entity recognition layer uses the Bi-LSTM neural network to deeply extract sentence features and combines it with the CRF layer to complete entity extraction;

[0081] In this embodiment, the initial code X of the sentence is input into the Bi-LSTM neural network, and the Bi-LSTM neural network is used to realize the deep extraction of sentence features, output the hidden state h corresponding to each word, and complete the prediction of the entity label sequence in combination with the CRF layer. The entity extracted from the sentence is obtained by parsing the entity label sequence, including the following steps:

[0082] S2.2.1: For each sentence, the initial code X = [x 1 ,x 2 ,…,x n ] is input into the Bi-LSTM neural network and the hidden state corresponding to each word is output represents vector concatenation, and the complete hidden state sequence is recorded as H = [h1 ,h 2 ,…,h n ];

[0083] S2.2.2: Input the complete hidden state sequence H into the fully connected layer and output a set of vector representations h with the same length as the entity category. s ;

[0084] S2.2.3: Connect the vector representation output by S2.2.2 to the CRF layer, use the CRF layer to perform structured prediction of entity labels, and obtain a set of globally optimal label sequences y s ;

[0085] S2.2.4: Through the global optimal label sequence y s Parse out the entities in the sentence and complete entity recognition, such as Figure 3 shown.

[0086] S2.3: The relation extraction layer pairs the extracted entities and uses the sentence encoding module based on the entity pair attention mechanism to generate sentence representations S under the entity pair attention mechanism, and then fuses the information of the entity pair to obtain the enhanced sentence representation S * , input feedforward neural network to extract the relationship between entities;

[0087] In this embodiment, the extracted entities are paired as the calculation basis of the sentence encoding module based on the entity pair attention mechanism, and the sentence representation S under the entity pair attention mechanism is generated respectively. Then, the information of the entity pair is integrated to obtain the enhanced sentence representation S * , input into the feedforward neural network to extract the relationship between entities, including the following steps:

[0088] S2.3.1: Pair the extracted entities and set the hidden states h corresponding to the paired entities i Perform splicing and filling to obtain entity e 1 and entity e 2 The initial representation of and Among them, a and b represent the components of entity e 1 and entity e 2 The word corresponds to the starting position of the hidden state, and p and q represent the entities e 1 and entity e 2 The number of words, m represents the length of the word after entity filling, Represents vector concatenation;

[0089] S2.3.2: e 1 and e 2 The embedded representation of the paired entities is introduced into the fully connected layer respectively and Splicing and Get the embedded representation u of the entity pair ep ;

[0090] S2.3.3: The hidden state h corresponding to each word obtained in S2.2.1 i The embedded representation u ep , as the basis for the calculation of the entity attention mechanism, according to the formula α i =Attention(h i ,u ep ),i∈[1,n] calculates the entity pair attention weight α=[α 1 ,α 2 ,…,α n ];

[0091] S2.3.4: The hidden state h corresponding to each word obtained according to S2.2.1 i and entity pair attention weight α i ,i∈[1,n], according to the formula Calculate the sentence’s embedded representation S, and then compare S with the entity’s embedded representation u ep Fusion enhances the sentence embedded representation S * ;

[0092] S2.3.5: The obtained enhanced sentence embedding representation S * Input the feedforward neural network to predict the relationship between paired entities, thereby completing the extraction of relationships, such as Figure 3 shown.

[0093] The entity pair attention mechanism formula α i =Attention(h i ,u ep ),i∈[1,n] are as follows:

[0094] Calculate the importance w of the entity to the i-th word in the sentence under attention i , as shown in formula (1):

[0095] w i =V T tanh(W h h i +W u u ep ) (1)

[0096] Among them, W h , W u and V represents the weight matrix parameters, V T Represents the transpose of V.

[0097] The importance of each word in the sentence is calculated by softmax w = [w 1 ,w 2 ,…,w n ] to perform normalization operation and obtain the entity pair attention weight α corresponding to the sentence = [α 1 ,α 2 ,…,α n ], where the attention weight α of the i-th word i The calculation is shown in formula (2):

[0098]

[0099] S3: According to the entities extracted in S2.2 and the entity relations extracted in S2.3, the loss functions of entity recognition and relationship extraction are set by combining the real labels of the entities and the real labels of the entity relations respectively; the loss function of entity recognition and the loss function of relationship extraction are combined to complete the training and testing of the entity-relationship joint extraction model based on the entity pair attention mechanism, and the model is updated according to the test results;

[0100] In this embodiment, according to the entities extracted in S2.2, combined with the real labels of the entities in the NYT dataset and the WebNLG dataset, the loss function of entity recognition is set; according to the entity relations extracted in S2.3, combined with the real labels of the entity relations in the NYT dataset and the WebNLG dataset, the loss function of relationship extraction is set; the loss function of entity recognition and the loss function of relationship extraction are combined to complete the training and testing of the entity relationship joint extraction model based on the entity pair attention mechanism, and the model is updated according to the test results, including the following steps:

[0101] S3.1: Based on the entities extracted in S2.2 and the actual labels of the entities, the loss function of entity recognition is set to the negative log-likelihood function form L ner =-∑ s∈S log(P(y s |h s ;θ)), where h s represents the vector representation obtained in S2.2.2 with the same length as the entity category, y s represents the globally optimal label sequence obtained by the CRF layer in S2.2.3, and θ represents the parameters involved in the CRF layer;

[0102] S3.2: According to the relationship y between entities extracted in S2.3 j , combined with the true labels of the relationship between entities, the negative log-likelihood loss function is used to calculate the loss value of relationship extraction, denoted as Where P represents y j and equal probability;

[0103] S3.3: Calculate the total loss value L = L using the joint loss function ner +L rel ;

[0104] S3.4: Use the test set to test the entity relationship joint extraction model based on the entity pair attention mechanism, record the model's accuracy, recall rate and F1 value as evaluation indicators for detecting the model effect, and save them. The results are shown in Table 2;

[0105] Table 2 Entity relationship joint extraction results

[0106]

[0107] S3.5: Repeat the test on the entity relationship joint extraction model based on the entity pair attention mechanism by modifying the hyperparameters, and save the hyperparameter with the highest F1 value in the test result as the final hyperparameter of the model; the hyperparameters include the learning rate and the number of iterations;

[0108] S3.6: Analyze the results of the entity relationship joint extraction model based on the entity pair attention mechanism, and verify the effectiveness of the model through the set F1 value.

Claims

1. A method for joint extraction of entity relations based on entity pair attention mechanism, characterized by: Sentence, remove duplicates, segment words, build dictionaries, and obtain entities and relationships between entities. Constructing an entity-relationship joint extraction model based on entity pair attention mechanism, the entity-relationship joint extraction model includes: an encoding layer for obtaining an initial encoding of a sentence, an entity recognition layer for extracting entities from a sentence, and a relationship extraction layer for extracting relationships between entities; Set the loss function for entity recognition and relationship extraction, combine the loss function for entity recognition and the loss function for relationship extraction, complete the training and testing of the entity-relationship joint extraction model, and update the entity-relationship joint extraction model according to the test results; The construction of the entity relationship joint extraction model based on the entity pair attention mechanism specifically includes the following steps: S2.1: The encoding layer uses embedded representation to represent the features of each word in the sentence at three different granularities: character level, word level, and part of speech. By splicing, a composite feature representation is formed to obtain the initial encoding X of the sentence; S2.2: The entity recognition layer inputs the initial code X of the sentence into the Bi-LSTM neural network, uses the Bi-LSTM neural network to achieve deep extraction of sentence features, outputs the hidden state h corresponding to each word, and combines with the CRF layer to complete the prediction of the entity label sequence. By parsing the entity label sequence, the entity extracted from the sentence is obtained; S2.3: The relation extraction layer pairs the extracted entities and uses the sentence encoding module based on the entity pair attention mechanism to generate sentence representations S under the entity pair attention mechanism, and then fuses the information of the entity pair to obtain the enhanced sentence representation S * , input feedforward neural network to extract the relationship between entities; The S2.1 specifically includes the following steps: S2.1.1: Use embedded representation to represent the words and parts of speech in each sentence into vectors x w and x pos ; S2.1.2: For each word in a sentence, use a convolutional neural network to obtain the character-level vector representation x corresponding to the word c ; S2.1.3: The obtained x w 、x pos and x c Concatenate to get the composite feature representation of each word Represents vector concatenation, and obtains the initial encoding of the sentence X = [x1, x2, ..., x n ]; The S2.2 specifically includes the following steps: S2.2.1: For each sentence, the initial encoding of the sentence is X = [x1, x2, ..., x n ] is input into the Bi-LSTM neural network and the hidden state corresponding to each word is output represents vector concatenation, and the complete hidden state sequence is recorded as H = [h1,h2,…,h n ]; S2.2.2: Input the complete hidden state sequence H into the fully connected layer and output a set of vector representations h with the same length as the entity category. s ; S2.2.3: Connect the vector representation output by S2.2.2 to the CRF layer, use the CRF layer to perform structured prediction of entity labels, and obtain a set of globally optimal label sequences y s ; S2.2.4: Through the global optimal label sequence y s Parse the entities in the sentence and complete entity recognition; The S2.3 specifically includes the following steps: S2.3.1: Pair the extracted entities and set the hidden states h corresponding to the paired entities i Perform concatenation and filling to obtain the initial representation of entity e1 and entity e2 and Among them, a and b represent the starting positions of the hidden states of the words that constitute entity e1 and entity e2, respectively; p and q represent the number of words that constitute entity e1 and entity e2, respectively; and m represents the word length after entity filling. Represents vector concatenation; S2.3.2: Introduce e1 and e2 into the fully connected layer to output the embedded representation of the paired entity and Splicing and Get the embedded representation u of the entity pair ep ; S2.3.3: The hidden state h corresponding to each word obtained in S2.2.1 i The embedded representation u ep , as the basis for the calculation of the entity attention mechanism, according to the formula α i =Attention(h i ,u ep ),i∈[1,n] calculates the entity pair attention weight α=[α1,α2,…,α n ]; S2.3.4: The hidden state h corresponding to each word obtained according to S2.2.1 i and entity pair attention weight α i ,i∈[1,n], according to the formula Calculate the sentence’s embedded representation S, and then compare S with the entity’s embedded representation u ep Fusion enhances the sentence embedded representation S * ; S2.3.5: The obtained enhanced sentence embedded representation S * Input the feedforward neural network to predict the relationship between paired entities, thereby completing the extraction of the relationship; The entity pair attention mechanism formula α i =Attention(h i ,u ep ),i∈[1,n] is specifically: Calculate the importance w of the entity to the i-th word in the sentence under attention i , as shown in formula (1): w i =V T tanh(W h h i +W u u ep ) (1) Among them, W h , W u and V represents the weight matrix parameters, V T represents the transpose of V; The importance of each word in the sentence is calculated by softmax w=[w1,w2,…,w n ] to perform normalization operation and obtain the entity pair attention weights α=[α1,α2,…,α n ], where the attention weight α of the i-th word i The calculation is shown in formula (2): The updating of the entity relationship joint extraction model specifically includes the following steps: S3.1: Based on the entities extracted in S2.2 and the actual labels of the entities, the loss function of entity recognition is set to the negative log-likelihood function form L ner =-∑ s∈S log(P(y s |h s ;θ)), where h s represents the vector representation obtained in S2.2.2 with the same length as the entity category, y s represents the globally optimal label sequence obtained by the CRF layer in S2.2.3, and θ represents the parameters involved in the CRF layer; S3.2: According to the relationship y between entities extracted in S2.3 j , combined with the true labels of the relationship between entities, the negative log-likelihood loss function is used to calculate the loss value of relationship extraction, denoted as Where P represents y j and equal probability; S3.3: Calculate the total loss value L = L using the joint loss function ner +L rel ; S3.4: Use the test set to test the entity relationship joint extraction model based on the entity pair attention mechanism, record the model's accuracy, recall rate and F1 value as evaluation indicators for detecting the model effect, and save them; S3.5: Repeat the test on the entity relationship joint extraction model based on the entity pair attention mechanism by modifying the hyperparameters, and save the hyperparameter with the highest F1 value in the test result as the final hyperparameter of the model; the hyperparameters include the learning rate and the number of iterations; S3.6: Analyze the results of the entity relationship joint extraction model based on the entity pair attention mechanism, and verify the effectiveness of the model through the set F1 value.

2. The entity relationship joint extraction method based on entity pair attention mechanism according to claim 1 is characterized by: The data set is segmented into sentences, deduplicated, word segmented, and a dictionary is constructed to obtain entities and relationships between entities, specifically including the following steps: S1.1: Sentence the data set, delete duplicate sentences, use the word segmentation tool in NLTK to process the sentences, obtain the target word segmentation, and build a dictionary of word mapping IDs; S1.2: For the sentences in the dataset that have been processed by word segmentation, use the part-of-speech tagging tool in NLTK to complete the part-of-speech tagging of the sentences and build a dictionary of part-of-speech mapping IDs; S1.3: For each word in the sentence, build a dictionary of character mapping IDs; S1.4: Count the entity categories that appear in the data set, and build a dictionary of entity category label mapping IDs based on the "BIESO" annotation method; S1.5: Count the entity relationship categories that appear in the data set and build a dictionary of entity relationship category mapping IDs; S1.6: Pad or truncate the sentences according to the set length, and divide the processed dataset into training set, validation set, and test set.