Temporal knowledge graph reasoning method and device based on temporal rule guidance and storage medium

By introducing tense rule guidance and cross-attention mechanisms into the tense knowledge graph inference method, the shortcomings of existing methods in utilizing context information and time information are solved, and higher inference accuracy and efficiency are achieved, especially in multi-entity interaction scenarios.

CN120196762APending Publication Date: 2025-06-24SOUTHWEST UNIV
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202510261869.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-06
Publication Date
2025-06-24

AI Technical Summary

Technical Problem

Existing tense knowledge graph inference methods cannot fully utilize the context and temporal information around entities, resulting in insufficient inference accuracy and efficiency when processing multi-entity dynamic interaction scenarios.

Method used

Using a method based on temporal rule guidance, by obtaining quadruple containing query targets, extracting multi-hop historical subgraphs, initializing embedding of entities, relationships and time, fusing time encoding and structural encoding, using the cross attention mechanism to calculate the correlation between the time relationship sequence and the entity sequence, iteratively generates the time relationship probability distribution, and optimize the model to improve prediction accuracy.

Benefits of technology

It significantly improves the interpretability and applicability of the model in the time dimension, improves the accuracy and efficiency of reasoning, especially in multi-entity interaction scenarios, and enhances the interpretability of the results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120196762A_ABST
    Figure CN120196762A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of artificial intelligence, in particular to a tense knowledge graph reasoning method and device based on tense rule guidance and a storage medium. The method comprises the following steps: firstly, extracting a multi-hop historical sub-graph based on a query quadruple, and integrating entity association information under time constraint; secondly, designing a time coding model, and explicitly capturing the influence of a time interval on an entity relationship through periodic features and learnable parameters; further, entity representation is enhanced by utilizing a relation type, and entity embedding is dynamically updated in combination with graph structure coding and a tense attention mechanism so as to fuse spatio-temporal semantics; then, a time relation sequence is generated through cross attention iteration, and target entity prediction is achieved in combination with probability distribution; and finally, optimizing the model by adopting a composite loss function, and analyzing a high-confidence symbol rule to provide interpretability. According to the method, the reasoning precision of the tense knowledge graph is remarkably improved, and the method has wide application value in time-sensitive scenes such as event prediction and trend analysis.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular, to a temporal knowledge graph reasoning method, device and storage medium guided by temporal rules. Background Art

[0002] A knowledge graph is a graph data structure used to represent facts in the real world, consisting of nodes and edges, where nodes represent entities objectively existing in the real world and edges represent the relationships between entities. However, traditional knowledge graphs mainly describe static common sense knowledge and rarely involve time information, which limits their applications in dealing with a large number of emerging knowledge with time information in cyberspace. Therefore, a temporal knowledge graph is introduced. A temporal knowledge graph is an extended form that, on the basis of a knowledge graph, introduces time information to describe the relationships and evolution processes between entities at different time points. Temporal knowledge graphs can be used to describe the historical and future relationships between entities, reflect the evolution processes and dynamic changes between entities, and have wide application values.

[0003] Reasoning tasks are one of the current hot topics in temporal knowledge graphs, aiming to predict missing facts in temporal knowledge graphs using existing facts with temporal information. Most existing reasoning methods are for traditional static knowledge graph tasks and cannot consider and utilize the additional temporal information in temporal knowledge graphs, resulting in the inability to solve the predictive reasoning problems of temporal knowledge graphs. Currently, academia and industry have proposed methods including but not limited to those based on recurrent neural networks and graph neural networks for the reasoning tasks of temporal knowledge graphs to improve prediction accuracy. These include: HyTE constructs the temporal information in the temporal knowledge graph as a hyperplane and then projects entity vectors and relation vectors onto this hyperplane. CyGNet proposes a copy generation method to simulate duplicate facts of the same entities and relations as each query. RE-NET learns the global representation of the temporal subgraph and the local representation of nodes, combining RNN and GCN to capture the temporal and structural dependencies of entity sequences. RE-GCN encodes all historical facts into the evolving representations of entities and relations to predict future facts. To integrate global temporal information, TiRCN designs a global historical encoder network for collecting duplicate historical facts. However, these methods operate in a black-box manner and cannot explain the prediction results. Therefore, some researchers provide interpretability for the prediction results by generating logical rules, that is, the rule-based temporal knowledge graph reasoning method mainly lies in how to mine logical rules from temporal facts and finally evaluate the confidence of the rules by combining statistics and temporal information and perform reasoning predictions according to the learned rules. StreamLearner generates rules using a static rule learner and then generalizes the rules to the temporal domain, where all body atoms have the same timestamp. TLogic learns temporal logic rules with confidence through temporal random walks, and the candidate scores are obtained by applying the rules in TKGs. TFLEX proposes a temporal feature-logical embedding framework that supports complex multi-hop logical rules on TKGs. TLmod proposes a temporal logic rule mining strategy based on traversal and pruning to achieve the extension of temporal logic rules. However, these methods often ignore some key information in the knowledge graph, resulting in the inability to guarantee high prediction accuracy. There are mainly the following two problems:

