Knowledge graph inference method based on double-view adaptive contrast learning
Through the dual-view adaptive contrast learning method, combined with local and global encoder, the local-global hard negative sample perception contrast learning module is used to solve the problem of insufficient noise processing and historical information capture in timing knowledge graph inference, and improve the model's lucidity Strong and predictive performance.
Patent Information
- Application Number
- CN202411197198.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-28
- Publication Date
- 2024-12-20
AI Technical Summary
Existing time-series knowledge graph inference methods are insufficient in dealing with noise and capturing critical historical information to effectively explore the adaptive balance between historical impact and potential future events contained in global knowledge.
Using a method based on dual-view adaptive contrast learning, a historical representation is generated through local and global encoders, and a local-global hardship negative sample-aware contrast learning module is introduced to enhance the anti-noise capability of the model and fuse local and global information for entity prediction.
The prediction performance of the timing knowledge graph inference model in complex scenarios is improved, and the prediction performance of the timing knowledge graph inference model is maintained with high accuracy, especially when historical data contains noise or lacks direct correlation information, which significantly improves robustness and accuracy.
Smart Images

Figure CN119168061A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of temporal knowledge graph reasoning, and specifically to a knowledge graph reasoning method based on dual-view adaptive contrast learning. Background Art
[0002] Temporal Knowledge Graph (TKG) represents dynamic facts as quadruple of the form (subject, relation, object, time), which is actually a sequence of KG snapshots with their respective timestamps. TKG reasoning aims to predict unknown facts by modeling historical KG snapshots, which involves two reasoning settings: interpolation and extrapolation. The interpolation setting focuses on completing the missing facts in history, while the extrapolation setting aims to predict facts that will occur in the future. In recent years, with the deepening of research on TKG reasoning, the extrapolation task has attracted great significance due to its superior performance in predicting future facts and its wide application value in event prediction, risk assessment, traffic flow prediction, etc.
[0003] Furthermore, accurate predictions of future facts require a comprehensive understanding of the development patterns of historical facts. Based on human cognition of the development of historical facts, many existing studies on TKG extrapolation are aimed at learning the repetitive and cyclical patterns of facts through global historical information, and modeling the evolutionary patterns of adjacent facts through local historical information. However, the above studies only focus on directly related history. They ignore the interactions and periodic semantics within timestamps and cannot effectively explore the adaptive balance between historical influences and potential future events contained in global knowledge. Therefore, this patent proposes a knowledge graph reasoning method based on dual-view adaptive contrastive learning, which can fuse local and global historical information in temporal knowledge graph reasoning tasks, and improve the model's noise resistance through adaptive negative sample weight-aware contrastive learning to provide more robust reasoning results. Summary of the invention
[0004] The purpose of the present invention is to solve the shortcomings of existing temporal knowledge graph reasoning methods in dealing with noise and capturing key historical information, and the problem of being unable to effectively explore the adaptive balance between historical influences and potential future events contained in global knowledge. To this end, the present invention proposes a knowledge graph reasoning method based on dual-view adaptive contrastive learning, which includes two encoders, local and global: the local encoder models the historical information of neighboring time segments through a relational graph convolutional network and a recurrent neural network to generate a local historical representation; the global encoder generates a global historical representation by sampling a historical query subgraph and using a relational graph convolutional network to model global information. In order to enhance the anti-interference ability of the model, the present invention designs a local-global difficult negative sample-aware contrastive learning module, which optimizes the robustness of the model to noise by mining the gradient contribution information of different negative samples and adding it to the training to maximize the similarity between local and global representations. Entity prediction is performed by fusing local and global representations, and the entity with the highest score is selected as the prediction result through a scoring function.
[0005] The present invention can effectively improve the prediction performance of the temporal knowledge graph reasoning model in complex scenarios, and can still maintain a high level of reasoning accuracy when historical data contains noise or lacks directly related information, thereby solving the problems mentioned in the above background technology.
[0006] To achieve the above object, the present invention provides the following technical solutions:
[0007] A knowledge graph reasoning method based on dual-view adaptive contrast learning includes the following steps:
[0008] Step S1 0: Obtain a set of four-tuples from the data set, construct a dynamic knowledge graph data set, and perform time segmentation to form a time series snapshot set, generate a time knowledge graph snapshot and query samples;
[0009] Step S20: Create a local history information encoder to generate entity and relationship representations of the local history;
[0010] Step S30: Create a global history information encoder, construct a query subgraph across timestamp history periods, and generate entity and relationship representations of the global history;
[0011] Step S40: performing comparative learning on the local historical information representation and the global historical information representation obtained in step S20 and step S30;
[0012] Step S50: using the global entity embedding representation and the local entity embedding representation obtained in step S20 and step S30, entity prediction is performed through a scoring function;
[0013] In the above scheme, step 10 includes the following steps:
[0014] Step S101, obtain a set of four tuples (subject, relationship, object, time) containing timestamps from the data set, and construct the original dynamic knowledge graph data set TKG set ;
[0015] Step S102: TKG is checked according to the timestamp. set Segmentation is performed, and the quadruple of each time point is extracted to generate the corresponding time snapshot G t , forming a time series snapshot set snapshot set = {G1, G2, ..., G |T|}, each snapshot represents the knowledge graph structure at that point in time;
[0016] Step S103: for each time snapshot G t ,For each quadruple, a corresponding reverse triple (object, inverse of the relation, subject) is generated.,The triples extracted from the historical subgraph are used as the forward query samples.,The reverse query samples are generated by exchanging the subject and object in the forward triple,and adding the number of the relation to the total number of relations to represent the reverse relation.
[0017] Get a more complete set of query samples;
[0018] Step S104: a two-stage forward propagation strategy is adopted in the model training process: first, the original snapshot set snapshot set Perform forward propagation to predict the entity relationship of the forward query; then in the second stage, the inverse snapshot set set After forward propagation, the obtained historical subgraph snapshot list contains multiple extended snapshot sets in the original time order.
[0019] In the above scheme, step 20 includes the following steps:
[0020] Step S201: It is known that each KG snapshot G = {G1, G2, ..., G |T|} is a directed multi-relation graph, which is a set of valid facts at time t. Facts or events are represented as four-tuples (s, r, o, t), where the main entity s∈E and the object entity i∈E are connected by the relationship r∈R at time t∈T, where E represents the entity set, R represents the relationship set, and T represents the timestamp set;
[0021] Step S202: for each K snapshot at each timestamp, update the entity representation by capturing the spatial structure semantic information between concurrent facts. Encode the time value information to obtain The moment-to-moment dynamic entity embedding is represented as Where W0 is the linear transformation matrix, d represents the eigenvector of the entity, and w t represents the weight matrix, b t represents the bias term, represents the dynamic embedding matrix of all entities at timestamp t, h t represents the dynamic embedding vector of the entity at timestamp t, The meaning of is the time code calculated by the periodic activation function, Indicates that h t and Connect into a longer vector. The symbol “||” represents the vector concatenation operation.
[0022] Step S203, the RGCN-based entity aggregator captures the structural dependencies between concurrent facts, and obtains the embedding representation of entity o and relationship r at the lth layer under the message passing framework as:
[0023]
[0024] where c O is the normalization constant, and is the parameter of the aggregated features and self-loop of the lth layer, σ1(·) is the RReLU activation function; represents the embedding vector of the main entity s at the lth layer of the RGCN local entity aggregator at timestamp t, r (l) represents the embedding vector of relation r at layer l, Represents the embedding vector of object entity o at timestamp t in the lth layer of the RGCN local entity aggregator, RGCN Local (*) represents the local relation graph convolutional network, Indicates existence, e s represents the source entity, r represents the relationship, e o represents the target entity, E t represents the edge set at time step t;
[0025] Step S204, based on the gated recurrent unit, the representation of the entity is gradually updated to model the sequential dependency of entities and relations in the KG snapshot sequence of the most recent m timestamps:
[0026]
[0027] in is the entity embedding matrix after the aggregation of the KG snapshot at time t, GRU E nt(*) represents the entity aggregator of the gated recurrent unit, which is used to update the representation of the entity. t+1 represents the entity embedding matrix of the knowledge graph snapshot at timestamp t+1, H tThe raw entity embedding matrix representing the knowledge graph snapshot at timestamp t;
[0028] For the relationship between entities, the time gate unit is used to update the relationship embedding at time t as follows:
[0029] R t+1 =U t ·R′ t +(1-U t )·R t
[0030] R t+1 represents the relation embedding after the time gate unit updates at timestamp t+1;
[0031] U t represents the gating vector of the time gate unit, which is updated at timestamp t;
[0032] R′ t represents the relation embedding after the time gate unit updates at timestamp t;
[0033] R t represents the original relation embedding at timestamp t;
[0034] Step S205: In order to make full use of the historical facts related to the query in the KG snapshot to predict the relevant information of the query, the importance of different KG snapshots to the query is distinguished by the entity-aware attention mechanism α i :
[0035]
[0036] Where σ2 represents the Sigmoid activation function, W5 represents a linear transformation matrix for processing input, represents the historical time step t q-m+i The aggregation of all related entities and relationships, t q represents a specific time step, Indicates that at time step t q and events q The relevant hidden state;
[0037] Model the KG snapshot information related to the query of the most recent timestamp, expressed as:
[0038]
[0039] in Local entity representation via entity-aware attention mechanism, where Indicates that at time step t q The original hidden state of Indicates that at time step tq -m+i's original hidden state, is the final generated local entity representation, R t+1 The final generated local relation representation.
[0040] In the above scheme, step 30 includes the following steps:
[0041] Step S301, for First, the single-hop historical facts containing the query subject entity s in a given query are Sampling is performed, and then the one-hop target object entity associated with the query entity-relationship pair is extracted, and the one-hop fact containing the one-hop target object entity is continued. Sampling is performed by integrating the two collected historical fact sets to obtain the historical static subgraph most relevant to the query, represented as
[0042] Step S302: Modeling the time-related global history graph to obtain a time graph G TCG ={E TCG , R TCG}, E TCG Indicates the time node, R TCG Represents the relationship between time nodes, obtains the relationship of four time granularities related to the query on the dataset, and updates t″ through another RGCN t :
[0043] t″ t =σ(W r t′ t +b t )
[0044] Where σ is the cosine activation function, is the learnable weight, t′ t is the propagation result of the time graph at the time node, b t is the bias, t″ t Embedding time information;
[0045] Step S303, updating the global entity representation by modeling the structural semantics and temporal information representation of the global historical query subgraph
[0046]
[0047] in represents the output embedding of the RGCN layer l entity that fuses static structure information and temporal embedding information. Global (*) Graph convolutional network representing global relations, In Figure g, the source entity e sIn the hidden state of layer l, r l represents the representation of relation r at level l, In Figure g, the source entity e o The hidden state at layer l;
[0048] Step S304: for global historical information, learn the historical fact representation related to the query through the entity-aware attention mechanism
[0049]
[0050] in represents the final global representation of the entity obtained by the global entity-aware attention encoder, σ represents the softmax activation function, W6 represents a weight matrix, represents the aggregated hidden state in graph g, σ is the weight output by the gating mechanism, R is the original relation embedding, and h represents the current hidden state.
[0051] In the above scheme, step 40 includes the following steps:
[0052] Step S401, the final local entity representation and the final global representation obtained in step S205 and step S304 are projected and expressed as zt:t through MLP normalization.
[0053]
[0054] Where MLP represents a multi-layer perceptron, r t represents the relationship at time step t, z t is the embedding of the local query at timestamp t, z g is the embedding of the global query. The local and global representations of the same query at timestamp t are used as positive pairs and are denoted as (z t,i , z g,i ), the local and global representations of different queries are used as negative pairs and are denoted as (z t,i , z g,k );
[0055] Step S402: for each negative sample z q,k , distinguishing difficult negative samples through an adaptive learning function of weights:
[0056]
[0057] Where W (1) and W (2) is the learnable parameter matrix of the two-layer MLP, σ (1) is the Tanh activation function, σ (1) is the Sigmoid activation function, which is used to convert the weight Limited to between 0 and 1, b (1) and b (2) represents the bias term, z g,i represents a positive sample, z g,k represents a negative sample, || represents the concatenation operation of the vector;
[0058] Step S403, based on the cosine similarity, the similarity between the sample pairs is evaluated, and the loss function of the negative sample gradient contribution contrast learning is adaptively adjusted as follows:
[0059]
[0060] Among them, τ is a hyperparameter defined by humans, which is used to adjust the uniformity of the distribution of data representation in the vector space. and They represent the query set and the number of queries at timestamp t respectively; exp represents the exponential function with base e;
[0061] Step S404, L lg The goal is to make the representations of the same category closer, enhancing the common essential features of the local and global encoders required to predict the query, thereby alleviating the impact of noise and improving the robustness of the model;
[0062] The supervision loss L is obtained by using the representation generated by the global encoder as an anchor gl , the final supervised contrast loss is calculated as:
[0063] L cl =(L lg +L gl ) / 2.
[0064] In the above scheme, step 50 includes the following steps:
[0065] Step S501, using ConvTransE at timestamp t q Perform entity prediction tasks, and the entity prediction score function is expressed as:
[0066]
[0067] where λ is a variable factor set to [0, 1] that weighs the global and local representations of an entity, It means that at time step t q The relationship between r and e q represents the target entity in the query, r q represents the relationship associated with the target entity, e represents the candidate entity, and q represents the target entity associated with the entity under the given relationship and timestamp;
[0068] In step S502, the entity prediction task can be regarded as a multi-label learning problem. The entity prediction loss and the contrast loss are trained synchronously. The final loss function is calculated as:
[0069]
[0070] Where φ(e s , r, e, t) is the entity prediction probability score, e s represents the known entity in the query, r represents the relationship with the known entity, e represents the candidate entity, t represents the timestamp, is the true discriminant label of the event, |E| is the set of all nodes in the graph, which is 1 if the fact occurs and 0 otherwise.
[0071] The beneficial effects of the present invention are:
[0072] The purpose of the present invention is to solve the problems that existing research ignores the importance of historical information related to the query in the process of encoding historical facts, lacks the basic pattern of capturing important historical facts related to the query in the KG snapshot, and does not pay attention to the robustness of the model, which leads to the inability of model learning to fully utilize the periodic information data between timestamps and is easily disturbed by input noise, which in turn leads to poor model generalization.
[0073] Therefore, the present invention creates a local history information encoder and a global history information encoder based on the conflict early warning integrated system event database, generates local history and global history dual-view entity representations to capture key history information related to the query. Through adaptive negative sample weighted contrast learning, the fusion of local and global history information is better guided and the anti-interference ability is enhanced. Thus, the problems mentioned in the above background technology are solved. BRIEF DESCRIPTION OF THE DRAWINGS
[0074] Figure 1 The figure is a flow chart of the steps of the method of the present invention. DETAILED DESCRIPTION
[0075] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0076] See also Figure 1 , the present invention provides a technical solution:
[0077] The present invention provides the following technical solution: a knowledge graph reasoning method based on dual-view adaptive contrast learning. The specific steps are to use the time series information prediction of global political events as an example. The specific steps of applying the small sample relationship extraction method to the field of political event reasoning are as follows:
[0078] Step 1: Generate a temporal knowledge graph snapshot and query samples based on the Conflict Early Warning Integrated System event database;
[0079] Step 1-1, obtain the four-tuple set (subject, relationship, body, time) containing timestamps from the dataset and construct the original dynamic knowledge graph dataset TKG set . Split according to timestamp and generate corresponding time snapshots Form a time series snapshot collection snapshot set = {G1, G2, ..., G |T|}, each snapshot represents the knowledge graph structure at that point in time.
[0080] Step 1-2, for each time snapshot G t , for each quadruple, a corresponding reverse triple (object, inverse of the relation, subject) is generated. The triple extracted from the history subgraph is used as a forward query sample. The reverse query sample is generated by exchanging the subject and object in the forward triple and adding the relation number to the total number of relations to represent the reverse relation. A more complete query sample set is obtained.
[0081] Steps 1-3: To avoid data leakage during model training, a two-stage forward propagation strategy is adopted: first, the original snapshot set snapshot set Perform forward propagation to predict the entity relationship of the forward query; then in the second stage, the inverse snapshot set set Perform forward propagation.
[0082] Step 2: Create a local history information encoder to generate entity and relationship representations of local history;
[0083] Step 2-1, it is known that each KG snapshot G = {G1, G2, ..., G |T|} is a directed multi-relation graph, which is a set of valid facts at time t. Facts (or events) are represented as four-tuples (s, r, o, t), where the main entity s∈ε, the object entity o∈ε, and the time Through relationship connect.
[0084] Step 2-2: For each K snapshot at each timestamp, update the entity representation by capturing the spatial structure semantic information between concurrent facts. Encode the time value information to obtain The moment-to-moment dynamic entity embedding is represented as Where W0 is the linear transformation matrix, d represents the eigenvector of the entity, and w t represents the weight matrix, b t represents the bias term, represents the dynamic embedding matrix of all entities at timestamp t, h t represents the dynamic embedding vector of the entity at timestamp t, The meaning of is the time code calculated by the periodic activation function, Indicates that h t and Connect into a longer vector. The symbol “||” represents the vector concatenation operation.
[0085] In step 2-3, the RGCN-based entity aggregator captures the structural dependencies between concurrent facts, and the embedding representation of entity o and relation r at the lth layer in the message passing framework is obtained as:
[0086]
[0087] where c O is the normalization constant, and is the parameter of the aggregated features and self-loop of the lth layer, σ1(·) is the RReLU activation function; represents the embedding vector of the main entity s at the lth layer of the RGCN local entity aggregator at timestamp t, r (l) represents the embedding vector of relation r at layer l, Represents the embedding vector of object entity o at timestamp t in the lth layer of the RGCN local entity aggregator, RGCN Local (*) represents the local relation graph convolutional network, Indicates existence, e s represents the source entity, r represents the relationship, e o represents the target entity, E t represents the edge set at time step t;
[0088] Step 2-4, based on the gated recurrent unit, gradually updates the entity representation and models the sequential dependencies between entities and relations in the KG snapshot sequence of the last m timestamps:
[0089]
[0090] in is the entity embedding matrix after the aggregation of the KG snapshot at time t, GRU Ent (*) represents the entity aggregator of the gated recurrent unit, which is used to update the representation of the entity, H t+1represents the entity embedding matrix of the knowledge graph snapshot at timestamp t+1, H t The raw entity embedding matrix representing the knowledge graph snapshot at timestamp t;
[0091] For the relationship between entities, the time gate unit is used to update the relationship embedding at time t as follows:
[0092] R t+1 =U t ·R′ t +(1-U t )·R t
[0093] R t+1 represents the relation embedding after the time gate unit updates at timestamp t+1;
[0094] U t represents the gating vector of the time gate unit, which is updated at timestamp t;
[0095] R′ t represents the relation embedding after the time gate unit updates at timestamp t;
[0096] R t represents the original relation embedding at timestamp t;
[0097] Step 2-5: In order to make full use of the historical facts related to the query in the KG snapshot to predict the relevant information of the query, the entity-aware attention mechanism is used to distinguish the importance of different KG snapshots for the query. i :
[0098]
[0099] Where σ2 represents the Sigmoid activation function, W5 represents a linear transformation matrix for processing input, represents the historical time step t q-m+i The aggregation of all related entities and relationships, t q represents a specific time step, Indicates that at time step t q and events q The relevant hidden state;
[0100] Model the KG snapshot information related to the query of the most recent timestamp, expressed as:
[0101]
[0102] in Local entity representation via entity-aware attention mechanism, where Indicates that at time step tq The original hidden state of Indicates that at time step t q -m+i's original hidden state, is the final generated local entity representation, R t+1 The final generated local relation representation.
[0103] Step 3: Create a global history information encoder, construct a query subgraph across timestamp history periods, and generate entity and relationship representations of the global history;
[0104] Step 3-1, for First, the single-hop historical facts containing the query subject entity s in a given query are Sampling is performed, and then the one-hop target object entity associated with the query entity-relationship pair is extracted, and the one-hop fact containing the one-hop target object entity is continued. Sampling is performed by integrating the two collected historical fact sets to obtain the historical static subgraph most relevant to the query, represented as
[0105] Step 3-2: Model the time-related global history graph to obtain the time graph G TCG ={E TCG , R TCGG},
[0106] E TCG Indicates the time node, R TCG Represents the relationship between time nodes, obtains the relationship of four time granularities related to the query on the dataset, and updates t″ through another RGCN t :
[0107] t″ t =σ(W r t′ t +b t )
[0108] Where σ is the cosine activation function, is the learnable weight, t′ t is the propagation result of the time graph at the time node, b t is the bias, t″ t Embed time information.
[0109] Step 3-3, update the global entity representation by modeling the structural semantics and temporal information representation of the global historical query subgraph
[0110]
[0111] in represents the output embedding of the RGCN layer l entity in the fusion of static structure information and temporal embedding information, RGC N Global (*) Graph convolutional network representing global relations, In Figure g, the source entity e s In the hidden state of layer l, r l represents the representation of relation r at level l, In Figure g, the source entity e o The hidden state at layer l.
[0112] Step 3-4: For global historical information, learn the historical fact representation related to the query through the entity-aware attention mechanism
[0113]
[0114] in represents the final global representation of the entity obtained by the global entity-aware attention encoder, σ represents the softmax activation function, W6 represents a weight matrix, represents the aggregated hidden state in graph g, σ is the weight output by the gating mechanism, R is the original relation embedding, and h represents the current hidden state.
[0115] Step 4: Compare and learn the local historical information representation and the global historical information representation obtained in steps 2 and 3;
[0116] Step 4-1: The local representation and global query representation obtained in steps 2-4 and 3-4 are projected and normalized by MLP to be expressed as Where Z t is the embedding of the local query at timestamp t, Z g is the embedding of the global query. The local and global representations of the same query at timestamp t are used as positive pairs and are denoted as (z t,i , z g,i ), the local and global representations of different queries are used as negative pairs and are denoted as (z t,i , z g,k ).
[0117] Step 4-2, for each negative sample z g,k , distinguishing difficult negative samples through an adaptive learning function of weights:
[0118]
[0119] Where W (1) and W (2) is the learnable parameter matrix of the two-layer MLP, σ (1) is the Tanh activation function, σ(1) Is the Sigmoid activation function, used to weight Limited to between 0 and 1, b (1) and b (2) represents the bias term, z g,i represents a positive sample, z g,k represents a negative sample, || represents the concatenation operation of the vector;
[0120] Step 4-3, based on the cosine similarity to evaluate the similarity between sample pairs, the loss function of adaptively adjusting the negative sample gradient contribution contrast learning is as follows:
[0121]
[0122] Among them, τ is a hyperparameter defined by humans, which is used to adjust the uniformity of the distribution of data representation in the vector space. and They represent the query set and the number of queries at timestamp t respectively; exp represents the exponential function with e as the base.
[0123] Step 4-4, The goal is to make the representations of the same category closer, enhancing the common essential features of the local and global encoders required to predict the query, thereby alleviating the impact of noise and improving the robustness of the model. Similarly, the supervision loss L can be obtained by using the representation generated by the global encoder as an anchor gl The final supervised contrast loss is calculated as
[0124] L cl =(L lg +L gl ) / 2.
[0125] Step 5: Use the global entity embedding representation and local entity embedding representation obtained in steps 2 and 3 to perform entity prediction through a scoring function;
[0126] Step 5-1, use ConvTransE at timestamp t h Perform entity prediction tasks, and the entity prediction score function is expressed as:
[0127]
[0128] where λ is a variable factor set to [0, 1] that weighs the global and local representations of an entity, It means that at time step t q The relationship between r and e q represents the target entity in the query, r q represents the relationship associated with the target entity, e represents the candidate entity, and q represents the target entity associated with the entity under the given relationship and timestamp;
[0129] Step 5-2, the entity prediction task can be regarded as a multi-label learning problem. The entity prediction loss and the contrast loss are trained simultaneously. The final loss function is calculated as:
[0130]
[0131] Where φ(e s , r, e, t) is the entity prediction probability score, e s represents the known entity in the query, r represents the relationship with the known entity, e represents the candidate entity, t represents the timestamp, is the true discriminant label of the event, |E| is the set of all nodes in the graph, which is 1 if the fact occurs and 0 otherwise.
[0132] The knowledge graph reasoning method based on dual-view adaptive weighted negative sample contrast learning includes a local history information encoder module, a global history information encoder module, and an adaptive negative sample weighting module, specifically:
[0133] Create a local history information encoder to generate entity and relationship representations of local history;
[0134] Create a global history information encoder, build a query subgraph across timestamp history periods, and generate entity and relationship representations of the global history:
[0135] A dual-view adaptive negative sample weighted contrast learning mechanism based on local historical information representation and global historical information representation is established to identify highly correlated local and global features of entities and relationships at the query level, so that the local and global representations of the same query are as close as possible, thereby promoting mutual learning between encoders. A module that adaptively learns the weights of negative samples is further used to make negative samples more personalized and have stronger learning capabilities for noisy data sets. Improve the performance of temporal knowledge graph reasoning.
[0136] The present invention creates a local history information encoder and a global history information encoder based on the conflict early warning integrated system event database, generates local history and global history dual-view entity representations to capture key history information related to the query, and better guides the fusion of local and global history information and enhances anti-interference capabilities through adaptive negative sample weighted contrast learning.
[0137] The knowledge graph reasoning method based on dual-view adaptive weighted negative sample contrast learning proposed in this paper solves the key problems in temporal knowledge graph reasoning through the following technical means:
[0138] 1. Local and global historical information encoding: The present invention creates local and global historical information encoders to capture neighboring time segments and global historical information respectively. The local encoder uses a relational graph convolutional network and a recurrent neural network to model the historical information of neighboring time segments and generate a local historical representation; the global encoder generates a global historical representation by sampling historical query subgraphs and using a relational graph convolutional network to model global information. This dual-view representation method can provide a more comprehensive understanding of the laws of historical development.
[0139] 2. Improved model robustness: Through adaptive negative sample weighted contrastive learning, the model can better identify and utilize key historical information and reduce the impact of noise. Specifically, a local-global difficult negative sample-aware contrastive learning module is introduced to mine different negative sample gradient contribution information for training, maximize the similarity between local and global representations, and optimize the model's robustness to noise.
[0140] 3. Entity-aware attention mechanism: The present invention uses entity-aware attention mechanism to distinguish the importance of different KG snapshots for queries. In this way, the model can more effectively use historical facts related to the query in the KG snapshot to model the relevant information of the predicted query.
[0141] 4. Extrapolation task performance optimization: This method is particularly suitable for extrapolation tasks that predict future events. It can achieve more accurate predictions in extrapolation tasks. This has significant application value in the fields of event prediction and risk assessment.
[0142] Compared with the existing technology, the present invention performs better in processing noise and capturing key historical information, especially when the historical data contains noise or lacks directly related information, it can still maintain a high inference accuracy. In addition, the inference performance of this method in complex scenarios is also significantly improved.
[0143] Although the present invention has been described in detail with reference to the aforementioned embodiments, it is still possible for those skilled in the art to modify the technical solutions described in the aforementioned embodiments, or to make equivalent substitutions for some of the technical features therein. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A knowledge graph reasoning method based on dual-view adaptive contrast learning, characterized in that: The following steps are involved: Step S10: Obtain a set of four-tuples from the data set, construct a dynamic knowledge graph data set, and perform time segmentation to form a time series snapshot set, generate a time knowledge graph snapshot and query samples; Step S20: Create a local history information encoder to generate entity and relationship representations of the local history; Step S30: Create a global history information encoder, construct a query subgraph across timestamp history periods, and generate entity and relationship representations of the global history: Step S40: performing comparative learning on the local historical information representation and the global historical information representation obtained in step S20 and step S30; Step S50: Using the global entity embedding representation and the local entity embedding representation obtained in step S20 and step S30, entity prediction is performed through a scoring function.
2. According to claim 1, a knowledge graph reasoning method based on dual-view adaptive contrast learning is characterized in that: Step 10 includes the following steps: Step S101, obtain a set of four tuples (subject, relationship, object, time) containing timestamps from the data set, and construct the original dynamic knowledge graph data set TKG set ; Step S102: TKG set Segmentation is performed, and the quadruple of each time point is extracted to generate the corresponding time snapshot G t , forming a time series snapshot set snapshot set = {G1, G2, ..., G |T| }, each snapshot represents the knowledge graph structure at that point in time; Step S103: for each time snapshot G t , Generate a corresponding reverse triplet (object, inverse of the relationship, subject) for each quadruple, and extract the triplet from the history subgraph as the forward query sample. Generate a reverse query sample by swapping the subject and object in the forward triplet and adding the relationship number to the total number of relationships to represent the reverse relationship. Get a more complete query sample set; Step S104: a two-stage forward propagation strategy is adopted in the model training process: first, the original snapshot set snapshot set Perform forward propagation to predict the entity relationship of the forward query; then in the second stage, the inverse snapshot set set After forward propagation, the obtained historical subgraph snapshot list contains multiple extended snapshot sets in the original time order.
3. According to claim 1, a knowledge graph reasoning method based on dual-view adaptive contrast learning is characterized in that: Step 20 includes the following steps: Step 5201, it is known that each KG snapshot G = {G1, G2, ..., G|T | } is a directed multi-relation graph, which is a set of valid facts at time t. Facts or events are represented as four-tuples (s, r, o, t), where the main entity s∈E and the object entity o∈E are connected by the relationship r∈R at time t∈T, where E represents the entity set, R represents the relationship set, and T represents the timestamp set; Step S202: for each K snapshot at each timestamp, update the entity representation by capturing the spatial structure semantic information between concurrent facts. Encode the time value information to obtain The moment-to-moment dynamic entity embedding is represented as Where W0 is the linear transformation matrix, d represents the eigenvector of the entity, and w t represents the weight matrix, b t represents the bias term, represents the dynamic embedding matrix of all entities at timestamp t, h t represents the dynamic embedding vector of the entity at timestamp t, The meaning of is the time code calculated by the periodic activation function, Indicates that h t and Connect to form a longer vector. The symbol "||" represents the vector concatenation operation. Step S203, the RGCN-based entity aggregator captures the structural dependencies between concurrent facts, and obtains the embedding representation of entity o and relationship r at the lth layer under the message passing framework as: where c O is the normalization constant, and is the parameter of the l-th layer aggregation feature and self-loop, σ1(·) is the RReLU activation function; represents the embedding vector of the main entity s at the lth layer of the RGCN local entity aggregator at timestamp t, r (l) represents the embedding vector of relation r at layer l, Represents the embedding vector of object entity o at timestamp t in the lth layer of the RGCN local entity aggregator, RGCN Local (*) represents the local relation graph convolutional network, Indicates existence, e s represents the source entity, r represents the relationship, e o represents the target entity, E t represents the edge set at time step t; Step S204, based on the gated recurrent unit, the representation of the entity is gradually updated to model the sequential dependency of entities and relations in the KG snapshot sequence of the most recent m timestamps: in is the entity embedding matrix after the aggregation of the KG snapshot at time t, GRU E nt(*) represents the entity aggregator of the gated recurrent unit, which is used to update the representation of the entity. t+1 represents the entity embedding matrix of the knowledge graph snapshot at timestamp t+1, H t The raw entity embedding matrix representing the knowledge graph snapshot at timestamp t; For the relationship between entities, the time gate unit is used to update the relationship embedding at time t as follows: R t+1 =U t ·R′ t +(1-U t )·R t R t+1 represents the relation embedding after the time gate unit updates at timestamp t+1; U t represents the gating vector of the time gate unit, which is updated at timestamp t; R′ t represents the relation embedding after the time gate unit updates at timestamp t; R t represents the original relation embedding at timestamp t; Step S205: In order to make full use of the historical facts related to the query in the KG snapshot to predict the relevant information of the query, the importance of different KG snapshots to the query is distinguished by the entity-aware attention mechanism α i : Where σ2 represents the Sigmoid activation function, W5 represents a linear transformation matrix for processing input, represents the historical time step t q-m+i The aggregation of all related entities and relationships, t q represents a specific time step, Indicates that at time step t q and events q The relevant hidden state; Model the KG snapshot information related to the query of the most recent timestamp, expressed as: in Local entity representation via entity-aware attention mechanism, where Indicates that at time step t q The original hidden state of Indicates that at time step t q -m+i's original hidden state, is the final generated local entity representation, R t+1 The final generated local relation representation.
4. The knowledge graph reasoning method based on dual-view adaptive contrast learning according to claim 3 is characterized in that: Step 30 includes the following steps: Step S301, for First, the single-hop historical facts containing the query subject entity s in a given query are Sampling is performed, and then the one-hop target object entity associated with the query entity-relationship pair is extracted, and the one-hop fact containing the one-hop target object entity is continued. Sampling is performed by integrating the two collected historical fact sets to obtain the historical static subgraph most relevant to the query, represented as Step S302: Modeling the time-related global history graph to obtain a time graph G TCG G={E TCG , R TCG }, E TCG Indicates the time node, R TCG Represents the relationship between time nodes, obtains the relationship of four time granularities related to the query on the dataset, and updates t″ through another RGCN t : t″ t =σ(W r t′ t +b t ) Where σ is the cosine activation function, is the learnable weight, t′ t is the propagation result of the time graph at the time node, b t is the bias, t″ t Embedding time information; Step S303, updating the global entity representation by modeling the structural semantics and temporal information representation of the global historical query subgraph in represents the output embedding of the RGCN layer l entity that fuses static structure information and temporal embedding information. Global (*) Graph convolutional network representing global relations, In Figure g, the source entity e s In the hidden state of layer l, r l represents the representation of relation r at level l, In Figure g, the source entity e o The hidden state at layer l; Step S304: for global historical information, learn the historical fact representation related to the query through the entity-aware attention mechanism in represents the final global representation of the entity obtained by the global entity-aware attention encoder, σ represents the softmax activation function, W6 represents a weight matrix, represents the aggregated hidden state in graph g, σ is the weight output by the gating mechanism, R is the original relation embedding, and h represents the current hidden state.
5. The knowledge graph reasoning method based on dual-view adaptive contrast learning according to claim 4 is characterized in that: Step 40 includes the following steps: Step S401: The final local entity representation and the final global representation obtained in step S205 and step S304 are projected and expressed as z by MLP normalization. t : Where MLP represents a multi-layer perceptron, r t represents the relationship at time step t, z t is the embedding of the local query at timestamp t, z g is the embedding of the global query. The local and global representations of the same query at timestamp t are used as positive pairs and are denoted as (z t,i , z q,i ), the local and global representations of different queries are used as negative pairs and are denoted as (z t,i , z g,k ); Step S402: for each negative sample z g,k , distinguishing difficult negative samples through an adaptive learning function of weights: Where W (1) and W (2) is the learnable parameter matrix of the two-layer MLP, σ (1) is the Tanh activation function, σ (1) Is the Sigmoid activation function, used to weight Limited to between 0 and 1, b (1) and b (2) represents the bias term, z g,i represents a positive sample, z g,k represents a negative sample, || represents the concatenation operation of the vector; Step S403, based on the cosine similarity, the similarity between the sample pairs is evaluated, and the loss function of the negative sample gradient contribution contrast learning is adaptively adjusted as follows: Among them, τ is a hyperparameter defined by humans, which is used to adjust the uniformity of the distribution of data representation in the vector space. and They represent the query set and the number of queries at timestamp t respectively; exp represents the exponential function with base e; Step S404, L lg The goal is to make the representations of the same category closer, enhancing the common essential features of the local and global encoders required to predict the query, thereby alleviating the impact of noise and improving the robustness of the model; The supervision loss L is obtained by using the representation generated by the global encoder as an anchor gl , the final supervised contrast loss is calculated as: L cl =(L lg +L gl ) / 2.
6. The knowledge graph reasoning method based on dual-view adaptive contrast learning according to claim 5 is characterized in that: Step 50 includes the following steps: Step S501, using ConvTransE at timestamp t g Perform entity prediction tasks, and the entity prediction score function is expressed as: where λ is a variable factor set to [0, 1] that weighs the global and local representations of an entity, It means that at time step t q The relationship between r and e q represents the target entity in the query, r q represents the relationship associated with the target entity, e represents the candidate entity, and q represents the target entity associated with the entity under the given relationship and timestamp; In step S502, the entity prediction task can be regarded as a multi-label learning problem. The entity prediction loss and the contrast loss are trained synchronously. The final loss function is calculated as: Where φ(e s , r, e, t) is the entity prediction probability score, e s represents the known entity in the query, r represents the relationship with the known entity, e represents the candidate entity, t represents the timestamp, is the true discriminant label of the event, |E| is the set of all nodes in the graph, which is 1 if the fact occurs and 0 otherwise.
Citation Information
Cited By
Representation learning method of time sequence knowledge graph based on local-global feature fusion
CN121787592A
Time knowledge graph question-answering system based on constraint perception and graph reasoning
CN122065955A
Time sequence knowledge graph extrapolation method based on global history and local evolution
CN122572610A
