Knowledge graph complex question and answer method based on query calculation tree

CN118964567APending Publication Date: 2024-11-15DALIAN NATIONALITIES UNIVERSITY
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411037683.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-31
Publication Date
2024-11-15

Smart Images

  • Figure CN118964567A_ABST
    Figure CN118964567A_ABST
Patent Text Reader

Abstract

The invention discloses a knowledge graph complex question-answering method based on a query calculation tree and belongs to the technical field of artificial intelligence. The method comprises the following steps: firstly, when a complex question and answer task on a knowledge graph is processed, converting the knowledge graph into a tree calculation graph by adopting a method of combining a Transform structure and a graph neural network so as to find an optimal solution; in the process, a triple conversion strategy is adopted, that is, each fact in the knowledge graph is represented as a triple, and the representation is utilized to construct a computational graph; secondly, forward and backward propagation is carried out on the tree calculation graph to find an optimal solution, in the pre-training process, a sub-graph is randomly sampled from the knowledge graph, and a mask entity is predicted; according to the method, a graph neural network and a multi-head attention mechanism are used for encoding questions, and finally answers are scored and sorted through an embedded scoring function, so that a task of answering complex questions on an incomplete knowledge graph is realized, and the complex logic problems in the incomplete knowledge graph are effectively solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the research direction of natural language processing (NLP) and knowledge graph in the field of artificial intelligence. This method combines query processing, knowledge representation, knowledge reasoning, graph computing and machine learning technologies to improve the ability of machines to understand natural language queries and extract accurate answers from incomplete knowledge graphs. Background Art

[0002] Knowledge graph (KG) is a technology that represents knowledge in a graph structure, which consists of a series of entities (nodes) and their relationships (edges). The purpose of knowledge graph is to provide a structured and semantically rich way of representing knowledge so that machines can better understand and reason about knowledge. In the development of knowledge graph, representation learning is one of the basic problems of querying knowledge graph. It currently has two main problems, one is incomplete knowledge and the other is low query efficiency. Although knowledge graphs have extracted millions of entities and billions of relationship facts from the real world, the data in large knowledge graphs is still sparse and incomplete, so studying the completion and embedding of knowledge graph data has become an important research direction. Knowledge graph embedding aims to embed entities and relationships into low-dimensional continuous vectors, and has been widely used in simple knowledge graph completion problems (h, r, ?), which consist of a single head entity h, a relationship r, and a missing tail entity. But in reality, queries may be more complex, and may involve entities from multiple sources, supplementary relationships, complex logic, and unknown intermediate entities, which are collectively referred to as complex problems.

[0003] For answering complex questions, in the simplest case, the task is reduced to link prediction: a 1-hop query to predict whether an edge exists between a pair of nodes. Complex queries involve other structures between nodes, such as 2-hop and 3-hop paths, and cross paths with intermediate variables, with complex logical relationships. Complex logic queries are queries that contain multiple conditions and logical operators, such as AND, OR, and NOT, which can be expressed in first-order logic (FOL), including conjunction (∧), disjunction (∨), negation (∨), and so on. and existential quantifiers Symbols such as . A more direct approach is to represent their computational graph as a directed acyclic graph (DAG), and solve it by traversing the knowledge graph and assigning feasible entities to intermediate variables according to its structure. At present, there are certain research results on complex logical queries both at home and abroad. By introducing logical rules, such as description logic and predicate logic, complex logical query requirements are met. By designing specific neural network structures, such as TransE and TransH, the complex semantic associations between entities and relationships in the knowledge graph are captured. However, the existing technologies cannot effectively deal with the problem of excessive search intensity of complex logical queries, cannot efficiently deal with the problem of combining entities and relationships into Transformer calculations, and cannot solve complex logical problems in incomplete knowledge graphs. Summary of the invention

[0004] In order to solve the problems existing in the above-mentioned prior art, the present invention aims to solve the problem that the prior art cannot effectively handle the excessive search intensity of complex logical queries, and proposes a complex question and answer method for knowledge graphs based on query calculation trees; at the same time, in order to more efficiently handle the problem of combining entities and relationships into Transformer calculations, the relationships in the graph are converted into relationship nodes, thereby converting the knowledge graph into a directed graph without edge attributes, so that the present invention can effectively solve complex logical problems in incomplete knowledge graphs.

[0005] To achieve the above object, the present invention provides the following technical solutions:

[0006] A knowledge graph complex question answering method based on query computation tree, randomly sampling subgraphs according to knowledge graph data, including:

