A Temporal Knowledge Graph Completion Method Based on Temporal Counterfactual Enhancement
By constructing a counterfactually enhanced timing knowledge graph completion method, using the k-kernel decomposition algorithm and community member functions to identify the community structure, and combining counterfactual processing and composite loss function to train the model, the data sparsity and noise problems in the timing knowledge graph are solved, and the robustness and prediction accuracy of the model are improved.
Patent Information
- Application Number
- CN202410941596.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-15
- Publication Date
- 2025-07-25
- Estimated Expiration
- 2044-07-15
AI Technical Summary
The prior art is difficult to effectively integrate time information in the timing knowledge graph, resulting in low accuracy when predicting future or retrospective states in the past, and faces problems of data sparseness and noise data, which affects the robustness and generalization ability of the model.
Time-changing k-kernel decomposition algorithm and community member functions are used to construct time-process tensors, counterfactual relationship data sets are generated through counterfactual processing and individual processing effect estimation, model training is combined with composite loss function, and encoder-decoder structure is constructed for prediction and filling of missing relationships.
It improves the robustness and prediction ability of the model under incomplete and sparse data, can better understand and predict the relationships of changing over time between entities, and enhances the generalization ability and prediction accuracy of the model.
Smart Images

Figure CN118885624B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of knowledge graphs, and more particularly to a method for temporal knowledge graph completion based on temporal counterfactual enhancement. Background Art
[0002] Knowledge Graphs (KGs) have become the cornerstone for constructing and leveraging vast information repositories, enabling artificial intelligence systems to process complex data in various fields. Knowledge graphs have evolved into Temporal Knowledge Graphs (TKGs), introducing time as a key dimension to track and predict the changes of entity relationships over time.
[0003] In the fields of knowledge graphs and temporal knowledge graphs, despite significant progress, existing technologies still face a series of challenges when dealing with the completion and prediction of temporal data. Traditional knowledge graph methods often ignore the key dimension of time and are unable to capture the dynamic changes of relationships between entities. Even in temporal knowledge graphs, how to effectively integrate time information to reflect the evolution of relationships over time remains a difficult problem, resulting in low accuracy of the model when predicting future or retrospective relationship states.
[0004] At the same time, temporal knowledge graphs are usually sparser than static knowledge graphs. They not only need to record entity-relationship triples but also need to annotate the specific time when each fact occurs. This high-dimensional data structure exacerbates the problem of data sparsity, resulting in the absence of many entity relationship links and affecting the generalization ability and prediction performance of the model.
[0005] In practical applications, certain types of entity relationships may occur far more frequently than other types of relationships, causing the model to tend to overfit common patterns and ignore rare but important relationship patterns. This requires the completion method to be able to fairly handle different types of relationships, especially in the context of time series. The relationships between entities often form specific patterns or community structures over time, and existing methods often do not fully explore how these structures affect the evolution of relationships.
[0006] In addition, in the face of noisy data, outliers, or newly emerging relationship types, existing models often perform poorly, showing limited robustness and generalization ability under different data conditions.
[0007] Therefore, how to design a method for temporal knowledge graph completion based on temporal counterfactual enhancement to improve the robustness of the model on incomplete and sparse data, and then optimize the completion and prediction capabilities of temporal knowledge graphs is an urgent problem to be solved by those skilled in the art. Summary of the Invention
[0008] In view of this, the present invention provides a method for temporal knowledge graph completion based on temporal counterfactual enhancement, which constructs counterfactual scenarios to enhance the model's understanding of time series data, improves the capture of temporal community structures, effectively solves the incompleteness problem in temporal knowledge graphs, and enables the model to better understand and predict the time-varying relationships between entities in practical applications.
[0009] To achieve the above object, the present invention adopts the following technical solutions:
[0010] A method for temporal knowledge graph completion based on temporal counterfactual enhancement, comprising the following steps:
[0011] S1. Obtain a temporal knowledge graph, define parameters for the temporal knowledge graph, and generate a factual relationship dataset;
[0012] S2. Based on the factual relationship dataset, use a time-varying k-core decomposition algorithm and a community membership function to construct a time processing tensor that maps the temporal graph structure;
[0013] S3. Adjust the entity neighborhood structure in the time processing tensor, perform counterfactual processing, and combine individual treatment effect estimation to construct a counterfactual relationship dataset; and merge the counterfactual relationship dataset and the factual relationship dataset to obtain a training dataset;
[0014] S4. Use the training dataset, combined with a composite loss function, to train a temporal knowledge graph completion model to obtain a trained temporal knowledge graph completion model;
[0015] S5. Input the temporal knowledge graph with missing relationships into the trained temporal knowledge graph completion model, perform missing relationship prediction and filling, and output the completed temporal knowledge graph.
[0016] Among them, in step S1, defining parameters for the temporal knowledge graph includes:
[0017] Define the temporal knowledge graph as G; in the temporal knowledge graph G, define the entity set as E, the relationship set as R, the timestamp set as T, and the factual quadruple as (s, r, o, t); where s is the head entity, r is the relationship, o is the tail entity, and t is the timestamp; and s, o ∈ E, r ∈ R, t ∈ T; the temporal knowledge graph G includes several temporal subgraphs, G = {G1, G2,..., G T}; the temporal subgraph includes all factual triples (s, r, o) occurring at timestamp t.
[0018] Preferably, step S2 includes:
[0019] S21. Construct an initial time processing tensor based on the factual relationship dataset
[0020]
[0021] S22. Perform community structure recognition on the initial time processing tensor using a time-varying k-core decomposition algorithm to obtain a community structure recognition result;
[0022] S23. Utilize the community structure recognition result to assign community labels to each entity through the community membership function C t and adjust the initial time processing tensor based on whether the source entity s and the target entity o are in the same community to obtain an adjusted time processing tensor
[0023]
[0024] S24. Combine the core numbers of each entity at timestamp t, perform threshold screening and weight adjustment on the adjusted time processing tensor to obtain a time processing tensor
[0025] Preferably, in step S23, the community membership function C t is: C t : E t →N, which means accepting any entity in the entity set E t at timestamp t as input and assigning a community number to each entity based on the community number set N; where N is a natural number.
[0026] Preferably, in step S24, the core number of each entity at timestamp t is updated at each time step through an iterative algorithm; the core number of each entity at timestamp t is expressed as:
[0027] k(t) = max{k ∈ N: deg k (t) ≥ k}
[0028] where deg k (t) represents the number of relationships between a certain entity and entities with at least core number k at timestamp t.
[0029] Preferably, in step S3, adjust the entity neighborhood structure in the time processing tensor, perform counterfactual processing, and combine individual treatment effect estimation to generate a counterfactual relationship dataset, including:
[0030] S31. Define entity pairs for context representation based on the time processing tensor; the entity pairs Integrate the characteristic information of relevant entities and their corresponding relationships;
[0031] S32. Based on the entity pair Define the counterfactual processing as m, and the entity structure information after counterfactual processing as m(s, o, t); the m(s, o, t) is a function of the temporal graph structure tensor. If the factual triple (s, r, o) is valid, then A(s, r, o) = 1; otherwise, A(s, r, o) = 0.
[0032] S33. Use A(s, r, o, t) to represent whether the factual triple (s, r, o) exists at timestamp t. If it exists, then A(s, r, o, t) = 1; otherwise, A(s, r, o, t) = 0.
[0033] S34. Perform individual treatment effect estimation to generate counterfactual relationships; the individual treatment effect is the probability difference of the existence of relationships under factual treatment and counterfactual treatment, specifically:
[0034] ITE(s, r, o, t) = P(A(s, r, o, t) = 1|T = 1) - P(A(s, r, o, t) = 1|T = 0)
[0035] where P(A(s, r, o, t) = 1|T = 1) represents the probability of the existence of the relationship under factual treatment, and P(A(s, r, o, t) = 1|T = 0) represents the probability of the existence of the relationship under counterfactual treatment.
[0036] Preferably, in the step S4, the composite loss function is:
[0037] L = L F + α·L CF + β·L D
[0038] where L F is the factual log-likelihood loss, L CF is the counterfactual log-likelihood loss, L D is the inconsistency loss, and α and β are weight parameters.
[0039] Preferably, in the step S5, the temporal knowledge graph completion model is an encoder-decoder structure; it includes: a temporal graph neural network encoder and a relation decoder; the relation decoder includes a multi-layer perceptron.
[0040] Preferably, the temporal graph neural network encoder updates entities and embeds relationships through a message passing mechanism, specifically:
[0041]
[0042] where Denote the embedding of entity s at timestamp t+1, Denote the embedding of entity s at timestamp t, Denote the embedding of relation r at timestamp t, Denote the neighborhood of entity s under timestamp t and relation r, t-GNN is the temporal graph neural network, and θ is the parameter of the temporal graph neural network.
[0043] Preferably, the relation decoder performs relation prediction between entity pairs, and calculates the probability score of a given entity pair and relation at a specific time through a multi-layer perceptron, specifically:
[0044] For a given entity pair (s, o) and relation r at timestamp t, the relation decoder is defined as:
[0045]
[0046] Where, and respectively represent the factual relation prediction probability and the counterfactual relation prediction probability; MLP represents the multi-layer perceptron, represents the concatenation operator, represents the embedding of entity s at timestamp t, represents the embedding of entity o at timestamp t, and respectively represent the factual processing vector and the counterfactual processing vector.
[0047] Through the above technical solutions, compared with the prior art, the technical solutions of the present invention have the following
[0048] Advantages:
[0049] 1. Adopt a time-varying - kernel decomposition algorithm to identify the community structure in the temporal knowledge graph, and assign community indices to each entity through the community membership function to construct a temporal processing tensor. It not only reveals the structural information of the temporal graph but also captures the dynamic interactions between entities through the temporal processing tensor, thereby improving the model's sensitivity and understanding depth of the temporal structure.
[0050] 2. Perform counterfactual processing by adjusting the entity neighborhood structure in the temporal processing tensor, simulating the possible changes in the existence of relations if the neighborhood structure of the entity is different. Combined with the estimation of the individual treatment effect (ITE), a counterfactual relation dataset is constructed. This process creates an "if... what would happen" scenario artificially, provides additional training data for the model, enhances the generalization ability of the model, and can more meticulously simulate the relationship dynamics in the time series, thereby improving the prediction accuracy.
[0051] 3. The counterfactual relationship dataset is merged with the factual relationship dataset to create a richer training dataset. The model is trained using a composite loss function, which optimizes the model's performance on known data and improves the stability and accuracy of the model when dealing with counterfactual data.
[0052] 4. The trained model is used to predict and fill in the temporal knowledge graph with missing relationships, effectively solving the incompleteness problem in the temporal knowledge graph, enabling the model to better understand and predict the relationships between entities over time in practical applications, and improving the integrity and practicality of the knowledge graph. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only the embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on the provided drawings.
[0054] Figure 1 Schematic flowchart of the temporal knowledge graph completion method based on temporal counterfactual enhancement provided by the embodiment of the present invention;
[0055] Figure 2 Schematic diagram of the model robustness evaluation result in the case of adding facts provided by the embodiment of the present invention;
[0056] Figure 3 Schematic diagram of the model robustness evaluation result in the case of deleting facts provided by the embodiment of the present invention;
[0057] Figure 4 Schematic diagram of the sensitivity analysis result based on parameter α provided by the embodiment of the present invention;
[0058] Figure 5 Schematic diagram of the sensitivity analysis result based on parameter β provided by the embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0059] The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the scope of protection of the present invention.
[0060] Embodiment 1;
[0061] As Figure 1As shown in the figure, this embodiment provides a method for temporal knowledge graph completion based on temporal counterfactual enhancement, including the following steps:
[0062] S1. Obtain a temporal knowledge graph, define parameters for the temporal knowledge graph, and generate a factual relationship dataset;
[0063] S2. Based on the factual relationship dataset, use a time-varying k-core decomposition algorithm and a community membership function to construct a time processing tensor that maps the temporal graph structure;
[0064] S3. Adjust the entity neighborhood structure in the time processing tensor, perform counterfactual processing, and combine individual treatment effect estimation to construct a counterfactual relationship dataset; and merge the counterfactual relationship dataset and the factual relationship dataset to obtain a training dataset;
[0065] S4. Use the training dataset and combine a composite loss function to train a temporal knowledge graph completion model to obtain a trained temporal knowledge graph completion model;
[0066] S5. Input the temporal knowledge graph with missing relationships into the trained temporal knowledge graph completion model, perform missing relationship prediction and filling, and output the completed temporal knowledge graph.
[0067] By introducing a temporal counterfactual enhancement strategy and constructing and utilizing counterfactual data, this method significantly improves the robustness and prediction ability of the model in the case of imperfect and sparse data, and realizes more accurate and delicate temporal knowledge graph completion.
[0068] The following further elaborates on the above steps and related technical features in detail:
[0069] In step S1 of this embodiment, defining parameters for the temporal knowledge graph includes:
[0070] Define the temporal knowledge graph as G; in the temporal knowledge graph G, define the entity set as E, the relationship set as R, the timestamp set as T, and the factual quadruple as (s, r, o, t); where s is the head entity, r is the relationship, o is the tail entity, and t is the timestamp; and s, o ∈ E, r ∈ R, t ∈ T; the temporal knowledge graph G includes several temporal subgraphs, G = {G1, G2, ……, G T}; the temporal subgraph includes all factual triples (s, r, o) that occur at timestamp t.
[0071] The above parameter definition of the temporal knowledge graph clearly points out the basic components such as entities, relationships, timestamps, and factual quadruples, provides a clear framework, facilitates the systematic organization and processing of temporal data, and ensures the applicability and operability of the following steps.
[0072] In step S2 of this embodiment, it includes:
[0073] S21. Based on the factual relationship dataset, construct an initial time processing tensor
[0074]
[0075] S22. Apply a time-varying k-core decomposition algorithm to the initial time processing tensor for community structure recognition to obtain the community structure recognition result;
[0076] S23. Utilize the community structure recognition result, and through the community membership function C t assign community labels to each entity, and adjust the initial time processing tensor based on whether the source entity s and the target entity o are in the same community to obtain the adjusted time processing tensor
[0077]
[0078] wherein, the community membership function C t is: C t : E t → N, indicating that at time stamp t, any entity in the entity set E t is taken as input, and a community number is assigned to each entity based on the community number set N; wherein, N is a natural number.
[0079] S24. Combine the core numbers of each entity at time stamp t, perform threshold screening and weight adjustment on the adjusted time processing tensor to obtain the time processing tensor
[0080] Threshold screening aims to filter out noise or insignificant associations from the time processing tensor, and only retain those strong associations or entity relationships with significant structural meanings. Specifically, it includes:
[0081] Define the threshold criteria: Based on the data statistical characteristics and experimental priors, set one or more thresholds to distinguish strong and weak relationships. For example, a reasonable threshold can be determined based on the core number distribution of entities, and only retain those entity pair relationships whose core numbers exceed a specific threshold. Screen the processing tensor: Traverse each element in the time processing tensor. If the processing value of the entity pair relationship represented by this element is lower than the preset threshold, set it to zero or directly remove it. The processing tensor is simplified, and only those entity relationships considered to be key or strong associations are retained.
[0082] Weight adjustment is to further highlight the influence of important relationships and optimize model learning by assigning different weights to different processes. Specifically, it includes:
[0083] Kernel-based Weight Assignment: Since the kernel number reflects the centrality of an entity in the community, we can assign different weights to entities according to their kernel numbers. For example, entity pairs with a high kernel number can be assigned greater weights because they are more critical in the community structure and have a stronger influence on the evolution of relationships. Dynamic Weight Adjustment: Weights can also be adjusted dynamically according to changes in the time series. In some cases, if the relationship of an entity pair significantly strengthens or weakens over time, the corresponding processing weight should also be adjusted accordingly to reflect this dynamicity.
[0084] Through the above-mentioned threshold screening and weight adjustment, we not only remove unimportant or noisy information, but also strengthen the model's attention to key temporal structure features, thereby improving the accuracy and robustness of the model when processing time series data.
[0085] In addition, the kernel number of each entity at timestamp t is updated at each time step through an iterative algorithm; the kernel number of each entity at timestamp t is expressed as:
[0086] k(t)=max{k∈N:deg k (t)≥k}
[0087] where deg k (t) represents the number of relationships between a certain entity and entities with at least kernel number k at timestamp t.
[0088] By introducing the -kernel decomposition algorithm here, it is possible to identify the community structure in the temporal knowledge graph and classify entities into different communities according to their relationship networks at specific timestamps. It captures the dynamics of entity relationships in the time dimension and provides a structured perspective for understanding and predicting relationship evolution. Using the community membership function to assign community indices to each entity further refines the understanding of the temporal community structure, thereby increasing the model's sensitivity to time-dependent relationships.
[0089] It adopts an iterative update method for entity kernel numbers, dynamically reflecting the changes in the connectivity and influence of entities in the network, enabling the subsequent model training process to adapt to the dynamic changes of the temporal graph and improving the model's dynamic adaptability and robustness.
[0090] In step S3 of this embodiment, the entity neighborhood structure in the time processing tensor is adjusted, counterfactual processing is performed, and combined with individual treatment effect estimation, a counterfactual relationship dataset is generated, including:
[0091] S31. Based on the time processing tensor, define the entity pair for context representation; the entity pair integrates the feature information of relevant entities and their corresponding relationships;
[0092] S32. Based on the entity pair Define the counterfactual treatment as \(m\), and the entity structure information after the counterfactual treatment as \(m(s, o, t)\); \(m(s, o, t)\) is a function of the temporal graph structure tensor. If the factual triple \((s, r, o)\) is valid, then \(A(s, r, o)=1\); otherwise, \(A(s, r, o)=0\).
[0093] Use \(A(s, r, o, t)\) to represent whether the factual triple \((s, r, o)\) exists at timestamp \(t\). If it exists, then \(A(s, r, o, t)=1\); otherwise, \(A(s, r, o, t)=0\).
[0094] S34. Perform individual treatment effect estimation to generate counterfactual relationships; the individual treatment effect is the probability difference of the existence of the relationship under the factual treatment and the counterfactual treatment, specifically:
[0095] ITE(s, r, o, t)=P(A(s, r, o, t)=1|T = 1)-P(A(s, r, o, t)=1|T = 0)
[0096] where \(P(A(s, r, o, t)=1|T = 1)\) represents the probability of the existence of the relationship under the factual treatment, and \(P(A(s, r, o, t)=1|T = 0)\) represents the probability of the existence of the relationship under the counterfactual treatment.
[0097] It constructs a counterfactual scenario, that is, assumes that the neighborhood structure of the entity changes, and explores the impact of this change on the possibility of the existence of the relationship. This method enriches the training data set by adding additional, hypothetical data points, thereby improving the generalization ability of the model. It can not only handle the actually observed relationships, but also infer the relationships that may exist under different neighborhood configurations, thus deepening the understanding of the dynamics of temporal relationships.
[0098] In step S4 of this embodiment, the composite loss function is:
[0099] L = L F +α·L CF +β·L D
[0100] where \(L F is the factual log-likelihood loss, \(L CF is the counterfactual log-likelihood loss, \(L D is the inconsistency loss, and α and β are weight parameters.
[0101] Specifically:
[0102]
[0103]
[0104] and respectively represent the factual relationship prediction probability and the counterfactual relationship prediction probability; n is the number of negative samples in the counterfactual relationship dataset related to the positive samples in the factual relationship dataset, (s' i , r, o' i , t) is the i-th negative sample in the counterfactual relationship dataset; it should be emphasized that negative samples are consistently applied in the processing of facts and counterfactuals.
[0105] It also includes minimizing the discrimination metric, which distinguishes the estimated factual distribution and the estimated counterfactual distribution, thus contributing to the learning process of stable representation, the inconsistency loss L D :
[0106]
[0107] where μ F and μ CF are the average representations of entity pairs under factual processing and counterfactual processing respectively.
[0108] Its loss function design that combines factual and counterfactual data optimizes the model's fitting of observed data and also promotes the model's understanding of unobserved counterfactual situations. By minimizing the inconsistency loss, the consistency of the model's representation under different processes is ensured, increasing the stability of the model.
[0109] In step S5 of this embodiment, the temporal knowledge graph completion model is an encoder-decoder structure; it includes: a temporal graph neural network encoder and a relationship decoder; the relationship decoder includes a multi-layer perceptron.
[0110] The temporal graph neural network encoder updates entities and relationship embeddings through a message passing mechanism, specifically:
[0111]
[0112] where represents the embedding of entity s at timestamp t + 1, represents the embedding of entity s at timestamp t, represents the embedding of relationship r at timestamp t, represents the neighborhood of entity s under timestamp t and relationship r, t-GNN is the temporal graph neural network, and θ is the temporal graph neural network parameter.
[0113] Through the time-aware message passing mechanism, the t-GNN encoder updates the embeddings of entities and relationships, effectively capturing the dynamic relationships and time evolution information between entities. This mechanism enables the model to learn more refined temporal feature representations, improving the model's expressive ability and the ability to model temporal dynamics.
[0114] The relation decoder predicts the relations between entity pairs, and calculates the probability scores of a given entity pair and relation at a specific time through a multi-layer perceptron. Specifically:
[0115] For a given entity pair (s, o) and relation r at timestamp t, the relation decoder is defined as:
[0116]
[0117] where and represent the factual relation prediction probability and the counterfactual relation prediction probability respectively; MLP represents the multi-layer perceptron, represents the concatenation operator, represents the embedding of entity s at timestamp t, represents the embedding of entity o at timestamp t, and represent the factual processing vector and the counterfactual processing vector respectively.
[0118] The multi-layer perceptron (MLP) is used to predict the probability of the existence of a relation. By combining the embeddings and processing information of entity pairs, the prediction accuracy is improved. In particular, it considers the performance of entity pairs under different processes (i.e., factual and counterfactual), providing a more comprehensive perspective for relation prediction, improving the expressive power of the model and the ability to model temporal dynamics.
[0119] The technical solution of this embodiment proposes a temporal knowledge graph completion method based on temporal counterfactual enhancement. By integrating the understanding of the temporal community structure and counterfactual thinking, it simulates and analyzes the dynamic changes of entity relations at different timestamps, and then predicts and fills the missing links in the temporal knowledge graph TKG. Combining the temporal graph neural network (t-GNN) encoder to capture the temporal dependencies of entities and relations, the relation decoder is used to predict the probability of the existence of a relation, and a composite loss function is used to optimize the performance of the model in factual and counterfactual scenarios. It not only enhances the processing ability of sparse and incomplete data, but also deepens the understanding of temporal data by constructing "hypothetical" scenarios, improving the prediction performance, and providing strong support for the deep completion of temporal knowledge graphs.
[0120] Example 2;
[0121] In this embodiment, a fictional academic conference publication scenario is taken as an example to construct an application case for temporal knowledge graph completion.
[0122] This temporal knowledge graph records the paper publication information of global academic conferences within a certain time period, including authors (Author), papers (Paper), conferences (Conference), and the relationships between them, such as "Writes" and "PresentedAt", as well as the submission date of each paper.
[0123] Parameter Definition and Generation of Fact Relationship Dataset: In the academic conference TKG, the entity set E includes authors (A), papers (P), and conferences (C), and the relationship set R contains "Writes", "PresentedAt", etc. The timestamp set T covers all months within the time period. For example, the quadruple (A1, Writes, P1, A moment) indicates that author A1 wrote paper P1 at moment A (a certain year and month). Through such parameter definitions, we construct a fact relationship dataset containing all known paper publication records.
[0124] Constructing the Time Processing Tensor: Using the time-varying k-core decomposition algorithm to identify the research community structure in the academic field, such as which author groups frequently publish papers at the same conference within a specific time period. The community membership function will assign a community label to each author and adjust the time processing tensor accordingly to strengthen the connections among community members. At the same time, the tensor weights are dynamically adjusted according to the activity of each author at a specific time (i.e., the number of papers co-authored with other authors) to strengthen the influence of active authors.
[0125] Counterfactual Processing and Relationship Dataset Construction: Based on the time processing tensor, counterfactual processing is carried out by adjusting the entity neighborhood structure, considering how the publication probability of a paper would be affected if it were written by another author instead of the current author or published at a different conference. Based on this counterfactual scenario, combined with individual treatment effect estimation, a counterfactual relationship dataset is generated. For example, evaluate how the publication probability of P1 at conference C1 would change if it were written by A2 instead of A1.
[0126] Composite Loss Function and Model Training: Combining the fact and counterfactual relationship datasets, a composite loss function is used for model training. This function includes fact log-likelihood loss, counterfactual log-likelihood loss, and inconsistency loss to optimize the model's prediction performance in dealing with real and hypothetical situations. In this way, the model can not only learn the existing publication patterns but also understand the possible publication paths under different assumptions.
[0127] Missing relationship prediction and completion: For papers with missing author or publication conference information in the records, this information is input into the trained temporal knowledge graph completion model, which predicts and fills in the missing information. For example, it predicts which author should write P2 in a certain year and an unspecified month, and in which conference it should be published.
[0128] Experiments were conducted on a set of fictional benchmark datasets that simulated academic conferences of various scales and topics. By comparing with baseline models (such as static knowledge graph embedding models), the accuracy of the method of the present invention in predicting the relationships between authors, papers, and conferences was verified. The evaluation metrics included Hit@k and Mean Reciprocal Rank (MRR). The results showed that this method performed better in dealing with the data sparsity problem, significantly improving the completion accuracy of the temporal knowledge graph and the generalization ability of the model.
[0129] From the description in this embodiment, it can be seen that the temporal knowledge graph completion method based on temporal counterfactual enhancement is not only applicable to specific fields, such as movies or certain related events, but also applicable to more abstract and general fields such as academic conferences, demonstrating the wide applicability and effectiveness of this technology in dealing with the problems of temporal data incompleteness and sparsity.
[0130] In addition, in this embodiment, four benchmark datasets were selected for link prediction based on the temporal knowledge graph completion model in the technical solution of this application. The benchmark datasets include: ICEWS14, ICEWS05-15, YAGO11k, and GDELT. These datasets cover political events, a wide time range, and entities and relationships of different scales, ensuring the comprehensiveness of the experiment. The link prediction task is carried out based on a time filtering scheme and an expected entity generation protocol, aiming to predict the missing entities given an entity and a relationship type.
[0131] The temporal knowledge graph completion model in the technical solution of this application was compared with a series of static and temporal knowledge graph embedding (KGE) methods, such as TransE, DistMult, RotatE, QuatE, TTransE, HyTE, etc., to verify its superiority.
[0132] As Figure 2 and Figure 3 shown, the robustness evaluation on the ICEWS14 dataset. Among them, the horizontal axis represents the percentage of the number of added or deleted facts, and the vertical axis represents the value of Hit@1. There are three curves in the figure, representing the changing trends of Hit@1 of the TCA, RotateQVS, and TeRo models in the cases of adding facts and deleting facts respectively.
[0133] By deliberately introducing data sparsity and noise, the ICEWS14 dataset was modified, and the temporal knowledge graph completion model demonstrated extremely high robustness. Even when there are significant changes in data integrity, TCA can still maintain good performance. Compared with other baseline models TeRo and RotateQVS, it performs better in data-sparse and noisy environments.
[0134] As Figure 4 and Figure 5 shown, the sensitivity analysis regarding the ICEWS14 and ICEWS05-15 datasets. The horizontal axis represents the value ranges of the hyperparameters α and β, and the vertical axis represents the value of MRR. There are four curves in the figure, with every two corresponding to one dataset, and different models are distinguished by colors. The curves show how the MRR values of the TCA model change on the two datasets as the parameters α and β change.
[0135] The effects of the hyperparameters α and β (which control the weights of the counterfactual loss and the inconsistency loss respectively) on the model training effect were also analyzed. The experimental results show that the temporal knowledge graph completion model still maintains stable performance under different hyperparameter configurations, further demonstrating its robustness.
[0136] The various embodiments in this specification are described in a progressive manner. Each embodiment focuses on the differences from other embodiments. For the same or similar parts among the various embodiments, reference can be made to each other. For the systems disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple, and reference can be made to the method part for the relevant parts.
[0137] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to these embodiments shown herein, but rather to the broadest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for temporal knowledge graph completion based on temporal counterfactual enhancement, characterized in that It includes the following steps: S1. Obtain the academic conference temporal knowledge graph, define parameters for the academic conference temporal knowledge graph, and generate a factual relationship dataset; The factual relationship dataset includes: an entity set, a relationship set, and a timestamp set; among them, the entity set includes authors, papers, and conferences; S2. Based on the fact relationship data set, use a time-varying k-core decomposition algorithm to identify the academic research community structure, and assign a community label to each author through a community member function to construct a time processing tensor that maps the time series graph structure; including: S21. Based on the fact relationship data set, construct an initial time processing tensor S22. Process the initial time processing tensor Use a time-varying k-core decomposition algorithm for community structure recognition to obtain the community structure recognition result; S23. Using the community structure recognition result, through the community membership function C t assign community labels to each entity, and process the initial time tensor, and adjust it based on whether the source entity s and the target entity o are in the same community, so as to obtain the adjusted time processing tensor S24. Combine the number of cores of each entity at timestamp t, perform threshold screening and weight adjustment on the adjusted time processing tensor to obtain a time processing tensor Among them, threshold screening includes defining a threshold criterion and screening the processing tensor, and weight adjustment includes weight assignment based on the number of cores and dynamic weight adjustment; S3. Adjust the entity neighborhood structure in the time processing tensor, perform counterfactual processing, and combine individual treatment effect estimation to construct a counterfactual relationship dataset; and merge the counterfactual relationship dataset and the factual relationship dataset to obtain a training dataset; including: S31. Define entity pairs based on the time-processed tensor for context representation; the entity pairs integrate the feature information of relevant entities and their corresponding relationships; S32. Based on the entity pair Define the counterfactual processing as m, and the entity structure information after counterfactual processing as m(s, o, t); the m(s, o, t) is a function of the temporal graph structure tensor. If the factual triple (s, r, o) is valid, then A(s, r, o) = 1; otherwise, A(s, r, o) = 0. S33. Use A(s, r, o, t) to represent whether the factual triple (s, r, o) at timestamp t exists. If it exists, then A(s, r, o, t)=1; otherwise, A(s, r, o, t)=0; S34. Perform individual treatment effect estimation to generate counterfactual relationships; the individual treatment effect is the probability difference of the existence of relationships under factual treatment and counterfactual treatment, specifically: ITE(s, r, o, t)=P(A(s, r, o, t)=1|T = 1)-P(A(s, r, o, t)=1|T = 0) where P(A(s, r, o, t)=1|T = 1) represents the probability of the existence of a relationship under factual treatment, and P(A(s, r, o, t)=1|T = 0) represents the probability of the existence of a relationship under counterfactual treatment; S4. Use the training dataset, combined with a composite loss function, to train a temporal knowledge graph completion model to obtain a trained temporal knowledge graph completion model; S5. Input the academic conference temporal knowledge graph with missing relationships into the trained temporal knowledge graph completion model to perform missing relationship prediction and filling, and output the completed academic conference temporal knowledge graph; the temporal knowledge graph completion model is an encoder-decoder structure; including: a time graph neural network encoder and a relationship decoder; the relationship decoder includes a multi-layer perceptron; The relationship decoder performs relationship prediction between entity pairs, and calculates the probability score of a given entity pair and relationship at a specific time through a multi-layer perceptron, specifically: For a given entity pair (s, o) and relationship r at timestamp t, the relationship decoder is defined as: Among them, and respectively represent the factual relationship prediction probability and the counterfactual relationship prediction probability; MLP represents a multi-layer perceptron, represents the concatenation operator, represents the embedding of entity s at timestamp t, represents the embedding of entity o at timestamp t, and respectively represent the factual processing vector and the counterfactual processing vector.
2. The method for temporal knowledge graph completion based on temporal counterfactual enhancement according to claim 1, wherein In step S1, defining parameters for the temporal knowledge graph includes: Define the temporal knowledge graph as G; in the temporal knowledge graph G, define the entity set as E, the relationship set as R, the timestamp set as T, and the fact quadruple as (s, r, o, t); where s is the head entity, r is the relationship, o is the tail entity, and t is the timestamp; and s, o ∈ E, r ∈ R, t ∈ T; the temporal knowledge graph G includes several temporal subgraphs, G = {G1, G2, ……, G T}; the temporal subgraph includes all fact triples (s, r, o) that occur at the timestamp t.
3. A method for temporal knowledge graph completion based on temporal counterfactual enhancement according to claim 1, wherein In the said step S23, the community member function C t is: C t : E t →N, which means that at time stamp t, any entity in the entity set E t is taken as input, and a community number is assigned to each entity based on the community number set N; where N is a natural number.
4. A method for temporal knowledge graph completion based on temporal counterfactual enhancement according to claim 1, wherein In step S24, the number of cores of each entity at timestamp t is updated through an iterative algorithm at each time step; the number of cores of each entity at timestamp t is expressed as: k(t) = max{k ∈ N : deg k (t) ≥ k} where deg k (t) represents the number of relationships between a certain entity and entities with at least k cores at timestamp t.
5. A method for temporal knowledge graph completion based on temporal counterfactual enhancement according to claim 1, wherein In step S4, the composite loss function is: L = L F + α·L CF + β·L D where L F is the factual log-likelihood loss, L CF is the counterfactual log-likelihood loss, L D is the inconsistency loss, and α and β are weight parameters.
6. The method for temporal knowledge graph completion based on temporal counterfactual enhancement according to claim 1, wherein The time graph neural network encoder performs entity update and relationship embedding through a message passing mechanism, specifically: Among them, represents the embedding of entity s at timestamp t+1, represents the embeddings of entities s and o at timestamp t, represents the embedding of relation r at timestamp t, represents the neighborhoods of entities s and o under timestamp t and relation r, t-GNN is a temporal graph neural network, and θ is the parameter of the temporal graph neural network.
Citation Information
Patent Citations
Knowledge graph completion method fusing weight and tense information
CN116304089A
Security entity knowledge graph relation reasoning method and device
CN116701651A