[0004] Insufficient mining of context information: Most current methods learn and reason based on individual quadruples and fail to fully utilize the broader context information around entities. This limitation makes the model perform inadequately in understanding the semantic relationships between entities and the global graph structure, unable to fully grasp the complex interaction logic between entities, thus restricting the accuracy and efficiency of reasoning, especially performing poorly in scenarios involving dynamic interactions among multiple entities.

[0005] Insufficient processing of temporal information: Although some methods try to improve the interpretability of models by introducing temporal logic rules, most temporal knowledge graph reasoning methods still rely on static entity and relationship models and fail to fully explore and model the dynamic changes in the time dimension. This approach that ignores time evolution cannot effectively capture the temporal dependency of entity relationships, limits the model's ability to predict future events and understand dynamic relationship changes, and thus reduces its performance in time-sensitive applications such as event prediction and trend analysis. Summary of the invention

[0006] In order to solve the above technical problems, the present invention provides a temporal knowledge graph reasoning method based on temporal rule guidance, comprising the following steps:

[0007] S1. Obtain a quadruple containing a query target, and extract a multi-hop historical subgraph associated with a head entity and a query time in the quadruple from a temporal knowledge graph, wherein the quadruple includes a head entity, a relationship, a query time, and a query target;

[0008] S2. Initialize embedding of all entities, relations and query times in the subgraph according to the obtained multi-hop historical subgraph, and enhance the entity representation according to the domain and scope information of the relation in the quadruple to obtain an enhanced entity embedding representation;

[0009] S3. Based on the temporal graph encoder, the enhanced entity embedding representation is dynamically updated by fusing time coding, structural coding and relational attention mechanism to obtain the entity sequence;

[0010] S4. Construct a temporal relationship sequence based on the relationship and time information, calculate the semantic relevance between the temporal relationship sequence and the entity sequence through the cross-attention mechanism, iteratively generate the temporal relationship probability distribution, and dynamically update the entity prediction results according to the temporal relationship probability distribution to obtain the query target result;

[0011] S5. Construct a composite loss function optimization model to optimize the query target results, and based on the relationship path of the query target results, analyze the temporal logic rules in the prediction process and calculate the confidence of the rules.

[0012] Furthermore, the step S1 includes the following steps:

[0013] S101. Based on the temporal knowledge graph, extract a set of neighbor nodes directly associated with the query target header entity and time, where the timestamp of the neighbor nodes is no later than the query time;

[0014] S102. Based on the obtained neighbor node set, further associated nodes are obtained layer by layer through a recursive expansion method to obtain a subgraph containing a multi-hop path, in which all involved entities, relationships and timestamp information are retained.

[0015] Furthermore, step S2 includes the following steps:

[0016] S201. Given a temporal knowledge graph, which can be expressed as:

[0017] G = {V, R, T, F}

[0018] where V is the set of entities, R is the set of relationships, T is the set of timestamps, and F is the set of facts;

[0019] S202. Randomly initialize the embeddings using the standard normal distribution, initialize the embeddings of each entity in the entity set, and initialize the embeddings of each relationship in the relationship set;

[0020] S203. Combine the time interval and periodic features with the time embedding, and its model can be expressed as:

[0021]

[0022] i = [1, …, n]

[0023] where w i is the learnable time frequency parameter, θ i is the phase shift, i is the learnable parameter, n is the total number of all elements in the set, d represents the dimension of the time embedding, is the time encoding vector, t q is the current query time information, t j is the time point in the historical subgraph.

[0024] Furthermore, the enhanced entity representation enhances the entity embedding representation through the domain and range embeddings of the relationship, and the enhanced entity embedding representation is:

[0025]

[0026] where X ei is the initialized entity embedding, Y ei is the enhanced entity embedding representation, is the domain of the relationship, is the range embedding of the relationship, is the domain distribution of the i-th relationship type after normalization, is the range distribution of the i-th relationship type after normalization.

[0027] Furthermore, the domain distribution of the i-th relationship type and the range distribution of the relationship type can be expressed as:

[0028]

[0029] where is the number of the i-th type of relationships connected to the entity, is the number of the i-th type of relationships connected to the self-entity, R is the number of relationship types, and j is the index of the relationship type.

[0030] Furthermore, step S3 includes the following steps:

[0031] S301. Fuse the enhanced entity embedding representation with the time encoding and the centrality encoding to obtain the time entity encoding, which can be expressed as:

