Knowledge graph reasoning method based on dynamic rule perception memory

By using a dynamic rule-based perception and memory method, combined with global relational memory and local rule compression, an interpretable reasoning path is generated, which solves the problem of insufficient utilization of dynamism and global semantics in knowledge graph reasoning, and achieves efficient and accurate knowledge graph reasoning.

CN121189442APending Publication Date: 2025-12-23NINGXIA UNIVERSITY +1
View PDF 0 Cites 5 Cited by

Patent Information

Application Number
CN202511218376.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-28
Publication Date
2025-12-23

AI Technical Summary

Technical Problem

Existing knowledge graph reasoning methods are inadequate in terms of dynamism, global semantic utilization, and high-quality path sampling, resulting in low reasoning efficiency and accuracy on large knowledge graphs, and a lack of dynamic rule adjustment and real-time query adaptability.

Method used

A dynamic rule-based perceptual memory approach is adopted, which generates a global relational memory matrix through a multi-head self-attention mechanism, combines local rule compression and high-quality path sampling, uses convolution operations and bidirectional breadth-first search to generate interpretable reasoning paths, and trains the method using a multi-class cross-entropy and noise contrast loss function to achieve dynamic adjustment of rule weights.

Benefits of technology

It significantly improves the interpretability and accuracy of knowledge graph reasoning, enhances Hit@1 and MRR metrics, and achieves efficient and accurate reasoning on large-scale knowledge graphs, overcoming the scalability and efficiency problems of traditional methods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121189442A_ABST
    Figure CN121189442A_ABST
Patent Text Reader

Abstract

The invention discloses a knowledge graph reasoning method based on dynamic rule perception memory. The method aims at solving the problems that an existing neural combination rule learning method is insufficient in expression ability and prone to splitting global semantics and local relation modes. The method comprises the following steps: introducing a lightweight dynamic relationship memory module, and executing self-attention on all relationships in a knowledge graph to capture global semantics; meanwhile, local relation interaction features are extracted through convolution, semantic fusion is carried out through a Transform encoder with multi-head attention and relative position coding, and unified and parallel-computing high-quality combination representation is constructed for each pair of relations in parallel. And meanwhile, a closed high-quality reasoning path is generated in combination with bidirectional breadth-first search. Through global semantic and local interactive collaborative modeling, the extendibility is ensured, the understanding of global semantics is enhanced, and the reasoning accuracy is improved. Global and local relation dependence is fused, an interpretable reasoning path is generated, and reasoning accuracy, expandability and robustness are improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of knowledge graph, and in particular to a knowledge graph reasoning method based on dynamic rule perception memory. BACKGROUND

[0002] Knowledge graph is widely used in search, recommendation, question answering and other artificial intelligence applications because it can provide structured knowledge representation. However, large-scale knowledge graphs in reality often have imperfections and noise, and need to be completed by reasoning to fill in missing facts. Existing knowledge graph reasoning methods are mainly divided into two categories: embedding-based methods and rule-based methods. Embedding methods encode entities and relationships into low-dimensional vector space, and predict potential triples through vector calculation, such as classic models TransE, RotatE, ConvE, etc. This kind of method has good prediction performance, but lacks explainability, because the reasoning process is hidden in vector operation and cannot give explicit reasoning path. On the contrary, rule-based methods use explicit first-order logic rules for reasoning, such as AMIE, RDF2Rules and other rule mining methods. Rule reasoning has high explainability, and each step of reasoning has corresponding rule basis, but it has poor scalability for large-scale graphs, and the rule search space explodes with the scale, resulting in low efficiency.

[0003] To alleviate the efficiency problem of symbolic reasoning, in recent years, several differentiable neural-symbolic fusion methods have appeared, which convert rule learning into trainable neural network models to optimize rule structure and weights simultaneously. Typical methods such as NeuralLP use recurrent neural networks to represent variable-length rule sequences to realize end-to-end optimization, DRUM efficiently captures rule patterns through bidirectional RNN, RNNLogic treats rules as latent variables and combines generator and discriminator for alternating training to improve reasoning performance on large graphs. The latest research such as NCRL decomposes rule combination into fragment recursive combination, improving the modular reasoning ability on large knowledge graphs. These methods balance performance and explainability to some extent, and can simultaneously learn rule structure and weights. However, they still have limitations: most models cannot dynamically adjust rule weights for specific queries, and use the same rule combination scoring mechanism for all samples; in addition, they still mainly rely on local relationship patterns and do not fully utilize global semantic information, and still have a long way to go for complex reasoning tasks. Therefore, further improving reasoning accuracy and efficiency while ensuring explainability is still a technical problem to be solved in the field of knowledge graph reasoning.

[0004] The closest prior art to the present application is the recently proposed neural symbolic reasoning model RulE and SARL, etc. On the one hand, the RulE method attempts to embed logical rules directly into a vector space, achieving soft fusion of symbolic knowledge by learning a unified embedding representation for entities, relations and rules. It assigns a static confidence to each rule and uses it to guide reasoning, to some extent alleviating the rigidity of pure symbolic reasoning. However, RulE still uses fixed rule weights for different queries, lacks a dynamic memory mechanism, and its use of semantic association of global relations is insufficient, and it cannot adjust the rule applicability according to the specific query context. On the other hand, the SARL model introduces a double-layer encoding of local structure attention and global shortest path embedding to extract entity local neighborhood information and overall topological features at the same time. This to some extent embodies the idea of combining global and local information, but SARL is mainly used to guide the generation of more accurate multi-hop rules, still belonging to the paradigm of off-line rule generation and re-application, lacking the ability to adjust the rule set in real time during reasoning. In addition, most existing methods use random or one-way search strategies for training data sampling, without strict control of the closure of the reasoning path, which can easily introduce invalid paths as training samples, affecting the robustness of model learning.

[0005] In summary, the prior art still has deficiencies in dynamicity, global semantic utilization and high-quality path sampling, and a new scheme is urgently needed to realize dynamic rule adjustment and efficient and accurate explainable reasoning on large-scale knowledge graphs. SUMMARY

[0006] To solve the above technical problems, the present application provides a knowledge graph reasoning method based on dynamic rule perception memory.

[0007] The present application is realized by the following technical solutions:

[0008] The knowledge graph reasoning method based on dynamic rule perception memory of the present application comprises the following steps:

[0009] Dynamic relation memory construction:

[0010] Obtain the embedding representation of each relation in the knowledge graph, the embedding representation being a pre-trained fixed-length real number vector;

[0011] Based on the multi-head self-attention mechanism, the relation embedding is globally modeled to generate a global relation memory matrix that can be dynamically updated according to the query during the reasoning process, the row and column indices of the matrix corresponding one-to-one to the relation categories, for forming a query-adaptive relation weight distribution;

[0012] Local rule compression:

[0013] For the inference rule sequence, the embedding representation of the adjacent relation pair is combined with the encoding vector representing its position in the rule sequence to obtain a relation pair vector containing position information;

