Knowledge graph completion method based on multi-head cross-alignment and dynamic feature refinement
Patent Information
- Application Number
- CN202610780555.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-02
- Publication Date
- 2026-10-30
AI Technical Summary
然而,该类方法通常仅在单一尺度或有限层级上进行特征建模,缺乏多尺度特征融合机制,难以同时捕获不同语义层次下的结构信息
[0087]第一,显著提升了实体与关系之间的语义对齐能力和复杂关系建模精度。通过构建双向多头交叉注意力机制,在实体到关系和关系到实体两个方向上建立显式交互,使实体表示能够在关系语义条件下动态调整,同时关系表示也能够感知实体特征,实现深层语义对齐。相较于现有技术中“先独立编码、再被动交互”的模式,本发明从表示学习初期即建立双向耦合关系,有效缓解了语义不一致问题,在复杂关系场景下取得了更高的推理精度。
Smart Images

Figure CN123014107A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of knowledge graphs, specifically to a knowledge graph completion method based on multi-head cross-alignment and dynamic feature refinement. Background Technology
[0002] Knowledge graphs, as semantic network structures that organize knowledge in the form of "head entity-relation-tail entity" triples, use graph structures to depict the connections between everything in the real world. Since Google formally proposed the concept of knowledge graphs in 2012, they have been widely used in artificial intelligence fields such as intelligent question answering, information retrieval, recommendation systems, and natural language understanding, becoming one of the key infrastructures driving the practical application of artificial intelligence technology. However, actual knowledge graphs often suffer from serious incompleteness, with many relationships that should exist between entities not being included. This incompleteness directly limits the utility and value of knowledge graphs in downstream applications. Knowledge graph completion tasks aim to automatically infer missing entity or relationship information in a knowledge graph based on existing partial triples. This can usually be formalized as a link prediction problem, i.e., given a set of triples... or In this case, predict the entity that is most likely to be true.
[0003] Existing knowledge graph completion methods can be mainly divided into three categories: distance-based models, tensor decomposition-based models, and neural network-based models.
[0004] Distance-based models characterize the relationships between entities and relations through geometric transformations. The most representative example is the TransE model proposed by Bordes et al. in 2013. This model views relations as translations from the head entity to the tail entity, assuming that a valid triple satisfies... TransE possesses advantages such as simple structure, high computational efficiency, and strong interpretability, but its expressive power is limited, making it difficult to model complex relational patterns, especially performing poorly in one-to-many, many-to-one, and many-to-many relationships. Subsequently, researchers proposed various improved models of TransE, such as TransH, TransR, and RotatE. Among them, RotatE proposed by Sun et al. defines relations as rotation operations in complex space, which can effectively model various relational patterns such as symmetric, antisymmetric, and inverse relationships, improving expressive power to a certain extent. However, this type of geometric transformation-based method is still generally limited by the pre-defined transformation forms and cannot fully characterize the rich and diverse semantic associations in knowledge graphs.
[0005] Tensor decomposition-based methods characterize the semantic relationships between entities and relations through bilinear or multilinear interaction functions. The RESCAL model proposed by Nickel et al. represents the knowledge graph as a third-order tensor and learns the representations of entities and relations through tensor decomposition. However, the number of parameters in this model is proportional to the square of the relation dimension, making it difficult to scale to large-scale knowledge graphs. DistMult, proposed by Yang et al., restricts the relation matrix to a diagonal matrix, significantly reducing the number of parameters, but thus loses the ability to model asymmetric relations. ComplEx, proposed by Trouillon et al., extends the embedding to complex space and successfully models asymmetric relations through complex conjugate inner products. Although tensor decomposition-based methods improve expressive power to some extent, their model forms are relatively fixed, typically using only simple bilinear functions, making it difficult to achieve a good balance between complex semantic modeling and parameter size.
[0006] In recent years, knowledge graph completion methods based on neural networks have made significant progress in modeling capabilities by introducing nonlinear mapping and complex feature interaction mechanisms. Among them, methods based on convolutional neural networks have received widespread attention. The ConvE model proposed by Dettmers et al. was the first to apply convolutional neural networks to knowledge graph completion. It reconstructs the one-dimensional embedding vectors of head entities and relations into two-dimensional feature maps and uses two-dimensional convolution operations to model the local interaction features between entities and relations, showing certain advantages in improving feature representation capabilities. The ConvKB model proposed by Nguyen et al. stacks the embedding vectors of head entities, relations, and tail entities into a three-column matrix and extracts features through one-dimensional convolution. However, these methods still have several key shortcomings.
[0007] First, existing methods lack sufficient semantic interaction and alignment capabilities between entities and relations. Models such as ConvE and ConvKB typically encode entities and relations independently, then complete the modeling through concatenation, fixed convolution, or shallow interactions, lacking explicit characterization of the bidirectional semantic dependencies between entities and relations. This approach fails to fully reflect the deep correspondence between entity and relation semantics, resulting in a weak semantic association between entity and relation representations. Under complex relational patterns, the model does not fully utilize entity-relational interaction information, thus limiting its ability to express complex relational patterns.
[0008] Secondly, existing convolutional knowledge graph completion methods have relatively fixed feature interaction methods and lack the ability to adaptively adjust to relational semantics. Models such as ConvE use convolutional kernels with fixed parameters to extract entity and relation features. Their convolutional operations typically employ the same feature extraction strategy for different relation types, failing to dynamically change the feature extraction strategy based on specific relational semantics. This makes it difficult for the model to finely characterize the local matching features between entities and relations under different semantic conditions when dealing with diverse relations and complex semantic structures, thus limiting the model's expressive power. Although InteractE proposed by Vashishth et al. enhances the interaction modeling ability between entities and relations to some extent through strategies such as feature rearrangement and multi-semantic space mapping, and MRCCA proposed by Cao et al. introduces a cross-attention mechanism for local feature enhancement, these methods still lack a systematic modeling of the bidirectional dependency relationship between entities and relations. The semantic alignment process is still insufficient, making it difficult to achieve fine-grained semantic matching. In addition, these methods usually focus on feature enhancement rather than feature selection, lacking an explicit feature selection mechanism, which easily introduces redundant information, thereby affecting the model's discriminative ability.
[0009] Secondly, existing methods often lack explicit filtering and enhancement mechanisms for key features during feature modeling. Methods like ConvD, by introducing dynamic convolutions or relation-aware convolution kernels, have improved the model's ability to model relational semantics to some extent, allowing the convolution kernels to adjust according to changes in relations. However, these methods typically perform feature modeling only at a single scale or a limited number of levels, lacking multi-scale feature fusion mechanisms and making it difficult to simultaneously capture structural information at different semantic levels. Furthermore, their feature fusion methods are relatively simple, lacking joint modeling and filtering mechanisms at the channel and spatial levels, resulting in limited ability to distinguish between key features and redundant information. Existing methods typically employ single-scale or coarse-grained feature fusion methods, making it difficult to effectively distinguish between key information and redundant noise, and also difficult to simultaneously capture interactive semantics at different scales, leading to insufficient inference accuracy and robustness in complex knowledge graph scenarios.
[0010] In summary, existing knowledge graph completion techniques still have significant shortcomings in entity-relation semantic alignment, adaptive feature interaction, and multi-level feature refinement. A new method is needed to achieve deep bidirectional alignment of entities and relations, construct a relation-driven dynamic feature modeling mechanism, and improve the model's expressive power and prediction accuracy in complex knowledge graph completion tasks through multi-scale and multi-dimensional feature refinement. Summary of the Invention
[0011] To address the aforementioned technical problems, this invention provides a knowledge graph completion method based on multi-head cross-alignment and dynamic feature refinement.
[0012] This invention is achieved through the following technical solution:
[0013] The knowledge graph completion method based on multi-head cross-alignment and dynamic feature refinement of the present invention includes the following steps:
[0014] S1: Obtain the initial embedding representation of the first entity and the initial embedding representation of the relation in the knowledge graph to be completed;
[0015] S2: A bidirectional multi-head cross-attention mechanism is adopted to calculate cross-attention in two directions: from the first entity to the relation and from the relation to the first entity, to obtain the enhanced representation on the first entity side and the enhanced representation on the relation side.
[0016] S3: Using learnable soft fusion weights, the initial embedding representation and the corresponding enhanced representation are weighted and fused to obtain a fused first entity representation and a fused relation representation;
[0017] S4: The fused first entity representation is reconstructed into a two-dimensional feature map, and it is concatenated with the original entity two-dimensional feature map obtained by reconstructing the initial embedding representation of the original first entity in the channel dimension, and the fused entity two-dimensional feature map is obtained by linear fusion mapping; at the same time, the fused relation representation is reconstructed into a relation two-dimensional feature map for subsequent generation of dynamic convolution kernels;
[0018] S5: Generate a dynamic convolution kernel using the two-dimensional feature map represented by the fusion relationship, and perform dynamic convolution on the two-dimensional feature map of the fusion entity in an overlapping sliding manner to obtain a relationship-aware feature map;
[0019] S6: Perform multi-scale feature extraction on the relation-aware feature map, capture the structural semantics under different receptive fields through parallel multi-branch convolution and pooling operations, and obtain multi-scale fusion features through residual connections;
[0020] S7: Perform channel attention recalibration on the multi-scale fusion features, generate channel weights through global pooling and bottleneck structure, and adaptively enhance and suppress feature channels to obtain recalibrated features;
[0021] S8: Perform gated filtering and spatial weighting operations sequentially on the recalibrated features, and combine them with the entity basis features obtained by reconstruction and pooling from the initial embedding representation of the original first entity to perform position-level recalibration and residual fusion to obtain a refined feature map;
[0022] S9: Map the refined feature map into a structure-aware feature vector, calculate the matching probability between the first entity and relation and the candidate second entity based on the vector, optimize the model parameters using the binary cross-entropy loss function, and determine the completed second entity based on the matching probability;
[0023] Wherein, when the first entity is the head entity, the second entity is the tail entity; when the first entity is the tail entity, the second entity is the head entity.
[0024] A knowledge graph is a semantic network that represents structured knowledge in the form of a directed graph. Nodes represent entities in the real world, and edges represent semantic relationships between entities. In a knowledge graph, facts are typically stored as triples: (head entity, relation, tail entity). However, real-world knowledge graphs often suffer from severe incompleteness, with many relationships that should exist between entities not being included. This directly limits the utility of knowledge graphs in downstream applications. The knowledge graph completion task aims to automatically infer missing links in the graph based on an existing set of incomplete triples. Its core can be formalized as a link prediction problem: given an incomplete query, such as knowing the head entity and relation but missing the tail entity, or knowing the tail entity and relation but missing the head entity, the model needs to predict the most likely entity from the candidate entity set.
[0025] In this invention, the first entity and the second entity are functional designations for the known entity and the entity to be predicted in the query, respectively. Specifically, when performing the task of completing the tail entity from the head entity, the known head entity is the first entity, and the tail entity to be predicted is the second entity; when performing the task of completing the head entity from the tail entity, the known tail entity is the first entity, and the head entity to be predicted is the second entity. This symmetrical design allows the same model structure to support both link prediction directions simultaneously without any modification, significantly improving the versatility and practicality of the method.
[0026] Initial embedding representation refers to mapping discrete symbols (entity identifiers and relation identifiers) in a knowledge graph to dense vectors in a continuous vector space. This distributed representation method can capture the latent semantic similarity between entities and relations, making semantically similar entities close to each other in the vector space. The embedding dimension d is a key hyperparameter that determines the size of the representation space. A larger embedding dimension provides stronger representational power but also increases the number of model parameters and the risk of overfitting; a smaller embedding dimension is more computationally efficient but may not be sufficient to fully express complex semantic relationships. In practice, the embedding dimension is usually taken as a power of 2, such as 128, 256, 512, or 1024, to facilitate hardware acceleration.
[0027] The bidirectional multi-head cross-attention mechanism originates from the Transformer architecture in natural language processing. Its core idea is to allow the model to dynamically adjust its representations based on the interaction between two input pairs. In this invention, this mechanism is innovatively applied to the bidirectional alignment of entity and relation representations: entity representations are updated under the guidance of relational semantics to highlight attributes relevant to the current relation; simultaneously, relation representations are refined under the guidance of entity semantics to capture the specific meaning of the relation within a particular entity context. This bidirectional coupling mechanism overcomes the fundamental shortcomings of traditional methods, such as independent encoding of entities and relations and a lack of deep semantic interaction.
[0028] Soft fusion weights are an adaptive balancing mechanism used to control the contribution ratio of original semantic information and interaction enhancement information in the final representation. Directly replacing the original embedding representation with the cross-attention-enhanced representation may result in the loss of global structural information contained in the original embedding, leading to a decrease in the model's semantic robustness. The soft fusion mechanism, by learning a differentiable weight coefficient, allows the model to dynamically determine how much original semantic information to retain and how much interaction information to incorporate based on the specific input, thereby achieving an optimal balance between the two.
[0029] The reconstruction operation of a 2D feature map involves rearranging the originally linearly arranged one-dimensional embedding vectors into a 2D matrix with spatial structure. The theoretical motivation for this operation lies in the fact that the success of convolutional neural networks in image processing has demonstrated that 2D spatial structures can effectively capture dependencies between local patterns. By reconstructing entity and relation embeddings into 2D feature maps, the model can explicitly model the local structural matching patterns between entities and relations using convolutional operations. This has stronger expressive power and generalization performance than simple vector inner products or bilinear transformations in traditional methods.
[0030] A core innovation of this invention is the relation-aware dynamic convolutional kernel. In traditional convolutional neural networks, the parameters of the convolutional kernel are fixed after training, and the same feature extraction strategy is applied to all input samples. However, in knowledge graph completion tasks, different relation types correspond to drastically different semantic patterns: for example, the "birthplace" relation focuses on a person's geographical location attribute, while the "creation" relation focuses on the creative association between an artist and their works. Using a fixed convolutional kernel is difficult to adapt to such diverse semantic scenarios simultaneously. The dynamic convolution mechanism proposed in this invention explicitly introduces relational semantics into the generation process of the convolutional kernel: the parameters of the convolutional kernel are no longer fixed, but are dynamically calculated based on the embedding representation of the current relation. This allows the model to adopt different feature extraction strategies for different relation types, significantly improving the modeling accuracy in complex relational scenarios.
[0031] Multi-scale feature extraction draws inspiration from the design principles of the Inception network in computer vision. In knowledge graphs, the patterns of association between entities may exist at different spatial scales: some local patterns may only involve interactions between a few feature dimensions, while some global patterns may require crossing a large receptive field to be effectively captured. By constructing a parallel branch structure containing convolutional kernels of different sizes, the model can simultaneously focus on fine-grained local features, mesoscale contextual information, and broad-ranging structural semantics, thereby forming a three-dimensional understanding of entity-relationship interaction patterns.
[0032] The channel attention recalibration mechanism originates from SENet, and its core idea is to allow the model to autonomously learn the importance weights of feature channels. After multi-scale feature extraction, feature maps of different channels correspond to responses at different scales and under different semantic modes. However, not all channels are equally important to the current completion task: some channels may capture discriminative features that are highly relevant to the semantics of the current relation, while others may contain noise or weakly relevant information. The channel attention mechanism aggregates spatial information through global pooling and then generates channel-level weights through a lightweight bottleneck network to adaptively enhance or suppress feature channels, thereby improving the discriminative quality of features.
[0033] The gating screening mechanism employs a gated linear unit implementation, using a gating signal generated by the Sigmoid function to perform fine-grained feature screening. The output range of the Sigmoid function is (0, 1). When the gating signal approaches 0, the feature value at the corresponding position is significantly suppressed; when the gating signal approaches 1, the feature value at the corresponding position can be preserved or enhanced. This mechanism can effectively filter redundant noise in the spatial dimension and highlight key structural patterns.
[0034] The spatial weighting operation further introduces entity prior constraints, inputting entity basis features and gating features into the spatial attention function to generate a spatial location weight map. This allows the model to highlight feature response regions that are most consistent with the semantics of the first entity at the spatial level, further enhancing the discriminativeness and interpretability of the feature representation.
[0035] The 1-N training strategy is a highly efficient training paradigm widely adopted in the field of knowledge graph completion in recent years. Unlike the traditional 1-1 training method (which calculates the loss for only one positive and one negative sample at a time), the 1-N strategy formalizes link prediction as a multi-label classification problem: for a given query pair, the model calculates its matching score with all candidate entities at once and updates its parameters based on the binary cross-entropy loss. This strategy not only significantly improves training efficiency but also allows the model to perceive the distribution characteristics of multiple negative samples simultaneously in each iteration, which is beneficial for learning a more discriminative decision boundary.
[0036] The binary cross-entropy loss function is one of the most widely used loss functions in binary classification problems. In the 1-N framework of knowledge graph completion, for a given query pair, the model outputs a matching probability for each candidate entity, with the true tail entity labeled 1 and the remaining candidate entities labeled 0. The loss function drives the model to assign higher matching probabilities to true entities and lower matching probabilities to false entities by minimizing the cross-entropy between the predicted probability distribution and the target label distribution. Label smoothing is a regularization technique that replaces hard labels (0 or 1) with soft labels (e.g., 0.9 and 0.1) to prevent the model from overconfident in the training samples, thereby improving generalization ability.
[0037] Furthermore, the step S1 of obtaining the initial embedding representation of the first entity and the initial embedding representation of the relation in the knowledge graph to be completed specifically includes:
[0038] Before model training begins, construct or load an entity embedding matrix. and a relation embedding matrix ,in This represents the total number of entities in the knowledge graph. Represents the total number of relations. As a preset embedding dimension, each row in the entity embedding matrix and the relation embedding matrix corresponds to a continuous vector representation of an entity or a relation, respectively;
[0039] Upon receiving the query pair to be completed Afterwards, among them For the first entity, according to the first entity The identifier is retrieved from the entity embedding matrix to find the corresponding first identifier. Row vectors, serving as the initial embedding representation of the first entity. And according to the relationship The identifier is retrieved from the relation embedding matrix to find the corresponding first identifier. Row vectors, serving as the initial embedding representation of the relation. ;
[0040] To improve the model's generalization ability during training and prevent overfitting, the initial embedding representation of the first entity is... Initial embedding representation of relations Before inputting into subsequent modules, both are subjected to random deactivation processing, which uses a preset discard probability. Randomly set some elements of the vector to zero, and retain the remaining elements proportionally. Scaling is performed to maintain its desired value;
[0041] The initial embedding representations of the first entity and the initial embedding representations of the relation, after the random deactivation process, are then passed to the bidirectional multi-head cross-attention module in step S2 as two inputs to the module.
[0042] Furthermore, the calculation of cross-attention using a bidirectional multi-head cross-attention mechanism in step S2 specifically includes:
[0043] The bidirectional multi-head cross-attention calculation performed in step S2 is divided into two symmetrical attention calculation paths, denoted as the first entity to relation direction. and related to the direction of the first entity ;
[0044] First entity to relation direction In this process, the initial embedded representation of the first entity after random deactivation in step S1 is used as the query input. The initial embedding representation of the relation after random deactivation in step S1 is used as the key input. Sum value input First, through three learnable linear mapping matrices... , , By performing linear projections on the query input, key input, and value input respectively, a query matrix is obtained. Key matrix Sum matrix Subsequently, the query matrix Key matrix Sum matrix Divide equally into the feature dimensions. Each part corresponds to an attention head, such that each attention head... Obtain the corresponding query subspace matrix Key space matrix Sum subspace matrix The feature dimension of each attention head is Within each attention head, scaled dot product attention computation is performed independently, i.e., the query subspace matrix is calculated first. With key space matrix Multiplying the transpose of matrices, then dividing the product by the scaling factor. Then, the attention weight matrix is obtained by normalization using the Softmax function, and then the attention weight matrix is compared with the value subspace matrix. Multiply to obtain the output of the attention head. The calculation formula is as follows: ; All The output vectors of each attention head are concatenated along the feature dimension to obtain a dimension of... The concatenated vectors are then processed by a learnable output mapping matrix. A linear transformation is performed on the concatenated vector to obtain the first entity-side augmented representation. ;
[0045] In relation to the direction of the first entity In this process, the initial embedding representation of the relation after random deactivation in step S1 is used as the query input. The initial embedded representation of the first entity after random deactivation in step S1 is used as the key input. Sum value input The same operational process as the first entity-to-relation direction is adopted, using three learnable linear mapping matrices. , , Perform projection and divide into Each attention head performs scaled dot product attention computation, and the outputs of all heads are concatenated and mapped through an output mapping matrix. Perform a linear transformation to obtain the relation-side enhanced representation. .
[0046] Furthermore, the weighted fusion using learnable soft fusion weights described in step S3 specifically includes:
[0047] Step S3 employs a learnable soft fusion mechanism to adaptively balance the original semantic information and the interaction enhancement information.
[0048] For the first entity side, the first entity is first embedded in the representation. and the first entity side enhancement representation The inputs are fed into a lightweight neural network consisting of a single fully connected layer. This single fully connected layer has two input nodes and two output nodes, and its output consists of two unnormalized raw fusion weights. and Subsequently, the original fusion weights were... and Applying Softmax normalization yields learnable soft fusion weights. and The calculation formula is as follows: , And satisfy Then, according to the formula The fused first entity representation is obtained by weighted summation of the initial embedded representation and the enhanced representation of the first entity. The weighted summation operation performs weighted fusion based on feature vectors in the vector space;
[0049] For the relation side, the same fusion process as the first entity side is adopted: the relation is initially embedded in the representation. and relational enhancement representation The input is fed into another lightweight neural network with the same structure, consisting of a single fully connected layer, to generate unnormalized raw fusion weights. and After Softmax normalization, the desired result is obtained. soft fusion weights and Then follow the formula The fusion relationship is obtained by performing a weighted summation. .
[0050] Furthermore, step S4 specifically includes:
[0051] The first entity representation of the fusion is obtained in step S3. Relationship between fusion and integration Subsequently, to leverage the modeling capabilities of convolutional neural networks for local structural patterns, the one-dimensional vector representation needs to be reconstructed into a two-dimensional feature map format. First, the fused first entity representation is then... Relationship between fusion and integration Perform a dimension rearrangement operation, changing it from a length of... One-dimensional vector rearranged to a preset size A two-dimensional matrix, where and All are integers greater than 1, and satisfy the following conditions: The and The specific value is determined before model training based on the embedding dimension. The factorization is predetermined, when Timely After rearrangement, two-dimensional first entity feature maps are obtained respectively. and two-dimensional relational feature map To facilitate convolution operations, it can be further viewed as a two-dimensional tensor with a single channel. ;
[0052] Considering the initial embedding representation of the original first entity The original first entity features still contain important basic semantic information. Step S4 jointly models the original first entity features and the first entity features enhanced by cross-attention in two-dimensional space; specifically, the initial embedding representation of the original first entity is... Reconstruct the preset size using the same dimensional rearrangement method as described above. Original entity two-dimensional feature map Then, the original entity's two-dimensional feature map is processed along the channel dimension. With the two-dimensional first entity feature map The concatenation is performed, meaning that if both are considered as single-channel two-dimensional tensors, the concatenation results in a two-dimensional feature map of the entity to be convolved and fused, which has two channels. Then, channel compression and linear fusion are performed on it through pointwise convolution to obtain a single-channel fused entity two-dimensional feature map;
[0053] The fused entity two-dimensional feature map It is then passed to step S5 as the target feature map for the dynamic convolution operation.
[0054] Furthermore, step S5 specifically includes:
[0055] After obtaining the two-dimensional feature map of the entity to be convolutionally fused from the output of step S4. and two-dimensional relational feature map Then, step S5 executes a relation-aware dynamic overlapping convolution mechanism to explicitly introduce relational semantics into the feature refinement process;
[0056] First, the two-dimensional relation feature map Consider it as a space with a size of A two-dimensional matrix containing one channel; to generate dynamic convolution kernels, this two-dimensional relational feature map is... In the spatial dimension, the convolution kernel is divided into multiple local regions according to a preset kernel size, and each local region is a dynamically generated convolution kernel;
[0057] The preset kernel size is the preset local window size. ,in The value is a positive integer smaller than the spatial size of the two-dimensional relation feature map, and the number of dynamic convolution kernels is equal to the number of sliding windows of the two-dimensional relation feature map in the spatial dimension;
[0058] Subsequently, the dynamically generated convolutional kernel is applied to the two-dimensional feature map of the entity to be convolved and fused using an overlapping sliding method with a stride of 1. Convolution operations are performed on the surface; since the two-dimensional feature map of the entity to be convolved and fused has two channels, the dynamic convolution kernel needs to have a matching number of channels, and each dynamic convolution kernel corresponds to a kernel with a size of [missing information]. The local region is flattened and used in subsequent matching calculations;
[0059] The specific process of convolution operation is as follows: the dynamically generated convolution kernel is matched with the corresponding local window in the two-dimensional feature map of the entity to be convolved and fused. At each sliding window position, the response value at that spatial position is obtained by calculating the similarity between the convolution kernel and the features within the corresponding window. By performing the above matching calculation on all possible spatial window positions, a multi-channel two-dimensional relation-aware feature map conditionalized by relational semantics is finally generated. The number of channels Equal to the number of the local regions;
[0060] This dynamic convolution operation can be uniformly represented as: ,in This represents a relation-driven dynamic overlapping convolution operator; the convolution kernel parameters in this operator are entirely adaptively generated by relation features, enabling the model to dynamically adjust its feature selection strategy for different relation types.
[0061] Furthermore, the multi-scale feature extraction of the relation-aware feature map described in step S6 specifically includes:
[0062] Obtain the relation-aware feature map output in step S5. Then, in step S6, an Inception-style multi-branch, multi-scale feature transformation is applied to the relation-aware feature map. Parallel modeling includes the following steps:
[0063] Construct a multi-branch parallel structure with four parallel branches: the first branch is The convolutional branch contains a convolutional kernel of size [size missing]. The first convolutional layer is used to capture local fine-grained patterns and linearly combine feature channels; the second branch is... The convolutional branch contains a convolutional kernel of size [size missing]. The convolutional layer has an effective receptive field of... The region is used to capture local contextual information at the mesoscale; the third branch is equivalent. Convolutional branches, through concatenating two The convolutional layer implementation is used to increase the receptive field while reducing computational complexity; the fourth branch is the average pooling branch, which contains a pooling window with a size of [missing information]. An average pooling layer with a stride of 1, followed by a... Convolutional layers are used to smooth features and reduce dimensionality while preserving spatial structure information.
[0064] The relation-aware feature map Simultaneously, the inputs are fed into the four branches mentioned above. Each branch performs forward computation independently, outputting a feature map with the same spatial size as the input feature map or the same size after appropriate padding. Then, the output feature maps from the four branches are concatenated along the channel dimension. That is, if each branch outputs... The feature maps of each channel are then concatenated to obtain a feature map with... The splicing feature map of each channel;
[0065] To maintain the stability of the feature representation while incorporating multi-scale structural information, step S6 further integrates the spliced feature map with the relationship-aware feature map of the original input. Perform residual connections; if the number of channels in the spliced feature map is related to the perceptual feature map... If the number of channels is inconsistent, then first go through one Convolutional layers generate relation-aware feature maps The number of channels was adjusted to match the splicing features. Figure 1 Then, the two are added element-wise at their corresponding spatial locations and channels to obtain the multi-scale fusion feature. This process can be formally represented as ,in This indicates the above multi-branch parallel transformation operation. This is a relational perception feature map after adjusting the number of channels.
[0066] Furthermore, the channel attention recalibration described in step S7 specifically includes:
[0067] After obtaining the multi-scale fusion features output in step S6 Afterwards, among them The number of channels in the feature map. and Representing spatial height and width, step S7 introduces a channel attention mechanism to adaptively recalibrate the multi-scale fused features:
[0068] First, regarding the multi-scale fusion features Perform global average pooling in the spatial dimension, that is, for each channel Calculate all on this channel The arithmetic mean of the feature values of each spatial location yields a length of... Channel descriptor vector , of which element The channel descriptor vector aggregates global spatial information for each channel;
[0069] Subsequently, the channel descriptor vector z is input into a bottleneck structure consisting of two fully connected layers to learn the nonlinear dependencies between channels; the first fully connected layer of the bottleneck structure compresses the input dimension C to a smaller dimension with a preset ratio r. Where r is the compression ratio, taking an integer value greater than 1; the output of this fully connected layer is then non-linearly transformed using the ReLU activation function to enhance the model's expressive power; next, the second fully connected layer reduces the dimension from... Restored to the original dimension C, its output is normalized using the Sigmoid activation function, generating a channel activation weight vector with values ranging from (0,1). The c-th element This represents the importance weight of the c-th feature channel;
[0070] Then, the channel activation weight vector s is combined with the original multi-scale fusion feature. Perform channel-by-channel multiplication along the channel dimension; that is, for each channel c, multiply the feature map of that channel. The eigenvalue of each spatial location is multiplied by the corresponding channel weight. The weighted feature map is obtained. Finally, in order to preserve the original multi-scale structural information while enhancing feature discriminative power, the weighted feature maps are... Combined with original multi-scale features Perform residual join, that is, add element-wise at the corresponding spatial locations and channels to obtain the recalibration features. .
[0071] Furthermore, step S8 specifically includes:
[0072] After obtaining the recalibration features output in step S7 Then, step S8 sequentially executes the two sub-steps of gating and spatial weighting;
[0073] The gated screening sub-step specifically involves: first, applying a convolution kernel with a size of [missing information] to the recalibrated feature U. The pointwise convolution operation does not change the spatial size of the feature map; it only performs a linear combination of channel information, and its output has the same spatial size as the input. The number of channels is C; the output of the pointwise convolution is input into the Sigmoid activation function to generate a gating signal with a value in the range (0,1). ,in For the Sigmoid function, Indicates the Pointwise convolution operator; simultaneously, the recalibrated feature U is input into the hyperbolic tangent activation function tanh. The features obtained after nonlinear activation are obtained. Its value ranges between (-1, 1), which can maintain the zero-centeredness of the feature and enhance the nonlinear expressive power; then, the gating signal G and the nonlinearly activated feature T are multiplied element-wise at the corresponding spatial positions and channels to obtain the gated feature. ,in This represents element-wise multiplication; the gating mechanism can adaptively suppress the eigenvalues of the weak response region and push them to zero according to the value of the gating signal while maintaining the nonlinear expressive power, and at the same time retain or enhance the eigenvalues of the strong response region, thereby effectively filtering redundant noise.
[0074] The spatial weighting sub-step is specifically as follows:
[0075] First, from the original entity two-dimensional feature map described in step S4 In this process, solid basis features are obtained through spatial average pooling. The average pooling operation will cover the entire The eigenvalues of a spatial region are aggregated into a single feature. A vector of channels, where The number of channels in the feature map before pooling is determined; for ease of subsequent operations, the entity basis features... Extended to the gating feature Feature maps with the same spatial dimensions; then, the gated features are... Features of the solid substrate The inputs are fed into the attention gating module to generate a spatial attention weight map, where each spatial location... weight value This indicates the importance of the location feature; subsequently, the spatial attention weight map is compared with the gating feature. Element-wise multiplication is performed at the corresponding spatial locations to weight the features of each channel. The weighted results are then aggregated along the channel dimension to obtain the spatial response features of a single channel. That is, for each channel c, the gated feature map is... Each spatial location eigenvalues multiplied by weights This yields a weighted gating feature map;
[0076] Finally, a residual fusion strategy is employed to integrate the entity's base features. The weighted gated feature map and the linear mapping result of the original first entity embedding. Joint modeling is performed, which involves element-wise addition at corresponding spatial locations and channels to obtain the refined feature map. ,in The initial embedding representation of the original first entity is obtained through a learnable linear mapping layer. Mapped to Obtained with the same dimensions and spatial size.
[0077] Furthermore, step S9 specifically includes:
[0078] After completing the multi-level feature refinement in step S8 and obtaining the refined feature map Afterwards, among them The number of channels in the feature map. and For spatial dimensions, step S9 involves three steps: feature projection, score calculation, and model optimization.
[0079] The feature projection step specifically involves: first, projecting the refined feature map... Perform a flattening operation, that is, flatten the three-dimensional tensor Rearranged into a length of A one-dimensional vector is then input into a fully connected layer, the weight matrix of which is... The bias vector is ,in For the dimension of entity embedding, the flattened vector is linearly mapped to a dimension of through matrix multiplication and bias addition operations. The intermediate vector is then input into a batch normalization layer. This layer normalizes the intermediate vectors of multiple samples within the current training batch, making their mean 0 and variance 1, thereby stabilizing the training process and accelerating model convergence. Finally, the output of the batch normalization layer is input into a ReLU activation function for nonlinear transformation to obtain the structure-aware feature vector. This vector integrates all semantic and structural information from cross-attention alignment and dynamic convolution to multi-level feature refinement;
[0080] The scoring calculation process employs a 1-N training strategy, modeling knowledge graph link prediction as a multi-label classification problem. Specifically, in each forward propagation, for a given query pair... ,in As the first entity, the model obtains the structure-aware feature vector. Then, the vector and the entity embedding matrix are calculated through a single matrix multiplication. The dot product similarity of the transposes of the given values yields a value of length . The original rating vector, where the t-th element represents the query pair. The original matching score with the candidate second entity t; then, the original score vector is multiplied by a learnable scale parameter. And add it to a learnable bias term b, where the scale parameter During model training, the values are automatically adjusted via backpropagation, and their range is constrained between [5, 15] to maintain a reasonable dynamic range for the score distribution. Then, the score vector after scaling and bias adjustment is input into the Sigmoid function, which maps each score value to a matching probability in the (0, 1) interval, resulting in a matching probability vector. ,in For the Sigmoid function;
[0081] The model optimization step employs a binary cross-entropy loss function to optimize the model parameters, formalizing the link prediction task into a multi-label binary classification problem; specifically, for a training sample... ,in For a real second entity, its target label is a string of length. A binary vector y, in which only the real second entity is represented. The position of the target label is set to 1, and the rest are set to 0; to improve the generalization ability of the model and prevent overfitting, label smoothing is applied to the target label, that is, the target value of the true second entity position is adjusted from 1 to 0. At the same time, adjust the target values at other locations from 0 to The smoothing coefficient The value is set to 0.1; then, the matching probability vector is calculated. The binary cross-entropy loss between the target label vector and the smoothed target label vector is defined as follows:
[0082] ;
[0083] in The target label value after smoothing. Candidate second entities predicted by the model The matching probability; the model uses the Adam optimizer, calculates the gradient based on the loss function and updates all learnable parameters through backpropagation until the loss converges;
[0084] After the model training is complete, for any given query pair to be completed ,in Given the first known entity, the matching probability vector is obtained through the forward computation process from steps S1 to S9. And select the candidate second entity with the highest matching probability value as the target for this query. The completion results are output to complete the missing entities in the knowledge graph to be completed;
[0085] Wherein, when the first entity is the head entity, the second entity is the tail entity, and the query pair This corresponds to the scenario where the head entity completes the tail entity; when the first entity is the tail entity, the second entity is the head entity, and the query pair... This corresponds to the scenario where the tail entity completes the head entity.
[0086] The beneficial effects of this invention are as follows:
[0087] First, it significantly improves the semantic alignment capability between entities and relations, as well as the modeling accuracy of complex relations. By constructing a bidirectional multi-head cross-attention mechanism, explicit interactions are established in both the entity-to-relation and relation-to-entity directions. This allows entity representations to dynamically adjust under relational semantic conditions, while relation representations can also perceive entity features, achieving deep semantic alignment. Compared to the existing technology's "independent encoding first, then passive interaction" model, this invention establishes bidirectional coupling relationships from the initial stage of representation learning, effectively alleviating semantic inconsistency problems and achieving higher inference accuracy in complex relational scenarios.
[0088] Second, it breaks through the limitation of fixed interaction patterns in traditional convolutional knowledge graph completion methods. By introducing a relation-driven dynamic two-dimensional convolution mechanism, relational semantics are mapped to adaptively generated convolutional kernels, enabling the model to flexibly adjust feature extraction strategies according to different relation types, thereby more precisely modeling the local structural matching patterns between entities and relations. Compared with traditional static convolution methods, this invention achieves strong coupling between convolutional kernel parameters and relational semantics, significantly enhancing the model's ability to express diverse relational semantics.
[0089] Third, it achieves multi-level feature refinement and key information highlighting. By combining multi-scale feature extraction, channel attention recalibration, gating filtering, and spatial weighting mechanisms, the features obtained from dynamic convolution are refined layer by layer. This simultaneously captures local fine-grained patterns, mesoscale contextual information, and structural semantic responses within a larger receptive field, highlighting key discriminative information and effectively suppressing redundant noise. Compared to the coarse-grained feature fusion methods in existing approaches, the multi-level feature refinement mechanism of this invention significantly improves the discriminativeness, stability, and robustness of model representation learning.
[0090] Fourth, it improves the overall prediction performance and generalization ability in knowledge graph completion tasks. By constructing a unified entity-relationship interaction modeling framework, and comprehensively utilizing original entity semantics, cross-attention enhanced representation, and multi-scale structural features, the model can achieve integrated modeling of local matching and global semantics while maintaining computational efficiency, utilizing both basic semantic information and high-order structural information. Experimental results on public benchmark datasets FB15K-237, WN18RR, and UMLS show that this invention outperforms existing mainstream methods in key evaluation metrics such as MRR, Hits@1, Hits@3, and Hits@10, verifying its effectiveness and advancement in complex knowledge graph completion tasks, and meeting the requirements for high accuracy and high reliability in practical application scenarios. Attached Figure Description
[0091] Figure 1 : Flowchart of the method of the present invention;
[0092] Figure 2: Performance comparison chart of the model under different numbers of attention heads in this invention;
[0093] Figure 3 : Performance comparison chart of the model under different scaling factors in this invention;
[0094] Figure 4 Performance comparison chart of models with different convolution kernel sizes. Detailed Implementation
[0095] The present invention will be further described below with reference to the accompanying drawings and specific embodiments:
[0096] Example: This invention proposes a knowledge graph completion method based on multi-head cross-alignment and dynamic feature refinement. To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be noted that the specific embodiments described herein are only for explaining the invention and are not intended to limit the scope of protection of the invention.
[0097] Overall technical solution overview:
[0098] The knowledge graph completion method proposed in this invention is based on the construction of a three-stage collaborative representation learning framework of "semantic alignment - dynamic modeling - feature refinement". Unlike the existing paradigm of encoding entities and relations independently and then performing shallow interactions, this invention establishes a bidirectional semantic coupling relationship between entities and relations from the initial stage of representation learning, and continuously introduces relational semantic guidance in the subsequent feature extraction process. Finally, through a multi-level feature refinement mechanism, it outputs a highly discriminative structure-aware feature vector for accurate link prediction.
[0099] Figure 1 The overall framework of the method of the present invention is shown. The entire technical solution can be divided into nine sequentially executed steps, and the specific implementation methods of each step are described in detail below.
[0100] Step S1: Obtain the initial embedding representation:
[0101] Before model training begins, it is necessary to first construct or load the embedding representation matrix of the knowledge graph. Specifically, this involves constructing an entity embedding matrix. and a relation embedding matrix ,in This represents the total number of entities in the knowledge graph. Represents the total number of relations. This refers to the preset embedding dimension. This determines the capacity of the representation space, which in practice can be selected between 128 and 1024 depending on the size and complexity of the knowledge graph. Commonly used values are 256 or 512. Entity embedding matrix Each row in the text corresponds to a specific entity. 3D continuous vector representation, relation embedding matrix Each row in the table corresponds to a specific relation. The two matrices are represented as 3D continuous vectors. At the beginning of training, they are usually randomly assigned values using Xavier initialization or uniform distribution initialization. Then, during model training, they are continuously optimized and adjusted through the backpropagation algorithm, so that semantically similar entities are close to each other in the vector space, and semantically similar relationships also exhibit similar geometric distributions.
[0102] Upon receiving the query pair to be completed Afterwards, among them The first entity (which can be either a head entity or a tail entity depending on the completion direction) is used as the basis for the model. Identifiers from entity embedding matrix Retrieve the corresponding number from the table Row vectors, serving as the initial embedding representation of the first entity. At the same time, according to the relationship Identifiers from relation embedding matrix Retrieve the corresponding number from the table Row vectors, serving as the initial embedding representation of relations. This table-based embedding acquisition method is the standard operation for knowledge graph representation learning, and has advantages such as simple implementation, high computational efficiency, and ease of parallelization.
[0103] To improve the model's generalization ability during training and prevent overfitting, the initial embedding representation of the first entity is... Initial embedding representation of relations Before inputting subsequent modules, random deactivation is applied to both. Random deactivation is a regularization technique widely used in deep neural networks. Its basic principle is to discard modules with a preset probability in each training iteration. Randomly set some elements of the vector to zero; these zeroed elements do not participate in forward propagation and backward gradient updates in the current iteration. The remaining elements are then proportionally... Scaling is applied to keep the expected value of the output vector consistent between training and inference phases. Dropout probability. The value is typically set between 0.1 and 0.5, with 0.2 or 0.3 being more commonly used. After random deactivation, the initial embedding representations of the first entity and the initial embedding representations of the relation are then passed to the bidirectional multi-head cross-attention module in step S2 as two inputs to the module.
[0104] Step S2: Bidirectional multi-head cross-attention semantic alignment;
[0105] The bidirectional multi-head cross-attention calculation performed in step S2 is divided into two symmetrical attention calculation paths, denoted as the first entity to relation direction. and related to the direction of the first entity The computations in these two directions are structurally symmetrical, but the sources of queries, keys, and values are interchanged, thus achieving bidirectional coupling between updating entity representations under relational semantics and updating relational representations under entity semantics.
[0106] First entity to relation direction ( In the process, the initial embedding representation of the first entity after random deactivation in step S1 is used as the query input. The initial embedding representation of the relation after random deactivation in step S1 is used as the key input. Sum value input First, through three learnable linear mapping matrices... , , The query matrix is obtained by performing linear projections on the query input, key input, and value input respectively. Key matrix Sum matrix The purpose of these three linear mapping matrices is to project the original embedding vectors onto different representation subspaces, enabling the model to capture semantic association patterns between entities and relations from multiple perspectives.
[0107] Then, query matrix Key matrix Sum matrix Divide equally into the feature dimensions. Each part corresponds to an attention head, such that each attention head... Obtain the corresponding query subspace matrix Key space matrix Sum subspace matrix The feature dimension of each attention head is . The introduction of the multi-head mechanism is to enhance the expressive power of the model: if only a single attention head is used, the model can only learn one entity-relation interaction pattern, which may not be enough to cover the rich and diverse semantic relationships in the knowledge graph; however, by performing attention computation in parallel in different low-dimensional subspaces, the model can explore diverse semantic interaction patterns simultaneously.
[0108] Within each attention head, scaled dot product attention computation is performed independently. Specifically, the query subspace matrix is first computed. With key space matrix The product of the transposes of matrices, the product matrix of the first and second elements. Line number Column elements represent the first The query vector and the first The inner product similarity between the key vectors. Then, the product result is divided by the scaling factor. The purpose of this scaling operation is to prevent when When the inner product value is large, it can cause the subsequent Softmax function to enter the saturation region, thus effectively avoiding the gradient vanishing problem. Next, the scaled similarity matrix is normalized along the key dimension using the Softmax function to obtain the attention weight matrix. Each row of this matrix represents the attention distribution of the corresponding query across all keys. Finally, the attention weight matrix is compared with the value subspace matrix. Multiply to obtain the output of the attention head. The complete calculation formula is as follows: .
[0109] After completing all After calculating the attention heads, the output vectors of each head are concatenated along the feature dimension to obtain a dimension of The concatenated vectors are then processed through a learnable output mapping matrix. A linear transformation is performed on the concatenated vector to obtain the first entity-side augmented representation. The purpose of the output mapping matrix is to interactively fuse the information extracted by different attention heads and map the fused representation back to the original embedding dimension.
[0110] In relation to the direction of the first entity ( In this process, the initial embedding representation of the relation after random deactivation in step S1 is used as the query input. The initial embedded representation of the first entity after random deactivation in step S1 is used as the key input. Sum value input The process follows the exact same workflow as the one from the first entity to the relation: through three learnable linear mapping matrices. , , Perform projection and divide into Each attention head performs scaled dot product attention computation, and the outputs of all heads are concatenated and mapped through an output mapping matrix. Perform a linear transformation to obtain the relation-side enhanced representation. The relation-side enhanced representation integrates the constraints and concretization of relation semantics by the first entity context, making the originally global relation representation specialized and refined for the current first entity.
[0111] Step S3: Soft fusion weighting;
[0112] Enhanced representation of the first entity side after obtaining the output of step S2. and relational enhancement representation Subsequently, directly replacing the original initial embedding representation with these enhanced representations may weaken the global structural information and semantic robustness contained in the original representation. This is because the original embedding representation... and These are obtained through global optimization learning across the entire knowledge graph. They contain the location information of entities and relations in the entire semantic space, reflecting their overall distribution characteristics within the knowledge graph; while augmented representations... and Although it incorporates specific interaction information from the current query context and has strong task relevance, it may deviate from global semantic constraints to some extent.
[0113] To achieve the optimal balance between original semantic information and interaction enhancement information, step S3 employs a learnable soft fusion mechanism to adaptively weight and fuse the two. For the first entity side, the initial embedding representation of the first entity is first... and the first entity side enhancement representation The inputs are fed into a lightweight neural network consisting of a single fully connected layer. This single fully connected layer has two input nodes and two output nodes, and its weight matrix has a size of [size missing]. The bias vector has a size of 2, and the output is two unnormalized raw fusion weights. and This minimalist network structure, while ensuring that the fusion strategy is learnable, minimizes the number of additional parameters and computational overhead.
[0114] Subsequently, the original fusion weights were adjusted. and Applying Softmax normalization yields learnable soft fusion weights. and The calculation formula is as follows: , Due to the properties of the Softmax function, the resulting soft fusion weights satisfy... The constraint can therefore be interpreted as the proportion of contributions of the original representation and the enhanced representation in the final fused representation. For example, if , This indicates that the fusion representation is in The information comes from the original embedding. The information comes from cross-attention enhancement.
[0115] Then, according to the formula The initial embedded representation of the first entity and the enhanced representation of the first entity are weighted and summed to obtain the fused first entity representation. The weighted summation operation is performed element-wise in a vector space, meaning that the same weighting operation is performed on each dimension of the vector.
[0116] For the relation side, the same fusion process as the first entity side is adopted: the relation is initially embedded in the representation. and relational enhancement representation The input is fed into another lightweight neural network with the same structure, consisting of a single fully connected layer, to generate unnormalized raw fusion weights. and After Softmax normalization, the desired result is obtained. soft fusion weights and Then follow the formula We perform a weighted summation to obtain the fusion relation representation. It should be noted that the entity-side and relation-side fusion networks are independent of each other, each with its own weight matrix and bias vector. Therefore, the entity fusion weights and relation fusion weights can be different, which is consistent with the intuitive understanding that entity semantics and relation semantics differ at the abstract level.
[0117] Step S4: Two-dimensional feature map reconstruction and union;
[0118] The first entity representation of the fusion is obtained in step S3. Relationship between fusion and integration Subsequently, to leverage the modeling capabilities of convolutional neural networks (CNNs) for local structural patterns, the one-dimensional vector representation needs to be reconstructed into a two-dimensional feature map format. The tremendous success of CNNs in computer vision has amply demonstrated that two-dimensional spatial structures can effectively capture the interdependencies between local patterns. By reconstructing the embedded representations of entities and relations into two-dimensional feature maps, the model can explicitly model the matching patterns between entities and relations at the local structural level using convolutional operations. This approach offers stronger expressive power and better generalization performance than simple vector inner products or bilinear transformations in traditional methods.
[0119] Specifically, the first entity representation of fusion is represented separately. Relationship between fusion and integration Perform a dimension rearrangement operation, changing it from a length of... One-dimensional vector rearranged to a preset size A two-dimensional matrix. Wherein, and All are integers greater than 1, and satisfy the following conditions: . and The specific value is determined before model training based on the embedding dimension. The factorization is predetermined. For example, when the embedding dimension is... At that time, a common choice is , This forms a square-shaped two-dimensional feature map; when At that time, you can choose , or , wait. and The relative proportions affect the distribution of the receptive field in the horizontal and vertical directions of the convolution operation; feature maps of different shapes may be suitable for capturing structural patterns of different properties. This should be determined before model training. and After the value is determined, it remains unchanged throughout the training and inference process.
[0120] After rearrangement, two-dimensional first entity feature maps are obtained respectively. and two-dimensional relational feature map To facilitate subsequent convolution operations, these two two-dimensional matrices can be further viewed as two-dimensional tensors with a single channel. The concept of channels originates from digital image processing: color images typically have three channels—red, green, and blue—each recording light intensity information at different wavelengths; in convolutional neural networks, the number of channels represents the depth dimension of the feature map.
[0121] Considering the initial embedding representation of the original first entity The original embedding representation still contains important basic semantic information. Step S4 jointly models the original first entity features and the first entity features enhanced by cross-attention in two-dimensional space. The basic semantic information in the original embedding representation may contain discriminative features directly related to the identity of the first entity. These features may be weakened or blurred after the cross-attention mechanism, so they need to be explicitly preserved and used in conjunction with the enhanced features.
[0122] Specifically, the initial embedding representation of the original first entity Reconstruct the preset size using the same dimensional rearrangement method as described above. Original entity two-dimensional feature map Then, the original entity's two-dimensional feature map is transformed along the channel dimension. With the two-dimensional first entity feature map The two are then concatenated. Since both can be considered as single-channel two-dimensional tensors, the concatenation results in a two-dimensional feature map of the entity to be convolved and fused, with two channels. The first channel corresponds to the original entity's two-dimensional feature map, carrying the basic semantic information of the first entity; the second channel corresponds to the two-dimensional feature map of the first entity after cross-attention enhancement, carrying refined semantic information guided by the relational context. This dual-channel design allows subsequent dynamic convolution operations to utilize feature information from both sources simultaneously. The two-dimensional feature map of the entity to be convolved is then subjected to channel compression and linear fusion through pointwise convolution to obtain a single-channel fused entity two-dimensional feature map.
[0123] The single-channel fused entity two-dimensional feature map is then passed to step S5 as the target feature map for the dynamic convolution operation; the relational two-dimensional feature map is passed to step S5 to generate the dynamic convolution kernel.
[0124] Step S5: Relationship-driven dynamic overlapping convolution;
[0125] After obtaining the two-dimensional feature map of the entity to be convolutionally fused from the output of step S4. and two-dimensional relational feature map Subsequently, step S5 executes a relation-aware dynamic overlapping convolution mechanism, explicitly introducing relational semantics into the feature refinement process. This is one of the core technological innovations of this invention. In traditional convolutional neural networks, the parameters of the convolution kernel are fixed after training, and the same feature extraction strategy is used for all input samples. However, in knowledge graph completion scenarios, the semantic patterns corresponding to different relation types vary greatly. For example, the "birthplace" relation requires the model to focus on the birth association between the person entity and the geographical location entity, while the "creation" relation requires the model to focus on the creation association between the creator entity and the work entity. It is difficult to perform refined modeling of such diverse semantic scenarios simultaneously using a fixed static convolution kernel. The dynamic convolution mechanism proposed in this invention explicitly introduces relational semantics into the generation process of the convolution kernel, enabling the parameters of the convolution kernel to be dynamically adjusted according to different input relations, thereby breaking through the expressive capacity bottleneck of traditional static convolution.
[0126] First, the two-dimensional relation feature map Considered as a spatial dimension A two-dimensional matrix containing one channel. To generate the dynamic convolution kernel, this two-dimensional relational feature map is... The system divides the space into multiple local regions according to a preset kernel size, with each local region serving as a dynamically generated convolutional kernel. In a specific implementation of this invention, the preset kernel size is the size of the local window. The two-dimensional relationship feature map The two-dimensional relation feature map is divided into multiple local regions according to the size of the local window in the spatial dimension, and each local region serves as a dynamically generated convolutional kernel. This means that each dynamic convolutional kernel covers the entire relation feature map, and the relational semantics are completely and losslessly encoded into each dynamic convolutional kernel. The number of dynamic convolutional kernels is equal to the number of local regions obtained by sliding the two-dimensional relation feature map in the spatial dimension according to the preset local window size.
[0127] Subsequently, the dynamically generated convolutional kernel is applied to the two-dimensional feature map of the entity to be convolved and fused using an overlapping sliding method with a stride of 1. Convolution operations are performed on the above; since both the fused entity 2D feature map and the relation 2D feature map are single-channel feature maps, each dynamic convolution kernel corresponds to a size of The local region is used as a flattened vector in subsequent matching calculations.
[0128] The specific process of convolution operation is as follows: On the two-dimensional feature map of the entity to be convolved and fused, the dynamic convolution kernel calculates the matching response between the local region of the relationship and the local window of the entity through batch matrix multiplication, thereby obtaining the feature map with relational semantic conditionalization; then, all matching results are rearranged according to spatial structure to generate a relation-aware feature map; by performing the above matching calculation on all possible spatial window positions, a multi-channel two-dimensional relation-aware feature map with relational semantic conditionalization is finally generated. The number of channels It equals the number of the local regions.
[0129] This dynamic convolution operation can be uniformly represented as: ,in This represents a relation-driven dynamic overlapping convolution operator. The convolution kernel parameters in this operator are adaptively generated entirely from relation features, enabling the model to dynamically adjust its feature selection strategy for different relation types. It explicitly characterizes the local matching pattern of "relation-entity" at the spatial level, providing rich structure-aware representations for subsequent multi-scale feature extraction and gating fusion.
[0130] Step S6: Multi-scale feature extraction;
[0131] Obtain the relation-aware feature map output in step S5. Subsequently, considering the multi-scale characteristics of entities and relations in the knowledge graph across spatial range, step S6 employs an Inception-style multi-branch, multi-scale feature transformation to transform the relation-aware feature map. Parallel modeling is employed. The Inception architecture, first proposed by the Google team in GoogleNet, is based on the core idea of running multiple convolutional operations of different sizes in parallel at the same layer, and then concatenating the outputs of each branch. This allows the network to capture feature patterns at different scales simultaneously. This "divide and conquer" design significantly expands the width and expressive power of the network while maintaining computational efficiency.
[0132] Specifically, construct a multi-branch parallel structure containing four parallel branches:
[0133] The first branch is The convolutional branch contains a convolutional kernel of size [size missing]. The convolutional layer. Convolution does not expand the receptive field in the spatial dimension. Its main functions are twofold: first, it linearly combines the channels of the input feature map to achieve information exchange and dimensionality reduction between channels; second, it introduces a non-linear activation function after convolution to enhance the network's expressive power. This branch is specifically designed to capture local fine-grained patterns, that is, to reorganize and refine feature channels at the finest granularity.
[0134] The second branch is The convolutional branch contains a convolutional kernel of size [size missing]. The convolutional layer. The effective receptive field of convolution is For regions, the output of the convolution operation at each spatial location integrates information from that location and its eight surrounding neighborhood locations, enabling the capture of medium-scale local context. In the two-dimensional feature representation of knowledge graphs, Regions may correspond to patterns of co-variation among multiple embedding dimensions, and this medium-scale semantic structure has important discriminative value in many relation types.
[0135] The third branch is Convolutional Branches, Large Receptive Field: The effective receptive field of convolutional branches is equivalent to... The region, which is formed by two stacked Convolutional layers are implemented to expand the receptive field while reducing computational overhead. The effective receptive field of the convolution branch is A larger receptive field allows for the capture of a wider range of structural semantic responses. A larger receptive field means that each output location can synthesize input information from a broader region, making it suitable for capturing macroscopic structural patterns that span multiple embedding dimensions. However, The computational cost of convolution is significantly higher than that of other methods. Convolution, therefore, in some lightweight implementations, two stacked convolutions can also be used. Convolution to approximate The receptive field of convolution is adjusted to reduce computational overhead.
[0136] The fourth branch is the max pooling branch, which contains a pooling window with a size of [missing value]. A max-pooling layer with a stride of 1, followed by a... Convolutional layers. Max pooling calculates the maximum value within each window, extracting the most salient response. Unlike average pooling, max pooling highlights the strongest feature activations within local regions, making it more suitable for capturing discriminative patterns. (The following...) Convolutional layers are used to adjust the number of channels in the pooled features so that they can be spliced together with the outputs of other branches.
[0137] Relationship-aware feature maps Simultaneously, the inputs are fed into the four branches mentioned above. Each branch performs forward computation independently, outputting a feature map with the same spatial dimensions as the input feature map or with the same dimensions after appropriate padding. Then, the output feature maps from the four branches are concatenated along the channel dimension. If each branch outputs... The feature maps of each channel are then concatenated to obtain a feature map with... The concatenated feature map of each channel. The concatenation operation along the channel dimension preserves all the feature information extracted from each branch, allowing the subsequent channel attention mechanism to learn how to optimally combine these multi-scale features.
[0138] To maintain the stability of the feature representation while incorporating multi-scale structural information, step S6 further incorporates the relationship between the concatenated feature map and the original input feature map. Perform residual connections. Residual connections are the core component of deep residual networks, and their form is the output... Transform (input) Input. This design allows gradients to propagate directly backward through the "identity mapping" path, effectively mitigating the gradient vanishing problem in deep networks and ensuring that the multi-scale feature extraction module does not lose effective information from the original relation-aware feature map while introducing new information. If the number of channels in the concatenated feature map is less than that in the relation-aware feature map... If the number of channels is inconsistent, then first go through one Convolutional layers will The number of channels was adjusted to match the splicing features. Figure 1 Then, the two are added element-wise at their corresponding spatial locations and channels to obtain multi-scale fused features. This process can be formally represented as ,in This indicates the above multi-branch parallel transformation operation. This is a relational perception feature map after adjusting the number of channels.
[0139] Step S7: Channel attention recalibration;
[0140] After obtaining the multi-scale fusion features output in step S6 Afterwards, among them The number of channels in the feature map. and The spatial height and width are respectively determined. Step S7 introduces a channel attention mechanism to adaptively recalibrate the multi-scale fused features. The channel attention mechanism originates from Squeeze-and-Excitation Networks in computer vision. Its core idea is to allow the model to autonomously learn the interdependencies between feature channels and adaptively adjust the channel responses by "selectively emphasizing and selectively ignoring" based on global information. In multi-scale fused features... In this context, different channels correspond to semantic features extracted at different scales and from different branches. Not all channels are equally important to the current completion task. Therefore, it is necessary to use a channel attention mechanism to highlight discriminative channels and suppress redundant channels.
[0141] First, regarding the multi-scale fusion features Perform global average pooling in the spatial dimension, that is, for each channel Calculate all on this channel The arithmetic mean of the feature values of each spatial location yields a length of... Channel descriptor vector , of which element The channel descriptor vector aggregates global statistics for each channel across the entire space, and can be considered a rough estimate of the global importance of the corresponding channel.
[0142] Then, the channel descriptor vector The input is fed into a bottleneck structure consisting of two fully connected layers to learn the non-linear dependencies between channels. The bottleneck structure is named for its shape, which is narrow in the middle and wide at both ends: the first fully connected layer receives the input dimension... Compress to a preset ratio smaller dimensions ,in The compression ratio is usually an integer greater than 1, with 16 being a commonly used value. This compression operation has a dual purpose: first, it limits the number of model parameters and computational cost, allowing the channel attention module to be lightweightly embedded into the main network; second, it forces the model to learn a compact representation of channel dependencies, acting as a regularization effect to address information bottlenecks and helping to extract the most essential inter-channel correlation patterns. The output of the first fully connected layer is then non-linearly transformed using the ReLU activation function, where ReLU is mathematically defined as... Its unilateral inhibition and non-saturation properties help enhance the model's expressive power and training stability.
[0143] Next, the second fully connected layer reduces the dimension from Restore to the original dimension Its output is normalized using the Sigmoid activation function. The mathematical form of the Sigmoid function is: Its output range is (0,1). After passing through the Sigmoid function, a channel activation weight vector with values in the range (0,1) is generated. , of which element Indicates the first The importance weight of each feature channel: the closer the value is to 1, the more important the channel is; the closer the value is to 0, the less important the channel is.
[0144] Then, the channel activation weight vector Combined with the original multi-scale fusion features Perform channel-by-channel multiplication along the channel dimension. That is, for each channel... The feature map of this channel The eigenvalue of each spatial location is multiplied by the corresponding channel weight. The weighted feature map is obtained. Finally, in order to preserve the original multi-scale structural information while enhancing feature discriminative power, the weighted feature maps are... Combined with original multi-scale features Perform residual join, which involves element-wise addition at corresponding spatial locations and channels to obtain recalibrated features. Residual connections ensure that even if there is some bias in the estimation of attention weights, the original features can still be passed to subsequent layers through the residual path.
[0145] Step S8: Gating and Spatial Weighting;
[0146] After obtaining the recalibration features output in step S7 Then, step S8 executes two sub-steps in sequence: gating and spatial weighting, to further highlight the key structural patterns and introduce the prior constraints of the first entity.
[0147] The gating filtering sub-step is implemented using a gated linear unit (GLU). GLU was initially proposed for language modeling tasks in natural language processing. Its core feature is controlling information flow through a learnable gating signal, enabling the network to adaptively determine which information can pass and which should be blocked. Specifically, the relabeled features are first... Apply a convolution kernel with a size of The pointwise convolution operation does not change the spatial size of the feature map; it only performs a linear combination of channel information, and its output has the same spatial size as the input. and number of channels The output of the pointwise convolution is fed into the Sigmoid activation function to generate a gating signal with values in the range (0,1). ,in For the Sigmoid function, express Pointwise convolution operator. Gating signal. Each element in the equation can be interpreted as the proportion of information passing through that spatial location and channel.
[0148] At the same time, the recalibrated features will be Input to hyperbolic tangent activation function The features obtained after nonlinear activation are obtained. . The mathematical form of the function is Its output range is (-1, 1), and it is symmetric about zero. This zero-centeredness helps alleviate the offset problem during gradient propagation, making the training of deep networks more stable. Subsequently, the gating signal... Features after nonlinear activation Element-wise multiplication is performed at the corresponding spatial locations and channels to obtain the gating features. ,in This represents element-wise multiplication. The actual effect of this operation is that for positions and channels where the gating signal approaches 1, the feature values are fully preserved; for positions and channels where the gating signal approaches 0, the feature values are pushed to zero, i.e., effectively filtered out.
[0149] The spatial weighting sub-step further introduces prior constraints on the first entity, making the feature refinement process not only dependent on relation-guided local responses but also constrained by the global semantics of the first entity. First, from the single-channel fusion entity two-dimensional feature map described in step S4... In this process, entity basis features are obtained through global average pooling. Global average pooling will... The eigenvalues of a spatial region are aggregated into a single statistic, therefore The basic features of the entity carry the overall semantic features of the first entity in the entire two-dimensional feature space and can be regarded as the "identity summary" of the first entity. For ease of subsequent operations, entity basis features... Extended to gating features Feature maps with the same spatial dimensions.
[0150] Then, the entity base features With gated features By concatenating along the channel dimension, a result is obtained with... The concatenated feature map of each channel is then input into a convolutional kernel with a size of [size missing]. The convolutional layer is compressed to have 1 channel, and a single-channel spatial location weight map is generated using the Sigmoid activation function. Each spatial location weight value This indicates the importance of the location feature. Because the spatial attention function considers both the gated, multi-scale refined features and the global semantic basis of the first entity when generating location weights, the generated weight map can highlight local responses that are semantically relevant to the current relation while maintaining consistency with the inherent semantics of the first entity.
[0151] Subsequently, the spatial location weight map With the gated features Element-wise multiplication is performed in the spatial dimension, that is, in each channel Above, the gated feature map Each spatial location eigenvalues multiplied by weights This yields a weighted gated feature map. Finally, a residual fusion strategy is employed to integrate the entity basis features. Weighted gating feature map and the linear mapping result of the original first entity embedding. Joint modeling involves element-wise addition at corresponding spatial locations and channels to obtain a refined feature map. ,in The initial embedding representation of the original first entity is obtained through a learnable linear mapping layer. Mapped to The same dimensions and spatial size are used. This triple residual fusion ensures that the refined feature map integrates the original entity semantics, the multi-scale refined features after gating and filtering, and the enhanced response after spatial weighting, forming a multi-level, multi-perspective entity-relation joint representation.
[0152] Step S9: Feature projection, score calculation, and model optimization;
[0153] After completing the multi-level feature refinement in step S8 and obtaining the refined feature map Then, step S9 performs three steps: feature projection, score calculation, and model optimization, completing the entire process calculation from two-dimensional spatial features to the final link prediction result.
[0154] Feature projection stage:
[0155] The feature projection stage is responsible for mapping the refined feature map of the two-dimensional spatial structure back to the one-dimensional embedding space, so as to perform matching calculations with the candidate entity embedding vectors. First, the refined feature map... Perform a flattening operation, that is, flatten the three-dimensional tensor Rearranged according to a preset order into a length of A one-dimensional vector. The flattening operation does not introduce any learnable parameters, ensuring that the transformation from spatial information to vector representation is completely deterministic.
[0156] Then, this one-dimensional vector is input into a fully connected layer. The weight matrix of the fully connected layer is... The bias vector is ,in The dimension for entity embedding. Through matrix multiplication and bias addition, the flattened vector is linearly mapped to a dimension of... The intermediate vector. The number of parameters in the fully connected layer is It is one of the parts of the model with a relatively concentrated number of parameters.
[0157] Next, the intermediate vectors are input into a batch normalization layer. The batch normalization layer normalizes the intermediate vectors of multiple samples within the current training batch, ensuring that their mean is 0 and variance is 1 in the batch dimension. Batch normalization plays several important roles in deep neural network training: it stabilizes the distribution of inputs to each layer by reducing internal covariate bias, thus allowing for a larger learning rate and accelerating model convergence; it has a slight regularization effect, preventing overfitting to individual samples to some extent; and it reduces the network's sensitivity to parameter initialization, making the training process more robust.
[0158] Finally, the output of the batch normalization layer is input into the ReLU activation function for nonlinear transformation to obtain the structure-aware feature vector. The mathematical definition of the ReLU activation function is... Its non-saturation and one-sided inhibition properties enable the network to learn complex nonlinear mappings while maintaining smooth gradient propagation. Structure-aware feature vectors It integrates all semantic and structural information from cross-attention alignment and dynamic convolution to multi-level feature refinement, and is a comprehensive approach to the original query pair. A highly refined continuous vector representation.
[0159] Scoring calculation process:
[0160] The scoring calculation stage employs a 1-N training strategy, modeling knowledge graph link prediction as a multi-label classification problem. The 1-N strategy represents a significant paradigm shift in the field of knowledge graph completion in recent years: unlike traditional 1-1 training where loss is calculated for only one positive sample and one randomly sampled negative sample at a time, the 1-N strategy calculates the loss for each given query pair in each forward propagation. The model obtains structure-aware feature vectors. Then, the matching score between the vector and all candidate entities in the knowledge graph is calculated at once. This strategy not only significantly improves training efficiency, but also allows the model to perceive the distribution characteristics of multiple negative samples simultaneously in each iteration, which is beneficial for learning more discriminative decision boundaries.
[0161] Specifically, the structure-aware feature vector is calculated through a single matrix multiplication. With entity embedding matrix The dot product similarity of the transposes of the given values yields a value of length . The original score vector, where the first... Each element represents a query pair. With candidate second entity The original matching score is then used. Subsequently, the original score vector is multiplied by a learnable scale parameter. and with a learnable bias term. Add. Scale parameter During model training, the values are automatically adjusted through backpropagation, and are usually constrained to the range of [5,15] to maintain a reasonable dynamic range for the score distribution. The value of affects the steepness of the matching probability distribution: When the value is large, the probability distribution becomes more polarized, and the model becomes more "confident." When the values are smaller, the probability distribution is smoother, and the model is more "conservative." Then, the scaled and bias-adjusted score vector is input into the Sigmoid function, mapping each score value to a matching probability within the (0,1) interval, resulting in a matching probability vector. ,in This is the Sigmoid function.
[0162] Model optimization phase:
[0163] The model optimization stage employs a binary cross-entropy loss function to optimize the model parameters, formalizing the link prediction task into a multi-label binary classification problem. For a training sample... ,in For a real second entity, its target label is a string of length. binary vector Only the corresponding real second entity The position is 1, and the rest are 0.
[0164] To improve the model's generalization ability and prevent overfitting, label smoothing is applied to the target labels. Label smoothing is an effective regularization technique that replaces traditional hard labels with soft labels: the target value at the true second entity location is adjusted from 1 to... At the same time, adjust the target values at other locations from 0 to The smoothing coefficient The value is set to 0.1. Label smoothing encourages the model to assign a probability of approximately 0.9 to real entities and distribute the remaining probability of approximately 0.1 evenly across all candidate entities. This soft objective constraint ensures that the model maintains its discriminative ability without becoming overconfident in any single training sample.
[0165] Then, calculate the matching probability vector. The binary cross-entropy loss between the target label vector and the smoothed target label vector is defined as follows:
[0166] ;
[0167] in The target label value after smoothing. Candidate second entities predicted by the model The matching probability.
[0168] The model employs the Adam optimizer, which calculates the gradient based on the loss function and updates all learnable parameters through backpropagation until the loss converges. The Adam optimizer combines the advantages of momentum methods and adaptive learning rates, and its first-moment estimation exhibits an exponential decay rate. Typically set to 0.9, the exponential decay rate estimated by the second moment. The initial learning rate is typically set to 0.999, and the initial learning rate is usually set to 0.001. During training, early stopping can be implemented based on performance on the validation set to prevent overfitting.
[0169] Model inference and completion results output:
[0170] Model inference and completion output: After model training is complete, for any given query pair to be completed, the output will be... ,in Given the first known entity, the matching probability vector is obtained through the forward computation process from steps S1 to S9. Since the random deactivation mechanism is turned off during the inference phase, the embedding vector is input into subsequent modules in its original form, and all learnable parameters remain fixed, thus the forward computation process is deterministic.
[0171] Select the candidate second entity with the highest matching probability value from the matching probability vector as the target for this query. The system outputs the completion results, thus completing the missing entities in the knowledge graph to be filled. In practical applications, it can also output a list of the top K candidate entities with the highest matching probabilities, for manual review or further filtering by downstream applications, as needed.
[0172] It should be noted that the method of this invention, through the symmetrical design of the "first entity" and the "second entity," can simultaneously support two link prediction directions. When the first entity is the head entity and the second entity is the tail entity, the query pair... This corresponds to the scenario where the head entity completes the tail entity, i.e., given... Prediction?; When the first entity is the tail entity and the second entity is the head entity, the query will return a match. This corresponds to the scenario where the tail entity completes the head entity, i.e., given... Prediction? This unified symmetry design allows the same model structure to be applied to two completion tasks without any modification, significantly improving the method's versatility and practical value.
[0173] Experimental verification and performance evaluation:
[0174] To verify the effectiveness and advancement of the method in this invention, systematic experimental evaluations were conducted on several publicly available benchmark datasets. The knowledge graph datasets used in the experiments included FB15K-237, WN18RR, and UMLS. FB15K-237 is a subset of the Freebase knowledge base, containing 237 relations and approximately 15,000 entities, primarily covering common-sense knowledge; WN18RR is a subset of the WordNet vocabulary knowledge base, containing 11 relations and approximately 40,000 entities, primarily covering semantic relationships between words; UMLS is the knowledge graph of the Unified Medical Language System, containing various semantic relationships between medical concepts. These three datasets differ significantly in scale, domain, and relation types, enabling a comprehensive evaluation of the model's performance in different scenarios.
[0175] The evaluation metrics used are MRR and Hits@K, which are commonly used in the knowledge graph completion field. MRR is the average inverse rank, which calculates the average of the inverse ranks of the real entity among all candidate entities. This metric is more sensitive to predictions with higher rankings. Hits@K is the top K hit rate, which calculates the proportion of samples in which the real entity appears in the top K predicted ranks. Commonly used K values include 1, 3, and 10. All experiments used a 1-N scoring strategy for filtering, that is, excluding candidate entities that have higher scores than the real entities but are already present as positive samples in the training set when calculating the ranking.
[0176]
[0177] Table 1: In-depth performance analysis of benchmark datasets FB15k-237 and WN18RR
[0178] According to Table 1 above:
[0179] 1. State-of-the-art (SOTA) performance leap: On the notoriously complex FB15k-237 dataset, the MCFR model achieves a MRR of 0.416. Compared to the previous best-performing convolutional model, ConvD (0.409), this invention achieves a relative improvement of approximately 1.7%. In the most challenging Hits@1 (preferred accuracy) dataset, the MCFR improves to 0.323, demonstrating the model's ability to accurately locate targets among a massive number of candidate entities.
[0180] 2. Long-tail relation processing capability: The WN18RR dataset is known for its limited relation types and numerous symmetric / reverse relations. MCFR's Hits@10 on this dataset surpasses the 0.60 mark (reaching 0.612), significantly outperforming Transformer-based variants such as Relphormer (0.591).
[0181] 3. Compared with mainstream architectures: Compared with the pure vector translation model (TransE) and the bilinear model (DistMult), MCFR shows multiple-fold growth in all metrics, which reflects the overwhelming advantage of bidirectional multi-head cross attention in capturing deep interactions between entities and relationships.
[0182] Conclusion: Experimental results strongly demonstrate that the MCFR architecture has extremely high prediction accuracy when processing large-scale, multi-relational general knowledge graphs. By combining global semantic alignment with local structural convolution, the model successfully addresses the weakness of traditional models in complex triple inference, establishing its leading position in connection prediction tasks.
[0183]
[0184] Table 2: Performance Analysis of Vertical Domain UMLS Datasets
[0185] According to Table 2 above:
[0186] 1. Achieving extremely high accuracy: UMLS is a professional knowledge graph in the medical field, characterized by a rigorous logical structure but a relatively fixed semantic space. MCFR achieved a Hits@1 score of 0.904 on this dataset, making it one of the few models to break the 0.9 mark on this metric.
[0187] 2. Robustness Validation: Compared with AnKGE (0.937), MCFR maintained a slight but stable lead (0.939) in the MRR index. This lead is particularly important in specialized fields, as the completion of medical knowledge places extremely high demands on the accuracy of the "preferred prediction".
[0188] 3. Low false negative rate: Hits@10 reaches 0.992, which means that the model can almost rank all correct facts in the top ten of the candidate list, greatly reducing the risk of false negatives in knowledge graph construction.
[0189] Conclusion: The MCFR model not only performs excellently in general domains but also demonstrates strong adaptability in specialized vertical fields (medicine). Its multi-scale feature refinement mechanism can accurately capture subtle semantic differences between medical terms, validating the great potential of this invention in practical industry applications (such as intelligent diagnosis and treatment, and medical knowledge discovery).
[0190] Table 3: Ablation Experiment Analysis
[0191] According to Table 3 above:
[0192] 1. The decisive role of Feature Refinement: After removing this module, the MRR plummeted from 0.416 to 0.378 (a decrease of approximately 9.1%). This demonstrates that the Inception-style multi-branch structure and channel attention mechanism play a crucial role in filtering noise and extracting key features.
[0193] 2. Dynamic Convolution vs. Static Convolution: After replacing the "relationship-driven dynamic convolution" of this invention with traditional static convolution, the MRR of WN18RR plummeted from 0.523 to 0.396 (a decrease of approximately 24%). This quantitatively demonstrates that the innovation of "dynamically generating convolution kernels based on relationships" is the core of capturing the heterogeneity of knowledge graphs.
[0194] 3. Component synergy effect: The absence of any single component will lead to a decline in performance, and the improvement of "Full Model" is not a simple superposition of the components, but a non-linear gain generated by the entity-relationship collaborative modeling framework.
[0195] Conclusion: Ablation experiments confirm the necessity and scientific validity of the four core technical features of this invention (bidirectional crossover, two-dimensional fusion, dynamic convolution, and multi-scale refinement). Dynamic convolution is key to addressing the diversity of relationships; feature refinement ensures improved prediction purity. This provides irrefutable experimental support for the inventiveness and technical contribution of this patent application.
[0196] Regarding the appendix Figure 2 The performance comparison shown with different numbers of attention heads reveals that the fluctuations in the experimental data profoundly reflect the sensitivity of the multi-head cross-alignment mechanism in capturing complex semantics of entities and relationships. As the number of attention heads increases from low to high, the model initially shows a significant upward trend in core metrics such as MRR and Hits@10, which verifies the necessity of parallel subspace learning.
[0197] In single-head attention mode, the model can only learn a single interactive projection between entities and relations. Multi-head mechanisms, however, allow the system to simultaneously capture multiple features such as structural consistency, semantic complementarity, and logical relevance across different representational dimensions. However, once the number of heads reaches a certain saturation point, the performance curve tends to plateau, indicating that an excessive number of heads may introduce computational redundancy or lead to parameter overfitting. Through comparative analysis, the optimal head configuration determined in this invention maximizes the multi-head cross-alignment module's ability to extract high-order semantic information while ensuring computational efficiency, ensuring that the model can accurately handle complex and ambiguous relations in knowledge graphs.
Claims
1. A knowledge graph completion method based on multi-head cross-alignment and dynamic feature refinement, characterized in that, Includes the following steps: S1: Obtain the initial embedding representation of the first entity and the initial embedding representation of the relation in the knowledge graph to be completed; S2: A bidirectional multi-head cross-attention mechanism is adopted to calculate cross-attention in two directions: from the first entity to the relation and from the relation to the first entity, to obtain the enhanced representation on the first entity side and the enhanced representation on the relation side. S3: Using learnable soft fusion weights, the initial embedding representation and the corresponding enhanced representation are weighted and fused to obtain a fused first entity representation and a fused relation representation; S4: The fused first entity representation is reconstructed into a two-dimensional feature map, and it is concatenated with the original entity two-dimensional feature map obtained by reconstructing the initial embedding representation of the original first entity in the channel dimension, and the fused entity two-dimensional feature map is obtained by linear fusion mapping; at the same time, the fused relation representation is reconstructed into a relation two-dimensional feature map for subsequent generation of dynamic convolution kernels; S5: Generate a dynamic convolution kernel using the two-dimensional feature map represented by the fusion relationship, and perform dynamic convolution on the two-dimensional feature map of the fusion entity in an overlapping sliding manner to obtain a relationship-aware feature map; S6: Perform multi-scale feature extraction on the relation-aware feature map, capture the structural semantics under different receptive fields through parallel multi-branch convolution and pooling operations, and obtain multi-scale fusion features through residual connections; S7: Perform channel attention recalibration on the multi-scale fusion features, generate channel weights through global pooling and bottleneck structure, and adaptively enhance and suppress feature channels to obtain recalibrated features; S8: Perform gated filtering and spatial weighting operations sequentially on the recalibrated features, and combine them with the entity basis features obtained by reconstruction and pooling from the initial embedding representation of the original first entity to perform position-level recalibration and residual fusion to obtain a refined feature map; S9: Map the refined feature map into a structure-aware feature vector, calculate the matching probability between the first entity and relation and the candidate second entity based on the vector, optimize the model parameters using the binary cross-entropy loss function, and determine the completed second entity based on the matching probability; Wherein, when the first entity is the head entity, the second entity is the tail entity; when the first entity is the tail entity, the second entity is the head entity.
2. The method according to claim 1, characterized in that, Step S1, which involves obtaining the initial embedding representation of the first entity and the initial embedding representation of the relation in the knowledge graph to be completed, specifically includes: Before model training begins, construct or load an entity embedding matrix. and a relation embedding matrix ,in This represents the total number of entities in the knowledge graph. Represents the total number of relations. As a preset embedding dimension, each row in the entity embedding matrix and the relation embedding matrix corresponds to a continuous vector representation of an entity or a relation, respectively; Upon receiving the query pair to be completed Afterwards, among them For the first entity, according to the first entity The identifier is retrieved from the entity embedding matrix to find the corresponding first identifier. Row vectors, serving as the initial embedding representation of the first entity. and according to the relationship The identifier is retrieved from the relation embedding matrix to find the corresponding first identifier. Row vectors, serving as the initial embedding representation of the relation. ; To improve the model's generalization ability during training and prevent overfitting, the initial embedding representation of the first entity is... Initial embedding representation of relations Before inputting into subsequent modules, both are subjected to random deactivation processing, which uses a preset discard probability. Randomly set some elements of the vector to zero, and retain the remaining elements proportionally. Scaling is performed to maintain its desired value; The initial embedding representations of the first entity and the initial embedding representations of the relation, after the random deactivation process, are then passed to the bidirectional multi-head cross-attention module in step S2 as two inputs to the module.
3. The method according to claim 1, characterized in that, Step S2, which involves calculating cross-attention using a bidirectional multi-head cross-attention mechanism, specifically includes: The bidirectional multi-head cross-attention calculation performed in step S2 is divided into two symmetrical attention calculation paths, denoted as the first entity to relation direction. and related to the direction of the first entity ; First entity to relation direction In this process, the initial embedded representation of the first entity after random deactivation in step S1 is used as the query input. The initial embedding representation of the relation after random deactivation in step S1 is used as the key input. Sum value input First, through three learnable linear mapping matrices... , , By performing linear projections on the query input, key input, and value input respectively, a query matrix is obtained. Key matrix Sum matrix Subsequently, the query matrix Key matrix Sum matrix Divide equally into the feature dimensions Each part corresponds to an attention head, such that each attention head... Obtain the corresponding query subspace matrix Key space matrix Sum subspace matrix The feature dimension of each attention head is Within each attention head, scaled dot product attention calculations are performed independently, i.e., the query subspace matrix is calculated first. With key space matrix Multiplying the transpose of matrices, then dividing the product by the scaling factor. Then, the attention weight matrix is obtained by normalization using the Softmax function, and then the attention weight matrix is compared with the value subspace matrix. Multiply to obtain the output of the attention head. The calculation formula is as follows: ; All The output vectors of each attention head are concatenated along the feature dimension to obtain a dimension of... The concatenated vectors are then processed by a learnable output mapping matrix. A linear transformation is performed on the concatenated vector to obtain the first entity-side augmented representation. ; In relation to the direction of the first entity In this process, the initial embedding representation of the relation after random deactivation in step S1 is used as the query input. The initial embedded representation of the first entity after random deactivation in step S1 is used as the key input. Sum value input The same operational process as the one from the first entity to the relation is adopted, using three learnable linear mapping matrices. , , Perform projection and divide into Each attention head performs scaled dot product attention computation, and the outputs of all heads are concatenated and mapped through an output mapping matrix. Perform a linear transformation to obtain the relation-side enhanced representation. .
4. The method according to claim 1, characterized in that, Step S3, which describes weighted fusion using learnable soft fusion weights, specifically includes: Step S3 employs a learnable soft fusion mechanism to adaptively balance the original semantic information and the interaction enhancement information. For the first entity side, the first entity is first embedded in the representation. and the first entity side enhancement representation The inputs are fed into a lightweight neural network consisting of a single fully connected layer. This single fully connected layer has two input nodes and two output nodes, and its output consists of two unnormalized raw fusion weights. and Subsequently, the original fusion weights were... and Applying Softmax normalization yields learnable soft fusion weights. and The calculation formula is as follows: , And satisfy Then, according to the formula The fused first entity representation is obtained by weighted summation of the initial embedded representation and the enhanced representation of the first entity. The weighted summation operation performs weighted fusion based on the feature vectors in the vector space; For the relation side, the same fusion process as the first entity side is adopted: the relation is initially embedded in the representation. and relational enhancement representation The input is fed into another lightweight neural network with the same structure, consisting of a single fully connected layer, to generate unnormalized raw fusion weights. and After Softmax normalization, the desired result is obtained. soft fusion weights and Then follow the formula The fusion relationship is obtained by performing a weighted summation. .
5. The method according to claim 1, characterized in that, Step S4 specifically includes: The first entity representation of the fusion is obtained in step S3. Relationship between fusion and integration Subsequently, to leverage the modeling capabilities of convolutional neural networks for local structural patterns, the one-dimensional vector representation needs to be reconstructed into a two-dimensional feature map format. First, the fused first entity representation is then... Relationship between fusion and integration Perform a dimension rearrangement operation, changing it from a length of... One-dimensional vector rearranged to a preset size A two-dimensional matrix, where and All are integers greater than 1, and satisfy the following conditions: The and The specific value is determined before model training based on the embedding dimension. The factorization is predetermined, when Timely After rearrangement, two-dimensional first entity feature maps are obtained respectively. and two-dimensional relational feature map To facilitate convolution operations, it can be further viewed as a two-dimensional tensor with a single channel. ; Considering the initial embedding representation of the original first entity The original first entity features still contain important basic semantic information. Step S4 jointly models the original first entity features and the first entity features enhanced by cross-attention in two-dimensional space; specifically, the initial embedding representation of the original first entity is... Reconstruct the preset size using the same dimensional rearrangement method as described above. Original entity two-dimensional feature map Then, the original entity's two-dimensional feature map is processed along the channel dimension. With the two-dimensional first entity feature map The two are concatenated. If both are considered as single-channel two-dimensional tensors, the concatenation results in a two-dimensional feature map of the entity to be convolved and fused with two channels. Then, channel compression and linear fusion are performed on the convolutional entity through pointwise convolution to obtain a single-channel fused entity two-dimensional feature map. The single-channel fused entity two-dimensional feature map is then passed to step S5 as the target feature map for the dynamic convolution operation; the relational two-dimensional feature map is passed to step S5 to generate the dynamic convolution kernel.
6. The method according to claim 1, characterized in that, Step S5 specifically includes: After obtaining the two-dimensional feature map of the entity to be convolutionally fused from the output of step S4. and two-dimensional relational feature map Then, step S5 executes a relation-aware dynamic overlapping convolution mechanism to explicitly introduce relational semantics into the feature refinement process; First, the two-dimensional relationship feature map Consider it as a space with dimensions of A two-dimensional matrix containing one channel; to generate dynamic convolution kernels, this two-dimensional relational feature map is... In the spatial dimension, the convolution kernel is divided into multiple local regions according to a preset kernel size, and each local region is a dynamically generated convolution kernel; The preset kernel size is the preset local window size. ,in The value is a positive integer smaller than the spatial size of the two-dimensional relation feature map, and the number of dynamic convolution kernels is equal to the number of sliding windows of the two-dimensional relation feature map in the spatial dimension; Subsequently, the dynamically generated convolutional kernel is applied to the two-dimensional feature map of the entity to be convolved and fused using an overlapping sliding method with a stride of 1. Convolution operations are performed on the above; since both the fused entity two-dimensional feature map and the relation two-dimensional feature map are single-channel feature maps, each dynamic convolution kernel corresponds to a size of The local region is used as a flattened vector in subsequent matching calculations; The specific process of convolution operation is as follows: the dynamically generated convolution kernel is matched with the corresponding local window in the two-dimensional feature map of the entity to be convolved and fused. At each sliding window position, the response value at that spatial position is obtained by calculating the similarity between the convolution kernel and the features within the corresponding window. By performing the above matching calculation on all possible spatial window positions, a multi-channel two-dimensional relation-aware feature map conditionalized by relational semantics is finally generated. The number of channels Equal to the number of the local regions; This dynamic convolution operation can be uniformly represented as: ,in This represents a relation-driven dynamic overlapping convolution operator; the convolution kernel parameters in this operator are entirely adaptively generated by relation features, enabling the model to dynamically adjust its feature selection strategy for different relation types.
7. The method according to claim 1, characterized in that, Step S6, which involves multi-scale feature extraction from the relation-aware feature map, specifically includes: Obtain the relation-aware feature map output in step S5. Then, in step S6, an Inception-style multi-branch, multi-scale feature transformation is applied to the relation-aware feature map. Parallel modeling includes the following steps: Construct a multi-branch parallel structure with four parallel branches: the first branch is The convolutional branch contains a convolutional kernel of size [size missing]. The first convolutional layer is used to capture local fine-grained patterns and linearly combine feature channels; the second branch is... The convolutional branch contains a convolutional kernel of size [size missing]. The convolutional layer has an effective receptive field of... The region is used to capture local contextual information at the mesoscale; the third branch is equivalent. Convolutional branches, through concatenating two The convolutional layer implementation is used to increase the receptive field while reducing computational complexity; the fourth branch is a max pooling branch, containing a pooling window with a size of... A max-pooling layer with a stride of 1, followed by a... Convolutional layers are used to smooth features and reduce dimensionality while preserving spatial structure information. The relation-aware feature map Simultaneously, the inputs are fed into the four branches mentioned above. Each branch performs forward computation independently, outputting a feature map with the same spatial size as the input feature map or the same size after appropriate padding. Then, the output feature maps from the four branches are concatenated along the channel dimension. That is, if each branch outputs... The feature maps of each channel are then concatenated to obtain a feature map with... The splicing feature map of each channel; To maintain the stability of the feature representation while incorporating multi-scale structural information, step S6 further integrates the spliced feature map with the relationship-aware feature map of the original input. Perform residual connections; if the number of channels in the spliced feature map is related to the perceptual feature map... If the number of channels is inconsistent, then first go through one Convolutional layers generate relation-aware feature maps The number of channels is adjusted to match the number of the stitched feature map, and then the two are added element-wise at their corresponding spatial positions and channels to obtain the multi-scale fused feature. This process can be formally represented as ,in This indicates the above multi-branch parallel transformation operation. This is a relational perception feature map after adjusting the number of channels.
8. The method according to claim 1, characterized in that, The channel attention recalibration described in step S7 specifically includes: After obtaining the multi-scale fusion features output in step S6 Afterwards, among them The number of channels in the feature map. and Representing spatial height and width, step S7 introduces a channel attention mechanism to adaptively recalibrate the multi-scale fused features: First, regarding the multi-scale fusion features Perform global average pooling in the spatial dimension, that is, for each channel Calculate all on this channel The arithmetic mean of the feature values of each spatial location yields a length of... Channel descriptor vector , of which element The channel descriptor vector aggregates global spatial information for each channel; Subsequently, the channel descriptor vector The input is fed into a bottleneck structure consisting of two fully connected layers to learn the nonlinear dependencies between channels; the first fully connected layer of the bottleneck structure receives the input dimension. Compress to a preset ratio smaller dimensions ,in The compression ratio is represented by an integer greater than 1; the output of this fully connected layer is then non-linearly transformed using the ReLU activation function to enhance the model's expressive power; next, a second fully connected layer reduces the dimension from... Restore to the original dimension Its output is normalized by the Sigmoid activation function, generating a channel activation weight vector with values ranging from (0,1). , of which element Indicates the first The importance weights of each feature channel; Then, the channel activation weight vector Combined with the original multi-scale fusion features Multiply channel by channel along the channel dimension, that is, for each channel The feature map of this channel The eigenvalue of each spatial location is multiplied by the corresponding channel weight. The weighted feature map is obtained. Finally, in order to preserve the original multi-scale structural information while enhancing feature discriminative power, the weighted feature maps are... Combined with original multi-scale features Perform residual join, that is, add element-wise at the corresponding spatial locations and channels to obtain the recalibration features. .
9. The method according to claim 1, characterized in that, Step S8 specifically includes: After obtaining the recalibration features output in step S7 Then, step S8 sequentially executes the two sub-steps of gating and spatial weighting; The gated screening sub-step specifically involves: first, processing the recalibrated features... Apply a convolution kernel with a size of The pointwise convolution operation does not change the spatial size of the feature map; it only performs a linear combination of channel information, and its output has the same spatial size as the input. and number of channels The output of the pointwise convolution is input into the Sigmoid activation function to generate a gating signal with a value between (0,1). ,in For the Sigmoid function, Indicates the Pointwise convolution operator; simultaneously, the recalibrated features Input to hyperbolic tangent activation function The features obtained after nonlinear activation are obtained. Its value ranges between (-1, 1), which can maintain the zero-centeredness of the feature and enhance the nonlinear expressive power; subsequently, the gating signal is... With the features after nonlinear activation Element-wise multiplication is performed at the corresponding spatial locations and channels to obtain the gated features. ,in This represents element-wise multiplication; the gating mechanism can adaptively suppress the eigenvalues of the weak response region and push them to zero according to the value of the gating signal while maintaining the nonlinear expressive power, and at the same time retain or enhance the eigenvalues of the strong response region, thereby effectively filtering redundant noise. The spatial weighting sub-step is specifically as follows: First, from the single-channel fused entity two-dimensional feature map described in step S4 In this process, entity basis features are obtained through global average pooling. The global average pooling operation will... The eigenvalues of a spatial region are aggregated into a single feature. A vector of channels, where The number of channels in the feature map before pooling is determined; for ease of subsequent operations, the entity basis features... Extended to the gating feature Feature maps with the same spatial dimensions; then, the gated features are... Features of the solid substrate The inputs are fed into the attention gating module to generate a spatial attention weight map, where each spatial location... weight value This indicates the importance of the location feature; subsequently, the spatial attention weight map is compared with the gating feature. Element-wise multiplication is performed at the corresponding spatial locations to weight the features of each channel. The weighted results are then aggregated along the channel dimension to obtain the spatial response features of a single channel. Above, the gated feature map Each spatial location eigenvalues multiplied by weights This yields a weighted gating feature map; Finally, a residual fusion strategy is employed to integrate the entity's base features. The weighted gated feature map and the linear mapping result of the original first entity embedding. Joint modeling is performed, which involves element-wise addition at corresponding spatial locations and channels to obtain the refined feature map. ,in The initial embedding representation of the original first entity is obtained through a learnable linear mapping layer. Mapped to Obtained with the same dimensions and spatial size.
10. The method according to claim 1, characterized in that, Step S9 specifically includes: After completing the multi-level feature refinement in step S8 and obtaining the refined feature map Afterwards, among them The number of channels in the feature map. and For spatial dimensions, step S9 involves three steps: feature projection, score calculation, and model optimization. The feature projection step specifically involves: first, projecting the refined feature map... Perform a flattening operation, that is, flatten the three-dimensional tensor Rearranged into a length of A one-dimensional vector is then input into a fully connected layer, the weight matrix of which is... The bias vector is ,in For the dimension of entity embedding, the flattened vector is linearly mapped to a dimension of through matrix multiplication and bias addition operations. The intermediate vector is then input into a batch normalization layer. This layer normalizes the intermediate vectors of multiple samples within the current training batch, making their mean 0 and variance 1, thereby stabilizing the training process and accelerating model convergence. Finally, the output of the batch normalization layer is input into a ReLU activation function for nonlinear transformation to obtain the structure-aware feature vector. This vector integrates all semantic and structural information from cross-attention alignment and dynamic convolution to multi-level feature refinement; The scoring calculation process employs a 1-N training strategy, modeling knowledge graph link prediction as a multi-label classification problem. Specifically, in each forward propagation, for a given query pair... ,in As the first entity, the model obtains the structure-aware feature vector. Then, the vector and the entity embedding matrix are calculated through a single matrix multiplication. The dot product similarity of the transposes of the given values yields a value of length . The original score vector, where the first... Each element represents a query pair. With candidate second entity The original matching score is then calculated; subsequently, the original score vector is multiplied by a learnable scaling parameter. and with a learnable bias term. Add, where the scale parameter During model training, the values are automatically adjusted via backpropagation, and their range is constrained between [5, 15] to maintain a reasonable dynamic range for the score distribution. Then, the score vector after scaling and bias adjustment is input into the Sigmoid function, which maps each score value to a matching probability in the (0, 1) interval, resulting in a matching probability vector. ,in For the Sigmoid function; The model optimization step employs a binary cross-entropy loss function to optimize the model parameters, formalizing the link prediction task into a multi-label binary classification problem; specifically, for a training sample... ,in For a real second entity, its target label is a string of length. binary vector Only the corresponding real second entity The position of the target label is set to 1, and the rest are set to 0; to improve the generalization ability of the model and prevent overfitting, label smoothing is applied to the target label, that is, the target value of the true second entity position is adjusted from 1 to 0. At the same time, adjust the target values at other locations from 0 to The smoothing coefficient The value is set to 0.1; then, the matching probability vector is calculated. The binary cross-entropy loss between the target label vector and the smoothed target label vector is defined as follows: ; in The target label value after smoothing. Candidate second entities predicted by the model The matching probability; the model uses the Adam optimizer, calculates the gradient based on the loss function and updates all learnable parameters through backpropagation until the loss converges; After the model training is complete, for any given query pair to be completed ,in Given the first known entity, the matching probability vector is obtained through the forward computation process from steps S1 to S9. And select the candidate second entity with the highest matching probability value as the target for this query. The completion results are output to complete the missing entities in the knowledge graph to be completed; Wherein, when the first entity is the head entity, the second entity is the tail entity, and the query pair This corresponds to the scenario where the head entity completes the tail entity; when the first entity is the tail entity, the second entity is the head entity, and the query pair... This corresponds to the scenario where the tail entity completes the head entity.