A small sample knowledge graph completion method based on graph structure information
Patent Information
- Application Number
- CN202411138796.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-19
- Publication Date
- 2026-09-22
- Estimated Expiration
- 2044-08-19
AI Technical Summary
[0006]本发明所要解决的技术问题是:提出一种基于图结构信息的小样本知识图谱补全方法,弥补现有方法未能充分利用子图结构信息导致的实体与关系嵌入不准确问题,使其在小样本知识图谱补全问题中能更好地提高补全效果
[0062]1)考虑了邻居子图对实体嵌入的作用,通过将头尾实体的一层邻居节点和二层邻居节点进行表征,再结合图注意力网络分别对一层邻居节点和二层邻居节点进行动态分配权重从而聚合得到中心节点信息,提高小样本知识图谱补全问题下的准确率。
Smart Images

Figure CN119227790B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of knowledge graph technology, and specifically to a method for small-sample knowledge graph completion based on graph structure information. Background Technology
[0002] Knowledge graphs, which are datasets stored in the form of triples, have been widely applied in intelligent fields such as text question answering and social recommendation. However, existing knowledge graphs generally suffer from insufficient information and sparse connections, resulting in limited support for downstream tasks. Knowledge graph completion methods, based on the existing set of triples, fully explore the potential relationships between entities and add new fact triples to the knowledge graph, thereby improving its completeness.
[0003] However, traditional knowledge graph methods require training with a large number of identical triplet entity pairs to achieve optimal results. Knowledge graphs generally suffer from knowledge gaps and long-tail effects, where a large amount of information is concentrated on a few popular nodes, resulting in a scarcity of most entity and relation information. To address these challenges, research has shifted to few-shot knowledge graph completion, aiming to utilize meta-learning or metric learning algorithms to fill in missing information and improve the completeness and coverage of the graph. However, current methods fail to fully utilize the potential information of knowledge graphs. Therefore, this application conducts research on few-shot knowledge graph completion technology based on graph structure information, aiming to effectively utilize the neighborhood and path information of entities to enhance the comprehensiveness of the knowledge graph.
[0004] Existing few-shot knowledge graph completion techniques are mainly divided into metric learning-based methods and meta-learning-based methods. Metric learning-based methods aim to capture complex interaction patterns between entities and relations by learning low-dimensional representations of them in the knowledge graph. The core of this method lies in constructing an embedding space that allows determining the existence of a specific relationship by calculating the distance between entity and relation vectors. Within this framework, the model training objective is to reduce the distance between positive examples and increase the distance between negative examples, enabling effective knowledge reasoning and completion even with limited data. Meta-learning-based methods, on the other hand, rely on meta-learning strategies to train a meta-model that can rapidly adjust its parameters when faced with new, limited samples, achieving accurate predictions. This allows the model to learn a new relation from only a very small number of examples, thus adapting to new tasks.
[0005] However, existing methods only consider partial structural information in the knowledge graph, such as neighbor node information or path information, and do not effectively integrate the complete information of the graph structure, so the completion effect needs to be improved. Summary of the Invention
[0006] The technical problem to be solved by this invention is to propose a few-sample knowledge graph completion method based on graph structure information, which makes up for the problem of inaccurate entity and relation embedding caused by the failure of existing methods to fully utilize subgraph structure information, so as to improve the completion effect in the few-sample knowledge graph completion problem.
[0007] The technical solution adopted by the present invention to solve the above-mentioned technical problems is as follows:
[0008] A few-sample knowledge graph completion method based on graph structure information includes the following steps:
[0009] S1: Pre-train the triples in the knowledge graph to obtain the entity relation embedding information of all knowledge graphs; at the same time, construct a small sample task set, divide different relations into different task sets according to the knowledge graph relations; and divide the support set and query set according to the number of training samples.
[0010] S2: Use the small sample task set as the positive sample set, perform negative sampling operation, add the negative sampling result to the positive sample set to form an expanded sample set, extract the knowledge graph subgraph for each sample in the sample set, and construct the corresponding neighbor subgraph and path subgraph.
[0011] S3: The graph attention network is used to dynamically assign weights to the first-level neighbor nodes and the second-level neighbor nodes respectively to aggregate the information of the central node and finally obtain the embedding of the central entity.
[0012] S4: Obtain relation embeddings through the constructed path subgraph, construct dual relation embeddings, and model relation representations from both aggregation and semantic interaction perspectives to achieve triple relation representation embeddings;
[0013] S5: Match and score the relationship representations of triples in the training set and triples in the test set to obtain the loss value, and train the small sample knowledge graph completion model based on the final loss value using stochastic gradient descent.
[0014] S6. Divide the small sample task to be tested into a support set and a query set. Generate the score of the candidate triples in the query set for the support set through the model. Finally, select the one with the highest score as the completion result.
[0015] As one implementation method, step S1 is as follows:
[0016] S11. Pre-train the triples in the knowledge graph using the transfer embedding model to obtain the pre-embedding information of all triples.
[0017] S12. Divide the knowledge graph into small sample tasks according to the relationships. Select a set number of triple relationships as small sample tasks to construct a dataset, and divide it into training, validation and test sets according to a set ratio; and divide other triples in the knowledge graph into background knowledge graphs.
[0018] In one implementation method, step S2 specifically includes the following sub-steps:
[0019] S21: Negative sampling construction, using Bernoulli negative sampling, constructs n for each sample in the positive sample set S. samp n negative samples are grouped into a positive-negative sample group, where n samp The hyperparameter for the number of negative samples;
[0020] S22: Neighbor subgraph construction; Construct a two-level neighbor subgraph based on the central node. For a pair of triples, construct the subgraph with the head entity and the tail entity as the central nodes respectively. First, select the central node v0∈V in the entity set V, and obtain the set N1(v0) of all the first-level neighbor nodes of the central node:
[0021] N1(v0)={v∈V∣(v0,v)∈E}
[0022] Where v represents the first-level neighbor nodes, and E represents the set of edges between nodes; then, the second-level neighbor node set N2(v0) is obtained:
[0023]
[0024] Where u represents the second-level neighbor nodes; for the first-level neighbor node set, all nodes are taken, and for the second-level neighbor node set, the first n unique nodes are taken.
[0025] Step 23: Constructing the path subgraph; Use a bidirectional breadth-first search algorithm to extract the path subgraph relating entity pairs;
[0026] For supporting the set S of entity pairs r Each supporting entity in h s , t s ∈S r Specifically, given the maximum path length T, starting from the initial entity h s Start execution A breadth-first search is used to collect neighbors with different hop counts. And from the beginning entity h s The corresponding paths of different lengths to these neighbors, i.e., the left-hand paths;
[0027] Similarly, from the tail entity t s Start, and execute A jump-breadth-first search is used to obtain neighbors. And from ts To their corresponding paths, i.e., the paths on the right;
[0028] Then, calculate the intersection. The neighbors in the intersection are used to connect the left and right paths, generating paths of different lengths from h. s to t s The path is represented as Ultimately, a multi-hop path between the head and tail entities is obtained.
[0029] As one implementation method, the central entity embedding is obtained through the following steps:
[0030] First, we define an attention mechanism; for any neighbor node... Attention coefficient α vu Calculated as:
[0031]
[0032] Where a is the learnable weight vector of the attention mechanism, and the superscript T denotes transpose; W is the weight matrix of the feature transformation, h v and h u These are the feature vectors of nodes v and u, respectively; | denotes the concatenation operation; LeakyReLU is the activation function; h k It is the feature vector of node k. At this time, the attention coefficients of the first and second layer neighbor nodes to the center node are calculated.
[0033] Then calculate the attention coefficient of the second-level neighbor node to the first-level neighbor node; for any first-level neighbor node and any second-level neighbor node corresponding to the first-level neighbor node u. Attention coefficient α uk Calculated as:
[0034]
[0035] The aggregation feature h′ of the first-level neighbor nodes u The formula is as follows:
[0036]
[0037] Where σ() is the activation function, α vk It is the attention coefficient of the central node to its second-level neighbor nodes, α. uk It is the attention coefficient of the first-level neighbor node to the second-level neighbor node;
[0038] Furthermore, the embedding representation h′ of the central node v is further... v It is obtained through a linear combination of weighted neighbor features, as shown in the following formula:
[0039]
[0040] Where, r vu Information about neighbor relationships at the first level. For connection operation;
[0041] Finally, construct the node feature matrix X to represent the initial and final representation of each node, with a shape of (N, F), where N is the number of nodes and F is the feature dimension of each node. Then, construct the adjacency matrix A to represent the structure of the graph, with a shape of (N, N). Finally, optimize the node embedding representation by minimizing the reconstruction error through the inner product decoder to obtain the embedding representation of the central entity node.
[0042] As one implementation method, the specific implementation process of triple relation representation embedding is as follows:
[0043] S41: First, define the constructed path subgraph, and traverse a path starting from the head node h; this path can be represented as an ordered pair of nodes and edges (r1, r2, ..., r...). l Formalized as:
[0044] h→u1→u2…→u l-1 →t
[0045] Each node u i and edge r i The beginning and end echo each other; therefore, for any path π = (r1→r2…→r l A sequence R can be defined. π To accurately represent the traversal order of nodes and edges on path π;
[0046] The attention mechanism is used to calculate the attention weight for each relation. Given a combination of the head node and the timestamp (h,t), the attention weight is n. i The calculation formula is:
[0047]
[0048] Among them, c r The target relation vector, The vector representation of the system in the path, where U and θ are training parameters, U T and θ T This represents its matrix transpose, and [·; ·] denotes the concatenation operation of vectors; the intermediate representation n through nonlinear transformation. i The normalized importance weights for each relation are calculated using a softmax function:
[0049]
[0050] Among them, R h→tβ represents the set of path relationships from the head node h to the tail node t. i Normalized importance weights for each relation.
[0051] Finally, a bidirectional gated loop unit is used to take each path as input and output the relationship level of the path.
[0052] S42: Model the relation representation by constructing a semantic aspect of triples, interactively process N paths using a Transformer encoder, and process the path embeddings through self-attention and feedforward networks in the Transformer encoder to output h. final It contains rich semantic representations that take into account all path information, resulting in embedding vectors for N paths.
[0053] By supporting a centralized given source node h s With target node t s Path embedding set And given the source node h in the query set q With target node t q Path embedding set Using the Transformer encoder, a set of support set path embedding vectors is constructed. and query set path embedding vector set Construct a similarity matrix S h The elements of the matrix express and Similarity between them;
[0054] Then based on the similarity matrix S h Accumulated similarity features are extracted using the kernel aggregation function of the radial basis function (RBF) to obtain the final feature vector.
[0055] As one implementation method, step 5 is as follows:
[0056] A path-based similarity embedding φ is converted into a score using a multilayer perceptron (MLP) layer, and max pooling is performed on the scores of all samples to output a single score g(h). q ,t q ,S r Specifically, it is described as follows:
[0057]
[0058] Where P(h) i ,t i ), i = s, t is h i to t iThe path embedding set; φ(,) represents the feature vector obtained through step S42 using the similarity matrix, trained using the loss function L. r The expression is as follows:
[0059]
[0060] Where m represents the margin boundary between positive and negative samples, and the set Contains incorrect query entity pairs They are the correct query entity pairs Q r ={(h q ,t q The opposite of the erroneous entity pair.
[0061] The beneficial effects of this invention are:
[0062] 1) The role of the neighbor subgraph in entity embedding is considered. By representing the first-level and second-level neighbor nodes of the head and tail entities, and then combining the graph attention network to dynamically assign weights to the first-level and second-level neighbor nodes respectively, the information of the center node is aggregated, thereby improving the accuracy of the small sample knowledge graph completion problem.
[0063] 2) The role of path subgraphs in relation embedding is considered. By constructing dual relation embeddings, relation representation is modeled from both aggregation and semantic interaction perspectives. In terms of aggregation, the Encoder model in Transformer is used to extract the structural hierarchy information of multiple paths between head and tail entities. Furthermore, head and tail entity embeddings are combined to extract different hierarchical features of relation paths and head and tail entities, classifying and aggregating the paths between them. In terms of interaction, a similarity matrix is constructed by combining multi-hop paths from the support set and multi-hop paths from the query set for interactive matching, thereby achieving triple relation representation embedding and further improving the accuracy in the few-sample knowledge graph completion problem. Attached Figure Description
[0064] Figure 1 This is the construction graph of the neighbor subgraph in this invention;
[0065] Figure 2 This is a construction graph for the path subgraph in this invention;
[0066] Figure 3 This is a diagram of the small-sample knowledge graph entity embedding model based on neighborhood information aggregation in this invention.
[0067] Figure 4 This is a graph of a few-sample knowledge graph relationship embedding model based on relationship path aggregation in this invention. Detailed Implementation
[0068] This invention aims to propose a few-sample knowledge graph completion method based on graph structure information, which overcomes the problem that existing methods fail to effectively utilize the structural graph in the knowledge graph for entity and relation representation embedding. The method mainly includes the following steps:
[0069] S1. Pre-train the knowledge graph to obtain the entity relation embedding information of all knowledge graphs. At the same time, construct a small sample task set, divide different relations into different task sets according to the knowledge graph relations, and divide the support set and query set according to the number of training samples K;
[0070] S2. Using the positive sample set of the small sample knowledge graph, perform negative sampling operation, add the negative sampling result to the positive sample set to form an expanded sample set, extract a knowledge graph subgraph for each sample in the sample set, and construct the corresponding neighbor subgraph and path subgraph.
[0071] S3. By dynamically assigning weights to the first-level neighbor nodes and the second-level neighbor nodes through a graph attention network, the information of the central node is aggregated, and finally the embedding of the central entity is obtained.
[0072] S4. Obtain relation embeddings through the constructed path subgraph, construct dual relation embeddings, and model relation representations from both aggregation and semantic interaction perspectives. This ultimately achieves triple relation representation embedding.
[0073] S5. Match and score the triples in the support set and the triples in the query set to obtain the loss value, and train the few-sample knowledge graph completion model based on the final loss value using the stochastic gradient descent method.
[0074] S6. Divide the small sample task to be tested into a support set and a query set. Generate the score of the candidate triples in the query set for the support set through the model. Finally, select the one with the highest score as the completion result.
[0075] Example:
[0076] This embodiment uses the NELL-One dataset to illustrate the overall process in detail:
[0077] Step 1: First, preprocess the sample data. Data preprocessing specifically includes two sub-steps: pre-training the knowledge graph and constructing a small sample task set.
[0078] Step 11: Pre-train the triples in the knowledge graph using the TransE (Transfer Embedding) model to obtain the pre-embedding information of all triples;
[0079] Step 12: Divide the knowledge graph into small-sample tasks based on relationships. Select relationships with fewer than 500 but greater than 50 triples as small-sample tasks to construct the NELL-One dataset. For training, validation, and testing task relationships, the NELL-One dataset is divided into 5:1, 5:5, and 1:1 ratios, respectively. Other triples in the knowledge graph are then classified as background knowledge graph.
[0080] Step 2: Perform negative sampling on the NELL-One dataset and construct subgraphs in the training and test sets, including neighbor subgraphs and path subgraphs;
[0081] Step 21: Negative sampling construction. Using Bernoulli negative sampling, construct n for each sample in the positive sample set S. samp n negative samples are grouped into a positive-negative sample group, where n samp This is a hyperparameter representing the number of negative samples. The formula for Bernoulli negative sampling is as follows:
[0082]
[0083] Where ht is the average number of tail entities corresponding to each head entity in the knowledge graph G; th is the average number of head entities corresponding to each tail entity in the knowledge graph G; p is the Bernoulli probability of the replacement method, which is randomly generated each time a negative sample is taken. When this value is less than p, the head entity of the positive sample is randomly replaced to obtain the negative sample; otherwise, the tail entity is randomly replaced to obtain the negative sample.
[0084] Step 22, Neighbor subgraph construction, as follows Figure 1 As shown, a two-level neighbor subgraph based on the central node needs to be constructed. For a pair of triples, the subgraph is constructed with the head entity and the tail entity as the central nodes respectively. First, the central node v0∈V in the entity set V is selected. Then, the set N1(v0) of all first-level neighbor nodes of the central node is obtained:
[0085] N1(v0)={v∈V∣(v0,v)∈E},
[0086] Where v represents the first-level neighbor nodes, and E represents the set of edges between nodes. Then, the second-level neighbor node set N2(v0) is obtained:
[0087]
[0088] Here, u represents the second-level neighbor nodes. For the first-level neighbor node set, all nodes are taken; for the second-level neighbor node set, the first n unique nodes are taken, considering removing duplicate nodes in N²(v₀). This method constructs a neighbor subgraph centered on the head and tail entities.
[0089] Step 23: Construct the path subgraph, as follows Figure 2As shown, considering the multi-hop paths between head and tail entities, a bidirectional breadth-first search (BFS) algorithm is used to extract the relationship path subgraph between entity pairs.
[0090] Then, for the set S of supporting entity pairs r Each supporting entity in h s , t s ∈S r Specifically, given the maximum path length T, starting from the initial entity h s Start execution A hop-based BFS collects neighbors with different hop counts. And from h s The corresponding paths of different lengths to these neighbors, i.e., the left-hand paths.
[0091] Similarly, from the tail entity t s Start, and execute Jump BFS to get neighbors And from t s To their corresponding paths, i.e., the paths on the right.
[0092] Then, calculate the intersection. The neighbors in the intersection are used to connect the left and right paths, generating paths of different lengths from h. s to t s The path is represented as Ultimately, the multi-hop path between the head and tail entities can be obtained.
[0093] Step 3: Entity embedding is performed on the small sample knowledge graph through neighborhood information aggregation, such as... Figure 3 As shown, there is a subgraph of two neighbors centered on the central node v0. This subgraph includes the direct neighbors (first-order neighbors) of the central node v and the neighbors of these neighbors (second-order neighbors), but does not include the central node v itself. Let v be a set of neighbors of a given order, represented by... This represents a set of secondary neighbors.
[0094] To aggregate information from these neighboring nodes using a graph attention network to obtain an embedded representation of entity v, an attention mechanism is first defined that learns the relative importance of different neighbors to the central node. For any neighboring node... Attention coefficient α vu Calculated as:
[0095]
[0096] Where a is the learnable weight vector of the attention mechanism, W is the weight matrix of the feature transformation, and h v and h u and are the feature vectors of nodes v and u, respectively, and | denotes the concatenation operation. LeakyReLU is the activation function. Here, the attention coefficients of the first and second layer neighbor nodes to the center node are calculated.
[0097] Next, we need to calculate the attention coefficients of the second-level neighbor nodes to the first-level neighbor nodes. For any first-level neighbor node... and any second-level neighbor node corresponding to the first-level neighbor node u. Attention coefficient α uk Calculated as:
[0098]
[0099] Among them, h k Let h′ be the feature vector of node k. After obtaining the attention coefficients from the two-layer neighbor nodes to the center node and the attention coefficients from the second-layer neighbor nodes to the first-layer neighbor nodes, the importance of the center node to the second layer needs to be added to the attention coefficients from the second-layer neighbor nodes to the first-layer neighbor nodes. This can get rid of the problem of excessive redundant information in the second-layer neighbor nodes and the weak correlation between them and the center node. Therefore, the aggregated feature h′ of the first-layer neighbor nodes... u The formula is as follows:
[0100]
[0101] Where σ() is the activation function, α vk It is the attention coefficient of the central node to its second-level neighbor nodes, α. uk It is the attention coefficient of the first-layer neighbor node to the second-layer neighbor node. In this way, we obtain the embedding representation of the first-layer neighbor node. This embedding representation not only combines the neighborhood information of the second-layer neighbor node, but also strengthens the relevance to the central node through the graph attention network.
[0102] Finally, the embedding representation h′ of the central node v is further... v It is obtained through a linear combination of weighted neighbor features, which not only combines the aggregated features h′ of the first-level neighbor nodes. u The embedding also includes information about the relationships between neighbors at one layer. vu By performing connection operations to embed the node, and aggregating information from relationships and neighbors, a more complete representation of the central node's embedding is obtained, as shown in the following formula:
[0103]
[0104] After obtaining the embedded representation of the central node, the encoding function of the image autoencoder is essentially completed. Next, a node feature matrix X is constructed to represent the initial and final representation of each node, with a shape of (N, F), where N is the number of nodes and F is the feature dimension of each node. Then, an adjacency matrix A is constructed to represent the graph structure, with a shape of (N, N), where A... ij This indicates whether there is an edge between node i and node j. A represents ij The matrix is transposed. The node embedding representation is then optimized by minimizing the reconstruction error using an inner product decoder. The goal of the graph autoencoder is to minimize the reconstruction error, which can be achieved using a binary cross-entropy loss function.
[0105]
[0106] This results in a more accurate representation of the embedded central entity node.
[0107] Step 4: Embed relationships into the small sample knowledge graph through relationship path aggregation, such as... Figure 4 As shown, relation embeddings are obtained through the constructed path subgraph, and dual relation embeddings are constructed to model the relation representation from an aggregation perspective, as detailed below:
[0108] Step 41: Model the relation representation by aggregating relation paths, such as... Figure 4 As shown above, we first define the constructed path subgraph and traverse a path starting from the head entity h. This path can be represented as an ordered pair of nodes and edges (r1, r2, ..., r...). l Formalized as:
[0109] h→u1→u2…→u l-1 →t
[0110] Each node u i and edge r i The beginning and end echo each other. Therefore, for any path π = (r1→r2…→r... l A sequence R can be defined. π This accurately represents the traversal order of nodes and edges on path π.
[0111] In the process of constructing a relation-level attention model based on neighborhood information, an attention mechanism is adopted to correctly evaluate the relevance between each relation in the path and the target relation. This mechanism is based on the state vector h of the head node. t and relation vector c r To calculate the attention weight for each relation, given the combination of the head node and the timestamp (h,t), the formula for calculating the attention weight is:
[0112]
[0113] Among them, c r The target relation vector, The vector representation of the system in the path, where U and θ are trainable parameters, U T and θ T This represents its matrix transpose, and [·; ·] denotes the concatenation operation of vectors. The intermediate representation n through nonlinear transformation. i The normalized importance weights for each relation are used to calculate the weights, which is achieved through a softmax function:
[0114]
[0115] Here, R h→t β represents the set of path relationships from the head node h to the tail node t. i Normalized importance weights for each relation.
[0116] Finally, the Bi-GRU (Bidirectional Gated Cyclic Unit) model is used to take each path as input and output the relationship level of the path.
[0117] Step 42: Model the relation representation by constructing semantic aspects of triples, such as... Figure 4 As shown in the lower section, a Transformer encoder is introduced to interactively process N paths. The Transformer model relies on its self-attention mechanism to handle the interactions between elements in the sequential data; it processes the path embeddings through self-attention and a feedforward network. Output h final This includes rich semantic representations that take all path information into account. This yields embedding vectors for N paths.
[0118] By supporting a centralized given source node h s With target node t s Path embedding set And given the source node h in the query set q With target node t q Path embedding set Using the methods described above, a set of support set path embedding vectors is constructed. and query set path embedding vector set Construct a similarity matrix S h The elements of the matrix express and The similarity between them.
[0119] Then, an aggregation function is applied to extract similarity features. Since the paths extracted from the graph are unordered and independent, the RBF (Radial Basis Function) kernel aggregation function is used to extract accumulated similarity features. Specifically, first, for matrix S... h each line Perform max pooling to obtain the maximum similarity. It represents the set of vectors h(h) embedded in the query set path. q ,t q The most likely matching term h in ) i Next, It is transformed into an eigenvector of length Γ. Generated using Γ RBF kernels, each feature The mean μ is used by the γth kernel γ and variance σ γ The generation is shown in the formula below. All kernels represent the distribution of similarity, therefore... express Close to μ γ The degree of similarity, i.e., the γth similarity feature. The transformation from one-dimensional similarity to Γ-dimensional feature vectors can improve the discriminative power of similarity features.
[0120]
[0121] Step 5: Construct a loss function to score triples, matching and scoring triples in the support set and the query set. Based on the final loss value, train a few-sample knowledge graph completion model using stochastic gradient descent. The specific details are as follows:
[0122] A path-based similarity embedding φ is converted into a score using a multilayer perceptron (MLP) layer, and max pooling is performed on the scores of all K-samples to output a single score g(h). q ,t q ,S r Specifically, it is described as follows:
[0123]
[0124] Where h q ,t q ∈S r ,P(h i ,t i ) for h i to t i The path embedding set. φ(,) represents the feature vector obtained through step S42 using the similarity matrix, which is then trained using a loss function and updated with parameters using the Adam optimizer; the loss function expression is as follows:
[0125]
[0126] Where m represents the boundary between positive and negative samples, and L r The loss function. (Set) Contains incorrect query entity pairs They are the correct query entity pairs Q r ={(h q ,t q The opposite of the erroneous entity pair.
[0127] Step 6: After completing the model training in Step 5, the model can be used for actual knowledge graph completion tasks.
[0128] For example, for a missing triple (h, r, ?) to be completed, we need to predict whether the head entity h and the relation r may contain tail entities. First, we extract each entity from the candidate entity set and construct a separate triple (h, r, ?) to be determined. i Then, in step 5, the triples from the support set and the undetermined triples from the query set are extracted and fed into the loss function to calculate the scores. This yields the score array [score0, score1, ..., score...]. m Sort the score array and use the relations in the candidate triplet with the highest score as the completion result.
[0129] Although the present invention has been described herein with reference to embodiments thereof, the above embodiments are merely preferred embodiments of the present invention, and the implementation of the present invention is not limited to the above embodiments. It should be understood that those skilled in the art can design many other modifications and implementations, which will fall within the scope and spirit of the principles disclosed in this application.
Claims
1. A few-sample knowledge graph completion method based on graph structure information, characterized in that, Includes the following steps: S1: Pre-train the triples in the knowledge graph to obtain the entity relation embedding information of all knowledge graphs; at the same time, construct a small sample task set and divide different relations into different task sets according to the knowledge graph relations; The support set and query set are divided according to the number of training samples. S2: Use the small sample task set as the positive sample set, perform negative sampling operation, add the negative sampling result to the positive sample set to form an expanded sample set, extract the knowledge graph subgraph for each sample in the sample set, and construct the corresponding neighbor subgraph and path subgraph. S3: The graph attention network is used to dynamically assign weights to the first-level neighbor nodes and the second-level neighbor nodes respectively to aggregate the information of the central node and finally obtain the embedding of the central entity. S4: Obtain relation embeddings through the constructed path subgraph, construct dual relation embeddings, and model relation representations from both aggregation and semantic interaction perspectives to achieve triple relation representation embeddings; S5: Match and score the relationship representations of triples in the training set and triples in the test set to obtain the loss value, and train the small sample knowledge graph completion model based on the final loss value using stochastic gradient descent. S6. Divide the small sample task to be tested into a support set and a query set. Generate the score of the support set for the candidate triples in the query set through the model. Finally, select the highest score as the completion result. Step S2 specifically includes the following sub-steps: S21: Negative sampling construction, using Bernoulli negative sampling, for the positive sample set. Each sample construction There are 1 negative samples, which are then grouped into a set of positive and negative samples, where The hyperparameter for the number of negative samples; S22: Neighbor Subgraph Construction; Construct a two-level neighbor subgraph based on the central node. For a pair of triples, construct the subgraph with the head entity and the tail entity as the central nodes respectively. First, select the entity set. The central node in Get the set of all first-level neighbor nodes of the central node. : in, As a first-level neighbor node, First, obtain the set of edges between nodes; then obtain the set of neighboring nodes in the second layer. : Where u represents the second-level neighbor nodes; for the first-level neighbor node set, all nodes are taken, and for the second-level neighbor node set, the top nodes are taken. Each node is unique; Step 23: Constructing the path subgraph; Use a bidirectional breadth-first search algorithm to extract the path subgraph relating entity pairs; For supporting entity pair sets Each supporting entity pair , Specifically, given the maximum path length Entity from scratch Start execution A breadth-first search is used to collect neighbors with different hop counts. and entities from scratch The corresponding paths of different lengths to these neighbors, i.e., the left-hand paths; Similarly, from the tail entity Start, and execute A jump-breadth-first search is used to obtain neighbors. and from To their corresponding paths, i.e., the paths on the right; Then, calculate the intersection. The neighbors in the intersection are used to connect the left and right paths, generating paths of different lengths from... arrive The path is represented as This ultimately yields a multi-hop path between the head and tail entities.
2. The method for few-sample knowledge graph completion based on graph structure information according to claim 1, characterized in that, The specific steps of S1 are as follows: S11. Pre-train the triples in the knowledge graph using the transfer embedding model to obtain the pre-embedding information of all triples. S12. Divide the knowledge graph into small sample tasks according to the relationship, select a set number of triples of the relationship as small sample tasks to construct the dataset, and divide it into training, validation and test sets according to the set ratio. The other triples in the knowledge graph are then classified as background knowledge graphs.
3. The method for few-sample knowledge graph completion based on graph structure information according to claim 1, characterized in that, The embedding of the central entity is obtained through the following steps: First, we define an attention mechanism; for any neighbor node... Attention coefficient Calculated as: in, It is the learnable weight vector of the attention mechanism, and the superscript T indicates transpose; It is the weight matrix of the feature transformation. and These are nodes and eigenvectors, This represents the concatenation operation; LeakyReLU is the activation function. It is the feature vector of node k. At this time, the attention coefficients of the first and second layer neighbor nodes to the center node are calculated. Then calculate the attention coefficient of the second-level neighbor node to the first-level neighbor node; for any first-level neighbor node and first-level neighbor nodes any corresponding second-level neighbor node Attention coefficient Calculated as: Aggregation characteristics of first-level neighbor nodes The formula is as follows: in, () is the activation function. It is the attention coefficient of the central node to its second-level neighbor nodes. It is the attention coefficient of the first-level neighbor node to the second-level neighbor node; Further, the central node Embedded representation It is obtained through a linear combination of weighted neighbor features, as shown in the following formula: in, Information about neighbor relationships at the first level. For connection operation; Finally, construct the node feature matrix. The initial rotation of each node is represented by the shape shown below. ,in The number of nodes is F, where F is the feature dimension of each node, and then an adjacency matrix is constructed. , representing the structure of the graph, with the shape as Then, the node embedding representation is optimized by minimizing the reconstruction error through the inner product decoder, and finally the central entity node embedding representation is obtained.
4. The method for few-sample knowledge graph completion based on graph structure information according to claim 3, characterized in that, The specific implementation process of the triple relation representation embedding is as follows: S41: First, define the constructed path subgraph, starting from the head node. Begin traversing a path; this path can be represented as an ordered series of nodes and edges. Formalized as: Each node and edge The beginning and end echo each other; therefore, for any path A sequence can be defined. To accurately represent the path The order in which nodes and edges are traversed; The attention mechanism is used to calculate the attention weight of each relation, given a combination of the head node and the timestamp. Attention weight The calculation formula is: in, The target relation vector, Vector representation of the system in the path. and These are training parameters. and This represents its matrix transpose, and Represents the concatenation operation of vectors; an intermediate representation through nonlinear transformations. To calculate the normalized importance weight of each relation, through a Implemented using functions: in, Indicates the beginning node To the tail node A set of path relationships in the middle. Normalized importance weights for each relation; Finally, a bidirectional gated loop unit is used to take each path as input and output the relationship level of the path; S42: Model the relation representation by constructing a semantic aspect of triples, interactively process N paths using a Transformer encoder, and process the path embeddings through self-attention and feedforward networks in the Transformer encoder to output... It contains a rich semantic representation that takes into account all path information, resulting in The embedding vectors corresponding to each path; By supporting centralized given source nodes With the target node Path embedding set and given a source node in the query set With the target node Path embedding set Using the Transformer encoder, a set of path embedding vectors supporting the set is constructed. and query set path embedding vector set Construct a similarity matrix The elements of the matrix express and Similarity between them; Then based on the similarity matrix Accumulated similarity features are extracted using the kernel aggregation function of the radial basis function (RBF) to obtain the final feature vector. ,in The maximum similarity is given.
5. The method for few-sample knowledge graph completion based on graph structure information according to claim 4, characterized in that, Step 5 is described in detail below: Path-based similarity embedding is performed using a multilayer perceptron (MLP) layer. Convert to scores, and perform max pooling on the scores of all samples to output a single score. Specifically, it is described as follows: in for arrive The path embedding set; This means that the feature vectors obtained through step S42 using the similarity matrix are trained using a loss function. The loss function... The expression is as follows: in, The set represents the boundary between positive and negative samples. Contains incorrect query entity pairs They are the correct query entity pairs Relative erroneous entity pairs.
6. The method for few-sample knowledge graph completion based on graph structure information according to claim 4, characterized in that, The formula for Bernoulli negative sampling is as follows: in, For knowledge graphs The average number of tail entities corresponding to each head entity; For knowledge graphs The average number of head entities corresponding to each tail entity; The Bernoulli probability for the replacement method is a value randomly generated during each negative sampling. When this value is less than... If the positive sample is obtained by randomly replacing the head entity, then the negative sample is obtained by randomly replacing the tail entity.
7. The method for few-sample knowledge graph completion based on graph structure information according to claim 4, characterized in that, Minimizing the reconstruction error is achieved through a binary cross-entropy loss function, as shown in the following formula: in, Representing the adjacency matrix Middle node and nodes Is there an edge between them? express Transpose of a matrix.
8. The method for few-sample knowledge graph completion based on graph structure information according to claim 4, characterized in that, The similarity matrix-based Accumulated similarity features are extracted using the kernel aggregation function of the radial basis function (RBF) to obtain the final feature vector. The specific steps are as follows: First, the matrix each line Perform max pooling to obtain the maximum similarity. This indicates embedding a set of vectors in the query set path. The most likely matching item ,Then Converted to a length of eigenvectors ,pass Each feature is generated using RBF kernels. By the Average usage per core and variance The formula for generation is shown below: All kernels represent the distribution of similarity, therefore express close to The degree of, that is, the One similarity feature.