[0014] The interaction features of the relation pair in the low-order adjacent range are extracted by convolution operation, and the global dependency information of the relation pair in the rule sequence context is obtained by combining the self-attention mechanism;

[0015] The merging priority score of each adjacent relation pair is calculated based on the scoring mechanism, and the relation pair with the highest score is selected for merging;

[0016] In the merging process, the relation pair vector is used as a query vector, and the key and value of the global relation memory matrix are fused by attention to generate an updated relation vector, until the rule sequence is compressed into a single rule representation vector;

[0017] High-quality path sampling:

[0018] Select anchor triples containing head entities and tail entities from the knowledge graph, and the entities are represented by unique identifiers;

[0019] Starting from the head entity and the tail entity respectively, bidirectional breadth-first search is performed to generate closed inference paths with closed head and tail entities, the path includes an ordered sequence of entities and corresponding relation sequence; The path that meets the closedness is taken as a positive sample rule, and the path that does not meet the closedness is taken as a negative sample rule;

[0020] Inference training:

[0021] The positive sample rule and the negative sample rule are input into the inference network including the dynamic relation memory module and the local rule compression module;

[0022] The inference network is trained based on the joint loss function of multi-class cross-entropy loss and noise contrast loss, to obtain a knowledge graph inference model that can dynamically adjust the rule weight and output the inference path when queried.

[0023] Preferably, the dynamic relation memory construction step comprises:

[0024] The embedding representation of each relation in the knowledge graph is linearly transformed to generate query representation, key representation and value representation respectively, and the linear transformation is realized by matrix multiplication;

[0025] The query representation, key representation and value representation are divided into several subspaces according to the multi-head structure, and the attention weight is calculated based on the dot product or cosine similarity of the query representation and the key representation in each subspace;

[0026] weighting the corresponding value representations with the attention weights to obtain an output vector of each subspace;

[0027] After the output vectors of each subspace are spliced and projected to the original embedding dimension, sequentially undergo the discard processing, residual connection and normalization processing, the global relationship memory matrix which can be called in the inference process is formed;

[0028] The global relationship memory matrix can dynamically highlight the relationship features related to each query and keep reuse in the same inference process.

[0029] Preferably, the local rule compression step comprises:

[0030] The position encoding is performed on the adjacent relationship pairs in the rule sequence according to their relative positions in the sequence to obtain a relationship pair vector containing position information;

[0031] The interaction features of the adjacent relationship pairs in the local range are extracted through convolution operation, and the global dependency information of the relationship pairs in the context of the rule sequence is obtained by using the sequence encoding structure;

[0032] The merging priority score of the relationship pairs is calculated based on a scoring mechanism, which comprehensively considers the similarity score of the local feature vector of the relationship pairs and the corresponding relationship in the global relationship memory matrix, and the similarity score is calculated by embedding vector cosine similarity;

[0033] The relationship pair with the highest score is selected for merging, and in the merging process, the relationship pair vector is used as the query vector, and the global relationship memory matrix is used as the key and value, and attention fusion is performed to introduce global semantic information, to generate an updated relationship vector;

[0034] The updated relationship vector is used to replace the merged relationship pair, and the above scoring, selecting and merging steps are repeated on the basis of the shortening of the rule sequence length, until the rule sequence is compressed into a single rule representation vector.

[0035] Preferably, the high-quality path sampling step comprises:

[0036] An anchor triple containing a head entity and a tail entity is selected from the knowledge graph;

[0037] Bidirectional breadth-first search is simultaneously performed on the directed graph structure of the knowledge graph with the head entity and the tail entity as the starting points, respectively, the node set is expanded layer by layer, and the search is terminated when the search depth reaches the preset upper limit or the intersection node is found;

[0038] The head entity path segment and the tail entity path segment are spliced at the intersection node to generate a complete inference path from the head entity to the tail entity;

[0039] The generated reasoning path is closedness verified, only the path that can connect the head entity and tail entity respectively at the beginning and end and the path relation combination is consistent with the original triple relation in semantics is reserved as a positive sample;

[0040] The semantic consistency is determined by comparing the vector similarity of the path relation combination and the original triple relation, and judging whether it exceeds the preset similarity threshold;

[0041] The path that does not meet the closedness is used as a negative sample, and is used for model training together with the positive sample.

[0042] Preferably, the reasoning training step comprises:

[0043] The positive sample rule and the negative sample rule are input into the reasoning network comprising the dynamic relation memory module and the local rule compression module to obtain a prediction probability distribution for each candidate relation;

[0044] The prediction probability of the target relation in the positive sample is maximized by using a first loss function, and the first loss function is a softmax multiclass cross entropy;

[0045] The prediction probability of the non-target relation in the negative sample is minimized by using a second loss function, and the second loss function is a binary classification logarithmic loss based on noise contrast estimation;

[0046] The first loss function and the second loss function are combined into a joint loss function according to a preset weight, and the parameters of the reasoning network are updated;

[0047] The first loss function is used to supervise the model to accurately output the true reasoning conclusion, and the second loss function is used to suppress the interference of noise paths on the model.

[0048] Preferably, the number of heads of the multi-head attention mechanism is set as an integral factor of the relation embedding dimension, so as to ensure that the dimensions of each subspace are equally divided and parallel computing is realized, and the dimensions of each subspace are equally divided;

[0049] The calculation complexity of the global relation memory matrix is proportional to the square of the number of relation categories, so that the calculation overhead is controllable under the condition that the size of the relation set is limited;

[0050] The global relation memory matrix is only triggered to recalculate when the query relation is detected to change in the reasoning process, otherwise the generated global relation memory matrix is reused in the current reasoning session.

[0051] Preferably, the scoring mechanism takes into account the similarity score between the local feature representation of the relation pair and the corresponding relation in the global relation memory matrix when evaluating the merge priority of adjacent relation pairs;

[0052] An entropy regularization term is introduced in the greedy selection merge process to prevent the model from over-relying on a small number of high-score relation pairs at the early stage of training and reducing the diversity of inference paths;

[0053] The multi-stage merge iteration of the rule sequence terminates when any of the following conditions is met:

[0054] The rule sequence length is compressed to a single relation representation;

[0055] The merge priority score of all current relation pairs is lower than the preset threshold.

[0056] Preferably, the maximum search depth of the bidirectional breadth-first search is set to no more than a preset integer d to limit the path length and reduce the computational overhead;

[0057] Set an upper limit N on the number of expandable nodes at each search level, and when the upper limit is reached, select the expansion node in order of the shortest path distance estimate from the target entity;

[0058] When there are multiple intersection nodes, preferentially select the intersection node that generates the shortest path length, and if the path lengths are the same, select the intersection node that is discovered first in the search process;

[0059] The closure verification not only requires that the head and tail entities of the path are consistent with the head and tail entities of the original anchor triple, but also requires that the path relation combination is semantically consistent with the original triple relation.

