Knowledge graph completion method and system based on dynamic complex rotation attention

By employing a dynamic complex rotation attention method, the problem of directional sensitivity to symmetry, antisymmetry, and local relationships in knowledge graph completion is solved, achieving higher accuracy and better generalization in knowledge graph completion.

CN121328670APending Publication Date: 2026-01-13GUANGDONG PHARMA UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511344037.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-09-19
Publication Date
2026-01-13

AI Technical Summary

Technical Problem

Existing knowledge graph completion methods lack explicit directional sensitivity when dealing with symmetric, antisymmetric, and local relationships, leading to errors in completion results, especially in scenarios with sparse or zero-sample data where performance is limited.

Method used

We employ a dynamic complex rotation attention approach, which dynamically generates rotation angles to perform complex rotations on entity embeddings. Combined with a multi-head attention mechanism, this approach captures the semantic and structural information of the knowledge graph, achieving consistency of symmetric relationships, directional differentiation of antisymmetric relationships, and dynamic boundary setting of local relationships.

Benefits of technology

It significantly improves the accuracy and generalization ability of knowledge graph completion, especially maintaining high-precision completion results in scenarios with sparse data or zero samples.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121328670A_ABST
    Figure CN121328670A_ABST
Patent Text Reader

Abstract

The invention discloses a knowledge graph completion method and system based on dynamic complex rotation attention, and the method comprises the steps: building an original message vector based on an entity embedding vector and a relation embedding vector, and carrying out the projection, and obtaining a query vector, a key vector and a value vector; performing feature extraction on the entity embedding vector and the relation embedding vector, and performing complex rotation operation on the query vector and the key vector based on a dynamic complex rotation mechanism to obtain a rotated query vector and a rotated key vector; and determining an attention weight coefficient according to the rotated query vector and the rotated key vector, aggregating value vectors, updating an entity embedding vector, and outputting an inter-entity relationship prediction result. According to the method, semantic information and structural information in the knowledge graph can be better captured. The knowledge graph completion method and system based on the dynamic complex rotation attention can be widely applied to the technical field of knowledge graph completion.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of knowledge graph completion technology, and in particular to a knowledge graph completion method and system based on dynamic complex rotational attention. Background Technology

[0002] Knowledge graphs (KGs), as an important form of structured knowledge representation, provide strong support for numerous knowledge-driven tasks. However, the incompleteness of KGs limits their effectiveness in artificial intelligence tasks such as intelligent question answering and information extraction. Knowledge graph completion (KGC) technology has emerged to address this, aiming to predict and supplement missing entities and relationships in KGs, improving their quality and coverage. Based on the information sources and technical approaches used, KGC methods can be mainly categorized as follows: methods based on knowledge graph embedding, graph neural networks, transformer methods based on attention mechanisms, and methods based on complex embeddings and rotations.

[0003] Knowledge graph embedding methods, represented by TransE, TransH, and TransR, capture entity-relation semantics through geometric distance metrics. However, they lack explicit consistency constraints when handling symmetric relations (such as "competing in the same field"), potentially leading to inconsistencies in bidirectional representations. For antisymmetric relations (such as "defeated / defeated"), the base model TransE cannot explicitly distinguish direction, while TransH / TransR partially alleviates the direction confusion problem through projection mechanisms, but still has limitations. Model performance generally degrades significantly with sparse data. The subsequent RESCAL model enhanced expressive power but suffers from parameter inflation and computational costs due to high-order tensor decomposition. These traditional static embeddings cannot dynamically adapt to local contexts after training (e.g., "opponents in the same group" only applies to specific events), limiting their applicability.

[0004] The development of graph neural networks has brought new opportunities to knowledge graphs. Graph neural networks (such as GCN and GAT) update node representations by aggregating neighbor information, but their undirected or weakly directed aggregation mechanisms may exacerbate representation inconsistencies in symmetric relationships. RGCN introduces a relationship-specific matrix to improve aggregation, assigning independent parameters to inverse relationships (such as "defeated") to distinguish directions, but the increased number of parameters may affect efficiency. Compared to rotation embedding, RGCN's parameterization method has less flexibility in accurately defining inverse semantics. Furthermore, the neighbor aggregation mechanism of GNNs lacks explicit local boundary control, which may introduce cross-group noise in the relationship "opponents in the same group," leading to prediction bias.

