A knowledge graph completion method and system based on heterosubgraph triple semantic aggregation
By constructing a heterogeneous graph and performing message aggregation using a heterogeneous subgraph triple semantic aggregation method, the problem of subgraph structure learning in existing technologies is solved, and the interpretability and completion accuracy of knowledge graphs are improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-24
- Publication Date
- 2026-03-13
AI Technical Summary
Existing technologies struggle to effectively learn subgraph structures, resulting in low interpretability of knowledge graph feature learning.
We adopt a method based on heterogeneous subgraph triple semantic aggregation. By constructing a heterogeneous graph, we obtain neighboring edges and neighboring nodes, use an attention mechanism to aggregate messages, learn the embedding representation of the directed subgraph of relational paths, and optimize the model through a loss function to achieve knowledge graph completion.
It improves the learning effect of knowledge graph structure and semantic features, enhances the interpretability of knowledge graph, and continuously improves the accuracy of the model through a self-reinforcing mechanism.
Smart Images

Figure CN116842185B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of knowledge graph feature learning, specifically to heteroproton-based learning. Figure 3 A knowledge graph completion method and system based on semantic aggregation. Background Technology
[0002] With the development of the internet, the amount of data has exploded. This data contains a wealth of knowledge and information, but its structure and semantics vary greatly, making it difficult to apply directly. Therefore, it is necessary to process and analyze the data to construct a knowledge graph with structured information and semantic relationships. Currently, with the development of natural language processing technology, natural language can be transformed into structured knowledge graph data. By extracting from large amounts of data, relationships between data can be summarized. However, these knowledge graphs often suffer from data sparsity and incompleteness.
[0003] Completing knowledge graphs helps improve their completeness, thereby enhancing the efficiency and accuracy of knowledge graph-based search engines and improving the service quality of intelligent customer service and personalized recommendations.
[0004] Among existing related technologies, triple-based methods have received widespread attention in knowledge graph completion. These methods directly reason about triples containing entities and relations. For example, the existing invention patent application document CN115809346A, "A Small Sample Knowledge Graph Completion Method Based on Multi-View Semantic Enhancement," combines structural views and text views to generate embedded representations of entities and relations. It uses an adaptive attention mechanism to address the influence of implicit common sense knowledge of entities on triples, and then considers that entities possess different common sense information under different relations to aggregate the neighborhood information of entities. Internal and external optimization processes handle complex relations by using common sense semantic constraints to locate embeddings with the same / different common sense knowledge into the same / different semantic spaces. Then, in the internal optimization process, it utilizes the characteristics of common sense views and complex relations to supervise the negative sampling process to generate effective and high-quality negative samples, and learns the representation of complex relations and hyperplane parameters. Finally, in the external optimization process, all parameters are updated to achieve better model results. Entities that do not conform to common sense knowledge are filtered out from the candidate entities through the common sense view, and the final candidate entity ranking is output. The aforementioned prior art, because it learns triples independently, cannot capture the local structure surrounding triples.
[0005] Therefore, path-based methods have been proposed. By sampling all relationship paths between entities and using an attention mechanism to weight different paths, they can capture structural information to some extent. However, when capturing structural information, subgraphs are clearly more reflective than paths.
[0006] The existing invention patent application document CN115438197A, entitled "A Method and System for Completing Relationships in a Knowledge Graph Based on a Two-Layer Heterogeneous Graph," describes a method comprising: S1, obtaining correspondences in all events from a known knowledge graph, wherein the correspondences include a heterogeneous graph composed of all entities contained in all events; S2, performing representation learning on the heterogeneous graph to obtain vector representations of each entity node, thereby obtaining subgraph structure embedding feature representations, and obtaining a pre-trained model, wherein step S2 further comprises: S21, obtaining and utilizing pre-set logical representation meta-paths; S22, aggregating the node embeddings of the meta-paths to obtain meta-path embedding representations, constructing a semantic embedding matrix, and fusing at least two meta-paths in an event to obtain the subgraph semantic features of the event on the heterogeneous graph; S23, generating heterogeneous subgraphs based on the node features and semantic features of the original heterogeneous subgraph, and fusing the heterogeneous subgraphs with the original heterogeneous subgraph to obtain a first fused new heterogeneous subgraph; S24, root... S25. Map each event in the first fused new heterogeneous subgraph to a subgraph, and fuse it with the node features and semantic features of the subgraph to obtain a second fused new heterogeneous subgraph; S26. Input the second fused new heterogeneous subgraph into a graph neural network model (GNN) and a pre-set regularizer to optimize the graph structure and GNN parameters of the second fused new heterogeneous subgraph through two-layer heterogeneous graph joint learning to obtain the pre-trained model; S3. Combine the pre-trained model to extract the event semantic features in the event knowledge graph; S4. Combine the subgraph structure embedding feature representation and the event semantic features to perform heterogeneous graph joint learning to obtain the event knowledge graph relationship prediction model; S5. Obtain and utilize new event entities, and expand and complete the basic heterogeneous graph according to the event knowledge graph relationship prediction model to obtain an updated heterogeneous graph. Use the updated heterogeneous graph to update the subgraph structure embedding feature representation to complete the event knowledge graph. The event knowledge graph relationship prediction model includes the TransR model. While the aforementioned existing GNN-based subgraph learning methods have achieved some success, they cannot distinguish the structural dependencies of neighbors and cannot interpret them. In addition, there are some methods based on closed subgraphs, but because they learn from closed subgraphs, their efficiency and effectiveness are relatively low.
[0007] In summary, existing technologies suffer from difficulties in effectively learning subgraph structures and low interpretability in knowledge graph feature learning. Summary of the Invention
[0008] The technical problem to be solved by this invention is how to solve the technical problems of existing technologies having difficulty in effectively learning subgraph structures and the low interpretability of knowledge graph feature learning.
[0009] The present invention solves the above-mentioned technical problems by adopting the following technical solution: based on heteroprotons Figure 3 Knowledge graph completion methods based on semantic aggregation include:
[0010] S1. Based on all events, entities, and relationships that constitute the knowledge graph of events, construct a heterogeneous graph with entities as nodes and relationships as edges.
[0011] S2. Based on the query parameters of entities and relationships, obtain adjacent edges and adjacent nodes from the heterogeneous graph, and construct a directed subgraph R of relationship paths accordingly.
[0012] S3. When executing step S2, the relation vector features in the query parameters are integrated into the neighboring edges and neighboring nodes in no less than two ways to obtain the fused feature vector. The attention value of the fused feature vector is calculated and the message is aggregated to obtain the current layer embedding representation. Step S3 is executed repeatedly until the set layer number L is reached, and the embedding representation of the directed subgraph R of the relation path is determined.
[0013] S4. Train the embedding representation of the directed subgraph R of the relational path to obtain the applicable model;
[0014] S5. By adding new entities, the original heterogeneous graph is completed to obtain a new heterogeneous graph. The new heterogeneous graph is then learned using an applicable model to complete the knowledge graph of the subject matter.
[0015] This invention proposes a three-level semantic message aggregation method based on nodes and relations, relations and neighbors, and nodes, relations, and neighbors to learn directed graphs extracted from knowledge graphs that are composed of relational paths. This enhances the learning of knowledge graph structure and semantic features, thereby achieving knowledge graph node completion.
[0016] In a more specific technical solution, step S1 includes:
[0017] S11. Obtain the set of entity, relation, and fact triples in the knowledge graph;
[0018] S12. Each entity in the knowledge graph is constructed using triples, where each entity includes a head entity and a tail entity.
[0019] S13. Extract the entities and their relationships of all events from the preset text;
[0020] S14. Increase the amount of data by adding inverse triples to obtain expanded triples. Construct a heterogeneous graph with entities in the expanded triples as nodes and relations as edges.
[0021] In a more specific technical solution, step S2 includes:
[0022] S21. Obtain the hierarchical path graph of st, which includes: a source node e q and a convergence node e a In the st hierarchical path graph, all edges connect nodes between consecutive layers, pointing from layer (l-1) to layer l.
[0023] S22, Move the source node e q and aggregation node e a Between, all paths with a length less than or equal to L are represented as relational paths of length L: e q →r 1 ·→r 2 …→r L e a ;
[0024] S23, Define the hierarchical metapath subgraph as The hierarchical path subgraph includes source entities and convergence entities. Entities within the same layer are distinct. In the path subgraph R, any path from the source entity to the convergence entity is a relational path: e q →r 1 ·→r 2 …→r L e a ;
[0025] S24. Construct the meta-path subgraph R. First, extract the neighborhoods of the source entity and the convergence entity at layer L to calculate the intersection of the neighborhoods. Then, use different convergence entities: e a ∈V, using the same query parameter (e q r q , ? ) to evaluate (e q r q e a When sharing the edge of the source entity, the adjacent edges
[0026] S25, in the source entity e q and the convergence entity e a When there is no relationship path between them, let
[0027] This invention proposes a novel attention-based semantic message aggregation method at three levels: node-relationship, relationship-adjacent, and node-relation-adjacent. This method is used to learn directed subgraph structures composed of paths between two nodes. Since the path between any two points in the graph may be a subset of the paths between other two nodes, we perform hierarchical message passing on such subgraphs and use dynamic programming to simplify the computation process, thereby optimizing the learning effect on the subgraph structure.
[0028] In a more specific technical solution, step S3 includes:
[0029] S31, For a query parameter (e) q r q During the construction of the directed graph, at least two levels of node and edge message passing are run. The node and edge message passing includes: node and relation level, relation and neighbor level, and node-relation-neighbor level semantic message aggregation.
[0030] S32. Initialize the matrix:
[0031]
[0032] Using as the medium for message passing between layers, in the formula, the superscript 0 indicates the layer, e q (e q r q ) indicates that e q Starting with (e) q r q () is for querying;
[0033] S33, Obtaining source node e a and convergence node e a When the neighborhood of the target node forms a path subgraph, when constructing the directed subgraph R of the relational path, attention coefficients of three levels are assigned to each node and edge, and the important path nodes and important edges of the target node are calculated accordingly, which serve as the calculation results of the three levels of attention mechanism.
[0034] S34. Aggregate the calculation results of the three attention mechanisms to obtain the aggregated message of the current layer:
[0035]
[0036] In the aforementioned formula:
[0037] In the formula, S hr This indicates the aggregation of nodes and relationships. Represents the aggregation of relations and adjacent edges. The coefficients l represent the l-th layer, θ is the Sigmoid activation function, and W represents the neighboring edge aggregation of node relationships. m ∈R n*n Let n be the linear transformation matrix, and n be the dimension.
[0038] S35. Furthermore, combining the GRU model to capture semantic relationships between long sequences, while mitigating gradient vanishing or exploding phenomena, the specific calculation method for processing aggregated messages at the current layer is as follows:
[0039] z t =θ(W z ·[h t-1 xt ])
[0040] r t =θ(W r ·[h t-1 x t ])
[0041]
[0042]
[0043] Where: h t-1 and x t As input to the GRU model, h t-1 equal x t Let W be the initial hidden layer tensor, θ be the Sigmoid activation function, σ be the Tanh activation function, and W be the σ value. z W r Both W and h are linear transformation matrices. t The output of the GRU model, i.e., the processed output.
[0044] In a more specific technical solution, step S33 involves three levels of semantic message aggregation calculation methods:
[0045] Nodes and Relationships:
[0046]
[0047] In the formula, the current query set is:
[0048] Q i ={(h i r i )|(h i r i h i )∈T tra}, T tra Represents the set of triples in the dataset; (h i r i ) represents the query in the current i-th batch (e q r q ,?);
[0049] N l h represents the set of neighboring edges obtained at layer l. r To obtain the embedding representation of the neighboring edges, σ is the activation function Tanh. W hr ∈R n*n Let n be the linear transformation matrix, and n be the dimension. It is the attention coefficient between nodes and relationships;
[0050] Relationships and neighbor level:
[0051]
[0052] In the formula, the query set Q i ={(h i r i )|(h i r i h i )∈T tra}, T tra Represents the set of triples in the dataset, (h i r i ) represents the query in the current i-th batch (h i r i ), (h i r i ) represents the query in the current i-th batch (e q r q ,?),Nl represents the set of neighboring edges obtained in the l-th layer, h r The obtained embedding representation of the neighboring edges is given by σ, which is the activation function Tanh. Let n be the linear transformation matrix, and n be the dimension. It is the attention coefficient between nodes and relationships;
[0053] Node relationships at the neighbor level:
[0054]
[0055] In the formula, the query set Q i ={(h i r i )|(h i r i h i )∈T tra}, T tra Represents the set of triples in the dataset, (h i r i ) represents the query in the current i-th batch (e q r q ,? ), N l h represents the set of neighboring edges obtained at layer l. r The obtained embedding representation of the neighboring edges is given by σ, which is the activation function Tanh. Let n be the linear transformation matrix, and n be the dimension. It is the attention coefficient between nodes and relationships.
[0056] In a more specific technical solution, in step S34, the calculation results of the three levels of messages are aggregated using the following logic to obtain the current layer aggregated message:
[0057]
[0058] in:
[0059] In the formula, S hr This indicates the aggregation of nodes and relationships. Represents the aggregation of relations and adjacent edges. The coefficient l represents the l-th layer, and θ is the Sigmoid activation function. IN m ∈R n*n Let n be the linear transformation matrix, and n be the dimension.
[0060] In this invention, a meta-path is the path taken by one entity to another in a heterogeneous graph. There are usually multiple such paths, which together form a new subgraph structure. Each path consists of nodes and edges, and multiple paths together constitute a subgraph. Furthermore, if attention coefficients are assigned to each neighboring node and edge when obtaining neighboring nodes and edges from known nodes, we can understand the influence of known neighboring nodes and edges on the inference of the target node—the attention coefficients—during the construction of this subgraph structure. This improves the interpretability of knowledge graph feature learning.
[0061] In a more specific technical solution, step S4 includes:
[0062] S41. Optimize the embedding representation of the directed subgraph R of the relational path through the loss function. Calculate the weight of each node and edge based on the query parameters and neighborhood semantic structure information to obtain applicable nodes and applicable edges, thereby learning and acquiring the structural features of the directed subgraph R of the relational path.
[0063] S42. Here, we set the scoring function for the prediction results as follows:
[0064]
[0065] S43. Update the parameters using the loss function through backpropagation to train a suitable model.
[0066] In a more specific technical solution, the loss function in step S43 adopts a multi-class function:
[0067]
[0068] In a more specific technical solution, step S5 includes:
[0069] S51. Based on the embedded representation, determine whether a new node is suitable to be added to the current heterogeneous graph;
[0070] S52. Add the new node to the original heterogeneous graph, complete and update the original heterogeneous graph to obtain the new heterogeneous graph;
[0071] S53, learn new heterogeneous graphs, obtain new embedded representations, and use them to complete the knowledge graph of things.
[0072] In this invention, the original heterogeneous graph is improved as the number of entities and relationships increases. Simultaneously, feedback to the original heterogeneous graph enhances the information content of the knowledge graph. Ultimately, through this continuous self-reinforcement, the knowledge graph becomes increasingly complete, and the accuracy of model completion is also improved.
[0073] In more specific technical solutions, based on heteroprotons Figure 3 The knowledge graph completion system with heavy semantic aggregation includes:
[0074] The heterogeneous graph construction module is used to construct a heterogeneous graph based on all events that constitute the knowledge graph, as well as all entities and relationships of the events, with entities as nodes and relationships as edges.
[0075] The directed subgraph construction module is used to obtain adjacent edges and adjacent nodes from the heterogeneous graph based on the query parameters of entities and relations, and construct a directed subgraph R of relational paths. The directed subgraph construction module is connected to the heterogeneous graph construction module.
[0076] The multi-attention embedding representation module is used to integrate the relation vector features in the query parameters into the neighboring edges and neighboring nodes in no less than two ways to obtain the fused feature vector, calculate the attention value of the fused feature vector, and perform message aggregation to obtain the current layer embedding representation until a set layer number L is reached. Then, the embedding representation of the directed subgraph R of the relation path is determined and constructed. The multi-attention embedding representation module is connected to the directed subgraph construction module.
[0077] The embedding representation training module is used to train the embedding representation of the directed subgraph R of relational paths to obtain an applicable model. The embedding representation training module is connected to the multi-attention embedding representation module.
[0078] The knowledge graph completion module is used to complete the original heterogeneous graph by adding new entities to obtain a new heterogeneous graph. The new heterogeneous graph is then learned using an applicable model to complete the knowledge graph of the subject matter. The knowledge graph completion module is connected to the embedding representation training module.
[0079] Compared with the prior art, the present invention has the following advantages: The present invention enhances the learning of the knowledge graph structure and semantic features by proposing the semantic message aggregation of nodes and relations, relations and neighbors, and nodes, relations and neighbors, and thus realizes the knowledge graph node completion.
[0080] This invention proposes a novel attention-based semantic message aggregation method at the node-relation level, relation-adjacent level, and node-relation-adjacent level for learning directed subgraph structures composed of paths between two nodes. Since the path between any two points in the graph may be a subset of the paths between other two nodes, we perform hierarchical message passing on this subgraph and employ dynamic programming to simplify the computation process, thereby optimizing the learning effect on the subgraph structure.
[0081] In this invention, a meta-path is the path taken by one entity to another in a heterogeneous graph. There are usually multiple such paths, which together form a new subgraph structure. Each path consists of nodes and edges, and multiple paths together constitute a subgraph. Furthermore, if attention coefficients are assigned to each neighboring node and edge when obtaining neighboring nodes and edges from known nodes, we can understand the influence of known neighboring nodes and edges on the inference of the target node—the attention coefficients—during the construction of this subgraph structure. This improves the interpretability of knowledge graph feature learning.
[0082] In this invention, the original heterogeneous graph is improved as the number of entities and relationships increases. Simultaneously, feedback to the original heterogeneous graph enhances the information content of the knowledge graph. Ultimately, through this continuous self-reinforcement, the knowledge graph becomes increasingly complete, and the accuracy of model completion is improved. This invention solves the technical problems of existing technologies, such as the difficulty in effectively learning subgraph structures and the low interpretability of knowledge graph feature learning. Attached Figure Description
[0083] Figure 1 This is the heteroproton-based embodiment of the present invention, which is described in Example 1 of the present invention. Figure 3 A schematic diagram illustrating the basic steps of a knowledge graph completion method based on semantic aggregation.
[0084] Figure 2 This is a schematic diagram illustrating the specific steps of constructing a heterogeneous graph in Embodiment 1 of the present invention;
[0085] Figure 3 This is a schematic diagram of the construction of a directed subgraph of relational paths in Embodiment 1 of the present invention;
[0086] Figure 4 This is a schematic diagram of the three levels of semantic message aggregation processing logic in Embodiment 1 of the present invention;
[0087] Figure 5 This is the path subgraph of Embodiment 1 of the present invention. Construction process diagram;
[0088] Figure 6 This is a schematic diagram illustrating the specific steps of constructing the embedded representation of the relational path subgraph in Embodiment 1 of the present invention;
[0089] Figure 7 This is a schematic diagram of the GRU model in Embodiment 1 of the present invention;
[0090] Figure 8 This is a directed graph R in Embodiment 1 of the present invention, and a schematic diagram of the recursive encoding of the directed graph R in the overall directed graph;
[0091] Figure 9 This is a schematic diagram illustrating the specific steps of the directed subgraph embedding representation and training of relational paths in Embodiment 1 of the present invention;
[0092] Figure 10 This is a schematic diagram illustrating the specific steps involved in completing the knowledge graph in Embodiment 1 of the present invention. Detailed Implementation
[0093] 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 in conjunction with the embodiments of the present invention. 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.
[0094] Example 1
[0095] like Figure 1 As shown, the present invention provides a heteroproton-based... Figure 3 The knowledge graph completion method based on semantic aggregation includes the following basic steps:
[0096] S1: Given all events that constitute the knowledge graph of events and all entities and relationships contained in all events, construct a heterogeneous graph with entities as nodes and relationships as edges;
[0097] S2: Based on the queried entities and relationships, obtain adjacent edges and adjacent nodes from the heterogeneous graph, and start constructing the directed subgraph R of relational paths;
[0098] In this embodiment, the known knowledge graph contains a large number of entities composed of events and the relationships between entities. These entities, representing events, collectively constitute a basic heterogeneous graph. A meta-path is the path taken by one entity to another in the heterogeneous graph; there are usually multiple paths, which can collectively form a new subgraph structure. Since this is a subgraph structure based on paths, if we add an attention coefficient to each neighboring edge and neighboring node when a node acquires its neighbors, we can determine during the construction of this subgraph structure that known neighboring nodes and edges are more meaningful for inferring the target node.
[0099] S3: When constructing the directed subgraph R of the relational path, the adjacent edges and adjacent nodes are integrated into the relational vector features in the query in three ways, and the attention value of the fused feature vector is calculated. Then, message aggregation is performed to obtain the embedding representation of this layer. This step is repeated until the set number of layers L is reached, and the embedding representation of the relational path subgraph is obtained.
[0100] In this embodiment, for query (e q r q , ? )(where e q This represents querying the head node of a triple, r q (This refers to querying relations within triples.) First, a subset of triples constituting the knowledge graph is randomly selected, with the head nodes of these triples serving as the starting points for the paths. Then, from the heterogeneous graph formed by these triples, the edges and neighboring nodes within a fixed hop count range of these nodes are obtained. The head nodes are already incorporated into the features at the beginning of the subgraph construction, but during the query... q Since it does not have any correlation with subsequent neighboring edges and nodes, we will use r when constructing each layer of the directed graph. q The features are then incorporated into the features of neighboring nodes and edges. An attention-based computation is then performed on the incorporated features, namely, the aggregation of semantic feature messages at the node-relationship level, relationship-neighborship level, and node-relationship-neighborship level, ultimately yielding the feature embedding of the subgraph.
[0101] S4: Train the embedded representation of the directed subgraph of relational paths after construction;
[0102] S5: By adding new entities to complete the original heterogeneous graph, and then using the new heterogeneous graph for further learning, the accuracy of the model can be improved, thus achieving the completion of the knowledge graph.
[0103] In this embodiment, the tail node in the triplet of the query is then used as the prediction target to train (query(e)). q r q The term "?" is composed of head nodes and relations of triples randomly selected from the training set. The tail nodes are known during model training but are not used as input conditions. In this way, the importance of known nodes in a heterogeneous primitive path to the target node can be learned, thus obtaining an attention-based embedding representation of the target node. This enables node completion for the knowledge graph.
[0104] like Figure 2 As shown, in this embodiment, step S1 further includes the following specific steps:
[0105] S11: It is known that the knowledge graph KG exists in the form of K = {V, R, F}, where V, R, F = {(e s ,r,e o )|e s en ∈V, r∈R} are sets of entity, relation, and fact triples, respectively;
[0106] S12: Each fact in the knowledge graph is composed of a triple; in this embodiment, the entities in the triple are represented by e. s e o (e s For the head entity, e o The entity is represented by the tail, and the relation is represented by r.
[0107] S13: Entity e in the triples constituting the heterogeneous graph s e o The relation r is extracted from texts containing knowledge facts, such as news articles and e-books; in this embodiment, entity e s e o The types include people, things, places, etc. Each fact contains entities and the relationships between them. Extract the entities and relationships of all events.
[0108] S14: Add inverse triples to increase the amount of data. Construct a heterogeneous graph with entities in the expanded triples as nodes and relations as edges.
[0109] In this embodiment, inverse relation refers to swapping the head and tail entities of a fact triple to form a new triple. In this embodiment, heterogeneous graphs include, but are not limited to, graphs with various types of nodes and relations.
[0110] like Figure 3 As shown, in this embodiment, step S2 further includes the following specific steps:
[0111] S21: The st hierarchical path graph is a directed graph with exactly one source node e. q and a convergence node e a All edges are oriented and can connect nodes between consecutive layers, pointing from layer (l-1) to layer l.
[0112] S22:e q and e a All paths with a length less than or equal to L are represented as relation paths e of length L. q →r 1 ·→r 2 …→r L e a ;
[0113] S23: The metapath subgraph R is defined as... It is a source entity e q and convergence entity e a A hierarchical path graph, where entities in the same layer have different path subgraphs R from e qto e a Any path is a relational path. q →r 1 ·→r 2 …→r L e a In this embodiment, r L Connect an entity in layer L-1 to an entity in layer L.
[0114] S24: Construct the metapath subgraph R, first extracting e q and e a The neighborhood of L, then calculate e q and e a The intersection of neighborhoods, when using different e a ∈V, but using the same query (e q r q , ? ) to evaluate (e q r q e a When ), e q Adjacent edges Shared.
[0115] like Figure 5 As shown, in this embodiment, the computational cost of overlapping subproblems is saved by using dynamic programming, and e is recursively constructed. q and any entity e o From the directed graph between them, we obtain the directed graph.
[0116] S25: If e q and e a There is no path order between them.
[0117] like Figure 6 As shown, in this embodiment, step S3 further includes the following specific steps:
[0118] S31: For a query (e q r q During the construction of the directed graph, three levels of attention-based message passing for nodes and edges are executed. In this embodiment, attention-based message passing for nodes and edges includes, but is not limited to: node-relation level, relation-adjacent level, and node-relation-adjacent level semantic aggregation.
[0119] S32: Known query (e q r q In the case of , ?, initialize a matrix As a medium for message passing between layers, where the superscript 0 indicates a layer, e q (eq r q ) indicates that e q Starting with (e) q r q () is for querying;
[0120] S33: Since it is a subgraph structure based on metapaths, when obtaining e... q and e a When constructing a path subgraph from the neighborhood of a node, each node and edge is assigned an attention coefficient at three levels. During the construction of the path subgraph, path nodes and edges that are more important to the target node are calculated.
[0121] like Figure 4 As shown, in this embodiment, the three levels of semantic message feature calculation methods are as follows:
[0122] (1) Node and Relationship Level:
[0123]
[0124] The current query set Q i ={(h i r i )|(h i r i h i )∈T tra},
[0125] T tra Represents the set of triples in the dataset, (h i r i ) represents the query in the current i-th batch (e q r q ,? ), N l h represents the set of neighboring edges obtained at layer l. r To obtain the embedding representation of the neighboring edges, σ is the activation function Tanh. W hr ∈R n*n Let n be the linear transformation matrix, and n be the dimension. It is the attention coefficient between nodes and relationships.
[0126] In this embodiment, The specific calculation method is as follows:
[0127]
[0128] Where W∈R n*n Let n be a learnable matrix, and h be the dimension size. i r i Indicates the i-th batch of queries (e q r qThe head node e in ( , ? ) q Relationship r q Embedded representation.
[0129] (2) Relationships and Adjacency Level:
[0130]
[0131] The query set Q i ={(h i r i )|(h i r i h i )∈T tra}, T tra Represents the set of triples in the dataset, (h i r i ) represents the query in the current i-th batch (e q r q ,? ), N l h represents the set of neighboring edges obtained at layer l. r The obtained embedding representation of the neighboring edges is given by σ, which is the activation function Tanh. Let n be the linear transformation matrix, and n be the dimension. It is the attention coefficient between nodes and relationships.
[0132] In this embodiment, The specific calculation method is as follows:
[0133]
[0134] Where W∈R n*n Let n be a learnable matrix, and h be the dimension size. i r i Indicates the i-th batch of queries (e q r q The head node e in ( , ? ) q Relationship r q Embedded representation, This represents the embedding representation of the neighboring edges obtained at layer l.
[0135] (3) Node relationship at the adjacent level:
[0136]
[0137] The query set Q i ={(h i r i )|(h i r i h i )∈T tra}, Ttra Represents the set of triples in the dataset, (h i r i ) represents the query in the current i-th batch (e q r q ,? ), N l h represents the set of neighboring edges obtained at layer l. r The obtained embedding representation of the neighboring edges is given by σ, which is the activation function Tanh. Let n be the linear transformation matrix, and n be the dimension. It is the attention coefficient between nodes and relationships.
[0138] In this embodiment, The specific calculation method is as follows:
[0139]
[0140] Where W∈R n*n Let n be a learnable matrix, and h be the dimension size. i r i Indicates the i-th batch of queries (e q r q The head node e in ( , ? ) q Relationship r q Embedded representation, This represents the embedding representation of the neighboring edges obtained at layer l.
[0141] S34: The results calculated by the three attention mechanisms are aggregated by addition to obtain the message of this layer:
[0142]
[0143] In this embodiment:
[0144] Where S hr This indicates the aggregation of nodes and relationships. Represents the aggregation of relations and adjacent edges. The coefficients l represent the l-th layer, θ is the Sigmoid activation function, and W represents the neighboring edge aggregation of node relationships. m ∈R n*n Let n be the linear transformation matrix, and n be the dimension.
[0145] S35: Then, combine the GRU model to perform selection and filtering on the aggregated message passing.
[0146] like Figure 7 As shown, in this embodiment, semantic relationships between long sequences are captured, and the current layer aggregated message is processed using the following formula to alleviate gradient vanishing or exploding phenomena. The specific processing method for the current layer aggregated message in this embodiment includes:
[0147] z t =θ(W z ·[h t-1 x t ])
[0148] r t =θ(W r ·[h t-1 x t ])
[0149]
[0150]
[0151] Where: h t-1 and x t As input to the GRU model, h t-1 equal x t Let W be the initial hidden layer tensor, θ be the Sigmoid activation function, σ be the Tanh activation function, and W be the σ value. z W r Both W and h are linear transformation matrices. t The output of the GRU model, i.e., the processed output.
[0152] like Figure 8 As shown, in this embodiment, the next layer is used to obtain the neighborhood, calculate the triple attention, and obtain all entities e. a For the graph Encoding representation
[0153] like Figure 9 As shown, in this embodiment, step S4 further includes the following specific steps:
[0154] S41: Message embedding of the path subgraph R calculated in S3 Optimization is performed using a loss function. This message, embedded during the optimization process, can be used to assign values to each node and edge based on a query (e.g., ...). q r q We calculate weights based on the semantic and structural information of the neighborhood, thereby obtaining the nodes and edges most useful for reasoning the results, and learning the structural features of the path subgraph.
[0155] S42: Here, set the scoring function for the prediction results as follows:
[0156]
[0157] S43: The loss function uses a multi-class function, that is:
[0158]
[0159] In this embodiment, the first part includes T tra (Training set) triples (e q r q e a The second part of the score includes those with the same query (e) q r q The scores of all triples ( , ? ).
[0160] S44: The model can be trained by updating the parameters through backpropagation using the loss function. It can be used to predict links in the knowledge graph of events, and similarly, it can be used to complete the triples of missing tail entities.
[0161] like Figure 10 As shown, step S5 includes the following specific steps:
[0162] S51: If a new entity is added to the current heterogeneous graph, it remains isolated within the knowledge graph and has not yet established relationships with other events. This is based on the knowledge already learned from the training set using queries (e... q r q An attention-based embedding representation with conditions , ? is used to determine whether a new node can be added to the current heterogeneous graph.
[0163] S52: Once it is determined that a new entity can form a relationship with the original entity, we add the new entity to the original heterogeneous graph and complete and update the original heterogeneous graph.
[0164] S53: Since new nodes have been added to the original heterogeneous graph, the original heterogeneous graph has been updated, and therefore the meta-path subgraph extracted from it has also been updated. We will further study this subgraph containing new information to obtain new embedding representations.
[0165] S54: After determining whether a new node belongs to the original heterogeneous graph, the new node is added to the original heterogeneous graph, expanding and updating it. As the number of entities and relationships increases, the original heterogeneous graph becomes more complete. Simultaneously, feedback to the original heterogeneous graph enhances the information content of the knowledge graph. Ultimately, through this continuous self-reinforcement, the knowledge graph becomes increasingly complete, and the accuracy of model completion is improved.
[0166] In summary, this invention enhances the learning of the structure and semantic features of the knowledge graph by proposing semantic message aggregation at the node-relation level, relation-adjacent level, and node-relation-adjacent level to learn the directed graph extracted from the knowledge graph, which is composed of relation paths. This enables the completion of knowledge graph nodes.
[0167] This invention proposes a novel attention-based semantic message aggregation method at the node-relation level, relation-adjacent level, and node-relation-adjacent level for learning directed subgraph structures composed of paths between two nodes. Since the path between any two points in the graph may be a subset of the paths between other two nodes, we perform hierarchical message passing on this subgraph and employ dynamic programming to simplify the computation process, thereby optimizing the learning effect on the subgraph structure.
[0168] In this invention, a meta-path is the path taken by one entity to another in a heterogeneous graph. There are usually multiple paths, which together form a new subgraph structure. Each path consists of nodes and edges, and multiple paths together constitute a subgraph. Furthermore, when obtaining neighboring nodes and edges through known nodes, an attention coefficient is assigned to each neighboring edge and node. This allows us to understand the influence of known neighboring nodes and edges on the inference of the target node—the attention coefficient—during the construction of this subgraph structure, thereby improving the interpretability of knowledge graph feature learning.
[0169] In this invention, the original heterogeneous graph is improved as the number of entities and relationships increases. Simultaneously, feedback to the original heterogeneous graph enhances the information content of the knowledge graph. Ultimately, through this continuous self-reinforcement, the knowledge graph becomes increasingly complete, and the accuracy of model completion is improved. This invention solves the technical problems of existing technologies, such as the difficulty in effectively learning subgraph structures and the low interpretability of knowledge graph feature learning.
[0170] The above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A knowledge graph completion method based on heteroprotic subgraph triple semantic aggregation, characterized in that, The method includes: S1. Based on all events constituting the knowledge graph and all entities and relationships of the events, construct a heterogeneous graph with the entities as nodes and the relationships as edges. S2. Based on the query parameters of the entity and the relationship, obtain the adjacent edges and adjacent nodes from the heterogeneous graph, and construct a directed subgraph of the relationship path accordingly. ; S3. When performing step S2, the relation vector features in the query parameters are integrated into the neighboring edges and neighboring nodes in at least two ways to obtain a fused feature vector. The attention value of the fused feature vector is calculated, and message aggregation is performed accordingly to obtain the current layer embedding representation. Step S3 is executed repeatedly until a set number of layers is reached. Determine and construct the directed subgraph of the relationship path. Embedded representation; S3 includes: S31. For one of the query parameters During the construction of the directed graph, at least two levels of point and edge message passing are run. The point and edge message passing includes: node-level aggregation, point-edge-level aggregation, and comprehensive aggregation: node-relationship level, relationship-adjacent-edge level, and node-relationship-adjacent-edge level semantic message aggregation. S32. Initialize the matrix: Using as the medium for message passing between layers, in the formula, the superscript Presentation layer, Indicated by Starting from the node, For querying; S33, Obtaining the source node and aggregation nodes When constructing a path subgraph from the neighborhood of the relational path, the directed subgraph of the relational path is constructed. At that time, attention coefficients of three levels are assigned to each node and edge, and the important path nodes and important edges of the target node are calculated accordingly, which serve as the calculation results of the three levels of attention mechanism. S34. Aggregate the calculation results of the three attention mechanisms to obtain the current layer aggregated message: In the aforementioned formula: In the formula, This indicates the aggregation of nodes and relationships. Represents the aggregation of relations and adjacent edges. The coefficients of adjacent edges representing node relationships are aggregated. Indicates the first layer, for Activation function , Let be a linear transformation matrix. For dimension size; S35. Combining the GRU model, the semantic relationships between long sequences are captured, and the current layer aggregated message is processed using the following logic: in: and for GRU The input to the model makes equal , For the initial hidden layer tensor, for Sigmoid Activation function Activation function Tanh , Both are linear transformation matrices. for GRU Model output, i.e., the processed output ; S4. Train the directed subgraph of the relational paths. The embedded representation is used to obtain the applicable model; S5. By adding new entities, the original heterogeneous graph is completed to obtain a new heterogeneous graph. The new heterogeneous graph is learned using the applicable model to complete the completion of the knowledge graph of the subject matter.
2. The knowledge graph completion method based on heteroprotic subgraph triple semantic aggregation according to claim 1, characterized in that, Step S1 includes: S11. Obtain the set of entity, relation, and fact triples in the knowledge graph. S12. Each entity in the knowledge graph is constructed using the triples, wherein the entity includes a head entity and a tail entity; S13. Extract the entities and their relationships for all events from the preset text; S14. Increase the amount of data by adding inverse triplet relations to obtain amplified triplets, and construct the heterogeneous graph with the entities in the amplified triplets as nodes and the relations as edges.
3. The knowledge graph completion method based on heteroprotic subgraph triple semantic aggregation according to claim 1, characterized in that, Step S2 includes: S21, Obtain A hierarchical path graph, which includes: a source node and a convergence node , wherein In the hierarchical path graph, all edges connect nodes between consecutive layers, starting from the first layer. Layer points to the first layer; S22, the source node and the aggregation node Between, all lengths less than or equal to The path is represented as a path of length . Relationship path: ; S23, Define the hierarchical metapath subgraph as The hierarchical meta-path subgraph includes source entities and convergence entities, with each entity in the same layer having a different path subgraph. In this context, any path from the source entity to the aggregation entity is a relational path: ; S24. Construct the metapath subgraph First, extract the source entity and The neighborhood of the convergent entity in the layer is used to calculate the intersection of the neighborhoods, using different convergent entities: Using the same query parameters To evaluate At the same time, the adjacent edges of the source entity are shared. ; S25, in the source entity .
4. The knowledge graph completion method based on heterosubgraph triple semantic aggregation according to claim 1, characterized in that, In step S33, the aggregation calculation methods for the three levels of semantic messages include: node and relation level, relation and neighbor level, and node-relation-neighbor level, wherein: Using the following logic, the semantic message is aggregated and computed at the node and the relation level: In the formula, the current query set , , Indicates the first The set of neighboring edges obtained by the layer. To obtain the embedding representation of the neighboring edges, Activation function Tanh ; The linear transformation matrix , For dimension size, ; Using the following logic, the semantic message is aggregated and computed at the relation and the neighbor level: In the formula, the query set , , Indicates the first The set of neighboring edges obtained by the layer. To obtain the embedding representation of the neighboring edges, Activation function ; Let be a linear transformation matrix. For dimension size, ; Using the following logic, the semantic message is aggregated and computed at the node relationship neighbor level: In the formula, the query set Represents the set of triples in the dataset. Indicates the first The set of neighboring edges obtained by the layer. To obtain the embedding representation of the neighboring edges, Activation function Tanh , Let be a linear transformation matrix. For dimension size, .
5. The knowledge graph completion method based on heteroprotic subgraph triple semantic aggregation according to claim 1, characterized in that, In step S34, the calculation results of the three levels of messages are aggregated using the following logic to obtain the current layer aggregated message: in: In the formula, This indicates the aggregation of nodes and relationships. Represents the aggregation of relations and adjacent edges. The coefficients of adjacent edges representing node relationships are aggregated. Indicates the first layer, for Sigmoid Activation function Let be a linear transformation matrix. For the dimension size.
6. The knowledge graph completion method based on heteroprotic subgraph triple semantic aggregation according to claim 1, characterized in that, Step S4 includes: S41. Optimize the directed subgraph of the relational path using a loss function. The embedding representation calculates the weights of each node and edge based on the query parameters and neighborhood semantic structure information to obtain applicable nodes and edges, thereby learning and acquiring the directed subgraph of the relational path. Structural features; S42. Here, we set the scoring function for the prediction results as follows: ; S43. Update the parameters using the loss function through backpropagation to train an applicable model.
7. The knowledge graph completion method based on heteroprotic subgraph triple semantic aggregation according to claim 6, characterized in that, The loss function in step S43 adopts multi-class function: 。 8. The knowledge graph completion method based on heteroprotic subgraph triple semantic aggregation according to claim 1, characterized in that, Step S5 includes: S51. Based on the embedded representation, determine whether the new node is suitable to be added to the current heterogeneous graph; S52. Add the new node to the original heterogeneous graph, complete and update the original heterogeneous graph to obtain a new heterogeneous graph; S53, learn the new heterogeneous graph, obtain a new embedding representation, and use it to complete the knowledge graph of the subject matter.
9. A knowledge graph completion system based on heterogeneous subgraph triple semantic aggregation, used to execute the knowledge graph completion method based on heterogeneous subgraph triple semantic aggregation as described in any one of claims 1 to 8, characterized in that, The system includes: The heterogeneous graph construction module is used to construct a heterogeneous graph based on all events constituting the knowledge graph, as well as all entities and relationships of the events, with the entities as nodes and the relationships as edges. The directed subgraph construction module is used to obtain neighboring edges and neighboring nodes from the heterogeneous graph based on the query parameters of the entity and the relationship, and construct a directed subgraph of relationship paths accordingly. R The directed subgraph construction module is connected to the heterogeneous graph construction module; The multi-attention embedding representation module is used to integrate the relation vector features in the query parameters into the neighboring edges and neighboring nodes in at least two ways to obtain a fused feature vector, calculate the attention value of the fused feature vector, and perform message aggregation to obtain the current layer embedding representation, until a set number of layers is reached. L Determine and construct the directed subgraph of the relationship path. R The multi-attention embedding representation module is connected to the directed subgraph construction module; Embedded representation training module, used to train the directed subgraph of the relation path. R The embedding representation is used to obtain an applicable model, and the embedding representation training module is connected to the multi-attention embedding representation module; The knowledge graph completion module is used to complete the original heterogeneous graph by adding new entities to obtain a new heterogeneous graph. The new heterogeneous graph is then learned using the applicable model to complete the completion of the knowledge graph. The knowledge graph completion module is connected to the embedding representation training module.
Citation Information
Patent Citations
Small sample knowledge graph completion method based on multi-view semantic enhancement
CN115809346A
Knowledge completion method and system under cloud ERP (Enterprise Resource Planning) based on heterogeneous graph comparative learning
CN114493516A
Two-layer heterogeneous graph-based affair knowledge graph relation completion method and system
CN115438197A