Temporal knowledge graph reasoning method, device and equipment based on attention mechanism
Through the temporal knowledge graph reasoning method based on the attention mechanism, historical information of entities is aggregated and updated, which solves the problem of insufficient reasoning ability of temporal knowledge graph in the existing technology, and achieves more accurate prediction of future events and explanation of historical basis.
Patent Information
- Application Number
- CN202210482447.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-05
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2042-05-05
AI Technical Summary
Existing temporal knowledge graph reasoning methods are difficult to correctly predict future events and interpret historical evidence. In particular, their reasoning capabilities are poor when faced with long historical dependencies, and they cannot effectively simulate the occurrence of cyclic events and their impact on future events.
Adopting the temporal knowledge graph reasoning method based on the attention mechanism, by constructing the temporal knowledge graph snapshot, aggregating the neighborhood information of the entity, using the multi-head attention mechanism to focus on historical information, updating the latent vector representation, and through the feed-forward neural network and multi-classification layer The network performs coding and scoring to achieve reasoning on the time series knowledge graph.
It improves the reasoning effect of the time series knowledge graph, can more accurately predict entities and relationships, improves the use of historical information, enhances the reasoning ability in the face of long history, and can effectively simulate the impact of concurrent events.
Smart Images

Figure CN114860854B
Abstract
Description
Technical Field
[0001] The present application relates to the field of knowledge graph technology, and in particular to a temporal knowledge graph reasoning method, apparatus, computer device and storage medium based on an attention mechanism. Background Art
[0002] In recent years, the Knowledge Graph (KG), as a structured semantic knowledge base, describes concepts and their relationships in the physical world in a symbolic formal way, and has become a research hotspot in academia and industry. Then, as time goes by, new knowledge may come from the rapidly generated and evolving data in various news media and social software, which needs to be continuously added to the KG to reflect the evolution of the knowledge base over time. Therefore, how to record facts that change over time and study their changing trends is of great significance. The knowledge reasoning of the data-driven temporal KG in the above context can be more accurate than the existing KG and grasp the trend of knowledge changes in real time. The reasoning of existing models is generally based on the real facts before the time to be inferred, such as the latest extrapolated temporal reasoning model Know-Evolve, and its extended model DyRep. These methods can continuously reason about the facts of future event graphs, however, they cannot simulate the occurrence of cyclic events and the inference of the impact of key facts on future events. Jin proposed the Recurrent Event Network (RE-NET), which can better solve the problem that the existing dynamic graph model is difficult to reason about high-concurrency events at multiple time points, and model the time correlation of dynamic graphs in the full time domain. However, in historical reasoning, it relies on RNN and its variants LSTM and its variants to simulate the laws of historical evolution, and relies on multi-relation neighborhood aggregation of concurrent events. However, although these methods can well explain the laws of historical development and change, they cannot correctly explain the historical basis of reasoning related to specific prediction problems, and lack the problem of poor historical reasoning ability when facing long historical dependencies. Summary of the invention
[0003] Based on this, it is necessary to provide a temporal knowledge graph reasoning method, device, computer equipment and storage medium based on an attention mechanism that can improve the reasoning effect of temporal knowledge graphs in response to the above technical problems.
[0004] A temporal knowledge graph reasoning method based on an attention mechanism, the method comprising:
[0005] Obtain the time series knowledge graph to be inferred, construct a knowledge graph snapshot for each time period according to the time annotation of the knowledge in the time series knowledge graph, and further obtain the neighborhood information of each entity in each time period;
[0006] Aggregating the neighborhood information corresponding to all relationships of multiple entities through a neighborhood aggregator to obtain a neighborhood feature representation of each entity;
[0007] The neighborhood feature representation of each entity in each time period in the temporal knowledge graph is input into a temporal event encoder based on an attention mechanism; the temporal event encoder based on the attention mechanism determines an attention weight matrix containing multi-head information according to the neighborhood feature representation of the target entity at the current moment and the neighborhood feature representation of the historical moment, and selectively pays attention to the temporal entity representation sequence of the historical information through the attention weight matrix, so as to obtain the latent vector representation of the target entity at the current moment after being updated by the temporal event encoder;
[0008] The time series event encoder is encoded and scored according to the latent vector representation through a feedforward neural network and a multi-classification layer network to achieve time series knowledge graph reasoning.
[0009] In one of the embodiments, the method further includes: aggregating the neighborhood information corresponding to all relations of the multiple entities through a neighborhood aggregator to obtain a neighborhood feature representation of each entity; the neighborhood aggregator is a multi-relation neighborhood aggregator, an attention aggregator or an average pooling aggregator;
[0010] The model structure of the multi-relation neighborhood aggregator is:
[0011]
[0012] in, represents the neighborhood feature representation of the entity output by the multi-relation neighborhood aggregator, Represents the set of neighbor nodes of the relation r of entity s at time t, c s represents the number of edges of entity s in the graph, which is used as a normalization factor, l represents the number of layers of the current aggregator, and W r represents the trainable parameters related to the relationship between entities o and s, W o represents the trainable parameter of the self-loop of entity s, h o ,h s The embedding vectors of entities o and s are respectively used to obtain the implicit representation of the intermediate layer through the multi-relation aggregator;
[0013] The model structure of the attention aggregator is:
[0014]
[0015] in, represents the neighborhood feature representation of the entity output by the attention aggregator, a o =softmax(v T tanh(W(es :e r :(h o +h r )))),e s represents the current predicted entity embedding vector, e r represents the embedding vector of the current predicted relation r, h r Represents entity e s and e r The relationship vector corresponding to the neighborhood information, e o represents the embeddable vector representation of entity o, softmax(·) is the normalized exponential function, v T represents weight, W(·) represents trainable parameter, and tanh(·) represents tanh activation function;
[0016] The model structure of the average pooling aggregator is:
[0017]
[0018] in, Represents the neighborhood feature representation of the entity output by the average pooling aggregator.
[0019] In one embodiment, the method further includes: obtaining a neighborhood feature representation g of the target entity at the current time t i,t ;
[0020] Get the neighborhood feature representation g of the target entity at each time step historical moment i,t′ , t′∈{t-τ,…,t};
[0021] According to g i,t and g i,t′ Determine the attention weight matrix containing multi-head information, and further determine the latent vector representation of the target entity after being updated by the temporal event encoder at the current time t:
[0022]
[0023] e ij =q ij -(λ z Δt+b z )+M ij
[0024]
[0025]
[0026] Among them, W q ,W k , Represents the preset linear projection matrix, represents the attention matrix weight containing multi-head information, The matrix is a mask matrix, Δt = Tt′, Δt is the time difference between the current event time and the prediction task time, T represents the time corresponding to the current prediction task, |E| represents the entity set, q ij represents the attention distribution value of entity j for entity i, d represents the dimension of input information, and λ z represents the parameter of historical latent representation decaying over time, b z represents the attenuation bias, i, j, k are time indices, j, k∈t′, h i,t is the latent vector representation of the target entity after being updated by the temporal event encoder at the current time t.
[0027] In one embodiment, the method further includes: decoding the latent vector representation of the entity and the relationship updated by the temporal event encoder at the current time t through a feedforward neural network;
[0028] The softmax activation function is used to output the probability distribution of the entity or relationship that needs to be predicted.
[0029] In one of the embodiments, it further includes: obtaining global information and local information about entity history information according to the latent vector representation of the entity;
[0030] According to the global information and the local information, the temporal event encoder is encoded and scored according to the latent vector representation through a feedforward neural network and a multi-classification layer network to achieve temporal knowledge graph reasoning.
[0031] In one of the embodiments, it also includes: encoding and scoring the time series event encoder according to the latent vector representation through a feedforward neural network and a multi-classification layer network according to the global information and the local information, so as to realize time series knowledge graph reasoning; the time series knowledge graph reasoning includes predicting the tail entity given a head entity and relationship at a time t, and predicting the relationship given an entity s at a time t.
[0032] In one embodiment, the neighborhood aggregator, the attention-based temporal event encoder, the feedforward neural network, and the multi-classification layer network constitute a temporal knowledge graph reasoning model. Before the temporal knowledge graph reasoning model realizes temporal knowledge graph reasoning, the method includes: training the temporal knowledge graph reasoning model by using the Adam algorithm and a preset loss function; wherein the preset loss function is a multi-classification cross entropy loss function, which is expressed as follows:
[0033]
[0034] Among them, p(o t |s t ,rt ) indicates that according to the header entity s t and the relationship t The tail entity o appears t The probability, p(r t |s t ) indicates that the entity s t Get the relationship r t The probability of logp(s t ) represents the confidence score of entity s at time t, λ 1 Represents the weight value of entity prediction, λ 2 Represents the weight value of the relationship prediction task.
[0035] A temporal knowledge graph reasoning device based on an attention mechanism, the device comprising:
[0036] A preprocessing module is used to obtain the time series knowledge graph to be inferred, construct a knowledge graph snapshot for each time period according to the time annotation of the knowledge in the time series knowledge graph, and further obtain the neighborhood information of each entity in each time period;
[0037] A neighborhood aggregator module, configured to aggregate the neighborhood information corresponding to all relationships of multiple entities through a neighborhood aggregator to obtain a neighborhood feature representation of each entity;
[0038] A temporal event encoder module, used for inputting the neighborhood feature representation of each entity in each time period in the temporal knowledge graph into a temporal event encoder based on an attention mechanism; the temporal event encoder based on the attention mechanism determines an attention weight matrix containing multi-head information according to the neighborhood feature representation of the target entity at the current moment and the neighborhood feature representation of the historical moment, and selectively pays attention to the temporal entity representation sequence of the historical information through the attention weight matrix, so as to obtain the latent vector representation of the target entity at the current moment after being updated by the temporal event encoder;
[0039] The decoding prediction module is used to encode and score the time series event encoder according to the latent vector representation through a feedforward neural network and a multi-classification layer network to realize time series knowledge graph reasoning.
[0040] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0041] Obtain the time series knowledge graph to be inferred, construct a knowledge graph snapshot for each time period according to the time annotation of the knowledge in the time series knowledge graph, and further obtain the neighborhood information of each entity in each time period;
[0042] Aggregating the neighborhood information corresponding to all relationships of multiple entities through a neighborhood aggregator to obtain a neighborhood feature representation of each entity;
[0043] The neighborhood feature representation of each entity in each time period in the temporal knowledge graph is input into a temporal event encoder based on an attention mechanism; the temporal event encoder based on the attention mechanism determines an attention weight matrix containing multi-head information according to the neighborhood feature representation of the target entity at the current moment and the neighborhood feature representation of the historical moment, and selectively pays attention to the temporal entity representation sequence of the historical information through the attention weight matrix, so as to obtain the latent vector representation of the target entity at the current moment after being updated by the temporal event encoder;
[0044] The time series event encoder is encoded and scored according to the latent vector representation through a feedforward neural network and a multi-classification layer network to achieve time series knowledge graph reasoning.
[0045] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the following steps:
[0046] Obtain the time series knowledge graph to be inferred, construct a knowledge graph snapshot for each time period according to the time annotation of the knowledge in the time series knowledge graph, and further obtain the neighborhood information of each entity in each time period;
[0047] Aggregating the neighborhood information corresponding to all relationships of multiple entities through a neighborhood aggregator to obtain a neighborhood feature representation of each entity;
[0048] The neighborhood feature representation of each entity in each time period in the temporal knowledge graph is input into a temporal event encoder based on an attention mechanism; the temporal event encoder based on the attention mechanism determines an attention weight matrix containing multi-head information according to the neighborhood feature representation of the target entity at the current moment and the neighborhood feature representation of the historical moment, and selectively pays attention to the temporal entity representation sequence of the historical information through the attention weight matrix, so as to obtain the latent vector representation of the target entity at the current moment after being updated by the temporal event encoder;
[0049] The time series event encoder is encoded and scored according to the latent vector representation through a feedforward neural network and a multi-classification layer network to achieve time series knowledge graph reasoning.
[0050] The above-mentioned time series knowledge graph reasoning method, device, computer equipment and storage medium based on the attention mechanism obtain the neighborhood information of each entity in each time period by constructing a knowledge graph snapshot of each time period in the time series knowledge graph; the neighborhood information corresponding to all relationships of multiple entities is aggregated by the neighborhood aggregator to obtain the neighborhood feature representation of each entity; the attention weight matrix containing multi-head information is determined by the time series event encoder based on the attention mechanism according to the neighborhood feature representation of the target entity at the current moment and the neighborhood feature representation of the historical moment, and the time entity representation sequence of the historical information is selectively paid attention to by the attention weight matrix, and the target entity is obtained at the current moment. The latent vector representation updated by the time series event encoder is obtained; the time series event encoder is encoded and scored according to the latent vector representation through a feedforward neural network and a multi-classification layer network to realize the time series knowledge graph reasoning. The present invention proposes a time series knowledge graph reasoning method based on the attention mechanism, which integrates the information of entities and relationships under the corresponding relationship of concurrent event entities, uses a multi-head attention mechanism for time series reasoning, and improves the time series knowledge graph reasoning effect. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] Figure 1 A schematic diagram of a flow chart of a temporal knowledge graph reasoning method based on an attention mechanism in one embodiment;
[0052] Figure 2 Schematic diagram of the algorithm structure of a temporal knowledge graph reasoning method based on an attention mechanism in one embodiment;
[0053] Figure 3 It is a structural block diagram of a temporal knowledge graph reasoning device based on an attention mechanism in one embodiment;
[0054] Figure 4 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0055] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0056] In one embodiment, Figure 1 As shown in the figure, a temporal knowledge graph reasoning method based on an attention mechanism is provided, which includes the following steps:
[0057] Step 102, obtain the time series knowledge graph to be inferred, construct a knowledge graph snapshot for each time period based on the time annotation of the knowledge in the time series knowledge graph, and further obtain the neighborhood information of each entity in each time period.
[0058] The temporal knowledge graph is defined as a directed graph with time labels between nodes. To introduce the dimension of time, events in the temporal knowledge graph are defined as a quadruple: (head entity, relationship, tail entity, time), which can be represented by symbols (h, r, t, τ). The reasoning of the temporal knowledge graph is generally based on the quadruple. Given a quadruple reasoning task with a missing condition, the possibility of the missing condition is inferred based on the existing quadruple data information. Since the temporal knowledge graph is a sequence graph composed of knowledge graphs at different times, the KG at the initial time is denoted as G. 0 , over time, the entire temporal knowledge graph is represented as follows:
[0059] G 0 →G 1 →G 2 →…→G T →G T+1 →…
[0060] Among them, G T (0≤T≤N) represents KG at time T. G T It is a directed graph composed of entities and relationships at time T, represented by G T =(E T ,R T )in, Represented as a set of nodes, Represents a relational combination. Any directed edge represents a triple (h, r, t) (h, t∈E T and r∈R T ), so GT can also be regarded as a set of triples.
[0061] In order to obtain the dynamic relationship between events at different times and in different relationships, the present invention proposes an attention-based temporal knowledge graph reasoning model Attn-Net.
[0062] Embed entities and relationships, and obtain neighborhood information of entities in each time period by building a time series knowledge graph snapshot.
[0063] Step 104, aggregating the neighborhood information corresponding to all the relationships of the multiple entities through a neighborhood aggregator to obtain a neighborhood feature representation of each entity.
[0064] The neighborhood aggregator is used to extract the hidden features of the target entity under multiple relations and aggregate the neighborhood information under the same timestamp to obtain the neighborhood feature representation of each entity.
[0065] Step 106, input the neighborhood feature representation of each entity in each time period in the temporal knowledge graph into the temporal event encoder based on the attention mechanism.
[0066] The attention mechanism-based temporal event encoder is used to capture the temporal dependencies of cross-time entities. The multi-head attention mechanism uses the hidden representation of the last historical moment and the previous historical information to perform attention, and fuses the previous historical information as the final output of the temporal event encoder. The attention mechanism-based temporal event encoder determines the attention weight matrix containing multi-head information according to the neighborhood feature representation of the target entity at the current moment and the neighborhood feature representation of the historical moment, and selectively focuses on the sequence of temporal entity representations of the historical information through the attention weight matrix to obtain the updated hidden vector representation of the target entity at the current moment by the temporal event encoder.
[0067] Specifically, the temporal event encoder captures the correlation of events in time and prediction tasks by modeling the joint probability of the entire graph. To selectively strengthen the historical information related to the prediction task through historical information, the temporal encoder of the present invention uses a neural network structure based on the multi-head attention mechanism. One way to integrate historical information is to selectively focus on the sequence of temporal entity representations of historical information. The present invention uses the following equation. At each time step t′∈{t - τ,…,t}, according to the entity embedding vector h of the time-dependent representation i,t′ Generate the final hidden representation vector at time t. Finally, define the attention time encoder Attn as follows:
[0068]
[0069] e ij = q ij -(λ z Δt + b z ) + M ij
[0070]
[0071]
[0072] Where, W q , W k , Represents a preset linear projection matrix, Represents the attention matrix weight containing multi-head information, The matrix is a mask matrix, Δt = T - t′, Δt is the time difference between the occurrence time of the current target event and the prediction task time, T represents the time corresponding to the current prediction task, t’ is t’ < T, t is the set of historical times at <T moment, |E| represents the entity set, q ij Represents the attention distribution value of entity j for entity i, d represents the dimension of the input information, λ z Represents the historical hidden representation decay parameter over time, b zrepresents the attenuation bias, i, j, k are time indices, j, k∈t′, h i,t is the latent vector representation of the target entity after being updated by the temporal event encoder at the current time t.
[0073] where g i,t Can be replaced by g i,t' , g i,t' ,t′∈{t-τ,…,t} is used as the latent representation of the entire historical moment, and the self-attention mechanism is used for historical encoding. The entity latent representation of the historical moment of the sequence and the previous text are self-attentioned to obtain the time-series encoding vector. Finally, the mean-pooling strategy is used to fuse the information, and finally the evolution information representation on the entire historical graph is obtained.
[0074]
[0075] Due to the problem that the length of historical information of different entities is different, it is necessary to perform a mask operation on the part without historical information so that the attention does not calculate the part without historical information. Finally, the attention model can be set to multi-head.
[0076] Step 108, encode and score the time series event encoder according to the latent vector representation through a feedforward neural network and a multi-classification layer network to achieve time series knowledge graph reasoning.
[0077] According to the output results of multi-head attention, the fully connected layer is used for feature extraction, and finally the logistic regression (softmax) activation function is used to output the probability distribution of the entity or relationship to be predicted. For entity prediction and relationship prediction, Attn-Net can be a multi-classification task, each class corresponds to an entity or relationship object. Given a time t (s, r) to predict the tail entity, its tail entity vector classification is closely related to the tail entity of the head entity s before time t. Similarly, given a time t entity s prediction relationship can also be regarded as a multi-classification task.
[0078] Specifically, Attn-Net can capture the semantic representation of entities and relations throughout the historical period. To better represent the confidence score of the predicted entity, the head entity and relation as well as the tail entity encoding are decoded through a feedforward neural network, and finally the tail entity probability score is obtained using softmax. Based on the above representation,
[0079] p(o t |s,r,G t-m:t-1 )=σ(FFNN(e s :e r :h t-1 (s,r)))
[0080] where e s , is the embedding representation of the head entity and the relation entity, is the implicit representation vector of the head entity and relation of s at time t-1 after being updated by the temporal encoder.
[0081] Similarly, the probability of predicting the head entity and relation can be expressed as follows:
[0082] p(r t |s,G t-m:t-1 )=σ(FFNN(e s :h t-1 (s)))
[0083] p(s t |G t-m:t-1 )=σ(FFNN(H t-1 ))
[0084] Among them, h t-1 (s) is the local information representation of the head entity s in the past, G is the global graph t-1 Graph neighborhood aggregator representation.
[0085] In order to summarize the impact of the entire graph on the current entity prediction, the representation H that retains the global information t By enriching the historical information representation at the current moment, the global information embedding presents the overall change trend of the graph where the entity is located, and the local information h t It mainly focuses on the structural representation information of specific entities. Global information and local information respectively focus on different levels of historical information changes.
[0086] G is the global graph t-1 Graph neighborhood aggregator representation. Global representation H t-1 The local representation information is represented by the temporal event encoder to obtain the evolutionary representation across time, which is expressed as follows:
[0087] H t =GRU(g(G t ),H t-1 )
[0088]
[0089]
[0090] G is the aggregator function mentioned above, represents the event associated with entity s at time t, Attn refers to the temporal encoder based on the attention mechanism, Attn 1 、Attn 2Use 1 and 2 to distinguish that Attn is used twice, instead of training with only one Attn. In the global information representation, GRU is used to update the representation, and the calculation of the global representation is defined as The maximum pooling operation is used to capture the feature representation of the global graph. t (s) is the embedding vector of entity s in the prediction task, h t (s,r) represents the concatenation of entity and relation embedding vectors in the prediction task.
[0091] In the above-mentioned temporal knowledge graph reasoning method based on the attention mechanism, by constructing a knowledge graph snapshot of each time period in the temporal knowledge graph, the neighborhood information of each entity in each time period is obtained; the neighborhood information corresponding to all relationships of multiple entities is aggregated by the neighborhood aggregator to obtain the neighborhood feature representation of each entity; the attention weight matrix containing multi-head information is determined by the temporal event encoder based on the attention mechanism according to the neighborhood feature representation of the target entity at the current moment and the neighborhood feature representation at the historical moment, and the time entity representation sequence of the historical information is selectively paid attention to by the attention weight matrix, and the latent vector representation of the target entity updated by the temporal event encoder at the current moment is obtained; the temporal event encoder is encoded and scored according to the latent vector representation by a feedforward neural network and a multi-classification layer network to realize temporal knowledge graph reasoning. The present invention proposes a temporal knowledge graph reasoning method based on the attention mechanism, which integrates the information of entities and relationships under the corresponding relationship of concurrent event entities, uses a multi-head attention mechanism for temporal reasoning, and improves the temporal knowledge graph reasoning effect.
[0092] In one embodiment, the method further includes: aggregating neighborhood information corresponding to all relations of multiple entities through a neighborhood aggregator to obtain a neighborhood feature representation of each entity; the neighborhood aggregator is a multi-relation neighborhood aggregator, an attention aggregator or an average pooling aggregator; and the model structure of the multi-relation neighborhood aggregator is:
[0093]
[0094] in, Neighborhood feature representation of entities output by multi-relation neighborhood aggregator, Represents the set of neighbor nodes of the relation r of entity s at time t, c s represents the number of edges of entity s in the graph, which is used as a normalization factor, l represents the number of layers of the current aggregator, and W r represents the trainable parameters related to the relationship between entities o and s, W o represents the trainable parameter of the self-loop of entity s, h o ,h sThe embedding vectors of entities o and s are respectively represented by the implicit representation of the intermediate layer obtained by the multi-relation aggregator; the model structure of the attention aggregator is:
[0095]
[0096] in, represents the neighborhood feature representation of the entity output by the attention aggregator, a o =softmax(v T tanh(W(e s :e r :(h o +h r )))),e s represents the current predicted entity embedding vector, e r represents the embedding vector of the current predicted relation r, h r Represents entity e s and e r The relationship vector corresponding to the neighborhood information, eo represents the embeddable vector representation of entity o, softmax(·) is the normalized exponential function, and v T represents the weight, W(·) represents the trainable parameter, and tanh(·) represents the tanh activation function; the model structure of the average pooling aggregator is:
[0097]
[0098] in, Neighborhood feature representation of an entity representing the output of the average pooling aggregator.
[0099] Among the three neighborhood aggregators above, the multi-relation neighborhood aggregator works best.
[0100] In one of the embodiments, it also includes: obtaining global information and local information about the entity's historical information based on the entity's latent vector representation; encoding and scoring the temporal event encoder based on the latent vector representation through a feedforward neural network and a multi-classification layer network according to the global information and the local information, so as to realize temporal knowledge graph reasoning.
[0101] In one embodiment, if Figure 2 As shown, the temporal knowledge graph inference model Attn-Net is composed of a neighborhood aggregator, a temporal event encoder based on an attention mechanism, a feedforward neural network, and a multi-classification layer network. Among them, the neighborhood aggregator is a multi-relation neighborhood aggregator, and the feedforward neural network is a fully connected decoding layer. Before the temporal knowledge graph inference model is used to implement temporal knowledge graph inference, it includes: training the temporal knowledge graph inference model through the Adam algorithm and the preset loss function; among them, the preset loss function is the multi-classification cross entropy loss function, which is expressed as follows:
[0102]
[0103] Among them, p(o t |s t ,r t ) indicates that according to the header entity s t and the relationship t The tail entity o appears t The probability, p(r t |s t ) indicates that the entity s t Get the relationship r t The probability of logp(s t ) represents the confidence score of entity s at time t, λ 1 Represents the weight value of entity prediction, λ 2 Represents the weight value of the relationship prediction task.
[0104] It should be understood that although Figure 1 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in the present invention, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 1 At least part of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.
[0105] In one specific embodiment, in order to evaluate the method proposed in the present invention, the commonly used public data sets WIKI and YAGO are used. Both the YAGO data set and WIKI are large open source databases, and the time interval between events is one year. The data contains the head entity, relationship, tail entity and the timestamp information of the event. The training set, validation set and test set are divided into 8:1:1 ratios.
[0106] The statistics of the dataset are listed in Table 1.
[0107] Table 1 Dataset statistics
[0108] Table 1 Dataset Statistics
[0109]
[0110] Two commonly used indicators in knowledge graph reasoning are used: Mean Reciprocal Ranking (MRR) and HITS@n. HITS@n refers to the average proportion of triples ranked less than or equal to n in entity prediction. The lower the value of this indicator, the higher the correct entity ranks in the candidate entity list and the more accurate the model prediction. The specific calculation methods of the two indicators are as follows:
[0111]
[0112] Among them, N represents the total number of prediction results, and rank represents the ranking of the prediction results in the actual output.
[0113]
[0114] Among them, N represents the total number of prediction results, and right represents the number of the top k prediction results.
[0115] In order to verify the performance of the proposed Attn-Net model, the comparison model used in this paper is as follows:
[0116] (1) HyTE: The triples (h, r, t, [Ts, Te]) with timestamps are expressed as hyperplanes, and the triples are projected onto these hyperplanes to obtain projection vectors respectively;
[0117] (2) R-GCN: a static multi-relational graph convolutional model;
[0118] (3) R-GCRN+MLP: predicting future facts by combining GCRN with MLP decoder;
[0119] (4) RE-Net: Modeling event sequences based on RNN event encoder and neighborhood aggregator.
[0120] The experimental results are as follows:
[0121] The experimental results of the Attn-Net model on the dataset are listed in Table 2 and Table 3. From the experimental results in Table 2 and Table 3, we can find that: 1) The effect of Attn-Net is generally better than the previous temporal reasoning model. 2) The effectiveness of the attention mechanism for temporal knowledge reasoning has been verified. On the two public datasets of WIKI and YAGO, Attn-Net has achieved consistent improvements in the Mean Rank indicator; at the same time, Attn-Net has achieved the best effect overall by further considering the importance of fusion relation representation in the aggregator on the basis of RE-NET. 3) On the YAGO public dataset, Attn-Net is not as good as Attn-Net (mean) in overall improvement effect. On the YAGO dataset, Attn-Net (mean) is 1% higher than Attn-Net in Hit (@10). This shows that the average pooling strategy is more conducive to the fusion of accurate prediction representations.
[0122] The experimental results are shown in Table 2. On the YAGO dataset, Attn-Net has the highest experimental results in the entity prediction task. Compared with RE-Net, Attn-Net (mean) has an improvement of 1.5% in the MRR index, and 1.3% and 0.8% in Hit@3 and Hit10 respectively. This shows that after the decoder in Transformer encodes the self-attention, the meanpooling strategy is used to fuse the evolution information of each historical information, which can be further improved and converge to the optimal value faster. This is because Attn-Net can effectively propose important historical information related to reasoning when encoding time series events. When RE-Net uses GRU to model and reason about recurrent events, historical information that is irrelevant to the current reasoning task affects the representation of the final result, resulting in a decrease in prediction accuracy. This shows that the mean strategy and attention mechanism have a certain improvement effect on reasoning tasks. It can improve the reasoning ability of the model as a whole. Attn-Net can improve the accuracy of entity prediction of the time series knowledge graph by modeling and reasoning about historical information.
[0123] Table 2 Experimental results of entity prediction on the YAGO dataset
[0124] Table 2Experimental results of entity prediction on Yago dataset
[0125]
[0126]
[0127] As shown in Table 2, in the YAGO dataset, HyTE
[12] It is a static four-tuple reasoning method that ignores the interaction between entities and time, so the reasoning effect on the YAGO dataset is poor. Attn-Net has the highest experimental results on entity prediction tasks. Compared with RE-Net, Attn-Net has a 1.5% improvement in MRR and a 1.5% improvement in Hit@3 and His@10 indicators, indicating that the overall prediction effect of the attention encoder has improved. This proves the effectiveness of the attention mechanism on the temporal sequence encoder.
[0128] As shown in Table 3, Attn-Net (mean) has improved 2% in MRR compared to RE-Net, indicating that attention-based temporal reasoning has been optimized overall on the WIKI dataset. The improvement effect on Hit@3 and Hit@10 is not very obvious, indicating that the role of attention on the WIKI dataset has improved the overall ranking of predictions, but has not yet reached a good reasoning state.
[0129] Table 3 Experimental results of entity prediction on WIKI dataset
[0130] Table 3 Experimental results of entity prediction on WIKI dataset
[0131]
[0132] In one embodiment, Figure 3 As shown, a temporal knowledge graph reasoning device based on an attention mechanism is provided, comprising: a preprocessing module 302, a neighborhood aggregator module 304, a temporal event encoder module 306 and a decoding prediction module 308, wherein:
[0133] The preprocessing module 302 is used to obtain the time series knowledge graph to be inferred, construct a knowledge graph snapshot for each time period according to the time annotation of the knowledge in the time series knowledge graph, and further obtain the neighborhood information of each entity in each time period;
[0134] A neighborhood aggregator module 304 is used to aggregate neighborhood information corresponding to all relationships of multiple entities through a neighborhood aggregator to obtain a neighborhood feature representation of each entity;
[0135] The temporal event encoder module 306 is used to input the neighborhood feature representation of each entity in each time period in the temporal knowledge graph into the temporal event encoder based on the attention mechanism; the temporal event encoder based on the attention mechanism determines the attention weight matrix containing multi-head information according to the neighborhood feature representation of the target entity at the current moment and the neighborhood feature representation of the historical moment, and selectively pays attention to the temporal entity representation sequence of the historical information through the attention weight matrix, and obtains the latent vector representation of the target entity at the current moment after being updated by the temporal event encoder;
[0136] The decoding prediction module 308 is used to encode and score the time series event encoder according to the latent vector representation through a feedforward neural network and a multi-classification layer network to achieve time series knowledge graph reasoning.
[0137] The neighborhood aggregator module 304 is also used to aggregate the neighborhood information corresponding to all the relationships of multiple entities through the neighborhood aggregator to obtain the neighborhood feature representation of each entity; the neighborhood aggregator is a multi-relation neighborhood aggregator, an attention aggregator or an average pooling aggregator; the model structure of the multi-relation neighborhood aggregator is:
[0138]
[0139] in, Neighborhood feature representation of entities output by multi-relation neighborhood aggregator, Represents the set of neighbor nodes of the relation r of entity s at time t, c s represents the number of edges of entity s in the graph, which is used as a normalization factor, l represents the number of layers of the current aggregator, and W r represents the trainable parameters related to the relationship between entities o and s, W o represents the trainable parameter of the self-loop of entity s, h o ,h s The embedding vectors of entities o and s are respectively represented by the implicit representation of the intermediate layer obtained by the multi-relation aggregator; the model structure of the attention aggregator is:
[0140]
[0141] in, represents the neighborhood feature representation of the entity output by the attention aggregator, a o =softmax(v T tanh(W(e s :e r :(h o +h r )))),e s represents the current predicted entity embedding vector, e r represents the embedding vector of the current predicted relation r, h rRepresents entity e s and e r The relationship vector corresponding to the neighborhood information, eo represents the embeddable vector representation of entity o, softmax(·) is the normalized exponential function, and v T represents the weight, W(·) represents the trainable parameter, and tanh(·) represents the tanh activation function; the model structure of the average pooling aggregator is:
[0142]
[0143] in, Neighborhood feature representation of an entity representing the output of the average pooling aggregator.
[0144] The temporal event encoder module 306 is also used to obtain the neighborhood feature representation g of the target entity at the current time t i , t ; Get the neighborhood feature representation g of the target entity at each time step historical moment i,t ′, t′∈{t-τ,…,t}; according to g i,t and g i,t′ Determine the attention weight matrix containing multi-head information, and further determine the latent vector representation of the target entity after being updated by the temporal event encoder at the current time t:
[0145]
[0146] e ij =q ij -(λ z Δt+b z )+M ij
[0147]
[0148]
[0149] Among them, W q ,W k , Represents the preset linear projection matrix, represents the attention matrix weight containing multi-head information, The matrix is a mask matrix, Δt = Tt′, Δt is the time difference between the current event time and the prediction task time, T represents the time corresponding to the current prediction task, |E| represents the entity set, q ij represents the attention distribution value of entity j for entity i, d represents the dimension of input information, and λ z represents the parameter of historical latent representation decaying over time, b z represents the attenuation bias, i, j, k are time indices, j, k∈t′, hi,t is the latent vector representation of the target entity after being updated by the temporal event encoder at the current time t.
[0150] The decoding prediction module 308 is also used to decode the latent vector representation of the entities and relationships updated by the temporal event encoder at the current time t through a feedforward neural network; and output the probability distribution of the entities or relationships to be predicted through a softmax activation function.
[0151] The decoding prediction module 308 is also used to obtain global and local information about the entity's historical information based on the entity's latent vector representation; based on the global and local information, the temporal event encoder is encoded and scored according to the latent vector representation through a feedforward neural network and a multi-classification layer network to realize temporal knowledge graph reasoning.
[0152] The decoding prediction module 308 is also used to encode and score the time series event encoder according to the latent vector representation based on global information and local information through a feedforward neural network and a multi-classification layer network to achieve time series knowledge graph reasoning; time series knowledge graph reasoning includes predicting the tail entity given a head entity and relationship at a time t, and predicting the relationship given an entity s at a time t.
[0153] For the specific limitations of the temporal knowledge graph reasoning device based on the attention mechanism, please refer to the limitations of the temporal knowledge graph reasoning method based on the attention mechanism above, which will not be repeated here. Each module in the above-mentioned temporal knowledge graph reasoning device based on the attention mechanism can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0154] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 4As shown. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a temporal knowledge graph reasoning method based on an attention mechanism is implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covered on the display screen, or a button, trackball or touchpad set on the computer device shell, or an external keyboard, touchpad or mouse, etc.
[0155] Those skilled in the art will understand that Figure 4 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0156] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps in the above method embodiment when executing the computer program.
[0157] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above method embodiment are implemented.
[0158] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0159] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0160] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. A temporal knowledge graph reasoning method based on attention mechanism, characterized in that: The method comprises: Obtain the time series knowledge graph to be inferred, construct a knowledge graph snapshot for each time period according to the time annotation of the knowledge in the time series knowledge graph, and further obtain the neighborhood information of each entity in each time period; Aggregating the neighborhood information corresponding to all relationships of multiple entities through a neighborhood aggregator to obtain a neighborhood feature representation of each entity; Inputting the neighborhood feature representation of each entity in each time period in the temporal knowledge graph into a temporal event encoder based on an attention mechanism; the temporal event encoder based on the attention mechanism is used to determine an attention weight matrix containing multi-head information according to the neighborhood feature representation of the target entity at the current moment and the neighborhood feature representation of the historical moment, and selectively focusing on the temporal entity representation sequence of the historical information through the attention weight matrix to obtain the latent vector representation of the target entity at the current moment after being updated by the temporal event encoder; The time series event encoder is encoded and scored according to the latent vector representation through a feedforward neural network and a multi-classification layer network to achieve time series knowledge graph reasoning.
2. The method according to claim 1, characterized in that Aggregating the neighborhood information corresponding to all relationships of multiple entities through a neighborhood aggregator to obtain a neighborhood feature representation of each entity, including: Aggregating the neighborhood information corresponding to all relations of multiple entities through a neighborhood aggregator to obtain a neighborhood feature representation of each entity; the neighborhood aggregator is a multi-relation neighborhood aggregator, an attention aggregator or an average pooling aggregator; The model structure of the multi-relation neighborhood aggregator is: in, represents the neighborhood feature representation of the entity output by the multi-relation neighborhood aggregator, Represents the set of neighbor nodes of the relation r of entity s at time t, c s represents the number of edges of entity s in the graph, which is used as a normalization factor, l represents the number of layers of the current aggregator, and W r represents the trainable parameters related to the relationship between entities o and s, W o represents the trainable parameter of the self-loop of entity s, h o ,h s The embedding vectors of entities o and s are respectively used to obtain the implicit representation of the intermediate layer through the multi-relation aggregator; The model structure of the attention aggregator is: in, represents the neighborhood feature representation of the entity output by the attention aggregator, a o =softmax(v T tanh(W(e s :e r :(h o +h r )))),e s represents the current predicted entity embedding vector, e r represents the embedding vector of the current predicted relation r, h r Represents entity e s and e r The relationship vector corresponding to the neighborhood information, eo represents the embeddable vector representation of entity o, softmax(·) is the normalized exponential function, and v T represents weight, W(·) represents trainable parameter, and tanh(·) represents tanh activation function; The model structure of the average pooling aggregator is: in, Represents the neighborhood feature representation of the entity output by the average pooling aggregator.
3. The method according to claim 2, characterized in that The neighborhood feature representation of each entity in each time period in the temporal knowledge graph is input into a temporal event encoder based on an attention mechanism; the temporal event encoder based on the attention mechanism determines an attention weight matrix containing multi-head information according to the neighborhood feature representation of the target entity at the current moment and the neighborhood feature representation of the historical moment, and selectively pays attention to the temporal entity representation sequence of the historical information through the attention weight matrix, and obtains the latent vector representation of the target entity at the current moment after being updated by the temporal event encoder, including: Get the neighborhood feature representation g of the target entity at the current time t i,t ; Get the neighborhood feature representation g of the target entity at each time step historical moment i,t′ , t′∈{t-τ,…,t}; According to g i,t and g i,t′ Determine the attention weight matrix containing multi-head information, and further determine the latent vector representation of the target entity after being updated by the temporal event encoder at the current time t: from ij =q ij -(λ z Δt+b z )+M ij Among them, W q ,W k , Represents the preset linear projection matrix, represents the attention matrix weight containing multi-head information, The matrix is a mask matrix, Δt = Tt′, Δt is the time difference between the current target event time and the prediction task time, T represents the time corresponding to the current prediction task, |E| represents the entity set, q ij represents the attention distribution value of entity j for entity i, d represents the dimension of input information, and λ z represents the parameter of historical latent representation decaying over time, b z represents the attenuation bias, i, j, k are time indices, j, k∈t′, h i,t is the latent vector representation of the target entity after being updated by the temporal event encoder at the current time t.
4. The method according to claim 3, characterized in that The time series event encoder is encoded and scored according to the latent vector representation through a feedforward neural network and a multi-classification layer network to realize time series knowledge graph reasoning, including: Decode the latent vector representation of entities and relationships updated by the temporal event encoder at the current time t through a feedforward neural network; The softmax activation function is used to output the probability distribution of the entity or relationship that needs to be predicted.
5. The method according to claim 4, characterized in that The time series event encoder is encoded and scored according to the latent vector representation through a feedforward neural network and a multi-classification layer network to realize time series knowledge graph reasoning, including: According to the latent vector representation of the entity, global information and local information about the entity's historical information are obtained; According to the global information and the local information, the temporal event encoder is encoded and scored according to the latent vector representation through a feedforward neural network and a multi-classification layer network to achieve temporal knowledge graph reasoning.
6. The method according to claim 5, characterized in that According to the global information and the local information, the temporal event encoder is encoded and scored according to the latent vector representation through a feedforward neural network and a multi-classification layer network to realize temporal knowledge graph reasoning, including: According to the global information and the local information, the time series event encoder is encoded and scored according to the latent vector representation through a feedforward neural network and a multi-classification layer network to achieve time series knowledge graph reasoning; the time series knowledge graph reasoning includes predicting the tail entity given a head entity and relationship at a time t, and predicting the relationship given an entity s at a time t.
7. The method according to claim 6, characterized in that The neighborhood aggregator, the attention-based temporal event encoder, the feedforward neural network, and the multi-classification layer network constitute a temporal knowledge graph reasoning model. Before the temporal knowledge graph reasoning is implemented by the temporal knowledge graph reasoning model, the following steps are included: The temporal knowledge graph inference model is trained by the Adam algorithm and a preset loss function; wherein the preset loss function is a multi-classification cross entropy loss function, which is expressed as follows: Among them, p(o t |s t ,r t ) indicates that according to the header entity s t and the relationship t The tail entity o appears t The probability, p(r t |s t ) indicates that the entity s t Get the relationship r t The probability of logp(s t ) represents the confidence score of entity s at time t, λ1 represents the weight value of entity prediction, and λ2 represents the weight value of relationship prediction task.
8. A temporal knowledge graph reasoning device based on an attention mechanism, characterized in that: The device comprises: A preprocessing module is used to obtain the time series knowledge graph to be inferred, construct a knowledge graph snapshot for each time period according to the time annotation of the knowledge in the time series knowledge graph, and further obtain the neighborhood information of each entity in each time period; A neighborhood aggregator module, configured to aggregate the neighborhood information corresponding to all relationships of multiple entities through a neighborhood aggregator to obtain a neighborhood feature representation of each entity; A temporal event encoder module, used for inputting the neighborhood feature representation of each entity in each time period in the temporal knowledge graph into a temporal event encoder based on an attention mechanism; the temporal event encoder based on the attention mechanism determines an attention weight matrix containing multi-head information according to the neighborhood feature representation of the target entity at the current moment and the neighborhood feature representation of the historical moment, and selectively pays attention to the temporal entity representation sequence of the historical information through the attention weight matrix, so as to obtain the latent vector representation of the target entity at the current moment after being updated by the temporal event encoder; The decoding prediction module is used to encode and score the time series event encoder according to the latent vector representation through a feedforward neural network and a multi-classification layer network to realize time series knowledge graph reasoning.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Knowledge graph relationship prediction method and device based on attention mechanism
CN113535984A
Risk prediction method and device, equipment and storage medium
CN113822494A
Interpretable bio-medical link prediction using deep neural representation
US20190303535A1
Semantic representation model-based text classification method and apparatus, and computer device
WO2021051503A1