[0005] Introducing attention mechanisms into knowledge graphs has become a research hotspot in recent years. Attention mechanisms (such as self-attention and relational attention) focus on key information through dynamic weight calculation, but they lack built-in mechanisms to ensure the consistency of bidirectional representations of symmetrical relations, and it is also difficult to explicitly encode directional semantics (such as distinguishing between "defeated" and "defeated") through attention weights. At the same time, the calculation of dynamic weights may not be able to fully capture the contextual boundaries of local relations (such as the effective range of "opponents in the same group"), which can easily lead to irrelevant entities being mistakenly focused on, especially in scenarios with few samples.

[0006] Furthermore, complex embeddings and rotation models offer new perspectives. Complex embeddings (ComplEx) and rotation models (RotatE) utilize the properties of complex space to model symmetric / antisymmetric relationships: the rotation angle is learned through training (not fixed), but as a static embedding, it cannot dynamically adjust the phase during inference based on the specific context (such as the competition in which "opponents in the same group" are located). While a fixed module length design helps stabilize training, it may limit the flexibility of representation under sparse data, affecting the consistency of symmetric relationships and the ability to discriminate the direction of antisymmetric relationships, thus limiting performance in dynamic contexts. Summary of the Invention

[0007] To address the aforementioned technical problems, the present invention aims to provide a knowledge graph completion method and system based on dynamic complex rotational attention, which can better capture semantic and structural information in the knowledge graph.

[0008] The first technical solution adopted in this invention is: a knowledge graph completion method based on dynamic complex rotational attention, comprising the following steps: Based on entity embedding vectors and relation embedding vectors, the original message vector is constructed and projected to obtain query vector, key vector and value vector; Feature extraction is performed on entity embedding vectors and relation embedding vectors, and based on a dynamic complex rotation mechanism, complex rotation operation is performed on query vectors and key vectors to obtain rotated query vectors and rotated key vectors. The attention weight coefficients are determined based on the rotated query vector and the rotated key vector, the value vectors are aggregated, the entity embedding vectors are updated, and the prediction results of the relationships between entities are output.

[0009] Furthermore, the step of constructing the original message vector and projecting it based on the entity embedding vector and relation embedding vector to obtain the query vector, key vector, and value vector specifically includes: Based on the input entity embedding vector, the head entity embedding vector and the tail entity embedding vector are extracted by indexing. The relation embedding vector is obtained by extracting from the relation embedding matrix. The head entity embedding vector, tail entity embedding vector, and relation embedding vector are concatenated in the last dimension to construct the original message vector; The original message vector is projected using a linear layer to obtain the query vector, key vector, and value vector.

[0010] Furthermore, the step of extracting features from the entity embedding vector and relation embedding vector, and performing a complex rotation operation on the query vector and key vector based on a dynamic complex rotation mechanism to obtain the rotated query vector and the rotated key vector, specifically includes: The global average value of the entity embedding vector and the relation embedding vector is calculated to obtain the global features of the input entity embedding and relation embedding. Local interactive computation is performed on the entity embedding vector and the relation embedding vector to obtain the local features of the input entity embedding and relation embedding; The local features are summed and averaged, and then the global features and the processed local features are fused to obtain the feature fused vector. The feature-fused vector is input into the angle generation network to generate the rotation angle. After passing through the sigmoid activation function and scaling operation, the dynamic rotation angles corresponding to the query vector and the key vector are obtained. Based on the dynamic rotation angles corresponding to the query vector and the key vector, a complex rotation operation is performed on the query vector and the key vector to obtain the rotated query vector and the rotated key vector.

[0011] Furthermore, the specific expression for generating the dynamic rotation angle is as follows: ; ; ; ; ; ; In the above formula, , , These are the head entity embedding vector, relation embedding vector, and tail entity embedding vector, respectively. Represents the angle generation network, Represents global features. Indicates local features, , Indicates the rotation angle. , This represents the dynamic rotation angle between the query vector and the key vector. Indicates the number of entities. Indicates the index, used to traverse all One entity, Indicates by and A vector obtained by splicing two features.

[0012] Furthermore, the step of performing a complex rotation operation on the query vector and key vector based on the dynamic rotation angles corresponding to the query vector and key vector to obtain the rotated query vector and key vector specifically includes: Represent the query vector and key vector as complex numbers, and obtain the real and imaginary parts of the query vector and key vector respectively; Based on the dynamic rotation angles corresponding to the query vector and the key vector, the real and imaginary parts corresponding to the query vector and the key vector are rotated respectively to obtain the real and imaginary parts corresponding to the rotated query vector and the rotated key vector. Add the real and imaginary parts of the rotated query vector and the rotated key vector respectively to obtain the rotated query vector and the rotated key vector.