[0032] h ei = Y ei + z deg - (ei) + z deg + (ei) + X ti

[0033] where h ei is the time entity encoding, X ti is the time embedding, is the out-degree encoding representation of the entity ei, is the in-degree encoding representation of the entity;

[0034] S302. Input the obtained time entity encoding into the temporal graph encoder, and calculate the importance of neighbor nodes to the target node through the attention mechanism to obtain the attention score, and its calculation formula can be expressed as:

[0035]

[0036] where A ij is the attention score, R is the number of relationship types, k r is whether there is a relationship r between the entity ei and the entity ej. If there is, then k r is 1, otherwise it is 0, x r is the encoding of the relationship r, T is the transpose operation of the matrix, W Q and W K are the query matrix and key matrix of the entity respectively, and W Kr is the key matrix of the relationship, and dk is the dimension of the matrix.

[0037] S303. Based on the spatial encoding, edge encoding and time attention value, construct a relevance representation function according to the attention score, and calculate the comprehensive attention score. The calculation formula can be expressed as:

[0038]

[0039] t ij = |t i - t j |

[0040] Among them, α ij is the comprehensive attention score, is the spatial encoding, c ij is the edge encoding, t ij is the temporal attention value, x rn is the shortest path SP ij on the nth edge x rn of the feature, is the weight embedding of the nth edge, and λ is a parameter that controls the degree of temporal attention attenuation of the time interval;

[0041] S304. According to the calculated comprehensive attention score, update the enhanced entity embedding representation and output the updated entity sequence to the temporal decoder. The update formula can be expressed as:

[0042]

[0043] Among them, z i is the embedding representation of the updated entity ei, W V is the value matrix of the entity, and W Vr is the value matrix of the relationship.

[0044] Furthermore, step S4 includes the following steps:

[0045] S401. Combine the initial embedding of the relationship and the time information to obtain the time relationship sequence, which can be expressed as:

[0046]

[0047] Among them, is the time relationship sequence, [.;.] is the vector concatenation operation, x r is the initial embedding of the relationship, and x t is the initial embedding of the time;

[0048] S402. Calculate the correlation score between the time relationship sequence and the entity sequence through the cross-attention mechanism. The calculation formula can be expressed as:

[0049]

[0050] K = S e W K

[0051] V = S e W V

[0052] Among them, S e is the entity sequence, is the time relationship sequence, K is the key of the entity sequence embedding, and K TK is the transpose of the key for entity sequence embedding, Q is the query vector for the temporal relation sequence, and V is the value vector for entity sequence embedding;

[0053] S403. The correlation scores calculated according to S402 are non-linearly transformed through a multi-layer perceptron to obtain the temporal relation probability distribution, and its calculation formula can be expressed as:

[0054]

[0055] where, W l+1 is the probability distribution of the next temporal relation, MLP is the multi-layer linear perceptron, is the relation sequence at the l-th step, is the temporal relation sequence at the l-th step, is the relation selected at the (l + 1)-th step, is the time selected at the (l + 1)-th step. After l steps are executed, a rule body with a maximum length of L is obtained;

[0056] S404. According to the temporal relation probability distribution, the entity probability vector is updated, and its update formula can be expressed as:

[0057]

[0058] z l ∈R E

[0059] where, z l is the probability distribution of all entities in the l-th step, W l ri and W l tj are the relation probability and the time probability in the l-th step respectively, is the adjacency matrix of relation R k , is the adjacency matrix of time t k . When l = 0, the entity probability vector z0 is a one-hot vector used to mark the head entity in the query target. It is continuously updated and iterated until the function converges to obtain the query target result.

[0060] Furthermore, the composite loss function optimization model described in step S5 can be expressed as:

[0061]

[0062] where, β is the weight of the time difference term, o is the tail entity in the quadruple, s is the head entity in the quadruple, p is the relation entity in the quadruple, γ is the scoring function threshold, t l is the predicted time information, and t is the time information in the quadruple.

[0063] The present invention also provides a computer device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the steps of any one of the above-mentioned temporal knowledge graph reasoning methods guided by temporal rules are implemented.

[0064] The present invention also provides a storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of any one of the above-mentioned temporal knowledge graph reasoning methods guided by temporal rules are implemented.

[0065] The beneficial effects of the present invention are as follows:

[0066] (1) In the processing of time information, the present invention introduces a time encoding and a time attention mechanism, enabling the model to dynamically capture the impact of time on entity relationships, and providing more accurate reasoning results in time-sensitive tasks (such as event prediction, trend analysis, etc.), significantly enhancing the interpretability and applicability of the model in the time dimension.

