Document-level relation extraction method, device, equipment and medium
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHENZHEN UNIV
- Filing Date
- 2024-11-12
- Publication Date
- 2026-08-07
AI Technical Summary
该方法产生的图结构较多,由于图结构存在噪声影响,该方法在关系抽取的过程中容易出现偏差现象,使得该方法特征提取不充分,从而导致关系抽取结果不够准确
Smart Images

Figure CN119830911B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of natural language processing technology. More specifically, this application relates to a method, apparatus, device, and medium for extracting document-level relationships. Background Technology
[0002] Traditional document-level relation extraction methods typically follow these steps: obtaining the initial document; preprocessing the text data of the initial document to obtain its encoded features; transforming the encoded features into a graph structure based on heuristic rules; capturing the implicit relationships between entities and sentences in the initial document; and obtaining the semantic relationships between entities in the initial document (i.e., the relation extraction results) through a classifier. The graph structures include mention heterogeneous graphs, entity heterogeneous graphs, and entity-volume heterogeneous graphs. Mention heterogeneous graphs capture the implicit relationships between mentions and sentences, entity heterogeneous graphs capture the implicit relationships between entities and sentences, and entity-mention heterogeneous graphs capture the implicit relationships between entities and mentions; all these implicit relationships are used for feature extraction. This method generates a large number of graph structures, and due to the noise inherent in these graph structures, the method is prone to bias during relation extraction, leading to insufficient feature extraction and inaccurate relation extraction results. Summary of the Invention
[0003] The purpose of this application is to provide a document-level relation extraction method, apparatus, device, and medium, which can enhance feature extraction capabilities and improve the accuracy of relation extraction results. This application is mainly achieved through the following technical solutions:
[0004] A first aspect of this application provides a document-level relation extraction method, including:
[0005] Get the initial document;
[0006] The initial document is tagged to obtain a tagged document, which contains at least one set of entity pairs;
[0007] Based on the tagged document, extract the head entity features, tail entity features, and relation features corresponding to the target entity pair, wherein the target entity pair is any one of the at least one set of entity pairs;
[0008] The IRTE method is used to calculate the head entity features, the tail entity features, and the relation features to obtain a first relation score corresponding to the target entity pair;
[0009] A hybrid expert system is used to analyze and process the first relationship score, the head entity features, the tail entity features, and the relationship features to obtain the final relationship score;
[0010] Based on the final relationship score, the relationship extraction result corresponding to the target entity pair is obtained.
[0011] According to one embodiment of this application, the step of extracting head entity features, tail entity features, and relation features corresponding to target entity pairs based on the tagged document includes:
[0012] The labeled document is encoded using a pre-trained language model to obtain the context embedding vector set and the first attention weight set of the labeled document;
[0013] Extract the head entity features and the tail entity features from all entity pairs in the tagged document;
[0014] The first attention weights corresponding to each entity in the labeled document are aggregated in the first attention weight set by the mean aggregation method to obtain the target attention corresponding to each entity;
[0015] Generate head entity attention and tail entity attention based on all target attention;
[0016] Calculate the second attention weight of the target entity pair based on the head entity attention and the tail entity attention;
[0017] The relational features are calculated based on the set of context embedding vectors and the second attention weights.
[0018] According to one embodiment of this application, the calculation formula for the step of encoding the labeled document using a pre-trained language model to obtain the context embedding vector set and the first attention weight set of the labeled document is as follows:
[0019] H,A=PLM(D=[h1,…,h l ],[a1,..a l ];
[0020] Wherein, H is the set of context embedding vectors, A is the first set of attention weights, PLM is the pre-trained language model, D is the labeled document, h1 is the context embedding vector corresponding to the first word in the labeled document, and h l Let a1 be the context embedding vector corresponding to the l-th word in the labeled document, and a1 be the first attention weight corresponding to the 1-th word in the labeled document. l The first attention weight is the value corresponding to the l-th word in the labeled document.
[0021] According to one embodiment of this application, the step of extracting the head entity features and the tail entity features based on all entity pairs in the tagged document includes:
[0022] Calculate the global representation of all entities in the tagged document;
[0023] The head entity feature is formed by the global representation corresponding to the first entity in all the entity pairs, and the tail entity feature is formed by the global representation corresponding to the second entity in all the entity pairs;
[0024] Each entity obtains its corresponding global representation through logsumexp pooling, calculated using the following formula: Among them, e i For any entity in the tagged document, For entity e i The global representation, For entity e i The number of mentions (i.e., entity e) i (the number of times the marked document appears), Let represent an embedding vector generated at position m for the j-th mention of the i-th entity, and let exp be the natural exponential function. It refers to entity e i The aggregation features, where R d It represents the d-dimensional real space.
[0025] According to one embodiment of this application, the calculation formula for aggregating the first attention weights corresponding to each entity in the labeled document in the first attention weight set using the mean aggregation method to obtain the target attention step corresponding to each entity is as follows:
[0026]
[0027] in, For entity e i attention, For entity e i The number of mentions, For the j-th entity e i The first attention weight corresponding to its location, R h×l This represents an h×l dimensional real space, where h is the number of attention heads and l is the length of the labeled document.
[0028] According to one embodiment of this application, the calculation formula for the step of calculating the second attention weight of the target entity pair based on the head entity attention and the tail entity attention is as follows:
[0029]
[0030] Where, q (s,o) This is the second attention weight. For the head entity attention, For Hadama accumulation, For the tail entity attention, This is the transpose of the attention of the head entity.
[0031] According to one embodiment of this application, the calculation formula for the step of calculating the relation features based on the context embedding vector set and the second attention weight is as follows:
[0032] c (s,o) =H T q (s,o) ;
[0033] Among them, c (s,o) H is the relation feature. T q is the transpose of the set of context embedding vectors. (s,o) This is the second attention weight.
[0034] According to one embodiment of this application, the step of calculating the head entity features, the tail entity features, and the relation features using the IRTE method to obtain the first relation score corresponding to the target entity pair includes:
[0035] The head entity features, the tail entity features, and the relationship features are weighted feature fusion and reshaping to obtain a first image vector;
[0036] An upsampling method is used to enhance the resolution of the first image vector to obtain a second image vector;
[0037] An image feature extraction model is used to extract features from the first image vector and the second image vector to obtain image feature representations;
[0038] The first relationship score is calculated based on the image feature representation.
[0039] According to one embodiment of this application, the calculation formula for the step of performing weighted feature fusion and reshaping on the head entity features, the tail entity features, and the relationship features to obtain the first image vector is as follows:
[0040]
[0041] Among them, F img The first image vector, For the head entity features, For the tail entity feature, c(s,o) Let α be the learnable parameter of the head entity feature, β be the learnable parameter of the tail entity feature, γ be the learnable parameter of the relationship feature, C be the channel of the first image vector, H be the height of the first image vector, and W be the width of the first image vector.
[0042] According to one embodiment of this application, the step of using a hybrid expert system to analyze and process the first relationship score, the head entity features, the tail entity features, and the relationship features to obtain the final relationship score includes:
[0043] The hybrid expert system is used to fuse the head entity features and the relation features to obtain a subject score;
[0044] The hybrid expert system is used to fuse the tail entity features and the relation features to obtain the object score;
[0045] The subject score and the object score are summed to obtain the second relation score;
[0046] The final relationship score is obtained by summing the first relationship score and the second relationship score.
[0047] According to one embodiment of this application, the step of obtaining the relation extraction result corresponding to the target entity pair based on the final relation score includes:
[0048] Obtain preset relationships with multiple probability values and multiple entity relationships;
[0049] The highest predicted probability value in the final relationship score is selected as the target probability value of the target entity.
[0050] Find an entity relationship that corresponds to the target probability value in the preset relationships and use it as the relationship extraction result.
[0051] A second aspect of this application provides a document-level relation extraction apparatus, comprising:
[0052] The initial document retrieval module is used to retrieve the initial document.
[0053] A tagged document acquisition module is used to perform tagging processing on the initial document to obtain a tagged document, wherein the tagged document contains at least one set of entity pairs;
[0054] The feature extraction module is used to extract head entity features, tail entity features and relation features corresponding to target entity pairs based on the tagged document, wherein the target entity pair is any one of the at least one set of entity pairs;
[0055] The first relation score acquisition module is used to calculate the head entity features, the tail entity features and the relation features using the IRTE method to obtain the first relation score corresponding to the target entity pair;
[0056] The final relationship score acquisition module is used to analyze and process the first relationship score, the head entity features, the tail entity features, and the relationship features using a hybrid expert system to obtain the final relationship score;
[0057] The relation extraction result acquisition module is used to obtain the relation extraction result corresponding to the target entity pair based on the final relation score.
[0058] A third aspect of this application provides a terminal device, including a processor and a memory, the memory being used to store a computer program, and the processor being used to call and run the computer program stored in the memory to perform the steps of the document-level relationship extraction method provided in the first aspect of this application.
[0059] A fourth aspect of this application provides a computer-readable storage medium for storing a computer program that causes a computer to perform the steps of the document-level relation extraction method provided in the first aspect of this application.
[0060] The beneficial effects of the embodiments of this application include at least the following:
[0061] This application combines the IRTE method and a hybrid expert system to extract document features, enriching the feature space and making the relation extraction results more accurate. Specifically, this application involves marking an initial document to obtain a marked document, which contains at least one set of entity pairs. Based on the marked document, head entity features, tail entity features, and relation features corresponding to the target entity pair are extracted, where the target entity pair is any one of the at least one set of entity pairs. The IRTE method is used to calculate the head entity features, tail entity features, and relation features to obtain a first relation score corresponding to the target entity pair. A hybrid expert system is used to analyze and process the first relation score, head entity features, tail entity features, and relation features to obtain a final relation score. Finally, the relation extraction result corresponding to the target entity pair is obtained based on the final relation score. Compared with the prior art, this application can more fully capture multiple relationships and complex contextual information in the document. Furthermore, this application does not generate a graph structure, overcoming the noise problem present in traditional methods. Therefore, this application can enhance the feature extraction capability and improve the accuracy of relation extraction results. Attached Figure Description
[0062] To more clearly illustrate the technical solutions in the embodiments of this application or the conventional technology, the drawings used in the description of the embodiments or the conventional technology will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0063] Figure 1 The flowcharts for some embodiments of the document-level relation extraction method of this application are shown below;
[0064] Figure 2 Here are flowcharts of some embodiments of the document-level relation extraction method of this application;
[0065] Figure 3 This is a schematic diagram of the document-level relation extraction device of this application in some embodiments;
[0066] Figure 4 This is a schematic block diagram of the terminal device of this application in some embodiments. Detailed Implementation
[0067] To make the above-mentioned objectives, features, and advantages of this application more apparent and understandable, the specific embodiments of this application are described in detail below with reference to the accompanying drawings. Many specific details are set forth in the following description to provide a thorough understanding of this application. However, this application can be implemented in many other ways different from those described herein, and those skilled in the art can make similar modifications without departing from the spirit of this application. Therefore, this application is not limited to the specific embodiments disclosed below.
[0068] It should be noted that the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, "multiple" means at least two, such as two, three, etc., unless otherwise explicitly specified.
[0069] The terms "exemplary" or "for example" are used to indicate that something is an example, illustration, or illustration. Any embodiment or design described as "exemplary" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of terms such as "exemplary" or "for example" is intended to present the relevant concepts in a specific manner.
[0070] The terms “comprising,” “including,” or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, system, product, or apparatus that includes a series of steps or units is not necessarily limited to those steps or units that are expressly listed, but may include other steps or units that are not expressly listed or that are inherent to such process, method, product, or apparatus.
[0071] Unless otherwise defined, all technical and scientific terms used in this application have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used in this application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. The term "and / or" as used in this application includes any and all combinations of one or more of the associated listed items.
[0072] The specific embodiments of this application will be further described below with reference to the accompanying drawings.
[0073] <Document-level Relationship Extraction Method>
[0074] like Figure 1 and Figure 2 As shown, Figure 1 This is a flowchart illustrating a document-level relation extraction method provided in the first aspect of the embodiments of this application. Figure 2 This is a flowchart of the document-level relation extraction method. Figure 1 The document-level relation extraction method includes:
[0075] S1. Obtain the initial document. This step can be referenced. Figure 2 The "Document" step.
[0076] The initial document can be a Word document, which contains text content.
[0077] S2. The initial document is tagged to obtain a tagged document, wherein the tagged document contains at least one set of entity pairs. This step can be referred to... Figure 2 The "Document Preprocessing" step in the document.
[0078] Specifically, in this application embodiment, the marker symbol "*" is used to emphasize the start and end positions of the mentioned entity (i.e., the entity that appears).
[0079] For example, the initial document states, "In 2023, Zhang San and Li Si jointly founded Company A. Zhang San and Li Si's goal is to promote the development of artificial intelligence. Company A has established a collaboration with University B to support research projects." After processing in step S2, the tagged document states, "In 2023, *Zhang San* and *Li Si* jointly founded *Company A*. *Zhang San* and *Li Si*'s goal is to promote the development of artificial intelligence. *Company A* has established a collaboration with *University B* to support research projects."
[0080] In the example above, the tagged document contains four entity pairs: (Zhang San, Li Si), (Zhang San, Company A), (Li Si, Company A), and (Company A, University B). Among these, (Zhang San, Li Si), (Zhang San, Company A), and (Li Si, Company A) are related entity pairs, while (Company A, University B) is an unrelated entity pair. Among the related entity pairs, the predicted relationship for (Zhang San, Li Si) is a partnership; for (Zhang San, Company A) it is a founder relationship; and for (Li Si, Company A) it is also a founder relationship. However, among the unrelated entity pairs, the predicted relationship for (Company A, University B) is no relationship.
[0081] In this embodiment of the application, D is used to represent the tagged document, that is, the preprocessed document, and the length of the tagged document is l. Therefore, D can be represented as... Where, x t Let t be the word at position t. The initial document contains n entities.
[0082] S3. Extract head entity features, tail entity features, and relation features corresponding to the target entity pair based on the tagged document, wherein the target entity pair is any one of the at least one set of entity pairs.
[0083] Furthermore, the step of extracting head entity features, tail entity features, and relation features corresponding to the target entity pairs based on the tagged documents includes:
[0084] S31. Encode the labeled document using a pre-trained language model to obtain the context embedding vector set and the first attention weight set of the labeled document. Step S31 can be understood as... Figure 2 The "model coding" step in the process.
[0085] The pre-trained language model can be a BERT (Bidirectional Encoder Representations from Transformers) pre-trained language model, a Roberta (Robustly Optimized BERT Pretraining Approach) pre-trained language model, or a DeBerta (Decoding-enhanced BERT with Disentangled Attention) pre-trained language model.
[0086] The pre-trained language model encodes each word in the tagged document into a d-dimensional vector. Therefore, assuming that the document encoding H after the pre-trained language model is [82,768], h1,h2…h 82 These represent the encoding vectors at that position; the dimension of self-attention A is [12, 82, 82], where 12 represents the number of attention heads, and (82, 82) represents the mutual influence between 82 words, i.e., attention. The d-dimensional vector can be a 768-dimensional vector or a 1024-dimensional vector, and the specific dimension can be determined by those skilled in the art according to actual needs.
[0087] Each element in the set of context embedding vectors is a context embedding vector.
[0088] Each element in the first set of attention weights is a first attention weight.
[0089] Furthermore, the calculation formulas for the context embedding vector set and the first attention weight set are as follows:
[0090] H,A=PLM(D=[h1,…,h l ],[a1,..a l ];
[0091] Wherein, H is the set of context embedding vectors, A is the first set of attention weights, PLM is the pre-trained language model, D is the labeled document, h1 is the context embedding vector corresponding to the first word in the labeled document, and h l Let a1 be the context embedding vector corresponding to the l-th word in the labeled document, and a1 be the first attention weight corresponding to the 1-th word in the labeled document. l The first attention weight is the value corresponding to the l-th word in the labeled document.
[0092] It is understandable that in the above formula, H = [h1, ..., h l A = [a1, ... a2] l ].
[0093] S32. Extract the head entity features and the tail entity features from all entity pairs in the tagged document.
[0094] Further, step S32 includes:
[0095] S321. Calculate the global representation of all entities in the tagged document.
[0096] Furthermore, in this embodiment of the application, each entity in the tagged document can obtain its corresponding global representation through logsumexp pooling, as shown in the following formula:
[0097]
[0098] Among them, e i For any entity in the tagged document, For entity e i The global representation, For entity e i The number of mentions (i.e., entity e) i (the number of times the marked document appears), Let represent an embedding vector generated at position m for the j-th mention of the i-th entity, and let exp be the natural exponential function. It refers to entity e i The aggregation features, where R d It represents the d-dimensional real space.
[0099] For example, when the entity is Zhang San and is mentioned twice, the positions of the two occurrences of the entity are denoted as m1 and m2 respectively. The formula for calculating the global representation of this entity can be understood as follows:
[0100]
[0101] Among them, Zhang San is an entity, h 张三 This is the global representation of entity Zhang San. An embedding vector is generated for the first occurrence of entity Zhang San at position m1. An embedding vector is generated for the entity Zhang San at position m2 where it appears for the second time.
[0102] S322. The head entity feature is formed by the global representation corresponding to the first entity in all the entity pairs, and the tail entity feature is formed by the global representation corresponding to the second entity in all the entity pairs.
[0103] Referring to the example document marked as "In 2023, *Zhang San* and *Li Si* co-founded *Company A*. *Zhang San* and *Li Si*'s goal is to advance the development of artificial intelligence. *Company A* has established a collaboration with *University B* to support research projects," the head entity characteristics can be identified as follows: The tail entity features are:
[0104] It should be understood that steps S32 and S33 can be interpreted as... Figure 2 The "entity embedding" step in the process involves aggregating the encoded features of entities that are mentioned multiple times.
[0105] S33. The first attention weights corresponding to each entity in the labeled document are aggregated using the mean aggregation method in the first attention weight set to obtain the target attention corresponding to each entity. The target attention is also the aggregation of the first attention weights of the entity.
[0106] In this embodiment of the application, the first attention weight set is weighted by mean aggregation, focusing on entities e. i The corresponding first attention weights are aggregated to obtain entity e. i The corresponding formula for calculating target attention is as follows:
[0107]
[0108] in, For entity e i attention, For entity e i The number of mentions, For the j-th entity e i The first attention weight corresponding to its location, R h×l This represents an h×l dimensional real space, where h is the number of attention heads and l is the length of the labeled document.
[0109] For example, referring to the document marked as "In 2023, *Zhang San* and *Li Si* co-founded *Company A*. *Zhang San* and *Li Si*'s goal is to advance the development of artificial intelligence. *Company A* has established a collaboration with *University B* to support research projects," the formula for calculating the target attention corresponding to the entity "Zhang San" is as follows:
[0110]
[0111] Where A 张三 For the target attention of entity "Zhang San", N 张三 The number of mentions of the entity "Zhang San". For the j-th entity e i The first attention weight corresponding to its location, R h×l This represents an h×l dimensional real space, where h is the number of attention heads and l is the length of the labeled document. Assuming the entity "Zhang San" appears twice in the labeled document, it can be represented as... The first attention weight is the weight corresponding to the location of the first entity "Zhang San". The first attention weight is the weight corresponding to the location of the second entity "Zhang San".
[0112] The formula for calculating the target attention corresponding to the entity "Li Si" is as follows:
[0113]
[0114] Where A 李四 For the target attention of entity "Li Si", N 李四 The number of mentions of the entity "Li Si" For the j-th entity e i The first attention weight corresponding to its location, R h×l This represents an h×l dimensional real space, where j is the number of attention heads and l is the length of the labeled document.
[0115] The formula for calculating the target attention for entity "Company A" is as follows:
[0116]
[0117] Where A A The company's target attention is for entity "Company A", N A The number of mentions of the entity "Company A" For the j-th entity e i The first attention weight corresponding to its location, R h×l This represents an h×l dimensional real space, where h is the number of attention heads and l is the length of the labeled document.
[0118] The formula for calculating the target attention corresponding to entity "University B" is as follows:
[0119]
[0120] Where A B The university is the target of attention for entity "University B", N B The number of mentions of the entity "University B" For the j-th entity e iThe first attention weight corresponding to its location, R h×l This represents an h×l dimensional real space, where h is the number of attention heads and l is the length of the labeled document.
[0121] S34. Generate head entity attention and tail entity attention based on all target attention.
[0122] In this embodiment of the application, the head entity attention is represented as The tail entity attention is represented as
[0123] S35. Calculate the second attention weight of the target entity pair based on the head entity attention and the tail entity attention.
[0124] This application embodiment uses a summation and averaging method to calculate the aggregated entity pair (i.e., the target entity pair) (e s ,e o The second attention weight.
[0125] Specifically, the calculation formula for step S35 is as follows:
[0126]
[0127] Where, q (s,o) This is the second attention weight. For the head entity attention, For Hadama accumulation, For the tail entity attention, This is the transpose of the attention of the head entity.
[0128] q (s,o) It is a distribution that reveals each word pair to entity pair (e s ,e o The weight (i.e. importance) of ).
[0129] S36. Calculate the relation features based on the context embedding vector set and the second attention weight.
[0130] The calculation formula for S36 is as follows:
[0131] c (s,o) =H T q (s,o) ;
[0132] Among them, c (s,o) H is the relation feature. T q is the transpose of the set of context embedding vectors. (s,o) This is the second attention weight. (s,o)It is also a weighted average of the codes for all words.
[0133] The steps can be understood as follows: Figure 2 The "local context pooling" step in the code. Local context pooling is the aggregation of attention weights for entities mentioned multiple times.
[0134] S4. Calculate the head entity features, tail entity features, and relation features using the IRTE method to obtain the first relation score corresponding to the target entity pair. Step S4 can be understood as... Figure 2 The "IRTE cross-modal feature fusion" step in the process.
[0135] The IRTE method aims to enrich the extracted text features through the application of cross-modal feature transformation and image feature extraction models (i.e., pre-trained image models).
[0136] Further, step S4 includes:
[0137] S41. Perform weighted feature fusion and reshaping on the head entity features, the tail entity features and the relationship features to obtain the first image vector.
[0138] It should be understood that the first image vector is similar to image information. Assuming that before step S41 is executed, the dimensions of the head entity feature, the tail entity feature, and the relation feature are all [82, 768], and after step S41 is executed, the dimensions of the head entity feature, the tail entity feature, and the relation feature are all [82, 32, 24], thus making the dimension of the first image vector [82, 3, 32, 24].
[0139] Furthermore, the calculation formula for step S41 is as follows:
[0140]
[0141] Among them, F img The first image vector, For the head entity features, For the tail entity feature, c (s,o) Let α be the learnable parameter of the head entity feature, β be the learnable parameter of the tail entity feature, γ be the learnable parameter of the relationship feature, C be the channel of the first image vector, H be the height of the first image vector, and W be the width of the first image vector.
[0142] S42. Upsampling is used to enhance the resolution of the first image vector to obtain the second image vector.
[0143] When the dimension of the first image vector is [82,3,32,24], the dimension of the second image vector is [82,3,64,48].
[0144] Furthermore, the calculation formula for step S42 is as follows:
[0145] F img-up =UpSampling(F img );
[0146] Among them, F img-up Let F be the second image vector. img Let be the first image vector, and UpSampling be the upsampling method.
[0147] S43. Use an image feature extraction model to extract features from the first image vector and the second image vector to obtain image feature representation.
[0148] The image feature extraction model can be a Dinov2 model, a Vit model, or a ConvnextV model. The Dinov2 model is based on a Transformer architecture; a Transformer is a model that uses an attention mechanism to process sequential data. The Vit model (Vision Transformer) is a self-attention model used for image tasks. The Vit model applies the Transformer model from natural language processing to image processing, using a self-attention mechanism to process image data. The ConvnextV model aims to incorporate some successful design concepts from the Vision Transformer (ViT) into a pure convolutional neural network to improve its performance.
[0149] In other embodiments, the image feature extraction model may be other models, which can be determined by those skilled in the art according to actual needs.
[0150] The dimensions of the image feature representation are [82, 512].
[0151] Furthermore, the calculation formula for step S43 is as follows:
[0152] R img =Model(F img )+Model(F img-up );
[0153] Among them, R img Let F be the image feature representation, Model be the image feature extraction model, and F be the image feature representation. img Let F be the first image vector. img-upThis is the second image vector.
[0154] S44. Calculate the first relationship score based on the image feature representation.
[0155] This application embodiment uses a linear layer to obtain the first relation score of the IRTE method.
[0156] Specifically, the calculation formula for S44 is as follows:
[0157] logit IRTE =Linear(R) img );
[0158] Among them, logit IRTE Score the first relationship, where Linear is a linear function and R is the sum of its components. img This represents the image features.
[0159] S5. A hybrid expert system is used to analyze and process the first relationship score, the head entity features, the tail entity features, and the relationship features to obtain the final relationship score. Step S5 can be understood as... Figure 2 The "Hybrid Expert System Enhancement Features" step in the process.
[0160] The Mixture of Experts (MoE) system is an architecture that improves the predictive performance and efficiency of a model by combining multiple sub-models (called "experts"). The MoE system includes expert networks and a gating mechanism. The expert networks are responsible for in-depth analysis and processing of the input features, while the gating mechanism (Gate) is responsible for weighting the outputs of the expert networks, selecting the k experts with the highest weights for output. Assume that the input feature x is processed by multiple expert networks f. i (x) is processed so that each expert i produces an output.
[0161] Each expert network in the hybrid expert system consists of a linear transformation layer, a GELU activation function, and a layer normalization layer. The gating mechanism consists of a linear layer and a Tanh activation function.
[0162] The gating mechanism is responsible for assigning weights to each expert. The specific formula for calculating the expert weights is as follows:
[0163]
[0164] Among them, w i The weights for each expert are defined, g(x) represents the gating mechanism (i.e., the gating score for expert i), and k represents the number of experts selected. Let g(x) be the exponential function value of the gating mechanism for expert i.
[0165] The formula for calculating the expert weights ultimately outputs the weighted sum of the selected experts' outputs.
[0166] Further, step S5 includes:
[0167] S51. The hybrid expert system is used to fuse the head entity features and the relation features to obtain the subject score.
[0168] In this embodiment of the application, four expert networks are set up in the MoE method (i.e., the hybrid expert system) to fuse the head entity features (i.e., the subject representation) and the relation features to form a context-enhanced representation of the subject (i.e., the subject score).
[0169] Furthermore, the calculation formula for step S51 is as follows:
[0170]
[0171] Among them, logit s The subject is scored; MoE is a hybrid expert system method. For the head entity feature, c (s,o) This refers to the relational feature.
[0172] S52. The hybrid expert system is used to fuse the tail entity features and the relation features to obtain the object score.
[0173] In this embodiment of the application, four expert networks are set up in the MoE method to fuse the tail entity features (i.e., object representation) and the relation features to form a context-enhanced representation of the object (i.e., the object score).
[0174] Furthermore, the calculation formula for step S52 is as follows:
[0175]
[0176] Among them, logit o For scoring the object, MoE is a hybrid expert system method. For the tail entity feature, c (s,o) This refers to the relational feature.
[0177] S53. Summing the subject score and the object score yields the second relation score.
[0178] Furthermore, the calculation formula for step S53 is as follows:
[0179] logit MoE =logits +logit o ;
[0180] Among them, logit MoE For the second relation score (i.e., the relation classification score using the hybrid expert system method), logit s Rate the subject, logit o Rate the object.
[0181] S54. Calculate the sum of the first relationship score and the second relationship score to obtain the final relationship score.
[0182] Furthermore, the calculation formula for step S54 is as follows:
[0183] logit = logit IRTE +logit MoE ;
[0184] Wherein, logit is the final relationship score, logit IRTE Score the first relationship, logit MoE Score the second relationship.
[0185] S6. Based on the final relationship score, obtain the relationship extraction result corresponding to the target entity pair. S6 can be understood as... Figure 2 The "relationship prediction" step in the process.
[0186] Further, step S6 includes:
[0187] S61. Obtain preset relationships with multiple probability values and multiple entity relationships.
[0188] For example, if the multiple probability values are 0.7, 0.1, and 0.2, and the multiple entity relationships are partnership, founder, and no relationship, then the preset relationship is 0.7 for partnership, 0.1 for founder, and 0.2 for no relationship.
[0189] S62. Select the highest predicted probability value from the final relationship score as the target probability value of the target entity.
[0190] For example, if the final relationship score is logit = [0.7, 0.1, 0.2], then the largest predicted probability value of 0.7 is selected as the target probability value.
[0191] S63. Find an entity relationship in the preset relationship that corresponds to the target probability value as the relationship extraction result.
[0192] Based on the above example, since a probability value of 0.7 corresponds to a partnership relationship, the partnership relationship is used as the result of the relationship extraction.
[0193] By employing the above technical solutions, this application combines the IRTE method and a hybrid expert system to extract document features, thereby enriching the feature space and making the relation extraction results more accurate. Compared with existing technologies, this application can more fully capture multiple relationships and complex contextual information in documents. Furthermore, this application does not generate a graph structure, overcoming the noise impact problem present in traditional methods. Therefore, this application can enhance feature extraction capabilities and improve the accuracy of relation extraction results.
[0194] In some implementations, after step S5, the document-level relation extraction method further includes:
[0195] S71. Divide the at least one set of entity pairs into two types: related entity pairs and unrelated entity pairs.
[0196] For example, referring to the document tagged as "In 2023, *Zhang San* and *Li Si* jointly founded *Company A*. The goal of *Zhang San* and *Li Si* is to promote the development of artificial intelligence. *Company A* has established a collaboration with *University B* to support research projects," then (Zhang San, Li Si), (Zhang San, Company A), and (Li Si, Company A) are classified as the related entity pair, and (Company A, University B) is classified as the unrelated entity pair.
[0197] S72. Perform a comparative learning operation on the related entity pairs and the unrelated entity pairs to obtain a comparative loss. S72 can be referenced from... Figure 2 The "contrastive learning" step in the process.
[0198] Further, step S72 includes:
[0199] S721. The related entity pairs are recorded as positive samples, and the unrelated entity pairs are recorded as negative samples.
[0200] Based on the example of step S71, (Zhang San, Li Si), (Zhang San, Company A), and (Li Si, Company A) are recorded as positive samples, and (Company A, University B) is recorded as a negative sample.
[0201] S722. Calculate the positive sample similarity using cosine similarity.
[0202] Furthermore, the calculation formula for step S722 is as follows:
[0203]
[0204] Where, positive represents the positive sample similarity, and "·" denotes the dot product of two vectors. c represents the head entity feature corresponding to the positive sample. (s,o) The relational features are as follows: The tail entity features corresponding to the positive sample. For vectors The 2-norm, For vectors The 2-norm.
[0205] Based on the example of step S721,
[0206] The L2 norm, also known as the Euclidean norm or L2 norm, is one of the most commonly used norms in vector spaces.
[0207] S723. Calculate the negative sample similarity of the negative samples using cosine similarity.
[0208] Furthermore, the calculation formula for step S723 is as follows:
[0209]
[0210] Where, negative represents the negative sample similarity, and "·" denotes the dot product of two vectors. For the head entity feature, c (s,o) The relational features are as follows: The relational features are as follows: For vectors The 2-norm, For vectors The 2-norm.
[0211] Based on the example of step S721,
[0212] S724. Calculate the contrast loss by combining the positive sample similarity and the negative sample similarity.
[0213] Specifically, the calculation formula for S724 is as follows:
[0214]
[0215] Among them, Loss contrastive The contrast loss is defined as mean, which represents the summation and averaging, exp is an exponential function with the natural constant e as the base, positive is the positive sample similarity, and negative is the negative sample similarity.
[0216] The embodiments of this application adjust the parameters of the image feature extraction model based on the contrast loss, so that the image feature extraction model can output a more accurate image feature representation.
[0217] Contrastive learning enhances a model’s ability to distinguish between different relation categories by calculating the cosine similarity between positive and negative samples.
[0218] In some implementations, after step S72, the document-level relation extraction method further includes:
[0219] S81. Set the threshold for TH class.
[0220] For example, the threshold is 0.5. In other embodiments, the specific value of the threshold can be determined by those skilled in the art based on actual needs.
[0221] The TH class is a specific class, and the threshold is an adaptive threshold for each sample.
[0222] S82. If the maximum predicted probability of the relationship corresponding to the target related entity pair is greater than the threshold, the target related entity pair is classified as a positive class; if the maximum predicted probability of the relationship corresponding to the target related entity pair is less than or equal to the threshold, the target related entity pair is classified as a negative class, where the target related entity pair is any pair of related entity pairs among all related entity pairs; all unrelated entity pairs are classified as negative classes.
[0223] The positive class can be understood as a class with a relationship, and the negative class can be understood as a class without a relationship.
[0224] For example, all related entity pairs include (Zhang San, Li Si), (Zhang San, Company A), and (Li Si, Company A), where the maximum predicted probability of the relationship corresponding to (Zhang San, Li Si) is 0.7, the maximum predicted probability of the relationship corresponding to (Zhang San, Company A) is 0.4, and the maximum predicted probability of the relationship corresponding to (Li Si, Company A) is 0.8. All unrelated entity pairs include (Company A, University B), whose maximum predicted probability of relationship is 0.9. Based on a threshold of 0.5, it can be determined that the positive class includes (Zhang San, Li Si) and (Li Si, Company A), and the negative class includes (Zhang San, Company A) and (Company A, University B).
[0225] S83. Calculate the corresponding positive class probability value based on the positive class.
[0226] Furthermore, the calculation formula for step S83 is as follows:
[0227]
[0228] Wherein, P(r)i ) represents the positive class probability value. For category r, which is positive i The probability score, where T is the temperature parameter. The probability score for category TH.
[0229] S84. Calculate the corresponding negative class probability value based on the negative class.
[0230] Furthermore, the calculation formula for step S84 is as follows:
[0231]
[0232] Wherein, P(r) TH ) represents the negative class probability value. For probability scores of category TH, For categories TH and negative categories N T The probability score, N T TH is the threshold value, which represents a subset of the negative class.
[0233] S85. Calculate the classification loss function based on the positive class probability value and the negative class probability value.
[0234] Furthermore, the calculation formula for step S85 is as follows:
[0235]
[0236] Among them, Loss AGL Let P be the classification loss function. T For a positive subset, P(r) i ) represents the positive class probability value, P(r) TH ) represents the negative class probability value, and γ is a dynamic value; more specifically, γ = initial γ *(1+decay rate *epoch), initial γ The initial value is decay. rate is the decay rate, and epoch is the number of times the model has been trained.
[0237] S86. Calculate the total loss based on the classification loss function and the contrastive loss. Step S86 can be understood as follows: Figure 2 The "AGL loss function calculation" step in the document.
[0238] Furthermore, the calculation formula for S86 is as follows:
[0239] Loss RE =Loss AGL +αLoss contrastive ;
[0240] Among them, Loss RE For the total loss, Loss AGL For the classification loss function, Loss contrastive Let α be the contrast loss, and α be a learnable parameter.
[0241] The total loss is used to adjust the parameters of the document-level relation extraction model, including the parameters of the pre-trained language model, the IRTE method, the hybrid expert system, and other network structures.
[0242] In this embodiment, both the contrastive loss and the total loss are adaptively and dynamically adjusted loss functions. Both can continuously optimize the model in each iteration, improving the model's convergence speed and performance. Furthermore, by utilizing contrastive learning and the AGL loss function, this embodiment can better handle long-tailed category problems and enhance the model's ability to identify rare relationships.
[0243] <Document-level relation extraction device>
[0244] like Figure 3 The diagram shown is a schematic block diagram of a document-level relationship extraction device provided in the second aspect of an embodiment of this application. Figure 3 In the document-level relation extraction device 100, the document-level relation extraction device includes:
[0245] Initial document acquisition module 101 is used to acquire the initial document;
[0246] The tagged document acquisition module 102 is used to perform tagging processing on the initial document to obtain a tagged document, wherein the tagged document contains at least one set of entity pairs;
[0247] The feature extraction module 103 is used to extract head entity features, tail entity features and relation features corresponding to target entity pairs based on the tagged document, wherein the target entity pair is any one of the at least one set of entity pairs;
[0248] The first relation score acquisition module 104 is used to calculate the head entity features, the tail entity features and the relation features using the IRTE method to obtain the first relation score corresponding to the target entity pair;
[0249] The final relationship score acquisition module 105 is used to analyze and process the first relationship score, the head entity features, the tail entity features and the relationship features using a hybrid expert system to obtain the final relationship score;
[0250] The relation extraction result acquisition module 106 is used to obtain the relation extraction result corresponding to the target entity pair based on the final relation score.
[0251] Terminal Equipment
[0252] A third aspect of this application provides a terminal device, the schematic diagram of which is as follows: Figure 4 As shown. The terminal device includes a processor, memory, network interface, display screen, and temperature sensor connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The network interface of the terminal device is used for communication with external terminals via a network connection. When the computer program is executed by the processor, it implements a document-level relation extraction method. The display screen can be a liquid crystal display (LCD) or an e-ink display. The temperature sensor is pre-installed inside the terminal device to detect the operating temperature of the internal components.
[0253] Those skilled in the art will understand that Figure 4 The schematic diagram shown is only a partial structural diagram related to the present invention and does not constitute a limitation on the terminal device to which the present invention is applied. The specific terminal device may include more or fewer components than shown in the figure, or combine certain components, or have different component arrangements.
[0254] In some embodiments, this application provides a terminal device, including a processor and a memory, the memory for storing a computer program, and the processor for calling and running the computer program stored in the memory to perform the steps of the document-level relation extraction method provided in the first aspect of this application.
[0255] Computer-readable storage media
[0256] A fourth aspect of this application provides a computer-readable storage medium for storing a computer program that causes a computer to perform the steps of the document-level relation extraction method provided in the first aspect of this application.
[0257] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided by this invention can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM), etc.
[0258] The technical features of the above embodiments can be combined without changing the basic principles of this application. For the sake of brevity, 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.
[0259] The above embodiments merely illustrate several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the patent protection scope of this application should be determined by the appended claims.
Claims
1. A document-level relation extraction method, characterized in that, include: Get the initial document; The initial document is tagged to obtain a tagged document, which contains at least one set of entity pairs; Based on the tagged document, extract the head entity features, tail entity features, and relation features corresponding to the target entity pair, wherein the target entity pair is any one of the at least one set of entity pairs; The IRTE method is used to calculate the head entity features, the tail entity features, and the relation features to obtain a first relation score corresponding to the target entity pair; A hybrid expert system is used to analyze and process the first relationship score, the head entity features, the tail entity features, and the relationship features to obtain the final relationship score; Based on the final relationship score, obtain the relationship extraction result corresponding to the target entity pair; The steps of extracting head entity features, tail entity features, and relation features corresponding to target entity pairs based on the labeled document include: encoding the labeled document using a pre-trained language model to obtain a context embedding vector set and a first attention weight set for the labeled document; extracting the head entity features and tail entity features based on all entity pairs in the labeled document; aggregating the first attention weights corresponding to each entity in the labeled document using a mean aggregation method to obtain the target attention corresponding to each entity; generating head entity attention and tail entity attention based on all target attentions; calculating the second attention weights of the target entity pairs based on the head entity attention and tail entity attention; and calculating the relation features based on the context embedding vector set and the second attention weights.
2. The document-level relation extraction method according to claim 1, characterized in that, The calculation formula for the step of encoding the labeled document using a pre-trained language model to obtain the context embedding vector set and the first attention weight set of the labeled document is as follows: ;in, The context embeds a set of vectors. For the first set of attention weights, For the pre-trained language model, For the tagged document, The context embedding vector corresponding to the first word in the tagged document. For the tagged document, the first The context embedding vector corresponding to each word The first attention weight is the first word in the labeled document. For the tagged document, the first The first attention weight corresponding to each word; The step of extracting the head entity feature and the tail entity feature based on all entity pairs in the tagged document includes calculating the global representation of all entities in the tagged document; the head entity feature is constructed from the global representation corresponding to the first entity in all entity pairs, and the tail entity feature is constructed from the global representation corresponding to the second entity in all entity pairs; wherein, each entity obtains its corresponding global representation through logsumexp pooling, and the calculation formula is as follows: ;in, For any entity in the tagged document, For entities The global representation, For entities The number of mentions, Indicates the first The first entity The second mention is in its location An embedding vector is generated at this point, and the exp function is the natural exponential function. It refers to entities The aggregation characteristics, where, It means 3D real space; The first attention weights in the first attention weight set corresponding to each entity in the labeled document are aggregated using the mean aggregation method. The calculation formula for the target attention step corresponding to each entity is as follows: ;in, For entities attention, For entities The number of mentions, For the first individual entities The first attention weight corresponding to its location, , It means 3D real space, For the number of attention heads, The length of the tagged document; The calculation formula for the second attention weight of the target entity pair based on the head entity attention and the tail entity attention is as follows: ;in, This is the second attention weight. For the head entity attention, For Hadama accumulation, For the tail entity attention, This is the transpose of the attention of the head entity.
3. The document-level relation extraction method according to claim 2, characterized in that, The calculation formula for the step of calculating the relation features based on the context embedding vector set and the second attention weight is as follows: ; in, The relational features are as follows: The transpose of the context embedding vector set. This is the second attention weight.
4. The document-level relation extraction method according to claim 1, characterized in that, The step of calculating the head entity features, tail entity features, and relation features using the IRTE method to obtain the first relation score corresponding to the target entity pair includes: The head entity features, the tail entity features, and the relationship features are weighted feature fusion and reshaping to obtain a first image vector; An upsampling method is used to enhance the resolution of the first image vector to obtain a second image vector; An image feature extraction model is used to extract features from the first image vector and the second image vector to obtain image feature representations; The first relationship score is calculated based on the image feature representation.
5. The document-level relation extraction method according to claim 4, characterized in that, The calculation formula for the step of weighted feature fusion and reshaping of the head entity features, the tail entity features, and the relation features to obtain the first image vector is as follows: ; in, The first image vector, For the head entity features, For the tail entity features, The relational features are as follows: These are the learnable parameters of the head entity features. These are the learnable parameters of the tail entity features. These are the learnable parameters of the relational features. For the channels of the first image vector, The height of the first image vector. The width of the first image vector.
6. The document-level relation extraction method according to claim 1, characterized in that, The step of using a hybrid expert system to analyze and process the first relationship score, the head entity features, the tail entity features, and the relationship features to obtain the final relationship score includes: The hybrid expert system is used to fuse the head entity features and the relation features to obtain a subject score; The hybrid expert system is used to fuse the tail entity features and the relation features to obtain the object score; The subject score and the object score are summed to obtain the second relation score; The final relationship score is obtained by summing the first relationship score and the second relationship score.
7. The document-level relation extraction method according to claim 1, characterized in that, The step of obtaining the relation extraction result corresponding to the target entity pair based on the final relation score includes: Obtain preset relationships with multiple probability values and multiple entity relationships; The highest predicted probability value in the final relationship score is selected as the target probability value of the target entity. Find an entity relationship that corresponds to the target probability value of the target entity in the preset relationship and use it as the relationship extraction result.
8. A document-level relation extraction device, characterized in that, include: The initial document retrieval module is used to retrieve the initial document. A tagged document acquisition module is used to perform tagging processing on the initial document to obtain a tagged document, wherein the tagged document contains at least one set of entity pairs; The feature extraction module is used to extract head entity features, tail entity features and relation features corresponding to target entity pairs based on the tagged document, wherein the target entity pair is any one of the at least one set of entity pairs; The first relation score acquisition module is used to calculate the head entity features, the tail entity features and the relation features using the IRTE method to obtain the first relation score corresponding to the target entity pair; The final relationship score acquisition module is used to analyze and process the first relationship score, the head entity features, the tail entity features, and the relationship features using a hybrid expert system to obtain the final relationship score; The relation extraction result acquisition module is used to obtain the relation extraction result corresponding to the target entity pair based on the final relation score; The feature extraction module is further configured to encode the labeled document using a pre-trained language model to obtain a set of context embedding vectors and a first attention weight set for the labeled document; extract the head entity features and the tail entity features based on all entity pairs in the labeled document; aggregate the first attention weights corresponding to each entity in the labeled document using a mean aggregation method to obtain the target attention corresponding to each entity; generate head entity attention and tail entity attention based on all target attentions; calculate the second attention weights of the target entity pairs based on the head entity attention and tail entity attention; and calculate the relation features based on the set of context embedding vectors and the second attention weights.
9. A terminal device, characterized in that, include: A processor and a memory, the memory being used to store a computer program, the processor being used to call and run the computer program stored in the memory to perform the steps of the document-level relation extraction method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, Used to store a computer program that causes a computer to perform the steps of the document-level relation extraction method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Document level relation extraction method and device, electronic equipment and storage medium
CN115358220A
Entity relationship extraction method and device, equipment and medium
CN116049398A