Local-global comparison embedded time sequence knowledge graph completion method

By employing a local-global contrastive embedding method, the problem of noise interference during the training process of temporal knowledge graph models is solved. Through local time-aware self-attention encoding and multi-head self-attention mechanism, temporal dependencies are captured, thereby improving the prediction accuracy and robustness of the model.

CN121920498APending Publication Date: 2026-04-24KUNMING UNIV OF SCI & TECH
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
KUNMING UNIV OF SCI & TECH
Filing Date
2026-03-05
Publication Date
2026-04-24

AI Technical Summary

Technical Problem

During training, the temporal knowledge graph model is subjected to additional noise interference, resulting in poor performance.

Method used

A local-global contrastive embedding method is adopted. Time series data is collected by sensors, preprocessed, and time-aware embedding vectors are extracted using local time-aware self-attention encoding and multi-head self-attention mechanism. Combined with static embedding, local and global representations are constructed and auxiliary loss functions are generated through contrastive learning to complete the link prediction task.

Benefits of technology

It enhances the model's understanding of temporal order, captures the dynamic changes of entities and relationships in the time dimension, automatically learns temporal dependencies, and integrates static semantic information with temporal evolution characteristics, thereby improving the model's prediction accuracy and robustness.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121920498A_ABST
    Figure CN121920498A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of perception of self-attention, in particular to a local-global contrast embedded time sequence knowledge graph completion method. The method comprises the following steps: collecting time sequence data through a sensor, and carrying out preprocessing operation on the collected time sequence data; performing local time sequence modeling on entities and relationships through local time perception self-attention coding based on the preprocessed time sequence data, and extracting a time perception embedded vector; fusing static embedding and time-aware embedding vectors based on feature global coding to obtain a final entity / relation embedding vector; constructing local and global representations of the query based on local-global comparative learning, and generating an auxiliary loss function through comparative learning; and completing a link prediction task based on a decoder embedding calculation scoring function, and generating a main training loss function. Time-aware entity embedding is extracted by using a multi-head self-attention mechanism, and a time sequence dependency relationship between entities can be automatically learned.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of sensory self-attention technology, and more specifically, to a method for completing temporal knowledge graphs using local-global contrastive embedding. Background Technology

[0002] Temporal knowledge graph completion is an important research direction in the field of knowledge graphs. It aims to enrich and expand temporal knowledge graphs by predicting and filling in missing triples. These triples are usually composed of a subject, a relation, and an object, and also include time information in the temporal knowledge graph.

[0003] During training, the input data is affected by additional noise, leading to poor model performance. To address this, a temporal knowledge graph completion method based on local-global contrastive embedding is provided. Summary of the Invention

[0004] The purpose of this invention is to provide a time-series knowledge graph completion method based on local-global contrastive embedding, in order to solve the problem mentioned in the background art where input data is interfered with by additional noise during training, resulting in poor model performance.

[0005] To achieve the above objectives, the present invention aims to provide a method for time-series knowledge graph completion using local-global contrast embedding, comprising the following steps: S1. Collect time series data through sensors and perform preprocessing operations on the collected time series data; S2. Based on the preprocessed time series data, local temporal modeling of entities and relationships is performed through local time-aware self-attention encoding, and time-aware embedding vectors are extracted. S3. Based on feature global encoding, fuse static embedding and time-aware embedding vectors to obtain the final entity / relationship embedding vector; S4. Construct local and global representations of the query based on local-global contrastive learning, and generate an auxiliary loss function through contrastive learning; S5. Based on the decoder embedding, calculate the scoring function to complete the link prediction task and generate the main training loss function.

[0006] As a further improvement to this technical solution, in S1, the time series data includes time series data, query data, static entity embedding matrix data, entity set and its timestamp data.

[0007] As a further improvement to this technical solution, in step S1, time series data is collected by a sensor, and the collected time series data is preprocessed. The specific steps of the preprocessing operation are as follows: S1.1. Based on the time format parsing and conversion library, the timestamps of all data points are parsed and converted into a standard format; S1.2, Implement null value detection and processing based on null value scanning detection algorithm and interpolation technology; S1.3. Based on string normalization operations and entity alignment technology, achieve entity / relationship standardization.

