A few-shot knowledge graph completion method based on relation slot attention and path perception

By combining a relational path graph neural network and a relational slot attention module with a slot-aware TransE scoring function, the problem of insufficient feature extraction and inadequate utilization of multi-hop relational path information in knowledge graph scenarios with few samples is solved. This achieves high-precision knowledge graph completion and improves the model's generalization ability and the feature recognition of entity relationships.

CN122174936APending Publication Date: 2026-06-09CHONGQING UNIV OF TECH

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
CHONGQING UNIV OF TECH
Filing Date
2026-01-30
Publication Date
2026-06-09

AI Technical Summary

Technical Problem

Existing knowledge graphs have weak generalization ability in scenarios with few samples, insufficient feature extraction, and fail to effectively utilize multi-hop relationship path information, resulting in insufficient completion accuracy.

Method used

The Relation Path Graph Neural Network (RPGNN) is used to aggregate multi-hop relation contexts. The relation slot attention module adaptively induces potential relation slots, and the slot-aware TransE scoring function is combined to complete the knowledge graph with few samples. The model parameters are optimized to improve the recognition and accuracy of entity and relation features.

Benefits of technology

It significantly improves the recognition accuracy of entity and relation features, achieves high-precision few-sample knowledge graph completion, has strong generalization ability in complex relation structures, and is suitable for various information retrieval tasks that rely on knowledge graphs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122174936A_ABST
    Figure CN122174936A_ABST
Patent Text Reader

Abstract

This invention discloses a few-shot knowledge graph completion method based on relation slot attention and path awareness, belonging to the field of knowledge graph technology. The method first obtains a set of support, query, and negative sample triples corresponding to the target relation; constructs a local relation subgraph for each triple, aggregates multiple contexts through a relation path graph neural network, generates structure-enhanced entity pair representations, and combines them into triple feature vectors; based on the support feature set, the relation slot attention module adaptively induces the characterization of potential relation slots for different relation sub-patterns; generates a global relation prototype vector based on the relation slots, and constructs a slot-aware context representation for each query triple; combines the two and completes the scoring through a slot-aware TransE scoring function, using grouped cross-entropy ranking loss to optimize model parameters, thus achieving few-shot knowledge graph completion. This method overcomes the limitations of single prototype modeling, accurately captures multimodal semantics of relations, and improves the completion accuracy and generalization ability in few-shot scenarios.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of knowledge graph technology, specifically to a few-shot knowledge graph completion method based on relation slot attention and path awareness. Background Technology

[0002] Knowledge graphs, as a structured data representation, accurately depict semantic relationships between entities through triples (head entity, relation, tail entity) and have been widely applied in fields such as intelligent question answering, recommendation systems, and natural language processing. However, due to limitations in data collection and the dynamic nature of knowledge updates, existing knowledge graphs generally suffer from missing triples, meaning they are incomplete. This severely restricts their application in high-precision scenarios. The few-shot knowledge graph completion task aims to complete the query triples for a target relation using a small number of labeled support triples, providing an effective approach to solving the sparsity problem of knowledge graphs and becoming a current research hotspot in the field of artificial intelligence.

[0003] Traditional knowledge graph completion methods rely heavily on large amounts of labeled data for model training, resulting in extremely poor generalization ability in scenarios with few samples. To improve the effectiveness of feature extraction, researchers have attempted to introduce attention mechanisms to capture key associations between entities and relations. However, early attention mechanisms often employed single-dimensional feature interaction methods, making it difficult to fully exploit the fine-grained semantic information within triples. Furthermore, existing methods frequently neglect the graph structure characteristics of knowledge graphs, failing to effectively utilize contextual information in multiple relational paths. This leads to insufficient recognizability of the generated entity and relation representation vectors, and the completion accuracy falls short of practical requirements.

[0004] Chinese patent (publication number: CN118396091A) discloses a knowledge graph completion method based on a multi-directional attention mechanism. This method constructs a scoring matrix by calculating the multi-directional attention scores of each element in the triple initialization vector, and introduces a directional position mask matrix to optimize the attention scoring function. Combined with a convolutional neural network, it achieves deep feature extraction, significantly improving the fine-grainedness of feature characterization compared to the traditional single attention mechanism. However, this patent solution still has significant shortcomings: First, it is not adapted for scenarios with few samples, and the model is prone to overfitting when the number of supported triples is extremely small; second, it only relies on the interaction features of the elements within the triples and does not combine the multi-hop relationship path information of the knowledge graph, resulting in a lack of structural context support for entity representation and limited completion performance.

[0005] Therefore, there is an urgent need for a completion method that can adaptively mine core relational patterns in few-sample scenarios and fully integrate graph structure path information. This method can solve the problems of weak generalization ability, insufficient feature extraction, and rigid path weight allocation in existing technologies in few-sample scenarios, and achieve high-precision few-sample knowledge graph completion, thereby further expanding the application boundaries of knowledge graphs. Summary of the Invention

[0006] To address the aforementioned technical issues, this application discloses a few-shot knowledge graph completion method based on relation slot attention and path awareness, specifically including:

[0007] Obtain the set of support triples, query triples, and negative sample triples corresponding to the target relation in the knowledge graph;

[0008] For each triplet in the set of supporting triplets, the set of query triplets, and the set of negative sample triplets, a local relation subgraph is constructed around its head and tail entities. The multi-hop relation context is aggregated through the relation path graph neural network RPGNN to generate a structure-enhanced entity pair representation.

[0009] The entity pairs with the enhanced structure are combined into triplet feature vectors to obtain the support feature set, the query feature set, and the negative sample feature set.

[0010] Based on the set of supporting features, K potential relation slots are adaptively induced by the relation slot attention module, and each relation slot characterizes a relation sub-pattern.

[0011] A global relation prototype vector is generated based on the relation slots, and a slot-aware context representation is constructed for each query triple;

