A structure perception-based multi-element relationship knowledge graph reasoning method and system
By constructing a structure-aware Transformer model, the problem of insufficient utilization of structural information in multivariate knowledge graph representation learning is solved, improving reasoning accuracy and model applicability, and making it suitable for recommendation systems, knowledge search and question answering systems.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHEJIANG UNIV
- Filing Date
- 2024-04-15
- Publication Date
- 2026-07-31
AI Technical Summary
Existing multivariate knowledge graph representation learning models based on the Transformer architecture fail to fully utilize the structural information of multivariate relational knowledge graphs, resulting in low inference accuracy and ignoring the connections and asymmetries between elements in the graph.
We construct a structure-aware Transformer model by extracting facts from a multivariate relational knowledge graph, masking elements one by one, randomly sampling subgraphs to serialize the input, adding position embedding representations, introducing connection structure enhancement and orientation information computation layers, and optimizing model parameters to improve inference accuracy.
It improves the accuracy of multi-relational knowledge graph reasoning and enhances the model's generalization ability, making it applicable to multi-relational, ordinary ternary, and temporal knowledge graph reasoning.
Smart Images

Figure CN118446289B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of multi-relational knowledge graph reasoning technology, specifically involving a multi-relational knowledge graph reasoning method and system based on structure awareness. Background Technology
[0002] Knowledge graphs are widely used in recommendation systems, search engines, question-answering systems, and other scenarios. Traditional knowledge graphs represent information in the form of binary relations (also known as "triples (head entity, relation, tail entity)"). Although the binary relation form of knowledge graph representation is widely used, its expressive power is limited when faced with complex facts. In reality, most complex facts involving multiple relations are difficult to express using binary relations. To address the shortcomings of binary relations in expressing complex facts, multi-relation knowledge graphs have been proposed. Multi-relations represent information in the form of a main triple plus multiple subordinate key-value pairs, i.e., (head entity, relation, tail entity, key1:value1, key2:value2, ..., keym:valuem), where m is the number of key-value pairs.
[0003] Reasoning based on multi-relational knowledge graphs is a fundamental technical problem in question-answering systems. This problem aims to investigate how to accurately predict the missing element when it is missing from a multi-relational fact. Existing techniques attempt to represent various elements of multi-relational knowledge graphs using low-dimensional dense vectors and design algorithmic models to learn and update these representations. These models can be broadly categorized into models based on Euclidean space vector translation (m-TransH, RAE, etc.), models based on convolutional neural network architectures (NaLP, HINGE, etc.), and models based on Transformer architectures (Hy-Transformer, GRAN, etc.). Among these, Transformer-based models have achieved better results in multi-relational knowledge graph representation learning compared to other models and are gradually being widely used in multi-relational knowledge graph reasoning problems.
[0004] However, most current Transformer-based models in multi-dimensional knowledge graph representation learning simply adopt the self-attention mechanism of the Transformer architecture, ignoring the structural complexity of multi-dimensional knowledge graphs themselves. This is mainly reflected in three aspects:
[0005] First, existing multivariate knowledge representation learning methods based on the Transformer architecture only provide a single fact as input. This means that during inference, each element can only pay attention to other elements in the single fact, ignoring the subgraph structure around the element, which may be helpful for inference.
[0006] Second, the original self-attention mechanism of Transformer treats the input sequence as a fully connected graph, which ignores the complex connections inherent in the multi-relation knowledge graph. In actual reasoning, the original connections between elements in the graph should be strengthened: connections between head entities and relations, tail entities and relations, keys and relations, and keys and values. Attention between these directly connected elements should be greater than attention between unconnected elements. However, the original Transformer self-attention mechanism cannot guarantee this, and the complex connection structures in the multi-relation knowledge graph may be lost.
[0007] Third, the existing Transformer architecture ignores the directionality of information flow in graph structures, i.e., the asymmetry of facts. In reality, most facts are asymmetric. Asymmetric facts mean that when we change the order of entities in a fact, the fact will no longer hold true. However, the self-attention mechanism itself is indeed order-independent, meaning that when the order of elements in a sequence is changed, the attention scores between elements do not change, which violates the asymmetry of facts.
[0008] In summary, existing multivariate knowledge graph representation learning models based on the Transformer architecture suffer from insufficient utilization of structural information. Summary of the Invention
[0009] In view of the above, the purpose of this invention is to provide a structure-aware multivariate relational knowledge graph reasoning method and system, which supplements the structural information utilization capability of the Transformer architecture multivariate knowledge graph representation learning model, improves the applicability of the Transformer architecture in the field of multivariate knowledge graph reasoning, and improves the accuracy of multivariate knowledge graph reasoning.
[0010] To achieve the above-mentioned objectives, an embodiment provides a structure-aware multi-relationship knowledge graph reasoning method, comprising the following steps:
[0011] Extract facts from the multi-relationship knowledge graph and mask each element in the facts to construct samples;
[0012] Randomly sample the subgraphs surrounding each entity or value in each sample, serialize the subgraphs, and concatenate them with the sample as the input sequence.
[0013] The input sequence corresponding to the facts is embedded and represented, and a learnable positional embedding representation at the fact level is added to the embedding representation of elements in different facts to obtain the complete embedding representation of the input sequence.
[0014] Construct a structure-aware Transformer model. The Transformer model is composed of multiple layers of identical blocks stacked together. Each block includes an attention computation layer that connects and reinforces the structure, as well as a direction information computation layer.
[0015] The Transformer model is used to update the complete embedding representation of the input sequence. The embedding representation corresponding to the mask element is extracted from the updated embedding representation, and the probability distribution of the mask element value is calculated. The loss value between the probability distribution and the true distribution is calculated, and the Transformer model parameters are updated based on the loss value.
[0016] The Transformer model with updated parameters is used to predict the probability distribution of the missing parts in incomplete facts. Candidate elements are then selected as the reasoning answer based on the probability distribution to complete the reasoning process.
[0017] Preferably, the fact representation shown consists of a triple and at least one key-value pair;
[0018] For each sample, when randomly sampling the subgraph around each entity or value, a central fact is selected, and the entities or values of the central fact are randomly sampled from the subgraph. When an entity or value of the central fact appears in other different facts, these facts will be regarded as neighboring facts of the central fact. The neighboring facts together constitute the subgraph of the central fact.
[0019] Preferably, the input sequence corresponding to the fact is embedded and represented, including:
[0020] We construct an initial embedding representation of all elements in the original fact using numerically random low-dimensional dense vectors, and then use the initial embedding representation to embed the input sequence corresponding to the fact.
[0021] Preferably, a learnable positional embedding representation at the fact level is added to the embedding representation of elements in different facts, including:
[0022]
[0023] Among them, H center The matrix represents the embedding representations of all elements of the central fact, where p0 represents a learnable positional embedding representation that is added to the embedding representations of all elements of the central fact. and p n The matrix represents the embedding representation of all elements of each neighbor fact and the learnable positional embedding representation corresponding to each neighbor fact, where n represents the index of the neighbor fact and N represents the number of neighbor facts; H input This represents the complete embedding representation of the input sequence.
[0024] Preferably, in the attention computation layer with enhanced connection structure, the complete embedding representation of the input sequence is first compared with three independent weight matrices W. Q W K W V Multiplying them together yields a new matrix Q,K,V:
[0025] Q = W Q H input
[0026] K = W K H input
[0027] V = W V H input
[0028] Among them, matrices Q and K will be used for attention calculation;
[0029] Joint representation enhancement of key-value pairs in facts:
[0030]
[0031]
[0032] in, Let K represent the vector representation of the m-th key in the fact within the K matrix. Let the vector representation of the m-th value in the fact be the corresponding value in the K matrix. Indicates will and The vectors are concatenated in the last dimension, W P This is the weight matrix, used to map the concatenated vector back to the original vector. and For the same dimensions, the updated matrix representation of the K matrix will be denoted as... and This indicates that the m-th key and the m-th value in the fact are... Vector representation in a matrix;
[0033] In the attention computation process, a bias vector representing the graph connectivity is introduced to obtain the updated embedding representation of the attention computation layer after connection structure enhancement.
[0034]
[0035]
[0036] Where S represents the length of the input sequence, i, j, and k are the indices of elements in the input sequence, and Q... i V represents the vector representation of the i-th element in matrix Q.j Let V be the vector representation of the j-th element in matrix V. Representation matrix The vector representation of the i-th element in the input sequence, T(i,j) represents the relationship between the elements in the input sequence, and there exists a T... s-r ,T r-o ,T k-v ,T r-k ,T c-s ,T none There are six types of relations. The first five represent the connections between the head entity and the relation, the relation and the tail entity, the key and the value, the relation and the key, and the relationship between the central fact element and its neighboring fact elements, respectively. The last type represents the relationship between two elements that do not have a direct connection in the graph. and This represents the bias vector corresponding to the relationship between the i-th and j-th elements in the input sequence. They are initially represented as random vectors and are updated during training. T none Except for the corresponding deviation vector, which is always set to zero vector, α ij and α ik Both represent the attention score between any two elements. This represents the updated embedding representation of the i-th element in the fact, obtained from the attention computation layer reinforced by the connection structure in the L-th layer of the model.
[0037] Preferably, in the orientation information computation layer, the orientation information is calculated from the embedding representation prior to the attention computation layer reinforced by the input connection structure:
[0038]
[0039]
[0040]
[0041] in, Let represent the embedding representations of the m-th key and value input to the L-th layer of the model, respectively. Let W represent the embedding representations of the head entity, relation, and tail entity input to the L-th layer of the model, respectively. The avg function represents the average pooling of multiple embedding representations. s W o W q W v W n These represent five different weight matrices, which are optimized during training. These represent the directional information corresponding to the head entity, tail entity, and the m-th value, respectively.
[0042] The directional information will be residually connected with the updated embedding representation obtained from the connection structure-enhanced attention computation layer of layer L to obtain the updated embedding representation of each block output:
[0043]
[0044]
[0045]
[0046] Where β is an adjustable hyperparameter. These represent the updated embedding representations of the head entity, tail entity, and m-th value in the input sequence, obtained through an attention computation layer enhanced with connection structure, respectively. and represent the updated embedding representation of the output of the Lth layer block, which serves as the input to the L+1th layer block.
[0047] Preferably, extracting the embedding representations corresponding to the mask elements from the updated embedding representation and calculating the probability distribution of the mask element values includes:
[0048] When the mask position is an entity or a value, the probability distribution PreE of the mask elements is:
[0049] PreE = softmax((h [M] W p +b)E T )
[0050] When the mask position is in a relation or key, the probability distribution PreR of the mask elements is:
[0051] PreR = softmax((h [M] W p +b)R T )
[0052] Among them, h [M] W represents the extraction of the embedding representation corresponding to the mask element from the updated embedding representation. p Let b be a learnable weight matrix, and E be a learnable bias vector. T R represents the embedding representation matrix corresponding to all candidate entities or values. T This represents the embedding representation matrix corresponding to all candidate relations or keys, and softmax represents the Softmax function.
[0053] Preferably, calculating the loss value between the probability distribution and the true distribution, and based on the loss value, includes:
[0054] If the mask position is on an entity or value, its loss function It is represented as:
[0055]
[0056] If the mask position is in the relation or key, its loss function It is represented as:
[0057]
[0058] Among them, PreE t y represents the predicted probability score of the t-th candidate entity or value in the probability distribution PreE, where |E| represents the total number of candidate entities or values. t PreR represents the label probability score of the t-th candidate entity or value; t Let |R| represent the predicted probability score of the t-th candidate relation or key in the probability distribution of candidate relations or keys, where |R| represents the total number of candidate relations or keys.
[0059] To achieve the above-mentioned objectives, embodiments of the present invention also provide a structure-aware multi-relational knowledge graph reasoning system, comprising:
[0060] The sample construction module is used to extract facts from the multivariate relational knowledge graph and mask the elements in the facts one by one to construct samples;
[0061] The input sequence construction module is used to randomly sample the subgraphs around each entity or value in each sample, and serialize the subgraphs and concatenate them with the sample as the input sequence.
[0062] The initial embedding representation module is used to perform embedding representation on the input sequence corresponding to the facts, and to add learnable positional embedding representations at the fact level to the embedding representations of elements in different facts, so as to obtain the complete embedding representation of the input sequence;
[0063] The model building module is used to build a structure-aware Transformer model. The Transformer model is composed of multiple layers of identical blocks stacked together. Each block includes an attention computing layer that connects and reinforces the structure, as well as a direction information computing layer.
[0064] The model optimization module is used to update the complete embedding representation of the input sequence using the Transformer model, extract the embedding representation corresponding to the mask element from the updated embedding representation and calculate the probability distribution of the mask element values, calculate the loss value between the probability distribution and the true distribution and update the Transformer model parameters based on the loss value.
[0065] The reasoning module is used to predict the probability distribution of missing parts in incomplete facts using a Transformer model with updated parameters, and then selects candidate elements as the reasoning answer based on the probability distribution to complete the reasoning process.
[0066] To achieve the above-mentioned objectives, embodiments of the present invention also provide a computing device, including a memory and one or more processors. The memory stores executable code, and when the one or more processors execute the executable code, they are used to implement the above-mentioned structure-aware multi-relationship knowledge graph reasoning method.
[0067] Compared with the prior art, the beneficial effects of the present invention include at least the following:
[0068] In the field of multi-relational knowledge graph reasoning, the structure-aware Transformer model designed in this invention supplements the Transformer architecture's ability to utilize structural information of multi-relational knowledge graphs from multiple perspectives, thereby improving the accuracy of reasoning. Furthermore, the constructed Transformer model has good generalization ability and can be applied not only to multi-relational knowledge graph reasoning but also to ordinary triplet knowledge graph reasoning and temporal knowledge graph reasoning. Attached Figure Description
[0069] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0070] Figure 1 This is a flowchart of the structure-aware multi-relationship knowledge graph reasoning method provided in the embodiment;
[0071] Figure 2 This is a structural diagram of the structure-aware Transformer model provided in the embodiment;
[0072] Figure 3 This is a schematic diagram of the structure of the multi-relationship knowledge graph reasoning system based on structure awareness provided in the embodiment.
[0073] Figure 4 This is a schematic diagram of the computing device provided in the embodiment. Detailed Implementation
[0074] 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 embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and do not limit the scope of protection of this invention.
[0075] The inventive concept of this invention is as follows: Most existing models based on the Transformer architecture for reasoning on multi-relational knowledge graphs cannot make good use of the rich structural information in multi-relational knowledge graphs, resulting in inaccuracies in multi-relational knowledge graph reasoning tasks. To address this, embodiments of this invention provide a structure-aware multi-relational knowledge graph reasoning scheme. This scheme fully considers the structural information of knowledge in the graph by constructing and introducing subgraphs during reasoning, thereby improving the accuracy of knowledge reasoning. This scheme can be used for reasoning of textual knowledge involved in recommendation systems, knowledge search, and question answering systems.
[0076] like Figure 1 As shown in the embodiment, a structure-aware multi-relational knowledge graph reasoning method includes the following steps:
[0077] S1 extracts facts from the multi-relationship knowledge graph and masks each element in the facts to construct samples.
[0078] In this embodiment, let G represent a multivariate relational knowledge graph, E represent the set of entities and values in the multivariate relational knowledge graph, and R represent the set of relations and keys in the knowledge graph. A single fact in the multivariate relational knowledge graph consists of a head entity, a relation, a tail entity, and associated key-value pairs. The head entity, relation, tail entity, and associated key-value pairs are all considered elements.
[0079] When constructing a sample, each element in the fact is masked, that is, a certain element is replaced by a mask symbol [MASK]. For example, the sample (Xiaoming, major, [MASK], university: a certain university, degree: master's) is obtained by replacing the tail entity in the fact with the mask symbol [MASK].
[0080] S2 randomly samples the subgraphs surrounding each entity or value in each sample, serializes the subgraphs, and concatenates them with the sample as the input sequence.
[0081] In this embodiment, when randomly sampling the subgraph surrounding each entity or value in each sample, a central fact is selected, and the entities or values of the central fact are randomly sampled from the subgraph. When an entity or value from the central fact appears in other different facts, these facts are considered neighboring facts of the central fact, and the neighboring facts together constitute the subgraph of the central fact. It should be noted that any fact can be used as the central fact. Assuming that the sample (Xiaoming, major, [MASK], university: a certain university, degree: master's) is used as the central fact, then the entity (Xiaoming) or the value (a certain university, master's) is randomly sampled from the subgraph.
[0082] After obtaining the subgraph, a specified number of neighboring facts are randomly selected and concatenated with the central fact to form the input sequence. This allows the elements in the central fact to also pay attention to the elements in the neighboring facts during attention calculation, thereby aiding reasoning.
[0083] S3. Embedding representation is performed on the input sequence corresponding to the facts, and learnable positional embedding representations at the fact level are added to the embedding representations of elements in different facts to obtain the complete embedding representation of the input sequence.
[0084] In this embodiment, the embedding representation of the input sequence corresponding to the fact includes: constructing an initial embedding representation of all elements in the original fact using a low-dimensional dense vector with numerical randomness, and then using the initial embedding representation to embed the input sequence corresponding to the fact.
[0085] In this embodiment, prior to the first layer of the model, learnable positional embedding representations at the fact level are added to the embedding representations of elements in different facts (central facts and neighbor facts), including:
[0086] Among them, H center The matrix represents the embedding representations of all elements of the central fact, where p0 represents a learnable positional embedding representation that is added to the embedding representations of all elements of the central fact. and p n The matrix represents the embedding representation of all elements of each neighbor fact and the learnable positional embedding representation corresponding to each neighbor fact, where n represents the index of the neighbor fact and N represents the number of neighbor facts; H input This represents the complete embedding representation of the input sequence.
[0087] S4. Construct a structure-aware Transformer model. The Transformer model is composed of multiple layers of identical blocks stacked together. Each block includes an attention computation layer that connects and reinforces the structure, as well as a direction information computation layer.
[0088] In the embodiment, the constructed structure-aware Transformer model is composed of multiple layers of identical blocks stacked together. Each block is composed of two sub-layers stacked together. These two sub-layers, from bottom to top, are the attention computation layer for structure enhancement and the orientation information computation layer, which are used to update the embedded representation of the input sequence while considering structural information.
[0089] In the attention computation layer with enhanced connection structure, the complete embedding representation of the input sequence is first processed by three independent weight matrices W. Q W K W V Multiplying them together yields a new matrix Q,K,V:
[0090] Q = W Q H input
[0091] K = W K H input
[0092] V = W V H input
[0093] Among them, matrices Q and K will be used for attention calculation;
[0094] To enhance the connectivity structure of multi-relation knowledge graphs during attention computation, joint representation enhancement is performed on key-value pairs in facts:
[0095]
[0096]
[0097] in, Let K represent the vector representation of the m-th key in the fact within the K matrix. Let the vector representation of the m-th value in the fact be the corresponding value in the K matrix. Indicates will and The vectors are concatenated in the last dimension, W P This is the weight matrix, used to map the concatenated vector back to the original vector. and For the same dimensions, the updated matrix representation of the K matrix will be denoted as... and This indicates that the m-th key and the m-th value in the fact are... Vector representation in a matrix;
[0098] In the attention computation process, a bias vector representing the graph connectivity is introduced to obtain the updated embedding representation of the attention computation layer after connection structure enhancement.
[0099]
[0100]
[0101] Where S represents the length of the input sequence, i, j, and k are the indices of elements in the input sequence, and Q... i V represents the vector representation of the i-th element in matrix Q. j Let V be the vector representation of the j-th element in matrix V. Representation matrix The vector representation of the i-th element in the input sequence, T(i,j) represents the relationship between the elements in the input sequence, and there exists a T...s-r ,T r-o ,T k-v ,T r-k ,T c-s ,T none There are six types of relations. The first five represent the connections between the head entity and the relation, the relation and the tail entity, the key and the value, the relation and the key, and the relationship between the central fact element and its neighboring fact elements, respectively. The last type represents the relationship between two elements that do not have a direct connection in the graph. and This represents the bias vector corresponding to the relationship between the i-th and j-th elements in the input sequence. They are initially represented as random vectors and are updated during training. T none Except for the corresponding deviation vector, which is always set to zero vector, α ij and α ik Both represent the attention score between any two elements. This represents the updated embedding representation of the i-th element in the fact, obtained from the attention computation layer reinforced by the connection structure in the L-th layer of the model.
[0102] Following the attention computation layer with enhanced connection structure, a direction information computation layer is superimposed. In this layer, the direction information is calculated from the embedding representation input to the attention computation layer prior to the enhanced connection structure layer.
[0103]
[0104]
[0105]
[0106] in, Let represent the embedding representations of the m-th key and value input to the L-th layer of the model, respectively. Let W represent the embedding representations of the head entity, relation, and tail entity input to the L-th layer of the model, respectively. The avg function represents the average pooling of multiple embedding representations. s W o W q W v W n These represent five different weight matrices, which are optimized during training. These represent the directional information corresponding to the head entity, tail entity, and the m-th value, respectively.
[0107] The directional information will be residually connected with the updated embedding representation obtained from the connection structure-enhanced attention computation layer of layer L to obtain the updated embedding representation of each block output:
[0108]
[0109]
[0110]
[0111] Where β is an adjustable hyperparameter. These represent the updated embedding representations of the head entity, tail entity, and m-th value in the input sequence, obtained through an attention computation layer enhanced with connection structure, respectively. Let N and L represent the updated embedding representation of the output of the Lth layer block, which serves as the input to the (L+1)th layer block. L The Transformer-type module of the layer block, the attention computation layer with enhanced connection structure, and the orientation information computation layer will be repeatedly executed N times. L Second-rate.
[0112] S5 uses the Transformer model to update the complete embedding representation of the input sequence, extracts the embedding representation corresponding to the mask element from the updated embedding representation, calculates the probability distribution of the mask element values, calculates the loss value between the probability distribution and the true distribution, and updates the Transformer model parameters based on the loss value.
[0113] In this embodiment, the complete embedding representation of the input sequence is input into the Transformer model. After the embedding representation is updated by multiple blocks in the Transformer model, the final updated embedding representation is obtained. Then, the embedding representation corresponding to the mask element is extracted from it. After the embedding representation is linearly mapped once, the similarity score is calculated with the embedding representation of all candidate elements to obtain the probability distribution of the mask element value.
[0114] Specifically, when the mask position is an entity or a value, the probability distribution PreE of the mask elements is:
[0115] PreE = softmax((h [M] W p +b)E T )
[0116] When the mask position is in a relation or key, the probability distribution PreR of the mask elements is:
[0117] PreR = softmax((h [M] W p +b)R T )
[0118] Among them, h [M] W represents the extraction of the embedding representation corresponding to the mask element from the updated embedding representation. pLet b be a learnable weight matrix, and E be a learnable bias vector. T R represents the embedding representation matrix corresponding to all candidate entities or values. T This represents the embedding representation matrix corresponding to all candidate relations or keys, and softmax represents the Softmax function.
[0119] In this embodiment, after obtaining the probability distribution of the mask element values, the loss value between the probability distribution and the true distribution is calculated and updated based on the loss value, so that the probability distribution calculated by the model is close to the true distribution.
[0120] Specifically, if the mask position is on an entity or value, its loss function... It is represented as:
[0121]
[0122] If the mask position is in the relation or key, its loss function It is represented as:
[0123]
[0124] Among them, PreE t y represents the predicted probability score of the t-th candidate entity or value in the probability distribution PreE, where |E| represents the total number of candidate entities or values. t PreR represents the label probability score of the t-th candidate entity or value; t Let |R| represent the predicted probability score of the t-th candidate relation or key in the probability distribution of candidate relations or keys, where |R| represents the total number of candidate relations or keys.
[0125] S6. Use the parameter-updated Transformer model to predict the probability distribution of the missing parts in the incomplete facts, and select candidate elements as the reasoning answer based on the probability distribution to complete the reasoning process.
[0126] In this embodiment, based on the optimized model and the updated element embedding representation, when given an incomplete fact that needs to be reasoned, the missing part of the incomplete fact that needs to be predicted is replaced with a mask. The updated Transformer model is then input and steps S2, S3, and S5 are repeated to obtain the predicted probability distribution of the mask elements. The candidate element with the highest predicted probability score is then selected as the reasoning answer, thereby completing the reasoning.
[0127] The aforementioned multi-relational knowledge graph reasoning method can be used for product recommendation in the e-commerce field. Specifically, during the recommendation process, facts are extracted from the multi-relational e-commerce knowledge graph to train the Transformer model, and the trained Transformer model is used to reason about the missing elements in the incomplete facts. The reasoning answer obtained is used as the product recommendation result.
[0128] like Figure 3 As shown, the embodiment also provides a structure-aware multivariate relation knowledge graph reasoning system 30, including a sample construction module 31, an input sequence construction module 32, an initial embedding representation module 33, a model construction module 34, a model optimization module 35, and a reasoning module 36. The sample construction module 31 extracts facts from the multivariate relation knowledge graph and masks the elements in the facts one by one to construct samples. The input sequence construction module 32 randomly samples the subgraphs surrounding each entity or value in each sample and serializes the subgraphs before concatenating them with the sample as the input sequence. The initial embedding representation module 33 performs embedding representation on the input sequence corresponding to the facts and adds learnable positional embedding representations at the fact level to the embedding representations of elements in different facts to obtain a complete embedding representation of the input sequence. The model construction module... 34 is used to construct a structure-aware Transformer model. The Transformer model is composed of multiple layers of identical blocks stacked together. Each block includes an attention computation layer for structural reinforcement and a direction information computation layer. The model optimization module 35 is used to update the complete embedding representation of the input sequence using the Transformer model. It extracts the embedding representation corresponding to the mask element from the updated embedding representation and calculates the probability distribution of the mask element values. It calculates the loss value between the probability distribution and the true distribution and updates the Transformer model parameters based on the loss value. The inference module 36 is used to predict the probability distribution of the missing part in the incomplete fact using the parameter-updated Transformer model. It selects candidate elements as inference answers based on the probability distribution and completes the inference process.
[0129] It should be noted that when constructing a human-computer interaction cognitive model, the structure-aware multi-relational knowledge graph reasoning system provided in the above embodiments should be illustrated using the above-described functional module division as an example. The functions can be assigned to different functional modules as needed, i.e., the internal structure of the terminal or server can be divided into different functional modules to complete all or part of the functions described above. Furthermore, the structure-aware multi-relational knowledge graph reasoning system and the structure-aware multi-relational knowledge graph reasoning method embodiments provided in the above embodiments belong to the same concept. For details of its specific implementation process, please refer to the structure-aware multi-relational knowledge graph reasoning method embodiments, which will not be repeated here.
[0130] Based on the same inventive concept, the embodiment also provides a computing device, including a memory and one or more processors. The memory stores executable code, and when the one or more processors execute the executable code, it is used to implement the above-described structure-aware multi-relationship knowledge graph reasoning method, specifically including the following steps:
[0131] S1, extract facts from the multi-relationship knowledge graph and mask the elements in the facts one by one to construct samples;
[0132] S2, randomly sample the subgraphs around each entity or value in each sample, serialize the subgraphs and concatenate them with the sample as the input sequence;
[0133] S3, embedding representation of the input sequence corresponding to the fact, and adding learnable positional embedding representation at the fact level to the embedding representation of elements in different facts, to obtain the complete embedding representation of the input sequence;
[0134] S4. Construct a structure-aware Transformer model. The Transformer model is composed of multiple layers of identical blocks stacked together. Each block includes an attention computation layer that connects and reinforces the structure, as well as a direction information computation layer.
[0135] S5. The Transformer model is used to update the complete embedding representation of the input sequence. The embedding representation corresponding to the mask element is extracted from the updated embedding representation, and the probability distribution of the mask element value is calculated. The loss value between the probability distribution and the true distribution is calculated, and the Transformer model parameters are updated according to the loss value.
[0136] S6. Use the parameter-updated Transformer model to predict the probability distribution of the missing parts in the incomplete facts, and select candidate elements as the reasoning answer based on the probability distribution to complete the reasoning process.
[0137] like Figure 4 As shown, the computing device provided in this embodiment, at the hardware level, includes not only a processor and memory, but also internal buses, network interfaces, memory, and other hardware required for business operations. The memory is non-volatile memory. The processor reads the corresponding computer program from the non-volatile memory into memory and then runs it to implement the structure-aware multi-relationship knowledge graph reasoning method described in S1-S6 above. Of course, besides software implementation, this invention does not exclude other implementation methods, such as logic devices or a combination of hardware and software, etc. That is to say, the execution entity of the following processing flow is not limited to individual logic units, but can also be hardware or logic devices.
[0138] The specific embodiments described above illustrate the technical solution and beneficial effects of the present invention in detail. It should be understood that the above description is only the most preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, additions, and equivalent substitutions made within the scope of the principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for structural perception-based multi-element relationship knowledge graph reasoning, characterized in that, Includes the following steps: Extract facts from the multi-relationship knowledge graph and mask each element in the facts to construct samples; Randomly sample the subgraphs surrounding each entity or value in each sample, serialize the subgraphs, and concatenate them with the sample as the input sequence. The input sequence corresponding to the facts is embedded and represented, and a learnable positional embedding representation at the fact level is added to the embedding representation of elements in different facts to obtain the complete embedding representation of the input sequence. Construct a structure-aware Transformer model. The Transformer model is composed of multiple layers of identical blocks stacked together. Each block includes an attention computation layer that connects and reinforces the structure, as well as a direction information computation layer. The Transformer model is used to update the complete embedding representation of the input sequence. The embedding representation corresponding to the mask element is extracted from the updated embedding representation, and the probability distribution of the mask element value is calculated. The loss value between the probability distribution and the true distribution is calculated, and the Transformer model parameters are updated based on the loss value. The Transformer model with updated parameters is used to predict the probability distribution of the missing parts in incomplete facts. Candidate elements are then selected as the reasoning answer based on the probability distribution to complete the reasoning process.
2. The structure-aware multi-relational knowledge graph reasoning method according to claim 1, characterized in that, The fact shown consists of a triple and at least one key-value pair; When randomly sampling the subgraph around each entity or value in each sample, a central fact is selected, and the entities or values of the central fact are randomly sampled from the subgraph. When an entity or value of the central fact appears in other different facts, these facts will be regarded as neighboring facts of the central fact. The neighboring facts together constitute the subgraph of the central fact. 3.The structure perception based multi-relational knowledge graph reasoning method of claim 2, wherein, Embedded representation of the input sequence corresponding to the facts includes: We construct an initial embedding representation of all elements in the original fact using numerically random low-dimensional dense vectors, and then use the initial embedding representation to embed the input sequence corresponding to the fact. 4.The structure perception based multi-relational knowledge graph reasoning method of claim 1, wherein, Add learnable positional embedding representations at the fact level to the embedding representations of elements in different facts, including: in, The matrix representing the embedding of all elements of the central fact. This represents a learnable positional embedding representation, which is added to the embedding representations of all elements in the central fact. and A matrix representing the embedding representations of all elements of each neighbor fact, and a learnable positional embedding representation corresponding to each neighbor fact. An index representing neighbor facts. Indicates the quantity of neighboring facts; This represents the complete embedding representation of the input sequence. 5.The structure perception based multi-relational knowledge graph reasoning method of claim 4, wherein, In the attention computation layer with connection structure reinforcement, the complete embedding representation of the input sequence will first be multiplied with three independent weight matrices to obtain a brand new matrix where the matrix will be used to perform attention computation; Joint representation enhancement of key-value pairs in facts: in, Indicating the fact that the first m Each key in The vector representation corresponding to the matrix, Indicating the fact that the first m The value is in The vector representation corresponding to the matrix, Indicates will and The vectors are concatenated in the last dimension. This is the weight matrix, used to map the concatenated vector back to the original vector. and Same dimension, The updated matrix representation will be denoted as , and Indicating the fact that the first m The key and the first m The value is in Vector representation in a matrix; In the attention calculation process, a bias vector representing atlas connection relationship is introduced to obtain an updated embedding representation of the attention calculation layer reinforced by the connection structure : in, S Indicates the length of the input sequence. and These are all indices of elements in the input sequence. Representation matrix The Middle i A vector representation of n elements, Representation matrix The Middle j A vector representation of n elements, Representation matrix The Middle i A vector representation of n elements, This represents the relationship between the elements in the input sequence, and it exists. There are six types of relations. The first five represent the connections between the head entity and the relation, the relation and the tail entity, the key and the value, the relation and the key, and the relationship between the central fact element and its neighboring fact elements, respectively. The last type represents the relationship between two elements that do not have a direct connection in the graph. , and Indicates the first... i The element and the first j The bias vectors corresponding to the relationships between the elements are initially represented as random vectors and are updated during training. Except for the corresponding deviation vector, which is always set to zero vector, and Both represent the attention score between any two elements. Indicating the fact that the first i The updated embedding representation of each element is obtained in the Lth layer of the model based on the attention computation layer enhanced by the connection structure.
6. The structure-aware multi-relational knowledge graph reasoning method according to claim 1, characterized in that, In the orientation information computation layer, the orientation information is computed from the embedding representation prior to the attention computation layer reinforced by the input connection structure: in, These represent the inputs of the Lth layer of the model, respectively. m An embedded representation of keys and values Let represent the embedding representations of the head entity, relation, and tail entity input to the L-th layer of the model, respectively. The function represents average pooling of multiple embedding representations. These represent five different weight matrices, which are optimized during training. Representing the head entity, tail entity, and first entity respectively. m The directional information corresponding to each value; The directional information will be residually connected with the updated embedding representation obtained from the connection structure-enhanced attention computation layer of layer L to obtain the updated embedding representation of each block output: in, These are adjustable hyperparameters. , , These represent the head entity, tail entity, and third entity in the input sequence, respectively. m The updated embedding representation is obtained by passing each value through an attention computation layer enhanced with a connection structure. and represent the updated embedding representation of the output of the Lth layer block, which serves as the input to the L+1th layer block. 7.The structure perception based multi-relational knowledge graph reasoning method of claim 1, wherein, Extracting the embedding representations corresponding to the mask elements from the updated embedding representation and calculating the probability distribution of the mask element values includes: When the mask position is at an entity or a value, the probability distribution of the mask element is: When the mask position is in a relationship or key, the probability distribution of the mask elements is: in, This indicates that the embedding representation corresponding to the mask element is extracted from the updated embedding representation. The weight matrix is a learnable matrix. This is a learnable bias vector. This represents the embedding representation matrix corresponding to all candidate entities or values. This represents the embedding representation matrix corresponding to all candidate relations or keys. This represents the Softmax function.
8. The structure-aware multi-relational knowledge graph reasoning method according to claim 7, characterized in that, Calculate the loss value between the probability distribution and the true distribution, and based on the loss value, include: If the mask position is at an entity or a value, its loss function is represented as: If the mask position is in the relation or key, its loss function It is represented as: in, Represents the probability distribution of candidate entities or values. The Middle t The predicted probability score of each candidate entity or value. This indicates the number of all candidate entities or values. The label probability score represents the t-th candidate entity or value. Represents the probability distribution of candidate relations or keys. The Middle t The predicted probability score of each candidate relation or key. This indicates the number of all candidate relations or keys. 9.A structure-aware multi-relational knowledge graph reasoning system, characterized in that, include: The sample construction module is used to extract facts from the multivariate relational knowledge graph and mask the elements in the facts one by one to construct samples; The input sequence construction module is used to randomly sample the subgraphs around each entity or value in each sample, and serialize the subgraphs and concatenate them with the sample as the input sequence. The initial embedding representation module is used to perform embedding representation on the input sequence corresponding to the facts, and to add learnable positional embedding representations at the fact level to the embedding representations of elements in different facts, so as to obtain the complete embedding representation of the input sequence; The model building module is used to build a structure-aware Transformer model. The Transformer model is composed of multiple layers of identical blocks stacked together. Each block includes an attention computing layer that connects and reinforces the structure, as well as a direction information computing layer. The model optimization module is used to update the complete embedding representation of the input sequence using the Transformer model, extract the embedding representation corresponding to the mask element from the updated embedding representation and calculate the probability distribution of the mask element values, calculate the loss value between the probability distribution and the true distribution and update the Transformer model parameters based on the loss value. The reasoning module is used to predict the probability distribution of missing parts in incomplete facts using a Transformer model with updated parameters, and then selects candidate elements as the reasoning answer based on the probability distribution to complete the reasoning process.
10. A computing device comprising a memory and one or more processors, the memory having stored therein executable code, wherein, When the one or more processors execute the executable code, they are used to implement the structure-aware multi-relational knowledge graph reasoning method according to any one of claims 1-8.