Semantic-enhanced time sequence knowledge graph reasoning method, device and equipment
Through the semantic-enhanced temporal knowledge graph reasoning method, using the graph structure represented by quadruples and triples, combined with embedding learning and random walk algorithms, the problem of inaccurate event prediction in the case of sparse data sets is solved, and network security is improved. Analytical accuracy and interpretability.
Patent Information
- Application Number
- CN202410953435.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-16
- Publication Date
- 2024-10-01
AI Technical Summary
Existing rule-based network security analysis models are difficult to accurately reflect the potential characteristics of events when the data set is sparse, resulting in inaccurate event prediction.
The semantic-enhanced temporal knowledge graph reasoning method is adopted to construct a temporal knowledge graph represented by quadruples and a heterogeneous relationship graph represented by triples, combined with embedding learning and random walk algorithms, to calculate semantic similarity and confidence, and output the best Excellent reasoning results.
It improves the accuracy of event prediction and the credibility of inference results when the data set is sparse, and enhances the interpretability and efficiency of the model.
Smart Images

Figure CN118734951A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a semantically enhanced temporal knowledge graph reasoning method, device and equipment. Background Art
[0002] The interpretability and security of artificial intelligence are closely related, and are also crucial for people to understand and trust artificial intelligence. In the field of network security, when an open source intelligence analysis indicates that a company or organization may launch a network attack, the security team needs to understand the basis and reasoning process of this analysis result, including the attack path, attack means, attack purpose, etc., in order to take corresponding defense measures and response strategies. However, in general, interpretability and model capabilities are inversely proportional. Therefore, exploring models that have both accuracy and interpretability is a challenging task. The reasoning model based on logical rules has good interpretability, mainly including steps such as rule extraction, rule learning, and rule application. However, the existing rule-based methods are easily affected by the data set. When the data set is biased or the data set is relatively sparse, it may cause the rule statistical score to fail to fully reflect the potential characteristics of the data, thereby failing to obtain accurate event predictions. Summary of the invention
[0003] Based on this, it is necessary to provide a semantically enhanced temporal knowledge graph reasoning method, device and equipment to address the above technical problems, which can improve the accuracy of event prediction when the data set is sparse.
[0004] A semantically enhanced temporal knowledge graph reasoning method, the method comprising:
[0005] Build a time series knowledge graph based on historical events. The time series knowledge graph is represented by a quadruple. The quadruple includes: head entity, relationship, tail entity, and timestamp.
[0006] According to the relative position relationship of entities in the time series knowledge graph, a heterogeneous relationship graph is constructed. The heterogeneous relationship graph is represented by triples. The triples include: head relationship entity, relative position pattern and tail relationship entity.
[0007] The relations in the heterogeneous relation graph are embedded to obtain the heterogeneous relation embedding representation.
[0008] According to the preset rule head, a random walk is performed in the time series knowledge graph to obtain the rule body, wherein both the rule head and the rule body are represented by a quadruple, and the timestamp of the rule head and the timestamp set of the rule body meet the preset time series order constraint.
[0009] According to the embedding representation of the heterogeneous relations and the embedding representation of the timestamp set, a first embedding representation of the rule body and a second embedding representation of the rule head are obtained.
[0010] Calculate semantic similarity based on the first embedding representation and the second embedding representation.
[0011] The confidence is obtained based on the number of rule supports that satisfy the temporal order constraints obtained by random walk and the number of rule body supports obtained by all traversals.
[0012] According to the semantic similarity and confidence, the optimal temporal knowledge graph reasoning result is output.
[0013] A semantically enhanced temporal knowledge graph reasoning device, the device comprising:
[0014] The time series knowledge graph construction module is used to construct a time series knowledge graph based on historical events. The time series knowledge graph is represented by a quadruple. The quadruple includes: head entity, relationship, tail entity, and timestamp.
[0015] The heterogeneous relationship graph construction module is used to construct a heterogeneous relationship graph based on the relative position relationship of entities in the time series knowledge graph. The heterogeneous relationship graph is represented by triples. The triples include: head relationship entity, relative position pattern and tail relationship entity.
[0016] The heterogeneous relationship embedding representation acquisition module is used to embed the relationships in the heterogeneous relationship graph to obtain the heterogeneous relationship embedding representation.
[0017] The rule body acquisition module is used to perform random walks in the temporal knowledge graph according to the preset rule head to obtain the rule body, wherein the rule head and the rule body are both represented by the four-tuple, and the timestamp of the rule head and the timestamp set of the rule body meet the preset temporal order constraint.
[0018] The splicing module is used to obtain a first embedded representation of the rule body and a second embedded representation of the rule head according to the embedded representation of the heterogeneous relationship and the embedded representation of the timestamp set.
[0019] The semantic similarity calculation module is used to calculate the semantic similarity according to the first embedding representation and the second embedding representation.
[0020] The confidence acquisition module is used to obtain the confidence according to the rule support number that satisfies the temporal order constraint obtained by random walk and the rule body support number of all traversal results.
[0021] The reasoning module is used to output the optimal temporal knowledge graph reasoning results based on semantic similarity and confidence.
[0022] 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:
[0023] Build a time series knowledge graph based on historical events. The time series knowledge graph is represented by a quadruple. The quadruple includes: head entity, relationship, tail entity, and timestamp.
[0024] According to the relative position relationship of entities in the time series knowledge graph, a heterogeneous relationship graph is constructed. The heterogeneous relationship graph is represented by triples. The triples include: head relationship entity, relative position pattern and tail relationship entity;
[0025] The relations in the heterogeneous relation graph are embedded to obtain the heterogeneous relation embedding representation.
[0026] According to the preset rule head, a random walk is performed in the time series knowledge graph to obtain the rule body, wherein both the rule head and the rule body are represented by a quadruple, and the timestamp of the rule head and the timestamp set of the rule body meet the preset time series order constraint.
[0027] According to the embedding representation of the heterogeneous relations and the embedding representation of the timestamp set, a first embedding representation of the rule body and a second embedding representation of the rule head are obtained.
[0028] Calculate semantic similarity based on the first embedding representation and the second embedding representation.
[0029] The confidence is obtained based on the number of rule supports that satisfy the temporal order constraints obtained by random walk and the number of rule body supports obtained by all traversals.
[0030] According to the semantic similarity and confidence, the optimal temporal knowledge graph reasoning result is output.
[0031] The above-mentioned semantically enhanced temporal knowledge graph reasoning method, device and equipment collects historical fact data to construct a knowledge graph in time order, so that the time order and association between fact data can be clearly displayed. The temporal knowledge graph records the evolution of the relationship between entities through a quadruple (head entity, relationship, tail entity, timestamp) to ensure accurate reflection of the time order. It can accurately record and express the complex time relationship between entities, improving the accuracy and completeness of knowledge. After the construction is completed, the heterogeneous relationship graph is constructed using the relative position relationship of the entities, and the triple is used to represent: head relationship entity, relative position pattern and tail relationship entity, so that the data can more comprehensively describe the information of the diversified relationship between entities, enriching the complexity of data expression and the diversity of semantics. Subsequently, the heterogeneous relationship is embedded into a low-dimensional space by using the embedding learning technology, which increases the semantic information of the relative position pattern in the relationship, and further enriches and expands the information in the temporal knowledge graph for subsequent semantic similarity calculation and reasoning. The random walk algorithm extracts the four-tuple that meets the rules from the temporal knowledge graph based on the preset temporal order constraints. Through the embedded representation of the rule body and the rule head, their distance or similarity in the embedded space is calculated to evaluate the semantic similarity between the rules. In addition, the confidence is calculated using the rule support number and the global support number obtained by random walk to reflect the reliability and confidence level of the reasoning results. In the reasoning process, through the embedded representation of the rules and the calculation of semantic similarity, the correlation and relevance between different rules can be accurately evaluated and compared, which improves the accuracy and efficiency of reasoning. The confidence evaluation mechanism effectively filters out the reasoning results with high confidence, enhancing the credibility and interpretability of the reasoning results. In the case of sparse data sets, the statistical accuracy of data features is improved, as well as the authenticity of predicted events. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 A flowchart of a semantically enhanced temporal knowledge graph reasoning method in one embodiment;
[0033] Figure 2 A schematic diagram of path sampling based on random walk in one embodiment;
[0034] Figure 3 is a relationship map based on relative positions in one embodiment, wherein Figure 3 (a) is a schematic diagram of the knowledge graph. Figure 3 (b) is to extract relational patterns from KG. Figure 3 (c) is a schematic diagram of the relationship map;
[0035] Figure 4 A schematic diagram of an RNN encoding framework in one embodiment;
[0036] Figure 5is a flowchart of semantically driven rule learning steps in one embodiment;
[0037] Figure 6 It is a structural block diagram of a semantically enhanced temporal knowledge graph reasoning device in one embodiment;
[0038] Figure 7 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0039] 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.
[0040] In one embodiment, Figure 1 As shown, a semantically enhanced temporal knowledge graph reasoning method is provided, including the following steps:
[0041] Step 102, construct a time series knowledge graph based on historical events.
[0042] The temporal knowledge graph is represented by a quadruple, which includes a head entity, a relationship, a tail entity, and a timestamp.
[0043] In traditional knowledge graphs, nodes are entities and edges are relationships, so triples are represented by nodes and edges. In this step, in the knowledge graph of heterogeneous information networks, the types of nodes include: entity nodes, relationship nodes, entity description information nodes, and entity type information nodes.
[0044] Specifically, obtain historical fact data Historical fact data is sampled in the form of text. Fact data can be input through computer peripherals or transmitted over a period of time during the interaction of the Internet of Things. Specific content includes but is not limited to text description data involving past relationships of key figures involved in litigation cases, or technical data between industry competitors in the past time period. Whether it is text description data or technical data, it can be web page text data obtained from the Internet or text extracted from a dedicated text library. Text is a natural language data. When the computer processes the text, the text can be input in the form of structured data, unstructured data, etc. Structured data can be forms, such as: Word, Excel, TXT format forms, which will not be elaborated here. The open world knowledge graph is dynamically changing, so it is always facing the update of triples in the knowledge graph, such as adding, deleting, and modifying entities or relationships.
[0045] Furthermore, ε represents the entity set, R represents the relationship set, Τ represents the timestamp set, and each time series historical fact is represented by a four-tuple (e s ,r,e o ,t) represents, where r∈R represents the head entity e s ∈ε and tail entity e o There is a certain relationship between ∈ε. O={(e s ,r,e o ,t)|t∈[t 0 ,T]} represents observable historical facts, [t 0 ,T] represents the accessible time interval, and then the unknown tail entity is inferred based on the three elements of the known head entity, relationship and the time when the event occurs.
[0046] Step 104, construct a heterogeneous relationship graph based on the relative position relationship of the entities in the temporal knowledge graph.
[0047] In the heterogeneous relationship graph, relations are regarded as heterogeneous nodes, and relative position patterns are regarded as edges between heterogeneous nodes. The heterogeneous relationship graph is represented by triples, including: head relationship entity, relative position pattern and tail relationship entity.
[0048] Specifically, four relative position modes are defined: OS, SO, OO, and SS, such as Figure 3 As shown in (a), any two relations in the knowledge graph may have multiple combinations. In the knowledge graph, four types of patterns can be extracted, such as Figure 3 (b) shows that the connection relationship r 2 and the relationship 4 The entity Kojima, also acts as a triple (Subject, r 2 ,Object) and another triple (Subject, 4 ,Object), we name this relationship model OS, and correspondingly, there are three models SO, OO, and SS.
[0049] Furthermore, a heterogeneous relationship graph is defined based on these four patterns. Each relationship in the original time series knowledge graph is used as a node in the relationship graph. In this way, each edge connecting two nodes in the relationship graph corresponds to a relative position pattern. There may be multiple edges between two nodes, corresponding to multiple relative position patterns. Figure 3 As shown in (c), there may be multiple edges between two nodes, and there are different types of edges in the relationship graph.
[0050] Step 106, embedding the relations in the heterogeneous relation graph to obtain a heterogeneous relation embedding representation.
[0051] Specifically, construct two matrices E s and E o , and Among them, the former is composed of the head entity and the relationship, which is the head relationship entity matrix, and the latter is composed of the tail entity and the relationship, which is the tail relationship entity matrix. s Each element E in s [i,j] represents entity e in the triple i and the relationship j The frequency of simultaneous occurrence, i.e. (e i , r j,## ). Similarly, E o Each element E in o [i,j] represents entity e in the triple i As the tail entity and relation r j The frequency of simultaneous occurrence, i.e. ( ## , r j , e i ).
[0052] Furthermore, the weights of the edges between adjacent nodes are determined based on the intimacy of adjacent nodes in the heterogeneous relationship graph. The weight of each edge is determined by calculating the "intimacy" between nodes. The intimacy between relationships can be defined as how many entities are shared between them. Furthermore, the adjacency matrix of the heterogeneous relationship graph is constructed based on the relative position pattern corresponding to the weight of each edge in the heterogeneous relationship graph.
[0053] Furthermore, corresponding to the four types of edges OS, SO, OO, and SS mentioned above, construct their corresponding adjacency matrix A s-o ,A o-s ,A s-s and A o-o :
[0054]
[0055] An adjacency matrix contains the weights of one type of edge. For example, in A s-o A s-o [i,j] represents two relations r that satisfy the SO pattern i and r j The weight between .
[0056] Furthermore, the above four adjacency matrices are normalized:
[0057]
[0058] Among them, D O and D Sare the degree symmetric matrices of the tail entity and the head entity, respectively, D s [i,i]=Σ i E s [i,j],D o [i,i]=Σ i E o [i,j], The dimension is is the collection of entity matrices, |ε| is the number of entities in the temporal knowledge graph, is the number of relations in the temporal knowledge graph.
[0059] Furthermore, for the aforementioned heterogeneous relationship graph, graph convolution-related technologies are applied to aggregate node information in two layers. First, the neighbors of the same type of edges, that is, the same relative position pattern, are aggregated:
[0060]
[0061] in, For the relationship i In the first layer of layer l+1, the feature representation is embedded. For the relationship j In the l The first layer of the layer embedding feature representation, σ is the activation function, C is the set of four relative position patterns (OS, SO, OO, SS), p∈{so,os,ss,oo} is one of the relationship patterns, is the adjacency matrix A p Upper i The set of neighbors of p is the coefficient of mode p, is the edge weight matrix, is the attention weight.
[0062] Furthermore, edges with different relative position patterns are aggregated and the attention weights Use graph attention mechanism to obtain:
[0063]
[0064] Among them, || represents the splicing operation, is the weight matrix, is a row weight vector, and finally each relationship r i The heterogeneous relation embedding representation vector is r i .
[0065] Step 108: Perform a random walk in the temporal knowledge graph according to the preset rule head to obtain the rule body.
[0066] The rule header and the rule body are both represented by a quadruple, and the timestamp of the rule header and the timestamp set of the rule body satisfy a preset temporal order constraint.
[0067] Specifically, Figure 2 As shown in the figure, the path sampling based on random walk. First, select an edge (e 1 ,r h ,e L+1 ,t h ) as the rule head, and then e 1 As a starting point, randomly sample a path of length l and use p l Represents. Random walk simulates the process of randomly walking on the graph starting from the starting node. Random walk can use different sampling strategies such as uniform random and Metropolis-Hastings.
[0068] Furthermore, the sampled paths are compared with the predefined time logic rule standard Matching is performed to determine whether they can form a rule body of temporal logic rules. And a stricter constraint 2 is adopted, which imposes stricter requirements on the temporal order of events, ensuring that they are arranged in a coherent and logical order.
[0069] Constraint 1. (Basic constraint for extrapolation)
[0070] For a temporal logic rule, there is a basic constraint for extrapolation, with the time axis from left to right t 1 <t 2 <…<t L+1 , that is, the timestamps contained in it must satisfy: max{t i}≤t L+1 , where i = 1, 2, ..., L. The subject e in the rule header 1 and object e L+1 They serve as the starting point and end point of the chain rule body respectively, so the defined logical rule is actually cyclic.
[0071] Constraint 2. (Temporal order constraint)
[0072] For a temporal logic rule, the time order constraint requires that all timestamps involved in the rule body must be arranged in time order:
[0073] t h >t 1 ≥t 2 ≥…≥t L
[0074] Constraint 2 includes constraint 1, which is a restriction on the order of timestamps. A time series knowledge graph of known fact data is constructed based on the two time constraints.
[0075] Step 110: Obtain a first embedded representation of the rule body and a second embedded representation of the rule header according to the embedded representation of the heterogeneous relationship and the embedded representation of the timestamp set.
[0076] Specifically, temporal logic rules can describe the logical relationship between events, such as "A happens after B", etc. These rules are encoded into vector representations. First, the embedding representations of the rule head and the rule body are learned separately, and then the similarity between the rule head and the rule body is calculated to obtain the semantic score of the rule.
[0077] Furthermore, according to the preset temporal order constraints, the rules in the temporal knowledge graph are relatively encoded to obtain the embedded representation of the timestamp set:
[0078]
[0079] Among them, t i is the embedding representation of the timestamp set, is the periodic encoding of the timestamp set, is the aperiodic encoding of the timestamp set, Δt i is the relative time difference, ω p is the periodic frequency, ω np is a non-periodic frequency, is the periodic phase shift, is a non-periodic phase shift.
[0080] Furthermore, for each temporal link (e i ,r i ,e i+1 ,t i ) representation learning, embedding the relationship into r i The embedded representation of the timestamp set t i Splice to obtain the representation of this temporal link:
[0081] b i =W b [r i ||t i ]
[0082] Where || represents the vector concatenation operation, is a learnable parameter, d is the dimension of relation embedding and time embedding, is the embedding representation of the i-th temporal link in the rule body, i∈1,2,…,L.
[0083] Furthermore, if Figure 4 As shown, RNN is used as the encoding framework to obtain the first embedding representation of the rule body:
[0084]
[0085] Compute the embedded representation of the rule header:
[0086] Head=W h r h
[0087] Among them, r h The embedding representation of the relation in the rule head, W h is the transformation matrix, and Head is the second embedding representation of the rule head.
[0088] Step 112: Calculate semantic similarity based on the first embedding representation and the second embedding representation.
[0089] Specifically,
[0090] C sem =sim(Body,Head)
[0091] Among them, C sem is the semantic score, Body is the embedded representation of the rule body, Head is the embedded representation of the rule head, and sim() is the similarity function, which represents any similarity calculation method that the user can choose. The similarity score between the representation of the rule head and the rule body reflects the correspondence or compatibility between the rule head and the rule body. The similarity score represents the semantic score C of the rule. sem A high semantic score for a rule indicates a high degree of semantic matching between the rule head and the rule body, which means that there is a clear and direct logical connection between the premise and conclusion of the rule, making it easy for people to understand the intention and relationship expressed by the rule, as well as to track and understand how the system draws conclusions from the premises.
[0092] Step 114, the confidence level is obtained according to the number of rule supports satisfying the temporal order constraints obtained by random walk and the number of rule body supports obtained by all traversals.
[0093] Specifically, the rule support number is counted and represented by rule support. The rule support number refers to the number of records or tuples that meet all the conditions of the rule (including the rule header and rule body) in the entire data set (time series knowledge graph).
[0094] Furthermore, the rule body support is counted, and the rule body support is represented by body support. The rule body support refers to the number of records or tuples that meet the conditions of the rule body (excluding the rule header). It focuses on the degree of satisfaction of the prerequisites in the rule, without involving the conclusion part.
[0095] Furthermore, the confidence of the rule is calculated. The confidence is usually used to estimate the probability of the correctness of the rule. In this paper, the confidence of the rule is taken as the statistical score C of the rule. sta Confidence is the ratio of the rule body support number to the rule support number. It provides a quantitative indicator to evaluate the reliability of the rule conclusion under given premises. High confidence means that the rule head is very reliable when the rule body is established, while low confidence means that the establishment of the rule head does not always follow the establishment of the rule body:
[0096]
[0097] Step 116: output the optimal temporal knowledge graph reasoning result based on semantic similarity and confidence.
[0098] Specifically, a score is obtained according to the semantic similarity and the confidence;
[0099]
[0100] Among them, R represents a rule, a and b are weighted coefficients, tmin represents the earliest time in the rule body, t q To query the time of a temporal historical fact, when λ>0, the coefficients represented by a, b, and 1-ab determine the relative importance or contribution of the corresponding terms in the rule in the final weighted sum, and the applicability of the rule is considered through the last term.
[0101] In the above-mentioned semantically enhanced temporal knowledge graph reasoning method, a knowledge graph in time order is constructed by collecting historical fact data, so that the time order and association between fact data can be clearly displayed. The temporal knowledge graph records the evolution of the relationship between entities through four tuples (head entity, relationship, tail entity, timestamp) to ensure accurate reflection of the time order. It can accurately record and express the complex time relationship between entities, improving the accuracy and completeness of knowledge. After the construction is completed, the heterogeneous relationship graph is constructed using the relative position relationship of the entities, and the triples are used to represent: head relationship entity, relative position pattern and tail relationship entity, so that the data can more comprehensively describe the information of the diversified relationship between entities, enriching the complexity of data expression and the diversity of semantics. Subsequently, the heterogeneous relations are embedded into the low-dimensional space by using the embedding learning technology, which increases the semantic information of the relative position pattern in the relationship, and further enriches and expands the information in the temporal knowledge graph for subsequent semantic similarity calculation and reasoning. The random walk algorithm extracts the four tuples that meet the rules from the temporal knowledge graph based on the preset temporal order constraints. Through the embedded representation of the rule body and the rule head, their distance or similarity in the embedded space is calculated to evaluate the semantic similarity between the rules. In addition, the confidence is calculated using the rule support number and the global support number obtained by random walk to reflect the reliability and confidence level of the reasoning results. In the reasoning process, through the embedded representation of the rules and the calculation of semantic similarity, the correlation and relevance between different rules can be accurately evaluated and compared, which improves the accuracy and efficiency of reasoning. The confidence evaluation mechanism effectively filters out the reasoning results with high confidence, enhancing the credibility and interpretability of the reasoning results. In the case of sparse data sets, the statistical accuracy of data features is improved, as well as the authenticity of predicted events.
[0102] In one of the embodiments, the relative position patterns corresponding to the two relations are obtained according to the relative position relationship of the entities in the time series knowledge graph in the two corresponding relations. The relative position patterns include: OS relation pattern, SO relation pattern, SS relation pattern and OO relation pattern. When the position of the entity changes from the first relation to the second relation, the entity is transformed from the tail entity to the head entity, and the relative position pattern from the first relation to the second relation is the OS relation pattern. When the relative position pattern of the entity changes from the second relation to the first relation, the relative position pattern is the SO relation pattern. When the relative position pattern of the entity changes from the first relation to the first relation, the relative position pattern is the OO relation pattern. When the relative position pattern of the entity changes from the second relation to the second relation, the relative position pattern is the SS relation pattern. A heterogeneous relation graph is constructed according to the relative position patterns and relations.
[0103] In one embodiment, a head relationship entity matrix and a tail relationship entity matrix are constructed respectively:
[0104]
[0105] Among them, E s is the head relationship entity matrix composed of the head entity and the relationship between the head entity, E o is the tail relationship entity matrix composed of the tail entity and the relationship corresponding to the tail entity, The dimension is is the collection of entity matrices, |ε| is the number of entities in the temporal knowledge graph, is the number of relations in the temporal knowledge graph. The adjacency matrix corresponding to each relative position mode is constructed according to the head relation entity matrix and the tail relation entity matrix:
[0106]
[0107] Among them, A s-o is the adjacency matrix of the SO relationship pattern, A o-s is the adjacency matrix of the OS relationship pattern, A o-o is the adjacency matrix of the OO relationship model, A s-s is the adjacency matrix of the SS relationship model, E s is the head relationship entity matrix composed of the head entity and the relationship between the head entity, E o The tail relationship entity matrix is composed of the tail entity and the relationship corresponding to the tail entity. The intimacy is calculated for the relative position pattern in the heterogeneous relationship graph, the relationship weight is determined, and the relationship weight is aggregated with the adjacency matrix to obtain the heterogeneous relationship embedding representation.
[0108] In one embodiment, after the adjacency matrix is normalized, the first-layer graph convolution algorithm is used to aggregate the neighborhood of the relative position pattern to obtain the first-layer embedded feature representation of the corresponding relationship of the same relative position pattern:
[0109]
[0110] in, For the relationship i In the first layer of layer l+1, the feature representation is embedded. For the relationship j In the first layer of the lth layer, the feature representation is embedded, σ is the activation function, C is the set of relative position patterns, p∈{so,os,ss,oo} is a relational pattern in the set of relative position patterns, is the adjacency matrix A p Upper i The set of neighbors of p is the coefficient of mode p, w p,l is the relationship weight matrix, is the attention weight. The graph attention mechanism is used to aggregate the different relative position patterns of the first layer embedding feature representation to obtain the heterogeneous relation embedding representation:
[0111]
[0112] Among them, || is the splicing operation, M p,l is the weight matrix, y p,l is a row weight value vector, is the attention weight, For the relationship i In the first layer of layer l, the feature representation is embedded. For the relationship j In the first layer of layer l, the feature representation is embedded. For the relationship j' Heterogeneous relation embedding representation at layer l.
[0113] In one embodiment, the rules in the temporal knowledge graph are relatively encoded according to the preset temporal order constraints to obtain an embedded representation of the timestamp set:
[0114]
[0115] Among them, t i is the embedding representation of the timestamp set, is the periodic encoding of the timestamp set, is the aperiodic encoding of the timestamp set, Δt i is the relative time difference, ω p is the periodic frequency, ω np is a non-periodic frequency, is the periodic phase shift, is a non-periodic phase shift.
[0116] In one embodiment, the temporal link (e i ,r i ,e i+1 ,t i ), concatenate the embedded representations of heterogeneous relations and the embedded representations of timestamp sets, and obtain the embedded representation of temporal links in the rule body:
[0117] b i =W b [r i ||t i ]
[0118] Among them, || is the vector concatenation operation, is a learnable parameter, d is the dimension of the embedding representation of the heterogeneous relationship, 2d is the dimension of the embedding representation of the timestamp set, and b i is the embedding representation of the i-th link in the rule body, t i is the embedding representation of the timestamp set, r iis an element in the rule, i∈1,2,…,L. The recurrent neural network RNN is used to process the embedding representation of each temporal link to obtain the first embedding representation of the rule body:
[0119] Body=RNN(b 1 ,b 2 ,…,b L )
[0120] Among them, Body is the first embedding representation of the rule body, b L is the embedding representation of the Lth link in the rule body. And the second embedding representation of the rule head is calculated:
[0121] Head=W h r h
[0122] Among them, r h is the embedding representation of the relation in the rule head, W h is the transformation matrix, and Head is the second embedding representation of the rule head.
[0123] In one embodiment,
[0124] C sem =sim(Body,Head)
[0125] Among them, C sem is the semantic score, Body is the embedded representation of the rule body, Head is the embedded representation of the rule head, and sim() is the similarity function.
[0126] In one embodiment,
[0127]
[0128] Among them, C sta is the confidence of the rule, rule support is the rule support number, and body support is the rule body support number.
[0129] In one embodiment, a score is obtained according to the semantic similarity and the confidence:
[0130]
[0131] Among them, R is the rule, a and b are weighting coefficients, t min is the earliest time in the rule body, t q To query the time of a temporal historical fact, C sta is the confidence of the rule, C semis the semantic score. The candidate answers are obtained according to the predicted facts corresponding to the scores, and all the candidate answers are ranked using standard evaluation indicators. The candidate answer corresponding to the highest indicator value is taken as the optimal temporal knowledge graph reasoning result.
[0132] It is worth noting that if Figure 5 As shown, a semantically driven rule learning step is provided. For a query q = (e q ,r q ,? ,t q ), the obtained temporal logic rules and their confidence scores can be used to provide answers. Specifically, for the learned rules Traverse the rule body it supports, and then query entity e q Start by tracing along each rule body to identify the end entity as a candidate answer e a At the end of the traversal, all answers are ranked using standard evaluation metrics, with the higher the values of all metrics, the better. This shows that incorporating semantics into rule learning can enhance the interpretability of reasoning, and can evaluate the accuracy and usefulness of rules based not only on the frequency of their occurrence in the data, but also on their semantic consistency with the context and domain knowledge.
[0133] It should be understood that although Figure 1 , Figure 5 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 this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 1 , Figure 5 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.
[0134] In one embodiment, Figure 6 As shown, a semantically enhanced temporal knowledge graph reasoning device is provided, including: a temporal knowledge graph construction module 602, a heterogeneous relationship graph construction module 604, a heterogeneous relationship embedding representation acquisition module 606, a rule body acquisition module 608, a splicing module 610, a semantic similarity calculation module 612, a confidence acquisition module 614 and a reasoning module 616, wherein:
[0135] The time series knowledge graph construction module 602 is used to construct a time series knowledge graph based on historical events. The time series knowledge graph is represented by a quadruple, which includes: a head entity, a relationship, a tail entity, and a timestamp.
[0136] The heterogeneous relationship graph construction module 604 is used to construct a heterogeneous relationship graph according to the relative position relationship of entities in the time series knowledge graph. The heterogeneous relationship graph is represented by triples. The triples include: a head relationship entity, a relative position pattern, and a tail relationship entity.
[0137] The heterogeneous relationship embedding representation acquisition module 606 is used to embed the relationships in the heterogeneous relationship graph to obtain the heterogeneous relationship embedding representation.
[0138] The rule body acquisition module 608 is used to perform random walks in the temporal knowledge graph according to the preset rule header to obtain the rule body, wherein the rule header and the rule body are both represented by the four-tuple, and the timestamp of the rule header and the timestamp set of the rule body meet the preset temporal order constraint.
[0139] The splicing module 610 is used to obtain a first embedded representation of the rule body and a second embedded representation of the rule header according to the embedded representation of the heterogeneous relationship and the embedded representation of the timestamp set.
[0140] The semantic similarity calculation module 612 is used to calculate the semantic similarity according to the first embedding representation and the second embedding representation.
[0141] The confidence acquisition module 614 is used to obtain the confidence according to the number of rule supports satisfying the temporal order constraint obtained by random walk and the number of rule body supports obtained by all traversals.
[0142] The reasoning module 616 is used to output the optimal temporal knowledge graph reasoning result based on the semantic similarity and the confidence.
[0143] For the specific limitations of a semantically enhanced temporal knowledge graph reasoning device, please refer to the limitations of a semantically enhanced temporal knowledge graph reasoning method above, which will not be repeated here. Each module in the above-mentioned semantically enhanced temporal knowledge graph reasoning device 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.
[0144] 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 7As 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 semantically enhanced temporal knowledge graph reasoning method 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 covering the display screen, or a button, trackball or touchpad set on the computer device housing, or an external keyboard, touchpad or mouse, etc.
[0145] Those skilled in the art will understand that Figure 6-Figure 7 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.
[0146] In one embodiment, a computer device is provided, including 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:
[0147] Build a time series knowledge graph based on historical events. The time series knowledge graph is represented by a quadruple. The quadruple includes: head entity, relationship, tail entity, and timestamp.
[0148] According to the relative position relationship of entities in the time series knowledge graph, a heterogeneous relationship graph is constructed. The heterogeneous relationship graph is represented by triples. The triples include: head relationship entity, relative position pattern and tail relationship entity.
[0149] The relations in the heterogeneous relation graph are embedded to obtain the heterogeneous relation embedding representation.
[0150] According to the preset rule head, a random walk is performed in the time series knowledge graph to obtain the rule body, wherein both the rule head and the rule body are represented by a quadruple, and the timestamp of the rule head and the timestamp set of the rule body meet the preset time series order constraint.
[0151] According to the embedding representation of the heterogeneous relations and the embedding representation of the timestamp set, a first embedding representation of the rule body and a second embedding representation of the rule head are obtained.
[0152] Calculate semantic similarity based on the first embedding representation and the second embedding representation.
[0153] The confidence is obtained based on the number of rule supports that satisfy the temporal order constraints obtained by random walk and the number of rule body supports obtained by all traversals.
[0154] According to the semantic similarity and confidence, the optimal temporal knowledge graph reasoning result is output.
[0155] 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).
[0156] 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.
[0157] 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 semantically enhanced temporal knowledge graph reasoning method, characterized in that: The method comprises: Construct a time series knowledge graph based on historical events; the time series knowledge graph is represented by a quadruple; the quadruple includes: a head entity, a relationship, a tail entity, and a timestamp; According to the relative position relationship of entities in the temporal knowledge graph, a heterogeneous relationship graph is constructed; the heterogeneous relationship graph is represented by triples; the triples include: a head relationship entity, a relative position pattern, and a tail relationship entity; Embedding the relations in the heterogeneous relation graph to obtain a heterogeneous relation embedding representation; A random walk is performed in the temporal knowledge graph according to a preset rule head to obtain a rule body; wherein the rule head and the rule body are both represented by the quadruple, and the timestamp of the rule head and the timestamp set of the rule body satisfy a preset temporal order constraint; Obtaining a first embedded representation of the rule body and a second embedded representation of the rule head according to the embedded representation of the heterogeneous relationship and the embedded representation of the timestamp set; Calculating semantic similarity according to the first embedding representation and the second embedding representation; Obtain confidence according to the number of rule supports satisfying the temporal order constraints obtained by random walk and the number of rule body supports obtained by all traversals; According to the semantic similarity and the confidence, the optimal temporal knowledge graph reasoning result is output.
2. The method according to claim 1, characterized in that: According to the relative position relationship of entities in the temporal knowledge graph, a heterogeneous relationship graph is constructed, including: According to the relative position relationship of the entity in the two corresponding relations in the temporal knowledge graph, the relative position pattern corresponding to the two relations is obtained; the relative position pattern includes: OS relation pattern, SO relation pattern, SS relation pattern and OO relation pattern; when the position of the entity changes from the first relation to the second relation, the entity is transformed from the tail entity to the head entity, then the relative position pattern from the first relation to the second relation is the OS relation pattern; when the relative position pattern of the entity changes from the second relation to the first relation is the SO relation pattern; when the relative position pattern of the entity changes from the first relation to the first relation is the OO relation pattern; when the relative position pattern of the entity changes from the second relation to the second relation is the SS relation pattern; A heterogeneous relationship map is constructed according to the relative position pattern and the relationship.
3. The method according to claim 2, characterized in that Embedding the relations in the heterogeneous relation graph to obtain a heterogeneous relation embedding representation includes: Construct the head relationship entity matrix and the tail relationship entity matrix respectively: Among them, E s is the head relationship entity matrix composed of the head entity and the relationship corresponding to the head entity, E o is a tail relationship entity matrix composed of the tail entity and the relationship corresponding to the tail entity, The dimension is The collection of entity matrices of is the number of entities in the temporal knowledge graph, is the number of relations in the temporal knowledge graph; Construct an adjacency matrix corresponding to each relative position mode according to the head relationship entity matrix and the tail relationship entity matrix: Among them, A s-o is the adjacency matrix of the SO relationship pattern, A o-s is the adjacency matrix of the OS relationship pattern, A o-o is the adjacency matrix of the OO relationship model, A s-s is the adjacency matrix of the SS relationship model, E s is the head relationship entity matrix composed of the head entity and the relationship corresponding to the head entity, E o A tail relationship entity matrix consisting of the tail entity node and the relationship corresponding to the tail entity; The intimacy of the relative position pattern in the heterogeneous relationship graph is calculated to determine the relationship weight, and the relationship weight and the adjacency matrix are aggregated to obtain the heterogeneous relationship embedding representation.
4. The method according to claim 3, characterized in that Aggregating the relationship weights and the adjacency matrix to obtain a heterogeneous relationship embedding representation includes: After normalizing the adjacency matrix, the first-layer graph convolution algorithm is used to aggregate the neighborhood of the relative position pattern to obtain the first-layer embedded feature representation of the corresponding relationship of the same relative position pattern: in, For the relationship i In the first layer of layer l+1, the feature representation is embedded. For the relationship j In the first layer of the lth layer, the feature representation is embedded, σ is the activation function, C is the set of relative position patterns, p∈{so,os,ss,oo} is a relational pattern in the set of relative position patterns, is the adjacency matrix A p Upper i The set of neighbors of p is the coefficient of mode p, w p,l is the relationship weight matrix, is the attention weight; The graph attention mechanism is used to aggregate the different relative position patterns of the first layer of embedded feature representations to obtain heterogeneous relational embedding representations: Among them, || is the splicing operation, M p,l is the weight matrix, y p,l is a row weight value vector, is the attention weight, For the relationship i In the first layer of layer l, the feature representation is embedded. For the relationship j In the first layer of layer l, the feature representation is embedded. For the relationship j' Heterogeneous relation embedding representation at layer l.
5. The method according to claim 4, characterized in that Get the embedded representation of the timestamp set, including: The rules in the temporal knowledge graph are relatively encoded according to the preset temporal order constraints to obtain an embedded representation of the timestamp set: Among them, t i is the embedding representation of the timestamp set, is the periodic encoding of the timestamp set, is the aperiodic encoding of the timestamp set, Δt i is the relative time difference, ω p is the periodic frequency, ω np is a non-periodic frequency, is the periodic phase shift, is a non-periodic phase shift.
6. The method according to claim 5, characterized in that According to the embedded representation of the heterogeneous relationship and the embedded representation of the timestamp set, a first embedded representation of the rule body and a second embedded representation of the rule head are obtained, including: For the temporal links in the rule body (e i ,r i ,e i+1 ,t i ), concatenate the embedded representation of the heterogeneous relations and the embedded representation of the timestamp set to obtain the embedded representation of the temporal links in the rule body: b i =W b [r i ||t i ] Among them, || is the vector concatenation operation, is a learnable parameter, d is the dimension of the embedding representation of the heterogeneous relationship, 2d is the dimension of the embedding representation of the timestamp set, and b i is the embedding representation of the i-th temporal link in the rule body, t i is the embedded representation of the timestamp, r i is an element in the rule, i∈1,2,…,L; A recurrent neural network (RNN) is used to process the embedding representation of each of the temporal links to obtain a first embedding representation of the rule body: Body=RNN(b1,b2,…,b L ) Among them, Body is the first embedding representation of the rule body, b L is the embedding representation of the Lth link in the rule body; And calculate the second embedding representation of the rule head: Head=W h r h Among them, r h is the embedding representation of the relation in the rule head, W h is the transformation matrix, and Head is the second embedding representation of the rule head.
7. The method according to claim 6, characterized in that Calculating semantic similarity according to the first embedding representation and the second embedding representation includes: C sem =sim(Body,Head) Among them, C sem is the semantic score, Body is the embedded representation of the rule body, Head is the embedded representation of the rule head, and sim() is the similarity function.
8. The method according to claim 7, characterized in that The confidence is obtained according to the number of rule supports that satisfy the temporal order constraints obtained by random walk and the number of rule body supports obtained by all traversals, including: Among them, C sta is the confidence of the rule, rule support is the rule support number, and body support is the rule body support number.
9. The method according to claim 8, characterized in that According to the semantic similarity and the confidence, the optimal temporal knowledge graph reasoning result is output, including: According to the semantic similarity and the confidence, a score is obtained: Among them, R is the rule, a and b are weighting coefficients, t min is the earliest time in the rule body, t q To query the time of a temporal historical fact, C sta is the confidence of the rule, C sem is the semantic score; The candidate answers are obtained according to the predicted facts corresponding to the scores, all the candidate answers are ranked using standard evaluation indicators, and the candidate answer corresponding to the highest indicator value is taken as the optimal temporal knowledge graph reasoning result.
10. A semantically enhanced temporal knowledge graph reasoning device, characterized in that: The device comprises: A time series knowledge graph construction module is used to construct a time series knowledge graph based on historical events; the time series knowledge graph is represented by a quadruple; the quadruple includes: a head entity, a relationship, a tail entity, and a timestamp; A heterogeneous relationship graph construction module is used to construct a heterogeneous relationship graph according to the relative position relationship of entities in the temporal knowledge graph; the heterogeneous relationship graph is represented by triples; the triples include: a head relationship entity, a relative position pattern, and a tail relationship entity; A heterogeneous relationship embedding representation acquisition module is used to embed the relationship in the heterogeneous relationship graph to obtain a heterogeneous relationship embedding representation; A rule body acquisition module, configured to perform a random walk in the temporal knowledge graph according to a preset rule head to obtain a rule body; wherein the rule head and the rule body are both represented by the quadruple, and the timestamp of the rule head and the timestamp set of the rule body satisfy a preset temporal order constraint; A concatenation module, configured to obtain a first embedded representation of the rule body and a second embedded representation of the rule head according to the embedded representation of the heterogeneous relationship and the embedded representation of the timestamp set; A semantic similarity calculation module, used for calculating semantic similarity according to the first embedding representation and the second embedding representation; A confidence acquisition module, used to obtain confidence according to the number of rule supports satisfying the temporal order constraints obtained by random walk and the number of rule body supports obtained by all traversals; The reasoning module is used to output the optimal temporal knowledge graph reasoning result according to the semantic similarity and the confidence.
11. 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 9 are implemented.
Citation Information
Cited By
Class case recommendation method and system
CN120541309A
Similar case recommendation method and system
CN120541309B
