Relationship extraction method, device, computer equipment and readable storage medium
By obtaining the word vector and entity-level feature vector of the document in the relationship extraction model and combining it with the document-level feature vector, the problem of low accuracy in traditional relationship extraction technology is solved, and higher entity relationship extraction accuracy and model learning ability are achieved.
Patent Information
- Application Number
- CN202111158259.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-30
- Publication Date
- 2025-09-12
- Estimated Expiration
- 2041-09-30
AI Technical Summary
Traditional relation extraction technology has low accuracy in extracting entity relationships from unstructured text.
By inputting the word vector after relationship extraction of the document into the relationship extraction model, the preliminary vector of the word is obtained, the entity-level feature vector of the entity pair is extracted, and combined with the document-level feature vector, the entity relationship between the entity pairs is determined, and the extraction accuracy is improved by using a fully connected neural network and self-attention mechanism.
It improves the accuracy and versatility of entity relationship extraction, can combine the contextual information of the document for inference and understanding, and enhances the learning ability and generalization of the relationship extraction model.
Smart Images

Figure CN113901232B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a relationship extraction method, apparatus, computer device, and readable storage medium. Background Art
[0002] With the rapid development of the financial industry, a large amount of unstructured text has accumulated within the industry, such as credit investigation reports and financial product instructions. A large amount of entity relationship information is hidden in this text content. Relationship extraction technology can extract structured text from unstructured text, providing foundational information for downstream tasks such as knowledge graph construction, risk transmission analysis, conversation building, and intelligent search.
[0003] Traditionally, unstructured text is fed into a deep learning model to extract sentence-level relationships. However, this approach often results in low accuracy in the extracted entity relationships. Summary of the Invention
[0004] Based on this, it is necessary to provide a relationship extraction method, device, computer equipment and readable storage medium to address the above technical problems.
[0005] A relationship extraction method, comprising:
[0006] Input the word vectors after relation extraction of the document into the relation extraction model to obtain preliminary vectors of the words in the document;
[0007] Extracting entity-level feature vectors of entity pairs in the document using the preliminary vectors;
[0008] Determining a document-level feature vector based on the preliminary vector and the entity-level feature vector;
[0009] The entity relationship between entity pairs in the document is determined using the entity-level feature vector and the document-level feature vector.
[0010] In one embodiment, extracting entity-level feature vectors of entity pairs in the document using the preliminary vectors includes:
[0011] Mapping the entity pair to a subspace using the preliminary vector to obtain a mapping vector, wherein the preliminary vector includes a word vector after relation extraction, an entity type feature vector, and a coreference feature vector;
[0012] The mapping vector is input into a first fully connected neural network model to obtain the entity-level feature vector.
[0013] In one embodiment, mapping the entity pair to a subspace using the preliminary vector to obtain a mapping vector comprises:
[0014] Calculating an average value of the preliminary vectors to obtain a reference vector of an entity in the entity pair;
[0015] Calculating an average value of the reference vectors to obtain an entity vector of the entity;
[0016] The entity vector is mapped to a subspace to obtain a mapping vector of the entity.
[0017] In one embodiment, determining the document-level feature vector based on the preliminary vector and the entity-level feature vector includes:
[0018] Assigning a first weight coefficient to each word in the document, and obtaining a sentence vector of a sentence in the document by using the first weight coefficient and a preliminary vector of the word;
[0019] Inputting the sentence vector and the entity-level feature vector into a second fully connected neural network model to obtain a sentence-level feature vector;
[0020] The document-level feature vector is obtained through the sentence-level feature vector.
[0021] In one embodiment, obtaining the document-level feature vector through the sentence-level feature vector includes:
[0022] Inputting the sentence-level feature vector into a bidirectional long short-term memory recurrent neural network model to obtain a feature vector of the sentence, and using a self-attention mechanism to obtain a second weight coefficient of the sentence;
[0023] The document-level feature vector is determined by using the feature vector of the sentence and the second weight coefficient of the sentence.
[0024] In one embodiment, determining the entity relationship between entity pairs in the document using the entity-level feature vector and the document-level feature vector includes:
[0025] Inputting the entity-level feature vector and the document-level feature vector into a third fully connected neural network model to obtain the relationship probability of each entity relationship existing between the entity pairs;
[0026] The entity relationship between the entity pairs is determined based on the relationship probability and a preset threshold.
[0027] In one embodiment, the method further comprises:
[0028] Obtaining a document vector for the document;
[0029] The document vector is converted to obtain the relation-extracted word vector, where the relation-extracted word vector includes the expression characters of the word in the document in the relation-extracted vocabulary, the filling attributes of the word in the document, and the sentence sequence number of the sentence to which the word belongs in the document.
[0030] A relationship extraction device, comprising:
[0031] A preliminary vector acquisition module, configured to input the word vectors after relation extraction of the document into the relation extraction model to obtain preliminary vectors of the words in the document;
[0032] A first feature vector acquisition module, configured to extract entity-level feature vectors of entity pairs in the document using the preliminary vectors;
[0033] A second feature vector acquisition module, configured to determine a document-level feature vector based on the preliminary vector and the entity-level feature vector;
[0034] The entity relationship determination module is used to determine the entity relationship between entity pairs in the document through the entity-level feature vector and the document-level feature vector.
[0035] A computer device includes a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0036] Input the word vectors after relation extraction of the document into the relation extraction model to obtain preliminary vectors of the words in the document;
[0037] Extracting entity-level feature vectors of entity pairs in the document using the preliminary vectors;
[0038] Determining a document-level feature vector based on the preliminary vector and the entity-level feature vector;
[0039] The entity relationship between entity pairs in the document is determined using the entity-level feature vector and the document-level feature vector.
[0040] A readable storage medium stores a computer program, which, when executed by a processor, implements the following steps:
[0041] Input the word vectors after relation extraction of the document into the relation extraction model to obtain preliminary vectors of the words in the document;
[0042] Extracting entity-level feature vectors of entity pairs in the document using the preliminary vectors;
[0043] Determining a document-level feature vector based on the preliminary vector and the entity-level feature vector;
[0044] The entity relationship between entity pairs in the document is determined using the entity-level feature vector and the document-level feature vector.
[0045] The above-mentioned relationship extraction method, device, computer equipment and readable storage medium, the computer equipment can input the word vector after relationship extraction of the document into the relationship extraction model to obtain the preliminary vector of the word in the document, extract the entity-level feature vector of the entity pair in the document through the preliminary vector, determine the document-level feature vector based on the preliminary vector and the entity-level feature vector, and determine the entity relationship between the entity pairs in the document through the entity-level feature vector and the document-level feature vector; this method avoids the problem of determining the entity relationship only through the sentence-level feature vector, and can first obtain the preliminary vector of the word in the document based on the relationship extraction model when determining the entity relationship between the entity pairs, and then extract the entity-level feature vector of the entity pair in the document and the document-level feature vector containing the context information of the sentences in the document through the preliminary vector, and combine the entity-level feature vector and the document-level feature vector to determine the entity relationship between the entity pairs in the document, so that the method can combine the context information of the sentences in the document to infer and understand the document as a whole, thereby improving the accuracy of the extracted entity relationship. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 1 is a flow chart of a relationship extraction method in one embodiment;
[0047] Figure 2 A schematic flow chart of a method for extracting entity-level feature vectors of entity pairs in one embodiment;
[0048] Figure 3 Schematic diagram of a method flow for mapping entity pairs to subspaces in another embodiment;
[0049] Figure 4 A schematic flow chart of a method for determining a document-level feature vector in another embodiment;
[0050] Figure 5 A schematic flow chart of a method for obtaining a document-level feature vector in another embodiment;
[0051] Figure 6 A schematic flow chart of a method for determining entity relationships between entity pairs in a document in another embodiment;
[0052] Figure 7 A flowchart of a method for obtaining word vectors after relation extraction in another embodiment;
[0053] Figure 8 is a structural block diagram of a relationship extraction device in one embodiment;
[0054] Figure 9FIG. 1 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0055] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.
[0056] The relationship extraction method provided in this embodiment can be applied to a computer device. The computer device can be an electronic device with image processing capabilities, such as a smartphone, tablet computer, laptop computer, desktop computer, or personal digital assistant. This embodiment does not limit the specific form of the computer device.
[0057] In one embodiment, Figure 1 As shown, a relationship extraction method is provided, which is described by taking the application of the method to a computer device as an example, and includes the following steps:
[0058] S100: Input the word vectors after relation extraction of the document into the relation extraction model to obtain preliminary vectors of the words in the document.
[0059] Specifically, the document's post-relationship extraction word vector can be a document vector obtained by processing the document, where the format of the document vector conforms to the input format of the relational extraction model. The post-relationship extraction word vector can include a vector corresponding to the ordinal position of each word in the document, a vector corresponding to the length of each sentence in the document, a vector corresponding to the ordinal position of each sentence in the document, the ordinal position of each word in the sentence to which it belongs, the character representation corresponding to each word in the document, and so on.
[0060] It is understood that the above-mentioned relationship extraction model can be a deep learning network model, and in this embodiment, it can be a BERT model. The above-mentioned preliminary vector of the word can include various feature vectors of the words in the document and common feature vectors between different words, etc. The computer device can pre-process the document to obtain the word vector after relationship extraction, and input the word vector after relationship extraction into the relationship extraction model to obtain the preliminary vector of the word in the document. The above-mentioned pre-processing can include the processing of removing punctuation marks in the document, the processing of removing paragraph spacing in the document, the processing of removing overlapping words in the document, etc.
[0061] Among them, the computer equipment can preprocess the document to obtain the word vector after relationship extraction, and input the word vector after relationship extraction into the relationship extraction model to first obtain the vector of the word in the document, that is, the word vector after relationship extraction, and further determine the preliminary vector of the word in the document through the word vector after relationship extraction.
[0062] S200 , extracting entity-level feature vectors of entity pairs in the document through preliminary vectors.
[0063] Specifically, the computer device can input the preliminary vectors of the words in the document into the fully connected neural network model to extract the entity-level feature vectors of the entity pairs in the document. It can also perform mapping processing on the preliminary vectors of the words in the document to obtain mapping results, and input the mapping results into the fully connected neural network model to extract the entity-level feature vectors of the entity pairs in the document. Of course, entity-level feature vectors of entity pairs in the document can also be extracted in other ways.
[0064] It can be understood that the above mapping process can be space mapping, equal value mapping or value range mapping, etc.
[0065] S300: Determine a document-level feature vector based on the preliminary vector and the entity-level feature vector.
[0066] Specifically, the computer device may perform arithmetic operations on the preliminary vectors of the characters in the document and the entity-level feature vectors to obtain a document-level feature vector, or may input the preliminary vectors of the characters in the document and the entity-level feature vectors into a neural network model to obtain a document-level feature vector, or may perform arithmetic operations on the preliminary vectors of the characters in the document and the entity-level feature vectors, and input the results of the arithmetic operations into a neural network model to obtain a document-level feature vector, which is not limited in this embodiment. The above-mentioned arithmetic operations may be addition, subtraction, multiplication, or division, etc., or may be a combination of these operations.
[0067] S400: Determine entity relationships between entity pairs in a document using entity-level feature vectors and document-level feature vectors.
[0068] It is understandable that the computer device can pre-assume the entity relationship between the entity pairs in the document, perform arithmetic operations on the entity-level feature vector and the document-level feature vector, and compare the operation result with the preset threshold corresponding to the assumed entity relationship to determine whether the assumed entity relationship is correct, so as to use the correct assumed relationship as the actual entity relationship between the entity pairs in the document, that is, the entity relationship between the entity pairs in the document. The above-mentioned arithmetic operation can be an addition operation, a subtraction operation, a multiplication operation or a division operation, etc., and can also be a combination of these operations. In addition, the arithmetic operation can also be an arithmetic operation performed by a neural network model. That is, the entity-level feature vector and the document-level feature vector can be input into the neural network model for predicting entity relationships to obtain the entity relationship between the entity pairs in the document. In addition, all the neural network models used in this embodiment can be combined into a whole, which is called an entity relationship extraction model.
[0069] In the above-mentioned relationship extraction method, the computer device can input the word vector after relationship extraction of the document into the relationship extraction model to obtain the preliminary vector of the word in the document, extract the entity-level feature vector of the entity pair in the document through the preliminary vector, determine the document-level feature vector based on the preliminary vector and the entity-level feature vector, and determine the entity relationship between the entity pairs in the document through the entity-level feature vector and the document-level feature vector; this method avoids the problem of determining the entity relationship only through the sentence-level feature vector, and can first obtain the preliminary vector of the word in the document based on the relationship extraction model when determining the entity relationship between the entity pairs, and then extract the entity-level feature vector of the entity pair in the document and the document-level feature vector containing the context information of the sentences in the document through the preliminary vector, and combine the entity-level feature vector and the document-level feature vector to determine the entity relationship between the entity pairs in the document, so that the method can combine the context information of the sentences in the document to infer and understand the document as a whole, thereby improving the accuracy of the extracted entity relationship; at the same time, this method can be applied to any type of document, thereby improving the versatility of the relationship extraction method.
[0070] As one example, Figure 2 As shown, the step of extracting entity-level feature vectors of entity pairs in the document using the preliminary vector in S200 can be implemented by the following steps:
[0071] S210 , mapping the entity pair to the subspace using the preliminary vector to obtain a mapping vector, wherein the preliminary vector includes the word vector after relation extraction, the entity type feature vector, and the coreference feature vector.
[0072] Specifically, to improve the entity relationship extraction model's ability to understand the entire document, additional feature vectors can be added to determine the relationship extraction results. These additional feature vectors can include entity type feature vectors and coreference feature vectors. Optionally, the entities in an entity pair can be words in the document, which are composed of multiple characters.
[0073] In this embodiment, the preliminary vector h of the word in the above document is i It can include word vectors after relation extraction, entity type feature vectors and co-reference feature vectors. Among them, the word vectors after relation extraction in the above preliminary vectors can contain the semantic information w of each word in the document, and the dimension of the semantic information w is d w The entity type feature vector introduced in this embodiment enriches the entity information and is conducive to the rapid learning of the entity relationship extraction model. The dimension can be expressed as d t For each word in the same entity, we can assign each word a common reference feature vector, the dimension of which can be expressed as d c , so the initial vectors of the words in the above document are
[0074] It is understood that the subspace can be a portion of the space with a smaller dimension than the full space. If the subspace is a K-dimensional subspace, K can be greater than 2. The computer device can use the preliminary vector to map each entity in the entity pair to the K subspace to obtain a mapping vector. Each entity can correspond to a mapping vector. The number of the mapping vectors can be greater than or equal to 2.
[0075] S220: Input the mapping vector into the first fully connected neural network model to obtain an entity-level feature vector.
[0076] Specifically, the computer device can combine all the mapping vectors and input the combined result into the first fully connected neural network model to obtain the entity-level feature vector I e , the mapping vector corresponding to each entity can also be directly input into the first fully connected neural network model to obtain the entity-level feature vector I e The first fully connected neural network model can be understood as a fully connected layer. The entity-level feature vector I e It can be understood as the relationship feature vector of each entity in the entity pair at the entity level.
[0077] For example, if the entity pair includes entity a and entity b, the mapping vectors obtained by mapping each entity to the K subspace can be expressed as and The vector after combining all the mapping vectors can be expressed as In order to represent the entity relationship extraction model, the entity pair a and b need to be extracted, and the mapping vectors are obtained respectively. and Afterwards, the computer device can use the first fully connected neural network model to obtain the final entity-level feature vector I e , entity-level feature vector I e It can be expressed by the following formula (1):
[0078]
[0079] Among them, w I and b I is the entity-level feature vector I e The corresponding learnable parameters.
[0080] In this embodiment, the entity-level feature vector I e When , the entity type feature vector and the co-reference feature vector are additionally incorporated, thereby accelerating the fitting efficiency of the entity relationship extraction model.
[0081] The above-mentioned relationship extraction method can use the preliminary vector to map the entity pair to the subspace to obtain the mapping vector, input the mapping vector into the first fully connected neural network model to obtain the entity-level feature vector, and then determine the entity relationship between the entity pairs in the document through the entity-level feature vector and the extracted document-level feature vector, so that the method can combine the contextual information of the sentences in the document to infer and understand the document as a whole, thereby improving the accuracy of the extracted entity relationship.
[0082] As one example, Figure 3 As shown, the step of mapping the entity pair to the subspace to obtain the mapping vector using the preliminary vector in S210 may specifically include:
[0083] S211. Calculate the average value of the preliminary vectors to obtain the reference vector of the entity in the entity pair.
[0084] In this embodiment, before mapping the entity pairs to the subspace, vector processing may be performed on the preliminary vectors of the words in the document, and then the vector processing results may be mapped to the subspace.
[0085] Specifically, the computer device may perform arithmetic operations on the preliminary vectors of the words in the document to obtain the reference vectors of each entity in the entity pair.
[0086] In this embodiment, an entity may have multiple references in a document, and a reference may be composed of multiple words in the document. Therefore, the reference vector can be represented by the average value of the preliminary vectors corresponding to all words, and the above arithmetic operation can be an average operation. l The specific expression can be shown as the following formula (2):
[0087]
[0088] Here, the above i represents the i-th word in the reference vector, and l represents the l-th reference vector.
[0089] S212. Calculate the average value of the reference vectors to obtain the entity vector of the entity.
[0090] Specifically, the computer device can perform arithmetic operations on the reference vector to obtain the entity vector of each entity in the entity pair. In this embodiment, an entity may have multiple references in a document, and a reference may be composed of multiple words in the document. Therefore, the entity vector can also be represented by the average value of the reference vectors corresponding to all references. The above arithmetic operation can be an average operation. a The specific expression can be shown as the following formula (3):
[0091]
[0092] S213. Map the entity vector to the subspace to obtain the mapping vector of the entity.
[0093] Specifically, to increase the representation capability of the entity relationship extraction model, the computer device may map the entity vector to the subspace through arithmetic operations to obtain the entity mapping vector. However, in this embodiment, the computer device may use a fully connected layer to map the entity vector to the subspace to obtain the entity mapping vector.
[0094] If the entity pair includes entity a and entity b, then the mapping vectors obtained by mapping each entity to the K-dimensional subspace can be expressed as and in, It can be expressed by the following formula (4):
[0095]
[0096] in, and They are all learnable parameters corresponding to the K-dimensional subspace, and k represents the kth dimension in the K-dimensional space.
[0097] The above-mentioned relationship extraction method can calculate the average value of the preliminary vector to obtain the reference vector of the entity in the entity pair, calculate the average value of the reference vector to obtain the entity vector of the entity, map the entity vector to the subspace to obtain the mapping vector of the entity, and then input the mapping vector into the first fully connected neural network model to obtain the entity-level feature vector, and determine the entity relationship between the entity pairs in the document through the entity-level feature vector and the extracted document-level feature vector, so that the method can combine the contextual information of the sentences in the document to infer and understand the document as a whole, thereby increasing the representation ability of the entity relationship extraction model and further improving the accuracy of the extracted entity relationship.
[0098] As one example, Figure 4 As shown, the step of determining the document-level feature vector based on the preliminary vector and the entity-level feature vector in S300 can be implemented by the following steps:
[0099] S310 , assigning a first weight coefficient to each word in the document, and obtaining a sentence vector of each sentence in the document using the first weight coefficient and a preliminary vector of the word.
[0100] Specifically, if a document contains L sentences, w ij is the numerical representation of the jth word in the i-th sentence. The numerical representation of each word in the document can form a document vector. Different words have different importance in a sentence. Therefore, the computer device can calculate the initial vector h of the word iInput into the fully connected network model, the self-attention mechanism is used to selectively give higher weights to more important words in the document and lower weights to other words, that is, the first weight coefficient a corresponding to each word is obtained. ij , then according to the first weight coefficient a ij Calculate the weight parameter c of the word ij , and then the weighted parameter c ij and the initial vector h of the word ij Perform weighted summation to obtain the sentence vector S of the sentence in the document i The above more important words can be understood as words in the sentence that have a greater impact on the relationship prediction of entity pairs.
[0101] In this step, the first weight coefficient a is obtained ij , weighted parameter c ij and sentence vector S i It can be expressed by the following formulas (5) to (7):
[0102]
[0103]
[0104]
[0105] Among them, u w 、b w (u w 、b w ∈R d ), W w (W w ∈R d×d ) and d are both learnable parameters, which can be randomly initialized by the deep learning model and updated by algorithms such as gradient descent using the loss function. The subscript w can represent the prediction situation; h ij The initial vector representation of each word in the initial vector of the word.
[0106] S320: Input the sentence vector and the entity-level feature vector into a second fully connected neural network model to obtain a sentence-level feature vector.
[0107] Specifically, the computer device can transform the sentence vector S i and entity-level feature vector I e Directly input into the second fully connected neural network model to obtain the sentence-level feature vector I si , you can also use the sentence vector S i and entity-level feature vector I e Combined into a matrix [S i ,I e], then further transform the matrix [S i ,I e ] is input into the second fully connected neural network model to obtain the sentence-level feature vector I si . The matrix [S i ,I e ]After being input into the second fully connected neural network model, the specific calculation process can be expressed by the formula:
[0108] I si =ReLU(W s [S i ,I e ]+b s ) (8);
[0109] Among them, W s 、b s Sentence vector S i The corresponding learnable parameters.
[0110] S330. Obtain a document-level feature vector through the sentence-level feature vector.
[0111] Specifically, the computer device can use the sentence-level feature vector I si Input into the neural network model, the sentence-level feature vector I si Perform arithmetic operations to obtain the document-level feature vector I d The neural network model can be a convolutional neural network model, a recurrent neural network model, a support vector machine model, or the like.
[0112] The above-mentioned relationship extraction method can obtain a document-level feature vector containing the contextual information of the sentences in the document, and then combine the entity-level feature vector and the document-level feature vector to determine the entity relationship between the entity pairs in the document, so as to improve the accuracy of the extracted entity relationship.
[0113] In some scenarios, after obtaining the sentence-level feature vector, in order to make more important sentences have higher weights in the document-level feature vector, the self-attention mechanism can be used to extract the document-level feature vector. Therefore, in the above S330, the step of obtaining the document-level feature vector through the sentence-level feature vector is as follows: Figure 5 Specifically, it may include:
[0114] S331. Input the sentence-level feature vector into the bidirectional long short-term memory recurrent neural network model to obtain the feature vector of the sentence, and use the self-attention mechanism to obtain the second weight coefficient of the sentence.
[0115] Specifically, the computer device can use the sentence-level feature vector I siInput the bidirectional long short-term memory recurrent neural network model and process it with the following formula (9) to obtain the feature vector c of the sentence. si , then according to the feature vector c of the sentence si The self-attention mechanism is used to selectively give higher weights to more important sentences in the document and lower weights to other sentences, and the second weight coefficient z of the sentence is obtained. i The above more important sentences can be understood as sentences in the document that have a greater impact on the relationship prediction of entity pairs.
[0116] The second weight coefficient z of the above sentence i The calculation process of can be expressed by the following formula (10):
[0117] c si =BiLSTM D (I si ),i∈[1,L] (9);
[0118]
[0119] Among them, u s 、b s (u s 、b s ∈R d ) and W s (W s ∈R d×d ) is the sentence vector S i The corresponding learnable parameters are, L, the total number of sentences in the document, T, the transposition operation, and D, the entire document.
[0120] S332: Determine a document-level feature vector using the feature vector of the sentence and the second weight coefficient of the sentence.
[0121] Specifically, the computer device can use the second weight coefficient z of the sentence i Calculate the weight parameter q of the sentence i , then the weighted parameter q of the sentence i and the sentence’s feature vector c si Perform weighted summation to obtain the document-level feature vector I d , I d ∈R d The weighted parameter q of the above sentence is i and document-level feature vector I d The calculation process can be expressed by the formula:
[0122]
[0123]
[0124] Among them, the document-level feature vector I d Represents the information of the entire document, including the context information of the sentences in the document.
[0125] The above-mentioned relationship extraction method can obtain a document-level feature vector containing the contextual information of the sentences in the document, and then combine the entity-level feature vector and the document-level feature vector to determine the entity relationship between the entity pairs in the document, so as to improve the accuracy of the extracted entity relationship.
[0126] As one example, Figure 6 As shown, the step of determining the entity relationship between entity pairs in the document using the entity-level feature vector and the document-level feature vector in S400 may specifically include the following steps:
[0127] S410: Input the entity-level feature vector and the document-level feature vector into a third fully connected neural network model to obtain the relationship probability of each entity relationship between entity pairs.
[0128] Specifically, in order to make full use of feature vectors at different levels, this embodiment can convert the entity-level feature vector I e and document-level feature vector I d Combine to get the matrix [I e ,I d ], the matrix [I e ,I d ] is used as the final vector for calculating the relationship probability P. Among them, the entity-level feature vector I e and document-level feature vector I d Before inputting the third fully connected neural network model, the computer device may first transform the entity-level feature vector I e and document-level feature vector I d By combining the entity-level feature vector I e and document-level feature vector I d The data is directly input into the third fully connected neural network model, and then the relationship probability P is calculated after the combination is performed by the third fully connected neural network model. The specific calculation process of the relationship probability P can be expressed by the formula:
[0129] P(r|E a ,E b )=sigmiod(W r [I e ,I d ]+b r ) (13);
[0130] Among them, r represents the relationship category to which the entity pair belongs, W r and b rare learnable parameters.
[0131] In this embodiment, all fully connected neural network models can be fully connected layers. Before using the entity relationship extraction model, the entity relationship extraction model is first trained to obtain the optimal entity relationship extraction model before use.
[0132] It is understandable that when training the entity relationship extraction model, the preset label is set to y, and each dimension value in y represents an entity relationship. 1 indicates that the relationship exists between the entities in the entity pair, and 0 indicates that the relationship does not exist between the entities in the entity pair. Select a document training set, obtain the relationship labels of all entity pairs in the training set, and convert all relationship labels into triples, namely (head entity, tail entity, entity relationship). For all entity pairs that appear in the paired documents, if there is an entity relationship between the entities in the entity pair, then when the training set is input into the BERT model in the entity relationship extraction model, reserved labels are added, that is, [unused0] and [unused1] are added before and after the head entity, and [unused2] and [unused3] are added before and after the tail entity. In the above way, all references to the same entity in the document are marked, so that the entity relationship extraction model can better understand the overall meaning of the document during the training process. The relationship label is a vector whose dimension is the total number of all entity relationships in the training set plus 1. In a certain dimension, a value of 0 indicates that there is no such relationship between the entities in the entity pair, and a value of 1 indicates that there is such a relationship between the entities in the entity pair. The first value in the relationship label indicates that there is no relationship between the entities in the entity pair. The entity relationship between the entities in the entity pair can be recorded in the relationship label. If there is no relationship between the entities, a 1 is marked on the dimension representing no relationship. For example, if the relationship label is [0, 0, 0, 1], it indicates that the entities in the entity pair are in the fourth type of relationship. If the relationship label is [1, 0, 0, 0], it indicates that the entities in the entity pair are in the first type of relationship. If there is no relationship between the entities in the entity pair, a 1 is also needed to be recorded in the corresponding position of the no relationship.
[0133] During the entity relationship extraction model training process, the preset label y and the relationship label are used to calculate the loss Loss during the model training process through binary cross entropy loss, which can be expressed as:
[0134]
[0135] Among them, y r Represents the true value in the relationship label, and l represents the total number of entity relationships between entities in the entity pair.
[0136] S420: Determine the entity relationship between the entity pairs based on the relationship probability and a preset threshold.
[0137] Specifically, the number of entity relationships between entities in an entity pair may be equal to the number of obtained relationship probabilities. Therefore, the number of preset thresholds may be greater than 0 and less than or equal to the number of relationship probabilities.
[0138] It is understood that the computer device may compare each relationship probability with a corresponding preset threshold value, and determine whether the entity relationship exists between the entity pair based on the comparison result. If so, the entity relationship is determined to be an entity relationship between the entity pair. If the relationship probability is greater than or equal to the corresponding preset threshold value, it can be determined that the entity relationship exists between the entity pair; otherwise, it is determined that the entity relationship does not exist between the entity pair.
[0139] The above-mentioned relationship extraction method can combine entity-level feature vectors and document-level feature vectors to determine the entity relationship between entity pairs in the document, so that the method can determine the entity relationship through the document-level feature vector containing the contextual information of the sentences in the document, thereby improving the accuracy of the extracted entity relationship; at the same time, the method determines the entity relationship through the extracted entity-level feature vectors and document-level feature vectors, which can enhance the learning ability and generalization of the entity relationship extraction model, thereby greatly improving the accuracy of document relationship extraction.
[0140] As one example, Figure 7 As shown, before the above steps, the relationship extraction method further includes the following steps:
[0141] S500, obtaining a document vector of a document;
[0142] Specifically, the above-mentioned document can be any form of document in any different fields, such as Chinese documents, English documents, pure data documents, or a combination of these documents. In particular, a word in English can be called a character in a document. The computer device can convert the characters in the document into a document vector representation, that is, a numerical representation. The above-mentioned document vector can be represented by the parameter D, w is the numerical representation of each word in the document, n is the total number of sentences in the document, T n is the total number of words in the nth sentence, is the Tth sentence in the nth sentence in the document n The numerical value of the word.
[0143] S600: Convert the document vector to obtain a word vector after relation extraction. The word vector after relation extraction includes the expression character input_ids of the word in the document in the relation extraction vocabulary, the filling attribute input_musk of the word in the document, and the sentence sequence number segment_ids of the sentence to which the word belongs in the document.
[0144] In this embodiment, the word vector after relation extraction can be composed of three parts, namely, the expression characters input_ids of the word in the document in the relation extraction vocabulary, the filling attribute input_musk of the word in the document, and the sentence sequence number segment_ids of the sentence to which the word belongs in the document, among which input_ids, input_musk and segment_ids can all represent vectors.
[0145] It is understandable that input_ids can represent the ordinal numbers corresponding to each word in the document in the relational extraction vocabulary, that is, the word segmenter provided by the BERT model can be used to convert each word in the document into input_ids. The above-mentioned relational extraction vocabulary can be understood as a set composed of characters that are mapped to each word in the document. The characters can be numbers, letters, special symbols, etc. Taking numbers as an example, if the word "Apple" is mapped to the number 100, then all "Apple" appearing in the document will be mapped to the number 100. input_musk can indicate whether the element in the document vector is a filler element or the original element corresponding to the word in the document.
[0146] Among them, the word vector after the above relationship extraction expresses the overall information of the document. However, since the BERT model has a limit on the character length of the document, the document vector can be preprocessed to obtain the preprocessing result, and then the preprocessing result is input into the BERT model for subsequent processing. Usually, the maximum character length of the BERT model is limited to 512, so the vector length of input_ids can be fixed to 512. For document vectors that are less than the maximum character length, the elements in input_ids can be padded with 0. For document vectors that exceed the maximum character length, truncation can be performed to make the length of each input_ids 512. In addition, input_musk can represent the padding elements in input_ids and the elements of the document vector itself, where 0 can represent the padding elements in input_ids.
[0147] Additionally, segment_ids represents the sequence number of the sentence to which each word belongs in the document, that is, the position number of the sentence to which each word belongs in the document. The BERT model can classify sentence pairs in a document, using segment_ids to distinguish between the two sentences in the document. A segment_id of 0 represents the first sentence, and 1 represents the second sentence.
[0148] The above-mentioned relationship extraction method can convert documents into relationship-extracted word vectors, that is, obtain vectors that can meet the input format of the BERT model, so that the relationship-extracted word vectors can be quickly processed to determine the entity relationship between entities in the entity pair, thereby improving the efficiency of entity relationship extraction.
[0149] To facilitate understanding by those skilled in the art, specifically, the method includes:
[0150] (1) Get the document vector of the document.
[0151] (2) The document vector is converted to obtain a word vector after relation extraction. The word vector after relation extraction includes the expression characters of the word in the document in the relation extraction vocabulary, the filling attributes of the word in the document, and the sentence sequence number of the sentence to which the word belongs in the document.
[0152] (3) Input the word vectors after relation extraction of the document into the relation extraction model to obtain the preliminary vectors of the words in the document.
[0153] (4) Calculate the average value of the preliminary vectors to obtain the reference vector of the entity in the entity pair, where the preliminary vector includes the word vector after relationship extraction, the entity type feature vector and the coreference feature vector.
[0154] (5) Calculate the average value of the referential vectors to obtain the entity vector of the entity.
[0155] (6) Map the entity vector to the subspace to obtain the mapping vector of the entity.
[0156] (7) Input the mapping vector into the first fully connected neural network model to obtain the entity-level feature vector.
[0157] (8) Assign a first weight coefficient to each word in the document, and obtain a sentence vector of each sentence in the document using the first weight coefficient and the preliminary vector of the word.
[0158] (9) The sentence vector and entity-level feature vector are input into the second fully connected neural network model to obtain a sentence-level feature vector.
[0159] (10) The sentence-level feature vector is input into the bidirectional long short-term memory recurrent neural network model to obtain the feature vector of the sentence, and the self-attention mechanism is used to obtain the second weight coefficient of the sentence.
[0160] (11) Determine the document-level feature vector through the feature vector of the sentence and the second weight coefficient of the sentence.
[0161] (12) The entity-level feature vector and the document-level feature vector are input into the third fully connected neural network model to obtain the relationship probability of each entity relationship between the entity pairs.
[0162] (13) Determine the entity relationship between entity pairs through relationship probability and preset threshold.
[0163] The execution process of the above (1) to (13) can be specifically referred to the description of the above embodiment. The implementation principles and technical effects are similar and will not be repeated here.
[0164] It should be understood that although Figure 1-7 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. In addition, Figure 1-7 At least part of the steps may include multiple steps or multiple stages. These steps or stages are not necessarily performed at the same time, but can be performed at different times. The order of execution of these steps or stages is not necessarily one by one, but can be performed in turn or alternately with other steps or at least part of the steps or stages in other steps.
[0165] In one embodiment, Figure 8 As shown, a relationship extraction device is provided, comprising: a preliminary vector acquisition module 11, a first feature vector acquisition module 12, a second feature vector acquisition module 13 and an entity relationship determination module 14, wherein:
[0166] A preliminary vector acquisition module 11 is used to input the word vectors after relation extraction of the document into the relation extraction model to obtain preliminary vectors of the words in the document;
[0167] A first feature vector acquisition module 12 is used to extract entity-level feature vectors of entity pairs in the document through preliminary vectors;
[0168] A second feature vector acquisition module 13 is used to determine a document-level feature vector based on the preliminary vector and the entity-level feature vector;
[0169] The entity relationship determination module 14 is configured to determine the entity relationship between entity pairs in a document using the entity-level feature vector and the document-level feature vector.
[0170] The relationship extraction device provided in this embodiment can execute the above method embodiment. Its implementation principle and technical effects are similar and will not be repeated here.
[0171] In one embodiment, the first feature vector acquisition module 12 includes: a mapping unit and a network processing unit, wherein:
[0172] A mapping unit, configured to map the entity pair to the subspace using the preliminary vector to obtain a mapping vector;
[0173] The first network processing unit is used to input the mapping vector into the first fully connected neural network model to obtain an entity-level feature vector.
[0174] The relationship extraction device provided in this embodiment can execute the above method embodiment. Its implementation principle and technical effects are similar and will not be repeated here.
[0175] In one embodiment, the mapping unit includes: a first computing subunit, a second computing subunit, and a mapping subunit, wherein:
[0176] A first calculation subunit is configured to calculate an average value of preliminary vectors to obtain a reference vector of an entity in an entity pair, wherein the preliminary vector includes a word vector after relation extraction, an entity type feature vector, and a coreference feature vector;
[0177] A second calculation subunit is used to calculate the average value of the reference vector to obtain the entity vector of the entity;
[0178] The mapping subunit is used to map the entity vector to the subspace to obtain the mapping vector of the entity.
[0179] The relationship extraction device provided in this embodiment can execute the above method embodiment. Its implementation principle and technical effects are similar and will not be repeated here.
[0180] In one embodiment, the second feature vector acquisition module 13 includes: a first computing unit, a second network processing unit, and a second computing unit, wherein:
[0181] a first calculation unit, configured to assign a first weight coefficient to each word in the document, and obtain a sentence vector of each sentence in the document using the first weight coefficient and a preliminary vector of the word;
[0182] A second network processing unit is used to input the sentence vector and the entity-level feature vector into a second fully connected neural network model to obtain a sentence-level feature vector;
[0183] The second computing unit is configured to obtain a document-level feature vector through the sentence-level feature vector.
[0184] The relationship extraction device provided in this embodiment can execute the above method embodiment. Its implementation principle and technical effects are similar and will not be repeated here.
[0185] In one embodiment, the second computing unit includes: a network processing subunit and a feature information determination subunit, wherein:
[0186] The network processing subunit is used to input the sentence-level feature vector into the bidirectional long short-term memory recurrent neural network model to obtain the feature vector of the sentence, and use the self-attention mechanism to obtain the second weight coefficient of the sentence;
[0187] The feature information determination subunit is used to determine a document-level feature vector through the feature vector of the sentence and the second weight coefficient of the sentence.
[0188] The relationship extraction device provided in this embodiment can execute the above method embodiment. Its implementation principle and technical effects are similar and will not be repeated here.
[0189] In one embodiment, the entity relationship determination module 14 includes: a third network processing unit and an entity relationship determination unit, wherein:
[0190] A third network processing unit is used to input the entity-level feature vector and the document-level feature vector into a third fully connected neural network model to obtain the relationship probability of each entity relationship between the entity pairs;
[0191] The entity relationship determination unit is used to determine the entity relationship between entity pairs through relationship probability and a preset threshold.
[0192] The relationship extraction device provided in this embodiment can execute the above method embodiment. Its implementation principle and technical effects are similar and will not be repeated here.
[0193] In one embodiment, the relationship extraction device further includes a document vector acquisition module and a vector conversion module, wherein:
[0194] Document vector acquisition module, used to obtain the document vector of the document;
[0195] The vector conversion module is used to convert the document vector to obtain the word vector after relation extraction. The word vector after relation extraction includes the expression characters of the word in the document in the relation extraction vocabulary, the filling attributes of the word in the document, and the sentence sequence number of the sentence to which the word belongs in the document.
[0196] The relationship extraction device provided in this embodiment can execute the above method embodiment. Its implementation principle and technical effects are similar and will not be repeated here.
[0197] For the specific definition of the relationship extraction device, please refer to the definition of the relationship extraction method above, which will not be repeated here. The various modules in the above-mentioned relationship extraction device can be implemented in whole or in part by software, hardware, and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0198] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 9As shown. The computer device includes a processor, a memory and a network interface connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store documents in various fields. The network interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a relationship extraction method is implemented.
[0199] Those skilled in the art will understand that Figure 9 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.
[0200] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:
[0201] Input the word vectors after relation extraction of the document into the relation extraction model to obtain the preliminary vectors of the words in the document;
[0202] Extract entity-level feature vectors of entity pairs in the document through preliminary vectors;
[0203] Determine the document-level feature vector based on the preliminary vector and the entity-level feature vector;
[0204] The entity relationship between entity pairs in the document is determined through the entity-level feature vector and the document-level feature vector.
[0205] In one embodiment, a readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented:
[0206] Input the word vectors after relation extraction of the document into the relation extraction model to obtain the preliminary vectors of the words in the document;
[0207] Extract entity-level feature vectors of entity pairs in the document through preliminary vectors;
[0208] Determine the document-level feature vector based on the preliminary vector and the entity-level feature vector;
[0209] The entity relationship between entity pairs in the document is determined through the entity-level feature vector and the document-level feature vector.
[0210] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0211] The technical features of the above embodiments can be combined arbitrarily. In order to make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0212] The above-described embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that a person skilled in the art could make various modifications and improvements without departing from the spirit of the present application, all of which fall within the scope of protection of the present application. Therefore, the scope of protection of the present patent application shall be determined by the appended claims.
Claims
1. A relationship extraction method, characterized in that: The method comprises: Input the word vectors after relation extraction of the document into the relation extraction model to obtain preliminary vectors of the words in the document; Inputting preliminary vectors of words in the document into a fully connected neural network model to extract entity-level feature vectors of entity pairs in the document; Inputting the preliminary vector of the word and the entity-level feature vector into a neural network model to obtain a document-level feature vector; or performing an arithmetic operation on the preliminary vector and the entity-level feature vector, and inputting the result of the arithmetic operation into a neural network model to obtain a document-level feature vector; The entity relationship between entity pairs in the document is determined using the entity-level feature vector and the document-level feature vector.
2. The method according to claim 1, characterized in that The extracting the entity-level feature vector of the entity pair in the document by using the preliminary vector includes: Mapping the entity pair to a subspace using the preliminary vector to obtain a mapping vector, wherein the preliminary vector includes a word vector after relation extraction, an entity type feature vector, and a coreference feature vector; the coreference feature vector is a same vector assigned to words within the same entity; The mapping vector is input into a first fully connected neural network model to obtain the entity-level feature vector.
3. The method according to claim 2, characterized in that Mapping the entity pair to a subspace to obtain a mapping vector using the preliminary vector includes: According to the reference corresponding to the entity in the entity pair, the average value of the preliminary vector of each word in the reference is calculated to obtain the reference vector of the entity in the entity pair; the reference refers to different names of the same entity in the document; Calculating an average value of the reference vectors to obtain an entity vector of the entity; The entity vector is mapped to a subspace to obtain a mapping vector of the entity.
4. The method according to any one of claims 1 to 3, characterized in that The document includes a plurality of sentences, each sentence includes a plurality of words; and determining a document-level feature vector based on the preliminary vector and the entity-level feature vector includes: Assigning a first weight coefficient to each word in the sentence in the document, and obtaining a sentence vector for the sentence in the document by using the first weight coefficient and a preliminary vector of each word in the sentence; Inputting the sentence vector and the entity-level feature vector into a second fully connected neural network model to obtain a sentence-level feature vector; The document-level feature vector is obtained through the sentence-level feature vector.
5. The method according to claim 4, characterized in that The step of obtaining the document-level feature vector through the sentence-level feature vector includes: Inputting the sentence-level feature vector into a bidirectional long short-term memory recurrent neural network model to obtain a feature vector of the sentence, and using a self-attention mechanism to obtain a second weight coefficient of the sentence; The document-level feature vector is determined by using the feature vector of the sentence and the second weight coefficient of the sentence.
6. The method according to claim 1, characterized in that Determining the entity relationship between entity pairs in the document using the entity-level feature vector and the document-level feature vector includes: Inputting the entity-level feature vector and the document-level feature vector into a third fully connected neural network model to obtain the relationship probability of each entity relationship existing between the entity pairs; Compare each relationship probability with the corresponding preset threshold. If the relationship probability is greater than or equal to the corresponding preset threshold, it can be determined that the entity relationship exists between the entity pairs. Otherwise, it is determined that the entity relationship does not exist between the entity pairs. The number of preset thresholds is greater than 0 and less than or equal to the number of relationship probabilities.
7. The method according to claim 1, characterized in that The method further comprises: The document is preprocessed to obtain a word vector after relation extraction, wherein the preprocessing includes removing punctuation marks in the document, removing paragraph spacing in the document, and removing overlapping words in the document; the word vector after relation extraction includes the expression characters of the word in the document in the relation extraction vocabulary, the filling attributes of the word in the document, and the sentence sequence number of the sentence to which the word belongs in the document.
8. A relationship extraction device, characterized in that: The device comprises: A preliminary vector acquisition module, configured to input the word vectors after relation extraction of the document into the relation extraction model to obtain preliminary vectors of the words in the document; A first feature vector acquisition module is used to input the preliminary vectors of the words in the document into a fully connected neural network model to extract entity-level feature vectors of entity pairs in the document; A second feature vector acquisition module is configured to input the preliminary vector of the word and the entity-level feature vector into a neural network model to obtain a document-level feature vector; or to perform an arithmetic operation on the preliminary vector and the entity-level feature vector and input the result of the arithmetic operation into a neural network model to obtain a document-level feature vector; The entity relationship determination module is used to determine the entity relationship between entity pairs in the document through the entity-level feature vector and the document-level feature vector.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Chinese named entity recognition method based on reading understanding
CN112101027A
System for searching, recommending, and exploring documents through conceptual associations
US20160012126A1