Relation extraction method and device based on two-layer convolutional neural network
By screening entity pairs and optimizing relationship type prediction through a two-layer convolutional neural network, it solves the problem of the inability of pre-trained models to reflect vocabulary ambiguity and waste of resources, and improves the effect and efficiency of relationship extraction.
Patent Information
- Application Number
- CN202110864354.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-29
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2041-07-29
Smart Images

Figure CN113627192B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of relationship extraction, word vectors, context features, convolutional neural networks, and more specifically to a relationship extraction method and device based on a two-layer convolutional neural network. Background Art
[0002] A relation is a triple that describes the semantic connection between entity pairs. Its form is (e1, r, e2), where e1 and e2 are entities and r is the semantic connection between entities. Relationships exist in large numbers in natural texts. For example, the sentence "President B of Country A came to Country C" contains the relations (Country A, President, B) and (A, came to Country C). Relationship extraction is an important research topic in the field of information extraction. It can establish connections between different entities, transform unstructured text into structured or semi-structured knowledge, and form a relational network composed of knowledge, which is used for intelligent services such as intelligent question answering, semantic search, and community discovery.
[0003] At present, there are four commonly used methods for relation extraction: rule template method, dependency analysis method, machine learning method and deep learning method. Among them, the first two methods are traditional methods, whose core is template matching and grammatical analysis, with limited processing rules, lack of scalability and universality, and are suitable for closed domain relation extraction. The machine learning method regards the relation extraction task as a multi-classification problem and makes predictions through training models. This method has self-learning ability and can break through the constraints of the limited processing rules of the first two methods, and is suitable for relation extraction in different scenarios; however, the features used in the training model are mostly the linguistic features of the entity itself, lacking the features of the context environment, and cannot represent the polysemous relationship of the entity in different contexts; in addition, the features are designed according to the actual application, which is very technical and has no fixed rules to follow. The deep learning method uses the vectorization (word embedding, part-of-speech embedding, etc.) results of the sentence where the entity is located as a feature, and predicts by training a deep network model that can accurately describe the nonlinear features between data. It uses transfer learning to adjust the model parameters, can flexibly match the application scenario, has good scalability and universality, and is suitable for open domain relationship extraction; the features used in this method are ordered sequences of individual word vectorization results, which can be directly generated by various vectorization models, without the need for special design based on actual applications, reducing the complexity of feature design. However, the feature vectors used in the deep learning training model usually come from pre-trained models, and their values have been solidified and cannot reflect the ambiguity of words in different contexts; the deep network structure is complex and has many parameters, and the cost of relationship prediction is very high. If the relationship between entities does not exist, then using this method for prediction will result in a huge waste of resources. In addition, deep learning is in the process of continuous development and improvement, and it is necessary to learn from the optimization strategies in this field to improve the effect of relationship extraction.
[0004] Therefore, it is necessary to solve the following problems existing in the current relationship extraction process: the use of pre-trained models to construct deep learning feature vectors cannot reflect the ambiguity of words in different contexts, processing samples where entity relationships themselves do not exist will seriously waste resources, and the optimization strategies in the field of deep learning are not fully borrowed. Summary of the invention
[0005] The technical task of the present invention is to provide a relationship extraction method and device based on a two-layer convolutional neural network, which is used to solve the problems existing in the current relationship extraction process that the use of pre-trained models to construct deep learning feature vectors cannot reflect the ambiguity of words in different contexts, processing samples where entity relationships themselves do not exist will seriously waste resources, and the optimization strategies in the field of deep learning are not fully borrowed.
[0006] The technical task of the present invention is achieved in the following way: a relationship extraction method based on a two-layer convolutional neural network, the specific steps of the method are as follows:
[0007] S1: Generate sentence feature vector based on entity boundaries;
[0008] S2: Training a relationship existence determination model based on a convolutional neural network;
[0009] S3: Use the relationship existence determination model to filter entity pairs and sentences that may have relationships;
[0010] S4: Generate sentence feature vector based on ELMO network;
[0011] S5: Generate relationship type vector;
[0012] S6: Training a convolutional neural network-based relation classification model;
[0013] S7: Use the relation classification model to predict the relation type of entity pairs.
[0014] Preferably, generating a sentence feature vector based on entity boundaries in step S1 refers to adding boundary symbols at both ends of the entity, statically vectorizing the sentence vocabulary containing the boundary symbols, and then splicing the vocabulary static word embeddings in order to form a sentence feature vector based on entity boundaries; specifically as follows:
[0015] S11: Add boundary symbols at both ends of the entity; specifically: in sentence S, W Start and W End Indicates the start and end of the word, E A and E B Represent any two entities, in E A and E B Add boundary symbols at both ends <e A >、<\e A >、 <eB >、<\e B >, forming a new sentence S Bord ;
[0016] S12: Generate lexical static word embeddings including boundary symbols;
[0017] S13: Concatenate static word embeddings according to the lexical order of the sentence;
[0018] S14: Returns a static word embedding sequence;
[0019] The training of the convolutional neural network-based relationship existence determination model in step S2 is to input the sentence feature vector based on the entity boundary and the relationship existence identifier into the convolutional neural network, and obtain the relationship existence determination model through training; specifically as follows:
[0020] S21: Generate entity pair relationship existence identification: Use R Ext (E A ,E B ) represents entity E A and E B Is there a relationship between:
[0021] ①: If there is a relationship between the two, then R Ext (E A ,E B )=1;
[0022] ②: If there is no relationship between the two, then R Ext (E A ,E B )=0;
[0023] S22: Set the hyperparameters of the first layer of convolutional neural network: set the structural parameters of the input layer module, convolution layer module, pooling layer module, fully connected layer module and output layer module;
[0024] S23: Initialize the parameters of the first layer of convolutional neural network: initialize the weight matrix and bias vector of different modules;
[0025] S24: Send the sentence feature vector based on entity boundaries to the input layer of the first convolutional neural network;
[0026] S25: Send the entity pair relationship existence mark to the output layer of the first convolutional neural network;
[0027] S26: training the first layer of convolutional neural network model according to the convergence condition;
[0028] S27: Returns the parameters of the first layer of the convolutional neural network.
[0029] Preferably, the relationship existence determination model in step S3 is used to process each entity pair (E A ,E B ), determine entity E A and E B Whether there is a relationship; as follows:
[0030] S31: Read entity pairs (E A ,E B ), where E A and E B Represents any two entities in sentence S;
[0031] S32: Generate entity pairs (E A ,E B )The corresponding sentence feature vector based on entity boundaries;
[0032] S33: sending the sentence feature vector based on entity boundaries to the input end of the relation existence determination model;
[0033] S34: Obtain the determination result R from the output end of the relationship existence determination model Ext (E A ,E B ), where R Ext (E A ,E B ) means E A and E B The result of the existence determination of the relationship between the two entities;
[0034] S35: Judge R Ext (E A ,E B ) and 0.5:
[0035] ①: If R Ext (E A ,E B )>0.5, then execute step S36;
[0036] ②: If R Ext (E A ,E B )≤0.5, jump to step S37;
[0037] S36: Marking entity E A and E B In sentence S there is a relation;
[0038] S37: Determine whether there are any unread entity pairs in sentence S (E A ,E B ):
[0039] ①: If yes, jump to step S31;
[0040] ②: If not, execute step S38;
[0041] S38: Return the entity pair (E A ,E B ).
[0042] Preferably, the generating of the sentence feature vector based on the ELMO network in step S4 specifically refers to generating the sentence S through the ELMO network. Bord The dynamic word embedding of each word in is concatenated after the static word embedding generated in step S1 to form the word embedding of each word, and then concatenated according to the order of the words in the sentence to form a sentence feature vector based on the ELMO network; specifically as follows:
[0043] S41: Read sentence S Bord The static word embedding sequence of S Bord Indicates that in E A and E B The new sentence generated by adding boundary symbols at both ends, E A and E B Entities representing relations in sentence S;
[0044] S42: Generate sentence S Bord Dynamic word embedding sequence: sentence S Bord The static word embedding sequence is fed into the input layer of the ELMO network, and the sentence S is obtained from the output layer. Bord The dynamic word embedding sequence has the same sequence length as the static word embedding sequence; specifically, as follows:
[0045] S421: Send the static word embedding sequence to the input layer of the ELMO network;
[0046] S422: Obtain the operation result of the ELMO network output layer;
[0047] S423: Obtaining dynamic word embedding of vocabulary according to the operation result;
[0048] S424: Concatenate dynamic word embeddings according to the lexical order of the sentence;
[0049] S425: Return the dynamic word embedding sequence;
[0050] S43: Generate sentence S Bord Word embedding sequence: Let sentence S Bord The number of words is n, and the static word embedding sequence is StaEmdSeq S =[e s1 ,e s2,…,e si ,…,e sn ], the dynamic word embedding sequence is DymEmdSeq S =[e d1 ,e d2 ,…,e di ,…,e dn ]; where e si and e di Represent the static word embedding and dynamic word embedding of the i-th word respectively; e si e di Represents the word embedding of the i-th word, and its corresponding operation is to transform e di Splice in e si Later, the sentence S Bord The word embedding sequence is EmdSeq S =[e s1 e d1 ,e s2 e d2 ,…,e sn e dn ];
[0051] S44: Return to S Bord word embedding sequence;
[0052] The generation of the relationship type vector in step S5 is specifically as follows:
[0053] One-Hot encoding is used to represent the relationship type between entities, that is, a vector RelVec with a length of T is used k Represents a relationship k , k∈[1,T]; where Rel k Represents entity E A and E B The relationship between k In the example, except for the kth bit which is 1, the rest of the bits are 0.
[0054] Preferably, the training of the relation classification model based on the convolutional neural network in step S6 specifically refers to setting the hyperparameters of the convolutional neural network, initializing the corresponding weight matrix and bias vector, and then sending the sentence feature vector and the relation type vector based on the ELMO network into the convolutional neural network, and training by optimizing the loss function to obtain the relation classification model; specifically as follows:
[0055] S61: Set the hyperparameters of the second layer of convolutional neural network: set the structural parameters of the input layer module, convolution layer module, pooling layer module, fully connected layer module and output layer module; the convolution layer module uses convolution kernels of different sizes; the pooling layer module uses pooling based on the attention mechanism; the details are as follows:
[0056] S611: Set input layer hyperparameters;
[0057] S612: Setting convolution kernels of different sizes;
[0058] S613: Set up pooling based on the attention mechanism: Assume that t convolution kernels of different sizes are used, and the size of the jth convolution kernel is L j , the convolution operation result R j is the length nL j +1 vector, corresponding to the attention weight A j is a vector of the same length, corresponding to the relationship type word embedding matrix W j The scale is (nL j +1)*T matrix, corresponding to the "element-relationship" correlation matrix G j are matrices of the same size, B j It's G j The column-normalized matrix of It is B j The g-th column vector of yes The mth element of ; specifically as follows:
[0059] S6131: Calculate the "element-relationship" correlation matrix G j =R j Trans *A j *W j , R j Trans YesR j The transpose of
[0060] S6132: Calculate G j The column normalized matrix B j :
[0061] S6133: R j and B j Maximum inner product of column vectors As a result of pooling;
[0062] S614: Set other hyper parameters;
[0063] S62: Initialize the parameters of the second layer of convolutional neural network: initialize the weight matrix and bias vector of different modules;
[0064] S63: Sending the sentence feature vector based on the ELMO network to the input layer of the second convolutional neural network;
[0065] S64: Send the relationship type vector to the output layer of the second convolutional neural network;
[0066] S65: Train the second layer of the convolutional neural network model according to the convergence condition: use the spacing loss function for training, which is defined as follows:
[0067] L margin =log(1+exp(ρ(d + -g + (S))))+log(1+exp(ρ(d - +g - (S))));
[0068] Among them, g + (S) indicates the correct classification score; g - (S) indicates the misclassification score; d + and d - Respectively represent the spacing thresholds of positive and negative samples; ρ represents the scaling factor;
[0069] S66: Returns the parameters of the second layer of the convolutional neural network.
[0070] Preferably, the use of the relation classification model to predict the relation type of the entity pair in step S7 refers to using the trained convolutional neural network to predict the relation type of the entity pair in the sentence to be processed, A' and E B' Represents any two entities in the sentence S' to be processed; specifically as follows:
[0071] S71: In entity E A' and E B' Add boundary symbols at both ends to get the new sentence S' Bord ;
[0072] S72: Generate S' Bord Entity boundary-based sentence feature vector;
[0073] S73: Generate S' Bord The sentence feature vector based on ELMO network;
[0074] S74: sending the sentence feature vector based on the ELMO network to the input layer of the second convolutional neural network;
[0075] S75: Run the second layer of convolutional neural network to obtain output layer information;
[0076] S76: Obtain the relationship type corresponding to the output end with the highest probability as entity E A' and E B' the relationship between;
[0077] S77: Determine whether there is an unread entity E in the sentence S' A' and E B':
[0078] ①: If yes, jump to step S71;
[0079] ②: If not, execute step S78;
[0080] S78: Return entity E A' and E B' The set of relations present in sentence S'.
[0081] A relationship extraction device based on a two-layer convolutional neural network, the device comprising:
[0082] A sentence feature vector generating component based on entity boundaries, used for generating a sentence feature vector based on entity boundaries;
[0083] A relationship existence determination model training component, used for training a relationship existence determination model based on a convolutional neural network;
[0084] The entity pairs and sentences generating component that may have a relationship is used to filter out the entity pairs and sentences that may have a relationship based on the relationship existence determination model;
[0085] A sentence feature vector generating component based on the ELMO network, used for generating a sentence feature vector based on the ELMO network;
[0086] A relation type vector generating component, used to generate a vector corresponding to the relation type;
[0087] A relation classification model training component, used to train a relation classification model based on a convolutional neural network;
[0088] The entity pair relationship type prediction component is used to predict the relationship type of entity pairs in a sentence based on the relationship classification model.
[0089] Preferably, the sentence feature vector generating component based on entity boundaries comprises:
[0090] An entity boundary symbol adding component is used to add boundary symbols at both ends of the entity in the sentence;
[0091] A static word embedding generation component is used to statically vectorize each word in a sentence containing boundary symbols;
[0092] The static word embedding concatenation component is used to concatenate the static word embedding of each word according to the order of the words in the sentence;
[0093] The relationship existence determination model training component includes:
[0094] An entity pair relationship existence identification generating component is used to generate an identification of whether a relationship between entity pairs exists;
[0095] The first layer hyperparameter setting component is used to set the structural parameters of different modules in the convolutional neural network for relationship existence determination;
[0096] The first layer parameter initialization component is used to initialize the parameters of different modules in the convolutional neural network for relationship existence determination;
[0097] The first layer input terminal setting component is used to send all sentence feature vectors based on entity boundaries to the input terminal of the convolutional neural network for relation existence determination;
[0098] The first layer output terminal setting component is used to send all entity pair relationship existence identifications to the output terminal of the convolutional neural network for relationship existence determination;
[0099] The first layer training convergence component is used to train the convolutional neural network for relationship existence judgment according to the convergence condition.
[0100] Preferably, the sentence feature vector generating component based on the ELMO network includes:
[0101] A static word embedding sequence reading component is used to read the static word embedding sequence of all words in the sentence;
[0102] A dynamic word embedding sequence generation component is used to generate dynamic word embedding sequences of all words in a sentence;
[0103] A word embedding sequence generation component is used to generate word embedding sequences for all words in a sentence;
[0104] The relationship classification model training component includes:
[0105] The second layer hyperparameter setting component is used to set the structural parameters of different modules in the convolutional neural network for relationship classification;
[0106] The second layer parameter initialization component is used to initialize the parameters of different modules in the convolutional neural network for relationship classification;
[0107] The second layer input terminal setting component is used to send all sentence feature vectors based on the ELMO network to the input terminal of the convolutional neural network for relation classification;
[0108] The second layer output terminal setting component is used to send all relationship type vectors to the output terminal of the convolutional neural network for relationship classification;
[0109] The second layer training convergence component is used to train the convolutional neural network for relational classification according to the convergence condition.
[0110] A computer-readable storage medium stores computer-executable instructions, which, when executed by the computer, implement the above-mentioned relationship extraction method based on a two-layer convolutional neural network.
[0111] The relationship extraction method and device based on a two-layer convolutional neural network of the present invention have the following advantages:
[0112] (i) The present invention uses the first layer of convolutional neural network to screen out entity pairs that cannot have a relationship, and then uses the second layer of convolutional neural network to predict the specific relationship type, which can reduce the calculation of relationship types of a large number of irrelevant entities, reduce costs, and improve effects;
[0113] (ii) The present invention adds boundary symbols to sentence entities and then performs static word embedding to obtain a sentence feature vector based on entity boundaries, which can describe the environmental features of the entity in the sentence as a whole, and send it to the first layer of convolutional neural network, and quickly determine whether there is a relationship between entities through a binary classification model; then obtain the dynamic word embedding of the sentence through the ELMO network, and splice it with the static word embedding of the sentence to obtain a sentence feature vector based on the ELMO network, which can describe both the overall features of the sentence and the individual features such as the polysemy of words in different contexts, as well as their relationship features with entity pairs, and send it to the second layer of convolutional neural network, which uses convolution kernels of different sizes, pooling based on the attention mechanism, and spacing loss function-based strategies for optimization, and accurately identifies the relationship type between entities through a multi-classification model; in addition, the static word embedding input to the first layer of convolutional neural network can generate input data for the second layer of convolutional neural network, and has good reusability;
[0114] (III) For all sentences containing entities, the present invention uses a convolutional neural network to process sentence feature vectors based on entity boundaries, and screens out entities that are unlikely to have relationships, thereby saving a large amount of relationship type calculation costs for irrelevant entities; for sentences containing entities that may have relationships, the present invention uses a convolutional neural network to process sentence feature vectors based on the ELMO network to determine the specific relationship type; through the refined processing of a two-layer convolutional neural network, limited resources are used for entity pairs that may have relationships and a relationship classification model with high accuracy, which can improve the effect of relationship extraction;
[0115] (IV) The two-layer convolutional neural network designed in the present invention meets the actual needs. Considering the speed, the first layer uses a conventional convolutional neural network to construct a binary classification model, which can quickly determine the existence of a relationship. Considering the accuracy, the second layer uses an optimized convolutional neural network to construct a multi-classification model, which can accurately determine the type of relationship. The static word embedding input into the first layer of the convolutional neural network is reusable and is used to generate input data for the second layer of the convolutional neural network. Compared with the conventional relationship extraction method, the present invention uses two layers of convolutional neural networks to ensure speed and accuracy respectively, which can balance these two contradictory performance indicators and improve the effect of relationship extraction. BRIEF DESCRIPTION OF THE DRAWINGS
[0116] The present invention is further described below in conjunction with the accompanying drawings.
[0117] Attached Figure 1 It is a flowchart of the relationship extraction method based on a two-layer convolutional neural network;
[0118] Attached Figure 2 Schematic diagram of a sentence with entity boundaries added;
[0119] Attached Figure 3 A flowchart of generating a sentence feature vector based on entity boundaries in step S1;
[0120] Attached Figure 4 A flowchart of training a convolutional neural network-based relationship existence determination model in step S2;
[0121] Attached Figure 5 A flowchart of using the relationship existence determination model in step S3 to screen entity pairs and sentences that may have a relationship;
[0122] Attached Figure 6 A flowchart of generating a sentence feature vector based on an ELMO network in step S4;
[0123] Attached Figure 7 The generated sentence S in step S42 Bord Flowchart of the dynamic word embedding sequence;
[0124] Attached Figure 8 A flowchart of training a convolutional neural network-based relation classification model in step S6;
[0125] Attached Fig. 9 A flowchart of setting the hyperparameters of the second layer of convolutional neural network in step S61;
[0126] Attached Fig.10 A flowchart of using a relation classification model to predict relation types of entity pairs in step S7;
[0127] Attached Fig.11A diagram of the structure of a two-layer convolutional neural network created for the present invention;
[0128] Attached Fig.12 This is a schematic diagram of generating dynamic word embedding through the ELMO network;
[0129] Attached Fig.13 It is a structural block diagram of a relationship extraction device based on a two-layer convolutional neural network. DETAILED DESCRIPTION
[0130] The relationship extraction method and device based on a two-layer convolutional neural network of the present invention are described in detail below with reference to the accompanying drawings and specific embodiments of the specification.
[0131] Embodiment 1:
[0132] As attached Figure 1 As shown, the relationship extraction method based on a two-layer convolutional neural network of the present invention has the following specific steps:
[0133] S1: Generate sentence feature vector based on entity boundaries;
[0134] S2: Training a relationship existence determination model based on a convolutional neural network;
[0135] S3: Use the relationship existence determination model to filter entity pairs and sentences that may have relationships;
[0136] S4: Generate sentence feature vector based on ELMO network;
[0137] S5: Generate relationship type vector;
[0138] S6: Training a convolutional neural network-based relation classification model;
[0139] S7: Use the relation classification model to predict the relation type of entity pairs.
[0140] In step S1 of this embodiment, generating a sentence feature vector based on entity boundaries refers to adding boundary symbols at both ends of the entity, statically vectorizing the vocabulary of the sentence containing the boundary symbols, and then splicing the vocabulary static word embeddings in order to form a sentence feature vector based on entity boundaries; as shown in the attached figure Figure 3 As shown, the details are as follows:
[0141] S11: Add boundary symbols at both ends of the entity; specifically: in sentence S, W Start and W End Indicates the start and end of the word, E A and E B Represent any two entities, in E A and E B Add boundary symbols at both ends <e A〉、<\e A >、 <e B 〉、<\e B >, forming a new sentence S Bord , as attached Figure 2 As shown;
[0142] S12: Generate lexical static word embeddings including boundary symbols;
[0143] S13: Concatenate static word embeddings according to the lexical order of the sentence;
[0144] S14: Returns a static word embedding sequence;
[0145] In step S2 of this embodiment, the training of the convolutional neural network-based relationship existence determination model is to input the sentence feature vector based on the entity boundary and the relationship existence identifier into the convolutional neural network, and obtain the relationship existence determination model through training; as shown in the attached figure Figure 4 As shown, the details are as follows:
[0146] S21: Generate entity pair relationship existence identification: Use R Ext (E A ,E B ) represents entity E A and E B Is there a relationship between:
[0147] ①: If there is a relationship between the two, then R Ext (E A ,E B )=1;
[0148] ②: If there is no relationship between the two, then R Ext (E A ,E B )=0;
[0149] S22: Set the hyperparameters of the first layer of convolutional neural network: set the structural parameters of the input layer module, convolution layer module, pooling layer module, fully connected layer module and output layer module;
[0150] S23: Initialize the parameters of the first layer of convolutional neural network: initialize the weight matrix and bias vector of different modules;
[0151] S24: Send the sentence feature vector based on entity boundaries to the input layer of the first convolutional neural network;
[0152] S25: Send the entity pair relationship existence mark to the output layer of the first convolutional neural network;
[0153] S26: training the first layer of convolutional neural network model according to the convergence condition;
[0154] S27: Returns the parameters of the first layer of the convolutional neural network.
[0155] In step S3 of this embodiment, using the relationship existence determination model to screen entity pairs and sentences that may have a relationship means using the relationship existence determination model to process each entity pair (E A ,E B ), determine entity E A and E B Is there a relationship? Figure 5 As shown, the details are as follows:
[0156] S31: Read entity pairs (E A ,E B ), where E A and E B Represents any two entities in sentence S;
[0157] S32: Generate entity pairs (E A ,E B )The corresponding sentence feature vector based on entity boundaries;
[0158] S33: sending the sentence feature vector based on entity boundaries to the input end of the relation existence determination model;
[0159] S34: Obtain the determination result R from the output end of the relationship existence determination model Ext (E A ,E B ), where R Ext (E A ,E B ) means E A and E B The result of the existence determination of the relationship between the two entities;
[0160] S35: Judge R Ext (E A ,E B ) and 0.5:
[0161] ①: If R Ext (E A ,E B )>0.5, then execute step S36;
[0162] ②: If R Ext (E A ,E B )≤0.5, jump to step S37;
[0163] S36: Marking entity E A and E B In sentence S there is a relation;
[0164] S37: Determine whether there are any unread entity pairs in sentence S (E A ,E B ):
[0165] ①: If yes, jump to step S31;
[0166] ②: If not, execute step S38;
[0167] S38: Return the entity pair (E A ,E B ).
[0168] In this embodiment, the generation of the sentence feature vector based on the ELMO network in step S4 specifically refers to generating the sentence S through the ELMO network. Bord The dynamic word embedding of each word in step S1 is concatenated after the static word embedding generated in step S1 to form the word embedding of each word, and then the words are concatenated in the order of the words in the sentence to form a sentence feature vector based on the ELMO network; as shown in the attached figure Figure 6 As shown, the details are as follows:
[0169] S41: Read sentence S Bord The static word embedding sequence of S Bord Indicates that in E A and E B The new sentence generated by adding boundary symbols at both ends, E A and E B Entities representing relations in sentence S;
[0170] S42: Generate sentence S Bord Dynamic word embedding sequence: sentence S Bord The static word embedding sequence is fed into the input layer of the ELMO network, and the sentence S is obtained from the output layer. Bord The dynamic word embedding sequence has the same sequence length as the static word embedding sequence; as shown in the attached Figure 7 As shown, the details are as follows:
[0171] S421: Send the static word embedding sequence to the input layer of the ELMO network;
[0172] S422: Obtain the operation result of the ELMO network output layer;
[0173] S423: Obtaining dynamic word embedding of vocabulary according to the operation result;
[0174] S424: Concatenate dynamic word embeddings according to the lexical order of the sentence;
[0175] S425: Return the dynamic word embedding sequence;
[0176] S43: Generate sentence S Bord Word embedding sequence: Let sentence S Bord The number of words is n, and the static word embedding sequence is StaEmdSeq S =[e s1 ,e s2 ,…,e si ,…,e sn ], the dynamic word embedding sequence is DymEmdSeq S =[e d1 ,e d2 ,…,e di ,…,e dn ]; where e si and e di Represent the static word embedding and dynamic word embedding of the i-th word respectively; e si e di Represents the word embedding of the i-th word, and its corresponding operation is to transform e di Splice in e si Later, the sentence S Bord The word embedding sequence is EmdSeq S =[e s1 e d1 ,e s2 e d2 ,…,e sn e dn ];
[0177] S44: Return to S Bord word embedding sequence;
[0178] The generation of the relationship type vector in step S5 in this embodiment is specifically as follows:
[0179] One-Hot encoding is used to represent the relationship type between entities, that is, a vector RelVec with a length of T is used k Represents a relationship k , k∈[1,T]; where Rel k Represents entity E A and E B The relationship between k In the example, except for the kth bit which is 1, the rest of the bits are 0.
[0180] In step S6 of this embodiment, the training of the relation classification model based on the convolutional neural network specifically refers to setting the hyperparameters of the convolutional neural network, initializing the corresponding weight matrix and bias vector, and then sending the sentence feature vector and the relation type vector based on the ELMO network into the convolutional neural network, and training by optimizing the loss function to obtain the relation classification model; as shown in the attached figure Figure 8 As shown, the details are as follows:
[0181] S61: Set the hyperparameters of the second layer of convolutional neural network: set the structural parameters of the input layer module, convolution layer module, pooling layer module, fully connected layer module and output layer module; among them, the convolution layer module uses convolution kernels of different sizes; the pooling layer module uses pooling based on the attention mechanism; as shown in the attached Fig. 9 As shown, the details are as follows:
[0182] S611: Set the hyper parameters of the input layer;
[0183] S612: Setting convolution kernels of different sizes;
[0184] S613: Set up pooling based on the attention mechanism: Assume that t convolution kernels of different sizes are used, and the size of the jth convolution kernel is L j , the convolution operation result R j is the length nL j +1 vector, corresponding to the attention weight A j is a vector of the same length, corresponding to the relationship type word embedding matrix W j The scale is (nL j +1)*T matrix, corresponding to the "element-relationship" correlation matrix G j are matrices of the same size, B j It's G j The column-normalized matrix of It is B j The g-th column vector of yes The mth element of ; specifically as follows:
[0185] S6131: Calculate the "element-relationship" correlation matrix YesR j The transpose of
[0186] S6132: Calculate G j The column normalized matrix B j :
[0187] S6133: R j and B j Maximum inner product of column vectors As a result of pooling;
[0188] S614: Set other hyper parameters;
[0189] S62: Initialize the parameters of the second layer of convolutional neural network: initialize the weight matrix and bias vector of different modules;
[0190] S63: Sending the sentence feature vector based on the ELMO network to the input layer of the second convolutional neural network;
[0191] S64: Send the relationship type vector to the output layer of the second convolutional neural network;
[0192] S65: Train the second layer of the convolutional neural network model according to the convergence condition: use the spacing loss function for training, which is defined as follows:
[0193] L margin =log(1+exp(ρ(d + -g + (S))))+log(1+exp(ρ(d - +g - (S))));
[0194] Among them, g + (S) indicates the correct classification score; g - (S) indicates the misclassification score; d + and d - Respectively represent the spacing thresholds of positive and negative samples; ρ represents the scaling factor;
[0195] S66: Returns the parameters of the second layer of the convolutional neural network.
[0196] In step S7 of this embodiment, using the relation classification model to predict the relation type of entity pairs refers to using the trained convolutional neural network to predict the relation type of entity pairs in the sentence to be processed. A' and E B' Represents any two entities in the sentence S' to be processed; Fig.10 As shown, the details are as follows:
[0197] S71: In entity E A' and E B' Add boundary symbols at both ends to get the new sentence S' Bord ;
[0198] S72: Generate S' Bord Entity boundary-based sentence feature vector;
[0199] S73: Generate S' Bord The sentence feature vector based on ELMO network;
[0200] S74: sending the sentence feature vector based on the ELMO network to the input layer of the second convolutional neural network;
[0201] S75: Run the second layer of convolutional neural network to obtain output layer information;
[0202] S76: Obtain the relationship type corresponding to the output end with the highest probability as entity E A' and E B' the relationship between;
[0203] S77: Determine whether there is an unread entity E in the sentence S' A' and E B' :
[0204] ①: If yes, jump to step S71;
[0205] ②: If not, execute step S78;
[0206] S78: Return entity E A' and E B' The set of relations present in sentence S'.
[0207] As attached Fig.11 As shown, the double-layer convolutional neural network created by the present invention is specifically as follows:
[0208] The bottom [e s1 ,e s2 ,…,e si ,…,e sn ] is a sentence feature vector based on entity boundaries. After feeding it into the first layer of convolutional neural network, we get entity E A and E B The result of the judgment whether there is a relationship R Ext (E A ,E B ); Above the first layer of the convolutional neural network is a control circuit consisting of a step function sgn(x), with a threshold of 0.5. The point ⊙ in the circle above the circuit represents the multiplication of a vector and a scalar; R Ext (E A ,E B ) is considered as x, if R Ext (E A ,E B )>0.5, then the output of the control circuit is 1, which is used to send the sentence feature vector based on entity boundaries into the ELMO network to perform subsequent relationship type calculations; if R Ext (E A ,E B )≤0.5, then the output of the control circuit is 0 and execution stops. The circle containing the symbol "C" on the right side of the ELMO network Represents vector concatenation, used to concatenate static word embeddings at the input of the ELMO network [e s1 ,e s2 ,…,e si ,…,e sn ] and the dynamic word embedding at the output [e d1 ,ed2 ,…,e di ,…,e dn ], and obtain the sentence feature vector [e s1 e d1 ,e s2 e d2 ,…,e sn e dn ]; After sending the feature vector into the second layer of convolutional neural network, the entity E can be obtained A and E B The type of relationship between them.
[0209] Embodiment 2:
[0210] The operations involved in this embodiment are all executed in the Python environment. LabeledRelSet is used to represent a data set with known relationships, and UnLabeledRelSet is used to represent a data set with unknown relationships. The LabeledRelSet is processed using the method of the present invention to obtain a relationship existence determination model and a relationship classification model, which are used to extract the relationships existing in UnLabeledRelSet.
[0211] In the dataset, each row represents a relationship between entity pairs in a sentence. If there are multiple relationships in a sentence, multiple rows are used to represent them. The format is as follows:
[0212] Entity 1 entity 2 relation sentence.
[0213] For example: Wang XX and Wu XX are teacher and student. Wang XX encourages Wu XX very much, hoping that he will pay equal attention to calligraphy and painting, and especially put more effort into calligraphy and painting.
[0214] The above example indicates that the relationship type between the entities "Wang XX" and "Wu XX" is "teacher-student".
[0215] There are 12 types of relationships in the dataset: superiors and subordinates, cooperation, friends, classmates, teachers and students, lovers, husband and wife, parents, brothers and sisters, grandparents and grandchildren, relatives, and others.
[0216] The data set only includes entities and relationships, lacking word segmentation information, so before using the method of the present invention, the data set needs to be preprocessed. First, spaces are removed, then stop words are eliminated according to the stop word list, and finally the jieba.cut function is used for word segmentation.
[0217] Execute S11: Add boundary symbols at both ends of the entity. Taking the above sentence as an example, the result after processing is " <e A >Wang XX<\e A >Yes <e B >Wu Moumou<\e B>He encouraged him and hoped that he would pay equal attention to calligraphy and painting, and put more effort into calligraphy and painting. "
[0218] Execute S12: Treat boundary symbols as words and use glove.Glove.word_vectors function to obtain static word embeddings for each word. The dimension of each word embedding is 100.
[0219] Execute S13: concatenate word embeddings according to lexical order to obtain a sentence feature vector based on entity boundaries.
[0220] Execute S22: First, create a keras.layers.Embedding object to define the input layer sequence. The maximum length of the sequence is 50 and the dimension of each element is 100.
[0221] Then, keras.layers.Conv1D is used to create the convolution kernel of the convolution layer (Size=2), and the number of convolution kernels is 32; keras.layers.MaxPooling1D is used to perform maximum pooling on the convolution kernel, and the pooling window size is 49.
[0222] Subsequently, keras.backend.concatenate is used to merge the output vectors of different pooling layers, keras.backend.flatten is used to flatten the merged output vector, and keras.backend.dropout is used to discard the components of the flattened result with a given probability (0.2). The dimension of the result is 32.
[0223] Finally, keras.layers.Dense is used to define the fully connected layer. The number of neurons in the input layer is 32, and the number of neurons in the output layer is 1, indicating whether there is a relationship between entities. The activation function is sigmoid.
[0224] Execute S23: Initialize the weight matrix and bias vector using the kernel_initializer and bias_initializer parameters of keras.layers.Conv1D and keras.layers.Dense.
[0225] Execute S24-S26: Use keras.models.Model to define and train the CNN model object RelExtCheck, and use the compile function of the object to compile the model. The main parameters are as follows:
[0226] Loss function: loss = 'binary_crossentropy', select the cross entropy suitable for binary classification;
[0227] Optimizer: optimizer = 'sgd', select stochastic gradient descent;
[0228] Evaluation indicators: metrics = ['binary_accuracy'], select an evaluation function suitable for binary classification.
[0229] Compile the CNN model object according to the above parameters as follows:
[0230] RelExtCheck.compile(loss='binary_crossentropy', optimizer='sgd', metrics=['binary_accuracy']);
[0231] BordFeatVecSet_Labeled and RelExtSet_Labeled are used to represent the sentence feature vector set based on entity boundaries and the entity pair relationship existence identifier set in LabeledRelSet, respectively. The fit function is used to train the model as follows:
[0232] RelExtCheck.fit(BordFeatVecSet_Labeled, RelExtSet_Labeled, batch_size=8000, epochs=10);
[0233] Assume that the sentence feature vector set based on entity boundaries contains G vectors. The above command means: a total of 10 iterations, the gradient is updated |G / 8000|+1 times in each iteration, and 8000 samples are selected for training each time.
[0234] Execute S3: Use BordFeatVecSet_UnLabeled to represent the sentence feature vector set based on entity boundaries in UnLabeledRelSet, and use the predict function of the RelExtCheck object to predict the judgment result, as follows:
[0235] RelExtSet_UnLabeled=RelExtCheck.predict(BordFeatVecSet_UnLabeled);
[0236] The obtained RelExtSet_UnLabeled is the entity pair relationship existence identification set in UnLabeledRelSet. If the value of an element is greater than 0.5, it means that the corresponding entity pair has a relationship.
[0237] Execute S41: read the sentence feature vector based on entity boundaries generated in step S1 to obtain sentence S BordStatic word embedding sequence StaEmdSeq S =[e s1 ,e s2 ,…,e si ,…,e sn ].
[0238] Execute S42: Use the tensorflow_hub.Module() function to load the ELMO word embedding model and convert StaEmdSeq S Input the model and get sentence S Bord Dynamic word embedding sequence DymEmdSeq S =[e d1 ,e d2 ,…,e di ,…,e dn ], as attached Fig.12 shown.
[0239] Execute S43: Splice sequence by StaEmdSeq S and DymEmdSeq S The corresponding elements of get sentence S Bord The word embedding sequence EmdSeq S =[e s1 e d1 ,e s2 e d2 ,…,e sn e dn ].
[0240] Execute S5: ID encode the 12 relationship types as follows (the numbers in brackets are the corresponding ID codes):
[0241] Superiors and subordinates (0), partners (1), friends (2), classmates (3), teachers and students (4), lovers (5), husband and wife (6), parents (7), brothers and sisters (8), grandparents and grandchildren (9), relatives (10), others (11).
[0242] One-Hot encoding is used to vectorize the ID code. The dimension of the vector corresponding to each ID code is 12, the component value of the corresponding bit is 1, and the component values of the remaining bits are all 0.
[0243] For example: the ID code of the relationship "siblings" is 8, and its corresponding vector is [0,0,0,0,0,0,0,0,1,0,0,0].
[0244] Execute S611: Create a keras.layers.Embedding object to define the input layer sequence. The maximum length of the sequence is 50 and the dimension of each element is 200.
[0245] Execute S612: Use keras.layers.Conv1D to create convolution kernels of different sizes (Size=2, 3, 4) of the convolution layer, and the number of convolution kernels of each size is 256.
[0246] Execute S613: Write a pooling function AttPooling based on the attention mechanism, call AttPooling in the custom layer created by keras.layers.core.Lambda(), and perform pooling based on the attention mechanism on the output results of the convolution layer. The pooling window sizes are 49, 48, and 47 respectively.
[0247] Execute S614: First, use keras.backend.concatenate to merge the output vectors of different pooling layers; then, use keras.backend.flatten to flatten the merged output vector; then, use keras.backend.dropout to discard the components of the flattened result according to a given probability (0.2), and the dimension of the result is 768.
[0248] Finally, keras.layers.Dense is used to define the fully connected layer. The number of neurons in the input layer is 768, and the number of neurons in the output layer is 12, representing 12 types of relationships. The activation function is softmax.
[0249] Execute S62: Initialize the weight matrix and bias vector using the kernel_initializer and bias_initializer parameters of keras.layers.Conv1D and keras.layers.Dense.
[0250] Execute S63-S65: write margin-based loss function;
[0251] Use keras.models.Model to define and train the CNN model object RelTypeCheck, and use the compile function of this object to compile the model. The main parameters are as follows:
[0252] Loss function: loss = 'margin', select a custom margin-based loss function;
[0253] Optimizer: optimizer = 'sgd', select stochastic gradient descent;
[0254] Evaluation indicators: metrics = ['categorical_accuracy'], select an evaluation function suitable for multi-classification.
[0255] Compile the CNN model object according to the above parameters as follows:
[0256] RelTypeCheck.compile(loss='margin', optimizer='sgd', metrics=['categorical_accuracy']);
[0257] ELMOFeatVecSet_Labeled and RelTypeSet_Labeled are used to represent the sentence feature vector and relation type vector set based on the ELMO network in LabeledRelSet, respectively. The fit function of the RelTypeCheck object is used to train the model, as follows:
[0258] RelTypeCheck.fit(ELMOFeatVecSet_Labeled, RelTypeSet_Labeled, batch_size=2000, epochs=10);
[0259] Assume that the number of "entity pair-sentence" feature vector sequences is G. The above command means: a total of 10 iterations, the gradient is updated |G / 2000|+1 times in each iteration, and 2000 samples are selected for training each time.
[0260] Execute S7: Use ELMOFeatVecSet_UnLabeled to represent the sentence feature vector set based on the ELMO network in UnLabeledRelSet, and use the predict function of the RelTypeCheck object to predict the judgment result:
[0261] RelTypeSet_UnLabeled=
[0262] RelTypeCheck.predict(ELMOFeatVecSet_UnLabeled);
[0263] The obtained RelTypeSet_UnLabeled is a set of relation type vectors in UnLabeledRelSet, the elements of which are probability vectors with a length of 12. The dimension number of the largest component is the ID code of the relation type, and the corresponding relation type can be determined based on the code.
[0264] Embodiment 3:
[0265] As attached Fig.13 As shown, the relationship extraction device based on a two-layer convolutional neural network of the present invention comprises:
[0266] A sentence feature vector generating component M1 based on entity boundaries, used to generate a sentence feature vector based on entity boundaries;
[0267] A relationship existence determination model training component M2, used for training a relationship existence determination model based on a convolutional neural network;
[0268] The entity pairs and sentences generating component M3 that may have a relationship is used to screen out the entity pairs and sentences that may have a relationship according to the relationship existence determination model;
[0269] A sentence feature vector generating component M4 based on the ELMO network, used for generating a sentence feature vector based on the ELMO network;
[0270] A relationship type vector generating component M5 is used to generate a vector corresponding to the relationship type;
[0271] A relation classification model training component M6 is used to train a relation classification model based on a convolutional neural network;
[0272] The entity pair relationship type prediction component M7 is used to predict the relationship type of entity pairs in a sentence based on the relationship classification model.
[0273] The sentence feature vector generating component M1 based on entity boundaries in this embodiment includes:
[0274] An entity boundary symbol adding component M11 is used to add boundary symbols at both ends of the entity of the sentence;
[0275] A static word embedding generation component M12, used for statically vectorizing each word in a sentence containing a boundary symbol;
[0276] Static word embedding concatenation component M13, used to concatenate the static word embedding of each word according to the order of the words in the sentence;
[0277] The relationship existence determination model training component M2 in this embodiment includes:
[0278] An entity pair relationship existence identification generating component M21 is used to generate an identification of whether a relationship between entity pairs exists;
[0279] The first layer hyperparameter setting component M22 is used to set the structural parameters of different modules in the convolutional neural network for relationship existence determination;
[0280] The first layer parameter initialization component M23 is used to initialize the parameters of different modules in the convolutional neural network for relationship existence determination;
[0281] The first layer input terminal setting component M24 is used to send all sentence feature vectors based on entity boundaries to the input terminal of the convolutional neural network for relationship existence determination;
[0282] The first layer output end is provided with a component M25, which is used to send all entity pair relationship existence identifications to the output end of the convolutional neural network for relationship existence determination;
[0283] The first layer training convergence component M26 is used to train the convolutional neural network for relationship existence judgment according to the convergence condition.
[0284] The sentence feature vector generating component M4 based on the ELMO network in this embodiment includes:
[0285] Static word embedding sequence reading component M41, used to read the static word embedding sequence of all words in the sentence;
[0286] A dynamic word embedding sequence generating component M42 is used to generate a dynamic word embedding sequence of all words in a sentence;
[0287] A word embedding sequence generating component M43 is used to generate word embedding sequences of all words in the sentence;
[0288] The relationship classification model training component M6 includes:
[0289] The second layer hyperparameter setting component M61 is used to set the structural parameters of different modules in the convolutional neural network for relationship classification;
[0290] The second layer parameter initialization component M62 is used to initialize the parameters of different modules in the convolutional neural network for relationship classification;
[0291] The second layer input terminal setting component M63 is used to send all sentence feature vectors based on the ELMO network to the input terminal of the convolutional neural network for relation classification;
[0292] The second layer output terminal is provided with a component M64, which is used to send all the relationship type vectors to the output terminal of the convolutional neural network for relationship classification;
[0293] The second layer training convergence component M65 is used to train the convolutional neural network for relationship classification according to the convergence condition.
[0294] Embodiment 4:
[0295] The embodiment of the present invention further provides a computer-readable storage medium, in which a plurality of instructions are stored, and the instructions are loaded by a processor, so that the processor executes the relationship extraction method based on a two-layer convolutional neural network in any embodiment of the present invention. Specifically, a system or device equipped with a storage medium can be provided, on which a software program code that implements the functions of any of the above embodiments is stored, and a computer (or CPU or MPU) of the system or device reads and executes the program code stored in the storage medium.
[0296] In this case, the program code itself read from the storage medium can realize the function of any one of the above-mentioned embodiments, and thus the program code and the storage medium storing the program code constitute a part of the present invention.
[0297] The storage medium embodiments for providing the program code include a floppy disk, a hard disk, a magneto-optical disk, an optical disk (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD+RW), a magnetic tape, a non-volatile memory card, and a ROM. Alternatively, the program code can be downloaded from a server computer by a communication network.
[0298] In addition, it should be clear that the functions of any of the above embodiments can be implemented not only by executing the program code read by the computer, but also by enabling an operating system operating on the computer to complete part or all of the actual operations based on instructions from the program code.
[0299] In addition, it can be understood that the program code read from the storage medium is written to a memory provided in an expansion board inserted into the computer or written to a memory provided in an expansion unit connected to the computer, and then based on the instructions of the program code, a CPU installed on the expansion board or the expansion unit is enabled to perform part or all of the actual operations, thereby realizing the functions of any of the above-mentioned embodiments.
[0300] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A relationship extraction method based on a two-layer convolutional neural network, characterized in that: The specific steps of this method are as follows: S1: Generate sentence feature vector based on entity boundaries; S2: Training a relationship existence determination model based on a convolutional neural network; S3: Use the relationship existence determination model to filter entity pairs and sentences that may have relationships; S4: Generate sentence feature vector based on ELMO network; S5: Generate relationship type vector; S6: Training a convolutional neural network-based relation classification model; S7: Use the relation classification model to predict the relation type of entity pairs; Among them, generating a sentence feature vector based on entity boundaries in step S1 refers to adding boundary symbols at both ends of the entity, statically vectorizing the vocabulary containing the boundary symbol sentence, and then splicing the static word embeddings of the vocabulary in order to form a sentence feature vector based on entity boundaries; specifically as follows: S11: Add boundary symbols at both ends of the entity; specifically: in sentence S, W Start and W End Indicates the start and end of the word, E A and E B Represent any two entities, in E A and E B Add boundary symbols at both ends <e A >、<\e A >、 <e B >、<\e B >, forming a new sentence S Bord ; S12: Generate lexical static word embeddings including boundary symbols; S13: Concatenate static word embeddings according to the lexical order of the sentence; S14: Returns a static word embedding sequence; The training of the convolutional neural network-based relationship existence determination model in step S2 is to input the sentence feature vector based on the entity boundary and the relationship existence identifier into the convolutional neural network, and obtain the relationship existence determination model through training; specifically as follows: S21: Generate entity pair relationship existence identification: Use R E xt(E A ,E B ) represents entity E A and E B Is there a relationship between: ①: If there is a relationship between the two, then R Ext (E A ,E B )=1; ②: If there is no relationship between the two, then R Ext (E A ,E B )=0; S22: Set the hyperparameters of the first layer of convolutional neural network: set the structural parameters of the input layer module, convolution layer module, pooling layer module, fully connected layer module and output layer module; S23: Initialize the parameters of the first layer of convolutional neural network: initialize the weight matrix and bias vector of different modules; S24: Send the sentence feature vector based on entity boundaries to the input layer of the first convolutional neural network; S25: Send the entity pair relationship existence mark to the output layer of the first convolutional neural network; S26: training the first layer of convolutional neural network model according to the convergence condition; S27: Returns the parameters of the first layer of the convolutional neural network.
2. The relationship extraction method based on a two-layer convolutional neural network according to claim 1 is characterized in that: Use the relation existence determination model in step S3 to process each entity pair (E A ,E B ), determine entity E A and E B Whether there is a relationship; as follows: S31: Read entity pairs (E A ,E B ), where E A and E B Represents any two entities in sentence S; S32: Generate entity pairs (E A ,E B )The corresponding sentence feature vector based on entity boundaries; S33: sending the sentence feature vector based on entity boundaries to the input end of the relation existence determination model; S34: Obtain the determination result R from the output end of the relationship existence determination model Ext (E A ,E B ), where R E xt(E A ,E B ) means E A and E B The result of the existence determination of the relationship between the two entities; S35: Judge R Ext (E A ,E B ) and 0.5: ①: If R Ext (E A ,E B )>0.5, then execute step S36; ②: If R Ext (E A ,E B )≤0.5, jump to step S37; S36: Marking entity E A and E B In sentence S there is a relation; S37: Determine whether there are any unread entity pairs in sentence S (E A ,E B ): ①: If yes, jump to step S31; ②: If not, execute step S38; S38: Return the entity pair (E A ,E B ).
3. The relationship extraction method based on a two-layer convolutional neural network according to claim 1, characterized in that: The generating of the sentence feature vector based on the ELMO network in step S4 specifically refers to generating the sentence S through the ELMO network Bord The dynamic word embedding of each word in is concatenated after the static word embedding generated in step S1 to form the word embedding of each word, and then concatenated according to the order of the words in the sentence to form a sentence feature vector based on the ELMO network; specifically as follows: S41: Read sentence S Bord The static word embedding sequence of S Bord Indicates that in E A and E B The new sentence generated by adding boundary symbols at both ends, E A and E B Entities representing relations in sentence S; S42: Generate sentence S Bord Dynamic word embedding sequence: sentence S Bord The static word embedding sequence is fed into the input layer of the ELMO network, and the sentence S is obtained from the output layer. Bord The dynamic word embedding sequence has the same sequence length as the static word embedding sequence; specifically, as follows: S421: Send the static word embedding sequence to the input layer of the ELMO network; S422: Obtain the operation result of the ELMO network output layer; S423: Obtaining dynamic word embedding of vocabulary according to the operation result; S424: Concatenate dynamic word embeddings according to the lexical order of the sentence; S425: Return the dynamic word embedding sequence; S43: Generate sentence S Bord Word embedding sequence: Let sentence S Bord The number of words is n, and the static word embedding sequence is StaEmdSeq S =[e s1 ,e s2 ,…,e si ,…,e sn ], the dynamic word embedding sequence is DymEmdSeq S =[e d1 ,e d2 ,…,e di ,…,e dn ]; where e si and e di Represent the static word embedding and dynamic word embedding of the i-th word respectively; e si e di Represents the word embedding of the i-th word, and its corresponding operation is to transform e di Splice in e si Later, the sentence S Bord The word embedding sequence is EmdSeq S =[e s1 e d1 ,e s2 e d2 ,…,e sn e dn ]; S44: Return to S Bord word embedding sequence; The generation of the relationship type vector in step S5 is specifically as follows: One-Hot encoding is used to represent the relationship type between entities, that is, a vector RelVec with a length of T is used k Represents a relationship k , k∈[1,T]; where Rel k Represents entity E A and E B The relationship between k In the example, except for the kth bit which is 1, the rest of the bits are 0.
4. The relationship extraction method based on a two-layer convolutional neural network according to claim 1, characterized in that: The training of the relation classification model based on the convolutional neural network in step S6 specifically refers to setting the hyperparameters of the convolutional neural network, initializing the corresponding weight matrix and bias vector, and then sending the sentence feature vector and the relation type vector based on the ELMO network into the convolutional neural network, and training by optimizing the loss function to obtain the relation classification model; specifically as follows: S61: Set the hyperparameters of the second layer of convolutional neural network: set the structural parameters of the input layer module, convolution layer module, pooling layer module, fully connected layer module and output layer module; among which, the convolution layer module adopts convolution kernels of different sizes, and the pooling layer module adopts pooling based on the attention mechanism; the details are as follows: S611: Set input layer hyperparameters; S612: Setting convolution kernels of different sizes; S613: Set up pooling based on the attention mechanism: Assume that t convolution kernels of different sizes are used, and the size of the jth convolution kernel is L j , the convolution operation result R j is the length nL j +1 vector, corresponding to the attention weight A j is a vector of the same length, corresponding to the relationship type word embedding matrix W j The scale is (nL j +1)*T matrix, corresponding to the "element-relationship" correlation matrix G j is a matrix of the same size, B j It's G j The column-normalized matrix of It is B j The g-th column vector of yes The mth element of ; specifically as follows: S6131: Calculate the "element-relationship" correlation matrix YesR j The transpose of S6132: Calculate G j The column normalized matrix B j : S6133: R j and B j Maximum inner product of column vectors As a result of pooling; S614: Set other hyper parameters; S62: Initialize the parameters of the second layer of convolutional neural network: initialize the weight matrix and bias vector of different modules; S63: Sending the sentence feature vector based on the ELMO network to the input layer of the second convolutional neural network; S64: Send the relationship type vector to the output layer of the second convolutional neural network; S65: Train the second layer of the convolutional neural network model according to the convergence condition: use the spacing loss function for training, which is defined as follows: Among them, g + (S) indicates the correct classification score; g - (S) indicates the misclassification score; d + and d - Respectively represent the spacing thresholds of positive and negative samples; ρ represents the scaling factor; S66: Returns the parameters of the second layer of the convolutional neural network.
5. The relationship extraction method based on a two-layer convolutional neural network according to any one of claims 1 to 4, characterized in that: The use of the relation classification model to predict the relation type of entity pairs in step S7 refers to using the trained convolutional neural network to predict the relation type of entity pairs in the sentence to be processed. A' and E B' Represents any two entities in the sentence S' to be processed; specifically as follows: S71: In entity E A' and E B' Add boundary symbols at both ends to get a new sentence S72: Generate Entity boundary-based sentence feature vector; S73: Generate The sentence feature vector based on ELMO network; S74: sending the sentence feature vector based on the ELMO network to the input layer of the second convolutional neural network; S75: Run the second layer of convolutional neural network to obtain output layer information; S76: Obtain the relationship type corresponding to the output end with the highest probability as entity E A' and E B' the relationship between; S77: Determine whether there is an unread entity E in the sentence S' A' and E B' : ①: If yes, jump to step S71; ②: If not, execute step S78; S78: Return entity E A' and E B' The set of relations present in sentence S'.
6. A relationship extraction device based on a two-layer convolutional neural network, characterized in that: The device includes: A sentence feature vector generating component based on entity boundaries, used for generating a sentence feature vector based on entity boundaries; A relationship existence determination model training component, used for training a relationship existence determination model based on a convolutional neural network; The entity pairs and sentences generating component that may have a relationship is used to filter out the entity pairs and sentences that may have a relationship based on the relationship existence determination model; A sentence feature vector generating component based on the ELMO network, used for generating a sentence feature vector based on the ELMO network; A relation type vector generating component, used to generate a vector corresponding to the relation type; A relation classification model training component, used to train a relation classification model based on a convolutional neural network; An entity pair relationship type prediction component is used to predict the relationship type of entity pairs in a sentence based on a relationship classification model; Among them, the sentence feature vector generation component based on entity boundaries includes: The entity boundary symbol adding component is used to add boundary symbols at both ends of the entity in the sentence; specifically: in sentence S, W Start and W End Indicates the start and end of the word, E A and E B Represent any two entities, in E A and E B Add boundary symbols at both ends <e A >、<\e A >、 <e B >、<\e B >, forming a new sentence S Bord ; A static word embedding generation component is used to statically vectorize each word in a sentence containing boundary symbols; The static word embedding concatenation component is used to concatenate the static word embedding of each word according to the order of the words in the sentence; The relationship existence determination model training component includes: An entity pair relationship existence identification generating component is used to generate an identification of whether a relationship between entity pairs exists; The first layer hyperparameter setting component is used to set the structural parameters of different modules in the convolutional neural network for relationship existence determination; The first layer parameter initialization component is used to initialize the parameters of different modules in the convolutional neural network for relationship existence determination; The first layer input terminal setting component is used to send all sentence feature vectors based on entity boundaries to the input terminal of the convolutional neural network for relation existence determination; The first layer output terminal setting component is used to send all entity pair relationship existence identifications to the output terminal of the convolutional neural network for relationship existence determination; The first layer training convergence component is used to train the convolutional neural network for relationship existence judgment according to the convergence condition.
7. The relationship extraction device based on a two-layer convolutional neural network according to claim 6, characterized in that: The sentence feature vector generating component based on the ELMO network includes: A static word embedding sequence reading component is used to read the static word embedding sequence of all words in the sentence; A dynamic word embedding sequence generation component is used to generate dynamic word embedding sequences of all words in a sentence; A word embedding sequence generation component is used to generate word embedding sequences for all words in a sentence; The relationship classification model training component includes: The second layer hyperparameter setting component is used to set the structural parameters of different modules in the convolutional neural network for relationship classification; The second layer parameter initialization component is used to initialize the parameters of different modules in the convolutional neural network for relationship classification; The second layer input terminal setting component is used to send all sentence feature vectors based on the ELMO network to the input terminal of the convolutional neural network for relation classification; The second layer output terminal setting component is used to send all relationship type vectors to the output terminal of the convolutional neural network for relationship classification; The second layer training convergence component is used to train the convolutional neural network for relational classification according to the convergence condition.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which, when executed by the computer, implement the relationship extraction method based on a two-layer convolutional neural network as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Keyword extraction method, verbal skill scoring method and verbal skill recommendation method
CN111160017A
Convolutional neural network entity relation extraction method fusing different pre-trained word vectors
CN112183103A