[0013] Furthermore, the expression for the complex number rotation operation is as follows: ; ; ; ; In the above formula, and Let them represent the real and imaginary parts of a complex number, respectively. The entity embeddings representing the inputs for model training. , This represents the real and imaginary parts of a vector that has undergone a complex rotation in a two-dimensional plane. This represents a rotated vector formed by concatenating the real and imaginary parts of the vector.

[0014] Furthermore, the step of determining the attention weight coefficients based on the rotated query vector and the rotated key vector, aggregating the value vectors, updating the entity embedding vectors, and outputting the entity relationship prediction results specifically includes: The similarity between the rotated query vector and the rotated key vector is calculated, and the calculation results are normalized to obtain the attention weight coefficient. Based on the attention weight coefficient, the value vector is weighted and summed, and then concatenated with the rotated query vector and the rotated key vector to obtain the aggregated entity embedding vector; The aggregated entity embedding vector is rejoined with the original message vector and then subjected to layer normalization to obtain the updated entity embedding vector. The updated entity embedding vectors are input into the scoring function to obtain the prediction results of the relationships between entities.

[0015] The second technical solution adopted in this invention is: a knowledge graph completion system based on dynamic complex rotational attention, comprising: The first module is used to construct the original message vector and project it based on the entity embedding vector and the relation embedding vector to obtain the query vector, key vector and value vector; The second module is used to extract features from entity embedding vectors and relation embedding vectors, and to perform complex rotation operations on query vectors and key vectors based on a dynamic complex rotation mechanism to obtain rotated query vectors and rotated key vectors. The third module is used to determine the attention weight coefficients based on the rotated query vector and the rotated key vector, aggregate the value vectors, update the entity embedding vectors, and output the prediction results of the relationships between entities.

[0016] The beneficial effects of the method and system of this invention are as follows: This invention constructs an original message vector based on entity embedding vectors and relation embedding vectors, projects it to obtain query vectors, key vectors, and value vectors, further extracts features from the entity embedding vectors and relation embedding vectors, and performs complex rotation operations on the query vectors and key vectors based on a dynamic complex rotation mechanism to obtain rotated query vectors and rotated key vectors. The global path first aggregates the mean of query-key-value pairs to capture the macroscopic symmetric / antisymmetric tendencies of relationships; the local path extracts fine-grained interaction features of the current context and fuses the two paths of information with learnable weights. After nonlinear mapping, the rotation angle of each attention head is generated in real time. This angle forms a continuous phase difference in the complex space, which can simultaneously satisfy the consistency constraint of symmetric relationships and the direction distinction of antisymmetric relationships. Finally, the attention weight coefficients are determined based on the rotated query vectors and rotated key vectors, and the value vectors are aggregated to update the entity embedding vectors, outputting the prediction results of relationships between entities. The message passing module combined with the dynamic complex rotation mechanism can better capture the semantic and structural information in the knowledge graph. Attached Figure Description

[0017] Figure 1 This is a flowchart of the steps of a knowledge graph completion method based on dynamic complex rotational attention according to the present invention; Figure 2 This is a structural block diagram of a knowledge graph completion system based on dynamic complex rotational attention according to the present invention; Figure 3 This is a schematic diagram of the knowledge graph completion process provided in a specific embodiment of the present invention; Figure 4 This is a schematic diagram of the dynamic angle generation process provided in a specific embodiment of the present invention; Figure 5 This is a flowchart illustrating the dynamic complex number rotation operation provided in a specific embodiment of the present invention. Detailed Implementation

[0018] The present invention will now be described in further detail with reference to the accompanying drawings and specific embodiments. The step numbers in the following embodiments are only for ease of explanation and do not limit the order of the steps. The execution order of each step in the embodiments can be adapted according to the understanding of those skilled in the art.

[0019] First, it's important to note that real-world knowledge graphs commonly suffer from entity omissions. This stems primarily from the limitations of the information sources themselves: web pages, academic papers, databases, and even crowdsourced data cannot exhaustively represent all objects in the real world. Newly emerging niche concepts, marginal figures, or unexpected events are often difficult to cover by mainstream corpora. Furthermore, extraction algorithms are prone to missing important information when dealing with ambiguous text, metaphorical expressions, or technical terms. The dynamic evolution of the real world also means that entities "emerging today" may not be detected by the system until tomorrow. Simultaneously, to reduce complexity, modelers often intentionally ignore low-frequency or time-sensitive instances. These factors collectively result in knowledge graphs only presenting a partial, rather than complete, picture of the real world. While knowledge graph completion technologies have achieved some success in addressing this issue, they still have unresolved shortcomings.

