Knowledge graph completion method based on self-attention combined graph path and neighborhood

By combining the self-attention model with graph paths and local neighborhood information, the problem of insufficient expression ability and excessive smoothing in knowledge graph completion is solved, the comprehensive utilization of long and short distance information is achieved, and the performance of knowledge graph completion is improved.

CN118569368APending Publication Date: 2024-08-30BEIHANG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410697009.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-31
Publication Date
2024-08-30

AI Technical Summary

Technical Problem

Existing knowledge graph completion methods are limited by the shallow structure and over-smoothing problems of graph neural networks, making it difficult to capture long-distance and even global information, resulting in insufficient expression ability and reduced performance.

Method used

A knowledge graph completion method based on self-attention combined with graph path and local neighborhood is adopted. Through data processing, path sampling, graph path encoding, masked entity relationship prediction and local neighborhood encoding, the self-attention model and Transformer network are used to learn the graph. Long and short distance dependence information in .

Benefits of technology

It improves the expressive ability of the model and achieves better performance in knowledge graph completion tasks, especially in terms of indicators such as MRR and Hits@5, which outperforms the current state-of-the-art methods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118569368A
    Figure CN118569368A
Patent Text Reader

Abstract

The invention provides a knowledge graph completion method based on a self-attention combination graph path and a neighborhood, and the method comprises the steps: carrying out the extension of an original knowledge graph, and adding a corresponding inverse relation for each relation in the knowledge graph; calculating the length of the shortest path between different nodes and the degree of each entity node; taking a head entity node in the to-be-predicted triple as an initial node, and sampling a plurality of graph paths; a graph path coding module inputs a sampled graph path into the self-attention network and converts the graph path into a vector form; the local neighborhood coding module gathers the vector representation of the path of the graph and the information of the triple to be predicted, and obtains the vector representation of a predicted tail entity; taking the cosine similarity between the special embedding vector and the embedding vector corresponding to the candidate entity as the score of the triple; and after obtaining the scores of all candidate entities, calculating the loss of the link prediction task. According to the technical scheme, better knowledge graph completion task performance is obtained.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of knowledge graph completion, and in particular to a knowledge graph completion method based on self-attention combined with graph paths and neighborhoods. Background Art

[0002] Knowledge graph is a main form of knowledge base. It is a collection of structured knowledge represented by fact triples (head entity, relationship, tail entity). It has been widely used in multiple artificial intelligence fields, such as semantic search, question answering, and recommendation systems. However, even large-scale knowledge graphs are inevitably incomplete and lack some facts, which limits the application of knowledge graphs in the real world. Therefore, the task of knowledge graph completion has become a hot research field.

[0003] The task of knowledge graph completion aims to predict missing triples in the knowledge graph. The current mainstream solution is knowledge graph embedding, which projects entities and relationships into a low-dimensional vector space to learn the implicit rules in the knowledge graph. Many existing methods achieve excellent performance by utilizing the graph structure information of the graph. The most representative of these methods is the graph neural network-based method that utilizes the local neighborhood structure in the graph. However, these methods have many disadvantages: 1. Limited by the shallow network structure of graph neural networks, the model’s expressive power is insufficient.

[0004] 2. As the number of graph neural network layers increases, existing methods will encounter the problem of over-smoothing, resulting in performance degradation. Therefore, methods based on graph neural networks can only capture local information within 1-2 hops near a single entity, and lack the ability to utilize long-distance or even global information. Summary of the invention

