Large language model joint inference method based on knowledge graph-enhanced chain-of-thought prompt
By forming local knowledge subgraphs and explicit decomposition encoding of graph reasoning models, the accuracy and interpretability issues of large language models when utilizing structured knowledge graphs are solved, achieving efficient and accurate natural language reasoning.
Patent Information
- Application Number
- PCT/CN2025/074150
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-07-22
- Filing Date
- 2025-01-23
- Publication Date
- 2026-01-29
AI Technical Summary
Large language models suffer from problems such as parameter errors, high training costs, cognitive differences, and missing topological information when utilizing structured knowledge graphs, resulting in insufficient reasoning accuracy and interpretability.
By extracting multi-hop neighborhood knowledge triples from problem entities to form local knowledge subgraphs, explicit decomposition and encoding are performed using a graph reasoning model. Combined with cross-attention and matrix transformation modules, thought chain hints are generated to assist the large language model in reasoning.
It improves the accuracy and interpretability of multi-hop reasoning in large language models, reduces time complexity, enhances the ability to analyze complex problems, and reduces the negative impact of irrelevant reasoning paths.
Smart Images

Figure CN2025074150_29012026_PF_FP_ABST
Abstract
Description
A Joint Reasoning Method for Large Language Models Based on Knowledge Graph-Enhanced Mind Chain Hints [Technical Field]
[0001] This invention belongs to the field of natural language reasoning technology, and more specifically, relates to a joint reasoning method for a large language model based on knowledge graph-enhanced thought chain prompts. [Background Technology]
[0002] Knowledge augmentation of large language models is a crucial task in the field of natural language processing. With the development of large-scale pre-trained language models, traditional static reasoning models that rely on parametric knowledge are susceptible to illusions when dealing with knowledge-intensive tasks, resulting in outputs containing factual errors.
[0003] To address the illusion problem caused by the black-box nature of large language models, accessing external knowledge graphs is an effective solution. Knowledge graphs store structured knowledge triples, providing relevant information and background knowledge for large language model reasoning, thus improving the accuracy and interpretability of the reasoning. However, due to differences in data structures, large language models struggle to directly retrieve and utilize structured knowledge graphs. Therefore, the task of knowledge graph-enhanced large language models has been proposed, aiming to provide effective methods for structured knowledge retrieval and large language model enhancement, ensuring that large language models can effectively utilize structured external knowledge to generate accurate and reliable natural language responses.
[0004] Currently, pluggable retrieval enhancement methods are commonly used to enhance knowledge in large language models. However, knowledge enhancement for large language models faces the following challenges:
[0005] (1) Due to the huge parameter scale and high training cost of large language models, they are not trained frequently. Therefore, the parameter knowledge inside the model often has errors and is outdated, making it difficult to guarantee the accuracy of the thought process in multi-hop reasoning, and thus making it difficult to ensure the reliability of the generated answer.
[0006] (2) There is a cognitive difference between large language models and knowledge retrieval machines. Knowledge retrieval machines usually retrieve related facts based on the similarity of embedded representations. However, in complex reasoning tasks, the relevance of knowledge cannot be equated with its usefulness in the reasoning process. This phenomenon leads to the large language model being misled, which in turn aggravates the problem of illusion.
[0007] (3) Large language models cannot directly use structured knowledge triples. Directly serializing discrete knowledge triples will lead to the loss of topological information of knowledge. In the reasoning process, the continuity of reasoning thinking cannot be guaranteed, and it is difficult to deal with complex problems. [Summary of the Invention]
[0008] To address the aforementioned deficiencies or improvement needs of existing technologies, this invention provides a large language model joint reasoning method based on knowledge graph-enhanced thinking chain prompts, aiming to improve the accuracy and interpretability of large language model joint reasoning.
[0009] To achieve the above objectives, according to a first aspect of the present invention, a joint reasoning method for a large language model based on knowledge graph-enhanced thought chain prompts is provided, comprising:
[0010] Extract the question entity from the original question text, extract all knowledge triples in the multi-hop neighborhood of the question entity from the knowledge graph to form a local knowledge subgraph. The number of jump steps in the multi-hop neighborhood is T steps, and each step corresponds to a reasoning stage, where T is a positive integer greater than 1.
[0011] The original question text is decomposed into S sub-question texts, and the original question text and the S sub-question texts are concatenated to obtain the concatenated question text, where S≤T;
[0012] The concatenated problem text is input into the graph reasoning model to obtain the weighted entity distribution. The graph reasoning model includes:
[0013] A question encoder is used to convert the concatenated question text into a question embedding representation p and a hidden layer representation H. q ;
[0014] T cross-attention modules are used to calculate the cross-attention representation of p. t is the number of the reasoning stage, t = 1, 2, ..., T;
[0015] This indicates the fusion module, used for fusion. and p t-1 The reasoning embedding representation p of stage t is obtained. t ;
[0016] Matrix transformation module, used to make p t After sequential processing using a multilayer perceptron and a nonlinear activation function, the relation distribution matrix R is obtained. t R t Different elements in the graph represent the confidence levels of different connecting edges in the knowledge graph.
[0017] Matrix transfer module, used to transfer data according to the R... t Construct the inference transition matrix W t The W t The different elements in the graph represent the confidence levels of different connected edges in the local knowledge subgraph.
[0018] The entity distribution output module is used to output the entity distribution e. t-1 With the Wt Multiplying them together yields the entity distribution e, representing the confidence level of each entity at step t. t Then, the entity distributions of all stages are summed using weighted averages to obtain the weighted entity distribution. And output, Each element in the expression represents the confidence level of different entities as answer entities;
[0019] From the weighted entity distribution Extract the top G answer entities with the highest confidence from the question entity, and use the inference transition matrix to backtrack the inference process of each answer entity to generate an inference path from the question entity to the corresponding answer entity, where G is a positive integer;
[0020] The reasoning path is used to assist the large language model in predicting the answer to the original question text.
[0021] In some embodiments, the graph reasoning model is trained, and the training method includes:
[0022] Construct an initial natural language question-answering sample set. Each sample in the sample set contains the original text question, knowledge graph, and corresponding answer entity.
[0023] Extract the question entity from the original question text, extract all knowledge triples in the multi-hop neighborhood of the question entity from the knowledge graph to form a local knowledge subgraph, the local knowledge subgraph contains the corresponding answer entity, and obtain the target entity distribution a as the label;
[0024] The original question text is decomposed into S sub-question texts, and the original question text and the S sub-question texts are concatenated to obtain the concatenated question text;
[0025] The concatenation problem text is input into the graph reasoning model for training, and the training loss function is:
[0026] In the formula, L represents the training loss of the graph reasoning model. Let 'a' be the weighted entity distribution and 'a' be the target entity distribution.
[0027] In some embodiments, in the entity distribution output module, the weighted summation of the entity distributions across all stages includes:
[0028] The problem embedding representation p is processed sequentially through a multilayer perceptron and a normalization function to obtain T weights β. t ~β T ;
[0029] The weighted entity distribution is obtained by summing the entity distributions of all stages using the following formula.
[0030] In the formula, β t Let t be the weight.
[0031] In some embodiments, the t-th cross-attention module computes the cross-attention representation of p. The process includes:
[0032] Calculate the attention query Q of p. t And calculate the H q Attention key K t And attention value V t ,
[0033] For the Q t K t and V t Attention calculations are performed to obtain the cross-attention representation. The calculation formula is:
[0034] In the formula, (K t ) T Indicates K t Perform matrix transpose, where dim represents the dimension of the problem embedding representation p.
[0035] In some embodiments, the relation distribution matrix R t R contains the confidence of directed connections between all pairs of entities in the knowledge graph. t The k-th element This represents the confidence level of the connection edge with index k in the knowledge graph.
[0036] According to the R t Construct the inference transition matrix W t The process includes:
[0037] Obtain the adjacency matrix representation M of the local knowledge subgraph, where the elements in the i-th and j-th rows of M are M'''''''''''''''''''''''''''''''''''''" ... ij When there is no connecting edge between the head entity i and the tail entity j, M ij =-1, when there is a connecting edge between the head entity i and the tail entity j, M ij The index of the connecting edge between the head entity i and the tail entity j;
[0038] Construct the inference transition matrix W t W t The elements in the i-th and j-th rows are
[0039] Wherein, the inference transition matrix W tThe matrix dimension of M is the same as that of the adjacency matrix representation.
[0040] In some embodiments, from the weighted entity distribution Extract the top G answer entities with the highest confidence from the given data;
[0041] For the g-th extracted answer entity E g G = 1, 2, ..., G; using the inference transition matrix to backtrack the reasoning process of each answer entity, a transition from the question entity to the answer entity E is generated. g The reasoning process includes:
[0042] Set T path sets Storage from question entity to answer entity E g The path with length t is a path that jumps. path and score are respectively The path set and score set in the data; for any implement:
[0043] Step S41: Initialize the operation, let path = E g score = 0, step = t;
[0044] Step S42: For each path in the current path... x x is the path index, based on the current path. x The entity located at the end of the backtracking direction is the tail entity V, which is determined by the inference transition matrix W. step Find all head entities that have connecting edges with tail entity V, and add the found head entities to the current path along the backtracking direction. x Get the updated path, and set the current path x score x The score of the path containing the newly added edge is obtained by adding the confidence score of the newly added edge to the score of the path containing the newly added edge.
[0045] Step S43: Determine if the current step is less than or equal to 1. If not, set step = step - 1 and jump to step S42. Otherwise, end the iteration and output the updated value.
[0046] Get the updated set of T paths Select the path with the highest preset number of scores as the path from the question entity to the answer entity E. g The reasoning path;
[0047] Retrieve the entities from question entity to answer entity E1 to E1 respectively. G The reasoning path.
[0048] In some of these embodiments, for each answer entity E g The path with the highest confidence is selected as the prompt information to assist the large language model in prediction.
[0049] According to a second aspect of the invention, an electronic device is provided, including a memory and a processor, the memory storing a computer program, the processor executing the computer program to implement the steps of the method as described in any of the preceding claims.
[0050] According to a third aspect of the invention, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, performs the steps of the method described in any of the preceding claims.
[0051] According to a fourth aspect of the invention, a computer program product is provided, comprising a computer program or instructions that, when executed by a processor, implement the steps of the method described in any of the preceding claims.
[0052] In summary, compared with the prior art, the large language model joint reasoning method based on knowledge graph-enhanced thinking chain prompts provided by this invention has the following beneficial effects:
[0053] 1. This invention first uses a graph reasoning model to obtain answer entities with high confidence in local knowledge subgraphs. Then, it uses a reasoning transition matrix to backtrack the reasoning process of each answer entity, generating a reasoning path from the question entity to the corresponding answer entity. The reasoning path is then used to assist a large language model in predicting the answer to the original question text. In this way, compared with the general breadth-first search algorithm, the power-law time complexity can be reduced to linear time complexity, thus improving the efficiency of answer search.
[0054] 2. Before using the graph reasoning model, this invention decomposes the original question text into sub-questions and then concatenates them. The concatenated question text is then input into the graph reasoning model. In this way, by explicitly decomposing and encoding complex questions, and utilizing the semantic characteristics of the sub-questions implicit in the question embedding representation in the high-dimensional vector space, the graph reasoning model can be guided to focus on different knowledge triples at different reasoning stages. This significantly reduces the problem of graph reasoning models falling into over-reasoning due to the continuous accumulation of computational errors in relation distribution, improves the accuracy of multi-hop graph reasoning, and further reduces the negative impact of irrelevant reasoning paths on the reasoning of large language models, thus ensuring the factuality and reliability of the reasoning of large language models.
[0055] 3. The graph reasoning model used in this invention includes a question encoder, a cross-attention module, a representation fusion module, a matrix transformation module, a matrix transition module, and an entity distribution output module. Through the designed graph reasoning model, the analytical capabilities of large language models for complex problems can be fully utilized. By using explicit sub-problems and the cross-attention module, the graph reasoning model is guided to assign higher transition probabilities to highly supportive relationships in the local knowledge subgraph at each step of the reasoning process, reducing the interference of irrelevant relationships on the reasoning process. This significantly reduces the accumulating bias in transition probabilities along the reasoning path, which can mislead the reasoning process. The introduced representation fusion module, by combining the cross-attention representation of the current stage with the reasoning embedding representation of the previous stage, simulates the continuity of human thought when reasoning about complex problems. This allows the current step of the graph reasoning process to consider the reasoning history of the previous stage, not only matching the thought process of large language models but also fully utilizing the unique relevance and hierarchy of knowledge graphs, enhancing the continuity of the graph reasoning process and further improving the accuracy of reasoning.
[0056] 4. In a specific embodiment, a loss function is introduced before applying the graph reasoning model. Training a graph reasoning model can enable it to converge quickly to the expected value, thus allowing it to accurately predict the confidence level of each answer entity based on the input question text.
[0057] 5. In a specific embodiment, a method for constructing the inference transition matrix W is proposed. t The specific formula provides a way to quickly construct the inference transition matrix and improve data processing speed.
[0058] 6. In a specific embodiment, a specific method for generating thought chain prompts is proposed. This method provides an effective way for large language models that can only accept text sequences as input to access multi-source heterogeneous knowledge data. It eliminates the limitations on the application of large language models due to differences in data modalities, and enables large language models to access external data using a general solution for different types of tasks and different modalities of data. [Attached Image Description]
[0059] Figure 1 is a flowchart of the steps of the joint reasoning method of a large language model based on knowledge graph-enhanced mind chain prompts in an embodiment of the present invention.
[0060] Figure 2 is a relationship diagram of local knowledge subgraphs in one embodiment of the present invention;
[0061] Figure 3 is a data processing diagram of a graph reasoning model in one embodiment of the present invention;
[0062] Figure 4 is a schematic diagram of the process of generating mind chain prompts in one embodiment of this application.
Detailed Implementation Methods
[0063] 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 and not intended to limit the invention. Furthermore, the technical features involved in the various embodiments of this invention described below can be combined with each other as long as they do not conflict with each other.
[0064] Figure 1 shows a flowchart of the steps of the large language model joint reasoning method based on knowledge graph-enhanced thinking chain prompts in an embodiment of the present invention, which mainly includes steps S1 to S5. Each step is described in detail below.
[0065] Step S1: Extract the question entity from the original question text, extract all knowledge triples in the multi-hop neighborhood of the question entity from the knowledge graph to form a local knowledge subgraph. The number of jump steps in the multi-hop neighborhood is T steps, and each step corresponds to a reasoning stage, where T is a positive integer greater than 1.
[0066] In this step, the input question text and knowledge graph data need to be preprocessed. Specifically, the question entities involved in the question text are extracted using entity recognition methods, and the question entities are linked to the knowledge graph using entity linking methods. All knowledge triples within the multi-hop neighborhood of the question entities are extracted to form a local knowledge subgraph, where the entities in the local knowledge subgraph represent the text content. Figure 2 shows a relationship diagram of the local knowledge subgraph in one embodiment of the present invention, where each hop corresponds to a reasoning stage, indicating that the entity at the end of the current subgraph is used as the head entity to find the associated tail entity. Furthermore, the local knowledge subgraph can be pruned using reasoning templates or similarity representations to reduce storage space overhead.
[0067] Step S2: Decompose the original question text into S sub-question texts and concatenate the original question text and the S sub-question texts to obtain the concatenated question text.
[0068] Where S≤T.
[0069] In one embodiment, a large language model can be used to decompose the question text into multiple reasoning sub-questions and concatenate them with the question text to obtain a concatenated question text. Specifically, this step may include the following processes:
[0070] Step S21: Input the question text, the question decomposition instruction (instruction is manually constructed by the user), and the upper limit T for the number of sub-questions into the Large Language Model (LLM). Instruct the LLM to decompose the question text q into at most T sub-questions. After decomposition, S sub-question texts q1, q2, ..., q3 are obtained.S Where S≤T is the number of sub-problem texts obtained after decomposing the problem text q using the Large Language Model (LLM), as shown in the following formula: q1,q2,......,q S =LLM(q,instruct,T)
[0071] Step S22: Combine the question text q and the sub-question texts q1, q2, ..., q S By concatenating the strings, we obtain the concatenated problem text [q:q1,q2,......,q S ].
[0072] Step S3: Input the concatenated question text into the graph reasoning model to obtain the weighted entity distribution.
[0073] The graph reasoning model includes: a question encoder, T cross-attention modules, a representation fusion module, a matrix transformation module, and an entity distribution output module.
[0074] Figure 3 shows the data processing process of the graph reasoning model in one embodiment of the present invention.
[0075] The question encoder is used to convert concatenated question text into a question embedding representation p and a hidden layer representation H. q In one embodiment, the question encoder can use an existing pre-trained language model, BERT. Specifically, it concatenates the question text [q:q1,q2,......,q...]. S Inputting the pre-trained language model BERT yields a question embedding representation p with dimension 1×dim and a hidden layer representation H with dimension |q|×dim. q =(h1,h2…,h |q| ), |q| represents the concatenation of the problem text [q:q1,q2,......,q S The total number of characters contained in h i Let p be the parameters of the i-th hidden layer, and dim be the dimension of the embedding representation output by the pre-trained language model BERT. |q| =BERT([q:q1,q2,......,q) S ])
[0076] T cross-attention modules are used to compute the cross-attention representation of p. t represents the inference stage number, t = 1, 2, ..., T. Since the graph inference process on the local knowledge subgraph in step S1 is divided into T stages, T cross-attention modules are correspondingly set in the graph inference model. The question embedding representation p is input into each of the T cross-attention modules to obtain T cross-attention representations. t = 1, 2, ..., T. In a specific embodiment, the process of each cross-attention module calculating the cross-attention representation includes:
[0077] First, calculate the attention query Q of p. t And calculate H q Attention key K t And attention value V t Specifically, using the weight matrix of stage t (All dimensions are dim × dim) Attention queries for stage t can be calculated. Attention key and attention value
[0078] Then, the attention calculation formula is used to calculate...
[0079] Among them, (K) t ) T The meaning is for attention key K t The matrix transpose operation, dim is the dimension of the embedding representation output by the pre-trained language model BERT.
[0080] Wherein, the dimension of the question embedding p is 1×dim, and the hidden layer represents H. q The dimension is |q|×dim, and the weight matrix for stage t is... The dimensions are all dim × dim, therefore the attention query Q t The dimension is 1×dim, and the attention key is K. t The dimension is |q|×dim, and the attention value is V. t The dimension of Q is |q| × dim. Further, Q... t (K t ) T The result after Softmax normalization has a dimension of 1×|q|. The dimension is 1×|q|, due to the attention value V t The dimension is |q|×dim, so The result dimension is 1×dim, that is, It is 1×dim dimension.
[0081] The fusion module indicates that it is used for fusion. and p t-1 The reasoning embedding representation p of stage t is obtained. t The reasoning embedding representation p of stage t. t Cross-attention representation for stage t The reasoning embedding representation p of stage t-1 t-1The sum of vectors, specifically expressed as:
[0082] In this invention, the cross-attention representation of the current stage is combined. The reasoning embedding representation of the previous stage enhances the continuity of the graph reasoning process. Since t = 1, 2, ..., T, the reasoning embedding representation p of the t = 0 stage can be set. 0 It is a zero vector with dimension 1×dim to meet the computational requirements of the inference embedding representation at the initial stage t=1.
[0083] The matrix transformation module is used to make p t After sequential processing using a multilayer perceptron and a nonlinear activation function, the relation distribution matrix R is obtained. t R t Different elements in the representation indicate the confidence level of different connections in the knowledge graph. Specifically, the inference embedding representation p of stage t is used. t The calculation proceeds sequentially through a multilayer perceptron and a nonlinear activation function to obtain the relational distribution matrix R for the t-th hop. t R t Each element in R represents the probability of different connections in the original knowledge graph, specifically expressed as: t =Sigmoid(MLP(p t ))
[0084] In one specific embodiment, the relation distribution matrix R t R contains the confidence of directed connections between all pairs of entities in the knowledge graph. t The k-th element This represents the confidence level of the connection edge with index k in the knowledge graph. That is, if the knowledge graph has h entities, the relation distribution matrix R... t The dimension can be h×h, and the number of connecting edges between the head and tail entities formed by any entity as the head entity and any entity as the tail entity is h×h. The relation distribution matrix R t The h×h elements in the equation correspond one-to-one with the confidence scores of the h×h connected edges.
[0085] The matrix transfer module is used to transfer data based on R. t Construct the inference transition matrix W t W t Different elements in R represent the confidence levels of different connected edges in the local knowledge subgraph. t The prediction process forecasts the confidence levels of all connections in the knowledge graph. Therefore, it also includes the confidence levels of connections formed at each stage of the local knowledge subgraph formed in step S1. The matrix transition module's role is to transform R... tThe confidence scores of the connecting edges in the local knowledge subgraph are extracted.
[0086] In practice, the local knowledge subgraph is stored in the form of an adjacency matrix representation M. Assuming the local knowledge subgraph has r entities, the number of connecting edges between the head and tail entities (where any entity is the head or tail entity) is r×r. The adjacency matrix representation M can have a dimension of r×r, and each of the r×r elements of M corresponds to an index of one of the r×r connecting edges. The elements in the i-th and j-th rows of M are... ij This corresponds to the index of the connecting edge between head entity i and tail entity j. In the local knowledge subgraph, the indices of the actual connecting edges can start from 1. For example, if there are 10 connecting edges in total, the indices will be 1 to 10. If there is no connecting edge between head entity i and tail entity j in the local knowledge subgraph, then M in M... ij It can be marked as an invalid value, for example, set to a negative value, specifically -1. If there is no connecting edge between the head entity i and the tail entity j in the local knowledge subgraph, then M ij Here are the indices of the connecting edges between the head entity i and the tail entity j. Therefore, the adjacency matrix representation M actually expresses the local knowledge subgraph constructed in step S1.
[0087] According to R t Construct the inference transition matrix W for stage t t The process includes:
[0088] Obtain the adjacency matrix representation M of the local knowledge subgraph;
[0089] Construct the inference transition matrix W t W t The elements in the i-th and j-th rows are
[0090] Wherein, the inference transition matrix W t The matrix dimension of M is the same as the matrix dimension of its adjacency matrix representation. That is, if in the adjacency matrix representation M, M... ij If the value is the edge index k, then from R t Find the element at edge index k M ij Replace with If the adjacency matrix represents M, then M ij The value is an invalid value of -1, indicating that the connecting edge does not exist in the local knowledge subgraph. Therefore, M is set to -1. ij Set all elements to 0. After all elements have been replaced, the resulting matrix is the inference transition matrix W. t .
[0091] Since the preceding text generated T relationship distribution matrices R based on T stages, 1 ~R T Therefore, through the above process, T inference transition matrices W are also formed. 1 ~W T .
[0092] The entity distribution output module is used to output the entity distribution e t-1 With W t Multiplying yields the entity distribution e t Then, the entity distributions of all stages are summed using weighted averages to obtain the weighted entity distribution. It outputs the confidence level of each element in the entity distribution as the answer entity.
[0093] Specifically, the sub-problem reasoning process is transformed into multi-hop reasoning within a local knowledge subgraph. Matrix operations are used to obtain the confidence scores of entities in the local knowledge subgraph at different reasoning stages. The weighted entity distribution is represented as: e t =e t-1 W t β = Softmax(MLP(p))
[0094] Where t is the number of the reasoning stage, e t For the entity distribution in stage t, W t Let be the reasoning transition matrix at stage t, β be the attention weights at different reasoning stages, Softmax be the normalized exponential function, and q be the embedding representation of the input question. This represents a weighted entity distribution.
[0095] When t=1, e 0 This corresponds to the distribution of problem entities, and its length is the number of entities in the local knowledge subgraph. Only the element corresponding to the problem entity node is 1, and the rest are 0. For example, if the local knowledge subgraph has 4 nodes, labeled nodes 1 to 4, and node 1 is the problem entity, then: e 0 =[1 0 0 0]
[0096] e 1 This represents the confidence level of each entity node at the first hop;
[0097] And so on, e t This represents the confidence level of each entity node at hop t;
[0098] After completing T-step jumps, the confidence scores of each entity node corresponding to each jump are weighted and summed to obtain the confidence score of each entity as the answer entity.
[0099] Understandably, the reasoning model shown above is the result of training, and the training methods include:
[0100] Construct an initial natural language question-answering sample set. Each sample in the sample set contains the original text question, knowledge graph, and corresponding answer entity.
[0101] Extract the question entity from the original question text, extract all knowledge triples in the multi-hop neighborhood of the question entity from the knowledge graph to form a local knowledge subgraph, and the local knowledge subgraph contains the corresponding answer entity to obtain the target entity distribution a as the label;
[0102] The original question text is decomposed into S sub-question texts, and the original question text and the S sub-question texts are concatenated to obtain the concatenated question text;
[0103] The concatenation problem text is input into the graph inference model for training, and the graph inference model parameters are updated using gradient descent until convergence. The training loss function is:
[0104] In the formula, L represents the training loss of the graph reasoning model. Let 'a' be the weighted entity distribution and 'a' be the target entity distribution.
[0105] Step S4: From weighted entity distribution The top G answer entities with the highest confidence are extracted from the problem. The reasoning process of each answer entity is traced back using the reasoning transition matrix to generate the reasoning path from the question entity to the corresponding answer entity.
[0106] G is a positive integer.
[0107] From weighted entity distribution The top G answer entities with the highest confidence are extracted, namely E1 to E2. G .
[0108] Figure 4 shows a schematic diagram of the process of generating thought chain prompts in one embodiment of this application. In step S3, starting from the question entity, the prompts are generated sequentially through the reasoning transition matrix W from the 1st to the Tth step. t Calculations are performed to find each answer entity. Therefore, in this step, the inverse calculation of step S3 can be performed, starting from the answer entity, and the inverse calculation is performed sequentially from the Tth jump to the 1st jump through the reasoning transition matrix to trace back to the question entity, obtain the reasoning path from the question entity to the corresponding answer entity, and obtain the thought chain hint.
[0109] In practice, for the g-th extracted answer entity E g By using the inference transition matrix to backtrack the reasoning process of each answer entity, a path from the question entity to the answer entity E is generated. g The reasoning process includes:
[0110] Set T path sets Storage from question entity to answer entity E g The path with length t is a path that jumps. path and score are respectively The path set and score set in the data; for any implement:
[0111] Step S41: Initialize the operation, let path = E g score = 0, step = t;
[0112] Step S42: For each path in the current path... x x is the path index, based on the current path. x The entity located at the end of the backtracking direction is the tail entity V, which is determined by the inference transition matrix W. step Find all head entities that have connecting edges with tail entity V, and add the found head entities to the current path along the backtracking direction. x Get the updated path, and set the current path x score x The score of the path containing the newly added edge is obtained by adding the confidence score of the newly added edge to the score of the path containing the newly added edge.
[0113] Step S43: Determine if the current step is less than or equal to 1. If not, set step = step - 1 and jump to step S42. Otherwise, end the iteration and output the updated value.
[0114] Get the updated set of T paths Select the path with the highest preset number of scores as the path from the question entity to the answer entity E. g The reasoning path;
[0115] Retrieve the entities from question entity to answer entity E1 to E1 respectively. G The reasoning path.
[0116] In some embodiments, considering storage costs, in step S42, after obtaining the updated path, the path will continue to be pruned according to the score of each path, and only the paths with the highest scores will be retained.
[0117] In some embodiments, when obtaining the updated set of T paths Only the path with the highest score is selected as the path from the question entity to the answer entity E. g The reasoning path, at this point, is from the question entity to the answer entity E1~E G There are a total of G reasoning paths.
[0118] The process will be explained in detail below.
[0119] Based on weighted entity distribution Select G answer entities E1, E2, ..., E with the highest confidence. G (The size of G is set by the user), for each answer entity E g We initialize T path sets. They are used to store the answer entity E respectively. g The 1-hop, 2-hop, ..., T-hop inference paths to the problem entity, where each initial path set Where path0 = E m Represented by the answer entity E m For the tail entity, 0 is the zero-hop path, and score0 is the confidence score of the current path, initially set to 0 (since initialization starts from the answer entity, it can be considered as starting from the answer entity E). m A path that is a tail entity and has no preceding entity; subsequent paths will be formed by adding new preceding entities on top of it during the backtracking process.
[0120] For the backtracking steps step = t, t-1, ..., 1, for the path set... Each path in (x is the number of the current path), extract the tail entity V of the path and the entity number index(V) of the entity, then the reasoning transition matrix W of the backtracking step can be obtained. step Find the current path x All preceding entity sets Specifically: retrieve the inference transition matrix W for the backtracking step. step The index(V) column, for all elements in this column. (Where, j = index(V), and Z is the number of entities in the local knowledge subgraph), if If the value is not 0, it means that there exists an edge starting from entity i∈{i} and extending along relation M. ij Arrival at entity j(M) ij The relationship number between the head entity i and the tail entity j is assigned, where entity j is the current path. x The tail entity V). Then, entity i is treated as the predecessor node of the current path and added to the current path path. x The updated It can be represented as:
[0121] k = M ij
[0122] Where → indicates adding entity i as a preceding entity to the path path. x R step M is the relational distribution matrix of the backtracking step step. ij Number the connection between head entity i and tail entity j, and define the new path. The confidence score is the original confidence score. x Add the relationship M between entity i and entity j ij probability
[0123] Step S5: Use inference paths to assist the large language model in predicting the answer to the original question text.
[0124] The final inference path P1, P2, ..., P obtained in the previous operation S4 G This refers to the thought chain hints from the question entity to the answer entity. We call these final reasoning paths knowledge graph-enhanced thought chain hints. We define the question text q and the knowledge graph-enhanced thought chain hints P1, P2, ..., P... G Input into a large language model (LLM) to generate the final answer: Answer = LLM(q, P1, P2, ..., P G )
[0125] Since the local knowledge subgraph is a directed cyclic graph, if we start directly from the problem entity and use a general breadth-first search algorithm, the time complexity of path generation is exponential O(n log n). T ), where n is the number of knowledge triples in the local knowledge subgraph, and T is the number of hops in the multi-hop neighborhood. That is, as the number of knowledge triples n in the local knowledge subgraph increases, the algorithm's running time increases by a power of n (T), which is unacceptable for the program. Therefore, this invention proposes the above-mentioned path backtracking algorithm based on bundle search. For candidate entities with high confidence, the search tree can be pruned by combining the inference transition matrix, thereby generating a multi-hop inference process that backtracks from the answer entity, generating a multi-hop inference path from the question entity to the answer entity, reducing the power-law time complexity to linear time complexity.
[0126] In this invention, by extracting question entities from the original question text, all knowledge triples within the multi-hop neighborhood of the question entities are extracted from the knowledge graph to form a local knowledge subgraph. A large language model is used to explicitly decompose and encode complex questions. A question encoder is combined to obtain the embedding representations of the original question and sub-questions in a high-dimensional vector space. A cross-attention module and a representation fusion module are combined to focus on the hierarchy and continuity of the graph reasoning process. Based on a matrix transformation module and a matrix transition module, multi-hop reasoning on the local knowledge subgraph is achieved to obtain the final entity distribution. Subsequently, based on the entity distribution, the reasoning process of each answer entity is traced back using a reasoning transition matrix to generate a reasoning path from the question entity to the corresponding answer entity. This path serves as a knowledge graph enhancement thought chain prompt, guiding the large language model to utilize the retrieved external knowledge to perform continuous and reasonable question reasoning, thereby improving the accuracy and interpretability of the predicted answer.
[0127] Example 2
[0128] The present invention also relates to an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the method described above.
[0129] The electronic device can be a desktop computer, laptop, handheld computer, or cloud server, etc. The processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The memory can be used to store computer programs and / or modules. The processor performs various functions of the electronic device by running or executing the computer programs and / or modules stored in the memory, and by accessing data stored in the memory.
[0130] Example 3
[0131] The present invention also relates to a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method described above.
[0132] Specifically, the memory may include high-speed random access memory, as well as non-volatile memory, such as hard disks, RAM, plug-in hard disks, smart media cards (SMC), secure digital (SD) cards, flash cards, at least one disk storage device, flash memory device, or other volatile solid-state storage devices.
[0133] Example 4
[0134] This invention provides a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the steps of the method described in the above embodiments of this invention.
[0135] The technical features of the embodiments described above can be combined arbitrarily. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as the combination of these technical features does not contradict each other, it should be considered within the scope of this specification. It should be noted that the terms "in one embodiment," "for example," and "again" in this invention are intended to illustrate the invention and are not intended to limit the invention.
[0136] The embodiments described above are merely examples of several implementations of the present invention, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and these modifications and improvements all fall within the scope of protection of the present invention.
Claims
1. A large language model joint reasoning method based on knowledge graph enhanced thinking chain prompts, characterized in that, Comprising: extracting a question entity in the original question text, extracting all knowledge triples within a multi-hop neighborhood of the question entity from a knowledge graph, forming a local knowledge subgraph, the number of jump steps of the multi-hop neighborhood being T steps, each step corresponding to a reasoning stage, T being a positive integer greater than 1; splitting the original question text into S sub-question texts and concatenating the original question text and the S sub-question texts to obtain a concatenated question text, S≤T; inputting the spliced problem text into the text input graph reasoning model to obtain a weighted entity distribution The graph reasoning model comprises: a question encoder to convert the concatenated question text into a question embedding representation p and a hidden layer representation H q ; T cross-attention modules, respectively, for computing cross-attention representations of the p t is the number of reasoning stages, t = 1, 2, …, T; representing a fusion module for fusing and p t-1 , resulting in a t-stage reasoning embedding representation p t ; A matrix transformation module is configured to transform the p t The relationship distribution matrix R is obtained by sequentially processing the multi-layer perception and the nonlinear activation function t The different elements in R t represent the confidence of different connection edges in the knowledge graph. a matrix transfer module configured to transfer the R t constructing an inference transfer matrix W t , different elements in the W t represent the confidence of different connection edges in the local knowledge sub-graph; an entity distribution output module configured to output the entity distribution e t-1 and the W t to obtain the entity distribution e t After that, the entity distributions of all stages are weighted and summed to obtain the weighted entity distribution and output, Each element in represents the confidence of different entities as answer entities; from the weighted entity distribution extracting the top G answer entities with the highest confidence from, and using a reasoning transition matrix to backtrack the reasoning process of each answer entity to generate a reasoning path from the question entity to the corresponding answer entity, G being a positive integer; Using the reasoning path to assist a large language model to predict the answer of the original question text.
2. The large language model federated inference method of claim 1, wherein, The graph reasoning model is obtained by training, and the training method comprises: constructing an initial natural language question and answer sample set, each sample in the sample set comprising an original text question, a knowledge graph, and a corresponding answer entity; extracting a question entity in the original question text, extracting all knowledge triples within a multi-hop neighborhood of the question entity from a knowledge graph, forming a local knowledge subgraph, the local knowledge subgraph containing the corresponding answer entity, obtaining a target entity distribution a as a label; splitting the original question text into S sub-question texts and concatenating the original question text and the S sub-question texts to obtain a concatenated question text; The splicing problem text is input into the graph reasoning model for training, and the training loss function is: In the formula, L is a graph reasoning model training loss, The weighted entity distribution is a target entity distribution a.
3. The large language model federated inference method of claim 1, wherein, In the entity distribution output module, the weighted sum of the entity distributions of all stages comprises: The question embedding representation p is sequentially processed by a multi-layer perception and a normalization function to obtain T weights β t ~ β T ; The weighted entity distribution is obtained by weighted sum of the entity distributions of all stages by the following equation In the formula, β t is the tth weight.
4. The large language model federated inference method of claim 1, wherein, the t-th cross attention module calculates the cross attention representation of the p the process comprises: compute an attention query Q for the p t and compute the H q an attention key K for the p t and an attention value V t , Attention is computed for the Q t , K t , and V t , resulting in cross-attention representations The calculation formula is: where (K t ) T denotes matrix transpose of K t and dim denotes the dimension of the problem embedding representation p.
5. The large language model federated inference method of claim 1, wherein, The relationship distribution matrix R t contains the confidence of the directed connection edge between all entities in the knowledge graph, R t The kth element in R represents the confidence of the connection edge with index k in the knowledge graph. According to the R t The process of constructing the inference transition matrix W t includes: obtaining a local knowledge sub-graph, and obtaining a matrix representation M of the local knowledge sub-graph, wherein an element in the ith row and the jth row of M is M ij M = -1 when there is a connection edge between the head entity i and the tail entity j ij M = -1 when there is a connection edge between the head entity i and the tail entity j ij is an index of the connection edge between the head entity i and the tail entity j Constructing the inference transition matrix W t , W t The element in the i-th row, j-th column of W wherein the matrix dimension of the transition matrix W t The matrix dimension of the transition matrix W is the same as the matrix dimension of the adjacency matrix representation M.
6. The large language model federated inference method of claim 1, wherein, extracting top G answer entities with the highest confidence from the weighted entity distribution For the gth extracted answer entity E g , g = 1, 2, …, G; backtracking the reasoning process of each answer entity by using the reasoning transfer matrix, generating the reasoning path from the question entity to the answer entity E g The process includes: Setting T path sets store paths of length t hops from question entities to answer entities E g path, score respectively a set of paths and a set of scores in the path set and the score set; for any The processor executes the computer program to implement the steps of the method of any one of claims 1 to 7. Step S41: Initialization operation, let path = E g score = 0, step = t; Step S42: For each path in the current path... x x is the path index, based on the current path. x The entity located at the end of the backtracking direction is the tail entity V, which is determined by the inference transition matrix W. step Find all head entities that have connecting edges with tail entity V, and add the found head entities to the current path along the backtracking direction. x Get the updated path, and set the current path x score x The score of the path containing the newly added edge is obtained by adding the confidence score of the newly added edge to the score of the path containing the newly added edge. Step S43: judging whether the current step is less than or equal to 1, if not, setting step = step - 1, jumping to step S42, otherwise, ending the iteration, and outputting the updated acquiring the updated T path set selecting a preset number of paths with the highest scores as the inference paths from the question entity to the answer entity E g ; Respectively acquire the reasoning paths from the question entity to the answer entities E1~E G .
7. The large language model federated inference method of claim 6, wherein, For each answer entity E g , select a path with the highest confidence as the prompt information to assist the large language model in prediction. 8.An electronic device comprising a memory and a processor, the memory storing a computer program, wherein, The computer program is executed by the processor to implement the steps of the method of any one of claims 1 to 7.
9. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program or instructions are executed by the processor to implement the steps of the method of any one of claims 1 to 7.
10. A computer program product comprising computer programs or instructions, characterized in that,
Citation Information
Patent Citations
Food safety question-answer reasoning method and system and electronic equipment
CN113849613A
Fine adjustment method, system and equipment based on large language model and medium
CN117290480A
Large language model joint reasoning method for enhancing thinking chain prompt based on knowledge graph
CN118940840A
Revision of and attribution for output of text generation models
WO2024073087A1
Cited By
Cross-organization emergency response process model extraction method based on large language model
CN121707438A
Scenic area intelligent question answering and recommendation method based on integration of knowledge graph and large model
CN121880532A
Problem processing method, device and equipment
CN121882281A
Cross-domain heterogeneous graph link prediction method based on structure perception and large language model
CN121936555A
Method and system for diagnosing health state of water lubricated bearing
CN122021836A