[0067] (2) By deeply mining the context information of entities in a temporal encoder, the present invention effectively integrates information in the time, space, and structure dimensions on the basis of fusing time information, enabling the model to generate entity embeddings with high semantic expression capabilities, capturing deeper semantic relationships and context information between entities, thereby improving the accuracy of reasoning, especially in complex dynamic scenarios such as multi-entity interaction scenarios.

[0068] (3) Through the temporal cross-attention mechanism, the present invention achieves high-precision prediction in the link prediction task. At the same time, the parsing of symbolic rules improves the interpretability of the results, enhancing the user's trust in the model prediction results. Description of the Drawings

[0069] Figure 1 A flowchart of a temporal knowledge graph reasoning method guided by temporal rules according to the present invention.

[0070] Figure 2 A schematic structural diagram of the temporal knowledge graph reasoning method according to an embodiment of the present invention.

[0071] Figure 3 A schematic structural diagram of the temporal encoder according to an embodiment of the present invention.

[0072] Figure 4 A schematic structural diagram of a computer device according to the present invention.

[0073] Figure 5 A schematic structural diagram of a storage medium according to the present invention.

[0074] In the figure, 200 - terminal device, 210 - memory, 211 - RAM, 212 - cache memory, 213 - ROM, 214 - programs / utilities, 215 - program modules, 220 - processor, 230 - bus, 240 - external device, 250 - I / O interface, 260 - network adapter, 300 - program product. Detailed implementation manners

[0075] For those skilled in the art to better understand the content of the present invention, and to make the objectives, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with embodiments and the accompanying drawings. The illustrative embodiments of the present invention and their descriptions are only used to explain the present invention and are not intended to further limit the present invention.

[0076] Embodiment 1:

[0077] As Figure 1 shown, the embodiment of the present invention provides a temporal knowledge graph reasoning method guided by temporal rules, including the following steps:

[0078] S1. Obtain a quadruple containing the query target, and extract a multi-hop historical subgraph associated with the head entity and the query time in the temporal knowledge graph, where the quadruple includes a head entity, a relationship, a query time, and a query target;

[0079] Specifically: For a given query (sq, rq,?, tq), where sq is the head entity, rq is the relationship, tq is the time,? represents the target to be queried, indicating an unknown state. First, extract a multi-hop historical subgraph related to the query head entity sq and time tq from the knowledge graph G The specific process is as follows: Obtain a set of neighbor nodes directly associated with the head entity sq and time tq from G, where the timestamps of these neighbor nodes are not later than the query time tq; then, through recursive expansion operations, obtain farther associated nodes layer by layer from these neighbor nodes, and finally form a subgraph containing multi-hop paths. Retain all the involved entities, relationships, and timestamp information in the subgraph as the input for subsequent temporal graph embedding and reasoning. This extraction method ensures that the model can obtain the context structure and dynamic time information related to the query, providing a necessary basis for the subsequent reasoning process.

[0080] S2. According to the obtained multi-hop historical subgraph, initialize the embedding of all entities, relationships, and query time in the subgraph, and enhance the entity representation according to the domain and range information of the relationship in the quadruple to obtain an enhanced entity embedding representation;

[0081] Specifically: Given a temporal knowledge graph G = {V, R, T, F}, where V represents the set of entities, R represents the set of relationships, T represents the set of timestamps, and F = {(s, r, o, t)|s, o ∈ V, r ∈ R, t ∈ T} represents the set of facts; for each entity v ∈ V, its embedding Xv is initialized, and for each relationship r ∈ Rr, its embedding Xr is initialized. The embeddings are randomly initialized using the standard normal distribution; meanwhile, in order to capture the dynamic change characteristics of time information, the time embedding combines the time interval and periodic features, and the specific formula is as follows:

[0082]

[0083] i = [1, …, n]

[0084] where, w i is the learnable time frequency parameter, θ i is the phase shift, i is the learnable parameter, n is the total number of all elements in the set, and d represents the dimension of the time embedding, is the time encoding vector, t q is the current query time information, and t j is the time point in the historical subgraph;

[0085] Specifically, considering the widespread existence of long-tail entities (i.e., entities with fewer associated relationships) in the temporal knowledge graph, these entities are usually difficult to effectively model through their own embedding representations. Therefore, in this step, the entity embedding representation is enriched by introducing relationship type information. The entity embedding representation is enhanced through the domain and range embeddings of the relationship, and the enhanced entity embedding representation is:

[0086]

[0087] where, X ei is the initialized entity embedding, Y ei is the enhanced entity embedding representation, and are the domain and range embeddings of the relationship respectively, are the domain distribution and range distribution of the i-th relationship type after normalization respectively.

[0088] Specifically, the distribution calculation can be expressed as:

[0089]