[0008] As a further improvement to this technical solution, in step S2, the specific steps for performing local temporal modeling of entities and relationships based on preprocessed time-series data through local time-aware self-attention encoding and extracting time-aware embedding vectors are as follows: S2.1 Constructing the entity matrix and time position matrix ; S2.2, Entity matrix obtained based on S2.1 With time position matrix Obtain an entity matrix containing time information ; S2.3, Using a multi-head self-attention mechanism for processing Output time-aware entity embeddings ; S2.4, Based on time vector Calculate time-aware embedding vectors .

[0009] As a further improvement to this technical solution, in step S2.3, a multi-head self-attention mechanism is used for processing. Output time-aware entity embeddings The specific steps are as follows: S2.3.1, Transform the entity matrix obtained in S2.2 using a fully connected linear transformation. The mapping is represented by three different attention parameter matrices: query, key, and value. S2.3.2 Calculate the attention weights between entities using the scaling dot product attention mechanism. ; S2.3.3. Based on the entity weight matrix and the corresponding entities, a single-head attention is obtained, and the entity / relation embedding vector is obtained by multiplying the single-head attention. The mathematical expression involved in calculating the entity / relation embedding vector is as follows: ; In the formula, Indicates the number of single-head attention; Indicates the index of the current attention head; Indicates the number of entities; Indicates an index; Indicates the first The weight of each entity under the current attention head; Indicates the first A vector of values ​​for each entity.

[0010] As a further improvement to this technical solution, in S2.3.2, a scaled dot product attention mechanism is used to calculate the attention weights between entities. The specific steps are as follows: Calculate the dot product of the query attention parameter matrix and the key attention parameter matrix; The attention weights are obtained by normalizing them using the Softmax function. The mathematical expression for calculating the attention weights is as follows: ; In the formula, Indicates attention weight; Represents the normalization function; Indicates the embedding dimension; This represents the scaling factor.

[0011] As a further improvement to this technical solution, the specific steps in S3 for obtaining the final entity / relationship embedding vector based on the fusion of static embedding and time-aware embedding vectors using feature global encoding are as follows: Weighting based on time information By controlling the proportion of temporal information in entity embedding, the final time-aware entity embedding can be obtained. Then compute time-aware entity embedding The mathematical expressions involved are: ; In the formula, Represents time-aware entity embedding; Indicates the weight of time information; This indicates the embedding of the original entity.

[0012] As a further improvement to this technical solution, in step S4, the specific steps for constructing local and global representations of the query based on local-global contrastive learning and generating an auxiliary loss function through contrastive learning are as follows: S4.1 Constructing a local query representation based on a multilayer perceptron and global query representation ; S4.2, Local query representation built based on S4.1 and global query representation Construct positive sample pairs and negative sample pairs ; S4.3 Obtaining the supervised contrastive loss function based on the InfoNCE loss function , , and Then calculate the supervised contrastive loss function. The mathematical expressions involved are: ; In the formula, This represents the local-global contrastive loss function; Represent the natural logarithm function; Represents an exponential function; Indicates the first Local query representation of each sample; Indicates the first A global query representation of each sample; Indicates temperature parameter; Represents the set of indices for all negative samples. Indices representing negative samples Indicates the number of queries; S4.4, Based on supervised contrastive loss function , , and The final supervised contrastive loss function is obtained. .

[0013] As a further improvement to this technical solution, the specific steps for constructing the multilayer perceptron in S4.1 are as follows: S4.1.1 Determine the input dimension, output dimension, number of hidden layers, and number of neurons in each layer; S4.1.2 Initialize the weight matrix and bias vector ; S4.1.3. Define a nonlinear activation function based on the ReLU function; S4.1.4 Calculate the output of each layer from front to back.