[0007] Module 1: Query computation tree layer: forward and backward propagation is performed through the tree-type computation graph to optimize the subquery assignment on the variable node to maximize the possibility; forward propagation is performed on the query computation tree to find the optimal solution, and backward propagation is used to assign intermediate variables to ensure interpretability;

[0008] Module 2: Data preprocessing layer: convert the relations in the knowledge graph into relation nodes, convert the knowledge graph into a directed graph without attribute edges, and map the entities and relation nodes into low-dimensional continuous vectors;

[0009] Module 3: Transformer layer based on expert hybrid strategy: Utilizing the sparse activation characteristics of the Transformer feedforward layer, the model capacity is expanded through a hybrid expert strategy to construct a query computation tree representation sequence and a relationship node representation sequence. This module is used to capture this sequence and update it to obtain a more comprehensive and specific semantic sequence.

[0010] The above modules are combined to finally obtain a fully trained knowledge graph model. Each element in this representation is masked with the [MASK] label to predict the masked part. Finally, the prediction results are sorted, and the link prediction evaluation indicators average reciprocal ranking MRR, average proportion Hits@1 of ranking less than or equal to 1, average proportion Hits@5 of ranking less than or equal to 5, and average proportion Hits@10 of ranking less than or equal to 10 are used as evaluation indicators.

[0011] Furthermore, we embed the forward-backward propagation method into module 1 to reduce the search space, and study the FOL query for local computations involving trees to efficiently find the optimal solution.

[0012] Furthermore, for module 2, the triple conversion method is used to convert the relationship into a relationship node and the knowledge graph into a directed graph without edge attributes.

[0013] Furthermore, for module three, a query computation tree representation sequence and a relationship node representation sequence are constructed, and this sequence is captured and updated using the MOE expert hybrid strategy to construct a more comprehensive and specific semantic sequence.

[0014] Furthermore, in the query calculation tree layer of module 1, the following steps are performed:

[0015] S1.1. Constructing the neural connection matrix:

[0016] The nodes and relations in the knowledge graph are converted into vectors through embedding methods. The vectors capture the structural information of the graph and are used for downstream tasks. The entities e and relations r are formed into a neural connection matrix M. r :

[0017] M r = r(e i ,e j ) Formula (1)

[0018] where e i , e j are the i-th and j-th entities;

[0019] S1.2. Generate dependency graph:

[0020] Assign a unique node to each variable and constant entity in each one-hop atom, and connect the nodes using undirected edges according to the one-hop atom, including the inverse relationship; let Q * (v=e) represents the maximum truth value of the subquery of the root node v when v is assigned to an entity e; the Q of each node v is derived recursively * (v) to maximize the truth value of the query calculation tree and finally derive the root v ? Q * (v ?); The dependency graph generation process of conjunction (∧) is expressed as follows:

[0021]

[0022] The dependency graph generation process of disjunction (∨) is expressed as follows:

[0023]

[0024] The dependency graph generation process of a positive relationship (r) is expressed as follows:

[0025] Q * (v ? )=max(Q * (v k )⊙M r ) Formula (4)

[0026] Inverse Relationship The dependency graph generation process is expressed as follows:

[0027] Q * (v ? )=max(Q * (v k )⊙(1-M r )) Formula (5)

[0028] S1.3. Construct query calculation tree:

[0029] In the query computation tree, each node v from the leaf node to the root computes Q * (v); The expression of the optimization problem is:

[0030]

[0031] S1.4. Optimize the query calculation tree:

[0032] The forward pass calculates the Q of each node v in the tree * (v), the optimal entity allocation set is obtained by backward propagation; after obtaining the root v ? After the optimal allocation of , the optimal allocation of its sub-edges is obtained according to formula (6) and the four edge types;

[0033] Conjunction (∧) and disjunction (∨) Since the child nodes represent the same variables as the parent nodes, their optimal allocation is expressed as follows:

[0034]

[0035] The optimal allocation of positive relations (r) is expressed as follows:

[0036] v k = arg max{Q *(v k =e)Tr(e,e t )} Formula (8)

[0037] Inverse Relationship The optimal allocation is expressed as follows:

[0038] v k = arg max{Q * (v k =e) T (1-r(e,et))} Formula (9)

[0039] Furthermore, the module 2 data preprocessing layer performs the following steps:

[0040] S2.1, triple conversion:

[0041] Put entities and relationships into this module and create a relationship node r in each triple ht To connect entity h and relationship r, by mapping each relationship in graph G to a relationship node, the resulting graph is represented as:

[0042] L(G)=(E',R') Formula (10)

[0043] Where E'=E∪{r ht |r(h,t)=1}, 1 means the condition is true; no attribute edge R'=r(r ht ,t);