[0090] where, and are the number of the i-th relationships connecting to the entity and connecting from the entity respectively, R is the number of relationship types, and j is the index of the relationship type.

[0091] S3. Based on the temporal graph encoder, the enhanced entity embedding representation is dynamically updated by integrating time encoding, structural encoding, and relational attention mechanism to obtain an entity sequence;

[0092] Specifically, as Figure 3 shown, the temporal graph encoder updates the entity embedding by integrating multi-dimensional information such as time, space, and graph structure to capture the contextual information and temporal dynamic characteristics between entities. The specific implementation process is as follows: First, the entity embedding is fused with time encoding and centrality encoding to generate the time entity encoding h ei . The time encoding can explicitly reflect the impact of time on entity relationships, and the centrality encoding describes the global importance of entities in the graph structure, which helps the model understand the role and position of entities in the overall network, thereby enhancing the entity embedding's ability to understand the overall graph structure information. The fused entity embedding representation is:

[0093]

[0094] where h ei is the time entity encoding, X ti is the time embedding, are the out-degree and in-degree encoding representations of the entity respectively;

[0095] Subsequently, the obtained time entity encoding is input into the temporal graph encoder, and the importance of neighbor nodes to the target node is calculated through the attention mechanism to obtain the attention score, and its calculation formula can be expressed as:

[0096]

[0097] where A ij is the attention score, R is the number of relationship types, k r is whether there is a relationship r between entity ei and entity ej, if it exists, it is 1, otherwise it is 0, x r is the encoding of relationship r, T is the transpose operation of the matrix, W Q and W K are the query matrix and key matrix of the entity respectively, W Kr is the key matrix of the relationship, and dk is the dimension of the matrix.

[0098] Then, based on the spatial encoding, edge encoding, and temporal attention value, a relevance representation function is constructed according to the attention score, and the comprehensive attention score is calculated. The calculation formula can be expressed as:

[0099]

[0100] t ij =|t i -t j |

[0101] Among them, α ij is the comprehensive attention score, is the spatial encoding, c ij is the edge encoding, t ij is the temporal attention value, x rn is the shortest path SP ij on the nth edge x rn features, is the weight embedding of the nth edge, and λ is a parameter that controls the attenuation degree of temporal attention by the time interval;

[0102] Finally, according to the calculated comprehensive attention score, the enhanced entity embedding representation is updated, and the updated entity sequence is output to the temporal decoder. Its update formula can be expressed as:

[0103]

[0104] Among them, z i is the embedding representation of the updated entity ei, W V is the value matrix of the entity, W Vr is the value matrix of the relationship.

[0105] S4. Construct a temporal relationship sequence based on relationship and time information, calculate the semantic correlation between the temporal relationship sequence and the entity sequence through the cross-attention mechanism, iteratively generate the temporal relationship probability distribution, and dynamically update the entity prediction result according to the temporal relationship probability distribution to obtain the query target result;

[0106] Specifically, by combining the time encoding and the relationship encoding to generate a temporal relationship sequence, it can effectively capture the time information and relationship characteristics in the query, providing a basis for the model to model the dynamic interaction between entities. It can be expressed as:

[0107]

[0108] Among them, is the temporal relationship sequence, [.;.] is the vector concatenation operation, x r , x t are the initial embeddings of the relationship and time respectively;

[0109] Then, calculate the correlation score between the temporal relationship sequence and the entity sequence through the cross-attention mechanism. Its calculation formula can be expressed as:

[0110]

[0111] K = S e W K

[0112] V = S e WV

[0113] Among them, S e is the entity sequence, and Q is the time relation sequence is the query vector, K and V are the key and value vectors of the entity sequence embedding respectively, and K T is the transpose of the key K of the entity sequence embedding;

[0114] Subsequently, according to the calculated correlation scores, a non-linear transformation is performed through a multi-layer perceptron to obtain the time relation probability distribution, and its calculation formula can be expressed as:

[0115]

[0116] Among them, W l+1 is the probability distribution of the next time relation, MLP is the multi-layer linear perceptron, is the relation sequence at the l-th step, is the time relation sequence at the l-th step, is the relation selected at the (l + 1)-th step, is the time selected at the (l + 1)-th step. One relation and one time are mined at each step. After l steps, a rule body with a maximum length of L is mined, where l = 1 - L;

[0117] Subsequently, according to the time relation probability distribution, at the l-th step, using the probabilities of all relations and times generated at the (l - 1)-th step, the entity probability vector is updated as:

[0118]

[0119] z l ∈R E

[0120] Among them, z l is the probability distribution of all entities at the l-th step, and W l ri and W l tj are the relation probability and the time probability at the l-th step respectively, is the adjacency matrix of the relation R k , is the adjacency matrix of the time t k . When l = 0, the entity probability vector z0 is a one-hot vector, which is used to mark the head entity sq of the query. Through continuous iteration, at each step, the model will integrate the time and relation probabilities into the entity distribution, and finally achieve accurate target entity prediction.

