Document-level entity relationship extraction method and device, electronic equipment and storage medium
The entity-level relationship matrix is constructed through pre-training language models and multi-head attention mechanisms, which solves the problem of ignoring the global information of documents in the existing technology, and realizes the accurate extraction of document-level entity relationships and the understanding of semantic structures.
Patent Information
- Application Number
- CN202510510083.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2024-12-30
- Filing Date
- 2025-04-23
- Publication Date
- 2025-08-08
AI Technical Summary
In the prior art, the entity relationship extraction method focuses more on sentence-level relationship extraction, ignores the global information of the document, especially the interdependent information at the semantic level, and lacks modeling the overall structure of the document.
The text data is encoded by a pre-trained language model, the position of entity words is marked through special characters, combined with the multi-head attention mechanism and the U2Netp model, an entity-level relationship matrix is constructed, and a multi-label classifier is used to extract document-level entity relationships.
It realizes the accurate extraction of document-level entity relationships, comprehensively considers multiple mentions of entity words, the correlation and correlation strength of entity words and text, and improves the understanding of information flow and semantic structure at the document level.
Smart Images

Figure CN120450022A_ABST
Abstract
Description
[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on December 30, 2024, with application number 202411957721.1 and application name “Document-level entity relationship extraction method, device, electronic device and storage medium”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present invention relates to the field of artificial intelligence technology, and in particular to a document-level entity relationship extraction method, device, electronic device and storage medium. Background Art
[0003] Currently, in related technologies, entity relationship extraction methods focus on sentence-level relationship extraction or reasoning information, but ignore the global information of the document, especially the interdependence information at the semantic level, and lack modeling of the overall structure of the document. The complexity of document-level relationship extraction lies in the fact that the information it expresses is not limited to a single sentence, but conveys a complete idea through the mutual connection of sentences in the entire document or chapter. This echoing feature means that even if entity pairs are far apart in the text, there may be some kind of semantic relationship between them. These relationships may be implied through a series of sentences and contextual clues, which are crucial to understanding the meaning of the entire document.
[0004] Therefore, in order to achieve accurate extraction of document-level entity relationships, how to propose a document-level entity relationship extraction method has become a technical problem that needs to be solved urgently. Summary of the Invention
[0005] In view of this, the present invention provides a method that can comprehensively consider various information in a document and perform more accurate document-level relationship extraction based on semantic features that are strongly correlated with entity pairs.
[0006] Specifically, the present invention is implemented through the following technical solutions: According to the first aspect of the present invention, a document-level entity relationship extraction method is provided, comprising: obtaining text data in a document to be processed; encoding the text data using a pre-established pre-trained language model to obtain a feature vector corresponding to the text data, and marking the mention position of each entity word with a special character; performing feature fusion processing on the feature vectors corresponding to multiple mentions of the same entity word in the text data according to the marked position of the special character in the text data to obtain a semantic expression comprehensive vector of the same entity word; using a multi-head attention mechanism to determine the association weight of each entity word with the text data in the document to be processed, as well as the association score of each group of entity pairs with the text data in the document to be processed; based on the semantic expression comprehensive vector, association weight and association score of the entity word, all entity words in the document to be processed are respectively regarded as the first entity and the last entity and matched with the remaining entity words, determining the association strength between each group of entity pairs, and generating an entity pair relationship feature graph according to the association strength; modeling the entity pair relationship feature graph to construct an entity-level relationship matrix; inputting the entity-level relationship matrix into U 2 The Netp model is used to process the expression information of the semantic relationship between different entity words, and the expression information of the semantic relationship between different entity words is processed in a preset manner using a pre-established multi-label classifier model to obtain the extraction result of the entity relationship in the document to be processed.
[0007] In some embodiments, the step of encoding text data using a pre-established pre-trained language model includes: segmenting the text data in the document to be processed to obtain multiple document paragraphs; and encoding each document paragraph separately using the pre-established pre-trained language model.
[0008] In some embodiments, the step of performing feature fusion processing on feature vectors corresponding to multiple mentions of the same entity word in text data includes: extracting the feature vector corresponding to each mention of the entity word; and performing smooth feature fusion processing on the feature vector corresponding to each mention of the entity word using LSE.
[0009] In some embodiments, the preset method includes bilinear calculation and cross entropy loss function calculation.
[0010] In some embodiments, the pre-trained language model includes a Bert-large model.
[0011] In some embodiments, the entity-level relationship matrix is input into U 2 The steps of processing the semantic relationship between different entity words in the Netp model include: converting the entity level relationship matrix into U 2The input format that Netp model can accept and input to U 2 In the Netp model, multiple encoders are used to encode the entity-level relationship matrix. During the encoding process, the RSU module is used to downsample the input entity-level relationship matrix and perform dilated convolution technology to obtain multiple encoded feature maps. Multiple decoders are used to decode the multiple encoded feature maps. During the decoding process, the encoded feature maps are upsampled to restore the encoded feature maps to their original size, generating multiple decoded feature maps. Multiple decoded feature maps are spliced to obtain the expression information of the semantic relationship between different entity words.
[0012] In some embodiments, the downsampling operation includes reducing the height and width dimensions of the entity-level relationship matrix according to a certain ratio, and the upsampling operation includes restoring the size of the feature map using an interpolation algorithm.
[0013] According to the second aspect of the present invention, a document-level entity relationship extraction device is provided, comprising: an encoding module for acquiring text data in a document to be processed; encoding the text data using a pre-established pre-trained language model to obtain a feature vector corresponding to the text data, and marking the mention position of each entity word with a special character; an extraction module for performing feature fusion processing on the feature vectors corresponding to multiple mentions of the same entity word in the text data according to the marked position of the special character in the text data, so as to obtain a semantic expression comprehensive vector of the same entity word; determining the association weight of each entity word with the text data in the document to be processed, and the association score of each group of entity pairs with the text data in the document to be processed using a multi-head attention mechanism; an enhancement module for matching all entity words in the document to be processed as the first entity and the last entity with the remaining entity words based on the semantic expression comprehensive vector, association weight and association score of the entity word, determining the association strength between each group of entity pairs, and generating an entity pair relationship feature graph according to the association strength; modeling the entity pair relationship feature graph, constructing an entity-level relationship matrix; inputting the entity-level relationship matrix into a U 2 The Netp model is used to process the expression information of the semantic relationship between different entity words; the classification module is used to use the pre-established multi-label classifier model to process the expression information of the semantic relationship between different entity words in a preset manner to obtain the extraction result of the entity relationship in the document to be processed.
[0014] According to a third aspect of the present invention, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the document-level entity relationship extraction method in the first aspect or any possible implementation of the first aspect are implemented.
[0015] According to a fourth aspect of the present invention, a storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the document-level entity relationship extraction method in the first aspect or any possible implementation of the first aspect are implemented.
[0016] The technical solution provided by the present invention brings at least the following beneficial effects: In this application, various information in the document can be comprehensively considered to achieve accurate extraction of document-level entity relationships, overcoming the problem of related technologies that only focus on sentence-level relationship extraction while ignoring the document's global information. In addition, by comprehensively considering multiple factors such as the multiple mentions of entity words, the relevance of entity words to the text, and the strength of the association between entity pairs, it helps to more accurately understand the semantic structure of the text and capture the contextual associations between entities, thereby better revealing the information flow at the document level and improving the accuracy of entity relationship extraction in the document to be processed. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0018] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or related technical descriptions. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0019] Figure 1 A flowchart of a document-level entity relationship extraction method provided by an embodiment of the present invention;
[0020] Figure 2 A schematic diagram of the overall framework of the document-level entity relationship extraction device provided by an embodiment of the present invention;
[0021] Figure 3 A schematic diagram of the process of calculating the relevance score using the multi-head attention mechanism provided in an embodiment of the present invention;
[0022] Figure 4 A schematic block diagram of a document-level entity relationship extraction device provided by an embodiment of the present invention
[0023] Figure 5 A block diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0024] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying 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 making creative efforts shall fall within the scope of protection of the present invention.
[0025] See also Figure 1 , an embodiment of the present invention provides a document-level entity relationship extraction method, which may include the following steps:
[0026] S102: Acquire text data in the document to be processed.
[0027] S104: Encode the text data using a pre-established pre-trained language model to obtain a feature vector corresponding to the text data, and mark the mention position of each entity word with special characters.
[0028] S106. Perform feature fusion processing on feature vectors corresponding to multiple mentions of the same entity word in the text data according to the marked positions of the special characters in the text data, so as to obtain a comprehensive semantic expression vector of the same entity word.
[0029] S108. Use a multi-head attention mechanism to determine the association weight between each entity word and the text data in the document to be processed, as well as the association score between each group of entity pairs and the text data in the document to be processed.
[0030] S110. Based on the semantic expression comprehensive vector, relevance weight and relevance score of the entity words, all entity words in the document to be processed are respectively regarded as the first entity and the last entity to be matched with the remaining entity words, the association strength between each group of entity pairs is determined, and the entity pair relationship feature graph is generated according to the association strength.
[0031] S112. Modeling the entity-to-relationship feature graph and constructing an entity-level relationship matrix;
[0032] S114. Input the entity level relationship matrix into U 2 The data is processed in the Netp model to obtain the expression information of the semantic relationship between different entity words.
[0033] S116. Using a pre-established multi-label classifier model, the expression information of the semantic relationship between different entity words is processed according to a preset method to obtain the extraction result of the entity relationship in the document to be processed.
[0034] According to the document-level entity relationship extraction method provided by the present invention, a pre-trained language model is used to encode the text data in the document to be processed. The pre-trained language model has demonstrated strong language understanding and feature representation capabilities in natural language processing tasks. It can automatically learn grammatical, semantic and other information in the text, thereby providing richer and more accurate feature representations for document-level relationship extraction, helping to improve the performance and generalization ability of the model. During the encoding process, special characters are used to mark the location of each entity mention in the text, so that the specific location of each entity in the text can be determined, so that in subsequent processing, information related to the entity can be more accurately associated and analyzed, providing the necessary basic information for subsequent steps such as feature extraction and relationship judgment. Feature fusion processing is then performed on the feature vectors corresponding to multiple mentions of the same entity word, comprehensively considering the multiple mentions of the entity and its contextual information to obtain a more comprehensive and accurate entity semantic expression, thereby more accurately understanding the meaning and role of the entity in the document, and obtaining a more comprehensive, accurate and robust semantic expression vector for the same entity word in the entire document. A multi-head attention mechanism is used to simultaneously evaluate the relevance of a single entity word to the document and the relevance between entity pairs to better capture the content dependencies between different parts of the document. Combined with the semantic expression comprehensive vector, relevance weight and relevance score of entity words, the association strength between all entity word pairs in the document to be processed is calculated, and a feature graph that fully represents all entity relationships in the document is generated based on these association strengths, which provides more intuitive and richer feature information for subsequent feature enhancement and relationship classification, so as to facilitate more accurate analysis and judgment of the relationship between entity pairs in the future. Then, modeling is performed based on the entity pair relationship feature graph, an entity level relationship matrix is constructed, and the entity level relationship matrix is processed, which can more carefully analyze the semantic structure and information distribution in the text, thereby better digging out important information related to the entity pair relationship. Finally, in the document-level relationship extraction task, there may be multiple different relationships between any two entities, and a multi-label classifier is needed to comprehensively judge whether there is a certain specific relationship between them and which specific relationships they are, so as to obtain the final extraction result of the entity relationship in the document to be processed. In this application, various information in the document can be comprehensively considered to achieve accurate extraction of document-level entity relationships, overcoming the problem that the related art only focuses on sentence-level relationship extraction and ignores the global information of the document. In addition, it comprehensively considers multiple factors such as multiple mentions of entity words, the correlation between entity words and text, and the strength of correlation between entity pairs, which helps to more accurately understand the semantic structure of the text and capture the contextual correlation between entities, thereby better revealing the information flow at the document level and improving the accuracy of entity relationship extraction in the document to be processed.
[0035] In some embodiments, the step of encoding text data using a pre-established pre-trained language model includes: segmenting the text data in the document to be processed to obtain multiple document paragraphs; and encoding each document paragraph separately using the pre-established pre-trained language model.
[0036] In this embodiment, by dividing a long document into multiple smaller parts and encoding these parts separately, the problem of excessive length of document-level text can be effectively addressed, enabling the pre-trained language model to better process long documents, avoiding information loss or inaccurate processing due to excessively long documents, improving the model's adaptability and processing capabilities for long documents, and also helping to improve encoding efficiency and accuracy.
[0037] In some embodiments, the step of performing feature fusion processing on the feature vectors corresponding to multiple mentions of the same entity word in the text data includes: extracting the feature vector corresponding to each mention of the entity word; and performing smooth feature fusion processing on the feature vector corresponding to each mention of the entity word using LSE (LogSumExp, logarithmic sum exponential average pooling).
[0038] In this embodiment, the LSE method is used to perform smooth feature fusion on the feature vectors corresponding to multiple mentions of the same entity word. This pooling method provides an approximate result of the smooth maximum value, which is suitable for processing fuzzy or similar feature fusion. In the case of multiple possibilities, it helps to accumulate weak signals from individual mentions without over-focusing on strong signals, thereby obtaining a more accurate and comprehensive entity semantic expression, providing a more reliable foundation for subsequent relationship extraction.
[0039] In some embodiments, the preset method includes bilinear calculation and cross entropy loss function calculation.
[0040] In this embodiment, by using bilinear calculation and cross-entropy loss function calculation methods, entity relationships can be calculated and evaluated more accurately. Bilinear calculation helps to comprehensively consider the fusion information of the feature matrix and the first entity, while cross-entropy loss function calculation improves the performance of entity relationship extraction by enhancing the model's ability to distinguish between target and non-target categories, making the extraction results more accurate and reliable.
[0041] In some embodiments, the pre-trained language model includes a Bert-large (Bidirectional Encoder Representations from Transformers Large, a pre-trained language model based on the Transformer architecture) model.
[0042] In this embodiment, the pre-trained model Bert-large based on Transformer (a sequence-to-sequence model based on the attention mechanism) is used for word embedding and encoding to better capture the semantic information and structural features in the text, providing richer and more effective feature representation for document-level entity relationship extraction.
[0043] In some embodiments, the entity-level relationship matrix is input into U 2 The steps of processing the entity level relationship matrix into U 2 The input format that Netp model can accept and input to U 2 In the Netp model, multiple encoders are used to encode the entity-level relationship matrix. During the encoding process, the RSU (Recurrent Spatial Unit) module is used to downsample the input entity-level relationship matrix and perform dilated convolution technology to obtain multiple encoded feature maps; multiple decoders are used to decode the multiple encoded feature maps. During the decoding process, the encoded feature maps are upsampled to restore the encoded feature maps to their original size, generating multiple decoded feature maps; the multiple decoded feature maps are spliced to obtain the expression information of the semantic relationship between different entity words.
[0044] In this embodiment, the entity level relationship matrix is input into U 2 The Netp model processes the data. Through multiple encoder downsampling operations and dilated convolution techniques, it effectively extracts local features from the matrix and captures more refined semantic connections between entity pairs. The decoder's upsampling helps preserve global semantic information and restore feature map details. Throughout this process, the information transfer from the encoding stage to the decoding stage and the scaling of feature maps enable the model to capture both local and global information. Through in-depth mining and information fusion at multiple stages, more accurate and richer representations of the semantic relationships between different entity words are obtained.
[0045] In some embodiments, the downsampling operation includes reducing the height and width dimensions of the entity-level relationship matrix according to a certain ratio, and the upsampling operation includes restoring the size of the feature map using an interpolation algorithm.
[0046] In this embodiment, the downsampling operation proportionally reduces the height and width dimensions of the entity-level relationship matrix, focusing on more important local features and improving the efficiency and accuracy of feature extraction. The upsampling operation uses an interpolation algorithm to restore the feature map size, restoring it to its original size while preserving important information. This ensures the integrity of global semantic information and provides strong support for ultimately accurate entity relationship extraction.
[0047] The document-level entity relationship extraction method and extraction device in this application are further introduced below in conjunction with a specific embodiment.
[0048] like Figure 2 As shown, the document-level entity relationship extraction device 1 is mainly divided into four sub-modules: a data encoding layer (encoding module 12), a feature extraction layer (extraction module 14), a feature enhancement layer (enhancement module 16) and a relationship classification layer (classification module 18).
[0049] In the encoding layer, a pre-trained language model is used, along with a segmented encoding strategy. This strategy allows the model to segment long documents into multiple sections and encode them separately. During the encoding process, special characters are used to annotate the locations of entity mentions in the text, providing necessary information for subsequent steps.
[0050] Secondly, in the feature extraction layer, the features of multiple mentions of the same entity in the paragraph are smoothly fused according to the annotation position to obtain a more accurate entity semantic expression. Then, the multi-head attention mechanism in the pre-trained model is used to obtain the text content related to all entity pairs, and the word pair feature graph is constructed accordingly.
[0051] The third feature enhancement module uses the semantic segmentation method to enhance the features of the dependent content in the associated text through multiple rounds of upsampling and downsampling operations and the residual structure therein, thereby achieving further extraction of important information.
[0052] Finally, a multi-label classifier is used to extract the relationship between all entity pairs in the document. This classifier combines the information provided by all the previous modules to determine whether there is a specific relationship between any two entities.
[0053] Document-level text encoding:
[0054] Bert-large is used for word embedding, and the special character "$" is inserted before and after each mention of the entity word to facilitate locating the position of each entity mention in the text and the boundaries of the phrase.
[0055] Since the document-level text is too long, a two-step encoding operation is designed for the text. The part that exceeds the encoding length is encoded separately and concatenated with the previous text to support the maximum length of the document data.
[0056] [h1, h2, ..., h k ] = BERT([x1, x2, ..., x k ]);
[0057] Among them, x i For each input word, h i is the feature vector of word encoding, k is the text length, and BERT is a pre-trained language model.
[0058] Smooth fusion of entity mentions:
[0059] For all mentions of each entity word in the text, LSE (LogSumExp) is used to smoothly fuse the different mentions of the same entity. This pooling method provides an approximate result of the smooth maximum value, which is suitable for processing fuzzy or similar feature fusion. In the case of multiple possibilities, it helps to accumulate weak signals from individual mentions without over-focusing on strong signals. The present invention uses the special character code preceding the entity mention as the feature expression of the mention. The fusion method of the entity word is as follows:
[0060]
[0061] Among them, i is the number of entity categories, j is the number of mentions of each entity word in the document, and h is M It means that Represents the semantic expression of the i-th entity word, Ne i is the total number of mentions of the i-th entity in the document, exp represents the exponential function, which is used to calculate the exponential value of the expression in the brackets, and log is the natural logarithm function, which is used to calculate the logarithm value of the expression in the brackets.
[0062] like Figure 3 As shown in Figure 2, the steps for extracting relevant content based on multi-head attention are as follows:
[0063] 1) Through the attention mechanism, we find sentence contents that are highly correlated with entity pairs and remove the noise caused by contents that are irrelevant to entity pairs in the process of entity relationship judgment.
[0064] 2) Word embedding is performed based on the Transformer pre-trained model BERT. Therefore, the model has learned the dependencies between different tokens (special characters) through the multi-head attention mechanism during the encoding phase. Here, the attention calculation results of BERT are directly used.
[0065] 3) Extract the corresponding entity part from the attention matrix of each head to represent the relevance of the entity to the full text. S1 and Sn represent the text content across sentences, E0 and Es are a set of entity pairs with relationships. Each entity has its own related content, and the overlapping part S key It means that the common dependency is obtained by combining the attention scores of the entity pairs, which can serve as a bridge to establish an association relationship between two cross-sentence entities. The specific calculation formula is as follows:
[0066] P=Norm(A i (H,pos(e s ))×A i (H,pos(e0)));
[0067] Among them, E0 and Es represent a set of entity pairs with a relationship, P represents the relevance score between the entity pair (composed of E0 and Es) and the document, Norm represents the normalization operation, which is used to standardize the calculation results to a certain range, and A i Represents the multi-head attention matrix. i represents the index of the attention head, H is the text feature vector, pos(e s ) and pos(e0): respectively represent the positions of entity words E0 and Es in the text, A i (H,pos(e s )) and A i (H, pos(e0)): represents the multi-head attention matrix A i Applied to the text feature vector H, the position of the entity words E0 and Es in the text is considered. The association result with the full text is obtained by combining the position of the entity words in the text, and finally normalized to obtain the relevance score P of the entity pair and the text.
[0068] Based on U 2 Netp's dependency features are enhanced:
[0069] The previous steps can obtain the feature expressions of all entity words in the text, the relevance weight of each entity and the text content, and the relevance score of each group of entity pairs and the text content.
[0070] Based on the above association scores, the entity relationship feature graph is constructed. All entity words in the text are respectively regarded as the first entity and the last entity and matched with the rest of the entity words.
[0071] Using U 2 Netp has the advantage of capturing important features and models the entity pair relationship feature graph that integrates text content. The part of interest that needs to be highlighted is the entity pair area where the relationship exists. Incorporating the association information between entity pairs and text into the matrix as prior knowledge can effectively avoid the influence of irrelevant noise.
[0072] Through the above steps, we can obtain richer semantic features that can provide a basis for entity-pair relationship extraction and construct the entity-level relationship matrix:
[0073] M ER ∈R N×N×D ;
[0074] Among them, M EE represents the entity relationship matrix, D is the dimension of the feature vector, N is the maximum number of entities calculated from all dataset samples, and R represents the set of real numbers.
[0075] Entity relationship matrix M ER Enter U 2 Netp,in the encoding stage, first performs downsampling operation through the first four RSU (Recurrent Spatial Unit) modules,,gradually reducing the matrix size, thereby more effectively,extracting local features in the matrix and capturing finer semantic,connections between entity pairs.
[0076] As the matrix size decreases, dilated convolution is used to expand the receptive field and preserve semantic details without changing the matrix scale. Subsequently, in the decoding stage, the feature map is restored to its original size through upsampling, which not only helps preserve global semantic information but also recovers the details of the feature map.
[0077] Throughout the entire process, each encoding stage passes partial information to the decoding layer, ensuring the flow and utilization of features. Furthermore, by scaling the feature maps, the model is able to simultaneously capture both local and global information. Each RSU module further enhances this capability by scaling the feature maps. After multiple stages of in-depth mining and information fusion, each encoder and decoder outputs a feature map. By concatenating multiple feature maps, the final semantic representation of entity relationships is obtained.
[0078] Entity relationship extraction:
[0079] The feature matrix is fused with the first entity and the final relationship result is calculated through bilinear calculation. The formula is as follows:
[0080] h s =tanh(W s (E s ⊙F E )+b s );
[0081] h0=tanh(W0(E0⊙F E )+b0);
[0082]
[0083] Among them, h s and h o is the output vector of the hidden layer, corresponding to entities E0 and Es respectively, tanh is the hyperbolic tangent activation function, W s 、W o and W r Represents the learning parameter matrix used for dimension change, W s Used to map the input E0⊙Es to the hidden layer hs, W o Used to map the input E0⊙Es to the hidden layer h0, W r Used to calculate the final probability output P(r|e s ,e0),b s 、b o and b r is a learnable offset parameter; F E represents an additional feature vector or mask, which is used to adjust the importance of each feature in E0 and Es. ⊙ is the symbol of element-level multiplication, which means the multiplication of elements at corresponding positions. P(r|e s , e0) represents the probability that a relationship r exists between the given entities E0 and Es. The sigmoid function is used to compress the output between 0 and 1, representing the probability, Indicates the calculation of h s and W r The inner product between h0.
[0084] To enhance the model’s ability to distinguish between target and non-target categories, a mapping function is used to weight the predicted values, and the cross entropy calculation of multi-label classification is implemented by combining the negative and positive class losses:
[0085] y a =(1-2·y t )·P(r|e s , e0);
[0086]
[0087] L=L neg +L pos ;
[0088] Among them, y t is the true label. The ∞ in the formula can adjust the magnitude of the predicted value so that the positive and negative classes can be better distinguished when calculating the cross entropy loss, helping to improve the performance of entity relationship extraction; a Indicates the confidence that there is a certain relationship between entity pairs, P(r|e s , e0) represents the probability that a given entity pair (E0, Es) has a relation r, L negrepresents the logarithmic loss of the negative class (i.e., there is no relationship between entity pairs), L pos represents the logarithmic loss of the positive class (that is, there is a relationship between entity pairs), L represents the total loss value, which is the sum of the negative class loss and the positive class loss, N represents the total number of entity pairs considered when calculating the loss, and ∞ represents a very large number used to adjust the magnitude of the predicted value. In this way, the loss calculation of the positive and negative classes can be made more differentiated in terms of values, thereby better optimizing the model during training.
[0089] In the present application, the complexity of document-level relationship extraction lies in the fact that the information it expresses is not limited to a single sentence, but conveys a complete idea through the mutual connection of sentences in the entire document or chapter. This characteristic of echoing each other means that even if the entity pairs are far apart in the text, there may be some kind of semantic relationship between them. These relationships may be hinted at through a series of sentences and context clues, and these clues are crucial for understanding the meaning of the entire document. Related methods focus more on sentence-level relationship extraction or reasoning information, but ignore the global information of the document, especially the interdependence information at the semantic level, and lack modeling of the overall structure of the document. The method proposed in the present invention integrates local and global semantic dependencies to mine and extract important features in the document, realizes modeling of the overall structure of the document, and performs document-level relationship extraction based on the obtained semantic features that are strongly correlated with the entity pairs.
[0090] Description of the problem in the related technology:
[0091] Determining the relationships between all entity pairs that appear in the entire text is crucial for understanding the semantic structure of the text, capturing the contextual connections between entities, and revealing the flow of information at the document level. This requires overcoming the challenges of document length and information complexity, effectively integrating the important content of each sentence to improve the accurate extraction of entity relationships. Furthermore, it is necessary to effectively cross paragraphs and sentences, consider the global context of entity relationships, and model the overall structure of the document to ensure that accurate understanding of entity relationships is not limited to the local context, but is based on a comprehensive consideration of the document's global information.
[0092] Related technical solutions:
[0093] 1) Edge-oriented graph neural models, which use different types of nodes and edges to create document-level graphs. The reasoning mechanism of graph edges can internally use multi-instance learning to learn intra-sentence and inter-sentence relations.
[0094] 2) A multi-scale neural architecture for document-level relation extraction, combining representations learned across various text spans in the entire document and sub-relation hierarchies.
[0095] 3) Graph-enhanced dual attention network to represent the complex interactions between sentences and potential relation instances, improving cross-sentence reasoning.
[0096] 4) Hierarchical reasoning network, which utilizes multi-granularity reasoning information from entity level, sentence level and document level to obtain and aggregate reasoning information of different granularities.
[0097] The shortcomings of related technologies are described as follows:
[0098] The complexity of document-level relationship extraction lies in the fact that the information it conveys is not limited to a single sentence, but rather conveys a complete idea through the interconnectedness of sentences throughout the entire document or chapter. This interconnectedness means that even entity pairs that are far apart in the text may still have some kind of semantic relationship. These relationships may be implied through a series of sentences and contextual clues, which are crucial for understanding the meaning of the entire document. Existing methods focus more on sentence-level relationship extraction or reasoning information, but ignore the global information of the document, especially the interdependence information at the semantic level, and lack modeling of the overall structure of the document.
[0099] To this end, this application provides a document-level entity relationship extraction method, which is as follows:
[0100] 1) Document-level text encoding:
[0101] Bert-large is used for word embedding, and the special character "$" is inserted before and after each mention of the entity word to facilitate locating the position of each entity mention in the text and the boundaries of the phrase.
[0102] Since the document-level text is too long, a two-step encoding operation is designed for the text. The part that exceeds the encoding length is encoded separately and concatenated with the previous text to support the maximum length of the document data.
[0103] [h1, h2, .., h k ] = BERT([x1, x2, ..., x k ]);
[0104] Among them, x i For each input word, h i is the feature vector of word encoding, k is the text length, and BERT is a pre-trained language model.
[0105] 2) Smooth fusion of entity mentions:
[0106] For all mentions of each entity word in the text, LSE (LogSumExp) is used to smoothly fuse the different mentions of the same entity. This pooling method provides an approximate result of the smooth maximum value, which is suitable for processing fuzzy or similar feature fusion. In the case of multiple possibilities, it helps to accumulate weak signals from individual mentions without over-focusing on strong signals. The present invention uses the special character code preceding the entity mention as the feature expression of the mention. The fusion method of the entity word is as follows:
[0107]
[0108] Among them, i is the number of entity categories, j is the number of mentions of each entity word in the document, and h is M It means mention, h E Represents the semantic expression of entity words, Ne i is the total number of mentions of the i-th entity in the document, exp is the exponential function used to calculate the exponential value of the expression in the brackets, and log is the natural logarithm function used to calculate the logarithm value of the expression in the brackets.
[0109] 3) Extract relevant content based on multi-head attention:
[0110] The attention mechanism is used to find sentence content that is highly correlated with entity pairs, and to remove the noise caused by content that is irrelevant to the entity pairs in the entity relationship judgment process.
[0111] Word embedding is performed based on the Transformer pre-trained model Bert. Therefore, the model has learned the dependencies between different tokens through the multi-head attention mechanism during the encoding stage. Here, the attention calculation results of Bert are directly used.
[0112] The corresponding entity part is extracted from the attention matrix of each head to represent the relevance of the entity to the full text. S1 and Sn represent the text content across sentences, E0 and Es are a set of entity pairs with relationships. Each entity has its own related content, and the overlapping part S key It means that the common dependency is obtained by combining the attention scores of the entity pair, which can serve as a bridge to establish an association relationship between two cross-sentence entities.
[0113] P=Norm(A i (H,pos(e s ))×A i (H,pos(e0)));
[0114] Among them, E0 and Es represent a set of entity pairs with a relationship, P represents the relevance score between the entity pair (composed of E0 and Es) and the document, Norm represents the normalization operation, which is used to standardize the calculation results to a certain range, and A i Represents the multi-head attention matrix; i represents the index of the attention head, H is the text feature vector, pos(e s ) and pos(e0): respectively represent the positions of entity words E0 and Es in the text, A i (H,pos(e s )) and A i (H, pos(e0)): represents the multi-head attention matrix A i Applied to the text feature vector H, the position of the entity words E0 and Es in the text is considered. The association result with the full text is obtained by combining the position of the entity words in the text, and finally the relevance score P of the entity pair and the text is obtained through naturalization.
[0115] 4) Based on U 2 Netp's dependency features are enhanced:
[0116] The previous steps can obtain the feature expressions of all entity words in the text, the relevance weight of each entity and the text content, and the relevance score of each group of entity pairs and the text content.
[0117] Based on the above association scores, the entity relationship feature graph is constructed. All entity words in the text are respectively regarded as the first entity and the last entity and matched with the rest of the entity words.
[0118] Using U 2 Netp has the advantage of capturing important features and models the entity pair relationship feature graph that integrates text content. The part of interest that needs to be highlighted is the entity pair area where the relationship exists. Incorporating the association information between entity pairs and text into the matrix as prior knowledge can effectively avoid the influence of irrelevant noise.
[0119] Through the above steps, we can obtain richer semantic features that can provide a basis for entity-pair relationship extraction and construct the entity-level relationship matrix:
[0120] M ER ∈R N×N×D ;
[0121] Among them, M ER represents the entity relationship matrix, D is the dimension of the feature vector, N is the maximum number of entities calculated from all dataset samples, and R represents the set of real numbers.
[0122] Entity relationship matrix M ER Enter U 2Netp,in the encoding stage, first performs downsampling operation through the first four RSU (Recurrent Spatial Unit) modules,,gradually reducing the matrix size, thereby more effectively,extracting local features in the matrix and capturing finer semantic,connections between entity pairs.
[0123] As the matrix size decreases, dilated convolution is used to expand the receptive field and preserve semantic details without changing the matrix scale. Subsequently, in the decoding stage, the feature map is restored to its original size through upsampling, which not only helps preserve global semantic information but also recovers the details of the feature map.
[0124] Throughout the entire process, each encoding stage passes some information to the decoding layer, ensuring the flow and utilization of features. Furthermore, by scaling the feature maps, the model is able to capture both local and global information simultaneously. This capability is further enhanced by the sub-scaling of the feature maps by each RSU module. After multiple stages of in-depth mining and information fusion, each encoder and decoder outputs a feature map. By concatenating multiple feature maps, the final semantic representation of entity relationships is obtained.
[0125] 5) Entity Relationship Extraction
[0126] The feature matrix is fused with the first entity and the final relationship result is calculated through bilinear calculation. The formula is as follows:
[0127] h s =tanh(W s (E s ⊙F E )+b s );
[0128] h0=tanh(W0(E0⊙F E )+b0);
[0129]
[0130] Among them, h s and h o is the output vector of the hidden layer, corresponding to entities E0 and Es respectively, tanh is the hyperbolic tangent activation function, W s 、W o and W r Represents the learning parameter matrix used for dimension change, W s Used to map the input E0⊙Es to the hidden layer hs, W o Used to map the input E0⊙Es to the hidden layer h0, W r Used to calculate the final probability output P(r|e s ,e0),b s、b o and b r is a learnable offset parameter; F E represents an additional feature vector or mask, which is used to adjust the importance of each feature in E0 and Es. ⊙ is the symbol of element-level multiplication, which means the multiplication of elements at corresponding positions. P(r|e s , e0) represents the probability that a relationship r exists between the given entities E0 and Es. The sigmoid function is used to compress the output between 0 and 1, representing the probability, Indicates the calculation of h s and W r The inner product between h0.
[0131] To enhance the model’s ability to distinguish between target and non-target categories, a mapping function is used to weight the predicted values, and the cross entropy calculation of multi-label classification is implemented by combining the negative and positive class losses:
[0132] y a =(1-2·y t )·P(r|e s , e0);
[0133]
[0134] L=L neg +L pos ;
[0135] Among them, y t is the true label. The ∞ in the formula can adjust the magnitude of the predicted value so that the positive and negative classes can be better distinguished when calculating the cross entropy loss, helping to improve the performance of entity relationship extraction; a Indicates the confidence that there is a certain relationship between entity pairs, P(r|e s , e0) represents the probability that a given entity pair (E0, Es) has a relation r, L neg represents the logarithmic loss of the negative class (i.e., there is no relationship between entity pairs), L pos represents the logarithmic loss of the positive class (that is, there is a relationship between entity pairs), L represents the total loss value, which is the sum of the negative class loss and the positive class loss, N represents the total number of entity pairs considered when calculating the loss, and ∞ represents a very large number used to adjust the magnitude of the predicted value. In this way, the loss calculation of the positive and negative classes can be made more differentiated in terms of values, thereby better optimizing the model during training.
[0136] Based on the same inventive concept, Figure 4As shown, the embodiment of the present invention also provides a document-level entity relationship extraction device 1, including: an encoding module 12, used to obtain text data in a document to be processed; using a pre-established pre-trained language model to encode the text data to obtain a feature vector corresponding to the text data, and marking the mention position of each entity word with a special character; an extraction module 14, used to perform feature fusion processing on the feature vectors corresponding to multiple mentions of the same entity word in the text data according to the marked position of the special character in the text data, so as to obtain a semantic expression comprehensive vector of the same entity word; using a multi-head attention mechanism to determine the association weight of each entity word with the text data in the document to be processed, and the association score of each group of entity pairs with the text data in the document to be processed; an enhancement module 16, used to match all entity words in the document to be processed as the first entity and the last entity with the remaining entity words based on the semantic expression comprehensive vector, association weight and association score of the entity word, determine the association strength between each group of entity pairs, and generate an entity pair relationship feature graph according to the association strength; model the entity pair relationship feature graph, construct an entity-level relationship matrix; input the entity-level relationship matrix into U 2 The Netp model is used to process the expression information of the semantic relationship between different entity words; the classification module 18 is used to use the pre-established multi-label classifier model to process the expression information of the semantic relationship between different entity words in a preset manner to obtain the extraction result of the entity relationship in the document to be processed.
[0137] The implementation process of the functions and effects of each module in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, and will not be repeated here.
[0138] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to the partial description of the method embodiments. The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present invention. A person of ordinary skill in the art can understand and implement the present invention without inventive work.
[0139] Based on the same inventive concept, see Figure 5An embodiment of the present invention further provides an electronic device 2, comprising a memory 20 (e.g., a non-volatile memory), a processor 22, and a computer program stored in the memory 20 and executable on the processor 22. When the processor 22 executes the computer program, it implements the steps of the document-level entity relationship extraction method in any of the possible implementations described above, which may be equivalent to the document-level entity relationship extraction apparatus described above. Of course, the processor may also be used to process other data or perform other operations. The electronic device 2 may be a PC, server, terminal, or other device.
[0140] The electronic device 2 may also generally include: a memory, a network interface, and an internal bus. In addition to these components, it may also include other hardware, which will not be described in detail.
[0141] It should be pointed out that the above-mentioned electronic device can be implemented through software. As a device in a logical sense, it is formed by the processor of the electronic device in which it is located reading the computer program instructions stored in the non-volatile memory into the internal memory for execution.
[0142] Based on the same inventive concept, an embodiment of the present invention further provides a storage medium storing a computer program, which, when executed by a processor, implements the steps of the document-level entity relationship extraction method in any possible implementation manner described above.
[0143] Alternatively, the storage medium may be a non-transitory computer-readable storage medium, for example, a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, and the like.
[0144] Based on the same inventive concept, an embodiment of the present invention further provides a computer program product, including a computer program, which, when executed by a processor, implements the steps of the document-level entity relationship extraction method in any possible implementation manner described above.
[0145] In the embodiments according to the present invention, the terms "first", "second", and "third" are used only for descriptive purposes and are not to be understood as indicating or implying relative importance; the term "plurality" refers to two or more, unless otherwise expressly defined. Terms such as "installed", "connected", "connected", and "fixed" should be understood in a broad sense. For example, "connected" can be a fixed connection, a detachable connection, or an integral connection; "connected" can be a direct connection or an indirect connection through an intermediate medium. For those skilled in the art, the specific meanings of the above terms in the embodiments according to the present invention can be understood according to specific circumstances.
[0146] In addition, although adopting specific order to describe each operation, this should be understood as requiring such operation to be carried out in the specific order or in sequential order, or requiring that all illustrated operations should be carried out to obtain desired result.Under certain environment, multitasking and parallel processing may be advantageous.Similarly, although comprising some specific implementation details in the above discussion, these should not be construed as limiting the scope of the present invention.Some features described in the context of independent embodiment can also be implemented in a single implementation in combination.On the contrary, the various features described in the context of independent implementation also can be implemented in a plurality of implementations individually or in the mode of any suitable subcombination.
[0147] Although the subject matter has been described in the language of specific structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.
[0148] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention. It will be apparent to those skilled in the art that various modifications and variations may be made to the embodiments of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the embodiments of the present invention shall be included within the scope of protection of the embodiments of the present invention.
Claims
1. A document-level entity relationship extraction method, characterized in that: include: Get the text data in the document to be processed; Encoding the text data using a pre-established pre-trained language model to obtain a feature vector corresponding to the text data, and marking the mention position of each entity word with special characters; performing feature fusion processing on the feature vectors corresponding to multiple mentions of the same entity word in the text data according to the marked position of the special character in the text data, so as to obtain a comprehensive semantic expression vector of the same entity word; Determine the association weight of each entity word with the text data in the document to be processed, and the association score of each entity pair with the text data in the document to be processed using a multi-head attention mechanism; Based on the semantic expression comprehensive vector of the entity word, the relevance weight and the relevance score, all entity words in the to-be-processed document are respectively used as the first entity and the last entity to perform matching calculations with the remaining entity words, determine the association strength between each group of entity pairs, and generate an entity pair relationship feature graph according to the association strength; Modeling the entity pair relationship feature graph and constructing an entity level relationship matrix; The entity level relationship matrix is input into the U 2 Processing is performed in the Netp model to obtain the expression information of the semantic relationship between different entity words; The expression information of the semantic relationship between the different entity words is processed in a preset manner using a pre-established multi-label classifier model to obtain an extraction result of the entity relationship in the document to be processed.
2. The document-level entity relationship extraction method according to claim 1, characterized in that: The step of encoding the text data using a pre-established pre-trained language model includes: Segmenting the text data in the document to be processed to obtain a plurality of document paragraphs; Each document paragraph is encoded using the pre-established pre-trained language model.
3. The document-level entity relationship extraction method according to claim 1, characterized in that: The step of performing feature fusion processing on the feature vectors corresponding to multiple mentions of the same entity word in the text data includes: Extracting the feature vector corresponding to each mention of the entity word; The LSE method is used to perform smooth feature fusion processing on the feature vector corresponding to each mention of the entity word.
4. The document-level entity relationship extraction method according to claim 1, characterized in that: The preset method includes bilinear calculation and cross entropy loss function calculation.
5. The document-level entity relationship extraction method according to claim 1, characterized in that: The pre-trained language model includes a Bert-large model.
6. The document-level entity relationship extraction method according to any one of claims 1 to 5, characterized in that: The entity level relationship matrix is input into the U 2 The steps of processing in the Netp model to obtain the expression information of the semantic relationship between different entity words include: Convert the entity-level relationship matrix to U 2 The Netp model accepts input formats and inputs them into the U 2 In the Netp model; The entity-level relationship matrix is encoded using multiple encoders. During the encoding process, the input entity-level relationship matrix is downsampled and processed using the dilated convolution technique using the RSU module to obtain multiple encoded feature maps. Using multiple decoders to decode the multiple encoded feature maps, during the decoding process, upsampling the encoded feature maps to restore the encoded feature maps to their original sizes, thereby generating multiple decoded feature maps; The plurality of decoded feature maps are spliced together to obtain the expression information of the semantic relationship between different entity words.
7. The document-level entity relationship extraction method according to claim 6, characterized in that: The downsampling operation includes reducing the height and width dimensions of the entity-level relationship matrix according to a certain ratio, and the upsampling operation includes restoring the size of the feature map using an interpolation algorithm.
8. A document-level entity relationship extraction device (1), characterized in that: include: An encoding module (12) is used to obtain text data in a document to be processed; encode the text data using a pre-established pre-trained language model to obtain a feature vector corresponding to the text data, and mark the mention position of each entity word with a special character; An extraction module (14) is configured to perform feature fusion processing on the feature vectors corresponding to multiple mentions of the same entity word in the text data according to the marked positions of the special characters in the text data, so as to obtain a comprehensive semantic expression vector of the same entity word; and to determine the association weight of each entity word with the text data in the to-be-processed document, and the association score of each entity pair with the text data in the to-be-processed document, using a multi-head attention mechanism; An enhancement module (16) is configured to perform matching calculations on all entity words in the to-be-processed document as the first entity and the last entity based on the semantic expression comprehensive vector of the entity word, the relevance weight, and the relevance score, determine the relevance strength between each group of entity pairs, and generate an entity pair relationship feature graph based on the relevance strength; Model the entity pair relationship feature graph and construct an entity level relationship matrix; input the entity level relationship matrix into the U 2 Processing is performed in the Netp model to obtain the expression information of the semantic relationship between different entity words; The classification module (18) is used to process the expression information of the semantic relationship between the different entity words in a preset manner using a pre-established multi-label classifier model to obtain the extraction result of the entity relationship in the document to be processed.
9. An electronic device (2), comprising a memory (20), a processor (22), and a computer program stored in the memory (20) and executable on the processor (22), characterized in that: When the processor (22) executes the computer program, the steps of the document-level entity relationship extraction method described in any one of claims 1 to 7 are implemented.
10. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the document-level entity relationship extraction method according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
File structured information extraction method and device, equipment, medium and product
CN120849649A