[0020] Currently, graph neural networks and attention mechanisms have performed well in knowledge graph completion tasks, uncovering latent patterns and connections within knowledge graphs and providing strong support for predicting missing entities and relationships. However, in-depth analysis reveals that most of these methods neglect the directional sensitivity of knowledge graphs, while real-world knowledge graph relationships generally exhibit characteristics such as symmetry, antisymmetry, and local relationships, which undoubtedly limits further improvements in completion performance.

[0021] In a knowledge graph for a particular year's European Championship, entities represent national teams, while edges depict interactions between them with clear directional semantics: the symmetrical "playing together" connection links France and Germany bidirectionally, because regardless of who plays at home, both teams will inevitably be on the same pitch simultaneously; the antisymmetric "victory" connection only allows a one-way edge from Spain to Croatia to hold true; if the model incorrectly adds a reverse edge from Croatia to Spain, it will immediately contradict the true result of the match; and the "opponents in the same group" connection is only valid and symmetrical in the group stage—Portugal and Turkey are opponents in Group F—but this relationship automatically becomes invalid in the knockout stage. If the model ignores this temporal-spatial locality, it might misclassify the final match between Portugal and France as "opponents in the same group." Therefore, only by explicitly distinguishing the directional sensitivity of symmetrical, antisymmetric, and local relationships can knowledge graph completion avoid making mistakes in the win-loss and grouping logic of the football world.

[0022] Knowledge graphs (KGs), which condense human knowledge in a structured way, have become an indispensable foundation for AI applications such as intelligent question answering and information extraction. However, missing facts, like "sentence breaks," greatly limit their usability. Therefore, knowledge graph completion (KGC) technology is highly anticipated—it aims to accurately "fill in the gaps" in known entity and relation networks, completing those triples that have not yet appeared explicitly, thereby improving the completeness and coverage of the graph. Unfortunately, current mainstream methods often treat relations as undirected and unbounded "universal connectors," ignoring the directional sensitivity that is prevalent in real-world graphs: some relations are inherently symmetrical (e.g., "competing in the same arena"), some are strictly antisymmetric (e.g., "defeated / defeated"), and others are only valid in specific contexts or time periods (e.g., "opponents in the same group"). If these directional characteristics are ignored, the completion results can easily go astray, or even contradict the facts.

[0023] Based on this, this invention proposes a knowledge graph reasoning framework of "dynamic complex rotational attention". Unlike static rotation angles, this framework embeds a learnable phase controller within the multi-head attention: the global path first aggregates the query-key-value mean to capture the macroscopic symmetric / antisymmetric tendency of the relationship; the local path extracts fine-grained interaction features of the current context (such as a group stage match of a World Cup) and fuses the two information paths with learnable weights, generating the rotation angle of each attention head in real time after nonlinear mapping. This angle forms a continuous phase difference in the complex space, which can simultaneously satisfy the consistency constraint of symmetric relationships, the direction distinction of antisymmetric relationships, and the dynamic boundary setting of local relationships such as "opponents in the same group", thus maintaining high accuracy in completion and generalization capabilities even in scenarios with sparse data or zero samples. The RotaryFormer model is based on a graph neural network (GNN) architecture, using entity embeddings and relation embeddings as inputs, and performs information transmission and aggregation through a multi-head parallel neural network structure, finally outputting an updated entity embedding representation. The core of the model lies in the message passing module that incorporates a dynamic complex rotation mechanism, which can better capture semantic and structural information in the knowledge graph.

[0024] Reference Figure 1 This invention provides a knowledge graph completion method based on dynamic complex rotational attention, which includes the following steps: S100. Based on entity embedding vector and relation embedding vector, construct the original message vector and project it to obtain query vector, key vector and value vector; Specifically, the head entity embedding vector and the tail entity embedding vector are extracted based on the input entity embedding vector through indexing; the relation embedding vector is extracted based on the relation embedding matrix; the head entity embedding vector, the tail entity embedding vector and the relation embedding vector are concatenated on the last dimension to construct the original message vector; the original message vector is projected based on the linear layer to obtain the query vector, the key vector and the value vector.

[0025] In this embodiment, RotaryFormer employs a multi-head parallel mechanism, processing the input entity embeddings and relation embeddings through multiple parallel neural network heads. Each head has independent parameters, enabling it to capture the features of entities and relations from different perspectives. This multi-head parallel approach enhances the model's expressive power, allowing it to better handle the complex and diverse relationships within knowledge graphs.

[0026] The message is constructed based on the embedding information of the head entity, relation, and tail entity. The model concatenates the head entity embedding, relation embedding, and tail entity embedding to form a message vector. Then, a multilayer perceptron (MLP) is used to transform the message vector to obtain the final message representation, which is expressed as: ; ; Among them, embedding the head entity Relational embedding Tail-end entity embedding The data is concatenated to form a message vector, which is then passed through a multi-head projection layer. Explicitly transform the message vector. Then segment the transformed message vector into query vectors. Key vector Sum value vector .