[0121] S5. Build a composite loss function optimization model to optimize the query target results, analyze the temporal logic rules in the prediction process based on the relationship paths of the query target results, and calculate the confidence of the rules.

[0122] Specifically, a composite loss function containing cross-entropy loss and a time difference term is designed. The role of cross-entropy loss is to maximize the prediction probability of the model for the correct target entity while minimizing the error of the model for the wrong target. The time difference term is used to optimize the time-related reasoning effect. By measuring the difference between the predicted time and the real time, it guides the model to capture the temporal dynamic characteristics more precisely. The predicted entity and the target entity are optimized through the cross-entropy loss function, and the time difference term is used to optimize the time-related reasoning effect. The introduction of the time difference term solves the key role of time information in the reasoning process and prevents the model from ignoring the influence of the time dimension. Finally, the loss function is defined as:

[0123]

[0124] where β is the weight of the time difference term, o is the tail entity in the quadruple, s is the head entity in the quadruple, p is the relationship entity in the quadruple, γ is the scoring function threshold, t l is the predicted time information, and t is the time information in the quadruple; by maximizing the probability of the correct target and minimizing the error between the prediction and the real target through the optimization function, that is:

[0125]

[0126] Specifically, for the query (sq, rq,?, tq), the model recovers potential rules through parameters. During the reasoning process, at each step, the relationships and times with weights exceeding the set threshold are selected, and at the same time, it is checked whether there is an entity connected to the current entity through these relationships in the previous step of reasoning, and whether the current time satisfies the condition of being less than the query time tq. By iteratively executing the above steps in a loop, the rule path is gradually constructed until the rule length reaches the maximum length T. During the rule generation process, the confidence of each rule is calculated by multiplying the weights of the selected relationships and times.

[0127] Finally, the model outputs symbolic rules with high confidence and logically interprets the query results. These extracted rules not only provide a clear causal relationship link for the model reasoning results but also greatly improve the credibility and interpretability of the model. The model structure of the temporal knowledge graph reasoning method is as Figure 2 shown.

[0128] Example 2

[0129] As Figure 4As shown, based on Embodiment 1, this embodiment proposes a terminal device for a temporal knowledge graph reasoning method guided by temporal rules. The terminal device 200 includes at least one memory 210, at least one processor 220, and a bus 230 connecting different platform systems.

[0130] The memory 210 may include a readable medium in the form of volatile memory, such as RAM 211 and / or cache memory 212, and may further include ROM 213.

[0131] Among them, the memory 210 also stores a computer program, which can be executed by the processor 220, so that the processor 220 executes any one of the above-mentioned temporal knowledge graph reasoning methods in the embodiments of the present application. Its specific implementation manner is consistent with the implementation manners and the achieved technical effects described in the embodiments of the above methods, and some contents will not be repeated. The memory 210 may further include a program / utilities 214 having a set (at least one) of program modules 215. Such program modules include, but are not limited to: an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include the implementation of a network environment.

[0132] Correspondingly, the processor 220 can execute the above computer program and can also execute the program / utilities 214.

[0133] The bus 230 may represent one or more of several types of bus structures, including a memory bus or a memory controller, a peripheral bus, a graphics acceleration port, a processor, or a local bus using any bus structure in a variety of bus structures.

[0134] The terminal device 200 can also communicate with one or more external devices 240, such as a keyboard, a pointing device, a Bluetooth device, etc., and can also communicate with one or more devices capable of interacting with the terminal device 200, and / or communicate with any device (such as a router, a modem, etc.) that enables the terminal device 200 to communicate with one or more other computing devices. Such communication can be carried out through the I / O interface 250. And the terminal device 200 can also communicate with one or more networks (such as a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) through the network adapter 260. The network adapter 260 can communicate with other modules of the terminal device 200 through the bus 230. It should be understood that although not shown in the figure, other hardware and / or software modules can be used in combination with the terminal device 200, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID systems, tape drives, and data backup storage platforms, etc.

[0135] Example 3

[0136] As Figure 5 shown, based on Example 1, this example proposes a computer-readable storage medium for a temporal knowledge graph reasoning method guided by temporal rules. Instructions are stored on the computer-readable storage medium, and when executed by a processor, these instructions implement any one of the above temporal knowledge graph reasoning methods guided by temporal rules. Its specific implementation manner is consistent with the implementation manner and the achieved technical effects described in the embodiments of the above method, and some content will not be elaborated again.