[0005] In view of the above problems, the present invention discloses a knowledge graph completion method based on self-attention combined with graph paths and neighborhoods, comprising: Step 1: Data processing: Expand the original knowledge graph and add a corresponding inverse relationship for each relationship in the knowledge graph; calculate the shortest path length between different nodes and the degree of each entity node; Step 2: Path sampling: The path sampling module uses the graph path sampling algorithm based on biased random walk to sample several graph paths according to the degrees of all entity nodes and the shortest path length information between all pairs of entity nodes, taking the head entity node in the triple to be predicted as the starting node. The number of graph paths is equal to the degree of the head entity node. Step 3: Path information encoding: The graph path encoding module inputs the sampled graph path into the self-attention network, learns the semantic information contained therein and converts it into a vector form; Step 3 includes a masked entity relationship prediction task: for each input graph path, a masked entity relationship prediction task is used, and a relationship or entity is randomly selected for each input graph path for prediction, and the classification loss of the masked entity relationship prediction task is calculated; Step 4: Local neighborhood information encoding: Collect the vector representations of all sampled graph paths and the information of the triples to be predicted, and obtain the vector representation of the predicted tail entity through the local neighborhood encoding module; Step 5: Take the special embedding vector in the input The output of the last layer at the corresponding position As the vector representation of the predicted tail entity, the link prediction task is performed, including: for the triple to be predicted Each candidate entity , taking the cosine similarity between the special embedding vector and the embedding vector corresponding to the candidate entity as a triplet Score , to calculate the scores of all candidate entities; Step 6: Train the model using the loss function: Take the sum of the cross entropy loss of the link prediction task and the classification loss of the masked entity relationship prediction task as the loss of the model, and update the model parameters through the back propagation algorithm until the loss converges to train the model.

[0006] In the above method, adding a corresponding inverse relationship to each relationship in the knowledge graph includes: The knowledge graph is represented as ,in, is a set of facts, including different entities; is a set of relations, including Different kinds of relationships; is a set of edges, each of which corresponds to a "head entity-relationship-tail entity" fact triple ,in is the head entity node, is the tail entity node, Indicate the relationship between them; For each fact triple, create a The inverse triplet of , the relationship set and edge set is expanded to: ; ; ; in, is the expanded relation set, consisting of the relation set The union of the and inverse relation sets yields, is the set of inverse triples, is the expanded triple set, consisting of the original triple set and inverse triple sets The union of .

[0007] In the above method, the "calculating the shortest path lengths between different nodes" includes: for each entity node, using the Dijkstra algorithm to calculate the shortest path lengths from it to all other entity nodes. The calculation process of the Dijkstra algorithm includes: for each node , first initialize its shortest distance to itself to 0, initialize the shortest distance to all other nodes to infinity, and then select a vertex with the shortest distance from it among all unvisited nodes , then update the node to node The adjacent nodes of The process is repeated until all nodes have been visited.

[0008] In the above method, the calculation of the degree of each entity node includes: for the node , its degree Equal to its out-degree and in-degree The sum is: .

[0009] out degree From the node The number of edges indicated: .

[0010] in, Refers to the head entity node and tail entity node The relationship between Refers to the head entity node , tail entity node and the relationship between them The fact triples.

[0011] degree Points to the node The number of edges: .

[0012] in, Refers to the head entity node and tail entity node The relationship between Refers to the head entity node , tail entity node and the relationship between them The fact triples.

[0013] In the above method, step 3 includes: Graph path data processing: Use type embedding to help the self-attention model network distinguish entity embedding, relationship embedding, and special embedding in the graph path, and use position vectors to represent the sequential relationship between entities and relationships in the graph path; The above process includes: Given a length of The graph path ,The input of the graph path encoding module consists of the following parts: graph path embedding , and a special embedding vector that can be learned : ; ; The self-attention model network uses type embedding to help the self-attention model network distinguish entity embedding, relationship embedding, and special embedding vectors. In addition, the self-attention model network uses position vectors to represent the sequential relationship between entities and relationships in the graph path. Therefore, the final input of the graph path encoding module is expressed as: , in is the position vector, is of type vector.

[0014] In the above method, step 4 comprises: Query vector calculation: The query vector representation is calculated using the head entity and relationship in the triple to be predicted, and the information of the triple to be predicted is passed to the self-attention model network; Data processing: Use type embedding to help the self-attention model network distinguish the graph path vector, query vector, and special embedding in the input data, and take the output of the last layer corresponding to the special embedding vector as the vector representation of the predicted tail entity.