[0012] The query triples and negative sample triples are scored using the slot-aware TransE scoring function, combined with the global relation prototype vector and the slot-aware context representation.

[0013] Based on the scoring results, the model parameters are optimized using grouped cross-entropy ranking loss, and the few-sample knowledge graph is completed based on the optimized model.

[0014] Preferably, the message passing process of the relational path graph neural network (RPGNN) includes:

[0015] For any edge u→v in the local relational subgraph, construct the edge message. ,in Let u be the representation of the source node u in the l-th layer. Embed the relationship of edge u→v. For the initial embedding of the target node v, For edge relation type, φ is a linear transformation matrix specific to the relation type, and φ is the activation function;

[0016] Calculate the attention weights of the incoming edges ,in Let N(v) be the attention parameter vector, and N(v) be the set of incoming neighbors of node v.

[0017] Update node representation ,in Let b be the weight matrix of the self-loop terms, b be the bias term, and σ be the activation function.

[0018] Preferably, the formula for constructing the triplet feature vector is:

[0019] ,in , , respectively, represent the structure enhancement representation of the head entity and the tail entity; , represents the concatenation of representation vectors. For element-wise product, The absolute value of the element-wise.

[0020] Preferably, the slot initialization method of the relation slot attention module is as follows:

[0021] Where μ and σ are learnable parameters, It follows a standard normal distribution N(0,I). Let K be the initial set of slots, K be the number of slots, and d be the feature dimension.

[0022] Preferably, the iterative update process of the relation slot attention module includes:

[0023] Layer normalization is performed on the slot set and the supporting feature set to generate query, key, and value vectors. , , ,in , , X is the learnable weight matrix, and X is the stacking matrix of the support feature sets;

[0024] Calculate the matching score between slots and supporting features and assign weights. , ,in The dimension of the key vector;

[0025] Aggregate to obtain slot update information Update slot status via GRU unit And optimized by residual feedforward transformation .

[0026] Preferably, the formula for generating the global relation prototype vector is:

[0027] , ,in Let be the representation of the k-th relation slot. This is the result of the average convergence of the grooves. , This is the weight matrix. , For bias terms, This is the global relation prototype vector.

[0028] Preferably, the process of constructing the slot-aware context representation includes:

[0029] Calculate the matching score between the query feature vector and each relation slot. ,in The triplet feature vector of the m-th query / negative sample;

[0030] The weights are obtained through softmax normalization. Weighted aggregation yields the slot-aware context vector. .

[0031] Preferably, the slot-sensing TransE scoring function is: ,in , These are the augmented representations of the head and tail entities of the m-th sample, respectively. , Encode weight matrices for specific entities. , This is the encoding bias term.

[0032] Preferably, the optimization objective of the few-sample knowledge graph completion is that the calculation formula for the grouped cross-entropy ranking loss is: ,in For querying the set, To query the positive sample score of q, Let N be the score of the j-th negative sample in query q, and N be the number of negative samples corresponding to each query.

[0033] Compared with the prior art, the technical solution of this application has the following technical effects:

[0034] This invention aggregates multi-hop relational contexts through Relational Path Graph Neural Network (RPGNN) to generate structurally enhanced representations for entities. It effectively integrates the local subgraph structure and semantic association information of the knowledge graph, so that entity representation no longer depends on the globally average semantics of static embedding, and significantly improves the recognizability of entity and relational features.

[0035] The relation slot attention module of this invention can adaptively induce multiple potential relation sub-patterns, breaking the limitation of traditional methods that treat relations as a single modality. It achieves a refined characterization of multimodal relation semantics. Through iterative attention update and competitive allocation mechanism, each relation slot focuses on capturing specific semantic patterns, which greatly enhances the model's ability to express complex relation structures.

[0036] The slot-aware TransE scoring function of this invention combines the global relation prototype with the query-specific context representation. It adaptively corrects the embedding of head and tail entities through residual injection, enabling the scoring process to accurately match the semantic pattern of query triples. This effectively alleviates the semantic confusion problem between different queries and significantly improves the accuracy and reliability of triple discrimination.

[0037] This invention, through modular design and end-to-end optimization, achieves the organic integration of path-aware coding, multimodal relationship modeling, and personalized scoring. It not only has strong generalization ability in scenarios with few samples, but also robustly addresses the issues of relationship multiplicity and support sample heterogeneity. It provides a more flexible and adaptive solution for knowledge graph completion and is widely applicable to various information retrieval tasks that rely on knowledge graphs.

[0038] The above description is only an overview of the technical solution of this application. In order to better understand the technical means of this application and implement it in accordance with the contents of the specification, and to make the above and other objects, features and advantages of this application more obvious and understandable, the preferred embodiments of this application are described in detail below with reference to the accompanying drawings.

[0039] The above and other objects, advantages and features of this application will become more apparent to those skilled in the art from the following detailed description of specific embodiments in conjunction with the accompanying drawings. Attached Figure Description

[0040] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. In all drawings, similar elements or parts are generally identified by similar reference numerals. In the drawings, the elements or parts are not necessarily drawn to scale.

[0041] Based on the description of the figures and their corresponding technical content in the document, the titles of the figures are as follows:

[0042] Figure 1 Flowchart of the core steps of a few-shot knowledge graph completion method based on relation slot attention and path awareness;

[0043] Figure 2 A schematic diagram illustrating the overall architecture and collaborative working relationships of the core modules of the RSA-FKGC model;

[0044] Figure 3 Detailed implementation flowchart of entity updater, relation slot attention and slot awareness TransE scoring module;

[0045] Figure 4 Flowchart of relation sub-pattern induction and entity representation adaptive correction in a few-shot knowledge graph completion task;

[0046] Figure 5 A comparison chart of the MRR and Hits@1 performance trends of various models under different support set sizes (K-shot);