[0014] As a further improvement to this technical solution, in step S5, the specific steps for calculating the scoring function based on the decoder embedding, completing the link prediction task, and generating the main training loss function are as follows: S5.1 Evaluation using DE-SimplE scoring function The rationality is then assessed. The mathematical expressions involved are: ; In the formula, ; ; ; In the formula, Represents the scoring function; Indicates head entity embedding; Indicates relational embedding; This indicates an enhanced tail entity embedding; Indicates temporal embedding; Represents time-aware head entity embedding. Indicates the subject in time The time weight vector below; Relational embeddings representing time perception. Indicates the relationship in time The time weight vector below; Represents time-aware tail entity embeddings. Indicates the object in time The time weight vector below; This represents the sum of each element in the vector; Indicates the reverse of the event; S5.2. Use the cross-entropy loss function to train the model to obtain the head entity. ,entity Training loss function Then the cross-entropy loss function is used to obtain the entity. Training loss function The mathematical expressions involved are: ; In the formula, Indicates a known head entity ,relation ,time In the case of predicting the tail entity The training loss function; Represents the training graph; This represents the candidate set generated through negative sampling; S5.3, Head Entity Based ,entity Training loss function Comparison loss function with supervision Obtain the overall loss function Then calculate the overall loss function. The mathematical expressions involved are: ; In the formula, This represents the total loss function used during model training; Indicates that in a known relation ,time Tail-end entity In the case of predicting the head entity The loss function corresponding to the task.

[0015] Compared with the prior art, the beneficial effects of the present invention are as follows: 1. In this local-global contrast embedding temporal knowledge graph completion method, local temporal modeling of entities and relations is performed based on local time-aware self-attention encoding, which can capture the dynamic changes of entities and relations in the time dimension and introduce position encoding to enhance the model's understanding of temporal order.

[0016] 2. In this local-global contrastive embedding temporal knowledge graph completion method, a multi-head self-attention mechanism is used to extract time-aware entity embeddings, which can automatically learn the temporal dependencies between entities.

[0017] 3. In this local-global contrastive embedding temporal knowledge graph completion method, static embedding and time-aware embedding are integrated to obtain the final entity / relationship representation. While retaining static semantic information, time evolution characteristics are introduced, and flexible dynamic adjustment is achieved by controlling the weight of time information. Attached Figure Description

[0018] Figure 1 This is a flowchart illustrating the overall method of the present invention; Figure 2 This is a general framework diagram of the present invention. Detailed Implementation

[0019] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0020] Example: Please refer to Figure 1-2 As shown, this embodiment provides a method for time-series knowledge graph completion using local-global contrastive embedding, including the following steps: S1. Collect time series data through sensors and perform preprocessing operations on the collected time series data.

[0021] In this embodiment S1, the time series data includes time series data, query data, static entity embedding matrix data, entity set and its timestamp data.

[0022] In this embodiment S1, time series data is collected by a sensor, and the collected time series data is preprocessed. The specific steps of the preprocessing operation are as follows: S1.1 Based on the time format parsing and conversion library, the timestamps of all data points are parsed and converted into a standard format, unified as ISO 8601 or Unix timestamp format, laying the foundation for time series alignment and analysis; S1.2. Implement null value detection and processing based on null value scanning detection algorithm and interpolation technology to ensure the integrity and quality of key fields (sensor ID, measurement value, timestamp) data; S1.3. Based on string normalization operations (lowercase conversion, removal of spaces / punctuation) and entity alignment techniques (string similarity calculation such as Levenshtein / Jaccard, rule matching or entity linking), entity / relationship standardization is achieved to ensure that identifiers such as sensors, indicators, and locations are consistent with the map ontology, thus providing a guarantee for accurate data-map mapping.

[0023] When collecting time-series data from sensors, this data needs to be aligned with entities and relationships in the knowledge graph to establish a correspondence between the time-series data and the graph structure. The collected data is then standardized with timestamps (using null value scanning detection algorithms and interpolation techniques), including handling missing values ​​and removing outliers, to ensure data quality. Based on this, a structured representation containing entities, attribute values, and timestamps is constructed as dynamic attribute information in the graph. Finally, the processed time-series attributes are embedded using statistical coding or deep models to generate embedded representations, which are then input into the time-varying features of nodes or edges into the time-series knowledge graph model.

[0024] S2. Based on the preprocessed time series data, local time-aware self-attention encoding is used to perform local time-series modeling of entities and relationships, and time-aware embedding vectors are extracted.