[0015] The above method also includes: Step 7: After the self-attention model network is trained, the fact triples in the test set are completed and predicted to test the effect of the knowledge graph completion model. The test set refers to a set of fact triples that are not used in the model training stage, which is used to evaluate the model's predictive ability for new data.

[0016] The beneficial effects brought by the present invention are: By combining the two types of structural information, graph path and local neighborhood in the knowledge graph, we achieve comprehensive utilization of long- and short-distance dependency information in the knowledge graph, and use the self-attention model to fully improve the expressiveness of the model and obtain better performance in the knowledge graph completion task. In terms of knowledge graph completion task indicators such as MRR and Hits@5, we have achieved better results than the current latest methods. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] Figure 1 It is a structural diagram of the knowledge graph completion method based on self-attention combined with graph paths and neighborhoods in the system of the present invention. DETAILED DESCRIPTION

[0018] In order to enable those skilled in the art to better understand the technical solutions in the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present application.

[0019] According to the technical solution of the present invention, the long- and short-distance dependencies in the graph are learned by combining the two knowledge graph structures of graph path and local neighborhood, and the knowledge graph is completed by using the powerful expression ability of the self-attention model (Transformer). Specifically, the model first samples multiple graph paths with the central entity as the starting point through a biased random walk algorithm, and then converts the graph path into a vector representation through the graph path encoding module and learns the long-distance dependencies contained therein. Finally, the local neighborhood encoding module collects all graph path vector representations to score the triples. In the process of graph path encoding, the masked entity relationship prediction task is used to enhance the model's learning ability for long-distance information.

[0020] Figure 1 This is a structural diagram of the knowledge graph completion method based on self-attention combined with graph paths and neighborhoods in the system of the present invention. This model executes the knowledge graph completion method according to the embodiment of the present invention. Figure 1 The method according to the embodiment of the present invention is described in detail. The method comprises the following steps: Step 1: Data processing: In the data processing stage, the original knowledge graph is expanded, and a corresponding inverse relationship is added to each relationship in the knowledge graph; the shortest path length between different entity nodes and the degree of each entity node are calculated.

[0021] First, in the data processing stage, the present invention adds a corresponding inverse relation and a corresponding inverse triple to each relation in the knowledge graph. The knowledge graph can be represented as .in, is a set of facts, including different entities; is a set of relations, including Different kinds of relationships; is a set of edges, each of which corresponds to a "head entity-relationship-tail entity" fact triple ,in is the head entity node, is the tail entity node, Indicates the relationship between them.

[0022] In order to ensure that information can flow in both directions, the present invention creates a pair with an inverse relationship for each fact triple. The inverse triplet of Therefore, the relation set and edge set is expanded to: ; ; .

[0023] in, is the expanded relation set, consisting of the relation set The union of the and inverse relation sets yields, is the set of inverse triples, is the expanded triple set, consisting of the original triple set and inverse triple sets The union of .

[0024] Secondly, for each entity node, Dijkstra's algorithm is used to calculate the shortest path length from it to all other entity nodes. Specifically, for the node , first initialize its shortest distance to itself to 0, initialize the shortest distance to all other nodes to infinity, and then select a node with the shortest distance from it among all unvisited nodes , then update the node To Node The adjacent nodes of The length of the shortest path. Repeat the process until all nodes have been visited. The update rule is as follows: , in, For Node and the above adjacent nodes The length of the shortest path between Used to take the minimum of two lengths. Is a connection node and nodes The weight of the edge.

[0025] Finally, the degree of each entity node is calculated. For example, its degree Equal to its out-degree and in-degree The sum is: .

[0026] out degree From the node The number of edges pointed out. The calculation formula can be expressed as: .

[0027] in, Refers to the head entity node and tail entity node The relationship between Refers to the head entity node , tail entity node and the relationship between them The fact triples.

[0028] degree Points to the node The number of edges can be calculated as: .

[0029] in, Refers to the head entity node and tail entity node The relationship between Refers to the head entity node , tail entity node and the relationship between them The fact triples.