[0027] S200. Extract features from entity embedding vectors and relation embedding vectors, and perform complex rotation operations on query vectors and key vectors based on dynamic complex rotation mechanism to obtain rotated query vectors and rotated key vectors. Specifically, a global average is calculated on the entity embedding vector and the relation embedding vector to obtain the global features of the input entity embedding and relation embedding; local interactive calculations are performed on the entity embedding vector and the relation embedding vector to obtain the local features of the input entity embedding and relation embedding; the local features are summed and averaged, and then the global features and the processed local features are fused to obtain the feature-fused vector; the feature-fused vector is input into the angle generation network to generate rotation angles, which are then processed by the sigmoid activation function and scaling operation to obtain the dynamic rotation angles corresponding to the query vector and the key vector; based on the dynamic rotation angles corresponding to the query vector and the key vector, a complex rotation operation is performed on the query vector and the key vector to obtain the rotated query vector and the rotated key vector.

[0028] Specifically, the query vector and key vector are represented as complex numbers, and their real and imaginary parts are obtained respectively. Based on the dynamic rotation angles of the query vector and key vector, their real and imaginary parts are rotated respectively to obtain the real and imaginary parts of the rotated query vector and key vector. The real and imaginary parts of the rotated query vector and key vector are then added together to obtain the rotated query vector and key vector.

[0029] In this embodiment, the dynamic complex rotation mechanism is one of the core innovations of the RotaryFormer model. This mechanism performs complex rotation operations on entity embeddings by dynamically generating rotation angles. Specifically, the model dynamically generates a set of rotation angles based on the embedding information of the input head entity, relation, and tail entity. Then, it uses these angles to perform complex rotations on the entity embeddings, enabling the entity embeddings to better represent their semantic and structural information in complex space.

[0030] The rotation angle is generated based on the idea of ​​multi-granularity feature fusion. The model first extracts global and local features from the input entity embeddings and relation embeddings, then fuses these features and generates the rotation angle through a neural network. Global features are obtained by calculating the global average of the entity embeddings and relation embeddings, while local features are obtained by calculating the local interactions between the entity embeddings and relation embeddings, expressed as: ; ; ; ; ; ; in, , , These are head entity embedding, relation embedding, and tail entity embedding, respectively. Their dimensions are all [missing information - likely a dimensionality]. ,in Represents batch size. Indicates the number of entities. For embedded dimensions, This represents an angle generation network, a neural network containing linear layers and layer normalization. Global features. Extraction is achieved by calculating the global average of entity embeddings and relation embeddings, while local features are obtained by calculating the local interactions between entity embeddings and relation embeddings. These local interaction features are then summed and averaged, and finally, the global and local features are fused. The resulting vector is input into an angle generation network (a neural network containing linear layers and layer normalization) to generate the rotation angle. After applying the sigmoid activation function and scaling, the final output dynamic rotation angle is obtained. and .

[0031] Complex rotation operations involve rotating entities embedded within a complex plane. The model represents entity embeddings as complex numbers and then rotates them using dynamically generated rotation angles. In this way, the model can encode and transform the semantic information of entities in complex space, thereby better capturing the complex relationships between entities. Its expression is: ; ; ; ; in, and These represent the real and imaginary parts of a complex number, respectively, obtained through entity embedding segmentation. The rotation angle is dynamically generated. The solid embedding is rotated, and the real and imaginary parts of the rotated complex number are added together to obtain the rotated solid embedding.

[0032] S300. Determine the attention weight coefficients based on the rotated query vector and the rotated key vector, aggregate the value vectors, update the entity embedding vectors, and output the prediction results of the relationships between entities.

[0033] Specifically, the similarity between the rotated query vector and the rotated key vector is calculated, and the result is normalized to obtain the attention weight coefficient. Based on the attention weight coefficient, the value vector is weighted and summed, and then concatenated with the rotated query vector and the rotated key vector to obtain the aggregated entity embedding vector. The aggregated entity embedding vector is then joined with the original message vector using a residual connection and layer normalization to obtain the updated entity embedding vector. Finally, the updated entity embedding vector is input into the scoring function to obtain the entity relationship prediction result.

[0034] In this embodiment, the RotaryFormer model employs an attention-based message passing mechanism. During message passing, each entity receives messages from neighboring entities based on its relationship with them. The model calculates attention weights to weight the importance of different messages, then aggregates the weighted messages to update the entity's embedding representation.