[0137] Figure 3 Fig. shows a program product 300 provided in this example for implementing the above method. It can use a portable compact disc read-only memory (CD-ROM) and include program code, and can run on a terminal device, such as a personal computer. However, the program product 300 of the present invention is not limited to this. In this example, the readable storage medium can be any tangible medium that contains or stores a program, and this program can be used by or in combination with an instruction execution system, device, or component. The program product 300 can adopt any combination of one or more readable media. The readable media can be a readable signal medium or a readable storage medium. The readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or component, or any combination of the above. More specific examples (non-exhaustive list) of the readable storage medium include: an electrical connection having one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0138] Computer-readable storage media may include data signals propagated in baseband or as part of a carrier wave, wherein readable program codes are carried. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The readable storage medium may also be any readable medium other than the readable storage medium, which may send, propagate, or transmit a program used by or in combination with an instruction execution system, an apparatus, or a device. The program code contained on the readable storage medium may be transmitted with any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the above. The program code for performing the operation of the present invention may be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java, C++, etc., and also conventional procedural programming languages ​​such as "C" language or similar programming languages. The program code may be executed entirely on a user computing device, partially on a user device, as an independent software package, partially on a user computing device, partially on a remote computing device, or entirely on a remote computing device or server. Where a remote computing device is involved, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., through the Internet using an Internet service provider).

[0139] The present invention is explained from the viewpoints of purpose of use, efficiency, progress and novelty, and the practical progress it has is in line with the functional enhancement and use requirements emphasized by the Patent Law. The above description and drawings of this application are only preferred embodiments of this application, and are not intended to limit this application. Therefore, all structures, devices, features, etc. that are similar or identical to those of this application, that is, all equivalent replacements or modifications made in accordance with the scope of the patent application of this application, should fall within the scope of protection of the patent application of this application.

[0140] The specific implementation methods described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific implementation method of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

Claims

1. A temporal knowledge graph reasoning method based on temporal rule guidance, characterized in that: The following steps are involved: S1. Obtain a quadruple containing a query target, and extract a multi-hop historical subgraph associated with a head entity and a query time in the quadruple from a temporal knowledge graph, wherein the quadruple includes a head entity, a relationship, a query time, and a query target; S2. Initialize embedding of all entities, relations and query times in the subgraph according to the obtained multi-hop historical subgraph, and enhance the entity representation according to the domain and scope information of the relation in the quadruple to obtain an enhanced entity embedding representation; S3. Based on the temporal graph encoder, the enhanced entity embedding representation is dynamically updated by fusing time coding, structural coding and relational attention mechanism to obtain the entity sequence; S4. Construct a temporal relationship sequence based on the relationship and time information, calculate the semantic relevance between the temporal relationship sequence and the entity sequence through the cross-attention mechanism, iteratively generate the temporal relationship probability distribution, and dynamically update the entity prediction results according to the temporal relationship probability distribution to obtain the query target result; S5. Construct a composite loss function optimization model to optimize the query target results, and based on the relationship path of the query target results, analyze the temporal logic rules in the prediction process and calculate the confidence of the rules.

2. According to claim 1, a temporal knowledge graph reasoning method based on temporal rule guidance is characterized in that: The step S1 comprises the following steps: S101. Based on the temporal knowledge graph, extract a set of neighbor nodes directly associated with the query target header entity and time, where the timestamp of the neighbor nodes is no later than the query time; S102. Based on the obtained neighbor node set, further associated nodes are obtained layer by layer through a recursive expansion method to obtain a subgraph containing a multi-hop path, in which all involved entities, relationships and timestamp information are retained.

3. According to claim 1, a temporal knowledge graph reasoning method based on temporal rule guidance is characterized in that: Step S2 includes the following steps: S201. Given a temporal knowledge graph, it can be expressed as: G={V,R,T,F} Among them, V is the entity set, R is the relationship set, T is the timestamp set, and F is the fact set; S202. Use standard normal distribution to randomly initialize the embedding, initialize the embedding of each entity in the entity set, and initialize the embedding of each relationship in the relationship set; S203. Combining the time interval and periodicity features with time embedding, the model can be expressed as: Among them, w i is the learnable time-frequency parameter, θ i is the phase shift, i is a learnable parameter, n is the total number of elements in the set, d is the dimension of time embedding, is the time encoding vector, t q is the current query time information, t j is the time point in the historical subgraph.

4. According to claim 1, a temporal knowledge graph reasoning method based on temporal rule guidance is characterized in that: The enhanced entity representation is represented by enhancing the entity embedding representation through the domain and scope embedding of the relationship. The enhanced entity embedding representation is: Among them, X ei To initialize entity embedding, Y ei To enhance entity embedding representation, For the field of relationship, is the scope embedding of the relation, is the normalized domain distribution of the ith relationship type, is the normalized range distribution of the i-th relationship type.