[0025] In this embodiment S2, based on the preprocessed time series data, local temporal modeling of entities and relationships is performed using local time-aware self-attention encoding, and the specific steps for extracting the time-aware embedding vector are as follows: S2.1 Constructing the entity matrix and time position matrix The mathematical expression involved in constructing the time position matrix is ​​as follows: ; In the formula, Representing the time position matrix The elements in Indicates the row number of a position in the matrix. The column number indicating the position in the matrix; Represents the sine function; Represents the cosine function; Indicates the embedding dimension; S2.2, Entity matrix obtained based on S2.1 With time position matrix Obtain an entity matrix containing time information Then calculate the entity matrix containing time information. The mathematical expressions involved are: ; In the formula, Represents the original entity embedding matrix; The entity matrix, which contains time information, is the final representation input into the model. S2.3, Using a multi-head self-attention mechanism for processing Output time-aware entity embeddings ; S2.4, Based on time vector Calculate time-aware embedding vectors Then the mathematical expression for calculating the time-aware embedding vector is: ; In the formula, This represents a relation vector enhanced with time information, used for downstream tasks such as prediction and inference. Representing time-aware entities - time embedding; This represents the transpose operation of the embedded vector, converting a column vector into a row vector for matrix multiplication. Representing the time vector The time matrix.

[0026] In this embodiment S2.3, a multi-head self-attention mechanism is used for processing. Output time-aware entity embeddings The specific steps are as follows: S2.3.1, Transform the entity matrix obtained in S2.2 using a fully connected linear transformation. If the mapping is represented by three different attention parameter matrices: query, key, and value, then the mathematical expression for the query attention parameter matrix is ​​as follows: ; In the formula, This represents the query attention parameter matrix, used to find relevant entities; The weight matrix represents the query attention parameter matrix; This represents the entity embedding submatrix used by the first attention head; The mathematical expression involved in mapping to the key attention parameter matrix is: ; In the formula, The key attention parameter matrix is ​​used to provide queryable information; The weight matrix represents the key attention parameter matrix; The mathematical expression involved in mapping to the value attention parameter matrix is: ; In the formula, The attention parameter matrix represents the actual information of the entity; The weight matrix represents the value attention parameter matrix; S2.3.2 Calculate the attention weights between entities using the scaling dot product attention mechanism. ; S2.3.3. Based on the entity weight matrix and the corresponding entities, a single-head attention is obtained, and the entity / relation embedding vector is obtained by multiplying the single-head attention. The mathematical expression involved in calculating the entity / relation embedding vector is as follows: ; In the formula, Indicates the number of single-head attention; Indicates the index of the current attention head; Indicates the number of entities; Indicates an index; Indicates the first The weight of each entity under the current attention head; Indicates the first A vector of values ​​for each entity.

[0027] In this embodiment S2.3.2, the scaling dot product attention mechanism is used to calculate the attention weights between entities. The specific steps are as follows: Calculate the dot product of the query attention parameter matrix and the key attention parameter matrix; The attention weights are obtained by normalizing them using the Softmax function. The mathematical expression for calculating the attention weights is as follows: ; In the formula, Attention weights represent the degree of attention each entity pays to other entities; they are a... The probability matrix, where each row represents the attention distribution of a certain entity to all entities; This represents a normalization function that performs exponential normalization on the input vector, making the output value equal to... Within a certain range, and summing to 1, it is used to convert similarity into a probability distribution; This indicates the embedding dimension, which is the size of the dimension of each entity; This represents the scaling factor, used to control the magnitude of the dot product value and avoid scaling due to dimensionality limitations. When the value is large, the dot product result becomes too large, causing the gradient of the Softmax function to vanish.

[0028] S3. Based on feature global encoding, fuse static embedding and time-aware embedding vectors to obtain the final entity / relationship embedding vector.

[0029] In this embodiment S3, the specific steps for obtaining the final entity / relation embedding vector based on the fusion of static embedding and time-aware embedding vectors using global feature encoding are as follows: Weighting based on time information By controlling the proportion of temporal information in entity embedding, the final time-aware entity embedding can be obtained. Then compute time-aware entity embedding The mathematical expressions involved are: ; In the formula, This represents the time-aware entity embedding, which is the final entity vector that incorporates time information and is the entity representation ultimately used by the model. The time information weight is a scalar between 0 and 1, used to control the proportion of time information in the final embedding. The larger the value, the stronger the influence of time information. This represents the original entity embedding, an entity vector that does not contain time information.