[0030] Step 2: Path sampling: Figure 1 As shown below, the path sampling module uses the graph path sampling algorithm based on biased random walk to sample several graph paths based on the degree of all entity nodes and the shortest path length information between all entity node pairs, with the head entity node in the triple to be predicted as the starting node. The number of graph paths is equal to the degree of the head entity node in the fact triple.

[0031] Step 2 may include: depth deviation calculation: determining the depth deviation in the sampling probability calculation according to the shortest path length between the next-hop candidate entity node and the starting entity node in the original knowledge graph; degree deviation calculation: determining the degree deviation in the sampling probability calculation according to the degree of the next-hop candidate entity node in the original knowledge graph, the process includes: In the knowledge graph, nodes is the starting point and the length is The graph path It can be expressed as: , in, represents the first entity sampled, Indicates the starting point With entity The adjacency relationship, represents the second entity sampled, Indicates the starting point With entity The adjacency relationship, Indicates the sampling entities, Indicates the starting point With entity adjacency relationship.

[0032] First, given a triple to be predicted , the number of graph paths sampled by the graph path sampling module in the knowledge graph model is equal to the head entity node To avoid path duplication and information redundancy between randomly sampled graph paths, for the same node The sampling module ensures that the fact triples composed of the first three elements in the sampled different graph paths are unique, that is, for different graph paths and ,have ,in , Head entity node The first-order neighbor nodes of .

[0033] The knowledge graph model calculates the depth deviation and degree deviation of the sampling. During the graph path sampling process, the currently selected entity is , the previous hop entity is , the candidate entity for the next hop is The first-order neighbor of . Assume that the next-hop candidate entity is , then the depth deviation The calculation method is: , in, Previous hop entity and candidate entities The length of the shortest path between To control the hyperparameter of the random walk path depth, it is generally set to To obtain a graph path with greater depth.

[0034] degree deviation The calculation method is: , in, It's a relationship The degree of Is Entity The degree of is a logarithmic function with base 10.

[0035] Finally, the probability calculation formula for the next-hop candidate relationship and entity in the process of graph path sampling is: ; .

[0036] in, is a hyperparameter that controls the degree bias weight.

[0037] The graph paths sampled by the graph path sampling module cannot be used directly. It is also necessary to learn the semantic information contained therein and convert it into a vector representation. Therefore, the following step 3 needs to be performed.

[0038] Step 3: Graph path information encoding: Figure 1 As shown in the middle part, the graph path encoding module inputs the sampled graph path into the Transformer network, learns the semantic information contained therein and converts it into vector form.

[0039] Step 3 includes: using type embedding to help the self-attention model network distinguish entity embedding, relationship embedding and special embedding in the graph path, and using position vectors to represent the sequential relationship between entities and relationships in the graph path; masked entity relationship prediction task: for each input graph path, the self-attention model network adopts a masked entity relationship prediction task, randomly selects a relationship or entity for prediction task for each input graph path, and calculates the loss, so as to enhance the ability of the self-attention model network to mine information from the graph path context. The process includes: Given a length of The graph path ,The input of the graph path encoding module mainly consists of the following parts: graph path embedding , and a special embedding vector that can be learned , expressed as: ; .

[0040] in, , , is the embedding dimension, is a size of The real number space, is a size of The real number space. It is composed of the embeddings corresponding to all entities and relationships in the graph path. They represent entity embedding and relation embedding respectively.

[0041] Type embedding is used to help the self-attention model network distinguish between entity embedding, relationship embedding, and special embedding vectors. In addition, the self-attention model network uses position vectors to represent the sequential relationship between entities and relationships in the graph path. Type embedding helps the model distinguish between these elements by assigning different embedding vectors to different types of elements in the input data. Therefore, the final input of the graph path encoding module is It is expressed as: , in, is the position vector representing the position of each element, is a type vector representing type embedding.

[0042] The graph path encoding module contains multiple Transformer encoding layers. The output of each layer is the input of the next layer. The input of the first layer is . Let the input of each layer be , then in each layer there are: ; ; ; ; .

