A Relation Extraction Method and System Based on Graph Neural Networks
By constructing a text graph structure and introducing multi-channel semantic representation and path-aware attention mechanism, the limitations of existing graph neural networks in complex relationship extraction are solved, achieving more refined semantic relationship recognition between entities and improved robustness, which is suitable for knowledge graph construction and information extraction systems.
Patent Information
- Application Number
- CN202511093745.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-06
- Publication Date
- 2025-10-28
- Estimated Expiration
- 2045-08-06
AI Technical Summary
Existing relation extraction methods based on graph neural networks have limitations in handling complex semantic relations, cross-sentence relations, and multi-entity co-occurrence relations. They are difficult to capture global contextual information and lack dynamic adjustment mechanisms, resulting in redundancy of graph structure information and low relation recognition accuracy.
A relation extraction method based on graph neural networks is adopted. By constructing a text graph structure, introducing multi-dimensional edge connections and heterogeneous graph structures, and combining multi-channel semantic representation, path-aware attention mechanism and context alignment strategy, multi-layer message passing and aggregation are carried out. Confidence filtering and semantic consistency verification are introduced to improve the accuracy and robustness of relationships between entities.
It significantly improves the accuracy of identifying multiple types of semantic relationships between entities in complex natural language text, enhances the model's global semantic modeling capability and controllability, and is suitable for knowledge graph construction and information extraction systems.
Smart Images