[0030] S4. Construct local and global representations of the query based on local-global contrastive learning, and generate an auxiliary loss function through contrastive learning.

[0031] In this embodiment S4, the specific steps for constructing local and global representations of the query based on local-global contrastive learning and generating an auxiliary loss function through contrastive learning are as follows: S4.1 Constructing a local query representation based on a multilayer perceptron and global query representation Then construct a local query representation. The mathematical expressions involved are: ; In the formula, This represents a partial query. This refers to a multilayer perceptron, which is a feedforward neural network, typically composed of several fully connected layers and nonlinear activation functions, used to map input vectors to a higher-level semantic space. Construct a global query representation The mathematical expressions involved are: ; In the formula, This represents the global query representation, which is a vector used in the model to represent the entire query; S4.2, Local query representation built based on S4.1 and global query representation Construct positive sample pairs and negative sample pairs ; S4.3 Obtaining the supervised contrastive loss function based on the InfoNCE loss function , , and Then calculate the supervised contrastive loss function. The mathematical expressions involved are: ; In the formula, This represents the local-global contrastive loss function, which is the contrastive learning objective used in the model to optimize local representations to make them more similar to the corresponding global representations, while dissimilar to other samples. This represents the natural logarithm function, used to convert ratios into logarithmic values, which facilitates gradient calculation and numerical stability. This represents an exponential function, used to construct probability distributions or similarity weights; Indicates the first The local query representation of a sample is the semantic representation of the current sample from a local perspective. Indicates the first The global query representation of a sample is the global semantic representation of the current sample in the entire context; This parameter represents the temperature and controls the "sharpness" of the similarity distribution. The smaller the value, the sharper the distribution, emphasizing positive examples; the larger the value, the smoother the distribution. Represents the set of indices for all negative samples. Indices representing negative samples Indicates the number of queries; S4.4, Based on supervised contrastive loss function , , and The final supervised contrastive loss function is obtained. The mathematical expression for calculating the final supervised contrastive loss function is: ; In the formula, This represents the overall contrastive loss function value after integration, used to optimize model parameters; This represents the global-to-local contrastive loss function, which uses the global representation as the query and matches it with positive samples in the local representation, while negative samples come from the local representations of other samples; This represents the local-to-local contrast loss function, which is the contrast loss function between different local views of the same object, and is used to enhance the consistency of local features; This represents the global-to-global contrastive loss function, which is a contrastive loss function between the global representations of the same object in different contexts, and is used to enhance global consistency.

[0032] In this embodiment S4.1, the specific steps for constructing the multilayer perceptron are as follows: S4.1.1 Determine the input dimension, output dimension, number of hidden layers, and number of neurons in each layer; S4.1.2 Initialize the weight matrix and bias vector ; S4.1.3. Define a nonlinear activation function based on the ReLU function; S4.1.4 Calculate the output of each layer from front to back. The mathematical expression involved in calculating the output of each layer is as follows: ; ; In the formula, Indicates the first The linear output of the layer, Indicates the level index; Indicates the first Layer weight matrix; Indicates the first The nonlinear output of the layer; Indicates the first Layer bias terms; Indicates the activation function; Indicates the first The final output of the layer.

[0033] S5. Based on the decoder embedding, calculate the scoring function to complete the link prediction task and generate the main training loss function.