[0060] Preferably, the combination weight of the first loss function and the second loss function is dynamically adjusted according to the performance indicators of the validation set during the training process to balance the contributions of accurate supervision and contrastive learning at different training stages;

[0061] The negative sample rule is generated by performing bidirectional breadth-first search between the same anchor entity pairs as the positive sample rule and filtering paths that cannot form a closed loop, and the number of negative samples corresponding to each positive sample rule is fixed at a preset value m;

[0062] A class balance weight is introduced when calculating the first loss function to weight the loss value according to the frequency of different relation classes appearing in the training data, thereby reducing the impact of class imbalance on model convergence.

[0063] In summary, the present application proposes a knowledge graph reasoning method based on dynamic rule perception memory, which includes the following interconnected modules and steps: dynamic relationship memory construction module, local rule compression module, high-quality path sampling module and reasoning training module. The implementation points and optional implementation forms of each step are described in detail below without departing from the scope defined in the claims.

[0064] 1. Overview of the process

[0065] The present method is generally implemented according to the following process:

[0066] (1) Obtain the pre-trained embedding representation of all relationships in the knowledge graph (each relationship is a fixed-length real number vector);

[0067] (2) Perform global modeling on the relationship set through the dynamic relationship memory construction module to obtain a global relationship memory matrix that can be called by reasoning and dynamically highlighted according to the query;

[0068] (3) Perform local rule compression on the candidate rule sequence: first, incorporate positional encoding and extract local and context features for adjacent relationship pairs, then merge according to the scoring mechanism until it is compressed into a single rule representation; During the merging process, attention fusion from the global relationship memory is introduced to inject global semantics;

[0069] (4) Sample high-quality paths (positive samples) from the knowledge graph using closed-loop bidirectional BFS and construct negative samples that cannot be closed;

[0070] (5) Input the positive and negative samples into the reasoning network containing the above modules, train based on the joint loss function of multiclass cross-entropy and noise contrast loss, and thus obtain a knowledge graph reasoning model that can dynamically adjust the rule weight and output the reasoning path when queried.

[0071] The following describes each module and key implementation details one by one to fully explain the technical solution of the present application.

[0072] 2. Dynamic relationship memory construction

[0073] 2.1 Embedding and linear transformation

[0074] The pre-trained embedding representation of each relationship r in the knowledge graph is denoted as (dimension d). Stack all relationship embeddings into a matrix (R is the number of relationship categories).

[0075] Through linear transformation (matrix multiplication), the query matrix , the key matrix , and the value matrix are obtained, where , , is a trainable linear mapping matrix. This process is “embedding the relation into linearly transformed query, key and value representations respectively”.

[0076] 2.2 Multi-head structure and attention computation