Figure CN120611052B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of natural language processing technology, specifically to a method and system for relation extraction based on graph neural networks. Background Technology
[0002] Relation extraction is a key task in information extraction, aiming to identify and extract semantic relationships between entities from unstructured text. Current mainstream methods include rule-based methods, statistical learning-based methods, and deep learning-based methods. Among these, deep learning methods have gradually become the mainstream approach due to their powerful feature representation capabilities.
[0003] However, existing deep learning methods still have certain limitations when dealing with complex semantic relationships, cross-sentence relationships, and multi-entity co-occurrence relationships. The main reason is that traditional sequence models (such as RNNs and CNNs) have difficulty capturing global contextual information when modeling dependencies between entities. To overcome these problems, in recent years, some studies have introduced graph structures to express entities in sentences and their multidimensional connections, and then used graph neural networks (GNNs) for modeling and analysis.
[0004] Nevertheless, existing relation extraction methods based on graph neural networks are still imperfect in terms of graph construction strategies, node representation methods, and edge weight definitions, which can easily lead to redundancy in graph structure information or low relation recognition accuracy. Furthermore, the lack of a dynamic adjustment mechanism limits the generalization ability of these methods in complex text scenarios. Therefore, there is an urgent need for a graph neural network-based relation extraction method that can efficiently model complex relationships between entities and improve the accuracy of relation extraction to meet the application requirements of large-scale information extraction systems. Summary of the Invention
[0005] The purpose of this invention is to provide a relation extraction method and system based on graph neural networks to address the shortcomings of the prior art.
[0006] To achieve the above objectives, the present invention provides the following technical solution: a relation extraction method based on graph neural networks, comprising:
[0007] S100. Obtain the target text, and perform word segmentation, part-of-speech tagging, and named entity recognition on the target text to extract the entity set. n represents the total number of entities;
[0008] S200. Construct a text graph G = (V, R) based on the entity set, where V is a set of nodes including the entities and their context words, and R is a set of edges including syntactic dependency edges, positional edges, and co-occurrence edges.
[0009] S300. Construct an initial feature vector for each node v∈V in the graph. The feature vector includes word vectors, part-of-speech information, and positional information;
[0010] S400. Input graph G into the graph neural network model and perform multi-layer message passing and aggregation to obtain the high-order representation of each node. , where k is the number of layers in the graph neural network;
[0011] S500, For the target entity pairs in the diagram The representations are concatenated or combined and input into the relation classifier to predict its relation type r∈R′, where R′ is a predefined set of relations;
[0012] S600, Output the triplet of relationships between entity pairs based on the prediction results. .
[0013] Preferably, S100 includes:
[0014] S101. Multi-channel encoding is performed on the target text. Pre-trained language models are used to extract context semantic vectors, lexical feature encoders are combined to extract part-of-speech embeddings, and BiLSTM is used to obtain syntactic sequence dependency representations.
[0015] S102. Perform vector-level fusion of part-of-speech embedding representations to construct enhanced word vector representations, and introduce a position-aware mechanism to encode the positional bias information of words relative to entities in a sentence;
[0016] S103. Based on the fused representation input conditional random field sequence labeler, a joint named entity recognition model is used to perform entity boundary recognition and type discrimination, and extract the entity set. n represents the total number of entities;
[0017] S104. A confidence screening mechanism is used to perform semantic consistency checks on the preliminary identification results, filter out low-confidence entities, and improve the accuracy and robustness of the entity set.
[0018] Preferably, S200 includes:
[0019] S201. Based on the entity set E, select words within the context of the entity window to form a candidate node set, and combine the syntactic analysis results to introduce dependency subtree nodes to form a node set V.
[0020] S202. A dependency parser is used to construct syntactic dependency relation edges. Directed edges are generated based on the dependency paths between words, and the syntactic relation type is attached as the edge weight attribute.
[0021] S203. Calculate the relative positional distance between words and entities, and set a threshold to construct positional relationship edges. The edge weight decreases inversely with the relative positional distance to capture the influence of local word order.
[0022] S204. Statistically count the co-occurrence frequency of entity pairs in the training corpus, and establish co-occurrence relation edges by combining word vector similarity. The edge weights are determined by a frequency-weighted cosine similarity function.
[0023] Preferably, S300 includes:
[0024] S301. For each node v in the node set V, call the pre-trained language model to obtain the context semantic word vector embedding. Used to capture global semantic features;
[0025] S302. Perform part-of-speech tagging on node v and map its corresponding part-of-speech tags to part-of-speech embedding vectors. Furthermore, a convolutional encoder is used to model the local context of the part-of-speech sequence;
[0026] S303. Construct a position encoding vector hˡ(v) based on the relative position information between node v and its entity, and use a learnable position embedding parameter table to realize the vectorized representation of continuous distance;
[0027] S304, will and The vectors are concatenated, and an initial feature vector of uniform dimension is obtained through a nonlinear transformation and normalization operation. This is used as input for subsequent graph neural networks.
[0028] Preferably, S400 includes:
[0029] S401. Input the text graph G = (V, R) into the graph neural network model, and use a heterogeneous graph convolution structure to define message passing functions for different types of edges R respectively;
[0030] S402. In the k-th layer graph neural network, for each node v∈V, it receives edge-type weighted feature information from its neighboring nodes u∈N(v). ;
[0031] S403. Aggregate neighbor information and its own upper-level representation. Perform residual connections and nonlinear transformations to generate the node representation of the current layer. ;
[0032] S404, stacked k-layer graph neural networks to capture multi-order semantic dependencies, ultimately obtaining a set of high-order node representations containing global structural semantics. .
[0033] Preferably, in the process of multi-layer message passing and aggregation in the graph neural network, the following is further included:
[0034] S405. In each layer, construct paths for all possible multi-hop connection paths, use a differentiable path scoring function to score the importance of different paths, and use the path score as a weight adjustment factor for message aggregation.
[0035] S406. The contextual semantics of nodes in the high-scoring path are used as structural supplementary signals and fused into the representation of the target node through a bidirectional gating mechanism to preserve the implicit semantic dependencies between cross-sentence or long-distance entities.
[0036] S407. After the final node representation is generated, the joint path attention distribution is used as an explicit graph structure supervision signal to construct an auxiliary loss function, thereby optimizing the graph neural network's ability to model critical paths and its generalization performance.
[0037] Preferably, S500 includes:
[0038] S501, For target entity pairs Extract the higher-order representation of each corresponding node. and It also merges the aggregated representations of all intermediate nodes within the shortest path in the graph structure to construct a structure-enhanced entity pair representation. ;
[0039] S502. Introduce a context alignment module, using graph attention to assign different weights to the context nodes where entity pairs appear in the sentence, calculate their context semantic alignment vectors, and then correlate them with the context nodes of the sentence. To merge;
[0040] S503. Input the fused entity pair representation into a multi-channel relation classification network, wherein the network includes a static relation prediction branch and a dynamic context-aware branch, which are used to model static semantic association and context-driven relation variability, respectively.
[0041] Preferably, S600 includes:
[0042] S601. Dynamically model the confidence level of the relation probability distribution output by the classifier, and adaptively adjust the confidence value of the predicted relation r by combining the co-occurrence pattern of entity pairs in the context and the edge connection strength in the graph structure.
[0043] S602. Set a confidence gating mechanism so that entity pair triples are constructed only when the prediction confidence exceeds a preset dynamic threshold. Otherwise, the prediction result is marked as a candidate relation and sent to the inference backtracking module for further confirmation;
[0044] S603. Introduce a semantic consistency verification strategy during the triple generation process, by... and Type alignment and contextual semantic consistency are checked to eliminate candidate triples with semantic conflicts;
[0045] S604 constructs the final output result set from triples that have passed confidence gating and consistency verification, and supports setting output rules according to domain or task type to realize customized management and automatic post-processing of triples.
[0046] The present invention also provides a relation extraction system based on graph neural networks, comprising:
[0047] The entity recognition module acquires the target text, performs word segmentation, part-of-speech tagging, and named entity recognition on the target text, and extracts the entity set; n represents the total number of entities;
[0048] The graph construction module constructs a text graph G = (V, R) based on the entity set, where V is a set of nodes including the entities and their context words, and R is a set of edges including syntactic dependency edges, positional edges, and co-occurrence edges.
[0049] The feature encoding module constructs an initial feature vector for each node v∈V in the graph. The feature vector includes word vectors, part-of-speech information, and positional information.
[0050] The graph neural network representation learning module inputs graph G into the graph neural network model and performs multi-layer message passing and aggregation to obtain the high-order representation of each node, where k is the number of layers in the graph neural network;
[0051] The relation modeling and classification module concatenates or combines the representations of target entity pairs in the graph, inputs them into the relation classifier to predict their relation type r∈R′, where R′ is a predefined set of relations;
[0052] The triplet construction module outputs triplets relating entity pairs based on the prediction results.
[0053] The technical effects and advantages provided by the present invention in the above technical solution are as follows:
[0054] 1. This invention provides a relation extraction method based on graph neural networks, which can accurately identify multiple types of semantic relationships between entities in complex natural language text. By introducing a heterogeneous graph structure and integrating entities, context words, and multi-dimensional edge connections between them (including syntactic dependencies, relative positions, and semantic co-occurrence edges), it effectively overcomes the shortcomings of traditional sequence models in modeling long-distance dependencies and structural ambiguities, achieving a more refined expression of text structure. Simultaneously, by leveraging multi-channel semantic representation, path-aware attention mechanisms, and context alignment strategies, the model possesses stronger global semantic modeling capabilities, significantly improving the accuracy and robustness of relation recognition under complex semantics.
[0055] 2. This invention introduces structural enhancement and supervised guidance mechanisms in all three core stages: entity representation, graph modeling, and relation classification, constructing entity pair representations with higher semantic recognizability. In particular, through confidence gating and semantic consistency verification strategies, adaptive control of prediction quality is achieved in the triple output stage, significantly reducing the probability of erroneous relation outputs and improving the system's controllability and deployability. The overall solution possesses significant advantages such as high accuracy, strong scalability, and excellent performance on cross-sentence and weakly supervised relations, making it suitable for various practical applications such as knowledge graph construction, information extraction systems, and text structuring. Attached Figure Description
[0056] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this invention. For those skilled in the art, other drawings can be obtained based on these drawings.
[0057] Figure 1 This is a mind map of the method of the present invention.
[0058] Figure 2 This is a mind map of the system modules of the present invention. Detailed Implementation
[0059] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0060] Example 1, please refer to Figure 1 As shown in this embodiment, a relation extraction method based on graph neural networks includes:
[0061] S100. Obtain the target text, and perform word segmentation, part-of-speech tagging, and named entity recognition on the target text to extract the entity set. n represents the total number of entities;
[0062] S200. Construct a text graph G = (V, R) based on the entity set, where V is a set of nodes including the entities and their context words, and R is a set of edges including syntactic dependency edges, positional edges, and co-occurrence edges.
[0063] S300. Construct an initial feature vector for each node v∈V in the graph. The feature vector includes word vectors, part-of-speech information, and positional information;
[0064] S400. Input graph G into the graph neural network model and perform multi-layer message passing and aggregation to obtain the high-order representation of each node. , where k is the number of layers in the graph neural network;
[0065] S500, For the target entity pairs in the diagram The representations are concatenated or combined and input into the relation classifier to predict its relation type r∈R′, where R′ is a predefined set of relations;
[0066] S600. Output the triplet representing the relationship between entity pairs based on the prediction result. .
[0067] In one embodiment of the present invention, step S100 aims to extract the entity set E from the target text with high precision, laying a solid foundation for subsequent graph structure construction and relation extraction. This step introduces multi-channel representation fusion, a location-aware mechanism, a joint recognition model, and a confidence screening mechanism to solve the problems of low accuracy, ambiguous boundaries, and weak entity generalization ability of traditional named entity recognition in complex contexts.
[0068] First, the target text is preprocessed, including standardization, symbol normalization, and sentence segmentation, to ensure that the input sequence meets the requirements of the encoding model. Then, a three-channel feature extraction strategy is used to perform multi-dimensional representation of each word.
[0069] Contextual semantic vector extraction: Pre-trained language models (such as BERT, RoBERTa, etc.) are used to model the context of the original text, outputting a context-sensitive semantic vector for each word, denoted as . This semantic vector has bidirectional encoding capabilities, enabling it to capture the semantic evolution of entities within a context, effectively overcoming the problem that fixed word vectors cannot handle ambiguity.
[0070] Lexical feature embedding representation: The lexical feature encoder maps the part-of-speech tag (POS) of each word into a low-dimensional dense vector. The vector is processed by a convolutional encoder to mine local dependencies in the part-of-speech sequence, thereby introducing syntactic clues to help distinguish homonyms or entities with ambiguous boundaries.
[0071] Syntactic dependency representation acquisition: A BiLSTM structure is used to bidirectionally model the original word sequence to generate sequence dependency vectors. This representation focuses on contextual order and syntactic dependency paths, enhancing the distinguishability of entity boundaries while preserving word sequences.
[0072] All three types of representations are extracted based on a unified word granularity, ensuring semantic consistency and vector alignment, and providing a structural foundation for subsequent fusion.
[0073] To integrate multi-channel information, the above three types of representations are fused using the following method:
[0074] First, for each word, three representation vectors... The vectors are concatenated to form preliminary enhanced word vectors;
[0075] Secondly, a location-aware mechanism is introduced, that is, for each word Construct a position vector This represents the relative distance between the word and the center of the candidate entity in the sentence. The position vector is obtained through a learnable position embedding matrix, achieving continuous relative distance vectorization;
[0076] Finally, the position vectors and fused semantic vectors are input into the fusion layer, and after nonlinear transformation (such as ReLU) and batch normalization, the final enhanced word vectors are obtained. .
[0077] This fusion strategy has good semantic alignment and entity perception capabilities, significantly enhancing the ability of entity representation to discriminate in complex contexts.
[0078] The enhanced word vector sequence is input into the named entity recognition module, which is trained jointly by a CRF sequence labeler and a named entity recognition neural network (such as BiLSTM-CRF).
[0079] BiLSTM further models long dependencies between word sequences;
[0080] The CRF module performs global optimization of the annotation results to ensure that legal transfer paths are satisfied between entity labels;
[0081] The model outputs the entity label for each word in the current context, such as B-PER, I-ORG, O, etc.
[0082] This joint model can not only accurately identify entity boundaries, but also label entity types and form entity sets. Each of them Each contains structural information such as location, boundary, and type, where n represents the total number of entities;
[0083] To further improve entity recognition quality, especially under conditions of ambiguous or noisy text, the system is designed with a confidence screening mechanism, including the following steps:
[0084] Confidence calculation: The probability of entity boundaries and their label assignments predicted by the model is statistically analyzed, and the prediction confidence value of each entity is calculated, which is in the form of the average CRF edge weight score of the entity's path.
[0085] Semantic consistency verification: Extract the semantic fragments of the identified entities in the context, calculate the semantic matching degree between them and the entity labels using a similarity model (such as SimCSE), and perform weakly supervised comparison in conjunction with an external dictionary or knowledge base;
[0086] Filtering strategy: Only entities that simultaneously meet the high confidence threshold and semantic consistency criteria are retained as valid entities. Low-confidence or conflicting entities are marked as "candidates" and proceed to the next stage of graph construction filtering or manual review process.
[0087] This strategy effectively improves the accuracy and robustness of the entity set E, and avoids low-quality entities interfering with subsequent graph modeling.
[0088] In a preferred embodiment of the present invention, step S200 aims to construct a semantic graph G = (V, R) based on the entity set E identified in step S100, where V is the set of nodes in the graph and R is the set of edges. This graph not only expresses the explicit and implicit structural relationships between entities, but also provides a basis for multidimensional semantic propagation for graph neural networks.
[0089] The graph construction mechanism proposed in this invention breaks through the limitations of traditional sequence modeling on linear text structures. It integrates three types of information paths: syntactic structure, word order, and semantic co-occurrence. Through structurally enhanced node construction and multilateral type fusion strategies, it constructs a high-order text graph structure with semantic awareness capabilities. Specifically, it includes the following sub-steps:
[0090] To enhance the expressive power of the graph structure, this step further introduces the entity's neighboring context words and their syntactic dependency substructures as candidate nodes, based on the entity set E:
[0091] Entity window selection: by each entity Centered on the position in the original text, a fixed-length window (e.g., ±5 words) is set forward and backward. Words within the window range are added to the candidate node set to preserve local semantic background.
[0092] Dependency subtree introduction: Perform dependency parsing on the text to obtain the dependency subtree of each word (i.e., the set of subordinate nodes when the word is the central node), and introduce non-entity word nodes belonging to any entity dependency path into the candidate set to preserve syntactic supplementary information;
[0093] Node deduplication: After deduplicating the candidate set, a node set V is obtained, which includes: named entity nodes, context word nodes, and syntactic structure enhancement nodes. Each node is associated with a unique identifier, a position index, and a type label for subsequent feature construction.
[0094] This step constructs a set of graph nodes with strong coverage and semantic continuity through a dual supplementary mechanism of semantic neighborhood and syntactic structure, providing structural diversity support for entity relationship modeling.
[0095] The edges between nodes in the graph form the path basis for entity relation propagation. First, syntactic dependency relation edges based on language structure are constructed, and their generation logic is as follows:
[0096] Utilize dependency parsers (such as Stanford CoreNLP, SpaCy, etc.) to obtain dependency structure information between words and extract the dependency relationship paths between all word pairs;
[0097] If node and If a dependency relationship exists, add a path from graph G to graph G. point to Directed edges form edge pairs ;
[0098] Each edge is associated with a syntax type label (such as nsubj, dobj, acl, etc.) as a syntax attribute of the edge;
[0099] Syntactic attributes are represented by trainable embedding vectors, forming part of the edge weights, which are then used to implement type-aware propagation in subsequent GNN models.
[0100] This edge type aims to preserve the dependencies between entities in a sentence and their context, enhancing the expressive power of graph structures for language organization.
[0101] To further supplement the order information between nodes, this step introduces an edge construction strategy based on relative positional distance to model the local word order:
[0102] For any pair of nodes If the distance between them in the original sentence does not exceed a preset threshold (e.g., 5 words), then a positional relationship edge is established between them.
[0103] This edge is undirected, and its strength (i.e., weight) is determined by its relative distance in the text. The inverse decay function is defined, for example... , where r is an adjustable attenuation coefficient;
[0104] All position edges are uniformly labeled as "position-edge" to distinguish them from dependent edges, and different propagation strategies are applied in the GNN.
[0105] This mechanism enhances the graph structure's ability to model sequential dependencies between short-distance neighboring nodes and captures linguistic phenomena such as "modifier-modified" and "subject-verb agreement".
[0106] To uncover implicit semantic co-occurrence relationships in text, a method for constructing edges based on co-occurrence statistics and word vector similarity is further introduced:
[0107] Statistical analysis of entity pairs in the training corpus Frequency of co-occurrence within the same semantic context (such as a sentence or paragraph) This is used to measure the degree of semantic association between entities;
[0108] Calculate the cosine similarity of entity word vectors This indicates the degree of semantic spatial proximity.
[0109] The final edge weight is defined as , where λ is a weighting coefficient that controls the fusion ratio of structural co-occurrence and semantic similarity;
[0110] Co-occurrence edges are added only when the edge weight exceeds the dynamic threshold τ to avoid introducing redundant weak associations.
[0111] This strategy breaks through the limitation of syntactic edges and positional edges being confined to intra-sentence structures, and provides a semantic association enhancement path for global corpora, effectively improving the ability to model long-term dependencies between entity pairs.
[0112] In the relation extraction method proposed in this invention, the nodes of the graph structure not only include the entity itself, but also its context words and grammatically dependent child nodes. The semantic differences between nodes in the node set V are significant, and the information granularity varies. To fully express the feature information of various types of nodes, step S300 designs a multi-source semantic feature construction mechanism, including semantic vector embedding, part-of-speech encoding, positional bias modeling, and feature fusion normalization strategies. Ultimately, this provides the graph neural network with a unified and structurally aligned initial node vector. Specifically, it includes the following sub-steps:
[0113] First, for each node v∈V, a pre-trained language model (such as BERT, RoBERTa, ERNIE, etc.) is invoked to obtain its contextual semantic word vector embedding. This language model is pre-trained on a large-scale corpus and possesses the ability to disambiguate polysemous words, understand syntactic structure, and model cross-sentence context. Its technical process is as follows:
[0114] The original text is segmented and aligned with tokens to ensure accurate mapping of node v in the model;
[0115] Take the sentence or context fragment containing node v as input and extract word vectors through each Transformer layer in the model;
[0116] Take the output vector after weighted fusion of the last layer or multiple layers of the model as the contextual semantic representation of node v. The dimensions are typically 768 or 1024.
[0117] If a node corresponds to multiple words, then average pooling or max pooling strategies are used to fuse the word vectors.
[0118] This semantic embedding introduces global semantic information into each node, compensating for the lack of expression in the static vector of the vocabulary under contextual changes.
[0119] To enhance the discriminative ability of nodes in local syntactic structures, each node v is subjected to part-of-speech tagging to obtain its corresponding part-of-speech label (such as NN, VB, JJ, etc.), and the label is encoded into a fixed-dimensional embedding vector. The specific steps are as follows:
[0120] Use natural language processing tools (such as SpaCy and LTP) to perform part-of-speech analysis on sentences;
[0121] Constructing a part-of-speech tag embedding matrix in d is the size of the part-of-speech tag set, and d is the dimension of the part-of-speech vector; The input is a one-dimensional convolutional encoder, which, combined with its adjacent part-of-speech context, extracts local dependency patterns at the grammatical phrase level. The output is a structure-sensitive part-of-speech representation vector that captures the functional roles of words and their contextual combination patterns. This strategy significantly improves the recognizability of the grammatical roles played by nodes and is an important semantic dimension for constructing the basis of syntactic edge propagation in graph structures.
[0122] The relative distance between entities and their context in text plays a crucial role in relation determination. Therefore, this invention introduces a learnable positional encoding mechanism based on entity reference positions to construct positional embedding vectors. Specifically, it includes:
[0123] For each node v, calculate its relative distance to the entity or target entity pair in the sentence. Map the relative distance as an index to the location embedding table. Where L is the maximum offset distance. The dimension of the position vector is , and the center position is . Position embedding vector It can directly participate in feature propagation in graph neural networks and supports updates during training. To avoid introducing noise due to excessive distance, nodes exceeding the offset range can be uniformly mapped to "far-distance" positional encodings. This positional representation makes the model distance-sensitive when dealing with entity relationships at different distance ranges, avoiding misjudgment of synonyms and structural mismatch problems.
[0124] To construct a unified initial node representation vector, it is necessary to analyze the above three types of vectors. To achieve integration and structural unification. Specifically, this includes:
[0125] By concatenating the three types of vectors along the vector dimension, a fused vector is obtained. ;enter To a single-layer linear transformation network The nodes are uniformly mapped to the dimension 'd' required by the graph neural network; a non-linear activation function (such as ReLU) is added to enhance the expression of non-linearity; finally, batch normalization (BatchNorm) and Dropout mechanisms are applied to improve training stability and prevent overfitting. The initial feature vectors of the fused nodes are then... It not only incorporates contextual, lexical, and structural information, but also possesses good normalization and training robustness, providing a consistent input format for information propagation in subsequent multi-layer graph neural networks.
[0126] In a preferred embodiment of the present invention, step S400 involves taking the previously constructed text graph G = (V, R) as input and using a graph neural network (GNN) model to perform multi-layer information propagation and representation updates on each node in the graph, thereby obtaining a high-order node representation set that expresses the global structural semantics. To enhance the model's ability to perceive semantic relationships between entities, this step employs a heterogeneous graph convolutional structure, a gated aggregation mechanism, and a path attention guidance strategy to achieve multi-type modeling, key relationship path identification, and improved generalization capabilities.
[0127] Text graphs G contain diverse edge types, including dependency syntax edges, positional relation edges, and semantic co-occurrence edges, which traditional GNN models struggle to model uniformly. Therefore, this step constructs a heterogeneous graph convolution module, defining an independent message-passing function for each edge type r∈R. Furthermore, different types of edges are modeled separately during the node information aggregation stage. The process is as follows:
[0128] Decompose the graph structure into multiple edge-type subgraphs. Process them separately;
[0129] Each subgraph uses an independent linear transformation weight matrix. Perform edge-type-specific encoding on the features of neighboring nodes;
[0130] During the node update phase, a multi-channel attention aggregation mechanism is introduced to adaptively fuse contributions from different edge types.
[0131] Finally, the information of each edge type channel is weighted and summed as the input of the node's aggregate representation.
[0132] This mechanism effectively solves the problem of type interference in heterogeneous structure graphs and improves the modeling accuracy of different relational paths.
[0133] In each graph convolution operation, for each target node v, its previous layer representation is: Adjacent nodes are The model considers all adjacent nodes. Features Aggregation is performed, and a weighting mechanism is introduced based on edge type. A gating mechanism is also introduced. Dynamic adjustment is achieved, as detailed below:
[0134] First, calculate the node pairs. Boundary rights The edge weight can be derived from edge attribute embedding or attention weight;
[0135] For each neighbor node u, calculate the gating function value. , where σ is the Sigmoid activation function; u and v represent nodes in the graph, u being a neighboring node and v being the current target node. Let represent the feature vectors of the neighbor node u and the target node v in the k-1 layer, respectively. The eigenvector concatenation operation combines the representations of u and v into a longer vector to explicitly express their joint state. Wg is the gate weight matrix (a learnable parameter), which performs a linear transformation on the concatenated eigenvectors to learn how to measure the influence of u on v. The aggregation expression is: In the formula, The edge weight index represents the structural importance of the edge (of type r) from node u to node v in the propagation of this layer (which may come from attention mechanisms, preset weights, or edge attribute embedding in the graph). This represents the transformation matrix corresponding to edge type r, used to represent the neighbor node u. Mapping to a semantic space aligned with the representation space of node v can be specific to edge types (commonly used in heterogeneous graphs). This represents the representation of neighbor node u at layer (k-1). Through a gating mechanism, the model can automatically select neighbor nodes that make substantial contributions to the current node, thus suppressing semantic noise.
[0136] After aggregating neighbor information, the steps for updating the node representation are as follows:
[0137] Representation of the previous layer Perform residual joins to form: ;
[0138] Apply a Dropout layer to randomly mask some feature channels to enhance training robustness;
[0139] Layer normalization is used to stabilize the training process and accelerate convergence.
[0140] This strategy effectively alleviates the oversmoothing problem in graph convolution and preserves the distinctiveness of node features in multi-layer propagation.
[0141] To capture multi-level dependency information between entities, a stacked k-layer graph convolutional network is used, with each layer sharing or having independent weights, to generate higher-level semantic representations through a progressive propagation approach.
[0142] The first layer primarily models direct syntactic dependencies and local neighborhood semantics;
[0143] The intermediate layer gradually introduces structural extension information, such as co-occurrence paths and semantic jump relationships;
[0144] The final output of the k-th layer Node embeddings that form a global structure awareness are used for subsequent entity relationship discrimination tasks.
[0145] In this process, node representations possess multi-granularity, cross-level, and structure-sensitive semantic embedding capabilities.
[0146] To further enhance the modeling capabilities for long-distance entity relationships and multi-hop semantic paths, step S400 also introduces a path-aware mechanism, which possesses strong structural reasoning and semantic alignment capabilities, specifically including:
[0147] In each layer of propagation, all possible slave nodes in the graph are considered. To the node multi-hop path Perform enumeration (limiting the number of hops to ≤ L) and compute its representation using the path representation function PathRep(P). Calculate the importance of each path using the path scoring function Score(P) (such as a differentiable neural network function). ,in This represents each node in the path; the score serves as a dynamic weight adjustment factor for the edges corresponding to the path in the current layer node aggregation, further guiding the priority of multi-hop semantic information aggregation.
[0148] For paths rated as high value, the semantic information of their internal nodes is used as structural supplementary signals:
[0149] Introducing a two-way gating mechanism and The intensity and aggregation method of introducing path semantic information are controlled separately;
[0150] The weights are adjusted based on the path score. The fusion ratio is adjusted based on the target node's state; the final fusion vector participates in the target node's representation update, achieving structural completion and remote dependency perception. This mechanism improves the expressiveness of cross-sentence or cross-entity relationship chains, a modeling task that existing GNNs based on first-order adjacency structures cannot accomplish.
[0151] To enhance the model's ability to focus on structural paths, a path attention supervision signal is introduced:
[0152] Perform KL divergence matching between the path score distribution and manually labeled critical paths or statistical priors;
[0153] Constructing auxiliary loss With the main loss (e.g., joint optimization of cross-entropy in relation classification);
[0154] The final loss function is: , where λ is the adjustment factor.
[0155] This supervision method has explicit structural guidance capabilities, which significantly improves the model's generalization ability on structurally complex texts.
[0156] In the relation extraction method based on graph neural networks proposed in this invention, step S500 is a crucial stage, responsible for mapping higher-order node representations to semantic relationships between entity pairs. Since relationships between entities typically depend not only on their own semantics but also on their connection paths and contextual environment within the graph structure, the traditional "entity vector concatenation + classifier" approach struggles to effectively capture relation evolution and contextual dependencies. Therefore, this invention designs a structure-enhanced entity pair modeling and multi-channel relation classification mechanism, including path representation fusion, context-aligned modeling, and multi-branch classifier optimization, specifically comprising the following sub-steps:
[0157] First, for the target entity pair Extracting the higher-order node representations obtained after propagation in the graph neural network. and To incorporate structural semantic path information, the intermediate node information along the shortest path in the graph is further integrated. The processing flow is as follows:
[0158] In a text graph G, the shortest path between entity pairs is calculated based on graph traversal algorithms (such as BFS or Dijkstra). Get the set M of intermediate nodes in the path, excluding the start and end entities;
[0159] Extract the representation of all nodes v∈M in set M. Aggregation is performed using methods such as average pooling, attention-weighted pooling, or max pooling, and is denoted as path semantic representation. ;
[0160] Constructing a structure-enhanced entity pair representation: This representation integrates the entity's own representation with the embedding of semantic hub nodes in the structural path, making up for the deficiency that simply splicing entity ontology information cannot model upstream and downstream relationship chains.
[0161] The semantic relationships between entity pairs are highly dependent on the context in which they occur. To improve the model's ability to identify context-sensitive relationships, this step designs a context alignment module to extract the contextual semantics associated with entity pairs and integrate them into the relation representation. Specifically, this includes:
[0162] For entity pairs Extract the higher-order representations of the context nodes C within a certain window (e.g., ±5 words) of the given sentence;
[0163] Using Graph Attention (GAT) to represent the semantics of each node v in set C Calculate attention weights , and entity pair representation Based on the relevance, a context-weighted vector is obtained. The contextual semantic vector is fused with the structure-enhanced entity pair representation to form the final relation representation vector used for classification. ;in This represents a nonlinear mapping network used to unify the representation dimension and semantic space. This mechanism can effectively align semantic context and improve the model's ability to judge ambiguous relationships, polysemous words, or semantic shifts.
[0164] To address the diversity of entity relationships and semantic-driven differences, this invention employs a multi-channel relationship classification network structure, separating structural semantics from contextual semantics in modeling to improve representation accuracy.
[0165] Static semantic branch: using standard fully connected networks Modeling is performed to extract stable relation representations related to semantic structure;
[0166] Dynamic Context-Aware Branch: Introduces context-change features to model the global context of the input text (such as sentence vectors and paragraph vectors) and processes them jointly with entity pair representations;
[0167] The probability distribution of the output relationship between the two branches The final fusion method can be weighted averaging, maximum entropy synthesis, or attention-controlled fusion, outputting the final predicted relationship category. .
[0168] This structure enhances the ability to differentiate between semantically stable relations and context-driven relations, thereby improving the fine-grained recognition capability of relation extraction.
[0169] Considering the challenges in practical applications such as imbalanced training samples, ambiguous relationship boundaries, and path interference, this invention designs a dual supervision mechanism to enhance the model's discriminative robustness:
[0170] Entity-level label supervision: Cross-entropy loss is optimized between the predicted relation r and the manually labeled data to ensure classification accuracy;
[0171] Path confidence-guided supervision: The path attention distribution calculated in step S400 is compared with the actual labeled paths using a similarity metric (e.g., KL divergence) to guide the model in learning reasonable structural path attention strategies; the comprehensive loss function is as follows: Where L_cls is the classification main loss, L_path is the path supervision auxiliary loss, and s is the adjustment factor.
[0172] This strategy not only constrains the model's classification output, but also introduces prior guidance at the structural modeling level, improving the model's convergence speed and generalization ability for weakly supervised samples.
[0173] After classifying and predicting the relationships between entity pairs, this invention designs a complete relation triplet output mechanism to ensure the structural accuracy, semantic consistency, and application adaptability of the output results. In traditional methods, classification results are typically used directly as the final triplet output, ignoring potential erroneous decisions by the classification model in marginal samples, ambiguous contexts, and low-confidence predictions. This invention, by introducing a dynamic confidence control mechanism, a semantic consistency verification strategy, and an inference backtracking support system, forms a triplet construction process with intelligent filtering capabilities and adaptive robustness, specifically including the following sub-steps:
[0174] First, confidence modeling is performed on the output of the relationship classification network. During the classifier output phase, for each pair of entities... The model outputs the probability distribution of its corresponding relation category r ∈ R′. To achieve dynamic adjustment, this step constructs a comprehensive confidence scoring function:
[0175] Define the confidence score function: ;in: The predicted probability output by the relation classifier; This refers to the semantic similarity of entity pairs co-occurring in the context (such as word vector similarity within the context window). α represents the average edge weight of the path connecting two entities in the graph structure; α, β, and γ are weighting coefficients that control the fusion ratio of different confidence sources. This confidence scoring mechanism achieves bidirectional constraints on the structure and semantics of the model output, effectively mitigating the uncertainty in relation classification caused by contextual bias.
[0176] To ensure the reliability of the triplet output, this step introduces a confidence gating mechanism to dynamically determine whether the prediction result meets the output condition. The processing flow is as follows:
[0177] Set a dynamic confidence threshold τ (which can be adaptively adjusted based on the number of bits or distribution characteristics in the training set);
[0178] when When constructing triples Marked as confirmed;
[0179] when When the condition is met, mark it as a candidate relationship and do not output it for the time being;
[0180] All candidate relationships will be sent to the reasoning backtracking module for further confirmation through downstream knowledge base consistency verification, rule reasoning, or context re-judgment strategies.
[0181] This gating strategy effectively avoids excessive output behavior of the model under critical prediction conditions, and improves the quality, stability and reliability of triple output.
[0182] To further ensure the semantic and logical consistency of the output triples, this step designs an entity semantic consistency verification mechanism, including entity type matching and context semantic rationality detection:
[0183] Entity type matching: Check and Does it conform to the semantic role required by relation r? For example, if r is a "membership relation", then It should be a "person's name" It should be "organization";
[0184] Contextual semantic verification: Extracting content from the original text and The context fragments are used to determine whether the relation statement is semantically consistent with the context through semantic consistency discrimination models (such as textual entailment model, SimCSE, etc.);
[0185] Triples that do not satisfy semantic logic are marked and filtered to avoid the injection of incorrect knowledge.
[0186] This mechanism effectively suppresses pseudo-relational triples caused by semantic ambiguity, sentence mismatch, or entity type mislabeling, significantly improving the semantic accuracy of triples.
[0187] For all relation triples that pass confidence gating and consistency checks The system organizes these into a unified output set T, supporting domain-specific management and customized output according to actual application needs:
[0188] Standardized result format: Supports output of structured data formats such as JSON, RDF, and CSV, which facilitates integration into information extraction systems or knowledge graph platforms;
[0189] Domain rule filtering: Introduces a domain dictionary and rule set based on task configuration, which can filter valid relationship types by industry (such as medical, legal);
[0190] Batch deduplication and aggregation: When there are multiple relationship prediction results for the same entity pair, retain the one with the highest confidence or sort them according to the priority of domain rules;
[0191] Automatic post-processing mechanism: Supports integration with external knowledge bases (such as Wikidata, CN-DBpedia) for completion, normalization and error correction, improving the consistency and completeness of knowledge output.
[0192] This post-processing workflow enables intelligent management and adaptive optimization of structured output, and is a key support module for the deployment and implementation of the relation extraction system.
[0193] Example 2: To verify the effectiveness of the "Relation Extraction Method Based on Graph Neural Network" described in this invention in practical tasks, the applicant constructed an experimental platform based on a public dataset, conducted comparative experiments, evaluated the relation extraction capability of the method in complex text, and compared its performance with existing mainstream methods, as detailed below:
[0194] Experimental platform: PyTorch 1.13, Python 3.9, CUDA 11.6, GPU is NVIDIA A100.
[0195] Dataset: The publicly available Chinese relation extraction dataset CCKS2019-Task1 is used. This dataset contains approximately 15,000 sentences with labeled triples, involving 9 types of entities and 50 types of relations, and has a certain degree of semantic complexity and structural diversity.
[0196] Data partitioning:
[0197] Training set: 12,000 records;
[0198] Validation set: 1,500 records;
[0199] Test set: 1,500 records;
[0200] To verify the performance of the method of this invention, four comparative models were designed, the composition and description of which are shown in Table 1. The experimental results are shown in Table 2.
[0201] Table 1. Comparison of Benchmark Models
[0202]
[0203] We adopt three evaluation metrics commonly used in the field of relation extraction:
[0204] Precision (P): The proportion of positive class predictions that are correct;
[0205] Recall(R): The proportion of positive classes that are correctly predicted in the actual class;
[0206] F1-score (F1): The harmonic mean of precision and recall. .
[0207] The prediction results adopt a strict triplet matching standard, that is, the entity boundary, type and relation are all consistent and considered to be correct.
[0208] Table 2 Comparison of Experimental Results
[0209]
[0210] As shown in Table 2, the method of this invention (M4) significantly outperforms other comparative models in F1-score, improving it by 4.4 percentage points compared to the GCN structure, demonstrating its modeling advantage in various complex relationships. The improved precision indicates that the structural enhancement modeling and confidence gating mechanism in this method effectively suppress the generation of low-confidence pseudo triples. The improved recall is attributed to the path-aware attention mechanism's ability to uncover longer-distance or implicit semantic relationships between entity pairs. Compared with traditional methods, this invention can not only model intra-sentence dependencies but also handle complex structures involving cross-sentence, multi-hop, and multi-semantic paths, enhancing the system's semantic generalization and relation interpretation capabilities.
[0211] In summary, the relation extraction method based on graph neural networks proposed in this invention effectively solves the problems of low recognition rate and high false alarm rate of existing methods in complex semantic scenarios through multi-source feature fusion, heterogeneous graph modeling, path supervision and classification optimization strategies, and has significant technical progress and engineering practical value.
[0212] Example 3, please refer to Figure 2As shown in this embodiment, a relation extraction system based on a graph neural network includes:
[0213] The entity recognition module acquires the target text, performs word segmentation, part-of-speech tagging, and named entity recognition on the target text, and extracts the entity set; n represents the total number of entities;
[0214] The graph construction module constructs a text graph G = (V, R) based on the entity set, where V is a set of nodes including the entities and their context words, and R is a set of edges including syntactic dependency edges, positional edges, and co-occurrence edges.
[0215] The feature encoding module constructs an initial feature vector for each node v∈V in the graph. The feature vector includes word vectors, part-of-speech information, and positional information.
[0216] The graph neural network representation learning module inputs graph G into the graph neural network model and performs multi-layer message passing and aggregation to obtain the high-order representation of each node, where k is the number of layers in the graph neural network;
[0217] The relation modeling and classification module concatenates or combines the representations of target entity pairs in the graph, inputs them into the relation classifier to predict their relation type r∈R′, where R′ is a predefined set of relations;
[0218] The triplet construction module outputs triplets relating entity pairs based on the prediction results.
[0219] The above is only a specific implementation method of the present application, but the scope of protection of the present application is not limited thereto. Any technician familiar with this technical field can easily think of changes or replacements within the technical scope disclosed in this application, which should be covered by the scope of protection of the present application.
Claims
1. A relation extraction method based on graph neural networks, characterized in that: include: S100. Obtain the target text, and perform word segmentation, part-of-speech tagging, and named entity recognition on the target text to extract the entity set. n represents the total number of entities; S200. Construct a text graph G = (V, R) based on the entity set, where V is a set of nodes including the entities and their context words, and R is a set of edges including syntactic dependency edges, positional edges, and co-occurrence edges. S300. Construct an initial feature vector for each node v∈V in the graph. The feature vector includes word vectors, part-of-speech information, and positional information; S400. Input graph G into the graph neural network model and perform multi-layer message passing and aggregation to obtain the high-order representation of each node. , where k is the number of layers in the graph neural network; The S400 includes: S401. Input the text graph G = (V, R) into the graph neural network model, and use a heterogeneous graph convolution structure to define message passing functions for different types of edges R respectively; S402. In the k-th layer graph neural network, for each node v∈V, it receives edge-type weighted feature information from its neighboring nodes u∈N(v). ; S403. Aggregate neighbor information and its own upper-level representation. Perform residual connections and nonlinear transformations to generate the node representation of the current layer. ; S404, stacked k-layer graph neural networks to capture multi-order semantic dependencies, ultimately obtaining a set of high-order node representations containing global structural semantics. ; S500, For the target entity pairs in the diagram The representations are concatenated or combined and input into the relation classifier to predict its relation type r∈R′, where R′ is a predefined set of relations; S600, Output the triplet of relationships between entity pairs based on the prediction results. .
2. The relation extraction method based on graph neural networks according to claim 1, characterized in that: S100 includes: S101. Multi-channel encoding is performed on the target text. Pre-trained language models are used to extract context semantic vectors, lexical feature encoders are combined to extract part-of-speech embeddings, and BiLSTM is used to obtain syntactic sequence dependency representations. S102. Perform vector-level fusion of part-of-speech embedding representations to construct enhanced word vector representations, and introduce a position-aware mechanism to encode the positional bias information of words relative to entities in a sentence; S103. Based on the fused representation input conditional random field sequence labeler, a joint named entity recognition model is used to perform entity boundary recognition and type discrimination, and extract the entity set. n represents the total number of entities; S104. A confidence screening mechanism is used to perform semantic consistency checks on the preliminary identification results, filter out low-confidence entities, and improve the accuracy and robustness of the entity set.
3. The relation extraction method based on graph neural networks according to claim 1, characterized in that: S200 includes: S201. Based on the entity set E, select words within the context of the entity window to form a candidate node set, and combine the syntactic analysis results to introduce dependency subtree nodes to form a node set V. S202. A dependency parser is used to construct syntactic dependency relation edges. Directed edges are generated based on the dependency paths between words, and the syntactic relation type is attached as the edge weight attribute. S203. Calculate the relative positional distance between words and entities, and set a threshold to construct positional relationship edges. The edge weight decreases inversely with the relative positional distance to capture the influence of local word order. S204. Statistically count the co-occurrence frequency of entity pairs in the training corpus, and establish co-occurrence relation edges by combining word vector similarity. The edge weights are determined by a frequency-weighted cosine similarity function.
4. The relation extraction method based on graph neural networks according to claim 1, characterized in that: The S300 includes: S301. For each node v in the node set V, call the pre-trained language model to obtain the context semantic word vector embedding. Used to capture global semantic features; S302. Perform part-of-speech tagging on node v and map its corresponding part-of-speech tags to part-of-speech embedding vectors. Furthermore, a convolutional encoder is used to model the local context of the part-of-speech sequence; S303. Construct a position encoding vector hˡ(v) based on the relative position information between node v and its entity, and use a learnable position embedding parameter table to realize the vectorized representation of continuous distance; S304, will , and The vectors are concatenated, and an initial feature vector of uniform dimension is obtained through a nonlinear transformation and normalization operation. This is used as input for subsequent graph neural networks.
5. The relation extraction method based on graph neural networks according to claim 1, characterized in that: In the process of multi-layer message passing and aggregation in graph neural networks, the following further includes: S405. In each layer, construct paths for all possible multi-hop connection paths, use a differentiable path scoring function to score the importance of different paths, and use the path score as a weight adjustment factor for message aggregation. S406. The contextual semantics of nodes in the high-scoring path are used as structural supplementary signals and fused into the representation of the target node through a bidirectional gating mechanism to preserve the implicit semantic dependencies between cross-sentence or long-distance entities. S407. After the final node representation is generated, the joint path attention distribution is used as an explicit graph structure supervision signal to construct an auxiliary loss function, thereby optimizing the graph neural network's ability to model critical paths and its generalization performance.
6. The relation extraction method based on graph neural networks according to claim 1, characterized in that: The S500 includes: S501, For target entity pairs Extract the higher-order representation of each corresponding node. and It also merges the aggregated representations of all intermediate nodes within the shortest path in the graph structure to construct a structure-enhanced entity pair representation. ; S502. Introduce a context alignment module, using graph attention to assign different weights to the context nodes where entity pairs appear in the sentence, calculate their context semantic alignment vectors, and then correlate them with the context nodes of the sentence. To merge; S503. Input the fused entity pair representation into a multi-channel relation classification network, wherein the network includes a static relation prediction branch and a dynamic context-aware branch, which are used to model static semantic association and context-driven relation variability, respectively.
7. The relation extraction method based on graph neural networks according to claim 1, characterized in that: The S600 includes: S601. Dynamically model the confidence level of the relation probability distribution output by the classifier, and adaptively adjust the confidence value of the predicted relation r by combining the co-occurrence pattern of entity pairs in the context and the edge connection strength in the graph structure. S602. Set a confidence gating mechanism so that entity pair triples are constructed only when the prediction confidence exceeds a preset dynamic threshold. Otherwise, the prediction result is marked as a candidate relation and sent to the inference backtracking module for further confirmation; S603. Introduce a semantic consistency verification strategy during the triple generation process, by... and Type alignment and contextual semantic consistency are checked to eliminate candidate triples with semantic conflicts; S604 constructs the final output result set from triples that have passed confidence gating and consistency verification, and supports setting output rules according to domain or task type to realize customized management and automatic post-processing of triples.
8. A relation extraction system based on graph neural networks, used to implement the relation extraction method based on graph neural networks as described in any one of claims 1-7, characterized in that: include: The entity recognition module acquires the target text, performs word segmentation, part-of-speech tagging, and named entity recognition on the target text, and extracts the entity set; n represents the total number of entities; The graph construction module constructs a text graph G = (V, R) based on the entity set, where V is a set of nodes including the entities and their context words, and R is a set of edges including syntactic dependency edges, positional edges, and co-occurrence edges. The feature encoding module constructs an initial feature vector for each node v∈V in the graph. The feature vector includes word vectors, part-of-speech information, and positional information. The graph neural network representation learning module inputs graph G into the graph neural network model and performs multi-layer message passing and aggregation to obtain the high-order representation of each node, where k is the number of layers in the graph neural network; The relation modeling and classification module concatenates or combines the representations of target entity pairs in the graph, inputs them into the relation classifier to predict their relation type r∈R′, where R′ is a predefined set of relations; The triplet construction module outputs triplets relating entity pairs based on the prediction results.
Citation Information
Patent Citations
Domain long text classification method and system based on knowledge graph
CN116521882A
Entity relationship extraction method fusing semantic information and syntactic information
CN119128154A