[0044] S2.2, Aggregation relationship edge:

[0045] In the kth layer of Transformer, H represents the number of attention heads, and the multi-head attention is calculated as follows:

[0046]

[0047] where d h =d / H, d represents the dimension. The linear transformation Q is expressed as follows:

[0048]

[0049] W Q is a weight matrix consisting of {Q, K, V}, which maps the embedding vector of node e to the space of the attention head;

[0050] Next, the feedforward neural network FFN(x) acts on the multi-head attention weighted output, and the calculation is as follows:

[0051] FFN(x)=σ(xW1+b1)W2+b2 Formula (13)

[0052] Where σ is the activation function and W is the weight;

[0053] S2.3, fine-tuning reasoning:

[0054] Randomly extract mask subgraphs of arbitrary shapes from the training set to pre-train the model, so that the receptive field of the sampled subgraph is increased, the query shape is more diverse, and the coverage of the original knowledge graph is improved. The masked entity set is expressed as:

[0055] E mask =E inter ∪E target Formula (14)

[0056] Among them, E inter represents the set of intermediate entities, E target represents the set of target entities; the loss function for the fine-tuning reasoning phase is expressed as:

[0057]

[0058] S2.4. Construct enhanced sequence representation:

[0059] The query computation tree representation sequence and the relationship node representation sequence are concatenated to obtain an enhanced sequence representation.

[0060] Furthermore, the Transformer layer of module 3 based on the expert mixture strategy performs the following steps:

[0061] S3.1. Capture representation sequence:

[0062] Apply a Transformer containing the MoE strategy to process the sequence representation. First, feed the enhanced representation sequence obtained by the previous two modules into this module, and use the multi-head attention in this module to capture the representation sequence as follows:

[0063]

[0064] Where s∈softmax, i is the index of s, and the output of FFN is the weighted average of each expert’s output;

[0065] S3.2, predict the representation sequence:

[0066] After obtaining the updated sequence, the method of masking each element is adopted to predict the masked element, and each masked element is predicted by the MLP decoder; finally, a probability distribution P is output as follows:

[0067] P = softmax(MLP(X' i )K T ) Formula (17)

[0068] Where k is the initial element embedding matrix, so it can cover the entities in ε or the relations in R according to the type of missing elements; finally, the loss is calculated using cross entropy and is calculated by predicting the similarity between the entities and the target to be predicted:

[0069]

[0070] where y t is the entry of the tth target label, P t is the t-th entry to be predicted, predicting the similarity score, using a single neuron and applying a sigmoid function to constrain the output to the [0,1] interval.

[0071] Furthermore, the calculation formula of the evaluation index is as follows:

[0072]

[0073] Among them, |S| represents the number of facts; for the value of n in Hits@n, n={1,5,10}, Ⅱ is the indicator function, when Ⅱ(rank i ≤n) takes 1 when the condition is met, and takes 0 when it is not met.

[0074] Beneficial effects of the present invention:

[0075] Compared with the prior art, the knowledge graph complex question answering method based on query computation tree described in the present invention not only optimizes the subquery assignment of variable nodes through forward and backward propagation of query computation tree, but also ensures that the model maintains the reasonable interpretability of intermediate variables while finding the optimal solution. This mechanism significantly improves the ability of the model in processing complex queries and reasoning tasks; utilizes the sparse activation characteristics and hybrid expert strategy of Transformer to effectively expand the capacity and representation ability of the model, so that the model can capture and update the deep semantic information of query computation tree and relationship nodes, and generate more comprehensive and specific semantic sequences; by converting the relationships and entities in the knowledge graph into low-dimensional continuous vectors and constructing The directed graph without attribute edges simplifies the complex structure of the knowledge graph and improves the efficiency of data processing. At the same time, this representation method helps the model better capture the potential connections between entities and relationships. The [MASK] label masking technology is used to evaluate the model's understanding ability and generalization performance by predicting the masked elements. This method not only improves the accuracy of the prediction, but also enhances the interpretability of the model, making the prediction results more reliable and easy to understand. A variety of evaluation indicators (such as average reciprocal ranking, average proportion of rankings less than or equal to a specific value) are used to comprehensively evaluate the model performance. These indicators reflect the performance of the model in the link prediction task from different angles, providing a strong basis for the optimization and improvement of the model. BRIEF DESCRIPTION OF THE DRAWINGS

[0076] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the present invention will be described in detail below in combination with the accompanying drawings and detailed embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative labor. Among them:

[0077] Figure 1 The overall flow chart of the invention is as follows;

[0078] Figure 2 It is the overall framework diagram of the present invention;

[0079] Figure 3 A flowchart representing a query-based computation tree is provided for the processing of the present invention;

[0080] Figure 4 A flow chart showing the processing of triple conversion in the present invention. DETAILED DESCRIPTION

[0081] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. Figure 1-4 The complex question-answering method of knowledge graph based on query computation tree is further explained.

[0082] Example 1

[0083] The knowledge graph complex question answering method based on the query computation tree has the following steps:

[0084] Step 1: Process the data source, pre-train the knowledge graph embedding model, and build a query calculation tree;

[0085] Step 2: Calculate the confidence of the subquery and the target query to generate an optimized query;

[0086] Step 3: Reason the optimized query and generate a dependency graph of the query computation tree;

[0087] Step 4: After generalization and fine-tuning, the enhanced sequence representation is obtained;

[0088] Step 5: Predict and output the query answer;

[0089] For step 1, first build a pre-trained model based on the current mainstream knowledge graph embedding datasets, such as Freebase, Wikidata, NELL, or FB15K. Train a pre-trained KGE model on the knowledge graph, such as ComplEx, RotatE, or TransE. The pre-trained KGE model can be used to calculate the confidence score of the query atom (a single triple), learn how to optimize the query computation tree, and perform reasoning and generate answers based on the query computation tree;

[0090] In order to optimize the query conditions in step 2, the complex query input is converted into a first-order logic (FOL) expression, including conjunction (∧), disjunction (∨), negation and existential quantifiers Symbols such as , and then convert the FOL expression into a query calculation tree. Through back propagation, the optimal entity assignment of the target query is found, that is, the entity assignment that maximizes the query confidence, and the optimized query is generated;

[0091] For step 3, convert the optimized query into a query graph, generate a dependency graph, assign a unique node to each variable in the FOL expression, and assign a unique node to each constant entity of the atomic formula. Sort the nodes in the dependency graph according to the structure of the FOL expression and assign directions to them so that all edges point to the parent node. According to the atomic formula, use undirected edges to connect the nodes and merge the joint branches;

[0092] After representing the query graphs in the above two steps in step 4, the feedback is sent to a Transformer layer based on knowledge graph embedding constructed by the present invention. In the multi-head attention mechanism of Transformer, MoE is used to calculate the similarity between each head attention node and all neighboring nodes. After generalization and fine-tuning, the calculated semantic sequence is obtained;

[0093] For step 5, an updated semantic sequence is obtained from step 4, each element of which is masked with [MASK] and then put into MLP to obtain the final prediction. Finally, the predicted entities and relationships are sorted, and the average reciprocal ranking MRR, the average proportion Hits@1 of ranking less than or equal to 1, the average proportion Hits@5 of ranking less than or equal to 5, and the average proportion Hits@10 of ranking less than or equal to 10 are used as evaluation indicators.

[0094] Example 2

[0095] Figure 1 It is the overall flow chart of the present invention, which is divided into five steps:

[0096] Step 1: Select a suitable knowledge graph as the data source and pre-train the knowledge graph embedding model;

[0097] Step 2 converts the complex query into a FOL expression and generates an optimized query computation tree representation sequence;

[0098] Step 3: Infer the optimized query to generate a dependency graph of the query computation tree;

[0099] Step 4: generalization fine-tuning, using the MOE expert mixture strategy to capture the two sequences and obtain an updated representation sequence;

[0100] Step 5 sorts the predicted entities and relations and uses the mean reciprocal ranking (MRR) as the evaluation metric.

[0101] In view of the above implementation steps, the present invention proposes a complex question-answering method based on a knowledge graph of a query computation tree. Figure 2 This is the overall model framework diagram, which includes the construction of three modules:

[0102] Module 1: Construction of query calculation tree layer;

[0103] Module 2: Construction of data preprocessing layer;

[0104] Module 3: Construction of Transformer layer based on expert mixture strategy;

[0105] First, for the knowledge graph completion task, the goal is to predict the missing triples in the current graph. Given a knowledge graph G = {E, R, F}, where E represents the set of all entities, R represents the set of all relations, and F is the set of all triples. The goal of knowledge graph completion is to find triples that are not in F but may exist.

[0106] F'={(h,r,t)|(h,r,t)∈F,r∈R}(Formula 21) where h represents the head entity, r represents the relation, and t represents the tail entity. The first-order logic (FOL) query q can be expressed as:

[0107]

[0108] where v1,…,v N is a variable, v ? ∈{v1,…,v N} is the answer variable. Each Respectively represent the truth value of the atomic relation formula on the relation r between two entities or its negation, expressed as:

[0109]

[0110] Where v, v' are variables and c is a constant entity.

[0111] Module 1 and Module 2 are both used to process the representation of queries in the knowledge graph. The difference is that Module 1 processes query expressions based on query computation trees, while Module 2 processes first-order logic query expressions. Therefore, in the present invention, both computation tree representation and first-order logic expression representation in complex logic queries can be processed simultaneously, thereby achieving comprehensive and diverse answers to complex questions. The specific process is as follows: Figure 3 shown.

[0112] For module 1, the present invention uses four query logic relationships to construct a query computation tree representation layer to obtain the answer entity representation. The query computation tree is an inference network, and its goal is to infer the most likely state of the root variable under the observation of the leaf node. The entity assignment of each variable is regarded as a state, and the relationship projection is regarded as the transition between states. The specific implementation steps are as follows:

[0113] Step 1: Construct the neural connection matrix

[0114] The neural connection matrix is ​​a matrix that describes the connection relationship between neurons in a neural network. In order to learn the low-dimensional representation of entities and relationships, the nodes and relationships in the knowledge graph are converted into vectors through embedding technology. These vectors can capture the structural information of the graph and be used for downstream tasks. The entity e and the relationship r are formed into a neural connection matrix M r :

[0115] M r = r(e i ,e j ) Formula (1)

[0116] where e i , e j are the i-th and j-th entities.

[0117] Step 2: Generate dependency graph

[0118] Assign a unique node to each variable and constant entity in each one-hop atom, and connect the nodes using undirected edges according to the one-hop atom, including the inverse relationship. Let Q * (v=e) represents the maximum truth value of the subquery of the root node v when v is assigned to an entity e. The Q of each node v is derived recursively * (v) to maximize the truth value of the query calculation tree and finally derive the root v ? Q * (v ? ). The dependency graph generation process of conjunction (∧) is expressed as follows:

[0119]

[0120] The dependency graph generation process of disjunction (∨) is expressed as follows:

[0121]

[0122] The dependency graph generation process of a positive relationship (r) is expressed as follows:

[0123] Q * (v ? )=ma(Q * (v k )⊙M r ) Formula (4) Inverse relationship The dependency graph generation process is expressed as follows:

[0124] Q * (v ? )=max(Q * (v k )⊙(1-M r )) Formula (5)

[0125] Step 3: Build the query calculation tree

[0126] In the query computation tree, each node v from the leaf node to the root computes Q * (v). The optimization problem is expressed as:

[0127]

[0128] Step 4: Optimize the query calculation tree

[0129] The forward pass calculates the Q of each node v in the tree * (v), the optimal entity allocation set is obtained by backward propagation. ? After the optimal allocation of , the optimal allocation of its sub-edges is obtained according to formula (6) and the four edge types.

[0130] Conjunction (∧) and disjunction (∨) Since the child nodes represent the same variables as the parent nodes, their optimal allocation is expressed as follows:

[0131]

[0132] The optimal allocation of positive relations (r) is expressed as follows:

[0133] v k = arg max{Q * (v k =e)Tr(e,e t )} Formula (8)

[0134] Inverse Relationship The optimal allocation is expressed as follows:

[0135] v k = arg max{Q * (v k =e)T(1-r(e,e t ))} Formula (9)

[0136] For module 2, the triples are converted into directed graphs without edge attributes. After generalization and fine-tuning, an enhanced sequence representation is obtained. Information from all directions is aggregated in each layer of calculation, including the following steps:

[0137] Step 1: Triplet conversion

[0138] Similarly, entities and relationships are placed in this module, but unlike the previous layer, this layer creates a relationship node r in each triple ht To connect entity h and relationship r, by mapping each relationship in graph G to a relationship node, the resulting graph is represented as:

[0139] L(G)=(E',R') Formula (10)

[0140] Where E'=E∪{r ht |r(h,t)=1}, 1 means the condition is true; no attribute edge R'=r(r ht ,t).

[0141] Step 2: Aggregate relationship edges

[0142] In the kth layer of Transformer, H represents the number of attention heads, and the multi-head attention is calculated as follows:

[0143]

[0144] where d h =d / H, d represents the dimension. The linear transformation Q is expressed as follows:

[0145]

[0146] W Q It is a weight matrix composed of {Q, K, V}, which maps the embedding vector of node e to the space of the attention head.

[0147] Next, the feedforward neural network FFN(x) acts on the multi-head attention weighted output, and the calculation is as follows:

[0148] FFN(x)=σ(xW1+b1)W2+b2 Formula (13)

[0149] Where σ is the activation function and W is the weight.

[0150] Step 3: Fine-tune inference

[0151] Randomly extract mask subgraphs of arbitrary shapes from the training set to pre-train the model, so that the receptive field of the sampled subgraph is increased, the query shape is more diverse, and the coverage of the original knowledge graph is improved. The masked entity set is expressed as:

[0152] E mask =E inter ∪E target Formula (14)

[0153] Among them, E inter represents the set of intermediate entities, E target Represents the set of target entities. The loss function for the fine-tuning reasoning phase is expressed as:

[0154]

[0155] Step 4: Construct enhanced sequence representation

[0156] The comprehensive module 1 obtains the query calculation tree representation sequence and the relationship node representation sequence. At the same time, in order to enable the Transformer layer in module 3 to effectively capture the logical relationship sequence representation in complex logical problems, these two graph representation sequences are spliced ​​to obtain an enhanced sequence representation.

[0157] For module three, a Transformer architecture with a Mixture of Experts (MoE) strategy is used. The large FFN is decomposed into multiple blocks through the MoE strategy, and a lightweight gating network is used to select experts to participate in the calculation. Therefore, it can effectively process the complex question-answer representation sequence of the knowledge graph based on the query calculation tree constructed by the present invention. The specific implementation steps are as follows:

[0158] Step 1: Capture the representation sequence

[0159] In order to effectively and comprehensively express complex logical queries, a Transformer with MoE strategy is applied to process sequence representation. The specific process is as follows: Figure 4 As shown, first, the enhanced representation sequence obtained by the previous two modules is fed into this module, and the multi-head attention in this module is used to capture the representation sequence as follows:

[0160]

[0161] Where s∈softmax, i is the index of s, and the output of FFN is the weighted average of the outputs of each expert.

[0162] Step 2: Predict the representation sequence

[0163] After obtaining the updated sequence, the method of masking each element is used to predict the masked element, and the MLP decoder is used to predict each masked element. Finally, a probability distribution P is output as follows:

[0164] P = softmax(MLP(X' i )K T ) Formula (17)

[0165] Where k is the initial element embedding matrix, so it can cover the entities in ε or the relations in R according to the type of missing elements. Finally, the loss is calculated using cross entropy and is calculated by predicting the similarity between the entities and the target to be predicted:

[0166]

[0167] where y t is the entry of the tth target label, P t is the t-th entry to be predicted, predicting the similarity score, using a single neuron and applying a sigmoid function to constrain the output to the [0,1] interval.

[0168] Based on the above three modules, a knowledge graph complex question answering method based on query computation tree is constructed. The test phase of this model is to perform link prediction. For each complex query, its answer is divided into simple answers and difficult answers according to whether the answer can be deduced from the existing edges in the graph. In the valid test set, the simple answer is the entity inferred by the edge in the training valid graph, while the difficult answer is the entity inferred by predicting the missing edge in the valid test. In the filtering setting, all simple and difficult answers are filtered out during the ranking process.

[0169] The predicted results are sorted. In order to measure the sorting results, the commonly used evaluation indicators for link prediction, namely, average reciprocal ranking MRR, average proportion Hits@1 of ranking less than or equal to 1, average proportion Hits@5 of ranking less than or equal to 5, and average proportion Hits@10 of ranking less than or equal to 10, are used as evaluation indicators. Their calculation formulas are as follows:

[0170]

[0171] Among them, |S| represents the number of facts; for the value of n in Hits@n, n={1,5,10}, Ⅱ is the indicator function, when Ⅱ(rank i ≤n) takes 1 when the condition is met, and takes 0 when it is not met.

[0172] Example 3

[0173] In Example 3, the knowledge graph complex question answering method based on the query computation tree of the present invention is applied to three existing complex question answering knowledge graph datasets for training and prediction. They are FB15k, FB15K-237 and NELL-995. Among them, FB15k is a subset extracted from Freebase, which is mainly used for the research of machine learning tasks such as knowledge graphs, link prediction, and relationship extraction. This dataset contains approximately 14,951 entities (such as people, places, movies, etc.) and 1,345 types of relationships (such as birthplace, date of birth, director, etc.), as well as approximately 592,213 training triples, 50,000 verification triples and 65,343 test triples. Each triple consists of a head entity, a relationship and a tail entity, in the form of (head entity, relationship, tail entity). The "15k" in the name of FB15k-237 means that the dataset contains approximately 15,000 keywords (entities), and "237" means that 237 types of relationships are defined in the dataset. The data size of FB15k-237 is moderate, neither too large to be difficult to handle nor too small to fully demonstrate the complexity of the knowledge graph. NELL-995 contains 995 precisely defined concepts and 135 relationships, and also has inverse triples of triples for reasoning tasks, providing richer contextual information. Due to the good robustness of this model, the same hyperparameter settings are used on different datasets, with the number of training iterations set to 300 rounds, the batch size to 1024, the learning rate to 5e-4, the embedding dimension to 256, and the number of attention heads to 4. The four indicators of MRR, Hits@1, Hits@5, and Hits@10 on the three datasets have achieved advanced performance, which also shows that the present invention performs well in the complex question-answering method of knowledge graph based on query computation tree.

[0174] Example 4

[0175] In Example 4, label smoothing regularization is adopted for the present invention. Label smoothing converts traditional hard labels (hard labels, i.e. one-hot encoded labels) into soft labels (soft labels), so that the model is not so absolutely dependent on the labels of training samples during the training process, thereby reducing overfitting and improving the robustness and generalization ability of the model. In an incomplete knowledge graph with complex problems, each entity is assigned a soft label, which can indicate that the entity may belong to certain countries, the gender of a person, the author of a book, and so on. The soft label gives the label a certain error tolerance probability, so that the model will not be overconfident when predicting, and can maintain good performance even in the face of inaccurate labels or noisy data. Based on this problem, different entity soft label smoothing parameters are set to analyze the present invention. FB15K-237 was used to verify whether the present invention is applicable to the label soft smoothing strategy, and different label soft smoothing parameters were set. The results showed that the entity soft smoothing parameter required on FB15K-237 with less training data was higher, which also corresponds to the entity soft label strategy. At the same time, it shows that the proposed knowledge graph complex question and answer method based on query computation tree has certain robustness and generalization ability for the entity soft label strategy.

[0176] The above description is only a preferred specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can make equivalent replacements or changes according to the technical scheme and inventive concept of the present invention within the technical scope disclosed by the present invention, which should be covered by the protection scope of the present invention.

Claims

1. A knowledge graph complex question answering method based on query computation tree, randomly sampling subgraphs according to knowledge graph data, characterized in that: include: Module 1: Query computation tree layer: forward and backward propagation through the tree-type computation graph, optimizing the subquery assignment on the variable node to maximize the possibility; Forward propagation is performed on the query computation tree to find the optimal solution, and backward propagation is used to assign intermediate variables to ensure interpretability; Module 2: Data preprocessing layer: convert the relations in the knowledge graph into relation nodes, convert the knowledge graph into a directed graph without attribute edges, and map the entities and relation nodes into low-dimensional continuous vectors; Module 3: Transformer layer based on expert hybrid strategy: Utilizing the sparse activation characteristics of the Transformer feedforward layer, the model capacity is expanded through a hybrid expert strategy to construct a query computation tree representation sequence and a relationship node representation sequence. This module is used to capture this sequence and update it to obtain a more comprehensive and specific semantic sequence. The above modules are combined to finally obtain a fully trained knowledge graph model. Each element in this representation is masked with the [MASK] label to predict the masked part. Finally, the prediction results are sorted, and the link prediction evaluation indicators average reciprocal ranking MRR, average proportion Hits@1 of ranking less than or equal to 1, average proportion Hits@5 of ranking less than or equal to 5, and average proportion Hits@10 of ranking less than or equal to 10 are used as evaluation indicators.

2. The knowledge graph complex question answering method based on query computation tree according to claim 1, characterized in that: For module one, we embed the forward-backward propagation method to reduce the search space, and study FOL query for local computations involving trees to find the optimal solution efficiently.

3. The knowledge graph complex question answering method based on query computation tree according to claim 1, characterized in that: For module 2, the triple conversion method is used to convert relations into relation nodes and the knowledge graph into a directed graph without edge attributes.

4. The knowledge graph complex question answering method based on query computation tree according to claim 1, characterized in that: For module three, we construct a query computation tree representation sequence and a relationship node representation sequence, and use the MOE expert hybrid strategy to capture this sequence and update it to construct a more comprehensive and specific semantic sequence.

5. The knowledge graph complex question answering method based on query computation tree according to claim 1, characterized in that: In the query calculation tree layer of module 1, the following steps are performed: S1.

1. Constructing the neural connection matrix: The nodes and relations in the knowledge graph are converted into vectors through embedding methods. The vectors capture the structural information of the graph and are used for downstream tasks. The entities e and relations r are formed into a neural connection matrix M. r : M r = r(e i , e j ) Formula (1) where e i , e j are the i-th and j-th entities; S1.

2. Generate dependency graph: Assign a unique node to each variable and constant entity in each one-hop atom, and connect the nodes using undirected edges according to the one-hop atom, including the inverse relationship; let Q * (v=e) represents the maximum truth value of the subquery of the root node v when v is assigned to an entity e; the Q of each node v is derived recursively * (v) to maximize the truth value of the query calculation tree and finally derive the root v ? Q * (v ? ); The dependency graph generation process of conjunction (∧) is expressed as follows: The dependency graph generation process of disjunction (∨) is expressed as follows: The dependency graph generation process of a positive relationship (r) is expressed as follows: Q * (v ? )=max(Q * (v k )⊙M r ) Formula (4) Inverse Relationship The dependency graph generation process is expressed as follows: Q * (v ? )=max(Q * (v k )⊙(1-M r )) Formula (5) S1.3, build query calculation tree: In the query computation tree, each node v from the leaf node to the root computes Q * (v); The expression of the optimization problem is: S1.

4. Optimize the query calculation tree: The forward pass calculates the Q of each node v in the tree * (v), the optimal entity allocation set is obtained by backward propagation; after obtaining the root v ? After the optimal allocation of , the optimal allocation of its sub-edges is obtained according to formula (6) and the four edge types; Conjunction (∧) and disjunction (∨) Since the child nodes represent the same variables as the parent nodes, their optimal allocation is expressed as follows: The optimal allocation of positive relations (r) is expressed as follows: Inverse Relationship The optimal allocation of is expressed as follows:

6. The knowledge graph complex question answering method based on query computation tree according to claim 1, characterized in that: Module 2, data preprocessing layer, performs the following steps: S2.1, triple conversion: Put entities and relationships into this module and create a relationship node r in each triple ht To connect entity h and relationship r, by mapping each relationship in graph G to a relationship node, the resulting graph is represented as: L(G)=(E',R') Formula (10) Where E'=E∪{r ht |r(h,t)=1}, 1 means the condition is true; no attribute edge R'=r(r ht ,t); S2.2, aggregation relationship edge: In the kth layer of Transformer, H represents the number of attention heads, and the multi-head attention is calculated as follows: where d h =d / H, d represents the dimension; the linear transformation Q is expressed as follows: W Q is a weight matrix consisting of {Q, K, V}, which maps the embedding vector of node e to the space of the attention head; Next, the feedforward neural network FFN(x) acts on the multi-head attention weighted output, and the calculation is as follows: FFN(x)=σ(xW1+b1)W2+b2 Formula (13) Where σ is the activation function and W is the weight; S2.3, fine-tuning reasoning: Randomly extract mask subgraphs of arbitrary shapes from the training set to pre-train the model, so that the receptive field of the sampled subgraph is increased, the query shape is more diverse, and the coverage of the original knowledge graph is improved. The masked entity set is expressed as: E mask =E inter ∪E target Formula (14) Among them, E inter represents the set of intermediate entities, E target represents the set of target entities; the loss function for the fine-tuning reasoning phase is expressed as: S2.

4. Construct enhanced sequence representation: The query computation tree representation sequence and the relationship node representation sequence are concatenated to obtain an enhanced sequence representation.

7. The knowledge graph complex question answering method based on query computation tree according to claim 1, characterized in that: Module 3 is based on the Transformer layer of the expert mixture strategy, and performs the following steps: S3.

1. Capture representation sequence: Apply a Transformer containing the MoE strategy to process the sequence representation. First, feed the enhanced representation sequence obtained by the previous two modules into this module, and use the multi-head attention in this module to capture the representation sequence as follows: Where s∈softmax, i is the index of s, and the output of FFN is the weighted average of each expert’s output; S3.2, predict the representation sequence: After obtaining the updated sequence, the method of masking each element is used to predict the masked element, and each masked element is predicted through the MLP decoder; finally, a probability distribution P is output as follows: P = softmax(MLP(X' i )K T ) Formula (17) Where k is the initial element embedding matrix, so it can cover the entities in ε or the relations in R according to the type of missing elements; finally, the loss is calculated using cross entropy and is calculated by predicting the similarity between the entities and the target to be predicted: where y t is the entry of the tth target label, P t is the t-th entry to be predicted, predicting the similarity score, using a single neuron and applying a sigmoid function to constrain the output to the [0,1] interval.

8. The knowledge graph complex question answering method based on query computation tree according to claim 1, characterized in that: The calculation formula of the evaluation index is as follows: Among them, |S| represents the number of facts; for the value of n in Hits@n, n={1,5,10}, Ⅱ is the indicator function, when Ⅱ(rank i ≤n) takes 1 when the condition is met, and takes 0 when it is not met.

Citation Information

Cited By

  • Causal modeling and logic verification combined interpretable student data generation method

    CN122472105A