[0077] Q, K, V are divided into h subspaces (i.e. reshape into , and attention weights are computed within each head. In order to satisfy the equal division of dimensions in each subspace, h is set as the integral divisor of d.

[0078] Within each subspace, attention weights can be computed by the dot product form (i.e. softmax (QK ) ) or cosine similarity, both of which are optional implementations. The corresponding value vectors are weighted and summed using attention weights to obtain the output vector of each head.

[0079] The output of each head is spliced and projected back to the original embedding dimension d, and then sequentially passes through dropout, residual connection and normalization (LayerNorm), finally forming the global relation memory matrix , whose row and column indices correspond one-to-one to the relation categories. This matrix is not only the global semantic view, but also the “dynamic memory” called in subsequent local merging / querying.

[0080] 2.3 Computational complexity and reuse strategy

[0081] The computational complexity of the resulting global relation memory matrix is proportional to the square of the number of relation categories R, which is controllable when the size of the relation set is limited (several tens to several hundreds), i.e. the computational complexity of the global relation memory matrix is proportional to the square of the number of relation categories, so as to keep the computational overhead controllable under the condition that the size of the relation set is limited.

[0082] In actual inference sessions, M can be reused within the same inference session, and only when it is detected that the current query (or query relation) changes will it trigger recalculation, otherwise the generated global relation memory matrix will be reused to save computation.

[0083] 3. Local rule compression

[0084] 3.1 Relation pair encoding and position encoding

[0085] Given a sequence of rule bodies , concatenate each adjacent relation pair , and add its relative position encoding in the sequence to obtain the relation pair vector containing position information ​That is, "combining the embedded representation of adjacent pairs with the encoded vector representing their position in the regular sequence".

[0086] 3.2 Local Convolution and Sequence Encoding

[0087] right One-dimensional convolution (Conv1D) is used to extract interaction features in the low-order neighborhood range (the convolution output is activated by the activation function σ) as a local feature representation.

[0088] The convolutional output is used to encode the input sequence using a structure such as a Transformer encoder to obtain global dependency information of relation pairs within the context of a regular sequence. The encoder supports relative position embeddings, allowing relation pairs at different positions to share parameters and be computed in parallel. The encoder ultimately outputs a vector for each relation pair. This is a combined representation of the adjacent pair.

[0089] 3.3 Merging Priority Scoring Mechanism

[0090] A merging priority score is calculated for each adjacent relation pair. The scoring mechanism comprehensively considers the similarity score between the local feature representation of the relation pair and the corresponding relation in the global relation memory matrix. The similarity score is calculated using the cosine similarity of the embedding vectors. In other words, the scoring function uses the local representation... Based on this, cosine similarity is introduced as a supplementary signal to evaluate the priority of the relationship pair in the merging process.

[0091] As a specific optional implementation, local scoring can be mapped to a scalar using a feedforward linear layer. The global similarity score is combined with the local score (e.g., weighted or other fusion strategies) to obtain the final merging priority. However, it does not limit which fusion coefficient must be used; the key is that the score reflects both local and global information.

[0092] 3.4 Greedy Selection, Attention Fusion and Update Merging

[0093] In each round of merging, the relation pair with the highest score is selected for merging (greedy Argmax selection). During the merging process, the selected relation pairs are represented as... As a query, the global relational memory matrix M is taken as the key / value, and multi-head attention fusion is performed to "read" the semantic information related to the relationship pair from the global semantic memory, generating an updated relationship vector. Then, through the feedforward network, residual and normalization, the final new relationship representation is obtained and replaces the position of the merged relationship pair in the original sequence. The attention fusion ensures that the merging result contains both local interaction semantics and global relationship knowledge. The attention structure here is compatible with the attention mechanism of dynamic relationship memory and can reuse its parameters / structure. That is, "in the merging process… while… attention fusion with the key and value of the global relationship memory matrix, generating an updated relationship vector."

[0094] 3.5 Multi-stage iteration and termination condition

[0095] The above scoring-selection-merging process is repeated (n−1) rounds or until the termination condition is met:

[0096] The rule sequence length is compressed into a single relationship representation; or

[0097] The current merging priority score of all relationship pairs is lower than the preset threshold, i.e., there are no significant mergable relationship pairs.

[0098] To prevent the model from over-relying on a few high-score combinations in the early training and causing a decrease in path diversity, an entropy regularization term can be introduced in the scoring and greedy selection process to regularize or encourage the entropy of the relationship pair score probability distribution, maintaining the diversity and robustness of the merging strategy.

[0099] 4. High-quality path sampling

[0100] 4.1 Anchor triple and bidirectional breadth-first search (Bidirectional BFS)

[0101] Select an anchor triple (h, r, t) containing head entity h and tail entity t from the knowledge graph. Starting from h and t, perform bidirectional breadth-first search on the directed graph structure of the knowledge graph: one end expands forward (from h outward), the other end expands backward (from t backward), and record the set of entities reachable at each layer and .

[0102] To control the search size, set a maximum search depth limit d (d is a preset integer and does not exceed this integer) and stop expanding immediately when an intersection node is found, and splice the two end paths to generate a complete reasoning path P from h to t.

[0103] 4.2 Upper limit of each layer expansion and node selection strategy

[0104] Set an upper limit N on the number of expandable nodes at each search level, and when the number of candidate expansion nodes exceeds the upper limit, sort them according to the shortest path estimation distance from the target entity (or another end frontier) in ascending order and preferentially select expansion (to improve the efficiency of finding intersection nodes and path quality).

[0105] 4.3 Intersection node selection priority

[0106] If there are multiple intersection nodes, the intersection node with the shortest path length will be preferentially selected; if multiple paths have the same length, the intersection node discovered first in the search process will be preferentially selected.

[0107] 4.4 Closeness and semantic consistency verification

[0108] Closeness verification is performed on the generated reasoning path P: the head entity h and the tail entity t of the path are required to be consistent with the head entity h and the tail entity t of the original anchor point triple (entity unique identifier matching), respectively, and the semantic combination of the path relations is required to be consistent with the original triple relation r. Semantic consistency can be judged by comparing the similarity (cosine similarity) between the path relation combination vector (e.g., the vector obtained by aggregating or combining the relation vectors on the path) and the original triple relation vector. If the similarity is higher than a preset threshold, it is considered to be semantically consistent, and thus a positive sample rule; otherwise, it is judged as not satisfying closeness.

[0109] The path that satisfies the closeness verification is regarded as a positive sample rule, and the path that does not satisfy the closeness is regarded as a negative sample rule. If no closed path is found within the limited depth, the triple can be skipped to generate a positive sample.

[0110] 5. Reasoning training

[0111] 5.1 Network input and output

[0112] The positive sample rules and corresponding negative sample rules obtained by bidirectional BFS sampling are input into the reasoning network containing a dynamic relation memory module and a local rule compression module. The network outputs a normalized prediction probability distribution for each candidate relation k , where represents the probability that the path P is closed by the kth relation, and corresponds to "unclosable", which is used to judge whether the path is closed and to which relation it is closed.

[0113] 5.2 First loss function: multi-class cross-entropy (supervised positive sample)

[0114] For positive samples, a Softmax multi-class cross-entropy loss is used to maximize the prediction probability of the true target relation. To alleviate the imbalance of relation categories in the training data, a class balance weight is introduced when calculating the cross-entropy (weighted cross-entropy, where the weight is set according to the frequency of each category in the training set, so as to balance the training), i.e. weighted cross-entropy .

[0115] 5.3 Second loss function: noise contrast (negative samples)

[0116] For negative samples, the response of the model to the noise path is suppressed by using noise contrast estimation (NCE) or a contrastive loss based on binary classification log loss. The specific form can use the log sigmoid score: for each negative sample path , the model gives a closed score , and the contrastive loss is constructed as , so as to strengthen the discrimination ability of positive and negative samples.

[0117] 5.4 Joint loss and weight balance

[0118] The first loss and the second loss are combined into a joint loss according to a preset weight : In order to balance the contributions of precise supervision and contrastive learning in different training stages, the combined weight of a can be dynamically adjusted during the training process according to the performance indicators of the validation set, for example, appropriately reducing a in the early stage to strengthen contrastive learning to suppress noise; and increasing a in the later stage to improve precise supervision.

[0119] 5.5 Negative sample generation and quantity constraint

[0120] For each positive sample rule, negative samples are generated by performing bidirectional BFS between the same anchor entity pairs and filtering paths that cannot form a closed loop, and the number of negative samples corresponding to each positive sample is fixed to a preset value m. Fixing m helps to improve training stability and batch design.

[0121] 6. Other implementation details and limitations

[0122] 6.1 Number of multi-head attention heads and subspace dimension

[0123] The number of multi-head attention heads h is set as an integer factor of the relationship embedding dimension d, which ensures that the dimensions of each subspace are equal and not less than 4, to meet the balanced needs of parallel computing and expression ability.

[0124] 6.2 Global relationship memory calculation reuse

[0125] The calculation complexity of the global relationship memory matrix M is O ( ) (R is the number of relationships), which is acceptable when the size of the relationship set is limited; in a reasoning session, M is reused before detecting changes in the query relationship, and is recalculated when the query changes are detected, to reduce redundant calculations.

[0126] 6.3 Scoring mechanism refinement

[0127] The scoring mechanism explicitly incorporates the similarity (cosine similarity) between local features (convolutional / encoder output) and corresponding relations in global memory into the evaluation index when assessing the merging priority of adjacent relations, to improve the semantic consistency of the merging decision.

[0128] 6.4 Entropy regularization

[0129] An entropy regularization term (based on the entropy of the probability distribution of the current round of relation pair scores) is introduced in the greedy selection merging process to prevent the model from excessively focusing on a small number of high-scoring relation pairs in the early stages of training, thereby maintaining the diversity and stability of the merging strategy.

[0130] 6.5 Merging iteration termination condition

[0131] The merging iteration terminates when any of the following conditions is met: the rule sequence is compressed into a single relation representation; or the merging priority score of all current relation pairs is below a pre-set threshold.

[0132] 6.6 Maximum search depth and level limit for bidirectional BFS

[0133] The maximum search depth of bidirectional BFS does not exceed a pre-set integer d; there is an upper limit N for the number of expandable nodes at each level, and when this limit is reached, the expandable nodes are selected in order of the estimated distance from the target entity from small to large.

[0134] 6.7 Intersection node priority rule

[0135] When there are multiple intersection nodes, the intersection node with the shortest path length is preferred; if the path lengths are the same, the intersection node discovered first in the search process is selected.

[0136] 6.8 Closure verification

[0137] Closure verification not only checks whether the path head and tail entities are consistent with the original anchor triple head and tail, but also requires that the path relation combination is semantically consistent with the original triple relation, and the semantic consistency is judged by vector similarity based on a threshold.

[0138] 6.9 Dynamic adjustment of joint loss weight

[0139] The combined weight α of cross-entropy and contrastive loss in the joint loss can be dynamically adjusted during training according to the performance of the validation set (such as Hits@k, MRR) to balance the influence of precise supervision and contrastive learning.

[0140] 6.10 Fixed number of negative samples

[0141] The number m of negative samples corresponding to each positive sample is a preset constant, so as to fix the contrast learning intensity.

[0142] 6.11 Category balance weight

[0143] Introducing a category balance weight in calculating cross entropy , so as to weight the loss value according to the occurrence frequency of different relationship categories in the training data, thereby reducing the influence of category imbalance on model convergence.

[0144] The beneficial effects of the present application are:

[0145] Compared with traditional embedding models (such as TransE, DistMult and other methods based only on vector calculation), the present application explicitly introduces a logical rule chain as an intermediate reasoning process, which can provide a clear rule path explanation for each reasoning result, significantly improving the explainability of the result. At the same time, in terms of accuracy, the present application effectively avoids the error reasoning mode that embedding methods are prone to fall into through dynamic memory and rule fusion, and according to experiments, higher Hit@1 and MRR index performances are achieved on complex relationship data sets.

[0146] Compared with pure symbolic rule mining methods (such as AMIE and other offline rule learning algorithms), the present application does not need to exhaust a large number of rules in advance for reasoning, which greatly improves the reasoning efficiency and scalability. Through online learning of rule weights and dynamic adjustment by a neural network, the present application can perform real-time reasoning on large knowledge graphs, while traditional symbolic methods are often difficult to apply when facing hundreds of thousands of entities and relationships. The present application maintains the high accuracy and rigorous reasoning of symbolic methods while overcoming the shortcomings of non-scalability.

[0147] Compared with recent neural-symbolic fusion models (such as Neural-LP, DRUM, RNNLogic, RulE, SARL, etc.), the present application introduces a new mechanism of global dynamic memory and local compression double path in the model architecture, which can dynamically adjust the rule combination in reasoning and avoid falling into local optimization by using global semantics. The existing methods usually use fixed rule patterns for all queries, or are limited to local information, while the present application realizes customized reasoning for queries. Experimental results show that on large data sets containing complex relationship patterns, the present application improves the Hits@1 index by several percentage points compared with the above-mentioned methods, proving the effectiveness of dynamic memory and closed-loop sampling in improving reasoning accuracy. BRIEF DESCRIPTION OF DRAWINGS

[0148] Figure 1 : the overall framework of the present application;

[0149] Figure 2 : the semantic similarity of the relationship vector of the present application is converted into an interpretable rule framework graph;

[0150] Figure 3 The similarity matrix diagram of relational memory modules on the WN18RR dataset in this invention;

[0151] Figure 4 The similarity matrix diagram of relational memory modules on the FB15K-237 dataset is presented in this invention.

[0152] Figure 5 Experimental diagram of closed path count analysis on UMLS dataset based on this invention.

[0153] Figure 6 : Experimental diagram of embedding size analysis of this invention on the UMLS dataset;

[0154] Figure 7 : A schematic diagram of the method steps of the present invention; Detailed Implementation

[0155] The present invention will be further described below with reference to the accompanying drawings and specific embodiments:

[0156] Example: The overall architecture of the knowledge graph reasoning method based on dynamic rule-aware memory provided by this invention is as follows: Figure 1 As shown, the overall process of this invention consists of four tightly coupled stages: "dynamic relation memory - local rule compression - closed-loop path sampling - joint loss training / online inference". First, the pre-trained vectors of each relation in the knowledge graph are input into a multi-head self-attention structure to construct a global relation memory matrix that can be dynamically updated according to the query. The system provides a global semantic view. Subsequently, adjacent relationship pairs in the candidate rule body are encoded using positional, convolutional, and sequence encoding. Merging priorities are calculated, and a greedy strategy is used to progressively compress them into a single rule representation. Training samples are generated by bidirectional BFS on anchor triples (h,r,t), and positive / negative rule paths are obtained by combining "closure + semantic consistency (based on cosine similarity threshold)". Finally, a weighted multi-class cross-entropy and noise contrastive loss are used for optimization, enabling the model to output both the probability distribution of the target relationship and the corresponding interpretable rule path during inference. This architecture revolves around two tightly coupled inference processes: a dynamic relationship memory path and a local compression path. On the one hand, the global relationship memory module provides a global semantic view for the current query, dynamically highlighting important relationships. On the other hand, the local rule compression module progressively merges multi-hop relationship chains to generate a compact rule representation. Ultimately, the results of these two paths interact in the memory-attention fusion unit to complete the inference prediction of the query. Furthermore, during training, a bidirectional BFS sampling mechanism is used to generate high-quality rule training samples, which are then optimized using a joint loss function.

[0157] After clarifying the overall framework, this invention further provides a conversion mechanism between relational similarity and rule generation. Figure 2 This demonstrates the transformation process of "relational semantic similarity—local relation pair encoding—memory-attention fusion—interpretable rule representation": On the one hand, relation embeddings are linearly mapped to form Q / K / V and multi-head attention is used to obtain a queryable global memory M, making semantically similar, inverse / combinable relations stand out in the memory space; on the other hand, adjacent relation pairs in the rule sequence ( , The system performs concatenation and relative position encoding, convolution to capture neighborhood interactions, and sequence encoding to model context dependencies, resulting in a combined representation. The scoring mechanism combines "local feature score + similarity signal with M (cosine similarity)" to determine the merging priority, greedily selecting the relation pair with the highest score. For query and M as key / value pairs, attention fusion is performed, and the new relation representation is updated via feedforward / residual updates. This process iterates until the entire rule body is compressed into a single vector. The resulting rule not only provides a prediction of the target relation but also retains the progressively merged path, score, and attention weights, forming an interpretable rule oriented towards a specific query.

[0158] To verify the modeling capability of global memory, this invention visualizes the relation similarity matrix on typical datasets. Figure 3 This is a relational memory similarity matrix on the WN18RR dataset, where the horizontal and vertical axes represent relation types, and the color intensity indicates the association strength between two relations in global memory. This matrix demonstrates the modeling ability of multi-head attention on the global relational structure—for example, symmetric / inverse relations form nearly symmetric highly correlated blocks on the matrix, and common combined links (such as the frequently co-occurring pattern A→B→C in the graph) have higher weights in their corresponding rows and columns, thus providing reliable global priors for attention reading during subsequent local merging. By comparing this matrix with the actual inference path, the model can dynamically emphasize more relevant relation clusters when facing different queries, improving the semantic consistency and interpretability of merging decisions.

[0159] Figure 4 This displays the relation memory similarity matrix on the FB15K-237 dataset. Compared to WN18RR, its relation set is larger and more diverse, and the matrix exhibits a more pronounced "block / band" structure, reflecting the global coupling of cross-type relations and the clustering effect of long-tail relations. Thanks to the global modeling of the memory matrix M, when faced with long chains, multi-hops, and semantically cross-domain rule bodies, the model can "read" relation clusters that better fit the current query in an attention-based manner during the compression stage, avoiding one-sided merging based solely on local neighborhood statistics, thus balancing efficiency and interpretability on complex datasets. For ease of reading, specific relation names are not labeled in the figure, but their acquisition method and matrix meaning are similar to those of the previous model.Figure 3 The same.

[0160] In terms of path sampling, Figure 5 The influence statistics of different search depth upper limit d and expandable node upper limit N on the number of closed paths, the proportion of positive / negative samples and the distribution of path length are given when the sampling strategy of "bidirectional BFS + closure verification + semantic consistency threshold" is used on the UMLS dataset: the horizontal axis exemplarily represents the sampling or path length / depth scale, and the vertical axis can represent the closed path count or proportion. This experiment is used to calibrate the sampling parameters to obtain enough and high-quality positive sample rules in the training set, while controlling the size of the negative sample that cannot be closed loop, so as to improve the supervision effect of the joint loss (cross entropy + noise contrast) on the model. The "closed" referred to in the figure means that the head and tail entities of the path are consistent with the anchor point (h, t), and the cosine similarity of the path relationship combination and the original relationship r in the embedding space is not less than the preset threshold, and the noise path is suppressed from the source.

[0161] Finally, Figure 6 The influence of embedding dimension d on performance (such as MRR / Hit@k) and resource overhead is analyzed: the horizontal axis is the relationship embedding dimension d (or its value group), and the vertical axis is the evaluation index or the measurement of reasoning / training overhead. The experiment is used to determine the reasonable d value interval on UMLS to balance the prediction accuracy and the calculation / storage cost. It should be noted that the number of heads h of multi-head attention is the integral divisor of d to ensure that the dimensions of each subspace are equal; the calculation complexity of the global relationship memory matrix increases by O(Rd2) with the number of relationship types R, while the setting of d mainly affects the dimension of each head subspace and the constant overhead within the linear mapping / attention, which is controllable overall when the R scale is limited. Therefore, The quantitative basis is provided for engineering selection, guiding to select a more optimal d and h combination on the target dataset. Figure 6

[0162] The following will be described in detail:

[0163] 1. Dynamic relationship memory module (global memory path)

[0164] Different relationship types have different performances, in order to model the dynamic interaction of different relationship types, the invention introduces a double-head self-attention mechanism to update the dynamic memory module. The relationship embedding matrix is set as , where R is the number of relationship types, and d is the embedding dimension. The query, key and value matrices are obtained by linear mapping:

[0165]

[0166] Subsequently, reshape it into an h-head structure (h=2)

[0167] ​ ,in, .

[0168] The attention of each head, for head i (i = 1, ..., h)

[0169]

[0170] Head output is:

[0171]

[0172] Head fusion and output: stitch together the outputs of all heads, project them, apply dropout, and add residual connections.

[0173]

[0174] in The resulting matrix As a global, relation-aware memory module, it is computed only once in each inference sample and can be reused by downstream modules. Since the set of relations in a knowledge graph is usually relatively small (tens to hundreds), this global relation-based attention mechanism has low computational overhead. Through this dynamic relation memory module, the model can obtain a "global perspective" of all relation semantics before entering specific rule inference.

[0175] 2. Local rule compression module

[0176] Given adjacent pairs in a rule sequence, this invention needs to evaluate their merging probability and semantics. This requires an efficient encoding method to represent the meaning implied by any combination of two adjacent pairs. To this end, this invention designs a local relation pair encoding module, which encodes all adjacent pairs in the rule body in parallel.

[0177] Assuming the current rule body sequence has a length of n, it is represented as follows: For each pair of adjacent relationship embedding combinations ( , The segments are concatenated and relative position codes are added to obtain the local segment input.

[0178]

[0179] in For relational embedding, It is a fixed relative position encoding.

[0180] Then, One-dimensional convolutions are input to capture low-order interaction features between local adjacency relationships:

[0181]

[0182] is the convolution output feature, is the activation function. To further model the context representation of adjacent relation pairs in the sequence, the present application uses the output encoder to obtain the sequence hidden state.

[0183]

[0184] The self-attention mechanism of the Transformer enables each relation vector to directly interact with another relation. After the encoding is completed, the present application takes the output of the last position of the sequence as the combined representation of the relation pair , . In this way, the representation set of all adjacent relation pairs is obtained. It needs to be emphasized that, since the Transformer encoder uses relative position embedding, the encoding process of adjacent relation pairs at different positions in the sequence can share model parameters and be completed in parallel. This design enables the local relation pair encoding module to handle different rule body lengths without adjusting the structure.

[0185] After obtaining the representation of all adjacent relation pairs , the present application needs to select an "optimal" relation pair from them for merging. Intuitively, different adjacent relation combinations have different contributions to the rule as a whole: certain combinations can better derive the rule head, and thus should be given priority for merging. To this end, the present application uses a simple feedforward network for each relation pair to calculate the score representing the priority of the relation pair as the next merging unit.

[0186]

[0187] wherein, represents the score layer weight, represents the bias. Through a linear transformation, the score is mapped to a scalar and compressed to the interval 0-1 by the sigmoid function . Then the k highest scoring relation pairs are selected for merging.

[0188] In the merging process, the present application does not simply take as the representation of the new relation, but designs a memory attention fusion mechanism to enhance the representation ability of the merging result using global relation memory. Specifically, the present application takes the representation of the selected relation pair As a query, the global relational memory matrix M is taken as the key and value to perform multi-head attention computation. This structure can be viewed as a simplified Transformer encoder, where tries to "read" relevant semantic information from the global memory to update its own representation:

[0189]

[0190] In the above formula, the present application will concatenate with the global relational memory M as the key and value input of the attention mechanism. After multi-head attention, the output fuses the representation of the original relation pair and the relevant information from the global semantic memory. Then it is further transformed by a feedforward network and added with the residual to get the final new relation representation .

[0191]

[0192] This memory attention fusion process ensures that each time the relation is merged, not only the semantics of the relation pair itself is considered, but also the global relational space is referenced to produce a more semantically consistent merging result. After the generation of the new relation , the present application updates the original rule body sequence: replace the relations at positions i and i+1 with , and reduce the sequence length by 1, the updated sequence representation is:

[0193] .

[0194] For the unselected relation pairs, by merging with the present round, their relations remain in the sequence, and after the length of the knowledge sequence is shortened, the interval of some relation pairs changes. Before the next iteration begins, the present application can recalculate the representation scores of the remaining vector relation pairs to reflect the new combination possibilities due to the sequence update. Then repeat the above scoring-selection-merging process. The entire multi-stage merging process will perform (n-1) rounds until the rule sequence is compressed to a length of 1.

[0195] The only relationship in this sequence is Z, which is the entire rule body combination representation, containing the comprehensive semantics of all relationships in the original rule chain. It is worth mentioning that in the selection of each step relationship pair, the present application does not use sampling strategies such as reinforcement learning, but directly uses the greedy Argmax to select the highest score. Although the greedy selection may not be globally optimal, the present application introduces an entropy regularization term in the training process, which to some extent avoids the model from converging to a suboptimal decision too early. In addition, by locally scoring all possible local relationship pairs and calculating the entropy in training, the present application encourages the model to learn a stable and deterministic combination order, rather than producing uncertainty on multiple combination paths. In summary, the model of the present application obtains global relationship information through dynamic memory, realizes multi-stage rule body combination representation by using local encoding and attention mechanism, and finally combines global memory for rule prediction.

[0196] 3. Bidirectional BFS closed-loop sampling mechanism

[0197] As random sampling may introduce invalid or noisy data, it can be seen in a large number of experiments. For some complex random combinations of relationships, the data desired by the present application is not produced. The bidirectional BFS sampling method selects entities in the triples in the knowledge graph as anchor points, and performs bidirectional breadth-first search (Bidirectional Breadth-First Search, BFS) in the graph to construct a connection path. This method aims to generate training samples with an explanation path for the reasoning model, that is, to mine multi-hop reasoning rules from existing relationship triples. The core steps include: sampling anchor entity from triples, constructing connection path based on anchor, and evaluating the closure of the path to form reasoning rule training samples.

[0198] First, select a triple in the knowledge graph as the anchor triple. The present application regards the head entity h and the tail entity t of this triple as anchor entities for search, and from these two anchor points, respectively, performs BFS search on the knowledge graph. All triples in the knowledge graph can be regarded as a directed graph, in which entities are nodes and relationships are directed edges. Therefore, bidirectional BFS from h and t as starting points is essentially expanding the node set from two directions on this directed graph. The bidirectional BFS path construction process is as follows: on the one hand, the BFS from the head entity h explores its neighbor nodes layer by layer, that is, all entities connected with the current front node set by direct relationship; on the other hand, the BFS from the tail entity t explores the entity set adjacent to it in the reverse direction layer by layer. As the search progresses, the present application records the entity set that can be reached from h and the entity set that can be reached from t To control search complexity, an upper limit d is set for the depth of bidirectional BFS in the actual implementation, and further expansion stops immediately after finding the intersection point, thereby optimizing sampling efficiency. Once the path connecting h and t is found, the present invention can concatenate the aforementioned segmented paths to obtain the complete inference path P from h to t. The constructed P is a multi-hop relationship link between anchor entities h and t.

[0199] Next, the closure of the path needs to be evaluated: This invention verifies whether the two ends of the path are exactly closed at the beginning and end entities h and t of the original triple. Since the above construction ensures that P starts at h and ends at t, if P exists, it means that a closed loop path (containing the original direct relation r) is formed between h and t. This invention considers the path to be closure-satisfied if and only if the path starts and ends at the original entity pair (h,t), that is, P correctly connects h and t to form a loop evidence.

[0200] Finally, the paths that pass the closure check are used together with the original triples to generate training samples for the inference rule. Specifically, whenever a closed path P is found connecting anchor entities h and t, this invention obtains a potential inference rule for relation r: if path P exists, then relation r(h,t) holds. The inference rule can then be formally expressed as:

[0201]

[0202] The first k are from The relationship of departure, the latter l is from The starting relationship. In short, the simultaneous existence of all intermediate relations along the path implies the validity of the original triple relation r. This invention treats (P,r) as a sample inference rule and adds it to the training set for model learning. If no closed path is found within a limited depth, the triple is skipped (no training sample is generated).

[0203] 4. Model Training and Optimization Objectives

[0204] This invention aims to ensure that the model can accurately determine each training sample on the samples generated by bidirectional BFS. The closure property. First, normalize the output set of all relationships between candidate heads into probabilities. .in Let represent the probability that path P is closed by the k-th relation, and This corresponds to "cannot be closed". (Note:)

[0205]

[0206] Secondly, to further separate positive and negative examples, this invention employs multi-class cross-entropy loss for positive samples to maximize the log-likelihood of the true relationship;

[0207]

[0208] where According to the category frequency is set to alleviate the analogy balance that bidirectional BFS may bring; if not weighted, is set to Meanwhile, to increase the discriminant ability of difficult negative example samples, the application randomly samples m negative paths that cannot form a closed loop for each positive sample on the same anchor pair (h, t) and introduces a noise contrast loss.

[0209] ,

[0210] where is the scoring function after taking logits, is sigmoid. The final objective function is the weighted sum of the two, written as

[0211]

[0212] balances the precision supervision and contrast learning. When , it degenerates into pure cross-entropy, and when , it further suppresses false positives brought by random paths by using negative sampling.

[0213] Through experiments, the experimental results of the comparison between the application and other models are as follows:

[0214]

[0215] Table 1: Experimental results of the comparison between the application and other models

[0216] The ablation experimental results of the application in the fusion of the dynamic relationship memory module and the local compression rule module are as follows:

[0217]

[0218] Table 2: Ablation experimental results of the fusion of the dynamic relationship memory module and the local compression rule module

[0219] Through the above embodiments and experimental diagrams, it can be seen that the “dynamic relationship memory + local rule compression” cooperative mechanism proposed by the application not only utilizes the global semantic perspective to guide rule generation, but also ensures the interpretability and precision of the model through high-quality path sampling and reasonable training strategies, thereby achieving excellent performance on various data sets.

[0220] Finally, it should be noted that the above only describes the preferred embodiments of the present application and is not intended to limit the present application. Although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art will appreciate that the technical solutions described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalent features, and any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims

1. A knowledge graph reasoning method based on dynamic rule-based perceptual memory, characterized in that, Includes the following steps: Dynamic relational memory construction: Obtain the embedding representation of each relation in the knowledge graph, wherein the embedding representation is a fixed-length real vector obtained through pre-training; The relation embedding is globally modeled based on a multi-head self-attention mechanism, generating a global relation memory matrix that can be dynamically updated according to the query during the inference process. The row and column indices of the matrix correspond one-to-one with the relation types, which is used to form a query-adaptive relation weight distribution. Local rule compression: For the inference rule sequence, the embedded representation of the adjacent relationship pair is combined with the encoding vector representing its position in the rule sequence to obtain a relationship pair vector containing positional information; The interaction features of the relation pair in the low-order neighborhood are extracted by using convolution operation, and the global dependency information of the relation pair in the context of the rule sequence is obtained by combining the self-attention mechanism. The merging priority score for each adjacent relationship pair is calculated based on a scoring mechanism, and the relationship pair with the highest score is selected for merging. During the merging process, the relation pair vector is used as a query vector and attention is fused with the keys and values ​​of the global relation memory matrix to generate an updated relation vector, until the rule sequence is compressed into a single rule representation vector. High-quality path sampling: Select anchor triples from the knowledge graph that contain a head entity and a tail entity, where each entity is represented by a unique identifier; Starting from the head entity and the tail entity respectively, a bidirectional breadth-first search is performed to generate a reasoning path with closed head and tail entities. The path includes a sequence of entities arranged in order and a corresponding sequence of relations. Paths that satisfy the closure condition are used as positive sample rules, and paths that do not satisfy the closure condition are used as negative sample rules. Reasoning training: The positive sample rules and negative sample rules are input into the inference network that includes the dynamic relation memory module and the local rule compression module; The inference network is trained using a joint loss function of multi-class cross-entropy loss and noise contrast loss to obtain a knowledge graph inference model that can dynamically adjust rule weights and output inference paths during queries.

2. The method according to claim 1, characterized in that, The dynamic relation memory construction steps include: The embedded representations of each relation in the knowledge graph are transformed linearly to generate query representations, key representations, and value representations, respectively. The linear transformation is achieved through matrix multiplication. The query representation, key representation, and value representation are divided into several subspaces according to a multi-head structure, and attention weights are calculated in each subspace based on the dot product or cosine similarity between the query representation and the key representation. The corresponding value representations are weighted and summed using the attention weights to obtain the output vectors of each subspace; After concatenating the output vectors of each subspace and projecting them onto the original embedding dimension, the vectors undergo discarding, residual connection, and normalization processes in sequence to form a global relational memory matrix that can be invoked during inference. The global relational memory matrix can dynamically highlight relational features related to each query and retain them during the same reasoning process.

3. The method according to claim 1, characterized in that, The local rule compression step includes: The adjacent relation pairs in the rule sequence are positionally encoded according to their relative positions in the sequence to obtain a relation pair vector containing positional information. The interaction features of the adjacent relationship pairs in a local range are extracted by convolution operation, and the global dependency information of the relationship pairs in the context of the rule sequence is obtained by using a sequence encoding structure. The merging priority score of the relation pair is calculated based on the scoring mechanism, which comprehensively considers the similarity score between the local feature vector of the relation pair and the corresponding relation in the global relation memory matrix. The similarity score is calculated by embedding vector cosine similarity. The relationship pairs with the highest scores are selected for merging. During the merging process, the relationship pair vector is used as the query vector, the global relation memory matrix is ​​used as the key and value, attention fusion is performed to introduce global semantic information, and an updated relation vector is generated. Replace the merged relation pairs with the updated relation vector, and repeat the scoring, selection, and merging steps above on the basis of shortening the rule sequence length, until the rule sequence is compressed into a single rule representation vector.

4. The method according to claim 1, characterized in that, The high-quality path sampling step includes: Select anchor triples containing head and tail entities from the knowledge graph; Starting from the head entity and the tail entity respectively, a bidirectional breadth-first search is simultaneously performed on the directed graph structure of the knowledge graph, expanding the node set layer by layer, and terminating the search when the search depth reaches the preset upper limit or when an intersection node is found. The path segment from the head entity and the path segment from the tail entity are concatenated at the intersection node to generate a complete inference path from the head entity to the tail entity. The generated reasoning paths are closed-loop verified, and only paths that can connect the head entity and the tail entity respectively and whose path relationship combination is semantically consistent with the original triple relationship are retained as positive samples. Semantic consistency is determined by comparing the vector similarity between the path relationship combination and the original triple relationship, and judging whether it exceeds a preset similarity threshold. Paths that do not satisfy closure are used as negative samples and are used together with the positive samples for model training.

5. The method according to claim 1, characterized in that, The reasoning training steps include: The positive sample rules and negative sample rules are input into an inference network containing the dynamic relation memory module and the local rule compression module to obtain the predicted probability distribution for each candidate relation. The predicted probability of the target relationship in the positive samples is maximized using the first loss function, which is softmax multi-class cross-entropy. The prediction probability of non-target relationships in negative samples is minimized using a second loss function, which is a binary log loss based on noise contrast estimation. The first loss function and the second loss function are combined into a joint loss function according to preset weights, and the parameters of the inference network are updated. The first loss function is used to supervise the model to accurately output true inference conclusions, and the second loss function is used to suppress the interference of noisy paths on the model.

6. The method according to claim 2, characterized in that, The number of heads in the multi-head attention mechanism is set to an integer divisibility factor of the relation embedding dimension to ensure that the dimensions of each subspace are equally divided and to achieve parallel computation, and that the dimensions of each subspace are equally divided. The computational complexity of the global relational memory matrix is ​​proportional to the square of the number of relation types, thus keeping the computational overhead controllable under the condition that the size of the relation set is limited; The global relation memory matrix is ​​only recalculated when a change in the query relation is detected during inference; otherwise, the generated global relation memory matrix is ​​reused within the current inference session.

7. The method according to claim 3, characterized in that, When evaluating the merging priority of adjacent relationship pairs, the scoring mechanism comprehensively considers the similarity score between the local feature representation of the relationship pair and the corresponding relationship in the global relationship memory matrix. An entropy regularization term is introduced in the greedy selection merging process to prevent the model from over-relying on a few high-scoring relation pairs in the early stages of training, thereby reducing the diversity of inference paths. The multi-stage merging iteration of the rule sequence terminates when any of the following conditions are met: The length of the regular sequence is compressed to a single relation representation; The merge priority scores for all current relation pairs are below the preset threshold.

8. The method according to claim 4, characterized in that, The maximum search depth of the bidirectional breadth-first search is set to no more than a preset integer d, in order to limit the path length and reduce computational overhead; At each search level, an upper limit N is set for the number of scalable nodes. When this upper limit is reached, the scalable nodes are selected in ascending order of the shortest path estimated distance to the target entity. When there are multiple intersection nodes, the intersection node with the shortest generated path length is selected first. If the path lengths are the same, the intersection node found first during the search process is selected. The closure verification not only requires that the first and last entities of the path be consistent with the first and last entities of the original anchor triple, respectively, but also requires that the path relation combination be semantically consistent with the original triple relation.

9. The method according to claim 5, characterized in that, The combined weights of the first loss function and the second loss function are dynamically adjusted during training based on the performance metrics of the validation set, so as to balance the contributions of precise supervision and contrastive learning at different training stages; The negative sample rule is generated by performing a bidirectional breadth-first search and filtering out paths that cannot form a closed loop between the same anchor point entity pairs as the positive sample rule. The number of negative samples corresponding to each positive sample rule is fixed to a preset value m. When calculating the first loss function, class balance weights are introduced to weight the loss value according to the frequency of different relation classes in the training data, thereby mitigating the impact of class imbalance on model convergence.

Citation Information

Cited By

  • Molecular inverse synthesis prediction method and system based on multi-step information fusion

    CN121641254A

  • A multi-step information fusion-based molecular retrosynthesis prediction method and system

    CN121641254B

  • Object segmentation method and system for sonar image attribute modeling and closed-loop enhancement

    CN121883516A

  • Model training method and system based on dynamic ontology evolution and heterogeneous reasoning network

    CN122114196A

  • A model training method and system based on dynamic ontology evolution and heterogeneous reasoning networks

    CN122114196B