Temporal feature knowledge graph logic query answering method, medium and equipment
By dynamically adjusting the weights of the logical system and constructing an MLP in the temporal feature knowledge graph, the problem that fixed logical strategies cannot adapt to differences in semantic relevance is solved, improving the accuracy and generalization ability of logical queries, especially when dealing with heterogeneous logical structures.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHINA UNIV OF GEOSCIENCES (WUHAN)
- Filing Date
- 2025-12-30
- Publication Date
- 2026-05-05
AI Technical Summary
In existing temporal feature knowledge graph logical query methods, fixed logical strategies cannot adapt to the differences in semantic relevance between different branch pairs, resulting in limited logical query reasoning accuracy, especially when dealing with heterogeneous logical structures, where the generalization ability is insufficient.
By employing a post-order traversal based on a query computation tree, the semantic similarity of the relational feature vectors of the branch pairs is calculated, the weights of the logic system are dynamically adjusted, and a gating mechanism is combined to generate hybrid weights. This constructs a multilayer perceptron (MLP) to automatically learn the complex relationships between branch pairs, thereby achieving differentiated reasoning in the logic system.
It significantly improves the accuracy of logical query responses, especially when dealing with data with strong semantic heterogeneity, and enhances the model's generalization ability and inference accuracy.
Smart Images