[0035] The attention mechanism is used to calculate message weights. The model obtains an attention score by calculating the similarity between the head entity embedding and the tail entity embedding. Then, the attention score is normalized using a softmax function to obtain the attention weights. These weights reflect the importance of different messages to the receiving entity, and their expression is as follows: ; in, and They are vector, A vector that has undergone a complex rotation, This is the dimension of each attention head, which is set here to the embedding dimension D / / num_heads.

[0036] In the message aggregation stage, the model performs matrix transformations on the messages based on attention weights to obtain aggregated message representations. Then, the aggregated messages are subjected to ReLU activation, dropout regularization, and bias correction to update the entity embeddings. This entire process achieves non-linear feature recombination and regularization, enhancing the model's expressive power. Its expression is as follows: ; in, It refers to the batch size. It is the sequence length. It is the size of the hidden layer; and yes The shape weight matrix, and It is a dimension of The bias vector. The attention score. With weight matrix and bias A linear transformation is performed, followed by the ReLU activation function (resetting all negative values ​​to zero), then Dropout regularization (randomly zeroing some neurons with probability p=drop and scaling the remaining values), and finally, the second set of weights is applied. and bias A further linear transformation is performed, resulting in a feature representation with the same dimension as the input, yielding the final message vector. This entire process achieves non-linear recombination and regularization of features, enhancing the model's expressive power.

[0037] To mitigate the vanishing and exploding gradient problems in deep neural networks, the RotaryFormer model adds residual connections after each message passing module. These residual connections allow the input to skip intermediate neural network layers and be added directly to the output, thus enabling the model to more efficiently pass information and propagate gradients.

[0038] Furthermore, the model employs layer normalization to standardize entity embeddings. Layer normalization stabilizes the model's training process, accelerates convergence, and improves performance. Its expression is: ; in, It is the original entity embedding, which will be processed The aggregated message is used as a residual and After addition and layer normalization, the updated entity embedding is obtained. .

[0039] Finally, the embodiments of the present invention will be described in conjunction with the accompanying drawings: like Figure 3 As shown, firstly, the head entity embedding `src_emb` and the tail entity embedding `dst_emb` are extracted from the input entity embedding `x` using indices `src` and `dst`, respectively. Then, the relation embedding `rel_emb` is extracted from the relation embedding matrix `rel_embed` based on `edge_type`. Next, these three embedding vectors are concatenated along the last dimension to construct a raw message vector that integrates all three. Finally, a linear layer `Wqkv` is used to project this message vector, generating a query vector `Q`, a key vector `K`, and a value vector `V`.

[0040] Furthermore, global and local features are extracted and concatenated through interactive head entity embedding, tail entity embedding, and relation embedding. After transformation, the dynamic angles corresponding to the query vector and key vector are obtained. Complex rotation operations are then performed on the query vector and key vector based on these two dynamic angles to generate a rotated vector, which is then concatenated with the reshaped value vector. Finally, after regularization and the action of the FFN module, the result is added to the original entity embedding to obtain the updated message vector, which is then scored using a scoring function.

[0041] like Figure 4 As shown, the head entity embedding, tail entity embedding, and relation embedding are multiplied to obtain local features. Simultaneously, a weighted average of these three embeddings is performed to extract global features. Subsequently, the global and local features are concatenated, and the concatenated features are input into a fully connected layer for projection transformation. Finally, after processing by an activation function and multiplying by 2π, the dynamic angles corresponding to the query vector and key vector are obtained. .

[0042] for Figure 3 The obtained dynamic angle Sine and cosine processing is performed. Then, the real and imaginary parts of the query vector obtained after the unbind operation are cross-multiplied with the processed angle, and then added or subtracted. The specific formula is as follows: real part × cos - Imaginary part × sin Real part × sin + Imaginary part × cos Next, the results are concatenated to form the real and imaginary parts of the rotated query vector, and then further concatenated to obtain the complete rotated query vector. The same operation is performed on the key vector to obtain the rotated key vector.

[0043] Finally, it should also be noted that: FB15K-237, WN18RR, and NELL-995 are commonly used datasets in the knowledge graph field, each with its own characteristics. FB15K-237, from the Freebase knowledge base, contains 14,541 entities, 237 relations, and approximately 270,000 triples. It is an improved version of FB15K, removing inverse relations, making it more challenging and suitable for knowledge graph completion tasks. WN18RR, derived from the WordNet dictionary, contains 40,943 entities, 11 relations, and approximately 90,000 triples. It is an improved version of WN18, solving the problem of overlap between the test and training sets, making it suitable for evaluating the performance of knowledge graph inference models. NELL-995, extracted from the NELL knowledge base, contains 74,536 entities, 200 relations, and approximately 150,000 triples. It aims to support relation prediction tasks; its relations have a hierarchical structure, reflecting the complex association patterns of knowledge graphs.