5. According to claim 4, a temporal knowledge graph reasoning method based on temporal rule guidance is characterized in that: The normalized domain distribution of the i-th relationship type and the normalized range distribution of the i-th relationship type can be expressed as: in, is the number of the i-th relationship connected to the entity, is the number of the i-th relationship connected to the self-entity, R is the number of relationship types, and j is the index of the relationship type.

6. According to claim 1, a temporal knowledge graph reasoning method based on temporal rule guidance is characterized in that: Step S3 includes the following steps: S301. The enhanced entity embedding representation is integrated with the time encoding and the centrality encoding to obtain the time entity encoding, which can be expressed as: Among them, h ei Encodes the time entity, X ti For time embedding, is the out-degree encoding representation of entity ei, is the in-degree encoding representation of the entity; S302. Input the obtained temporal entity code into the temporal graph encoder, calculate the importance of the neighbor node to the target node through the attention mechanism, and obtain the attention score, which can be expressed as: Among them, A ij is the attention score, R is the number of relationship types, k r Is there a relationship r between entity ei and entity ej? If so, then k r is 1, otherwise it is 0, X r is the encoding of relation r, T is the transpose operation of the matrix, W Q , W K are the query matrix and key matrix of the entity respectively, W Kr is the key matrix of the relation, and dk is the dimension of the matrix. S303. Based on the spatial coding, edge coding and temporal attention value, a correlation representation function is constructed according to the attention score, and a comprehensive attention score is calculated. The calculation formula can be expressed as: t ij =|t i -t j | Among them, α ij is the comprehensive attention score, is the spatial encoding, c ij is the edge encoding, t ij is the temporal attention value, x rn is the shortest path SP ij The characteristics of the nth edge r, is the weight embedding of the nth edge, λ is the parameter that controls the degree of attenuation of temporal attention due to the time interval; S304. Update the enhanced entity embedding representation according to the calculated comprehensive attention score, and output the updated entity sequence to the temporal decoder. The update formula can be expressed as: Among them, z i is the updated embedding representation of entity ei, W V is the value matrix of the entity, W Vr is the value matrix of the relationship.

7. According to claim 1, a temporal knowledge graph reasoning method based on temporal rule guidance is characterized in that: Step S4 includes the following steps: S401. Combine the initial embedding of the relationship and time information to obtain a temporal relationship sequence, which can be expressed as: in, is the initial time relationship sequence, [.;.] is the vector concatenation operation, x r is the initial embedding of the relation, x t For the initial embedding of time; S402. Calculate the correlation score between the temporal relationship sequence and the entity sequence through the cross attention mechanism, and its calculation formula can be expressed as: K=S e W K V=S e W V Among them, S e is a sequence of entities, is the temporal relation sequence, K is the key of the entity sequence embedding, K T is the transpose of the key K embedded in the entity sequence, Q is the query vector of the temporal relationship sequence, and V is the value vector embedded in the entity sequence; S403. According to the correlation score calculated in S402, a nonlinear transformation is performed through a multi-layer perceptron to obtain a probability distribution of the time relationship, and its calculation formula can be expressed as: Among them, W l+1 is the probability distribution of the next time relationship, MLP is a multi-layer linear perceptron, is the relation sequence of step l, is the time relationship sequence of step l, is the relationship selected in step l+1, is the time selected for the l+1th step. After executing l steps, a rule body with a maximum length of L is obtained. S404. Update the entity probability vector according to the time relationship probability distribution. The update formula can be expressed as: Among them, Z l is the probability distribution of all entities in step l, is the relationship probability of the lth step, is the time probability of step l, For the relationship R k The adjacency matrix of is time t k When l = 0, the entity probability vector Z0 is a one-hot vector, which is used to mark the head entity in the query target. The function is continuously updated and iterated until the function converges to obtain the query target result.

8. According to claim 1, a temporal knowledge graph reasoning method based on temporal rule guidance is characterized in that: The composite loss function optimization model in step S5 can be expressed as: Among them, β is the time difference weight, o is the tail entity in the quadruple, s is the head entity in the quadruple, p is the relationship entity in the quadruple, γ is the scoring function threshold, t L is the predicted time information, and t is the time information in the quadruple.

9. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of a temporal knowledge graph reasoning method based on temporal rule guidance as described in any one of claims 1 to 8 are implemented.

10. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of a temporal knowledge graph reasoning method based on temporal rule guidance as described in any one of claims 1 to 8 are implemented.

Citation Information

Cited By

  • Agricultural pest diagnosis and prevention method and device, electronic equipment and storage medium

    CN121640072A

  • Ground surface change prediction method based on space-time rule guided knowledge graph reasoning and application thereof

    CN121745320A