[0047] Figure 6 The influence of different numbers of relation slots on the MRR and Hits@K index of the RSA-FKGC model. Detailed Implementation

[0048] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. In the following description, specific details such as specific configurations and components are provided merely to help fully understand the embodiments of this application. Therefore, those skilled in the art should understand that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this application. In addition, for clarity and brevity, descriptions of known functions and structures are omitted in the embodiments.

[0049] It should be understood that the phrase "an embodiment" or "this embodiment" throughout the specification means that a specific feature, structure, or characteristic related to the embodiment is included in at least one embodiment of this application. Therefore, "an embodiment" or "this embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. Furthermore, these specific features, structures, or characteristics can be combined in any suitable manner in one or more embodiments.

[0050] Furthermore, reference numerals and / or letters may be repeated in different examples within this application. Such repetition is for the purpose of simplification and clarity and does not in itself indicate a relationship between the various embodiments and / or settings discussed.

[0051] In this article, the term "and / or" is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can mean: A exists alone, B exists alone, and A and B exist simultaneously. The term " / and" in this article describes another type of relationship between related objects, indicating that two relationships can exist. For example, A / and B can mean: A exists alone, and A and B exist alone. In addition, the character " / " in this article generally indicates that the related objects before and after it are in an "or" relationship.

[0052] In this article, the term "at least one" is merely a description of the relationship between related objects, indicating that there can be three relationships. For example, "at least one of A and B" can mean: A exists alone, A and B exist simultaneously, or B exists alone.

[0053] It should also be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion.

[0054] Example 1

[0055] This embodiment mainly describes a few-shot knowledge graph completion method based on relation slot attention and path awareness, such as... Figure 1 As shown, it specifically includes:

[0056] Obtain the set of support triples, query triples, and negative sample triples corresponding to the target relation in the knowledge graph;

[0057] For each triplet in the set of supporting triplets, the set of query triplets, and the set of negative sample triplets, a local relation subgraph is constructed around its head and tail entities. The multi-hop relation context is aggregated through the relation path graph neural network RPGNN to generate a structure-enhanced entity pair representation.

[0058] The entity pairs with the enhanced structure are combined into triplet feature vectors to obtain the support feature set, the query feature set, and the negative sample feature set.

[0059] Based on the set of supporting features, K potential relation slots are adaptively induced by the relation slot attention module, and each relation slot characterizes a relation sub-pattern.

[0060] A global relation prototype vector is generated based on the relation slots, and a slot-aware context representation is constructed for each query triple;

[0061] The query triples and negative sample triples are scored using the slot-aware TransE scoring function, combined with the global relation prototype vector and the slot-aware context representation.

[0062] Based on the scoring results, the model parameters are optimized using grouped cross-entropy ranking loss, and the few-sample knowledge graph is completed based on the optimized model.

[0063] Furthermore, such as Figures 2-3As shown, the model in this application is RSA-FKGC, designed specifically for low-shot scenarios. It addresses the problems of overly smooth relation representations and insufficient generalization ability in traditional methods by explicitly modeling the multimodal semantics and graph structure path information of relations. The model adopts a three-part architecture of feature enhancement, pattern mining, and accurate scoring. It consists of three core modules: Entity Updating Machine, Relational Slot Attention, and Slot-aware TransE Scorer, which work in sequence and cooperate to form an end-to-end inference link: the Entity Updating Machine is responsible for extracting structurally enhanced entity and triple features from the original triples;

[0064] The relation slot attention module adaptively mines multiple potential relation sub-patterns from the support set features, breaking the modeling limitations of a single prototype vector;

[0065] The slot-aware TransE scoring module accurately matches the mined relationship patterns with the query samples, achieving high-precision triplet discrimination through entity representation adaptive correction, and completing the few-sample knowledge graph completion, such as... Figure 4 As shown, the specific steps are as follows:

[0066] S1. Data Preparation and Task Definition

[0067] Obtain the set of support triples, query triples, and negative sample triples corresponding to the target relation in the knowledge graph; whereby the knowledge graph is defined as... , Represents a set of entities. A set representing relations. Let the set of fact triples be represented by the fact triples. Any fact triple is represented by the fact triples. express, and All belong to These correspond to the head entity and the tail entity, respectively. belong Correspondence; few-shot knowledge graph completion uses "relationships" as the task unit for modeling, with each relationship... This corresponds to one episode (few-sample task). Each episode contains three sets of triples: the set of supporting triples. Query the set of triples With negative sample triple set Supports sets of triples , containing the relationship -shot: Known facts are used to characterize the relational semantics of the current task and provide conditional context; query the set of triples. It consists of the facts to be predicted under the same relationship, in the form of Tail entity prediction or Head entity prediction requires, in actual inference, an analysis of the candidate entity set. Scoring and ranking; set of negative sample triples Through the The positive triplet in the sample is used to generate entity replacement sampling, specifically by fixing... Replace tail body or fix Replacing the head entity yields triples with the same relation as the positive example but not valid, used for contrastive discrimination and ranking learning during training; the relation sets of the training and testing phases do not overlap, i.e. The model in Cross-task learning is performed on top of this. Inductive inferences are made to assess the ability to generalize to unseen relationships.

[0068] S2, Entity updater processing, generating structural enhancement features.

[0069] The entity updater processes each triplet in the support triplet set, query triplet set, and negative sample triplet set to generate structure-enhanced entity pair representations and triplet feature vectors. The entity updater is the core of the model's feature extraction; its design goal is to explicitly inject local structure and multi-hop path semantics under limited sample conditions, freeing entity and triplet representations from the limitations of static embedding. It comprises two closely connected sub-modules: Relational Path GNN (RPGNN) and TripleFeature Composition. The specific processing flow is as follows:

[0070] Construction of local relational subgraphs: around each triplet Head and tail entities Constructing local relational subgraphs The subgraph is based on anchor point -hop neighborhood / path enhancement subgraph is specifically designed to capture relational context and structural associations within a multi-hop range around an entity, providing rich structural basis for entity representation;

[0071] RPGNN encoding: As a core submodule of the entity updater, RPGNN integrates structural information from local subgraphs into entity representations through multi-layer relation-aware message passing; assuming each entity... The initial representation is In the During layer propagation, for any edge (Its relation type is denoted as) Relational embedding is denoted as First, construct the edge message. ,in For activation function, A linear transformation matrix specific to the relation type is used to achieve accurate adaptation between the relation type and message features, ensuring that the semantic differences between different relations are effectively captured; to adaptively select more contributing structural evidence among multiple incoming edges of the same target node, an attention weighting mechanism is introduced, and the attention score is obtained through the original embedding of the target node. With edge message The result is obtained by linear projection after splicing and activation by LeakyReLU, as shown in the formula. ,in The attention parameter vector is then applied in the ingress neighborhood. Perform softmax normalization on the top to obtain Node updates are achieved through weighted aggregation of incoming edge messages, while incorporating self-loop terms to preserve the prior semantics of entities and avoid over-reliance on local noise structures under conditions of few samples. The update formula is as follows: ,in The weight matrix of the self-loop terms. For bias terms, For activation functions; after After layer propagation, take any triplet from episode. The head and tail entities are ultimately represented as structurally enhanced entity pairs. ,in , The ensemble-level output of RPGNN is , , These represent the entity pair representation sets corresponding to the support set, query set, and negative sample set, respectively.

[0072] Triple Feature Composition: This submodule combines the structurally enhanced entity pairs output by RPGNN. Further mapped to triplet feature vectors, the semantic information, interaction information, and difference information of the head and tail entities are explicitly encoded through multi-dimensional feature fusion, and the formula is constructed as follows: In the formula, ";" represents vector concatenation operation. " indicates element-wise multiplication operation, " represents element-wise absolute value operation; based on this construction method, the support feature sets are obtained respectively. Query feature set negative sample feature set ;set up To support triples The corresponding triplet features, As a feature dimension, it will support feature sets. Stacked in set form into a matrix This serves as the input data for the relation slot attention module.

[0073] S3. Relationship slot attention module processing: inducing relationship slots and generating key representations.

[0074] The support feature set is deeply processed through the relation slot attention module, which adaptively induces... This module identifies potential relation slots and generates a global relation prototype vector and a slot-aware context representation for the query. It is the core of the model for multimodal relation modeling, aiming to break the traditional assumption that relations are treated as unimodal semantics. It mines multiple potential sub-patterns (such as specific entity type combinations, specific path patterns, etc.) contained in relations from a small number of support samples, providing fine-grained semantic basis for subsequent accurate scoring. The specific processing flow is as follows:

[0075] Slot initialization: Relationship slots are initialized in round 0. ,in and For learnable parameters, Follows a standard normal distribution , This initial set of slots is used for initialization. This initialization method avoids the degenerate convergence problem caused by fixed initialization by sampling with a learnable Gaussian distribution. At the same time, it provides a natural and separable starting point for different slots, laying the foundation for subsequent functional differentiation.

[0076] Iterative attention update: A multi-round cross-attention and iterative update mechanism is adopted to gradually focus the slot vector on different semantic patterns in the support set; in the first round... During the iteration process, the slot set and support feature set are first subjected to LayerNorm (LN) processing to stabilize the numerical distribution during training and improve the model's generalization ability. The processing formula is as follows: , Subsequently, query, key, and value vectors are generated based on the normalized results. The query vector is generated from the slot set, while the key and value vectors are generated from the support feature set. , , , , , A learnable weight matrix is ​​used to map input features to a unified attention space; the matching score of the slots to supporting evidence is calculated. , Using the key vector dimension, this operation is used to accurately measure the semantic similarity between each slot and each supporting feature; softmax normalization is performed on the slot dimension to obtain the assigned weights. , And satisfy This normalization process generates a competitive allocation of each support sample among different slots, forcing the slot vectors to achieve functional differentiation and ensuring that each slot focuses on capturing a unique relational sub-pattern; based on the allocation weights, the value vectors are weighted and aggregated to obtain the updated information for each slot. , , To prevent tiny values ​​with a denominator of zero, this aggregation method effectively stabilizes the numerical range of support sets of different sizes, improving module robustness; iterative updates employ gated recursive units (GRUs) to implement incremental corrections based on historical slot states, as shown in the formula. Subsequently, a feedforward transform with residuals is applied to enhance the representation capability of the slot vector, corresponding to MLP stands for Multilayer Perceptron; after After rounds of iteration, the final set of relation slots is obtained. Each row vector corresponds to a relation slot representation, and each representation precisely describes a relation sub-pattern.

[0077] Global relation prototype vector generation: for relation slot sets By performing mean aggregation, we obtain , For the first Representation of relation slots, , This is the entity embedding dimension; then it is mapped back to the entity embedding dimension through two layers of linear transformation. ,get ,in , This is the weight matrix. , For bias terms; Within an episode, all queries and negative samples are shared to provide a global semantic representation of the relationship, integrating the common features of all sub-patterns;