[0044] To meet the evaluation needs of knowledge graph embedding models in inductive learning scenarios, Ten et al. generated inductive versions of these datasets in 2020. The inductive versions of FB15K-237 and WN18RR feature disjoint entity sets between the training and test sets, used to evaluate the model's generalization ability to unseen entities. Their v1 to v4 versions differ in the number of entities and relations, graph attributes, and difficulty levels. The inductive version of NELL-995 involves not only unseen entities but also unseen relations, and its v1 to v4 versions also differ in data size and complexity. These inductive datasets provide evaluation scenarios with different difficulty levels for the models, testing their reasoning ability on unseen entities or relations.

[0045] This invention achieves direct and inevitable technical benefits in knowledge graph completion tasks through a dynamic complex rotation attention mechanism. Its core lies in a learnable phase controller embedded within multi-head attention. This controller aggregates macroscopic features of entity-relationship interactions via global paths and extracts fine-grained semantics from specific triple contexts via local paths. It dynamically generates adaptive rotation phase differences in complex space, thereby accurately modeling cross-scene relational semantics and significantly improving zero-shot generalization capabilities.

[0046] In traditional transduction scenarios (FB15K-237 / WN18RR / NELL-995 standard datasets), this mechanism strictly satisfies the 180° rotation constraint for symmetric relations (such as _hypernym in WN18RR), accurately distinguishes the asymmetric rotation direction for antisymmetric relations (such as / film / film_directed_by in FB15K-237), and dynamically constrains the local rotation boundaries for context-sensitive relations (such as teamplaysinleague(event, league) in NELL-995). These direct mechanisms inevitably lead to significantly better performance on standard datasets in terms of Hits@10 and MRR, especially in static rotation models (such as RotatE), where the MRR is improved by ≥10%, and by 5% in some attention-based methods.

[0047] In strictly inductive scenarios (versions 1-4 of FB15K-237-ind / WN18RR-ind / NELL-995-ind), context-aware rotation angles are generated to generalize the semantic roles of unseen entities (FB15K-237-ind / WN18RR-ind), and zero-shot relation prediction is achieved by inferring rotation patterns for unseen relations (NELL-995-ind) through global-local path fusion. These direct mechanisms inevitably lead to significantly better Hits@10 and MRR metrics than other models on the standard test set and all inductive versions (v1-v4), especially in the high-difficulty versions v3 / v4 where entities / relations are not visible, where the Hits@10 metric is improved by ≥7%.

[0048] Reference Figure 2 A knowledge graph completion system based on dynamic complex rotational attention, comprising: The first module 201 is used to construct the original message vector and project it based on the entity embedding vector and the relation embedding vector to obtain the query vector, key vector and value vector. The second module 202 is used to extract features from the entity embedding vector and the relation embedding vector, and to perform complex rotation operation on the query vector and the key vector based on the dynamic complex rotation mechanism to obtain the rotated query vector and the rotated key vector. The third module 203 is used to determine the attention weight coefficients based on the rotated query vector and the rotated key vector, aggregate the value vectors, update the entity embedding vectors, and output the prediction results of the relationships between entities.

[0049] The content of the above method embodiments is applicable to this system embodiment. The specific functions implemented in this system embodiment are the same as those in the above method embodiments, and the beneficial effects achieved are also the same as those achieved in the above method embodiments.

[0050] The above is a detailed description of the preferred embodiments of the present invention. However, the present invention is not limited to the embodiments described. Those skilled in the art can make various equivalent modifications or substitutions without departing from the spirit of the present invention. All such equivalent modifications or substitutions are included within the scope defined by the claims of this application.

Claims

1. A knowledge graph completion method based on dynamic complex rotational attention, characterized in that, Includes the following steps: Based on entity embedding vectors and relation embedding vectors, the original message vector is constructed and projected to obtain query vector, key vector and value vector; Feature extraction is performed on entity embedding vectors and relation embedding vectors, and based on a dynamic complex rotation mechanism, complex rotation operation is performed on query vectors and key vectors to obtain rotated query vectors and rotated key vectors. The attention weight coefficients are determined based on the rotated query vector and the rotated key vector, the value vectors are aggregated, the entity embedding vectors are updated, and the prediction results of the relationships between entities are output.