[0034] In this embodiment S5, the specific steps for calculating the scoring function based on the decoder embedding, completing the link prediction task, and generating the main training loss function are as follows: S5.1 Evaluation using DE-SimplE scoring function The rationality is then assessed. The mathematical expressions involved are: ; In the formula, ; ; ; In the formula, The scoring function is the model's scoring function for a given combination of head entity, relation, tail entity, and timestamp. The larger the value, the more reasonable the combination. Head entity embedding is the vector representation of the subject entity in the knowledge graph; Relational embedding is a vector representation of the relationship between two entities; The enhanced tail entity embedding is the tail entity representation after time information fusion; The time embedding is a vector representation of the timestamp; Represents time-aware head entity embeddings, head entities The representation after integration with time information. Indicates the subject in time The time weight vector below; Relational embeddings that represent time-awareness are relations The representation after integration with time information. Indicates the relationship in time The time weight vector below; The time-aware tail entity embedding is the enhanced tail entity. The representation after further integration with time information. Indicates the object in time The time weight vector below; This represents the sum of each element in the vector; Indicates the reverse of the event; S5.2. Use the cross-entropy loss function to train the model to obtain the head entity. ,entity Training loss function Then the cross-entropy loss function is used to obtain the entity. Training loss function The mathematical expressions involved are: ; In the formula, Indicates a known head entity ,relation ,time In the case of predicting the tail entity The training loss function; The training graph represents the set of all real-world quadruples in the training set. This represents the candidate set generated through negative sampling; S5.3, Head Entity Based ,entity Training loss function Comparison loss function with supervision Obtain the overall loss function Then calculate the overall loss function. The mathematical expressions involved are: ; In the formula, This represents the total loss function used during model training, which is a weighted sum of multiple sub-loss functions; Indicates that in a known relation ,time Tail-end entity In the case of predicting the head entity The loss function corresponding to the task.

[0035] The foregoing has shown and described the basic principles, main features, and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above embodiments. The embodiments and descriptions in the specification are merely preferred examples and are not intended to limit the invention. Various changes and modifications can be made to the invention without departing from its spirit and scope, and all such changes and modifications fall within the scope of the present invention as claimed. The scope of protection of the present invention is defined by the appended claims and their equivalents.

Claims

1. A temporal knowledge graph completion method based on local-global contrast embedding, characterized by: Includes the following steps: S1. Collect time series data through sensors and perform preprocessing operations on the collected time series data; S2. Based on the preprocessed time series data, local temporal modeling of entities and relationships is performed through local time-aware self-attention encoding, and time-aware embedding vectors are extracted. S3. Based on feature global encoding, fuse static embedding and time-aware embedding vectors to obtain the final entity / relationship embedding vector; S4. Construct local and global representations of the query based on local-global contrastive learning, and generate an auxiliary loss function through contrastive learning; S5. Based on the decoder embedding, calculate the scoring function to complete the link prediction task and generate the main training loss function.

2. The temporal knowledge graph completion method with local-global contrast embedding according to claim 1, characterized in that: In S1, the time series data includes time series data, query data, static entity embedding matrix data, entity set and its timestamp data.

3. The temporal knowledge graph completion method based on local-global contrast embedding according to claim 1, characterized in that: In step S1, time-series data is collected through sensors, and the collected time-series data is preprocessed. The specific steps of the preprocessing operation are as follows: S1.

1. Based on the time format parsing and conversion library, the timestamps of all data points are parsed and converted into a standard format; S1.2, Implement null value detection and processing based on null value scanning detection algorithm and interpolation technology; S1.

3. Based on string normalization operations and entity alignment technology, achieve entity / relationship standardization.

4. The temporal knowledge graph completion method with local-global contrast embedding according to claim 1, characterized in that: In step S2, the specific steps for extracting time-aware embedding vectors by performing local temporal modeling of entities and relationships based on preprocessed time-series data using local time-aware self-attention encoding are as follows: S2.1 Constructing the entity matrix and time position matrix ; S2.2, Entity matrix obtained based on S2.1 With time position matrix Obtain an entity matrix containing time information ; S2.3, Using a multi-head self-attention mechanism for processing Output time-aware entity embeddings ; S2.4, Based on time vector Calculate time-aware embedding vectors .

5. The temporal knowledge graph completion method with local-global contrast embedding according to claim 4, characterized in that: In S2.3, a multi-head self-attention mechanism is used for processing. Output time-aware entity embeddings The specific steps are as follows: S2.3.1, Transform the entity matrix obtained in S2.2 using a fully connected linear transformation. The mapping is represented by three different attention parameter matrices: query, key, and value. S2.3.2 Calculate the attention weights between entities using the scaling dot product attention mechanism. ; S2.3.

3. Based on the entity weight matrix and the corresponding entities, a single-head attention is obtained, and the entity / relation embedding vector is obtained by multiplying the single-head attention. The mathematical expression involved in calculating the entity / relation embedding vector is as follows: ; In the formula, Indicates the number of single-head attention; Indicates the index of the current attention head; Indicates the number of entities; Indicates an index; Indicates the first The weight of each entity under the current attention head; Indicates the first A vector of values ​​for each entity.

