A representation learning method of time sequence knowledge graph based on local-global feature fusion
By using a local-global feature fusion method, the problems of temporal dynamic changes and information fragmentation in traditional knowledge graph representation learning are solved, achieving higher prediction accuracy and robustness, as well as improved adaptability and generalization ability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- KUNMING UNIV OF SCI & TECH
- Filing Date
- 2026-03-03
- Publication Date
- 2026-04-28
AI Technical Summary
Traditional knowledge graph representation learning methods ignore the dynamic characteristics of entities and relationships over time, resulting in a disconnect between local and global information. This makes it difficult to effectively model temporal dynamic changes, entity-relationship coupling, and semantic heterogeneity, thus affecting prediction performance.
By dividing the time axis into multiple time points, local spatiotemporal features are extracted using a local encoder, global features are extracted using a global encoder, and the gating mechanism is used to adaptively weight the features for fusion. Entity and relation prediction is performed by combining ConvTransE and ConvTransR models, and end-to-end training is driven by a loss function.
It improves the model's prediction accuracy and robustness for time-series knowledge graphs, enhances its ability to capture long-term dependencies, and improves the model's adaptability and generalization ability in different application scenarios.
Smart Images

Figure CN121787592B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of temporal knowledge graph technology, and more specifically, to a representation learning method for temporal knowledge graphs based on local-global feature fusion. Background Technology
[0002] Traditional knowledge graph representation learning methods mostly focus on static knowledge graphs, ignoring the dynamic characteristics of entities and relations evolving over time. However, in many practical applications (such as recommender systems and financial risk prediction), entities and their relations change over time. Existing methods typically only focus on extracting local structural information from the knowledge graph (through graph convolutional networks (GCNs) or relational graph convolutional networks (RGCNs), while neglecting the global semantic information within the entire graph structure. This local perspective prevents the model from fully utilizing the potential long-range dependencies within the entire graph structure, thus affecting the final prediction performance. In temporal knowledge graphs, the coupling between entities and relations, as well as the heterogeneity of their respective semantics, pose a challenge. Simply embedding entities and relations into the same vector space can lead to information loss or inaccurate representations, thereby affecting the performance of downstream tasks. Therefore, this paper proposes a representation learning method for temporal knowledge graphs based on local-global feature fusion. Summary of the Invention
[0003] The purpose of this invention is to provide a representation learning method for temporal knowledge graphs based on local-global feature fusion, so as to solve the problems of traditional knowledge graph representation learning methods proposed in the background art, which are difficult to effectively model temporal dynamic changes, the separation of local and global information, entity-relation coupling and semantic heterogeneity.
[0004] To achieve the above objectives, the present invention aims to provide a representation learning method for temporal knowledge graphs based on local-global feature fusion, comprising the following steps:
[0005] S1. Divide the entire timeline into multiple time points and construct a time-series knowledge graph based on these time points;
[0006] S2. Based on the temporal knowledge graph, a local encoder is used to extract local spatiotemporal features, and a global encoder is used to extract global features.
[0007] S3. The local spatiotemporal features are fused with global features using an adaptive weighting method with a gating mechanism.
[0008] S4. Based on the decoder, the fused features are used to perform entity prediction using the ConvTransE model, and based on the decoder, the fused features are used to perform relationship prediction using the ConvTransR model.
[0009] S5. Feed the prediction results back to the loss function to drive end-to-end training.
[0010] As a further improvement to this technical solution, in step S1, the entire timeline is divided into multiple time points, and a time-series knowledge graph is constructed based on these time points, including the following steps:
[0011] S1.1. Based on the time interval x, divide the entire time axis into a series of consecutive time points. Each time point represents a specific time period. Construct the corresponding time sub-graph based on the entity relationships that occur within that time period.
[0012] S1.2 For each point in time, collect data on all entities and their relationships that occurred within the corresponding time period;
[0013] S1.3 At each time point, a corresponding knowledge graph is constructed using a multi-relationship graph structure encoder based on the collected data.
[0014] As a further improvement to this technical solution, in step S2, local spatiotemporal features are extracted using a local encoder based on a temporal knowledge graph, including the following steps:
[0015] S2.1 At each time step, a relational graph convolutional network is used to take the entity node embedding representation obtained in the previous time step as input, and the graph convolution module RGCNCell is used to perform relation-aware graph convolutional updates on the current graph structure.
[0016] S2.2. The UnionRGCNLayer is used to aggregate and update the neighbors of each node. Edges of different relation types are guided by the input relation embedding and aggregated using different convolution parameters.
[0017] S2.3 When updating the representation of entities in the graph at each time step, a long short-term memory network is used to update the entity embeddings in each graph at each time step;
[0018] S2.4. Collect relevant entity context embeddings based on the connection relationships between entities, aggregate them, and merge them with the current relationship embeddings to generate a new temporal relationship representation;
[0019] S2.5 After the above steps, the local encoder generates a temporally enhanced hidden representation.
[0020] As a further improvement to this technical solution, step S2 involves extracting global features using a global encoder, including the following steps:
[0021] S2.6 Merge the historical time subgraphs and calculate the historical global entity representation matrix through the structure convolution module;
[0022] S2.7 Construct a query semantic vector using entity embeddings and relational context representations in the current query;
[0023] S2.8 Calculate the importance of historical entities through an attention mechanism and output a global semantic representation.
[0024] As a further improvement to this technical solution, in step S3, a gating mechanism adaptive weighting method is used to fuse local spatiotemporal features with global features, including the following steps:
[0025] S3.1 Define trainable parameter matrices and corresponding bias terms for local spatiotemporal features and global features respectively, and use activation functions to control the weights of local and global features;
[0026] S3.2 Calculate the respective gating weights based on the local spatiotemporal features and global features and their corresponding parameter matrices;
[0027] S3.3 Modulate the original local spatiotemporal features and global features based on the calculated gating weights;
[0028] S3.4. Concatenate the gated local spatiotemporal features with the global features to form a new vector;
[0029] S3.5. Feed the concatenated vector into an MLP layer for nonlinear transformation to generate the final fused representation.
[0030] As a further improvement to this technical solution, in step S4, entity prediction is performed on the fused features using the ConvTransE model based on the decoder, including the following steps:
[0031] S4.1 For the embedded representation of main entities and relationships, convolution-based operations are used to extract features;
[0032] S4.2. The embedded representations of the main entities and relationships are fused together through feature fusion operations;
[0033] S4.3 Match the fused representation with the target entity for prediction and calculate the score.
[0034] As a further improvement to this technical solution, in step S4, the relationship prediction is performed on the fused features using the ConvTransR model based on the decoder, including the following steps:
[0035] S4.4 Introduce a relation-specific projection matrix in the ConvTransR model;
[0036] S4.5. Through the dynamic projection mechanism, based on the embedding of the subject and object of the current triple in the previous moment, map them to the corresponding relational subspace.
[0037] S4.6 Define the scoring function for relation prediction and calculate the probability that a given triplet is true.
[0038] As a further improvement to this technical solution, in step S5, the prediction result is fed back to the loss function to drive end-to-end training, including the following steps:
[0039] S5.1. Use the scores of entity prediction and relationship prediction in step S4 as input to calculate the loss function, and select the marginal loss function as the optimization objective.
[0040] S5.2 Execute forward propagation, process the input data using the current model parameters, and obtain the prediction score for each triple;
[0041] S5.3 Calculate the gradient of the loss function with respect to the parameters of each layer, starting from the output layer and working backwards.
[0042] S5.4 In each layer, calculate the gradient of the loss with respect to each weight parameter according to the chain rule;
[0043] S5.5. Update the model parameters using an optimization algorithm based on the calculated gradient;
[0044] S5.6 Repeat the forward propagation, loss calculation, back propagation, and parameter update process for the entire dataset until the maximum number of iterations y is reached.
[0045] As a further improvement to this technical solution, in S5.4, in each layer, the gradient of the loss with respect to each weight parameter is calculated according to the chain rule, including the following steps:
[0046] S5.41. Process the input data using the current network parameters to obtain the prediction score for each triple;
[0047] S5.42. Calculate the difference between the model output and the actual labels using the selected loss function;
[0048] S5.43. Starting from the last layer, calculate the gradient of the loss with respect to the output of that layer;
[0049] S5.44. Calculate the error term and parameter gradient for each layer in the network.
[0050] As a further improvement to this technical solution, in step S5.5, the model parameters are updated using an optimization algorithm based on the calculated gradient, including the following steps:
[0051] S5.51. Initialize all parameters of the model;
[0052] S5.52. Process the input data using the current model parameters to generate prediction results;
[0053] S5.53, Introduced a learning rate scheduler;
[0054] S5.54. For each parameter, update the parameter according to its corresponding gradient.
[0055] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0056] 1. This representation learning method for temporal knowledge graphs based on local-global feature fusion combines spatiotemporal features and global semantic information extracted from the knowledge graph by local and global encoders, enabling more accurate capture of the dynamic changes of entities and their relationships over time. In particular, the adaptive weighting method using a gating mechanism to fuse local and global features not only enhances the model's understanding of short-term details but also strengthens its ability to capture long-term dependencies. This multi-layered information integration approach gives the model higher prediction accuracy and robustness when processing complex temporal graph data, thereby improving the performance of downstream tasks such as entity prediction and relationship prediction.
[0057] 2. This representation learning method for temporal knowledge graphs based on local-global feature fusion effectively addresses the coexistence of entity-relation coupling and semantic heterogeneity in temporal knowledge graphs by introducing an evolutionary mechanism for relation embedding and using ConvTransE and ConvTransR models for entity and relation prediction, respectively. Furthermore, the aggregation of entity embeddings in the historical graph structure using an attention mechanism further enhances the model's focus on important nodes at different times, making it better adaptable to various application scenarios. This approach not only increases the model's adaptability to different types of data but also improves its generalization ability, enabling it to maintain good performance on unseen data. Attached Figure Description
[0058] Figure 1 This is a flowchart illustrating the overall method of the present invention;
[0059] Figure 2 This is a model framework diagram for embedding time-dimensional knowledge graph representation learning in this embodiment;
[0060] Figure 3 This is a diagram of the global encoder structure in this embodiment;
[0061] Figure 4 This is a structural diagram of the local-global feature fusion module in this embodiment. Detailed Implementation
[0062] 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, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.
[0063] Example: Please refer to Figure 1 As shown, this embodiment provides a representation learning method for temporal knowledge graphs based on local-global feature fusion, including the following steps:
[0064] The method proposed in this invention consists of three modules: a local encoder based on RGCN-LSTM, a global encoder, and a feature fusion module. For example... Figure 2 The local encoder primarily consists of a Relational Graph Convolutional Network (RGCN) and a Long Short-Term Memory (LSTM) network. RGCN extracts local structural features from the knowledge graph, while LSTM models the temporal evolution of entity representations, ultimately generating a temporally enhanced hidden representation Hr. The global encoder captures the global structural information of the entire knowledge graph, generating a global historical entity embedding representation He and a relation embedding representation Rt, providing long-term cross-entity association features. In the feature fusion module, the Hr output from the local encoder and the He output from the global encoder are processed by a feature fusion unit mechanism to more efficiently fuse local temporal information with global structural information. This module reorganizes information from different sources through feature interaction operations and combines concatenation and multilayer perceptron (MLP) for nonlinear transformation to generate the final fused representation He. Finally, the representation is fed into a hierarchical model for prediction. The decoder performs entity prediction and improves the model's reasoning ability on the temporal knowledge graph by optimizing the inference loss.
[0065] S1. Divide the entire timeline into multiple time points and construct a time-series knowledge graph based on these time points;
[0066] In this embodiment, the entire timeline is divided into multiple time points, and a time-series knowledge graph is constructed based on these time points, including the following steps:
[0067] S1.1. Based on the time interval x, divide the entire time axis into a series of consecutive time points. Each time point represents a specific time period. Construct the corresponding time sub-graph based on the entity relationships that occur within that time period.
[0068] S1.2 For each point in time, collect data on all entities and their relationships that occurred within the corresponding time period;
[0069] S1.3 At each point in time, a corresponding knowledge graph is constructed using a multi-relationship graph structure encoder based on the collected data. Each knowledge graph reflects the relationship network between entities at that specific point in time.
[0070] S2. Based on the temporal knowledge graph, a local encoder is used to extract local spatiotemporal features, and a global encoder is used to extract global features.
[0071] In this embodiment, local spatiotemporal features are extracted using a local encoder based on a temporal knowledge graph, including the following steps:
[0072] S2.1 At each time step, a relational graph convolutional network (RGCN) is used to embed the entity nodes obtained in the previous time step into the representation. As input, the graph convolution module RGCNCell is used to perform relation-aware graph convolution updates on the current graph structure;
[0073] S2.2. The UnionRGCNLayer (a variant for processing multi-relational data, based on relational graph convolutional networks) is used to aggregate and update the neighbors of each node. Edges of different relation types are guided by the input relation embedding and aggregated using different convolutional parameters to achieve structure-aware updates of the current entity.
[0074] The update method is as follows: (This formula aggregates the structural features of nodes in the graph, updates them by combining the embedding information of neighboring nodes and relational semantics, and thus obtains the representation of the node in the next layer.) ):
[0075] ;
[0076] In the formula, Indicates time Upper Entity Node In the Layer representation, Indicates the relationship With nodes The set of connected neighbor nodes, Representing relations Embedded vector, It represents the feature interaction function between entity embeddings and relation embeddings, and is the Hadamard product. Represents the linear transformation matrix shared by all relations. This represents the transformation matrix used for self-loop connections. This represents the normalization factor, set to the number of neighbors. , This represents a non-linear activation function, specifically the RReLU function. Indicate neighboring nodes;
[0077] S2.3 In order to capture the trend of entity changes over time, when updating the entity representation in the graph at each time step, a Long Short-Term Memory (LSTM) network is used to update the entity embedding in each graph at each time step to alleviate the gradient explosion or vanishing problem and speed up the training convergence.
[0078] Since knowledge graphs are dynamic, only a single time step is considered. The structural information cannot capture the evolutionary trend of entity representations. To further preserve the useful structural information gained during evolution, and to enable the model network to learn updated representations, LSTM is used to update the entity embeddings in each graph at each time step when updating the entity representations in the graph. LSTM effectively alleviates the gradient explosion or vanishing problem, accelerating training convergence. Specifically, in the... Layers, entity nodes in time The update process for the representation is as follows:
[0079] ;
[0080] In the formula, This represents an intermediate state after structural convolution, not the final state. This indicates the hidden state at the previous moment. It indicates the memory state at the previous moment. The entity representation of the current time step. This indicates the memory state at the current time step;
[0081] S2.4 To capture the changes in relation semantics over time in knowledge graphs, an evolution mechanism for relation embedding is introduced. Relevant entity context embeddings are collected based on the connection relationships between entities. After aggregation, they are fused with the current relation embeddings to generate new temporal relation representations. This process takes into account the long-term evolution characteristics of relations over time, enabling the model to learn the dynamic representation of relations in different time states.
[0082] The specific embedding and fusion process is as follows:
[0083] ;
[0084] In the formula, It is the initial relation embedding. Indicates time step All usage relationships The set of triples, It is the head entity of the triplet. The representation, summed and averaged, achieves the semantic information propagation from entities to relations, and then... After adding them together, normalize the results to obtain the time steps. Relationship on When at time step If the current facts do not include the current relationship, Then it is 0;
[0085] Considering the long-term evolution of relations over time, we learn dynamic representations of relations at different time states, and the update process is as follows:
[0086] ;
[0087] In the formula, This indicates the embedding of the relation at the previous time step. This represents the memory state of the relation embedding in the previous time step, and the output of the current step. It will be used for relationship prediction tasks, or as an auxiliary feature for entity representation prediction;
[0088] S2.5 After the above steps, the local encoder generates a temporally enhanced hidden representation, which integrates the change patterns of entities and their neighborhood relationships within a specific time slice as well as the trend of evolution over time.
[0089] Furthermore, global features are extracted using a global encoder, including the following steps:
[0090] In processing time-series graph data, to further explore the global semantics inherent in the long-term evolution information of the time-series graph and extract global features of nodes and relationships from a global perspective of the entire graph, a global encoder module is now employed. This module extracts historical entity representations highly relevant to the current query semantics through attention aggregation of entity embeddings in the historical graph structure, enhancing the model's ability to model long-term dependencies. Unlike local encoders, global encoders do not rely on modeling dependencies between time steps; instead, they construct a unified global feature representation through the extraction of information from the entire graph, thus providing strong support for subsequent tasks. The structure of the global encoder is as follows: Figure 3 As shown;
[0091] S2.6. Merge the historical time subgraphs and calculate the historical global entity representation matrix using the Structured Convolutional Module (RGCN). The historical global entity representation matrix represents the global information of each node in the entire graph;
[0092] S2.7 Utilizing entity embeddings and relational context representations in the current query Constructing query semantic vectors Its dimension is consistent with the number of entities, and is non-zero only at the position of the queried entity;
[0093] S2.8 Calculate the importance of historical entities through an attention mechanism and output a global semantic representation;
[0094] The specific steps for calculating the importance of historical entities using the attention mechanism are as follows:
[0095] Using linear transformations combined with query masks ( To calculate the importance score:
[0096] ;
[0097] The entity embeddings in the history graph are weighted and averaged based on the scores to obtain the attention-weighted semantic representation of the history graph:
[0098] ;
[0099] in, This indicates the semantic importance of the query to historical entities. This represents a normalization function that transforms a vector of real numbers into a probability distribution, used to generate attention weights. Represents a linear transformation function (fully connected layer). Indicates the first Attention score of each entity Index representing an entity, Represents the total number of entities. This represents the attention-weighted semantic representation of the historical graph. This representation captures the structural information in the historical graph that best matches the current semantic meaning, and is passed into the subsequent fusion module as a global semantic supplement. The aggregation enhancement of the adjacency relationships of entities in the current graph from the local encoder, namely:
[0100] ;
[0101] In the formula, This represents the representation of relations in the current graph structure extracted from the local encoder. Relation embedding, i.e., a low-dimensional vector representation of relations, is used to model the semantic information of relations;
[0102] This global attention mechanism introduces structural semantics and semantic relevance in the historical graph context without increasing computational overhead. This makes the global feature embedding more accurately reflect the importance of nodes and relationships in the graph, improves the ability to extract global features, and enhances the model's adaptability and expressiveness when dealing with complex time-series graph data. It also provides more accurate global information support for downstream reasoning and recommendation tasks.
[0103] S3. The local spatiotemporal features are fused with global features using an adaptive weighting method with a gating mechanism.
[0104] In this embodiment, to effectively integrate the contextual semantic representations of entities and relationships in the local graph with the semantic information extracted by the global attention mechanism, this invention designs a local-global feature fusion module as a connecting link between the two. This module aims to alleviate potential semantic discrepancies between local and global representations and improve the semantic consistency and predictive discriminability of entity representations by fusing features.
[0105] An adaptive weighting method using a gating mechanism is employed to fuse local spatiotemporal features with global features, including the following steps:
[0106] S3.1 Define trainable parameter matrices and corresponding bias terms for local spatiotemporal features and global features respectively, and use activation functions (ReLU function) to control the weights of local and global features;
[0107] S3.2 Calculate the gating weights of the local spatiotemporal features and global features and their corresponding parameter matrices. This step can be regarded as determining the proportion of local and global features flowing into the fusion path through an attention mechanism.
[0108] Their respective gating weights are:
[0109] ;
[0110] ;
[0111] In the formula, , For a trainable parameter matrix, , For the corresponding bias term, The sigmoid activation function controls the importance of local and global feature pathways. , Attention-gated weights control the proportion of local and global features flowing into the fusion path. This indicates that Hadamard operates on an element-wise basis. This represents the local spatiotemporal feature vector of the input. This represents the input global feature vector;
[0112] S3.3 Modulate the original local spatiotemporal features and global features based on the calculated gating weights;
[0113] The original features are modulated as follows:
[0114] ;
[0115] ;
[0116] In the formula, This represents the local feature representation after modulation by the gating mechanism. This represents the global feature representation modulated by a gating mechanism.
[0117] S3.4. Concatenate the gated local spatiotemporal features with the global features to form a new vector;
[0118] S3.5. Feed the concatenated vector into one or more MLP layers for nonlinear transformation to generate the final fused representation. ;
[0119] ;
[0120] In the formula, This indicates a splicing operation that combines the gated and adjusted local and global features.
[0121] Through the above design, the local-global feature fusion module effectively captures the information representation of entities at different granularities, taking into account both short-term detailed information and long-term association patterns, thus improving the robustness of downstream inference and prediction tasks. After using the feature fusion unit, the local and global representations can also complement each other, avoiding overfitting and noise in both tasks and improving generalization ability. The goal of this module is to combine features from the local encoder and the global encoder to form a unified representation, fusing spatiotemporal information to improve the model's predictive performance, enabling the model to learn both short-term detailed information and long-term knowledge relationships simultaneously. The model diagram is shown below. Figure 4 As shown.
[0122] S4. Based on the decoder, the fused features are used to perform entity prediction using the ConvTransE model, and based on the decoder, the fused features are used to perform relationship prediction using the ConvTransR model.
[0123] In this embodiment, entity prediction is performed using the ConvTransE model based on the fused features obtained from the decoder, including the following steps:
[0124] In temporal knowledge graph reasoning tasks, decoders are typically used to predict entities and relations. To reasonably evaluate the accuracy of the prediction results, a common method is to use a scoring function to calculate the matching probability of triples. Studies have shown that GNNs incorporating convolutional scoring functions perform well in knowledge graph prediction tasks. Therefore, this paper selects a dual-decoder structure based on convolutional neural networks, using ConvTransE and ConvTransR as decoders for entity prediction and relation prediction, respectively, to model the temporal evolution characteristics of entities and relations. This dual-decoder model differentiates the temporal dependencies of entities and relations, maintaining the translation invariance of the Trans series models while extracting high-order structural features using convolutional kernels, effectively alleviating the problem of coexistence of entity-relation coupling and semantic heterogeneity in temporal knowledge graphs.
[0125] S4.1 For the embedded representation of main entities and relationships, convolution-based operations are used to extract features;
[0126] S4.2. The embedding representations of the main entity and the relationship are fused together through feature fusion operation in order to capture the correlation between the two.
[0127] S4.3 Match and predict the fused representation with the target entity, and calculate the score;
[0128] The formula for calculating the score is:
[0129] ;
[0130] In the formula, This indicates the structure of the known history graph (represented by the representation). ), historical relationship embedding (by (representation) and subject and relationships Predicting the target entity under the premise of The probability, This indicates a feature fusion operation. This represents the sigmoid activation function. This represents the entity embedding in the history graph.
[0131] Furthermore, based on the decoder, the ConvTransR model is used to predict relationships using the fused features, including the following steps:
[0132] S4.4 Introduce a relation-specific projection matrix in the ConvTransR model;
[0133] S4.5. Through the dynamic projection mechanism (the dynamic projection mechanism is: multiply the subject entity embedding and the object entity embedding by the projection matrix of the relation respectively to obtain the projected vector), according to the embedding of the subject and object of the current triple in the previous time step, it is mapped to the corresponding relation subspace. This process is particularly suitable for capturing relation evolution features and semantic changes.
[0134] S4.6 Define the scoring function for relation prediction and calculate the probability of a given triple being true (the score is calculated based on the relation embedding representation in the historical graph and the embedding of the subject and object of the current triple in the previous time step).
[0135] The scoring function for relationship prediction is:
[0136] ;
[0137] In the formula, This indicates the structure of the known history graph (represented by the representation). ), historical relationship embedding (by (representation) and subject and entity Predicting target relationships under the premise of The probability, Relationship embedding representation in the history graph, This indicates the embedding of the current triple's subject in the previous time step. These represent the embedding of the object in the current triplet at the previous time step.
[0138] S5. Feed the prediction results back to the loss function to drive end-to-end training;
[0139] In this embodiment, the prediction results are fed back to the loss function to drive end-to-end training, including the following steps:
[0140] S5.1. The scores of entity prediction and relationship prediction in step S4 are used as input to calculate the loss function. The marginal loss function is selected as the optimization objective to ensure that the score of the positive sample triplet is significantly higher than the score of the negative sample triplet.
[0141] S5.2 Execute forward propagation, process the input data using the current model parameters, and obtain the prediction score for each triple;
[0142] S5.3. Use the automatic differentiation tool (PyTorch's autograd engine) to calculate the gradient of the loss function with respect to the parameters of each layer, starting from the output layer and working backward.
[0143] S5.4 In each layer, the gradient of the loss with respect to each weight parameter is calculated according to the chain rule. These gradients indicate how to adjust the weights to reduce the loss.
[0144] In each layer, the gradient of the loss with respect to each weight parameter is calculated according to the chain rule, including the following steps:
[0145] S5.41. Process the input data using the current network parameters to obtain the prediction score for each triple. This process involves the activation function and linear transformation of each layer.
[0146] S5.42. Use the selected loss function to calculate the difference between the model output and the actual label, and calculate whether the difference between the positive sample score and the negative sample score meets the preset marginal value.
[0147] S5.43. Starting from the last layer, calculate the gradient of the loss with respect to the output of that layer. This usually involves the derivative of the loss function with respect to the output of the last layer.
[0148] S5.44. For each layer in the network, calculate the error term (for each layer, first calculate the error term, which represents the gradient of the loss with respect to the input of that layer. The error term is calculated using the error term of the next layer and the weights of the current layer and the derivative of the activation function) and the parameter gradient (calculate the gradient of the loss with respect to the weights and biases of that layer using the error term).
[0149] S5.5 Use the SGD optimization algorithm to update the model parameters based on the calculated gradient. The goal of the optimization algorithm is to minimize the loss function, thereby improving the model's prediction accuracy.
[0150] The process of updating model parameters using the SGD (Simplified Generating Decomposition) algorithm based on the calculated gradients includes the following steps:
[0151] S5.51. Initialize all parameters of the model (weights and biases);
[0152] S5.52. Process the input data using the current model parameters to generate prediction results;
[0153] S5.53. Introducing a learning rate scheduler (which gradually decreases the learning rate over time) to help the model converge better;
[0154] S5.54. For each parameter, update the parameter according to its corresponding gradient.
[0155] S5.6 Repeat the forward propagation (prediction), loss calculation, backpropagation, and parameter update process for the entire dataset until the maximum number of iterations y is reached.
[0156] The foregoing has shown and described the basic principles, main features, and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above embodiments. The embodiments and descriptions in the specification are merely preferred examples and are not intended to limit the invention. Various changes and modifications can be made to the invention without departing from its spirit and scope, and all such changes and modifications fall within the scope of the claimed invention.
Claims
1. A representation learning method for temporal knowledge graphs based on local-global feature fusion, characterized in that, Includes the following steps: S1. Divide the entire timeline into multiple time points and construct a time-series knowledge graph based on these time points; S2. Based on the temporal knowledge graph, a local encoder is used to extract local spatiotemporal features, and a global encoder is used to extract global features. S3. The local spatiotemporal features are fused with global features using an adaptive weighting method with a gating mechanism. S4. Based on the decoder, the fused features are used to perform entity prediction using the ConvTransE model, and based on the decoder, the fused features are used to perform relationship prediction using the ConvTransR model. S5. Feed the prediction results back to the loss function to drive end-to-end training; In step S2, local spatiotemporal features are extracted using a local encoder based on a temporal knowledge graph, including the following steps: S2.1 At each time step, a relational graph convolutional network is used to take the entity node embedding representation obtained in the previous time step as input, and the graph convolution module RGCNCell is used to perform relation-aware graph convolutional updates on the current graph structure. S2.
2. The UnionRGCNLayer is used to aggregate and update the neighbors of each node. Edges of different relation types are guided by the input relation embedding and aggregated using different convolution parameters. S2.3 When updating the representation of entities in the graph at each time step, a long short-term memory network is used to update the entity embeddings in each graph at each time step; S2.
4. Collect relevant entity context embeddings based on the connection relationships between entities, aggregate them, and merge them with the current relationship embeddings to generate a new temporal relationship representation; S2.5 After the above steps, the local encoder generates a temporally enhanced hidden representation; In step S2, global features are extracted using a global encoder, including the following steps: S2.6 Merge the historical time subgraphs and calculate the historical global entity representation matrix through the structure convolution module; S2.7 Construct a query semantic vector using entity embeddings and relational context representations in the current query; S2.8 Calculate the importance of historical entities through an attention mechanism and output a global semantic representation.
2. The representation learning method for temporal knowledge graphs based on local-global feature fusion according to claim 1, characterized in that: In step S1, the entire timeline is divided into multiple time points, and a time-series knowledge graph is constructed based on these time points, including the following steps: S1.
1. Based on the time interval x, divide the entire time axis into a series of consecutive time points. Each time point represents a specific time period. Construct the corresponding time sub-graph based on the entity relationships that occur within that time period. S1.2 For each point in time, collect data on all entities and their relationships that occurred within the corresponding time period; S1.3 At each time point, a corresponding knowledge graph is constructed using a multi-relationship graph structure encoder based on the collected data.
3. The representation learning method for temporal knowledge graphs based on local-global feature fusion according to claim 1, characterized in that: In step S3, the local spatiotemporal features and global features are fused using a gating mechanism adaptive weighting method, including the following steps: S3.1 Define trainable parameter matrices and corresponding bias terms for local spatiotemporal features and global features respectively, and use activation functions to control the weights of local and global features; S3.2 Calculate the respective gating weights based on the local spatiotemporal features and global features and their corresponding parameter matrices; S3.3 Modulate the original local spatiotemporal features and global features based on the calculated gating weights; S3.
4. Concatenate the gated local spatiotemporal features with the global features to form a new vector; S3.
5. Feed the concatenated vector into an MLP layer for nonlinear transformation to generate the final fused representation.
4. The representation learning method for temporal knowledge graphs based on local-global feature fusion according to claim 1, characterized in that: In step S4, entity prediction is performed using the ConvTransE model based on the fused features obtained from the decoder, including the following steps: S4.1 For the embedded representation of main entities and relationships, convolution-based operations are used to extract features; S4.
2. The embedded representations of the main entities and relationships are fused together through feature fusion operations; S4.3 Match the fused representation with the target entity for prediction and calculate the score.
5. The representation learning method for temporal knowledge graphs based on local-global feature fusion according to claim 1, characterized in that: In step S4, relation prediction is performed on the fused features using the ConvTransR model based on the decoder, including the following steps: S4.4 Introduce a relation-specific projection matrix in the ConvTransR model; S4.
5. Through the dynamic projection mechanism, based on the embedding of the subject and object of the current triple in the previous moment, map them to the corresponding relational subspace. S4.6 Define the scoring function for relation prediction and calculate the probability that a given triplet is true.
6. The representation learning method for temporal knowledge graphs based on local-global feature fusion according to claim 1, characterized in that: In step S5, the prediction results are fed back to the loss function to drive end-to-end training, including the following steps: S5.
1. Use the scores of entity prediction and relationship prediction in step S4 as input to calculate the loss function, and select the marginal loss function as the optimization objective. S5.2 Execute forward propagation, process the input data using the current model parameters, and obtain the prediction score for each triple; S5.3 Calculate the gradient of the loss function with respect to the parameters of each layer, starting from the output layer and working backwards. S5.4 In each layer, calculate the gradient of the loss with respect to each weight parameter according to the chain rule; S5.
5. Update the model parameters using an optimization algorithm based on the calculated gradient; S5.6 Repeat the forward propagation, loss calculation, back propagation, and parameter update process for the entire dataset until the maximum number of iterations y is reached.
7. The representation learning method for temporal knowledge graphs based on local-global feature fusion according to claim 6, characterized in that: In S5.4, in each layer, the gradient of the loss with respect to each weight parameter is calculated according to the chain rule, including the following steps: S5.
41. Process the input data using the current network parameters to obtain the prediction score for each triple; S5.
42. Calculate the difference between the model output and the actual labels using the selected loss function; S5.
43. Starting from the last layer, calculate the gradient of the loss with respect to the output of that layer; S5.
44. Calculate the error term and parameter gradient for each layer in the network.
8. The representation learning method for temporal knowledge graphs based on local-global feature fusion according to claim 6, characterized in that: In step S5.5, the model parameters are updated using an optimization algorithm based on the calculated gradient, including the following steps: S5.
51. Initialize all parameters of the model; S5.
52. Process the input data using the current model parameters to generate prediction results; S5.53, Introduced a learning rate scheduler; S5.
54. For each parameter, update the parameter according to its corresponding gradient.
Citation Information
Patent Citations
Time sequence knowledge graph reasoning method, device and equipment based on attention mechanism
CN114860854A
Small sample tense knowledge graph completion method based on relation adaptive network
CN116340524A