Figure CN121979979A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of temporal feature knowledge graph technology, and in particular to a method, medium, and device for logical query and answering of temporal feature knowledge graph. Background Technology
[0002] Traditional knowledge graphs represent knowledge in the form of static triples, which cannot effectively depict the dynamic nature of facts. Temporal feature knowledge graphs, by introducing a time dimension and using (head entity, relation, tail entity, time) quadruples, enable the accurate representation of time-sensitive knowledge such as user behavior sequences and employee career development trajectories. While this expansion enriches knowledge service capabilities, it also brings greater technical challenges.
[0003] In practical applications of temporal feature knowledge graphs, users often have differentiated and complex query needs, requiring queries involving multi-hop reasoning and logical operations. For example, on e-commerce platforms, it might be necessary to find "high-value users who have recently browsed smart home products and have a long-term interest in health and wellness categories"; in human resource management scenarios, it might be necessary to find "current employees with cloud computing project experience who have completed digital transformation training in the past two years." These queries not only involve time constraints but also logical connection operations, posing a significant challenge to existing methods. The approach to solving this temporal logical query answering task typically involves query embedding models.
[0004] Temporal logical query answering is one of the cutting-edge tasks in temporal feature knowledge graphs, aiming to handle combined queries involving multi-hop reasoning and logical predicates (conjunction, disjunction, negation). Current temporal feature knowledge graph logical query answering methods face a key problem: in handling logical connections, to aggregate feature information from multiple logical query paths, existing methods typically use a single logical system (such as Gödel, Product, or...) (ukasiewicz), however, this fixed strategy cannot adapt to the differences in semantic relevance between different branch pairs. For example, in a human resource management scenario, "an employee's Python skills - an employee's participation in machine learning projects" is a highly relevant branch because the two are semantically closely related; possessing Python skills greatly increases the likelihood of participating in machine learning projects. On the other hand, "an employee's department - an employee's first aid certificate" has no strong correlation; holding a first aid certificate is more of a personal choice. If a more inclusive Gödel logic is used to process the low-relevance branch for these two types of branches with significant differences in relevance, excessive inclusion will introduce a large number of noisy answers; if a strict filtering method is used... When ukasiewicz logic processes highly relevant branches, it may lose potential positive examples due to excessive suppression. Even with a compromise product logic, its fixed probability multiplication assumption makes it difficult to maintain optimal performance in differentiated semantic scenarios. This contradiction between the fixed strategy and semantic relevance limits the inference accuracy of logical queries, resulting in limited generalization ability when dealing with heterogeneous logical structures. Summary of the Invention
[0005] The purpose of this invention is to address the problem that fixed logic strategies in traditional methods limit the accuracy of logical query reasoning, and to propose a temporal feature knowledge graph logical query answering method, comprising the following steps: S1. Based on the post-order traversal of the query computation tree, with fixed entity embeddings as input, when the projection operator is encountered, a single-hop projection operation is performed on the query based on time and relational features to convert the entity embedding or query embedding into the next-hop query embedding. When encountering the negation operator, perform complementation. When encountering intersection or union logical operations, take the following steps: (1) Obtain the logical query delimiter pairs for intersection or union logical operations, and extract the input of the delimiter pair logical operations: query embedding and and the relational feature vectors of the branch pairs and ; (2) Based on relational feature vectors and Calculate the semantic similarity of relation feature vectors And map semantic similarity to , , Initial weights of the three logic systems ; Embed the query and relational feature vectors and After concatenation, input into MLP for calculation. , , Dynamic weights of three logic systems ; (3) Based on initial weights and dynamic weights Generate using gating mechanism , , Mixed weights of three logic systems ; (4) Combining mixed weights and , , Three logical systems are used to output logical strategies and obtain query embedding output; S2. Calculate the query score based on the query embedding and the entity embedding to obtain the query answer set.
[0006] Furthermore, based on query embedding or Extracting the relational feature vector of the path pair from the three types of the previous hop and The method is as follows: (1) The logic of the previous hop is projection, which directly obtains the feature vector of the previous hop relationship; (2) If the logic of the previous hop is negative, obtain the relational feature vector of the projection of the negative previous hop; (3) The logic of the previous jump is the intersection. The result of the relationship feature vector of the path pair of the intersection is obtained according to type (1) and (2) and then averaged.
[0007] Furthermore, semantic similarity The calculation formula is: .
[0008] Furthermore, semantic similarity is mapped to , , Initial weights of the three logic systems Specifically: , in, , They represent , , The initial weights of the three logic systems, where T is the temperature parameter controlling the width of the transition interval. ( ) represents the Sigmoid function.
[0009] Furthermore, dynamic weights The calculation formula is as follows: , , , in, and The weights and bias parameters for the first layer, and The weights and bias parameters of the output layer. , They are Gödel, Product, The dynamic weights of the three logic systems of ukasiewicz This represents the hidden layer feature vector of an MLP. This represents the input feature vector of the MLP.
[0010] Furthermore, mixed weights The calculation formula is as follows: , , , in, , They are , , The weights of the three logic systems are mixed, where g is the gating vector, ⊙ represents element-wise multiplication, and σ represents the sigmoid function. and These are the weights and biases of the gating mechanism. , They represent , , The initial weights of the three logic systems , They are , , Dynamic weights of the three logical systems.
[0011] Furthermore, the Gödel logic operator is improved in the following way: , , in, Let represent the intersection of nodes a and b in Gödel logic, and τ represent the temperature coefficient. This represents the union of nodes a and b in Gödel logic.
[0012] Furthermore, improvements can be made in the following ways. ukasiewicz logical operators: , , , in, express In the ukasiewicz logic, the intersection of nodes a and b is given by k=1+γ, where γ represents the leakage factor and λ is a learnable threshold. express The union of nodes a and b under the ukasiewicz logic, when the input of the logical query branch to the previous hop of the branch is negative, will be... Replace with .
[0013] The present invention also proposes a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described temporal feature knowledge graph logical query and answer method.
[0014] The present invention also proposes an electronic device, including a processor and a memory, wherein the processor and the memory are interconnected, wherein the memory is used to store a computer program, the computer program including computer-readable instructions, and the processor is configured to invoke the computer-readable instructions to execute the above-described temporal feature knowledge graph logical query and answer method.
[0015] The beneficial effects of the technical solution provided by this invention are: This invention first calculates the cosine similarity of the delimited pair relation representation as an artificial prior, mapping the explicit semantic relevance to the initial weight bias of three logical systems, and then considering the prior assignment function and Gödel... To address the threshold abruptness and gradient blocking issues caused by piecewise functions in the ukasiewicz logical operator, a differentiable logical fusion mechanism is proposed. This mechanism achieves smooth weight transitions through a sigmoid function and introduces a temperature coefficient and leakage factor to continuously differentiablely approximate the traditional logical operator, ensuring end-to-end model training. Secondly, a multilayer perceptron (MLP) is constructed, using the query embedding and relation representation of the previous hop as input to automatically learn complex implicit associations between branch pairs and generate data-driven logical system weights. Finally, a hybrid weight structure for different logical systems is constructed based on the initial and dynamic weights to achieve differentiated inference for highly relevant and low-relevance branch pairs. This method significantly improves the accuracy of logical query responses, especially when dealing with semantically heterogeneous data. Attached Figure Description
[0016] Figure 1 This is a flowchart of the temporal feature knowledge graph logical query and answer method according to an embodiment of the present invention; Figure 2 This is a schematic diagram of the query computation tree corresponding to the 14 query structures of temporal logical query responses; Figure 3 This is an example diagram showing three types of the previous hop in the logical query routing of this invention. Figure 4 This is an example diagram of logical query routing pairs in an embodiment of the present invention; Figure 5This is a block diagram of an electronic device according to an exemplary embodiment of the present invention. Detailed Implementation
[0017] To make the objectives, technical solutions, and advantages of the present invention clearer, the embodiments of the present invention will be further described below with reference to the accompanying drawings.
[0018] The flowchart of the temporal feature knowledge graph logical query and answer method of this invention is as follows: Figure 1 Specifically, it includes the following steps: S1. Based on the post-order traversal of the query computation tree, with fixed entity embeddings as input, when the projection operator is encountered, a single-hop projection operation is performed on the query based on time and relational features to convert the entity embedding or query embedding into the next-hop query embedding.
[0019] A query computation tree is a tree-like data structure transformed during query execution to describe the query's "intent" and logical relationships, regardless of the specific data access methods. It includes leaf nodes (representing base tables in the database) and a root node (representing the final operation of the entire query, whose output is the query result). Common relational algebra operators include selection, projection, join, union, intersection, difference, and negation. A schematic diagram of the query computation trees corresponding to the 14 query structures for temporal logical query responses is provided below. Figure 2 Leaf nodes represent definite entity embedding inputs, root nodes represent the final query embedding outputs, a single solid arrow represents projection (p), a single red arrow represents negation (n), multiple intersecting solid arrows represent intersection (i) operations, and two intersecting red arrows represent union (u) operations.
[0020] The query structure may contain projection (p), intersection (i), union (u), and negation (n). Intersection (i) may be a ternary or binary logical connector. A ternary operator can be converted into two consecutive binary operations, with the intersection of the two binary operations and the ternary operator. Union (u) is a binary logical connector. The input consists of two query embeddings. Negation (n) is unary, regardless of whether it is in the input or output. , , In which of the three logical systems is negation a simple complement operation (1- )
[0021] Gödel, Product The formulas for the intersection (i) and union (u) of the logical operators of the three logic systems of ukasiewicz are shown in Table 1.
[0022] Table 1
[0023] in, and They represent queries respectively. and The embedding of these logical operators and their mathematical characteristics: Gödel logic exhibits extreme inclusiveness or strictness through min / max operations; Product logic's multiplicative operations have a probabilistic interpretation and behave relatively mildly. The ukasiewicz logic achieves clear boundary filtering through linear thresholds.
[0024] To ensure end-to-end trainability, this invention makes differentiable improvements to traditional logic operations.
[0025] (1) Improved Gödel logic operator Differentiable approximation of the min operation is achieved by introducing a temperature coefficient τ: , , in, Let represent the intersection of nodes a and b in Gödel logic, and τ represent the temperature coefficient. This represents the union of nodes a and b under Gödel logic. The temperature coefficient τ is dynamically adjusted during training, with an initial value of 1.0 and eventually converged to 0.1, achieving a gradual transition from smooth approximation to precise computation.
[0026] (2) Improvement ukasiewicz logical operators The fixed threshold 1 is replaced with a learnable parameter λ, which adaptively matches the statistical properties of the current embedding distribution. A leakage factor γ is added to mitigate the vanishing gradient problem. , , , in, express The intersection of nodes a and b under the ukasiewicz logic, k=1+γ, where γ represents the leakage factor, initialized to 0.3, and... The decay (t is the number of training epochs) and λ are learnable thresholds that can adaptively match the statistical properties of the current embedding distribution. express In the ukasiewicz logic, the union of nodes a and b, when the input of the previous hop in a query structure branch of this intersection or union is n (negation), the upper bound expectation of its data is also adjusted and complemented. Replace with .
[0027] The formula for a single-hop lookup is as follows: , in, This represents the input vector, when the query input is an anchor entity. Embedding for entities When the query input is the query vector of the previous hop, Output of the query from the previous hop ; It is a relational projection operator and a time projection operator. It is a time projection operator.
[0028] When encountering the negation operator, perform complementation. When encountering intersection or union logical operations, take the following steps: Step 1: Obtain the logical query decoupling pairs for intersection and union logical operations. Extract the query embedding of the delimiter before performing logical operations. and and query embedding and The previous hop relation feature vector and Determine the feature type of the current logical connector. The previous hop of the two input branch queries of a logical connector has three types. The query embedding of the logical query branch... and Examples of the three types of the previous jump Figure 3 According to their types, obtain the relation feature vectors respectively: (1) The logic of the previous hop is projection (p), directly obtain the relation feature vector of the previous hop; (2) The logic of the previous hop is negation (n), negation itself has no features, obtain the relation feature vector of the projection (p) of the previous hop of negation (data stipulates that the previous hop of negation must be projection); (3) The logic of the previous hop is intersection (i), according to type (1) and (2), obtain the result of the relation feature vector of the path of this intersection (i) and average it.
[0029] Below is an example of a logical query routing pair to help understand the routing pairs, query embedding, and relation embedding in this step. (See also...) Figure 4 The query is: Find out who was interviewed by Catherine on November 4, 2014, and made a statement in Iran on September 15, 2014, and who was interviewed on November 11, 2014. The two paths are "the person interviewed by Catherine on November 4, 2014" and "the person who made a statement in Iran on September 15, 2014". Their query embeddings reflect the query results of their respective paths, and are also the inputs to "AND (intersection(i))". The relational embeddings are the representations of "interview" and "make a statement" mentioned above, and their features and relevance affect how the model combines these two query embeddings.
[0030] Step 2: Based on relation feature vectors and Calculate the semantic similarity of relation feature vectors And map semantic similarity to , , Initial weights of the three logic systems .
[0031] semantic similarity The calculation formula is: , In one embodiment of the present invention, similarity is mapped to an initial weight distribution according to a predefined logical preference rule. The calculation formula is as follows: , in, They represent , , The initial weights of the three logic systems and It is a preset hyperparameter threshold.
[0032] Smoothing of the prior weight allocation function: The piecewise weight allocation function based on a fixed threshold is non-differentiable at the threshold point, leading to gradient vanishing and weight jumps. To overcome the problem of the piecewise function being non-differentiable at the threshold, a preferred embodiment of the present invention adopts a method based on the Sigmoid function (…). The smooth mapping of ) is given by the following formula: , Where T is a temperature parameter controlling the width of the transition interval, enabling a differentiable transformation from prior rules to data-driven weights. ( ) represents the Sigmoid function.
[0033] These prior weights ensure that the model has basic logical discrimination capabilities from the early stages of training.
[0034] Embed the query and Relational embedding and After concatenation, input into MLP for calculation. , , Dynamic weights of three logic systems .
[0035] Dynamic weights The calculation formula is as follows: , , , in, and The weights and bias parameters for the first layer, and The weights and bias parameters of the output layer. They are , , Dynamic weights of the three logic systems And each weight is greater than 0. This represents a vector concatenation operation. This represents the hidden layer feature vector of an MLP. This represents the input feature vector of the MLP.
[0036] Step 3: Based on the initial weights and dynamic weights Generate using gating mechanism , , The mixed weight W of the three logic systems.
[0037] The formula for calculating the mixed weight w is as follows: , , , in, , They are Gödel, Product, The ukasiewicz uses a hybrid weighting of three logic systems, where g is the gating vector, ⊙ represents element-wise multiplication, and σ denotes the sigmoid function. and These are the weights and biases of the gating mechanism. , They represent , , The initial weights of the three logic systems , They are , , Dynamic weights of the three logical systems.
[0038] Step 4: Combine mixed weights and , , Three logical systems are used to process the query embedding results using their respective formulas (as shown in Table 1). These three results are then weighted and summed using the previously defined mixed weights. A logical strategy is then output, yielding the query embedding output of the logical operation.
[0039] S2. Calculate the query score based on the query embedding and the entity embeddings, and converge the results according to the loss function to obtain the query answer set.
[0040] Query score is used to measure the degree to which an entity e belongs to a set of query answers; query embedding. Represented as the confidence of each set in answering the query q, entity embedding It is represented as the probability of belonging to each set, therefore the score function φ(q,e)= .
[0041] During model training, various types of data are mixed together to improve generalization ability. A query structure includes input entity labels, operators (for projection operators, the time and relation labels of this hop need to be specified), tree structure order, and other information. For the same query q, k negative samples are generated, and the objective is to maximize the scores of the sampled query and answer entities while minimizing the scores of the negative sample entities. , Where L represents the loss function, It is a query The core function of the relevant normalization factor is to balance the differences in score scales between different queries, making model training more stable and effective. Let q represent the score function for query q and entity e, and k represent the number of negative samples. It is a hyperparameter that represents a fixed margin that allows for an appropriate difference in scores between positive and negative examples. This indicates a query for q and the entity. The scoring function, This represents the i-th negative sample answer entity for query q.
[0042] To verify the effectiveness of the method of the present invention, under the same benchmark model TFQE, its logical operation methods were respectively fixed with Product and Gödel (traditional). (ukasiewicz, when the vector dimension is high, the intersection value is always 0, which is not conducive to propagation, so it is not compared). This invention also includes the adaptive allocation mechanism proposed in this paper. The dataset uses the single-hop full set of GDELT and 13 other datasets sampled from single-hop data. The evaluation metrics are: Mean Reciprocal Rank (MRR) and Hit@10, both reflecting query accuracy; higher is better.
[0043] , Where S is the set of triples, |S| is the number of triple sets, and rank is... i This refers to the predicted link ranking of the i-th triple. A higher value for this metric is better.
[0044] , Where II is the indicator function (the function value is 1 if the condition is true, otherwise it is 0). The larger this indicator is, the better.
[0045] Conclusion: The method of this invention has a significant improvement on 11 query structures that include logical operators, with an average improvement of 11% relative to product, and a slightly acceptable loss on the three types that do not include logical operators (1p / 2p / 3p).
[0046] Table 2
[0047] In one exemplary embodiment, a computer-readable storage medium is included, which stores a computer program that, when executed by a processor, implements the above-described temporal feature knowledge graph logical query and answering method.
[0048] Please see Figure 5 In one exemplary embodiment, the device further includes an electronic device including at least one processor, at least one memory, and at least one communication bus.
[0049] The memory stores a computer program, which includes computer-readable instructions. The processor calls the computer-readable instructions stored in the memory through the communication bus to execute the aforementioned temporal feature knowledge graph logical query and answer method.
[0050] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A temporal feature knowledge graph logical query and answering method, characterized in that, Includes the following steps: S1. Based on the post-order traversal of the query computation tree, with fixed entity embeddings as input, when the projection operator is encountered, a single-hop projection operation is performed on the query based on time and relational features to convert the entity embedding or query embedding into the next-hop query embedding. When encountering the negation operator, perform complementation. When encountering intersection or union logical operations, take the following steps: (1) Obtain the logical query delimiter pairs for intersection or union logical operations, and extract the input of the delimiter pair logical operations: query embedding and and the relational feature vectors of the branch pairs and ; (2) Based on relational feature vectors and Calculate the semantic similarity of relation feature vectors And map semantic similarity to Gödel, Product, Initial weights of three logic systems (ukasiewicz) ; Embed the query and relational feature vectors and After concatenation, input into MLP for calculation. , , Dynamic weights of three logic systems ; (3) Based on initial weights and dynamic weights Generate using gating mechanism , , Mixed weights of three logic systems ; (4) Combining mixed weights and , , Three logical systems are used to output logical strategies and obtain query embedding output; S2. Calculate the query score based on the query embedding and the entity embedding to obtain the query answer set.
2. The temporal feature knowledge graph logical query and answering method according to claim 1, characterized in that, Based on query embedding or Extracting the relational feature vector of the path pair from the three types of the previous hop and The method is as follows: (1) The logic of the previous hop is projection, which directly obtains the feature vector of the previous hop relationship; (2) If the logic of the previous hop is negative, obtain the relational feature vector of the projection of the negative previous hop; (3) The logic of the previous jump is the intersection. The result of the relationship feature vector of the path pair of the intersection is obtained according to type (1) and (2) and then averaged.
3. The temporal feature knowledge graph logical query and answering method according to claim 1, characterized in that, semantic similarity The calculation formula is: 。 4. The temporal feature knowledge graph logical query and answering method according to claim 1, characterized in that, Map semantic similarity to , , Initial weights of the three logic systems Specifically: , in, , They represent , , The initial weights of the three logic systems, where T is the temperature parameter controlling the width of the transition interval. ( ) represents the Sigmoid function.
5. The temporal feature knowledge graph logical query and answering method according to claim 1, characterized in that, Dynamic weights The calculation formula is as follows: , , , in, and The weights and bias parameters for the first layer, and The weights and bias parameters of the output layer. , They are , , Dynamic weights of the three logic systems This represents the hidden layer feature vector of an MLP. This represents the input feature vector of the MLP.
6. The temporal feature knowledge graph logical query and answering method according to claim 1, characterized in that, Mixed weights The calculation formula is as follows: , , , in, , They are , , The weights of the three logic systems are mixed, where g is the gating vector, ⊙ represents element-wise multiplication, and σ represents the sigmoid function. and These are the weights and biases of the gating mechanism. , They represent , , The initial weights of the three logic systems , They are , , Dynamic weights of the three logical systems.
7. The temporal feature knowledge graph logical query and answering method according to claim 1, characterized in that, The Gödel logic operator can be improved in the following ways: , , in, Let represent the intersection of nodes a and b in Gödel logic, and τ represent the temperature coefficient. This represents the union of nodes a and b in Gödel logic.
8. The temporal feature knowledge graph logical query and answering method according to claim 1, characterized in that, Improve in the following ways ukasiewicz logical operators: , , , in, express In the ukasiewicz logic, the intersection of nodes a and b is given by k=1+γ, where γ represents the leakage factor and λ is a learnable threshold. express The union of nodes a and b under the ukasiewicz logic, when the input of the logical query branch to the previous hop of the branch is negative, will be... Replace with .
9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, it implements the method as described in any one of claims 1-8.
10. An electronic device, characterized in that, The device includes a processor and a memory interconnected thereto, wherein the memory is used to store a computer program, the computer program including computer-readable instructions, and the processor is configured to invoke the computer-readable instructions to perform the method as described in any one of claims 1-8.