2. The knowledge graph completion method based on dynamic complex rotational attention as described in claim 1, characterized in that, The step of constructing the original message vector and projecting it based on the entity embedding vector and relation embedding vector to obtain the query vector, key vector, and value vector specifically includes: Based on the input entity embedding vector, the head entity embedding vector and the tail entity embedding vector are extracted by indexing. The relation embedding vector is obtained by extracting from the relation embedding matrix. The head entity embedding vector, tail entity embedding vector, and relation embedding vector are concatenated in the last dimension to construct the original message vector; The original message vector is projected using a linear layer to obtain the query vector, key vector, and value vector.

3. The knowledge graph completion method based on dynamic complex rotational attention as described in claim 2, characterized in that, The step of extracting features from entity embedding vectors and relation embedding vectors, and performing complex rotation operations on query vectors and key vectors based on a dynamic complex rotation mechanism to obtain rotated query vectors and key vectors, specifically includes: The global average value of the entity embedding vector and the relation embedding vector is calculated to obtain the global features of the input entity embedding and relation embedding. Local interactive computation is performed on the entity embedding vector and the relation embedding vector to obtain the local features of the input entity embedding and relation embedding; The local features are summed and averaged, and then the global features and the processed local features are fused to obtain the feature fused vector. The feature-fused vector is input into the angle generation network to generate the rotation angle. After passing through the sigmoid activation function and scaling operation, the dynamic rotation angles corresponding to the query vector and the key vector are obtained. Based on the dynamic rotation angles corresponding to the query vector and the key vector, a complex rotation operation is performed on the query vector and the key vector to obtain the rotated query vector and the rotated key vector.

4. The knowledge graph completion method based on dynamic complex rotational attention as described in claim 3, characterized in that, The specific expression for generating the dynamic rotation angle is as follows: ; ; ; ; ; ; In the above formula, , , These are the head entity embedding vector, relation embedding vector, and tail entity embedding vector, respectively. Represents the angle generation network, Represents global features. Indicates local features, , Indicates the rotation angle. , This represents the dynamic rotation angle between the query vector and the key vector. Indicates the number of entities. Indicates the index, used to traverse all One entity, Indicates by and A vector obtained by splicing two features.

5. The knowledge graph completion method based on dynamic complex rotational attention according to claim 4, characterized in that, The step of performing a complex rotation operation on the query vector and key vector based on the dynamic rotation angles corresponding to the query vector and key vector to obtain the rotated query vector and key vector specifically includes: Represent the query vector and key vector as complex numbers, and obtain the real and imaginary parts of the query vector and key vector respectively; Based on the dynamic rotation angles corresponding to the query vector and the key vector, the real and imaginary parts corresponding to the query vector and the key vector are rotated respectively to obtain the real and imaginary parts corresponding to the rotated query vector and the rotated key vector. Add the real and imaginary parts of the rotated query vector and the rotated key vector respectively to obtain the rotated query vector and the rotated key vector.

6. The knowledge graph completion method based on dynamic complex rotational attention according to claim 5, characterized in that, The expression for the complex number rotation operation is as follows: ; ; ; ; In the above formula, and Let them represent the real and imaginary parts of a complex number, respectively. The entity embeddings representing the inputs for model training. , This represents the real and imaginary parts of a vector that has undergone a complex rotation in a two-dimensional plane. This represents a rotated vector formed by concatenating the real and imaginary parts of the vector.

7. The knowledge graph completion method based on dynamic complex rotational attention as described in claim 6, characterized in that, The step of determining the attention weight coefficients based on the rotated query vector and the rotated key vector, aggregating the value vectors, updating the entity embedding vectors, and outputting the entity relationship prediction results specifically includes: The similarity between the rotated query vector and the rotated key vector is calculated, and the calculation results are normalized to obtain the attention weight coefficient. Based on the attention weight coefficient, the value vector is weighted and summed, and then concatenated with the rotated query vector and the rotated key vector to obtain the aggregated entity embedding vector; The aggregated entity embedding vector is rejoined with the original message vector and then subjected to layer normalization to obtain the updated entity embedding vector. The updated entity embedding vectors are input into the scoring function to obtain the prediction results of the relationships between entities.

8. A knowledge graph completion system based on dynamic complex rotational attention, characterized in that, Includes the following modules: The first module is used to construct the original message vector and project it based on the entity embedding vector and the relation embedding vector to obtain the query vector, key vector and value vector; The second module is used to extract features from entity embedding vectors and relation embedding vectors, and to perform complex rotation operations on query vectors and key vectors based on a dynamic complex rotation mechanism to obtain rotated query vectors and rotated key vectors. The third module is used to determine the attention weight coefficients based on the rotated query vector and the rotated key vector, aggregate the value vectors, update the entity embedding vectors, and output the prediction results of the relationships between entities.