A relation extraction system with relational pattern recognition capabilities
Through the combination of the self-attention mechanism to generate pattern capture matrices and the selective attention mechanism, the problem of the Transformer model ignoring local related information in relationship extraction is solved, high-quality sentence vectors are generated, and the effect of relationship extraction and model performance are improved.
Patent Information
- Application Number
- CN202110966806.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-23
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2041-08-23
AI Technical Summary
Existing relationship extraction methods based on the Transformer model cannot effectively capture the relationship patterns in sentences, especially the local association information of words is ignored, resulting in the loss of relationship pattern capture and limiting the performance of the model.
The pattern capture matrix P is generated through the self-attention mechanism, the low-level attention parameters of the Transformer model are adjusted, and the sentence representation is aggregated using the selected attention mechanism. The softmax method is used to classify the relationship types and predict the relationship types in the sentences.
The improved model can generate high-quality sentence vectors containing relational pattern information, improving the effect of relation extraction. Experiments show that the performance on the NYT data set is better than other similar models, improving training efficiency and generalization ability.
Smart Images

Figure CN113657095B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of natural language processing and deep learning technology, and in particular to a relation extraction system capable of relation pattern recognition. Background Art
[0002] Relation extraction is defined as a task of extracting structured data from rough unstructured text information. It is very important in the field of natural language processing. Relation extraction is widely used in many aspects, such as text classification, question answering, and web search.
[0003] For the relation extraction task, an important challenge is the lack of manually annotated training data. To address this problem, Mintz et al. proposed a remote supervision method to automatically construct training data. The basic assumption is that if an entity pair (e h ,e t ) If there is a relation r in the knowledge base, then all sentences about this entity pair will express the relation r in different ways. Since there may be multiple relations between the same entity pair, remote supervision relation extraction is a multi-label prediction task.
[0004] With the rapid development of pre-trained models, the performance of pre-trained models in relation extraction tasks is getting better and better, especially the pre-trained Transformer model. Specifically, the pre-trained Transformer model can generate high-quality sentence vectors, which can provide great help for the subsequent relation extraction tasks, enabling the relation extraction tasks to achieve good performance results. Representative literature includes "Attention Is All You Need" published by Google and "Improving Language Understanding by Generative Pre-training" published by openAI. The latter is the GPT language model used in this invention.
[0005] However, existing relation extraction based on Transformer models cannot capture the relational patterns in sentences. They only consider the overall association between words, but ignore the local association between words, such as the information of phrase structure. In the article "Improving Language Understanding by Generative Pre-training", the GPT model adopts an overall self-attention mechanism, which only considers the relationship between words in the sentence as a whole, and inevitably ignores the local association between words, resulting in the loss of relational pattern capture. This weakness limits the overall performance of the Transformer model. Therefore, capturing local dependency information such as relational patterns has become a feasible way to improve the Transformer model. Summary of the invention
[0006] The purpose of the present invention is to overcome the lack of local dependency in the existing Transformer model-based methods when representing sentence vectors, so that the Transformer model can represent the information of the relational pattern while generating the sentence vector. The core idea is to use the neural network with the self-attention mechanism to generate the pattern capture matrix P for the word vector sequence, and use the P matrix to adjust the low-level attention parameters of the Transformer model. After that, the selective attention mechanism is used to aggregate the representation of each sentence in the sentence bag to generate the vector representation of the sentence bag; finally, the softmax method is used to classify the operation results of the relational representation and the sentence bag representation, and then predict the type of relationship contained in the sentence bag.
[0007] To achieve the above object, the present invention provides a relation extraction system with relation pattern recognition capability, comprising a receiving module, a word vector sequence generation module and a relation extraction model, wherein:
[0008] The receiving module is used to receive the sentence bag and the target entity pair (e h ,e t );
[0009] The word vector sequence generation module is used to embed the words of each sentence in the sentence bag by combining the position and symbol, and convert the sentence into a word vector sequence;
[0010] The relation extraction model is used to predict the set of relations contained in the sentence bag.
[0011] Furthermore, in the word vector sequence generation module, a start symbol and an end symbol are first added to the first position of the sentence; the symbol and position of the word are encoded using a byte pair encoding method to obtain a symbol embedding vector e t and the position embedding vector e p; Add the embedding vectors to get the word vector representation of each word, and the word vector representations in the sentence constitute a word vector sequence.
[0012] Furthermore, the relation extraction model includes a pattern capture matrix generation module, a sentence bag vector construction module and a classifier module, wherein:
[0013] A pattern capture matrix generation module is used to receive a word vector sequence and generate a pattern capture matrix P;
[0014] The sentence vector construction module is used to receive the pattern capture matrix P and the word vector sequence and calculate the vector representation s of the sentence i ;
[0015] The bag-of-sentence vector construction module is used to calculate all the sentence vectors in the bag-of-sentence by selecting the attention mechanism to obtain the vector representation b of the bag-of-sentence;
[0016] The classifier module is used to classify the result of multiplying the vector representation b of the sentence bag and the relation embedding matrix R, and then predict the relationship contained in the sentence bag.
[0017] Furthermore, in the pattern capture matrix generation module, the step of generating the pattern capture matrix P includes:
[0018] S31. Use the self-attention mechanism on the word vector sequence to generate a d-dimensional query vector q for each word. i , key vector k i and the value vector v i ;
[0019] S32, use q for adjacent words i and k i The vector calculates the probability that they belong to the same relational pattern, denoted by c i,i+1 :
[0020]
[0021] S33, for c i,i+1 ,c i+1,i Their values are generally not the same, so we calculate the probability that the i-th and i+1-th words belong to the same relational pattern, which is uniformly recorded as p i , the formula is:
[0022]
[0023] S34, Provisions i:j represents the probability that the i-th word to the j-th word belong to the same relational pattern at the same time, p i:j The calculation method is:
[0024]
[0025] S35, generate pattern capture matrix P:
[0026] P i,j =p i:j
[0027] Furthermore, in the sentence vector construction module, the word vector sequence is input into the improved GPT model to generate a sentence vector with relational pattern information. The improved GPT model is improved in that the attention score of the first layer is affected by the pattern capture matrix P, and the calculation formula is:
[0028]
[0029] where ⊙ is the element-wise multiplication, d k Represents the dimension of the key vector in the multi-head attention mechanism. Here, the matrix P contains the local dependencies between words in the sentence, that is, the probability information that adjacent words belong to the same relational pattern. Inputting P into GPT can enable it to capture the local dependencies between words in the sentence.
[0030] Furthermore, in the bag-of-sentence vector construction module, the bag-of-sentence vector b is obtained by weighted summing the sentence vectors in the bag-of-sentence using the selective attention mechanism, and the calculation formula is as follows:
[0031] b=∑α j s j
[0032] Among them, α j Represents the sentence s j With relation i The correlation coefficient is calculated as follows:
[0033]
[0034] in Represents the target relationship r i The representation vector of .
[0035] Furthermore, the classifier module includes a classifier consisting of a fully connected layer and a softmax layer, and the relationship prediction step includes:
[0036] S61. Multiply the sentence bag vector b by the relation representation matrix R, and record the result as o, where the R matrix is randomly initialized:
[0037] o=bR T
[0038] S62. For the output o, the classifier is used to calculate the probability of the relationship in the sentence bag. The calculation method is:
[0039]
[0040] Among them, Θ represents all the parameters in the relation extraction model, k represents the number of relations, and r represents the relation.
[0041] Furthermore, when training the relation extraction model, the loss function is:
[0042]
[0043] Where n represents the number of sentence packets, and each sentence packet corresponds to an entity pair.
[0044] Furthermore, in order to improve the generalization ability of the model and to make the model converge faster, the overall loss function of the relationship extraction model is:
[0045]
[0046] Among them, λ is the harmonic factor, This is the loss function for the original GPT model pre-training phase:
[0047]
[0048] Among them, w is the original GPT model in the pre-training process to predict t i The size of the constructed context window.
[0049] The relationship extraction system provided by the present invention has the following beneficial effects:
[0050] 1. Through the self-attention mechanism network, a relationship pattern capture matrix is generated and provided to the improved GPT model, which can overcome the disadvantage of missing local dependency information.
[0051] 2. The improved GPT model can generate higher-quality sentence vectors containing relational pattern information, improving the effect of the original Transformer-based relation extraction. Experiments show that its performance on the NYT dataset is better than other similar models.
[0052] 3. By combining the loss function of the relational pattern capture matrix generation module of the self-attention mechanism and the loss function of the GPT model, a more reasonable and effective loss function can be constructed to improve the efficiency of training. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0054] Figure 1 A schematic diagram of the structure of a relationship extraction system according to an embodiment of the present invention;
[0055] Figure 2 A flowchart of the relation extraction with relation pattern recognition capability of the present invention;
[0056] Figure 3 A schematic diagram of the word embedding process of the present invention;
[0057] Figure 4 is a flow chart of generating the pattern capture matrix P in the present invention;
[0058] Figure 5 This is a workflow diagram of the GPT model used in the present invention;
[0059] Figure 6 The precision-recall curves of the present invention and the baseline model on the NYT dataset;
[0060] Figure 7 This is the precision-recall curve of the present invention and the baseline model on the GIDS dataset. DETAILED DESCRIPTION
[0061] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0062] The present invention will be further described below in conjunction with the accompanying drawings and specific embodiments.
[0063] In order to make the technical solutions and advantages in the examples of the present application clearer, the exemplary embodiments of the present application are further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present application, rather than an exhaustive list of all the embodiments. It should be noted that the examples in the present application can be combined with each other in the absence of conflict.
[0064] The present invention provides a relation extraction system with relation pattern recognition capability, such as Figure 1 As shown, it includes a receiving module, a word vector sequence generation module and a relation extraction model, where:
[0065] The receiving module is used to receive the sentence bag and the target entity pair (e h ,e t );
[0066] The word vector sequence generation module is used to embed the words of each sentence in the sentence bag by combining the position and symbol, and convert the sentence into a word vector sequence;
[0067] The relation extraction model is used to predict the set of relations contained in the sentence bag.
[0068] The workflow of the relation extraction system is as follows Figure 2 shown.
[0069] In the word vector sequence generation module, we first add the start symbol and the end symbol to the beginning of the sentence; then we use the byte pair encoding method to encode the symbol and position of the word, and get the symbol embedding vector e t and the position embedding vector e p ; Add the embedding vectors to get the word vector representation of each word. The word vector representation in the sentence constitutes a word vector sequence, such as Figure 3 The following is a detailed description of the generation process:
[0070] (1) Add the start symbol (_START_) and the end symbol (_CLS_) to the beginning of the sentence;
[0071] (2) Use byte pair encoding to encode the symbol and position of the word respectively. Get the symbol embedding vector e t and the position embedding vector e p ;
[0072] (3) Word vector representation x i =e ti +e pi , which is obtained by adding the two embedding vectors.
[0073] The relation extraction model includes a pattern capture matrix generation module, a sentence bag vector embedding module and a classifier module. The pattern capture matrix generation module is used to receive a word vector sequence and generate a pattern capture matrix P; the sentence vector construction module is used to receive a pattern capture matrix P and a word vector sequence and calculate the vector representation s of the sentence. i; The sentence bag vector construction module is used to calculate the vector representation b of the sentence bag by selecting the attention mechanism for all the sentence vectors in the sentence bag; the classifier module is used to classify the result of multiplying the vector representation b of the sentence bag and the relationship embedding matrix R, and then predict the relationship contained in the sentence bag.
[0074] In the pattern capture matrix generation module, the generation process of matrix P is as follows Figure 4 As shown, specifically including:
[0075] S31, word vector x generated based on word embedding i , using the self-attention mechanism, a query vector q of d dimensions is generated for each word (here d is generally a lower dimension than the word embedding vector, generally half of the word embedding vector dimension. For example, if the word embedding dimension is 256, then d is 128) i , key vector k i and the value vector v i ,Right now:
[0076] q i =x i W q
[0077] k i =x i W k
[0078] v i =x i W v
[0079] S32, for adjacent words (such as the i-th and i+1-th), use q between each two i and k i Vectors calculate the probability c that they belong to the same relational pattern i,i+1 :
[0080]
[0081] S33, for c i,i+1 ,c i+1,i Use their geometric mean to unify the representation, denoted by p i , which indicates the probability that the i-th and i+1-th words belong to the same relational pattern:
[0082]
[0083] S34, calculate each p i After the value, specify p i:j represents the probability that the i-th word to the j-th word belong to the same relational pattern at the same time, p i:j The calculation method is:
[0084]
[0085] S35, generate pattern capture matrix P:
[0086] P i,j =p i:j
[0087] In the sentence vector construction module, the sentence vector s is generated by the improved GPT model (Generative Pre-trained Transformer) i The improved GPT model accepts the word vector sequence after the above word embedding as input, and outputs the sentence vector. The original GPT model is as follows Figure 5 As shown in the figure, the improvement of the improved GPT model is the "self-attention mechanism with Mask", that is, the attention score of the first layer of the original GPT model. This attention score is affected by the pattern capture matrix P and is calculated as follows:
[0088]
[0089] where ⊙ is the element-wise multiplication, d k Represents the dimension of the key vector in the multi-head attention mechanism. The purpose of adding the matrix P to the improved GPT model is to accurately capture the influence of the relational pattern, and then generate a sentence vector with relational pattern information. The matrix P contains the local dependencies between words in the sentence, that is, the probability information that adjacent words belong to the same relational pattern. Inputting P into GPT enables it to capture the local dependencies between words in the sentence. The original GPT model does not consider the local association between words in the sentence, and thus adopts an overall self-attention mechanism, which ignores the information of the relational pattern and limits the performance of the model. In the present invention, the information of the relational pattern, that is, the local dependency information matrix P between words, is added to the original GPT model, so that its performance is improved. Experiments on data sets such as NYT show that doing so can improve the performance of the original GPT model.
[0090] In the bag-of-sentences vector construction module, all the sentence vectors s in the bag-of-sentences are i The sentence bag representation vector b is obtained by selecting the weighted sum of the attention mechanism. The calculation formula is as follows:
[0091] b=∑α j s j
[0092] The summation means to sum the operation results of all sentences in the sentence bag. j Represents the sentence s j With relationi The correlation coefficient is calculated as follows:
[0093]
[0094] in Represents the target relationship r i The representation vector of (that is, one of the columns of the relation representation matrix R) is generated by random initialization.
[0095] In the classifier module, the sentence bag representation vector b is first multiplied by the relation representation matrix R, and the result is recorded as o. Here, the R matrix is randomly initialized.
[0096] o=bR T
[0097] Next, for the output o, the classifier is used to calculate the probability of the relationship involved in the sentence bag, so as to obtain the relationship that the sentence bag finally corresponds to. The method used by the classifier is softmax, and the calculation method is:
[0098]
[0099] Among them, k represents the number of relations, Θ represents all the parameters in the relation extraction model, and r represents the relation in the relation set.
[0100] The parameters for relation extraction model training include W in the pattern capture matrix generation module q ,W v ,W k The training process of the three embedding matrices and the series of neural network parameters in the improved GPT model in the sentence vector construction module is the same as the conventional operation and will not be described in detail. However, the loss function during model training adopts the following optimization method, which is one of the characteristics of the present invention.
[0101] The cross entropy loss function, as the main optimization objective of the relationship extraction model, is:
[0102]
[0103] Where n represents the number of sentence packets, and each sentence packet corresponds to an entity pair.
[0104] In one embodiment, in order to improve the generalization ability of the model and make the model converge faster, the loss function of the original GPT model pre-training part is also used as an auxiliary item, with the aim of making the overall relationship extraction model training process more stable:
[0105]
[0106] Where w is the original GPT model pre-training process to predict the word t iThe size of the constructed context window.
[0107] In summary, the overall loss function of the model is defined as:
[0108]
[0109] The λ is a harmonic factor used to balance the two terms.
[0110] The effectiveness of the present invention will be further illustrated by experiments below.
[0111] The datasets used in this experiment are the New York Times (NYT) dataset and the Google IISc Distant Supervision (GIDS) dataset, which are widely used datasets for the problem of distant supervised relation extraction. The NYT dataset contains about 520,000 training sentences and about 172,000 test sentences. There are 53 different relations in the dataset (including "no relation" relations). The GIDS dataset contains about 11,000 training sentences and 5,663 test sentences, and has 5 different relations (including "no relation" relations).
[0112] First, the parameter information statistics of the model are shown in Table 1:
[0113] Table 1 Training parameter settings
[0114]
[0115] In the experimental comparison, we selected the baseline models PCNN+ATT, BGWA, RESIDE, DISTRE and DCRE. In terms of experimental indicators, we used the precision-recall curve, P@N (the precision score of the first N extracted relation instances), and AUC (area under the curve) to measure. First, the P@N and AUC value tables on the two datasets are shown in Tables 2 and 3:
[0116] Table 2: Performance of this model and the baseline model on the NYT dataset
[0117]
[0118] Table 3: Performance of this model and the baseline model on the GIDS dataset
[0119]
[0120] It can be seen that this model performs better than other baseline models in terms of P@1000 and P@2000 indicators. In addition, this model also outperforms other models in terms of precision-recall performance, such as Figure 6and Figure 7 shown.
[0121] Those skilled in the art will appreciate that the foregoing embodiments are merely intended to illustrate the technical solutions of the present invention rather than to limit the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art will appreciate that the technical solutions described in the foregoing embodiments may be modified or some or all of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope defined by the claims of the present invention.
Claims
1. A relation extraction system with relational pattern recognition capabilities, It is characterized in that The system includes a receiving module, a word vector sequence generation module and a relation extraction model, wherein: The receiving module is used to receive the sentence bag and the target entity pair (e h , e t ); The word vector sequence generation module is used to embed the words of each sentence in the sentence bag by combining the position and symbol, and convert the sentence into a word vector sequence; Relation extraction model, used to predict the set of relations contained in the sentence bag; The relation extraction model includes a pattern capture matrix generation module, a sentence bag vector construction module and a classifier module, among which: A pattern capture matrix generation module is used to receive a word vector sequence and generate a pattern capture matrix P; The sentence vector construction module is used to receive the pattern capture matrix P and the word vector sequence and calculate the vector representation s of the sentence i ; The bag-of-sentence vector construction module is used to calculate all the sentence vectors in the bag-of-sentence by selecting the attention mechanism to obtain the vector representation b of the bag-of-sentence; The classifier module is used to classify the result of multiplying the vector representation b of the sentence bag and the relation embedding matrix R, and then predict the relationship contained in the sentence bag; In the pattern capture matrix generation module, the step of generating the pattern capture matrix P includes: S31. Use the self-attention mechanism on the word vector sequence to generate a d-dimensional query vector q for each word. i , key vector k i and the value vector v i ; S32, use q for adjacent words i and k i Vectors calculate the probability c that they belong to the same relational pattern i,i+1 : S33, calculate the probability that the i-th and i+1-th words belong to the same relational pattern, the formula is: S34, Provisions i:j represents the probability that the i-th word to the j-th word belong to the same relational pattern at the same time, p i:j The calculation method is: S35, generate pattern capture matrix P: P i,j =p i:j ; In the sentence vector construction module, the word vector sequence is input into the improved GPT model to generate a sentence vector with relational pattern information. The calculation formula of the attention score of the first layer of the improved GPT model is: where ⊙ is the element-wise multiplication, d k Represents the dimension of the key vector in the multi-head attention mechanism.
2. The relationship extraction system according to claim 1, It is characterized in that In the word vector sequence generation module, the start symbol and the end symbol are first added to the first position of the sentence; the symbol and position of the word are encoded using the byte pair encoding method to obtain the symbol embedding vector e t and the position embedding vector e p ; Add the embedding vectors to get the word vector representation of each word, and the word vector representations in the sentence constitute a word vector sequence.
3. The relationship extraction system according to claim 1, It is characterized in that In the bag-of-sentence vector construction module, the bag-of-sentence vector b is obtained by weighted summing the sentence vectors in the bag-of-sentence using the selective attention mechanism. The calculation formula is as follows: b=∑α j s j Among them, α j Representative sentence s j With relation i The correlation coefficient is calculated as follows: in Represents the target relationship r i The representation vector of .
4. The relationship extraction system according to claim 1, It is characterized in that The classifier module includes a classifier composed of a fully connected layer and a softmax layer, and the relationship prediction step includes: S61. Multiply the sentence bag vector b by the relation representation matrix R, and record the result as o, where the R matrix is randomly initialized: o=bR T S62. For the output o, the classifier is used to calculate the probability of the sentence bag belonging to the relationship. The calculation method is: Among them, Θ represents all the parameters in the relation extraction model, k represents the number of relations, and r represents the relation.
5. The relationship extraction system according to claim 4, It is characterized in that When training the relation extraction model, the loss function is: Where n represents the number of sentence packets, and each sentence packet corresponds to an entity pair.
6. The relationship extraction system according to claim 5, It is characterized in that In order to improve the generalization ability of the model and make the model converge faster, the overall loss function of the relationship extraction model is: Among them, λ is the harmonic factor, is the pre-training loss function of the original GPT model: Among them, w is the original GPT model in order to predict t i The size of the constructed context window.