6. The temporal knowledge graph completion method with local-global contrast embedding according to claim 5, characterized in that: In S2.3.2, the scaling dot product attention mechanism is used to calculate the attention weights between entities. The specific steps are as follows: Calculate the dot product of the query attention parameter matrix and the key attention parameter matrix; The attention weights are obtained by normalizing them using the Softmax function. The mathematical expression for calculating the attention weights is as follows: ; In the formula, Indicates attention weight; Represents the normalization function; Indicates the embedding dimension; This represents the scaling factor.

7. The temporal knowledge graph completion method with local-global contrast embedding according to claim 1, characterized in that: In step S3, the specific steps for fusing static embeddings and time-aware embedding vectors based on global feature encoding to obtain the final entity / relationship embedding vector are as follows: Weighting based on time information By controlling the proportion of temporal information in entity embedding, the final time-aware entity embedding can be obtained. Then compute time-aware entity embedding The mathematical expressions involved are: ; In the formula, Represents time-aware entity embedding; Indicates the weight of time information; This indicates the embedding of the original entity.

8. The method for completing a temporal knowledge graph using local-global contrast embedding according to claim 1, characterized in that: In step S4, the specific steps for constructing local and global representations of the query based on local-global contrastive learning and generating an auxiliary loss function through contrastive learning are as follows: S4.1 Constructing a local query representation based on a multilayer perceptron and global query representation ; S4.2, Local query representation built based on S4.1 and global query representation Construct positive sample pairs and negative sample pairs ; S4.3 Obtaining the supervised contrastive loss function based on the InfoNCE loss function , , and Then calculate the supervised contrastive loss function. The mathematical expressions involved are: ; In the formula, This represents the local-global contrastive loss function; Represent the natural logarithm function; Represents an exponential function; Indicates the first Local query representation of each sample; Indicates the first A global query representation of each sample; Indicates temperature parameter; Represents the set of indices for all negative samples. Indices representing negative samples Indicates the number of queries; S4.4, Based on supervised contrastive loss function , , and The final supervised contrastive loss function is obtained. .

9. The temporal knowledge graph completion method with local-global contrast embedding according to claim 8, characterized in that: In S4.1, the specific steps for constructing the multilayer perceptron are as follows: S4.1.1 Determine the input dimension, output dimension, number of hidden layers, and number of neurons in each layer; S4.1.2 Initialize the weight matrix and bias vector ; S4.1.

3. Define a nonlinear activation function based on the ReLU function; S4.1.4 Calculate the output of each layer from front to back.

10. The temporal knowledge graph completion method with local-global contrast embedding according to claim 1, characterized in that: In step S5, the specific steps for calculating the scoring function based on the decoder embedding, completing the link prediction task, and generating the main training loss function are as follows: S5.1 Evaluation using DE-SimplE scoring function The rationality is then assessed. The mathematical expressions involved are: ; In the formula, ; ; ; In the formula, Represents the scoring function; Indicates head entity embedding; Indicates relational embedding; This indicates an enhanced tail entity embedding; Indicates temporal embedding; Represents time-aware head entity embedding. Indicates the subject in time The time weight vector below; Relational embeddings representing time perception. Indicates the relationship in time The time weight vector below; Represents time-aware tail entity embeddings. Indicates the object in time The time weight vector below; This represents the sum of each element in the vector; Indicates the reverse of the event; S5.

2. Use the cross-entropy loss function to train the model to obtain the head entity. loss function ,entity Training loss function Then the cross-entropy loss function is used to obtain the entity. Training loss function The mathematical expressions involved are: ; In the formula, Indicates a known head entity ,relation ,time In the case of predicting the tail entity The training loss function; Represents the training graph; This represents the candidate set generated through negative sampling; S5.3, Head Entity Based ,entity Training loss function Comparison loss function with supervision Obtain the overall loss function Then calculate the overall loss function. The mathematical expressions involved are: ; In the formula, This represents the total loss function used during model training; Indicates that in a known relation ,time Tail-end entity In the case of predicting the head entity The loss function corresponding to the task.