A knowledge graph reasoning method that combines relational context and prototype memory
By combining relational conditional context and prototype memory, a relational conditional evidence base is constructed and injected with context vectors to obtain prototype information. Combined with the local structural representation generated by the graph encoder, a dual-path scoring mechanism is adopted to solve the problem of difficulty in distinguishing semantically similar entities in existing knowledge graph reasoning, and achieve higher accuracy and stable entity prediction.
Patent Information
- Application Number
- CN202611342530.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-01
- Publication Date
- 2026-11-17
AI Technical Summary
Existing text-based knowledge graph reasoning methods have low accuracy in distinguishing candidate entities that are semantically similar but have different relational conditions, and it is difficult to make accurate reasoning using contextual evidence.
This paper proposes a knowledge graph reasoning method that combines relational context and prototype memory. By constructing a relational evidence base, injecting relational context vectors and obtaining prototype information, a semantic relation vector is formed. Combined with the local structural representation generated by the graph encoder, a dual-path scoring mechanism is used for entity prediction.
It improves the accuracy and stability of knowledge graph reasoning, enabling robust ranking in scenarios with large numbers of candidates and similar scores, thus enhancing the model's discriminativeness and robustness.
Smart Images

Figure CN123117282A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of knowledge graph technology, and in particular to a knowledge graph reasoning method that combines relational conditional context with prototype memory. Background Technology
[0002] A knowledge graph (KG) is a structured representation of real-world entities and their relationships. It aims to infer unknown links based on known facts within the graph, serving as a crucial foundation for knowledge acquisition and structured understanding. Knowledge graphs are widely used in information retrieval, logical reasoning, recommender systems, materials science, and biomedical research.
[0003] In recent years, text-based methods based on pre-trained language models (PLMs) typically encode triple queries into vectors and match them with candidate entities to predict the optimal entity. For example, these methods usually first transform the triple query to be completed into a natural language text sequence containing entity and relational semantic information, then encode it into a high-dimensional feature vector using the powerful contextual semantic modeling capabilities of PLMs, and then calculate semantic similarity with the vectors obtained from the text description encodings of all candidate entities one by one. The entity with the highest matching degree is then selected as the optimal prediction result through ranking.
[0004] However, existing text-based methods rely solely on the overall similarity matching between the triple query vector and the candidate entity vector. The model struggles to accurately distinguish between candidate entities that are semantically similar but have different relational conditions, resulting in low accuracy in knowledge graph reasoning. Summary of the Invention
[0005] Therefore, it is necessary to provide a knowledge graph reasoning method that combines relational conditional context with prototype memory to address the aforementioned technical problems. This method improves the reasoning accuracy of knowledge graphs.
[0006] The following technical solution is adopted in this specification: This manual provides a knowledge graph reasoning method that combines relational conditional context with prototype memory, including: Obtain a relational evidence base consisting of a preset query and its corresponding entities with the same head and relationship, excluding true tails, from the knowledge graph; construct a basic query vector and multiple candidate entity vectors based on the preset query; Based on a preset query and a relation condition evidence base, a relation condition context vector is determined. This context vector is then injected into the preset query to obtain an initial enhanced query representation. A semantic relation vector is constructed based on the basic query vector, and prototype information most relevant to the current relation in the semantic relation vector is obtained from a learnable prototype library. This prototype information is injected into the initial enhanced query representation to obtain an enhanced query representation. The transpose of the enhanced query representation is multiplied by each candidate entity vector to determine the first-way score for each candidate entity vector. The enhanced query representation is then fused with the local structure representation of the knowledge graph generated by the graph encoder to obtain the final enhanced query representation. The transpose of the final enhanced query representation is multiplied by each candidate entity vector to determine the second-way score for each candidate entity vector. The optimal entity is predicted based on the first-way score and the second-way score of each candidate entity vector.
[0007] Optionally, the relational condition context vector is determined based on a preset query and relational condition evidence base, specifically including: Retrieve entities from the training set that have the same head and relation as the preset query, excluding true tails, as a set of relation condition evidence; The final set of relational conditional evidence is obtained by filtering based on the similarity between each element in the relational conditional evidence set and the basic query vector. Multi-head attention aggregation is performed on the final set of relational condition evidence to obtain the relational condition context vector.
[0008] Optionally, the final set of relational conditional evidence is obtained by filtering based on the similarity between each element in the relational conditional evidence set and the base query vector, specifically including: The similarity between each element in the relational condition evidence set and the basic query vector is sorted in descending order to obtain a similarity sequence; Select the first preset number of elements in the similarity sequence, and perform staged threshold filtering on the first preset number of elements; If the threshold filtering result is not empty, then the threshold filtering result will be used as the filtered relational condition evidence. If the threshold filtering result is empty, then the first preset number of elements are retained as evidence of the relationship conditions after filtering. The filtered relational condition evidence is deredundant to reduce redundancy among multiple pieces of evidence, resulting in the final set of relational condition evidence.
[0009] Optionally, a phased threshold filtering is performed on the first preset number of elements, specifically including: When the current training round is less than the preset switching round, the first stage similarity threshold is used as the current similarity threshold; when the current training round reaches or exceeds the preset switching round, the second stage similarity threshold is used as the current similarity threshold. The similarity of each element in the first preset number of elements is compared with the current similarity threshold. Elements with a similarity not lower than the current similarity threshold are retained to obtain the threshold filtering result.
[0010] Optionally, the relational condition context vector is injected into a preset query to obtain an initial enhanced query representation, specifically including: Multiply the base query vector and the relational condition context vector element by element to obtain the product result; The product result, relational condition context vector, and basic query vector are concatenated to obtain the joint feature vector; A linear transformation is performed on the joint feature vectors to obtain the gated intermediate representation; The gating intermediate representation is processed by an activation function to obtain the gating coefficients; Based on the gating coefficient, the basic query vector and the relational condition context vector are weighted, summed, and then normalized to obtain the initial enhanced query representation after injecting relational condition information.
[0011] Optionally, prototype information most relevant to the current relation in the semantic relation vector can be obtained from a learnable prototype library, specifically including: The cosine similarity between the learnable prototype library and the semantic relation vector is input into the normalized exponential function for solution, and the prototype semantic association weight matrix is obtained. After multiplying the transpose of the learnable prototype library with the prototype semantic association weight matrix and normalizing it, the prototype information most relevant to the current relationship is obtained.
[0012] Optionally, based on the first-way score and the second-way score of each candidate entity vector, the optimal entity is predicted, specifically including: Construct a high-confidence candidate set based on the first-way score of each candidate entity vector; Based on the second-way score of each candidate entity vector, the optimal entity within the high-confidence set and the optimal entity outside the high-confidence set are determined; The predicted entity is determined based on the best entity within the high confidence set and the best entity outside the high confidence set.
[0013] Optionally, based on the second-way score of each candidate entity vector, the optimal entity within the high-confidence set and the optimal entity outside the high-confidence set are determined, specifically including: The candidate entity corresponding to the maximum value of the second-way score in the high-confidence candidate set is determined as the optimal entity in the high-confidence candidate set; The candidate entity corresponding to the maximum score of the second path outside the high-confidence candidate set is determined as the optimal entity outside the high-confidence candidate set.
[0014] Optionally, the predicted entity is determined based on the best entity within the high-confidence set and the best entity outside the high-confidence set, specifically including: When the difference between the second-way score of the best entity outside the high-confidence candidate set and the second-way score of the best entity inside the high-confidence candidate set is greater than a preset threshold, the best entity outside the high-confidence candidate set is determined as the predicted entity. When the difference between the second-way score of the best entity outside the high-confidence candidate set and the second-way score of the best entity inside the high-confidence candidate set is less than or equal to a preset threshold, the best entity inside the high-confidence candidate set is determined as the predicted entity.
[0015] Optionally, a semantic relation vector is constructed based on the basic query vector, specifically including: The names and descriptions of the header entities in the preset query are encoded and normalized to obtain the text representation of the header entities; Take the difference between the base query vector and the header entity text representation; Normalize the difference to obtain the semantic relation vector.
[0016] This specification provides a knowledge graph reasoning device that combines relational conditional context with prototype memory, including: The module is used to obtain a relational evidence base consisting of a preset query in the knowledge graph and entities with the same head and relationship as the query but excluding true tails; and to construct a basic query vector and multiple candidate entity vectors based on the preset query. The computation module is used to determine the relation condition context vector based on a preset query and a relation condition evidence base, inject the relation condition context vector into the preset query to obtain an initial enhanced query representation; construct a semantic relation vector based on the basic query vector, and obtain the prototype information most relevant to the current relation in the semantic relation vector from a learnable prototype library; inject the prototype information into the initial enhanced query representation to obtain an enhanced query representation; multiply the transpose of the enhanced query representation with each candidate entity vector to determine the first-way score of each candidate entity vector; fuse the enhanced query representation with the local structure representation of the knowledge graph generated based on the graph encoder to obtain the final enhanced query representation; multiply the transpose of the final enhanced query representation with each candidate entity vector to determine the second-way score of each candidate entity vector. The prediction module is used to predict the optimal entity based on the first-way score and the second-way score of each candidate entity vector.
[0017] This specification provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the aforementioned knowledge graph reasoning method that combines relational conditional context and prototype memory.
[0018] This specification provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, implements the aforementioned knowledge graph reasoning method that combines relational conditional context and prototype memory.
[0019] The above-mentioned technical solutions adopted in this specification can achieve the following beneficial effects: In the knowledge graph reasoning method combining relational conditional context and prototype memory provided in this specification, this invention introduces a learnable prototype library. By matching the exclusive prototype information of the current relation with semantic relation vectors and injecting it into the query representation, the query representation accurately anchors the exclusive semantic features of the current relation, significantly improving the discriminativeness of the vectors. The semantically enhanced query representation is fused with the local structural representation generated by the graph encoder to form a semantic plus structural dual-path independent scoring mechanism. This retains the fine-grained semantic understanding advantage of PLM while making up for the deficiency of pure text methods in capturing graph topological relationships, thereby improving the accuracy of knowledge graph reasoning. Attached Figure Description
[0020] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0021] Figure 1 This document provides a flowchart illustrating a knowledge graph reasoning method that combines relational context and prototype memory. Figure 2 This is a schematic diagram of the RCC-RPMKGR provided by the present invention; Figure 3 This specification provides a schematic diagram of a knowledge graph reasoning device that combines relational conditional context with prototype memory. Figure 4 This is a schematic diagram of a computer device used in this specification to implement a knowledge graph reasoning method that combines relational conditional context and prototype memory. Detailed Implementation
[0022] To make the objectives, technical solutions, and advantages of this specification clearer, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments in this specification without creative effort are within the scope of protection of this application.
[0023] Devices such as desktop computers, servers, and laptops are capable of executing the solutions described in this manual. For ease of explanation, the following description will focus on servers as the primary execution method.
[0024] Knowledge graph reasoning methods can be categorized based on their utilization of structural and semantic information: (1) triple-based methods; (2) message-passing-based local structural reasoning methods; and (3) Transformer-based global modeling methods. Triple-based scoring methods (such as TransEp, DistMult, ComplEx, RotatE, etc.) reduce reasoning to matching and scoring entity-relation representations, which is efficient and scalable. However, they usually treat triples as approximately independent samples, easily ignoring higher-order neighborhood and path structures, thus limiting their application in multi-hop reasoning and inductive generalization scenarios.
[0025] Message-passing-based methods achieve structural reasoning by aggregating information in local neighborhoods, excelling at capturing local reachability and relational constraints. However, they may also be limited by issues such as information over-compression, noise propagation, and difficulty in modeling long-distance dependencies. Transformer-based methods attempt to model more global structural interactions using attention mechanisms. For example, KnowFormer combines structural reasoning with Transformer attention to alleviate the limitations of traditional message passing.
[0026] Furthermore, with the development of pre-trained language models, text-based KGC has become an important direction: SimKGC, with contrastive learning as its core, maps entity / relation text to a unified semantic space and performs retrieval-based reasoning, significantly improving the performance of text-driven link prediction. However, relying solely on text matching often lacks controllable relational contextual evidence, and relational semantics are easily instantiated by local samples, leading to unstable ranking in cases of long-tail relations and similar scores. To address the evidence organization problem, RAA-KGC enhances query representation by sampling relation-aware anchors with the same head and relation, verifying the effectiveness of relational contextual prediction for tail entities. Further, prompt-based reasoning work improves cross-setting contextual reasoning capabilities by constructing prompt graphs or example facts as contextual cues. However, the above methods still face challenges: how to construct a low-noise, controllable, learnable, and semantically stable relation modeling method to support robust ranking decisions in scenarios with large-scale candidates and similar scores.
[0027] To overcome this limitation, KG reasoning faces three fundamental challenges: (1) how to construct contextual evidence that is strongly relevant to the query, controllable, and learnable without introducing a large amount of noise. (2) how to avoid instantiating relational representations in local samples and instead form a stable relational semantic structure. (3) how to reduce the instability of scores and improve the reproducibility and consistency of the reasoning process in scenarios where large numbers of candidates and scores are close.
[0028] Existing text-based methods rely solely on the overall similarity matching between the triple query vector and the candidate entity vector. This matching method does not fully utilize the contextual evidence related to the current relationship, making it difficult for the model to accurately distinguish candidate entities that are semantically similar but have different relationship conditions, resulting in low accuracy in knowledge graph reasoning.
[0029] To address the aforementioned challenges, this invention proposes a text-structure collaborative framework (Relation-Conditioned Context and Relation Prototype Memory Knowledge GraphReasoning, RCC-RPMKGR) for knowledge graph reasoning. Through controllable aggregation of relational conditional evidence, stable relational semantic structure learning, and ranking decision enhancement mechanisms, a more accurate and robust knowledge graph reasoning method is formed. We propose a Relation-Conditioned Context (RCC) mechanism: for each query, we construct context candidates with the same header and relation online, and after screening, inject them into the query representation through attention aggregation and gating, thereby improving the discriminativeness and robustness of entity prediction without introducing external knowledge.
[0030] The Relational Prototype Memory (RPM) module is introduced to complete relational semantics and improve separability through prototype interaction: By using a learnable prototype library and structured regular constraints on relational representations, and by adding text-graph relational alignment constraints during training, relational representations are kept consistent in semantic space and structural space, thereby obtaining more stable and interpretable relational embeddings.
[0031] A unified strategy for decoding using a dual-perspective approach oriented towards reasoning is employed: simultaneously calculating the basic semantic score and the enhanced score, achieving adaptive correction through candidate shrinkage and difference threshold arbitration, and obtaining a more robust final ranking through rank ensemble.
[0032] The technical solutions provided by the various embodiments of this application are described in detail below with reference to the accompanying drawings.
[0033] Figure 1 This is a flowchart illustrating a knowledge graph reasoning method that combines relational context and prototype memory, as described in this specification. The method includes the following steps: S101: Obtain the pre-defined query in the knowledge graph and the corresponding entities with the same head and relationship but excluding true tails, forming a relational evidence base; construct a basic query vector and multiple candidate entity vectors based on the pre-defined query.
[0034] Construct a basic query vector based on the preset query. and entity vector This includes: constructing query-side text and entity-side text describing all candidate entities in the knowledge graph based on a preset query; and processing the query-side text through a query encoder to obtain the basic query vector. The entity-side text is processed by an entity encoder to obtain entity vectors. .
[0035] Based on the base query vector Constructing semantic relation vectors This includes: encoding and normalizing the names and descriptions of the header entities in the preset query to obtain the text representation of the header entities; and encoding the basic query vector. With head entity text representation Take the difference; normalize the difference to obtain the semantic relation vector. .
[0036] To achieve stable and scalable initial ranking capabilities in link prediction tasks across the entire entity space, this invention employs a dual-tower text inference engine. It provides low-variance ranking signals through retrieval-based semantic matching and supports pre-computation and caching of all entity representations during the inference phase to achieve efficient full-database scoring. Given a preset query... Construct query-side text With entity-side text Input the encoders for the query tower and the physical tower respectively, and then pool and process them. Normalization yields the following formula: Formula (1):
[0037] (1); in, Based on the query vector, For entity vectors, For query side text, This is the entity-side text.
[0038] The basic similarity function is defined by the inner product, and the similarity function is given by formula (2): (2); in, For preset query With candidate entities The basic similarity score between them This is a predefined query consisting of a header entity and relations. Candidate entities in the knowledge graph. This is the base query vector generated based on the header entities and relationships in the preset query. Candidate entities The corresponding entity vector, This indicates the transpose operation.
[0039] During training, a scoring matrix is formed within each batch. An additive margin is applied to the diagonal fractions of positive samples, and the fractions are scaled using a learnable temperature parameter to adjust the contrastive learning distribution; simultaneously, a filtered mask is constructed based on the training triplet dictionary to filter out samples with the same... The positions of other real tail entities are masked to minimum values to avoid false negatives.
[0040] Figure 2 A schematic diagram of the RCC-RPMKGR provided by the present invention is shown below. Figure 2 As shown, the overall method consists of four functional modules: a basic reasoning module, a relational context enhancement module for introducing relational conditional evidence, a relational prototype memory module for characterizing reusable relational semantic structures, and a dual-view robust inference module for fusing two signals and completing the final prediction.
[0041] In an exemplary embodiment, determining the relational condition context vector based on a preset query and a relational condition evidence base specifically includes: retrieving entities from the training set that have the same head and relation as the preset query and exclude true tails as a relational condition evidence set; filtering based on the similarity between each element in the relational condition evidence set and the basic query vector to obtain the final relational condition evidence set; and performing multi-head attention aggregation on the final relational condition evidence set to obtain the relational condition context vector.
[0042] In an exemplary embodiment, the final set of relational conditional evidence is obtained by filtering based on the similarity between each element in the relational conditional evidence set and the basic query vector. Specifically, this includes: sorting the similarity between each element in the relational conditional evidence set and the basic query vector in descending order to obtain a similarity sequence; selecting the first preset number of elements in the similarity sequence and performing staged threshold filtering on the first preset number of elements; if the threshold filtering result is not empty, then the threshold filtering result is used as the filtered relational conditional evidence; if the threshold filtering result is empty, then the first preset number of elements are retained as the filtered relational conditional evidence; and performing redundancy removal selection on the filtered relational conditional evidence to reduce the duplication among multiple pieces of evidence, thereby obtaining the final set of relational conditional evidence.
[0043] In an exemplary embodiment, a phased threshold filtering is performed on the first preset number of elements, specifically including: when the current training round is less than the preset switching round, the first stage similarity threshold is used as the current similarity threshold; when the current training round reaches or exceeds the preset switching round, the second stage similarity threshold is used as the current similarity threshold; the similarity of each element in the first preset number of elements is compared with the current similarity threshold, and elements with a similarity not lower than the current similarity threshold are retained to obtain the threshold filtering result.
[0044] Specifically, a two-stage screening process is performed on the evidence of relationship conditions: first, a Top-... The results are retained, and then a phased threshold filtering is applied. If the filtering results are empty, the results are reverted to the highest-scoring relational condition evidence. On this basis, MMR is further used for redundancy removal selection to achieve a balance between relevance and diversity.
[0045] In knowledge graph reasoning, given a query Only rely on Local textual semantics often fail to reflect the conditional constraints formed by the relationship in the training facts, thus making it difficult to understand the relationship within the same context. Unstable rankings arise when there are multiple tails, similar scores, or sparse relational semantics. Inspired by RAA-KGC, this invention proposes a relational conditional context enhancement module: without introducing external knowledge, it constructs strongly relevant and noise-controlled contextual evidence for each query online and injects it into the query representation in a learnable manner.
[0046] For training samples This invention retrieves facts with the same head and the same relation from the training set and excludes true tails as the relation condition evidence set, which is given by formula (3): (3); in, This is a set of evidence relating to conditions.
[0047] The number of relation condition evidences is truncated to a maximum of four in the implementation. Each relation condition evidence triple is then textualized into a head-relation-tail triplet input, which is used in a query-shared encoder to obtain a set of relation condition evidence vectors. This invention uses query vectors. The similarity to the evidence of the relational condition is given by formula (4):
[0048] (4); in, For similarity, Let be the set of relational condition evidence vectors.
[0049] In an exemplary embodiment, injecting the relational condition context vector into a preset query to obtain an initial enhanced query representation specifically includes: multiplying the basic query vector and the relational condition context vector element by element to obtain a product result; concatenating the product result, the relational condition context vector, and the basic query vector to obtain a joint feature vector; and performing a linear transformation on the joint feature vector to obtain a gated intermediate representation. The gating intermediate representation is processed by an activation function to obtain gating coefficients. Based on the gating coefficients, the basic query vector and the relational condition context vector are weighted, summed, and then normalized to obtain the initial enhanced query representation after injecting relational condition information.
[0050] Specifically, the relational condition context vector is injected into a preset query through gated fusion to obtain an initial enhanced query representation after injecting relational condition information. Specifically, this includes: the base query vector relational conditional context vector Multiply the elements together to obtain the product; combine the product with the relational context vector. Basic query vector Perform linear transformation Operation, obtain ;Will After linear activation The gating coefficients are obtained; based on the gating coefficients, the basic query vector is... Relational conditional context vector After weighted summation and normalization, the initial enhanced query representation after injecting relational condition information is obtained. .
[0051] For the final set of relational conditional evidence, this invention uses multi-head attention aggregation to obtain the relational conditional context vector. The attention distribution p is used, and evidence collapse and redundant aggregation are suppressed by attention entropy regularization and relational condition evidence similarity diversity penalty. Gated fusion is used to inject the relational conditional context vector into the preset query to obtain the initial enhanced query representation, as shown in formula (5):
[0052] (5); in, y The gating coefficients are used, and the gating bias is initialized to a positive value to preserve basic semantics in the early stages of training and gradually incorporate evidence enhancement. This is the initial enhanced query representation after injecting relational condition information. This is the relational conditional context vector.
[0053] S102: Determine the relation condition context vector based on the preset query and the relation condition evidence base, and inject the relation condition context vector into the preset query to obtain the initial enhanced query representation; construct the semantic relation vector based on the basic query vector, and obtain the prototype information most relevant to the current relation in the semantic relation vector from the learnable prototype library; inject the prototype information into the initial enhanced query representation to obtain the enhanced query representation, and multiply the transpose of the enhanced query representation with each candidate entity vector to determine the first-way score of each candidate entity vector; fuse the enhanced query representation with the local structure representation of the knowledge graph generated based on the graph encoder to obtain the final enhanced query representation, and multiply the transpose of the final enhanced query representation with each candidate entity vector to determine the second-way score of each candidate entity vector.
[0054] In an exemplary embodiment, constructing a semantic relation vector based on a base query vector specifically includes: encoding and normalizing the name and description information of the head entity in the preset query to obtain a text representation of the head entity; taking the difference between the base query vector and the text representation of the head entity; and normalizing the difference to obtain a semantic relation vector.
[0055] Specifically, although RCC can inject relational evidence with the same conditions into queries, its effectiveness is still limited by the coverage of training facts. When available evidence is scarce or relationships exhibit a long-tail distribution, relational semantics may still be instantiated by local samples, making it difficult to form a stable and reusable semantic structure. Therefore, this invention introduces Relational Prototype Memory (RPM) based on RCC, using a learnable prototype library to structurally complete and constrain relational semantics, thereby improving generalization stability and interpretability in long-tail relation scenarios. The enhanced query representation of RCC output is as follows: The basic query is represented as The header entity text is represented as The present invention first constructs a semantic relation vector as shown in formula (6):
[0056] (6); In an exemplary embodiment, obtaining the prototype information most relevant to the current relationship in the semantic relationship vector from the learnable prototype library specifically includes: inputting the cosine similarity between the learnable prototype library and the semantic relationship vector into a normalized exponential function for solving to obtain the prototype semantic association weight matrix; multiplying the transpose of the learnable prototype library with the prototype semantic association weight matrix and then normalizing to obtain the prototype information most relevant to the current relationship.
[0057] Specifically, based on cosine similarity and temperature coefficient, a learnable prototype library is developed. Perform attention retrieval and aggregation to obtain prototype information most relevant to the current relationship. Specifically, this includes: based on a learnable prototyping library semantic relation vector The cosine similarity between them is then subjected to softmax to obtain... ; will provide a learnable prototype library transpose and After multiplication, normalization is performed to obtain the prototype information most relevant to the current relationship. Maintain a learnable prototype library. Based on cosine similarity and temperature coefficient The prototypes are then subjected to attention retrieval and aggregation to obtain the prototype information most relevant to the current relationship, as shown in formula (7):
[0058] (7); The prototype semantics injected into RCC through gating fusion are represented by formula (8): (8); in, This is an enhanced query representation of the RPM output. During training, this invention introduces pull constraints to narrow down the query representation. and And apply Orth regularization to the prototype library to suppress inter-prototype correlation: Let It penalizes the portion of its off-diagonal related terms that exceeds the tolerance threshold, thereby avoiding prototype collapse and maintaining the separability and stability of the prototype space.
[0059] Textual reasoning can capture semantic similarity, but may overlook explicit graph topology. To supplement these structural cues, this invention introduces a graph branch containing inverse relationships onto the training graph, such as... Figure 1 (4) in Figure 1 As shown in (5) of the figure. The graph encoder generates a local structure representation. This is then combined with a prototype-enhanced semantic representation from RPM. To integrate.
[0060] set up The training graph is represented here. This invention employs a lightweight relation-aware graph encoder to perform neighborhood message passing, as shown in formula (9):
[0061] (9); in, Indicates the first In-layer entities The expression, For relation type Embedded, express The neighboring domain, This is a learnable projection matrix. After... After the layer, the encoder outputs the normalized entity embedding and relation embedding.
[0062] For a query This invention reads the head entity embedding in the graph branch. and relational embedding The local structure is then represented as formula (10). (10); in, This indicates element-wise multiplication. Therefore, It can capture query-related structural priors induced by graph branches.
[0063] This invention fuses the structural view and the semantic view in the following way to obtain the final enhanced query representation as formula (11): (11); in, To ultimately enhance the query representation, Used to control the degree of contribution of structural information. In practical applications, It can be set to a fixed value, a globally learnable parameter, or a relationship-specific parameter. The final result... It is used as an enhanced representation for subsequent fine-grained scoring branches.
[0064] The graph encoder takes as input entity nodes, relation edges, and relation type information. It performs relation-aware aggregation based on the connection structure and relation types between entities to obtain a graph structure representation of the entities. For queries, it reads the graph structure representations of the head entity and the current relation, and then fuses and normalizes them to obtain a local structure representation.
[0065] Based on the base query vector Final query representation and entity vector Calculate the first path score respectively Second-way rating Specifically, this includes: the base query vector transpose and entity vector Multiply by each other to get the score for the first path. This will ultimately enhance the query representation. transpose and entity vector Multiply by each other to get the second score. .
[0066] Specifically, under the full entity ranking setting, the candidate space is extremely large and the score distribution often exhibits dense intervals. A single scoring signal is prone to causing ranking instability and reducing prediction consistency. This invention combines basic semantic representation and enhanced semantic representation for scoring during the inference stage, and achieves robust ranking through candidate set constraints, difference threshold decision-making, and rank fusion.
[0067] For each query The model outputs the basic query vector. and and entity vector The two-way score is calculated using formula (12): (12) ; S103: Predict the optimal entity based on the first-way score and the second-way score of each candidate entity vector.
[0068] In an exemplary embodiment, predicting the optimal entity based on the first-way score and the second-way score of each candidate entity vector specifically includes: constructing a high-confidence candidate set based on the first-way score of each candidate entity vector; determining the optimal entity within the high-confidence set and the optimal entity outside the high-confidence set based on the second-way score of each candidate entity vector; and determining the predicted entity based on the optimal entity within the high-confidence set and the optimal entity outside the high-confidence set.
[0069] In an exemplary embodiment, the optimal entity within the high confidence set and the optimal entity outside the high confidence set are determined based on the second-way score of each candidate entity vector. Specifically, this includes determining the candidate entity corresponding to the maximum value of the second-way score within the high confidence candidate set as the optimal entity within the high confidence candidate set. The candidate entity corresponding to the maximum score of the second path outside the high-confidence candidate set is determined as the optimal entity outside the high-confidence candidate set.
[0070] In an exemplary embodiment, determining a predicted entity based on the best entity within the high-confidence set and the best entity outside the high-confidence set specifically includes: when the difference between the second-way score of the best entity outside the high-confidence candidate set and the second-way score of the best entity within the high-confidence candidate set is greater than a preset threshold, the best entity outside the high-confidence candidate set is determined as the predicted entity; when the difference between the second-way score of the best entity outside the high-confidence candidate set and the second-way score of the best entity within the high-confidence candidate set is less than or equal to the preset threshold, the best entity within the high-confidence candidate set is determined as the predicted entity.
[0071] Specifically, under the conduction setting, the training graph can be optionally utilized. -hop neighborhood pairs A bias is applied to introduce structural priors. Subsequently, the invention uses... Selecting a high-confidence candidate set and in The optimal entities inside and outside the set are obtained by formula (13):
[0072] (13); when Threshold arbitration is triggered at any time, allowing for... As the final top-1, otherwise choose This allows for adaptive correction when scores are close. Simultaneously, to reduce the impact of single-path noise on the overall ranking, this invention integrates the two-path ranking at the rank level: Let... , They are respectively , The ranking within the industry is then used to obtain the fusion score using Reciprocal Rank Fusion, as shown in formula (14):
[0073] (14); in, For merging scores.
[0074] by Generate the final ranking; if the decision coverage mode is enabled, the top-1 result obtained from threshold arbitration will be promoted to the first position in the fusion ranking to ensure decision consistency.
[0075] In an exemplary embodiment, the present invention verifies the effectiveness and feasibility of RCC-RPMKGR around three questions: (RQ1) whether the model achieves consistent gains and has statistical stability on multiple benchmark datasets; (RQ2) whether RCC and RPM exhibit complementary improvements in multi-tailed / long-tailed relationship scenarios; and (RQ3) whether structural branching and inference strategies bring gains.
[0076] This invention was evaluated on three commonly used datasets: The details of these three datasets are shown in Table 1.
[0077] Table 1. Statistics of the dataset used in this invention Dataset train valid test WN18RR 86835 3034 3134 FB15k-237 272115 17535 20466 Wikidata5M-Trans 20614279 5163 5163 To comprehensively evaluate the performance of the model in this invention, traditional embedded models and text / structure-aware models are selected as baselines. The embedded baselines include TransE, DistMult, RotatE, and HouseE, representing classic triple scoring methods. Simultaneously, this invention further selects five representative state-of-the-art models for comparison: 1) ULTRA, a structure-enhanced inductive reasoning model; 2) SimKGC, a textual knowledge graph completion method based on contrastive learning; 3) RAA-KGC, which enhances tail entity prediction through relation-aware anchors and contextual evidence; 4) KnowFormer, a global structure modeling method based on Transformer; and 5) DuetGraph, a recent model that improves inference performance by jointly modeling richer graph structure dependencies.
[0078] To answer (RQ1), this invention evaluated model performance on multiple datasets, with results shown in Table 2. For all datasets, this invention used the widely used metrics Hit@k and MRR for evaluation. Hit@k and MRR metrics were multiplied by 100. Baseline results are derived from their papers or copied from open-source code. Some baseline results are omitted in Table 2 due to missing experimental results or small portions of the source code for certain methods. This invention highlights the best method in each category for different model types in bold, and underlines indicate suboptimal methods.
[0079] Table 2 Comparison of RCC-RPMKGR results on different datasets Experimental results show that the RCC-RPMKGR model proposed in this invention exhibits strong performance in the link prediction task of knowledge graph reasoning, outperforming most baseline models on all three datasets.
[0080] To answer RQ2 and RQ3 questions and to better understand the effectiveness of different modules, this invention conducted experimental studies: (i) verifying the necessity and complementarity of the semantic enhancement module; (ii) verifying the contribution and stability of the structural branching and fusion mechanism; and (iii) verifying whether the robust ranking strategy in the reasoning phase brings gains.
[0081] Module ablation experiments show that modules have good complementarity in semantic enhancement, relation modeling and structural supplementation, which together improve the accuracy and robustness of knowledge graph reasoning.
[0082] Table 3 Ablation To verify the contribution of structural branching and its fusion mechanism to inference performance (RQ3) and to test the stability brought by fusion weight learning, this invention compares the results by only changing the structural branching-related components under the same training configuration and with a fixed semantic enhancement module. The results are shown in Table 4. The overall metrics consistently improve after introducing GraphEncoder compared to w / o Graph, indicating that structural message passing provides an effective structural prior for tail entity prediction.
[0083] Table 4. Parameter settings for different structural branches To verify whether the dual-view ranking strategy in the inference stage can bring benefits, this invention compares inference strategies on the same trained model parameters. This invention adds various methods step by step. The results show that RRF integrates the two at the rank level to improve overall robustness, while CTF corrects the top 1 at the decision level. This proves that the model of this invention can alleviate the problem of unstable ranking caused by a large number of candidates and similar scores.
[0084] Table 5 Feasibility Experiment of Dual-Perspective Ranking Strategy This invention proposes an evidence- and prototype-guided knowledge graph reasoning method based on text-structure fusion—RCC-RPMKGR. This method introduces a relational conditional context enhancement mechanism, dynamically constructing and filtering relation-related contextual evidence for each query, thereby improving the discriminative ability of tail entity prediction. Simultaneously, this invention designs a relational prototype memory module, supplementing and constraining relational semantics through learnable prototypes, thus enhancing the stability of relational representations. In the reasoning stage, this invention further employs a dual-view reasoning strategy, combining basic semantic scores with enhanced scores, and obtains a more stable final ranking result through candidate set shrinking, threshold-based arbitration, and ranking-level fusion. Experimental results show that the proposed method exhibits excellent performance.
[0085] Knowledge graph reasoning aims to infer unknown links based on known facts in the graph, and is a crucial foundational task for knowledge acquisition and structured understanding. In recent years, text-based methods based on pre-trained language models (PLMs) typically encode triple queries as vectors and match them with candidate entities, but they still have shortcomings in utilizing relational context, reusable inductive generalization of relational semantics, and robust decision-making during the reasoning phase. To address these shortcomings, this invention proposes a text-structure collaborative reasoning framework, RCC-RPMKGR. First, this invention designs a Relational Condition Context Enhancement (RCC) mechanism to strengthen discriminative cues under relational conditions. Second, this invention introduces Relational Prototype Memory (RPM), which uses a learnable prototype library and structured regularization to constrain relational representations, combined with semantic-structure alignment during training. Finally, a dual-view decoding strategy is used in parallel to compute the basic semantic score and the enhanced score during the reasoning phase. Experiments have been conducted on multiple knowledge graph reasoning benchmarks, and the results show that RCC-RPMKGR achieves good performance in the task.
[0086] When applying the knowledge graph reasoning method combining relational context and prototype memory provided in this manual, it is not necessary to rely on... Figure 1 The steps shown are executed in sequence. The specific execution order of each step can be determined as needed, and this manual does not impose any restrictions on it.
[0087] The above describes a knowledge graph reasoning method combining relational conditional context and prototype memory, provided by one or more embodiments of this specification. Based on the same approach, this specification also provides a corresponding knowledge graph reasoning device combining relational conditional context and prototype memory, such as... Figure 3 As shown.
[0088] Figure 3 This specification provides a schematic diagram of a knowledge graph reasoning device that combines relational conditional context and prototype memory, including: Module 301 is used to obtain a relational evidence base consisting of a preset query in the knowledge graph and entities with the same head and relationship as the query and excluding true tails; and to construct a basic query vector and multiple candidate entity vectors based on the preset query.
[0089] The calculation module 302 is used to determine the relation condition context vector based on the preset query and the relation condition evidence library, inject the relation condition context vector into the preset query to obtain the initial enhanced query representation; construct the semantic relation vector based on the basic query vector, and obtain the prototype information most relevant to the current relation in the semantic relation vector from the learnable prototype library; inject the prototype information into the initial enhanced query representation to obtain the enhanced query representation; multiply the transpose of the enhanced query representation with each candidate entity vector to determine the first-way score of each candidate entity vector; fuse the enhanced query representation with the local structure representation of the knowledge graph generated based on the graph encoder to obtain the final enhanced query representation; multiply the transpose of the final enhanced query representation with each candidate entity vector to determine the second-way score of each candidate entity vector.
[0090] The prediction module 303 is used to predict the optimal entity based on the first-way score and the second-way score of each candidate entity vector.
[0091] Specific limitations regarding the knowledge graph reasoning device that combines relational context and prototype memory can be found in the limitations of the knowledge graph reasoning method that combines relational context and prototype memory mentioned above, and will not be repeated here. Each module in the aforementioned knowledge graph reasoning device that combines relational context and prototype memory can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0092] This specification also provides a computer-readable storage medium storing a computer program that can be used to execute the above-described... Figure 1 The provided method combines relational context and prototype memory to form a knowledge graph reasoning approach.
[0093] This instruction manual also provides Figure 4 The schematic diagram of the computer device shown is as follows: Figure 4At the hardware level, the computer device includes a processor, internal bus, network interface, memory, and non-volatile memory, and may also include other hardware required for business operations. The processor reads the corresponding computer program from the non-volatile memory into memory and then runs it to achieve the above-mentioned functions. Figure 1 The provided method combines relational context and prototype memory to form a knowledge graph reasoning approach.
[0094] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the methods described above. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, or optical storage, etc. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc.
[0095] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
Claims
1. A knowledge graph reasoning method that combines relational conditional context with prototype memory, characterized in that, Includes the following steps: Obtain a relational evidence base consisting of preset queries in the knowledge graph and their corresponding entities with the same head and relationship, excluding true tails; Based on the preset query, construct a basic query vector and multiple candidate entity vectors; Based on the preset query and the relation condition evidence base, a relation condition context vector is determined, and the relation condition context vector is injected into the preset query to obtain an initial enhanced query representation; A semantic relation vector is constructed based on the basic query vector, and the prototype information most relevant to the current relation in the semantic relation vector is obtained from the learnable prototype library; The prototype information is injected into the initial enhanced query representation to obtain the enhanced query representation. The transpose of the enhanced query representation is multiplied by each candidate entity vector to determine the first score of each candidate entity vector. The enhanced query representation is fused with the local structure representation of the knowledge graph generated based on the graph encoder to obtain the final enhanced query representation. The transpose of the final enhanced query representation is multiplied by each candidate entity vector to determine the second score of each candidate entity vector. The optimal entity is predicted based on the first-way score and the second-way score of each candidate entity vector.
2. The knowledge graph reasoning method combining relational conditional context and prototype memory as described in claim 1, characterized in that, The step of determining the relational condition context vector based on the preset query and the relational condition evidence base specifically includes: Retrieve entities from the training set that have the same head and relationship as the preset query, excluding true tails, as a set of relation condition evidence; The final set of relational conditional evidence is obtained by filtering based on the similarity between each element in the relational conditional evidence set and the basic query vector. Multi-head attention aggregation is performed on the final set of relational condition evidence to obtain the relational condition context vector.
3. The knowledge graph reasoning method combining relational conditional context and prototype memory as described in claim 2, characterized in that, The step of filtering based on the similarity between each element in the relational condition evidence set and the basic query vector to obtain the final relational condition evidence set specifically includes: The similarity between each element in the relational condition evidence set and the basic query vector is sorted in descending order to obtain a similarity sequence; Select the first preset number of elements in the similarity sequence, and perform staged threshold filtering on the first preset number of elements; If the threshold filtering result is not empty, then the threshold filtering result is used as the filtered relational condition evidence. If the threshold filtering result is empty, then the first preset number of elements are retained as evidence of the filtered relational conditions. The filtered relational condition evidence is deredundant to reduce redundancy among multiple pieces of evidence, resulting in the final set of relational condition evidence.
4. The knowledge graph reasoning method combining relational conditional context and prototype memory as described in claim 3, characterized in that, The step of performing phased threshold filtering on the first preset number of elements specifically includes: When the current training round is less than the preset switching round, the first stage similarity threshold is used as the current similarity threshold; when the current training round reaches or exceeds the preset switching round, the second stage similarity threshold is used as the current similarity threshold. The similarity of each element in the first preset number of elements is compared with the current similarity threshold. Elements with a similarity not lower than the current similarity threshold are retained to obtain the threshold filtering result.
5. The knowledge graph reasoning method combining relational conditional context and prototype memory as described in claim 1, characterized in that, The step of injecting the relational condition context vector into the preset query to obtain an initial enhanced query representation specifically includes: Multiply the base query vector and the relational condition context vector element by element to obtain the product result; The product result, the relational condition context vector, and the basic query vector are concatenated to obtain a joint feature vector; A linear transformation is performed on the joint feature vector to obtain the gated intermediate representation; The gating intermediate representation is processed by an activation function to obtain the gating coefficients; Based on the gating coefficient, the basic query vector and the relational condition context vector are weighted, summed, and then normalized to obtain the initial enhanced query representation after injecting relational condition information.
6. The knowledge graph reasoning method combining relational conditional context and prototype memory as described in claim 1, characterized in that, The step of obtaining the prototype information most relevant to the current relation in the semantic relation vector from the learnable prototype library specifically includes: The cosine similarity between the learnable prototype library and the semantic relationship vector is input into the normalized exponential function for solution, and the prototype semantic association weight matrix is obtained. After multiplying the transpose of the learnable prototype library with the prototype semantic association weight matrix and normalizing it, the prototype information most relevant to the current relationship is obtained.
7. The knowledge graph reasoning method combining relational conditional context and prototype memory as described in claim 1, characterized in that, The prediction of the optimal entity based on the first-way score and the second-way score of each candidate entity vector specifically includes: Construct a high-confidence candidate set based on the first-way score of each candidate entity vector; Based on the second-way score of each candidate entity vector, the optimal entity within the high-confidence set and the optimal entity outside the high-confidence set are determined; The predicted entity is determined based on the best entity within the high confidence set and the best entity outside the high confidence set.
8. The knowledge graph reasoning method combining relational conditional context and prototype memory as described in claim 7, characterized in that, The second-way scoring based on each candidate entity vector, which determines the optimal entity within the high-confidence set and the optimal entity outside the high-confidence set, specifically includes: The candidate entity corresponding to the maximum value of the second-way score in the high-confidence candidate set is determined as the optimal entity in the high-confidence candidate set; The candidate entity corresponding to the maximum value of the second-way score outside the high-confidence candidate set is determined as the optimal entity outside the high-confidence candidate set.
9. The knowledge graph reasoning method combining relational conditional context and prototype memory as described in claim 7, characterized in that, The process of determining the predicted entity based on the optimal entity within the high-confidence set and the optimal entity outside the high-confidence set specifically includes: When the difference between the second-way score of the best entity outside the high-confidence candidate set and the second-way score of the best entity inside the high-confidence candidate set is greater than a preset threshold, the best entity outside the high-confidence candidate set is determined as the predicted entity. When the difference between the second-way score of the best entity outside the high-confidence candidate set and the second-way score of the best entity inside the high-confidence candidate set is less than or equal to a preset threshold, the best entity inside the high-confidence candidate set is determined as the predicted entity.
10. The knowledge graph reasoning method combining relational conditional context and prototype memory as described in claim 1, characterized in that, The construction of semantic relation vectors based on the basic query vector specifically includes: The names and descriptions of the header entities in the preset query are encoded and normalized to obtain the text representation of the header entities; Take the difference between the basic query vector and the header entity text representation; The difference is normalized to obtain the semantic relation vector.