[0078] Slot-aware context representation construction: For each query and negative sample, a dedicated slot-aware context representation is constructed to achieve accurate matching between the query and relation sub-patterns; the triple features of the query and negative sample are concatenated into... ( , , To query the number of samples, (Number of negative samples), calculate the matching score between each sample feature and each relation slot in dot product form. This score directly reflects the semantic fit between the sample and the corresponding relation slot; softmax normalization is performed on the slot dimension to obtain the matching weight. This is used to quantitatively measure the importance of each relation slot to the current sample; the slot set is read out based on the matching weights to obtain... , For the first The slot-aware context vector for each sample integrates the semantic information of the relation slots most relevant to the sample, providing a basis for sample-specific entity correction.

[0079] S4, the slot-aware TransE scoring module processes the data, completing scoring and model optimization.

[0080] The slot-aware TransE scoring module accurately scores query triples and negative sample triples, and optimizes model parameters based on the scoring results to ultimately complete the few-sample knowledge graph. This module is the core of the model's reasoning, and its design goal is to implement the multi-slot semantics of relations into specific triple discrimination. By explicitly distinguishing the matching geometry corresponding to different evidence patterns, it achieves personalized scoring that matches the specific needs of each case. The specific process is as follows:

[0081] Entity representation correction: Based on slot-aware context vectors, adaptive correction is performed on the head and tail entity representations of samples to make the entity representations fit the relation sub-pattern corresponding to the current query; from entity pair representations or Take the first one from the middle The head and tail entity vectors of each sample The slot encoder consists of two independent linear mapping branches, one dedicated to handling the slot conditional correction of the head entity and the other to the tail entity, ensuring the correction is targeted and accurate, and transferring the slot-aware context vector... Mapping to entity embedding dimension It is injected into the head and tail entity representations in the form of residuals to achieve adaptive correction. The specific formula is as follows: , ,in Encode weight matrices for specific entities. For encoding bias terms; the corrected entity representation is as follows , This representation integrates global structural information and local slot semantic information, significantly improving its recognizability;

[0082] Triple score: The consistency score of a sample under the current episode condition is calculated using the TransE distance method, and the formula is as follows: A higher score indicates a greater likelihood of a triple being true; in implementation, all queries and negative samples are first calculated uniformly. Then according to the number of positive samples Segmentation is performed to obtain (Positive sample score set) and (Negative sample score set) provides data support for subsequent loss calculation;

[0083] Model optimization: Grouped cross-entropy ranking loss is used as the optimization objective. This loss treats each query as a... - This classification problem is specifically designed for ranking needs involving few-sample completion. Its aim is to significantly increase the scores of positive samples compared to negative samples, thereby improving the model's ranking performance. The loss function formula is: ,in For querying the set, For query The positive candidate score, For query The Each negative candidate score The number of negative samples corresponding to each query is specified; model training uses the Adam optimizer to update parameters, and a warm-up cosine annealing strategy is employed for the learning rate. Mixed-precision training and global gradient pruning techniques are combined to improve training efficiency and numerical stability, avoiding gradient explosion or vanishing problems during training; the training process strictly follows an episodic few-shot setting, sampling a batch of tasks (episodes) from the training set in each epoch. The model first constructs a relational context from the support set, then scores the positive and negative candidates of the query, and based on... After calculating the loss, backpropagation is performed to update all learnable parameters in the entity updater, relation slot attention module, and slot-aware TransE scoring module. Model selection is based on the validation set MRR (mean reciprocal ranking) as the core indicator. The checkpoint of the optimal model is saved, and an early stopping strategy is used to avoid model overfitting.

[0084] Completion reasoning: During the evaluation phase, the candidate entity set is sorted in descending order of score within the episode to obtain the ranking of the real entities. And calculate the core evaluation indicators: , ,in To assess the total number of queries, This is an indicator function that takes the value 1 when the condition in parentheses is true, and 0 otherwise. The optimal model obtained through training outputs the completion results on the test episodes, thus completing the few-shot knowledge graph completion task.

[0085] This implementation details how to aggregate multi-hop structural information through a path-aware graph neural network, combine it with relation slot attention to mine multimodal relation sub-patterns, and then use slot-aware scoring to achieve adaptive correction of entity representation. This breaks through the limitations of single prototype modeling and improves the accuracy and generalization ability of relation semantic characterization in low-sample scenarios.

[0086] Based on Example 1, this example verifies the performance and effectiveness of the proposed RSA-FKGC model in the few-shot knowledge graph completion task. Using internationally recognized benchmark datasets, a multi-dimensional experimental scheme was designed, including overall performance comparison experiments, core module ablation experiments, support set size sensitivity analysis, verification of complex relationship modeling capabilities, and analysis of the impact of the number of relationship slots. Through systematic experimental design and data analysis, the superiority and practicality of the proposed technical solution are fully demonstrated from multiple perspectives, including model competitiveness, core module contribution, parameter robustness, and scenario adaptability.

[0087] The experiments selected two classic benchmark datasets in the field of few-shot knowledge graph completion: FB15K-237 and NELL. These two datasets are widely used in related research and have good representativeness and comparability. FB15K-237 is a subset selected from the Freebase knowledge base, after removing obvious inverse relations and redundant relation pairs to avoid the influence of data bias on the experimental results. This dataset contains 236 relations, 14,294 entities, and a total of 307,376 triples, with 295,845 in the training set, 3,056 in the validation set, and 8,475 in the test set. The relation distribution is relatively balanced, making it suitable for evaluating the performance of the model in common few-shot scenarios. The NELL dataset originates from a knowledge base built using a continuous information extraction system developed by Carnegie Mellon University. It covers a larger scale of entities and relations, containing 582 relations, 68,544 entities, and a total of 192,797 triples. The training, validation, and test sets contain 189,635, 1,004, and 2,158 records respectively. This dataset features more complex relational semantics and sparser entity associations, placing higher demands on the model's generalization ability and fine-grained semantic capture capabilities. To ensure the inductive and fair nature of the experiment, we strictly adhere to the few-shot learning task setting, completely separating the relation sets for the training and testing phases. The model learns cross-task relationships on the training set and performs completion reasoning on unseen relationships on the test set, truly reflecting the model's ability to generalize to new relationships.

[0088] To comprehensively evaluate the performance of RSA-FKGC, we selected two representative baseline models, covering mainstream technical paradigms of traditional knowledge graph completion and few-shot knowledge graph completion. The first category comprises traditional knowledge graph completion methods, including TransE, TransH, DistMult, and ComplEx. These methods rely on a large number of training samples to learn entity and relation embeddings and are not optimized for few-shot scenarios. They are used to verify the limitations of traditional methods under few-shot conditions, highlighting the necessity of our application's design for few-shot scenarios. The second category consists of methods specifically designed for few-shot knowledge graph completion, encompassing several core technical approaches: FAAN, GANA, and GMTatching based on metric learning, which complete few-shot inference by modeling similarity; MetaR and FSRL based on meta-learning, which adapt to new relations by learning cross-relation transferability; and NP-FKGC and ReCDAP based on probabilistic modeling and generation mechanisms, which capture relation distribution features through more flexible model structures. All experimental results for the baselines use official data published in their original papers to ensure the fairness and objectivity of the comparison.

[0089] The experiment uses the recognized core evaluation metrics in the few-shot knowledge graph completion task to comprehensively measure the model's completion performance: MRR (Mean Reciprocal Rank), which is used to evaluate the overall ranking quality of all query samples. It is calculated as the inverse average of the real entity rankings of all query samples. The higher the MRR value, the more accurate the overall ranking. Hits@K (K=1,5,10) is used to evaluate the model's Top-K prediction accuracy. It is calculated as the proportion of query samples whose real entity ranking is in the top K. The higher the Hits@K value, the better the model performs in high-priority predictions.

[0090] The training process strictly adheres to an episodic few-shot setting. Each training epoch randomly samples a batch of tasks (episodes) from the training set. Each episode contains a support set, a query set, and a negative sample set. Model optimization employs the Adam optimizer, with a warm-up cosine annealing learning rate strategy. The learning rate is gradually increased initially to stabilize model training, and then gradually decreased in subsequent stages to optimize convergence. Simultaneously, mixed-precision training and global gradient pruning techniques are combined to improve training efficiency and avoid gradient explosion or vanishing problems. Model selection uses validation set MRR as the core metric. When the validation set MRR stops improving for several consecutive epochs, an early stopping strategy is used to stop training, saving the optimal model parameter checkpoint and avoiding overfitting. In the evaluation phase, within each test episode, the candidate entity set is sorted in descending order of model output score. The ranking of the real entities is calculated, and then the MRR and Hits@1, Hits@5, and Hits@10 metrics are statistically analyzed. Finally, the average result of all test episodes is reported.

[0091] The core objective of the overall performance comparison experiment is to verify the competitiveness of RSA-FKGC with existing mainstream methods in the few-shot knowledge graph completion task. Experiments were conducted on the FB15K-237 and NELL datasets, with all models using the same evaluation criteria and task settings. The experimental results are shown in Table 1 below:

[0092] The experimental results show that traditional knowledge graph completion methods (TransE, TransH, DistMult, ComplEx) significantly lag behind dedicated few-shot completion methods on both datasets. This fully demonstrates that the traditional training mode, which relies on a large amount of labeled data, is difficult to adapt to few-shot scenarios, highlighting the necessity of designing a dedicated model for few-shot scenarios in this application. In specialized few-shot completion methods, RSA-FKGC demonstrates strong competitiveness: On the NELL dataset, RSA-FKGC achieves an MRR of 0.523, Hits@10 of 0.609, and Hits@5 of 0.585, all the best among the compared methods. Its Hits@1 score of 0.488 is second only to ReCDAP's 0.493, indicating superior overall performance. On the FB15K-237 dataset, RSA-FKGC achieves an MRR of 0.603, Hits@5 of 0.709, and Hits@1 of 0.501, all ranking first. Its Hits@10 score of 0.732 is second only to ReCDAP's 0.745, also showing the best overall performance. This result fully demonstrates that the three-part architecture proposed in this application—path-aware encoding, relation slot attention, and slot-aware scoring—can effectively capture multimodal semantic and graph structure information of relations in few-shot scenarios, significantly improving the accuracy of completion inference.

[0093] To verify the necessity and contribution of each core module in RSA-FKGC, we designed a two-layer ablation experiment at the module and component levels. By removing key modules or components, we compared the changes in model performance to clarify the core role of each module. The experiments were conducted on the NELL dataset using a 5-shot task setting. The experimental results are shown in Tables 2-3 below:

[0094] Table 2. Module-level ablation experimental results:

[0095] Table 3. Component-level ablation experiment results (for Slot-aware TransE Scorer):

[0096] Module-level ablation experiments show that after removing the relation slot attention module, the model's MRR decreased from 0.523 to 0.475, Hits@10 decreased from 0.609 to 0.549, and Hits@1 decreased from 0.488 to 0.417. All indicators showed significant declines, indicating that the relation slot attention module effectively improved the model's ability to characterize complex relations by adaptively inducing multimodal relation sub-patterns, and is a crucial support for the model's performance improvement. After removing the slot-aware TransE scoring module, the model's performance experienced a precipitous drop, with an MRR of only 0.221, a 57.7% decrease compared to the complete model, and Hits@1 decreased to 0.143, approaching the level of traditional methods. This fully demonstrates that the slot-aware TransE scoring module is the core of the model's accurate reasoning. By combining relation slot semantics with entity representation correction, it significantly improves the accuracy of triplet discrimination, which is one of the key innovations of this application.

[0097] Component-level ablation experiments demonstrate that each component of the slot-aware TransE scoring module plays an irreplaceable role: removing the query conditional context encoder z reduces the MRR to 0.261, indicating that the dynamic matching mechanism between queries and relation slots can provide personalized semantic support for each query; removing the entity-specific encoder reduces the MRR to 0.262, showing that the independent correction strategy for head and tail entities can better adapt to the semantic characteristics of different entities; sharing the head and tail entity encoders results in the worst model performance (MRR=0.191), further validating the necessity of entity-specific encoding. These results fully demonstrate that the core modules and components designed in this application cooperate with each other and are indispensable, jointly constituting a high-performance few-shot knowledge graph completion model.

[0098] Support set size is a key variable in few-shot learning tasks, directly affecting the model's ability to capture relational semantics. To verify the robustness of RSA-FKGC to support set size, we compared the performance trends of RSA-FKGC and mainstream comparison methods in terms of MRR and Hits@1 metrics under different shot settings of K=1, 3, 5, 7, 9. The experimental results are as follows. Figure 5 As shown (left chart shows MRR trend, right chart shows Hits@1 trend):

[0099] The experimental results show that, overall, the performance of all models increases as the support set size K increases from 1 to 5. This is because more support triples provide more sufficient semantic and contextual evidence of relationships, helping the model capture relationship patterns more accurately. When K continues to increase to 7 or 9, the performance of most models begins to fluctuate or decline. This is because as the support set size expands, the newly added samples contain noise or heterogeneous semantics, causing relationship patterns to become blurred, and the differences in the sensitivity of different models to noise and heterogeneous samples gradually become apparent.

[0100] RSA-FKGC exhibits strong robustness across different support set sizes: In terms of the MRR metric, RSA-FKGC reaches its optimal value of 0.523 at K=5, maintains a high level of 0.512 at K=7, and shows no significant performance decline even when K increases to 9. This is closely related to the structured aggregation mechanism of its relation slot attention module—this module can adaptively separate different relation sub-patterns from the support set, effectively filtering noise and heterogeneous information, making the model more adaptable to changes in support set size. In terms of the Hits@1 metric, RSA-FKGC reaches a peak of 0.488 at K=5, slightly declining when K increases to 7 and 9, but still maintaining a high overall level. This is because while the soft-weighted fusion strategy of slot attention can improve overall ranking stability (MRR metric), it also smooths out the score differences between high-scoring candidate entities, making them more susceptible to support set noise in highly competitive Top-1 scenarios. Overall, RSA-FKGC maintains excellent performance and demonstrates good robustness across different support set sizes.

[0101] Relationships in knowledge graphs often possess complex multiplicity characteristics, including one-to-one and one-to-many types. The ability to model complex relationships is a crucial metric for evaluating the performance of knowledge graph completion models. To verify the adaptability of RSA-FKGC to complex relationships, we conducted 5-shot completion experiments on the NELL dataset for two typical complex relationships: one-to-one and one-to-many. The performance of different models was compared, and the experimental results are shown in Table 4 below.

[0102] Experimental results show that traditional knowledge graph completion methods exhibit significant performance degradation in one-to-many relationships. For example, TransE's MRR drops from 0.198 for one-to-one relationships to 0.088 for one-to-many relationships, and Hits@1 decreases from 0.186 to 0.033. This is because traditional methods rely on fixed geometric assumptions to model relationships, making it difficult to adapt to the semantic ambiguity of one head entity corresponding to multiple tail entities in one-to-many relationships. Although meta-learning-based methods (such as MetaR and FAAN) outperform traditional methods overall, their improvement in one-to-many relationships is limited, indicating that their adaptability to relation multiplicity is still insufficient.

[0103] RSA-FKGC demonstrates outstanding advantages in complex relationship modeling tasks: for one-to-many relationships, its MRR reaches 0.532, Hits@10 reaches 0.613, Hits@5 reaches 0.560, and Hits@1 reaches 0.491, all of which are the best values ​​among all compared methods. Simultaneously, RSA-FKGC also maintains competitive performance in one-to-one relationships (MRR=0.589, Hits@10=0.720). Notably, the performance gap between RSA-FKGC and other methods in one-to-one and one-to-many relationships is significantly smaller than that of other compared methods, indicating stronger robustness to relationship multiplicity. This advantage stems from the core design of RSA-FKGC: the relationship slot attention module decouples different relational semantic patterns from a small number of support triples, while the slot-aware scoring module matches the most suitable semantic pattern for each query, effectively alleviating semantic ambiguity in one-to-many relationships and enabling the model to maintain high-precision completion reasoning capabilities even in complex relationship scenarios.

[0104] The number of relation slots, K, is a key hyperparameter of RSA-FKGC, directly determining the model's ability to characterize multimodal relation semantics. To determine the optimal number of relation slots and verify the model's sensitivity to this parameter, we conducted 5-shot completion experiments on the NELL dataset with different values ​​of K (1, 3, 5, 7, 9, 15, 20) to analyze the impact of the number of relation slots on model performance. The experimental results are as follows. Figure 6 As shown:

[0105] Experimental results show that the number of relation slots has a significant impact on model performance: when K=1, the model performance is the worst (MRR≈0.35), which is consistent with the limitations of traditional single-prototype modeling methods, proving that a single relation slot cannot capture the multimodal semantics of relations; as the number of relation slots increases from 1 to 5, the model's performance indicators continue to rise, reaching the optimal value when K=5 (MRR=0.523, Hits@10=0.609, Hits@5=0.585, Hits@1=0.488), indicating that an appropriate number of relation slots can enable the model to effectively separate multiple semantic patterns and provide richer contextual evidence for queries; when the number of relation slots continues to increase to 7, 9, 15, and 20, the model performance begins to gradually decline, especially the Hits@1 indicator, which declines more significantly. When K=20, the MRR drops to around 0.48 and the Hits@1 drops to around 0.42. This is because too many relation slots lead to fragmentation of relation evidence, making the semantic pattern corresponding to each slot unclear. At the same time, more noise is introduced during the soft attention aggregation process, affecting the model's discrimination accuracy.

[0106] These experimental results clearly demonstrate that, in a relation-based slot modeling framework, appropriate slot capacity is crucial for balancing semantic expressiveness and evidentiary stability. This application experimentally verifies that when K=5, the model achieves the optimal balance between semantic characterization and robustness, providing a clear reference for parameter setting in practical applications.

[0107] Through multi-dimensional system experiments, the proposed RSA-FKGC model demonstrates significant performance advantages and robustness in the few-shot knowledge graph completion task. Overall performance comparison experiments prove that RSA-FKGC outperforms or matches existing mainstream methods on two benchmark datasets, fully demonstrating its competitiveness. Ablation experiments of core modules verify the necessity and core contributions of the entity updater, relation slot attention module, and slot-aware TransE scoring module, especially the slot-aware TransE scoring module, which plays a decisive role in improving model performance. Support set size sensitivity analysis and relation slot number impact analysis show that RSA-FKGC has strong robustness to changes in key parameters and maintains excellent performance under different experimental settings. Verification of complex relation modeling capabilities demonstrates that RSA-FKGC can effectively adapt to complex relation scenarios such as one-to-one and one-to-many relationships, exhibiting good scenario adaptability.

[0108] The above are merely preferred embodiments of the present invention and are not intended to limit the scope of protection of the present invention. For those skilled in the art, the present invention can have various modifications and variations. Any changes, modifications, substitutions, integrations, and parameter changes made to these embodiments within the spirit and principles of the present invention, without departing from the principles and spirit of the present invention, through conventional substitutions or to achieve the same function, fall within the scope of protection of the present invention.

Claims

1. A few-shot knowledge graph completion method based on relation slot attention and path awareness, characterized in that, include: Obtain the set of support triples, query triples, and negative sample triples corresponding to the target relation in the knowledge graph; For each triplet in the set of supporting triplets, the set of query triplets, and the set of negative sample triplets, a local relation subgraph is constructed around its head and tail entities. The multi-hop relation context is aggregated through the relation path graph neural network RPGNN to generate a structure-enhanced entity pair representation. The entity pairs with the enhanced structure are combined into triplet feature vectors to obtain the support feature set, the query feature set, and the negative sample feature set. Based on the set of supporting features, K potential relation slots are adaptively induced by the relation slot attention module, and each relation slot characterizes a relation sub-pattern. A global relation prototype vector is generated based on the relation slots, and a slot-aware context representation is constructed for each query triple; The query triples and negative sample triples are scored using the slot-aware TransE scoring function, combined with the global relation prototype vector and the slot-aware context representation. Based on the scoring results, the model parameters are optimized using grouped cross-entropy ranking loss, and the few-sample knowledge graph is completed based on the optimized model.

2. The few-shot knowledge graph completion method based on relation slot attention and path awareness according to claim 1, characterized in that, The message passing process of the relational path graph neural network RPGNN includes: For any edge u→v in the local relational subgraph, construct the edge message. ,in Let u be the representation of the source node u in the l-th layer. Embed the relationship of edge u→v. For the initial embedding of the target node v, For edge relation type, φ is a linear transformation matrix specific to the relation type, and φ is the activation function; Calculate the attention weights of the incoming edges ,in Let N(v) be the attention parameter vector, and N(v) be the set of incoming neighbors of node v. Update node representation ,in Let b be the weight matrix of the self-loop terms, b be the bias term, and σ be the activation function.

3. The few-shot knowledge graph completion method based on relation slot attention and path awareness according to claim 1, characterized in that, The formula for constructing the eigenvector of the triplet is: ,in , , respectively, represent the structure enhancement representation of the head entity and the tail entity; , represents the concatenation of representation vectors. For element-wise product, The absolute value of the element-wise.

4. The few-shot knowledge graph completion method based on relation slot attention and path awareness according to claim 1, characterized in that, The slot initialization method of the relation slot attention module is as follows: Where μ and σ are learnable parameters, It follows a standard normal distribution N(0,I). Let K be the initial set of slots, K be the number of slots, and d be the feature dimension.

5. The few-shot knowledge graph completion method based on relation slot attention and path awareness according to claim 4, characterized in that, The iterative update process of the relation slot attention module includes: Layer normalization is performed on the slot set and the support feature set to generate query, key, and value vectors. , , ,in , , X is the learnable weight matrix, and X is the stacking matrix of the support feature sets; Calculate the matching score between slots and supporting features and assign weights. , ,in The dimension of the key vector; Aggregate to obtain slot update information Update slot status via GRU unit And optimized by residual feedforward transformation .

6. The few-shot knowledge graph completion method based on relation slot attention and path awareness according to claim 1, characterized in that, The formula for generating the global relation prototype vector is: , ,in Let be the representation of the k-th relation slot. This is the result of the average convergence of the grooves. , This is the weight matrix. , For bias terms, This is the prototype vector of global relations.

7. The few-shot knowledge graph completion method based on relation slot attention and path awareness according to claim 6, characterized in that, The process of constructing the slot-aware context representation includes: Calculate the matching score between the query feature vector and each relation slot. ,in The triplet feature vector of the m-th query / negative sample; The weights are obtained through softmax normalization. Weighted aggregation yields the slot-aware context vector. .

8. The few-shot knowledge graph completion method based on relation slot attention and path awareness according to claim 7, characterized in that, The slot-sensing TransE scoring function is: ,in , These are the augmented representations of the head and tail entities of the m-th sample, respectively. , Encode weight matrices for specific entities. , This is the encoding bias term.

9. The few-shot knowledge graph completion method based on relation slot attention and path awareness according to claim 1, characterized in that, The optimization objective of the few-shot knowledge graph completion is to calculate the grouped cross-entropy ranking loss using the following formula: ,in For querying the set, To query the positive sample score of q, Let N be the score of the j-th negative sample in query q, and N be the number of negative samples corresponding to each query.