[0043] in, is the attention function, is the query matrix, is the key matrix, is the value matrix, Is the activation function, used to normalize the original data of the previous layer to between, is the embedding dimension, are the learnable parameters of the model, Depend on Calculated through the attention mechanism, is the layer normalization function, Depend on With input Add and normalize the layers to get, is the ReLU activation function, which is used to increase the nonlinearity of the network. yes The transformation result after two layers of feedforward network is the final output Depend on and It is obtained by adding and performing layer normalization.

[0044] Furthermore, in order to stabilize the learning process of self-attention, Transformer adopts a multi-head attention mechanism. Independent attention heads , the attention mechanism can be expressed as: ; .

[0045] in, are learnable parameters, The function is used to concatenate multiple input vectors. Suppose the output of the last layer of the graph path encoding module is ,in is the path length, is the embedding dimension, is a size of In the real number space, take the vector Output embedding at the corresponding position A vector representation of the current graph path.

[0046] In order to improve the model's ability to mine long-distance information, the model uses the Masked Entity and Relation Prediction (MERP) task. , the model will randomly select a relationship or entity for prediction. Taking entity as an example, the selected entity Will be replaced with a special masking placeholder [MASK] with a certain probability, and other random entities may remain unchanged. In the prediction stage, the model takes the output embedding matrix The embedding corresponding to the selected entity in , through a double-layer fully connected layer and calculate the cosine similarity to obtain candidate entities The correct probability : , in, and They are RELU and Sigmoid activation functions, and is the projection matrix, For Entity The embedding For Entity When the selected element is a relationship, the processing method is similar.

[0047] The final model uses the cross entropy loss function to calculate the classification loss of the masked entity relationship prediction task: , in, is the classification label in the MERP task, is the correct probability of the corresponding candidate entity.

[0048] Step 4: Local neighborhood information encoding: Figure 1 As shown in the upper part, the vector representations of all sampled graph paths and the information of the triples to be predicted are collected, and the vector representation of the predicted tail entity is obtained through the local neighborhood encoding module. This step includes: query vector calculation: the query vector representation is calculated using the head entity and relationship in the triple to be predicted, and the information of the triple to be predicted is passed to the self-attention model network; data processing: type embedding is used to help the self-attention model network distinguish between graph path vectors, query vectors, and special embeddings in the input data, including: The model will sample multiple graph paths, and by restricting the sampling rules, these graph paths can cover the first-order neighborhood of the central entity. The central entity is a node that is currently being focused on. In this way, the self-attention model network can combine the local neighborhood information and graph path information of the knowledge graph at the same time.

[0049] The input of the local neighborhood encoding module mainly includes the following parts: graph path embedding matrix , query embedding , and the special embedding vector . Assume the number of sampling graph paths is , , It means the size is The real space of , consists of the embedding representations of all sampled graph paths starting from the central entity: .

[0050] is the query vector, consisting of the triples to be predicted Middle head entity and relationship The corresponding embedding vector and The calculation results are: , in, is the vector addition function.

[0051] Similarly, different types of embeddings are used to distinguish graph path embedding matrices , query embedding , and the special embedding vector . Special embedding vector is the embedding vector of the comprehensive information of the entire input sequence. The final input of the local neighborhood encoding module is: ; .

[0052] in, is of type vector.

[0053] The local neighborhood encoding module is also composed of multiple Transformer encoding layers. The next layer receives the output of the previous layer as input, and each layer performs multi-head attention calculations.

[0054] Step 5: Take the special embedding vector in the input The output of the last layer at the corresponding position As the vector representation of the predicted tail entity, we can perform the link prediction task. Specifically, for the triple to be predicted Each candidate entity ,Will and with The corresponding embedding vector The cosine similarity between Score , and use this to calculate the scores of all candidate entities.

[0055] Step 6: Train the model using the loss function: After obtaining the scores of all candidate entities, use the cross entropy loss function to calculate the loss of the link prediction task: , in, is the number of triplets to be predicted, It is The real labels, It is The probability that a triplet is predicted to be 1.

[0056] The cross entropy loss of the link prediction task and the classification loss of the masked entity relationship prediction task are added together to obtain the final loss function for model training: ; .

[0057] in, is the number of graph paths sampled, is the classification loss for the masked entity relation prediction task corresponding to the graph path.

[0058] After calculating the loss, the model parameters are iteratively updated using the back-propagation algorithm to train the model until the loss function converges. The loss function is used to measure the difference between the model's predicted results and the actual results. The process of reducing this difference by adjusting the model's parameters is called training the model. After calculating the loss, the model needs to be trained by adjusting the model's parameters until the loss function converges. After training is completed, the trained model can be used to perform knowledge graph completion tasks on test data and to verify the model's effectiveness.

[0059] The above method may also include step 7: after the model is trained, the fact triples in the test set are completed and predicted to test the effect of the knowledge graph completion model. The verification means include three evaluation indicators: mean rank (MR), mean reciprocal rank (MRR) and top N percentage (Hits@n). The smaller the MR, the larger the MRR and Hits@n, the better the prediction ability of the model. The test set refers to a set of fact triples that are not used in the model training stage, which is used to evaluate the prediction ability of the model for new data. In the knowledge graph, a fact triple is usually represented as (entity 1, relationship, entity 2), which is used to represent a semantic relationship between two entities. For example, (Paris, is the capital, France) is a fact triple. In the knowledge graph completion or link prediction task, the triple to be predicted may be a partially known triple, such as (entity 1, relationship,?) or (?, relationship, entity 2), where the question mark represents the part that needs to be predicted by the model. The model's task is to predict the missing entity to complete the triple.

[0060] In summary, based on the graph path sampling algorithm with biased random walk, multiple graph paths are sampled in the graph starting from the central entity; the sampled graph paths need to be converted into vector form before they can be used, and the graph path encoding module is responsible for learning the long-distance semantic information contained in the graph path and converting it into a vector representation; the local neighborhood encoding module receives the output of the graph path encoding module as input, integrates the contextual neighborhood information composed of multiple graph paths and the query vector containing the triple information to be tested, and completes the knowledge graph completion.

[0061] In the knowledge graph embedding method described above, by fusing the two structural information of local neighborhood and graph path in the knowledge graph, the model completes the mining of long-distance information while utilizing rich neighborhood information, and utilizes the powerful expressive ability of the Transformer model to achieve comprehensive learning of long- and short-distance dependencies in the graph, ultimately achieving a better knowledge graph completion effect.

[0062] Although the above describes the illustrative specific embodiments of the present invention to facilitate those skilled in the art to understand the present invention, and it should be clear that the present invention is not limited to the scope of the specific embodiments, for those of ordinary skill in the art, as long as various changes are within the spirit and scope of the present invention as defined and determined by the attached claims, these changes are obvious, and all inventions and creations using the concept of the present invention are protected.

Claims

1. A knowledge graph completion method based on self-attention combined with graph paths and neighborhoods, characterized in that: include: Step 1: Data processing: Expand the original knowledge graph and add a corresponding inverse relationship for each relationship in the knowledge graph; Calculate the shortest path length between different nodes and the degree of each entity node; Step 2: Path sampling: The path sampling module uses the graph path sampling algorithm based on biased random walk to sample several graph paths according to the degrees of all entity nodes and the shortest path length information between all pairs of entity nodes, taking the head entity node in the triple to be predicted as the starting node. The number of graph paths is equal to the degree of the head entity node. Step 3: Path information encoding: The graph path encoding module inputs the sampled graph path into the self-attention network, learns the semantic information contained therein and converts it into a vector form; Step 3 includes a masked entity relationship prediction task: for each input graph path, a masked entity relationship prediction task is used, and a relationship or entity is randomly selected for each input graph path for prediction, and the classification loss of the masked entity relationship prediction task is calculated; Step 4: Local neighborhood information encoding: Collect the vector representations of all sampled graph paths and the information of the triples to be predicted, and obtain the vector representation of the predicted tail entity through the local neighborhood encoding module; Step 5: Take the special embedding vector in the input The output of the last layer at the corresponding position As the vector representation of the predicted tail entity, the link prediction task is performed, including: for the triple to be predicted Each candidate entity , taking the cosine similarity between the special embedding vector and the embedding vector corresponding to the candidate entity as a triplet Score , to calculate the scores of all candidate entities; Step 6: Train the model using the loss function: After obtaining the scores of all candidate entities, use the cross entropy loss function to calculate the loss of the link prediction task, and add it to the classification loss of the masked entity relationship prediction task as the final loss function of the model. Then, iteratively update the model parameters through the back-propagation algorithm to train the model until the loss function converges.

2. The method for completing a knowledge graph based on self-attention combined with graph paths and neighborhoods according to claim 1, characterized in that: The adding of a corresponding inverse relationship for each relationship in the knowledge graph includes: The knowledge graph is represented as ,in, is a set of facts, including different entities; is a set of relations, including Different kinds of relationships; It is a set of edges, each of which corresponds to a "head entity-relationship-tail entity" fact triple ,in is the head entity node, is the tail entity node, Indicate the relationship between them; For each fact triple, create a The inverse triplet of , the relationship set and edge set is expanded to: ; ; ; in, is the expanded relation set, consisting of the relation set The union of the and inverse relation sets yields, is the set of inverse triples, is the expanded triple set, consisting of the original triple set and inverse triple sets The union of .

3. The method for completing a knowledge graph based on self-attention combined with graph paths and neighborhoods according to claim 1, characterized in that: The "calculating the shortest path lengths between different nodes" includes: for each entity node, using the Dijkstra algorithm to calculate the shortest path lengths from it to all other entity nodes. The calculation process of the Dijkstra algorithm includes: for each node , first initialize its shortest distance to itself to 0, initialize the shortest distance to all other nodes to infinity, and then select a vertex with the shortest distance from it among all unvisited nodes , then update the node to node The adjacent nodes of The process is repeated until all nodes have been visited.

4. The method for completing a knowledge graph based on self-attention combined with graph paths and neighborhoods according to claim 1, characterized in that: The calculation of the degree of each entity node includes: for the node , its degree Equal to its out-degree and in-degree The sum is: , out degree From the node The number of edges indicated: , in, Refers to the head entity node and tail entity node The relationship between Refers to the head entity node , tail entity node and the relationship between them The fact triples that are composed; degree Points to the node The number of edges: , in, Refers to the head entity node and tail entity node The relationship between the head entity node , tail entity node and the relationship between them The fact triples.

5. The method for completing a knowledge graph based on self-attention combined with graph paths and neighborhoods according to claim 1, characterized in that: Step 3 includes: Graph path data processing: Use type embedding to help the self-attention model network distinguish entity embedding, relationship embedding, and special embedding in the graph path, and use position vectors to represent the sequential relationship between entities and relationships in the graph path; The above process includes: Given a length of The graph path ,The input of the graph path encoding module consists of the following parts: graph path embedding , and a special embedding vector that can be learned : ; ; The self-attention model network uses type embedding to help the self-attention model network distinguish entity embedding, relationship embedding, and special embedding vectors. In addition, the self-attention model network uses position vectors to represent the sequential relationship between entities and relationships in the graph path. Therefore, the final input of the graph path encoding module is expressed as: , in, is the position vector, is of type vector.

6. The method for completing a knowledge graph based on self-attention combined with graph paths and neighborhoods according to claim 1, characterized in that: The step 4 comprises: Query vector calculation: The query vector representation is calculated using the head entity and relationship in the triple to be predicted, and the information of the triple to be predicted is passed to the self-attention model network; Data processing: Use type embedding to help the self-attention model network distinguish the graph path vector, query vector, and special embedding in the input data, and take the output of the last layer corresponding to the special embedding vector as the vector representation of the predicted tail entity.

7. The method for completing a knowledge graph based on self-attention combined with graph paths and neighborhoods according to claim 1, characterized in that: Also includes: Step 7: After the self-attention model network is trained, the fact triples in the test set are completed and predicted to test the effectiveness of the knowledge graph completion model. The test set refers to a set of fact triples that are not used in the model training phase, which is used to evaluate the model's ability to predict new data.