Large language model joint reasoning method for enhancing thinking chain prompt based on knowledge graph

By introducing knowledge graphs to enhance thinking chain prompts in large language models, the problem of hallucination and misleading in knowledge-intensive tasks is solved, the accuracy and interpretability of reasoning are improved, and efficient answer search is achieved and inference path generation.

CN118940840AActive Publication Date: 2024-11-12HUAZHONG UNIV OF SCI & TECH

Patent Information

Application Number
CN202410983442.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-22
Publication Date
2024-11-12
Estimated Expiration
2044-07-22

AI Technical Summary

Technical Problem

Large language models are easily affected by hallucinations when dealing with knowledge-intensive tasks, and have factual errors in the output. Due to the huge parameter scale, it is difficult to ensure the accuracy of the thinking process in multi-hop reasoning; large language models and knowledge retrieval machines The cognitive differences between them lead to misleading, and the inability to directly use structured knowledge triplets, resulting in the lack of continuity of reasoning thinking.

Method used

Using a large language model joint inference method based on knowledge graph-enhanced thinking chain hints, a local knowledge sub-graph is formed by extracting multi-hop neighborhood knowledge triplets of problem entities, decomposing the original problem text into sub-problem text and splicing it, and using graph inference model Generate weighted entity distribution and inference paths, backtrack the inference process of the answer entity, and generate thinking chain prompts to assist large language models in predicting answers.

Benefits of technology

Improve the accuracy and interpretability of joint inference of large language models, reduce the time complexity of search answers, reduce the negative impact of irrelevant inference paths on large language models, ensure the factuality and reliability of inference, and significantly improve the Accuracy and continuity of multi-hop graph reasoning.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118940840A_ABST
    Figure CN118940840A_ABST
Patent Text Reader

Abstract

The invention belongs to the related technical field of natural language reasoning, and discloses a big language model joint reasoning method based on knowledge graph enhanced thinking chain prompt, which comprises the following steps: constructing a local knowledge sub-graph, decomposing an original problem text into S sub-problem texts, and splicing the original problem text and the S sub-problem texts, and inputting the spliced question text into a graph reasoning model to obtain weighted entity distribution, extracting first G answer entities with the highest confidence from the weighted entity distribution, backtracking the reasoning process of each answer entity by utilizing a reasoning transfer matrix, generating a reasoning path from the question entity to the corresponding answer entity, and obtaining a final reasoning path from the question entity to the corresponding answer entity. And predicting the answer of the original question text by using the reasoning path to assist the large language model. Through the method, the big language model can quickly and accurately find the answer of the question text.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field related to natural language reasoning, and more specifically, relates to a large language model joint reasoning method based on knowledge graph enhanced thought chain prompts. Background Art

[0002] Knowledge enhancement of large language models is a very important 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 parameter knowledge are easily affected by hallucinations when dealing with knowledge-intensive tasks, and output answers with factual errors.

[0003] In order to solve the hallucination problem caused by the black box characteristics of large language models, accessing external knowledge graphs is an effective solution. The knowledge graph stores structured knowledge triples that can provide relevant information and background knowledge for large language model reasoning, thereby improving the accuracy and explainability of reasoning. However, due to differences in data structure, it is difficult for large language models to directly retrieve and utilize structured knowledge graphs. Therefore, the task of enhancing large language models with knowledge graphs is proposed, with the aim of providing effective structured knowledge retrieval and large language model enhancement methods to ensure that large language models can effectively utilize structured external knowledge and generate accurate and reliable natural language answers.

[0004] Currently, pluggable retrieval enhancement methods are usually used to achieve knowledge enhancement of large language models. However, knowledge enhancement of large language models faces the following problems:

[0005] (1) Since large language models have huge parameter sizes and high training costs, they are not trained frequently. Therefore, the parameter knowledge within the model is often wrong or outdated, making it difficult to ensure the accuracy of the thinking process in multi-hop reasoning, and thus the reliability of the generated answers.

[0006] (2) There is a cognitive difference between large language models and knowledge retrievers. Knowledge retrievers 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 hallucinations.

[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. The continuity of reasoning thinking cannot be guaranteed during the reasoning process, making it difficult to deal with complex problems. Summary of the invention

[0008] In response to the above defects or improvement needs of the prior art, the present invention provides a large language model joint reasoning method based on knowledge graph enhanced thinking chain prompts, which aims to improve the accuracy and explainability of large language model joint reasoning.

[0009] To achieve the above object, according to a first aspect of the present invention, a large language model joint reasoning method based on knowledge graph enhanced thought chain prompts is provided, which includes:

[0010] Extract the question entity in the original question text, and 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, each step corresponds to a reasoning stage, and T is a positive integer greater than 1;

[0011] Decomposing 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;

[0012] Input the concatenated question text into the graph reasoning model to obtain the weighted entity distribution The graph reasoning model includes:

[0013] Question encoder, 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, used to calculate the cross-attention representation of p t is the number of the reasoning stage, t = 1, 2, ..., T;

[0015] Represents the fusion module, used for fusion and p t-1 , and get the reasoning embedding representation p at stage t t ;

[0016] A matrix transformation module is used to make the p t After being processed by multi-layer perceptron and nonlinear activation function, the relationship distribution matrix R is obtained. t , R t Different elements in represent the confidence of different connection edges in the knowledge graph;

[0017] Matrix transfer module for t Construct the inference transfer matrix W t , the W t Different elements in represent the confidences of different connecting edges in the local knowledge subgraph;

[0018] Entity distribution output module, used to distribute entity t-1 With the Wt Multiply them together to get the entity distribution e representing the confidence of each entity in the tth step t Finally, the entity distributions of all stages are weighted and summed to obtain the weighted entity distribution And output, Each element in represents the confidence that a different entity is the answer entity;

[0019] From the weighted entity distribution Extract the first G answer entities with the highest confidence, use the reasoning transfer matrix to trace back the reasoning process of each answer entity, and generate a reasoning 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 obtained through training, and the training method includes:

[0022] Construct an initial natural language question-answering sample set, where each sample in the sample set contains the original text question, the knowledge graph, and the corresponding answer entity;

[0023] Extract the question entity in the original question text, extract all knowledge triples in the multi-hop neighborhood of the question entity from the knowledge graph, form a local knowledge subgraph, the local knowledge subgraph contains the corresponding answer entity, and obtain the target entity distribution a as a label;

[0024] Decomposing 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;

[0025] The splicing problem text is input into the graph reasoning model for training, and the training loss function is:

[0026]

[0027] Where L is the graph reasoning model training loss, is the weighted entity distribution, and a is the target entity distribution.

[0028] In some embodiments, in the entity distribution output module, performing weighted summation of entity distributions of all stages includes:

[0029] The problem embedding representation p is processed by a multi-layer perceptron and a normalization function in turn to obtain T weights β t ~β T ;

[0030] The weighted entity distribution is obtained by weighting the entity distribution of all stages through the following formula:

[0031]

[0032] In the formula, β t is the tth weight.

[0033] In some embodiments, the t-th cross-attention module calculates the cross-attention representation of p The process includes:

[0034] Compute the attention query Q for p t And calculate the H q Attention key K t and attention value V t ,

[0035] For the Q t , K t and V t Perform attention calculation to obtain cross attention representation The calculation formula is:

[0036]

[0037] In the formula, (K t ) T Indicates K t Perform matrix transposition, dim represents the dimension of the problem embedding representation p.

[0038] In some embodiments, the relationship distribution matrix R t Contains the confidence of all directed connections between entities in the knowledge graph, R t The kth element in Represents the confidence of the edge with index k in the knowledge graph;

[0039] According to the R t Construct the inference transfer matrix W t The process includes:

[0040] Get 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 is the index of the connecting edge between the head entity i and the tail entity j;

[0041] Construct the inference transfer matrix W t , W t The elements in the i-th and j-th rows are

[0042]

[0043] Among them, the inference transfer matrix W t The matrix dimensions of are the same as the matrix dimensions of the adjacency matrix representation M.

[0044] In some embodiments, the weighted entity distribution Extract the top G answer entities with the highest confidence;

[0045] For the g-th extracted answer entity E g , g = 1, 2, ..., G; use the reasoning transfer matrix to trace back the reasoning process of each answer entity and generate the equation from the question entity to the answer entity E g The reasoning path of the process includes:

[0046] Set T path sets Store from question entity to answer entity E g The path length is a path of t hops, path,score are The path set and score set in implement:

[0047] Step S41: Initialization operation, set path = E g , score = 0, step = t;

[0048] Step S42: for each path in the current path x , x is the path index, with the current path x The entity at the end of the backtracking direction is the tail entity V, which is inferred by the transfer matrix W step Find all head entities that have connecting edges with the tail entity V, and add the found head entities to the current path along the backtracking direction x , get the updated path, and change the current path x score x Add the confidence score of the newly added connection edge to get the score of the path where the newly added connection edge is located;

[0049] Step S43: Determine whether 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

[0050] Get the updated set of T paths Select the preset number of paths with the highest scores as the paths from the question entity to the answer entity Eg The reasoning path of

[0051] Get the answer entities E1~E from the question entity respectively G The reasoning path.

[0052] In some embodiments, for each answer entity E g , select a path with the highest confidence as prompt information to assist the large language model prediction.

[0053] According to a second aspect of the present invention, there is provided an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of any of the above methods when executing the computer program.

[0054] According to a third aspect of the present invention, there is provided a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of any of the above methods.

[0055] According to a fourth aspect of the present invention, there is provided a computer program product, comprising a computer program or instructions, which, when executed by a processor, implement the steps of any of the methods described above.

[0056] In general, compared with the prior art, the above technical solution conceived by the present invention has the following beneficial effects:

[0057] 1. The present invention first adopts a graph reasoning model to obtain answer entities with higher confidence in the local knowledge subgraph, and then uses the reasoning transfer matrix to trace back the reasoning process of each answer entity, generates a reasoning path from the question entity to the corresponding answer entity, and uses the reasoning path to assist the large language model in predicting the answer to the original question text. In this way, compared with the general breadth-first search algorithm, the time complexity of the power function level can be reduced to linear time complexity, thereby improving the efficiency of searching for answers.

[0058] 2. Before using the graph reasoning model, the present invention first decomposes the original question text into sub-questions and then splices them, and then inputs the spliced ​​question text into the graph reasoning model. In this way, by explicitly decomposing and encoding complex problems and utilizing the semantic characteristics of the sub-questions implicit in the problem 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, significantly reducing the problem of the graph reasoning model falling into over-reasoning due to the continuous accumulation of calculation errors in the relationship distribution, improving the accuracy of multi-hop graph reasoning, and thereby reducing the negative impact of irrelevant reasoning paths on the reasoning of the large language model, thereby ensuring the factuality and reliability of the reasoning of the large language model.

[0059] 3. The graph reasoning model used in the present invention includes a question encoder, a cross-attention module, a representation fusion module, a matrix transformation module, a matrix transfer module and an entity distribution output module. Through the designed graph reasoning model, the large language model's ability to analyze complex problems can be fully utilized. Through explicit sub-problems and cross-attention modules, the graph reasoning model is guided to assign a higher transfer probability to the relationship with high support for reasoning in the local knowledge subgraph in each step of the reasoning process, and reduce the interference of irrelevant relationships on the reasoning process, which significantly reduces the deviation of the transfer probability and the misleading of the reasoning process that accumulates continuously along the reasoning path. The representation fusion module introduced combines the cross-attention representation of the current stage and the reasoning embedding representation of the previous stage, and simulates the continuity of human thinking when reasoning complex problems, so that the graph reasoning process of the current step can pay attention to the reasoning resume of the previous stage, which not only matches the thinking process of the large language model, but also makes full use of the unique relevance and hierarchy of the knowledge graph, enhances the continuity of the graph reasoning process, and further improves the accuracy of reasoning.

[0060] 4. In a specific embodiment, before applying the graph reasoning model, a loss function is introduced Training the graph reasoning model can make the graph reasoning model converge quickly to expectations, so that the graph reasoning model can accurately predict the confidence of each answer entity based on the input question text.

[0061] 5. In a specific embodiment, a method for constructing an inference transfer matrix W is proposed. t The specific formula of is used to quickly construct the inference transfer matrix and improve the data processing speed.

[0062] 6. In a specific embodiment, a specific method for generating thought chain prompts is proposed. Through this method, an effective way to access multi-source heterogeneous knowledge data is provided for a large language model that can only accept text sequences as input, eliminating the limitations on the application of large language models due to differences in data modalities, so that the large language model can use a universal solution to access external data for different types of tasks and different modal data. BRIEF DESCRIPTION OF THE DRAWINGS

[0063] Figure 1 It is a flowchart of the steps of a large language model joint reasoning method based on knowledge graph enhanced thought chain prompts in one embodiment of the present invention;

[0064] Figure 2 is a relationship diagram of a local knowledge subgraph in one embodiment of the present invention;

[0065] Figure 3is a data processing process diagram of a graph reasoning model in one embodiment of the present invention;

[0066] Figure 4 It is a schematic diagram of the process of generating thought chain prompts in one embodiment of the present application. DETAILED DESCRIPTION

[0067] In order to make the purpose, technical solutions 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. In addition, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.

[0068] like Figure 1 The figure shows a step flow chart of a large language model joint reasoning method based on knowledge graph enhanced thought chain prompts in one embodiment of the present invention, which mainly includes steps S1 to S5. Each step is described in detail below.

[0069] Step S1: Extract the question entity in the original question text, extract all knowledge triples in the multi-hop neighborhood of the question entity from the knowledge graph, and form a local knowledge subgraph. The number of jump steps in the multi-hop neighborhood is T steps, each step corresponds to an inference stage, and T is a positive integer greater than 1.

[0070] 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 through the entity recognition method, and the question entities are linked to the knowledge graph through the entity linking method. All knowledge triples in the multi-hop neighborhood of the question entity are extracted to form a local knowledge subgraph. The entities in the local knowledge subgraph represent the text content. Figure 2 The figure shows a relationship diagram of a local knowledge subgraph in an embodiment of the present invention, wherein each jump 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 tail entity associated with it. Furthermore, the local knowledge subgraph can be pruned by reasoning templates or representation similarity to reduce storage space overhead.

[0071] 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 a concatenated question text.

[0072] Among them, S≤T.

[0073] In one embodiment, the question text may be decomposed into multiple reasoning sub-questions using a large language model and concatenated with the question text to obtain a concatenated question text. Specifically, this step may include the following process:

[0074] Step S21: Input the question text, the question decomposition instruction instruct (the question decomposition instruction is manually constructed by the user) and the upper limit T of the number of sub-questions into the large language model LLM, and instruct the large language model LLM to decompose the question text q into at most T sub-questions. After decomposition, S sub-question texts q1, q2, ..., q S , where S≤T is the number of sub-question texts obtained after the large language model LLM decomposes the question text q. The formula is as follows:

[0075] q1,q2,......,q S =LLM(q,instruct,T)

[0076] Step S22: Question text q and sub-question texts q1, q2, ..., q S Perform splicing to obtain the splicing question text [q:q1,q2,......,q S ].

[0077] Step S3: Input the concatenated question text into the graph reasoning model to obtain the weighted entity distribution

[0078] The graph reasoning model includes: question encoder, T cross-attention modules, representation fusion module, matrix transformation module and entity distribution output module.

[0079] like Figure 3 The figure shows a data processing process diagram of a graph reasoning model in one embodiment of the present invention.

[0080] The question encoder is used to convert the concatenated question text into the question embedding representation p and the hidden layer representation H q In one embodiment, the question encoder can use the existing pre-trained language model BERT. Specifically, the question text [q:q1,q2,......,q S ] Input the pre-trained language model BERT, and get a question embedding representation p with a dimension of 1×dim and a hidden layer representation H with a dimension of |q|×dim q =(h1,h2…,h |q| ), |q| is the concatenated question text [q:q1,q2,......,q S ] contains the total number of characters, h i is the parameter of the i-th hidden layer, and dim is the dimension of the embedded representation output by the pre-trained language model BERT.

[0081] p,(h1,…,h |q| )=BERT([q:q1,q2,......,q S ])

[0082] 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. Since the graph reasoning process on the local knowledge subgraph in step S1 is divided into T stages, T cross-attention modules are also set up in the graph reasoning model. The question embedding representation p is input into T cross-attention modules respectively 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:

[0083] 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 (dimensions are dim×dim) can calculate the attention query at stage t Attention key and attention value

[0084]

[0085] Then, use the attention calculation formula to calculate

[0086]

[0087] Among them, (K t ) T The meaning is for the attention key K t The matrix transpose operation of , dim is the dimension of the embedding representation output by the pre-trained language model BERT.

[0088] The dimension of the question embedding p is 1×dim, and the hidden layer represents H q The dimension is |q|×dim, the weight matrix of stage t The dimensions are all dim×dim, so 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 is |q|×dim. Further Q t (K t ) T The dimension is 1×|q|, and the result after Softmax normalization is The dimension is 1×|q|, because the attention value V t The dimension of is |q|×dim, so The resulting dimension is 1×dim, that is, It is 1×dim dimension.

[0089] Indicates that the fusion module is used to fuse and p t-1 , and get the reasoning embedding representation p at stage t t The inference embedding representation p at stage t is t is the cross attention representation at stage t and the inference embedding representation p at stage t-1 t-1 The sum of the vectors is specifically expressed as:

[0090]

[0091] In this paper, by combining the cross attention representation of the current stage and the reasoning embedding representation of the previous stage to enhance the continuity of the graph reasoning process. Since t = 1, 2, ..., T, we can set the reasoning embedding representation p at stage t = 0 0 is a zero vector of dimension 1×dim to satisfy the computational requirements of reasoning about the embedding representation at the initial stage t=1.

[0092] The matrix transformation module is used to make p t After being processed by multi-layer perceptron and nonlinear activation function, the relationship distribution matrix R is obtained. t , R t The different elements in represent the confidence of different connecting edges in the knowledge graph. Specifically, the reasoning embedding representation p at stage t is used t , the calculation is processed by the multi-layer perceptron and nonlinear activation function in turn, and the relationship distribution matrix R of the t-th jump is obtained t , R t Each element in represents the probability of different connection relationships in the original knowledge graph, which can be specifically expressed as:

[0093] R t =Sigmoid(MLP(p t ))

[0094] In a specific embodiment, the relationship distribution matrix R t Contains the confidence of all directed connections between entities in the knowledge graph, R t The kth element in represents the confidence of the edge with index k in the knowledge graph. That is, if there are h entities in the knowledge graph, the relationship distribution matrix R t The dimension of can be h×h, the number of connecting edges between the head entity and the tail entity formed by any entity as the head entity and any entity as the tail entity is h×h, and the relationship distribution matrix R tThe h×h elements in correspond one to one to the confidences of the h×h connecting edges.

[0095] The matrix transfer module is used to t Construct the inference transfer matrix W t , W t Different elements in represent the confidence of different connecting edges in the local knowledge subgraph. t The confidence of all the connecting edges in the knowledge graph is predicted in step S1, so it also includes the confidence of the connecting edges formed at each stage of the local knowledge subgraph formed in step S1. The role of the matrix transfer module is to transfer the confidence of all the connecting edges from R t The confidence of the connecting edges of the local knowledge subgraph is extracted.

[0096] In the specific operation, the local knowledge subgraph is stored in the form of an adjacency matrix representation M. Assuming that the local knowledge subgraph has r entities, the number of connecting edges between the head entity and the tail entity formed by any entity as the head entity and any entity as the tail entity is r×r, the dimension of the adjacency matrix representation M can be r×r, and the r×r elements of the adjacency matrix representation M correspond one-to-one to the indexes of the r×r connecting edges. The elements of the i-th and j-th rows in M ​​are M ij , corresponding to the index of the edge connecting the head entity i and the tail entity j. In the local knowledge subgraph, the index of the actual edge can be numbered starting from 1. For example, if there are 10 edges in total, the indexes are 1 to 10. If there is no edge connecting the head entity i and the 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 a connecting edge between the head entity i and the tail entity j in the local knowledge subgraph, then M ij is the index of the connecting edge 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.

[0097] According to R t Construct the inference transfer matrix W of stage t t The process includes:

[0098] Obtain the adjacency matrix representation M of the local knowledge subgraph;

[0099] Construct the inference transfer matrix W t , W t The elements in the i-th and j-th rows are

[0100]

[0101] Among them, the inference transfer matrix W tThe matrix dimensions of M are the same as the matrix dimensions of the adjacency matrix representation M. That is, if the adjacency matrix representation M, M ij The value of the connecting edge index k is t Find the element with edge index k in M ij Replace with If the adjacency matrix represents M, M ij The value of is an invalid value -1, indicating that the connection edge does not exist in the local knowledge subgraph, then M ij Set to 0. After all elements are replaced, the replaced matrix is ​​the inference transfer matrix W. t .

[0102] Since the previous article formed T relationship distribution matrices R according to T stages 1 ~R T , so through the above process, T inference transfer matrices W are also formed 1 ~W T .

[0103] The entity distribution output module is used to distribute the entity t-1 With W t Multiply to get entity distribution e t Finally, the entity distributions of all stages are weighted and summed to obtain the weighted entity distribution And output, each element in the entity distribution represents the confidence that different entities are the answer entities.

[0104] Specifically, the sub-problem reasoning process is converted into multi-hop reasoning in the local knowledge subgraph, and the confidence scores of the entities in the local knowledge subgraph at different reasoning stages are obtained through matrix operations. The weighted entity distribution is expressed as:

[0105] e t =e t-1 W t

[0106] β=Softmax(MLP(p))

[0107]

[0108] Where t is the number of the inference stage, e t is the entity distribution at stage t, W t is the inference transfer matrix at stage t, β is the attention weight at different inference stages, Softmax is the normalized exponential function, q is the embedded representation of the input question, is the weighted entity distribution.

[0109] When t = 1, e 0It corresponds to the distribution of problem entities, and its length is the number of entities in the local knowledge subgraph, where only the elements corresponding to the problem entity nodes are 1, and the rest are 0. Figure 1 There are 4 nodes, namely nodes 1 to 4, 1 is the problem entity, then:

[0110] e 0 =[1 0 0 0]

[0111]

[0112] e 1 It represents the confidence of each entity node at the first hop;

[0113] By analogy, e t It represents the confidence of each entity node at the tth hop;

[0114] After completing T steps of jumps, the confidence of each entity node corresponding to each step of jump is weighted and summed to obtain the confidence of each entity as the answer entity.

[0115] It can be understood that the above inference model is obtained through training. The training method includes:

[0116] Construct an initial natural language question-answering sample set, where each sample in the sample set contains the original text question, the knowledge graph, and the corresponding answer entity;

[0117] Extract the question entity in the original question text, extract all knowledge triples in the multi-hop neighborhood of the question entity from the knowledge graph, form a local knowledge subgraph, the local knowledge subgraph contains the corresponding answer entity, and obtain the target entity distribution a as the label;

[0118] Decomposing 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;

[0119] The concatenated question text is input into the graph reasoning model for training and the graph reasoning model parameters are updated using gradient descent until convergence. The training loss function is:

[0120]

[0121] Where L is the graph reasoning model training loss, is the weighted entity distribution, and a is the target entity distribution.

[0122] Step S4: From the weighted entity distribution The first G answer entities with the highest confidence are extracted, and the reasoning process of each answer entity is traced back using the reasoning transfer matrix to generate the reasoning path from the question entity to the corresponding answer entity.

[0123] G is a positive integer.

[0124] From weighted entity distribution Extract the top G answer entities with the highest confidence, which are E1~E G .

[0125] like Figure 4 The figure shows a schematic diagram of the process of generating a thought chain prompt in an embodiment of the present application. In step S3, starting from the question entity, from the 1st to the Tth jump, the reasoning transfer matrix W is sequentially used. t Calculations are performed to find each answer entity. Therefore, in this step, the inverse calculation of step S3 can be followed, with the answer entity as the starting point, and inverse calculations can be performed through the reasoning transfer matrix from the Tth jump to the 1st jump, tracing back to the question entity, obtaining the reasoning path from the question entity to the corresponding answer entity, and obtaining a thinking chain prompt.

[0126] In the specific operation, for the g-th extracted answer entity E g , use the reasoning transfer matrix to trace back the reasoning process of each answer entity and generate the equation from the question entity to the answer entity E g The reasoning path of the process includes:

[0127] Set T path sets Store from question entity to answer entity E g The path length is a path of t hops, path,score are The path set and score set in implement:

[0128] Step S41: Initialization operation, set path = E g , score = 0, step = t;

[0129] Step S42: for each path in the current path x , x is the path index, with the current path x The entity at the end of the backtracking direction is the tail entity V, which is inferred by the transfer matrix W step Find all head entities that have connecting edges with the tail entity V, and add the found head entities to the current path along the backtracking direction x , get the updated path, and change the current path x score x Add the confidence score of the newly added connection edge to get the score of the path where the newly added connection edge is located;

[0130] Step S43: Determine whether 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

[0131] Get the updated set of T paths Select the preset number of paths with the highest scores as the paths from the question entity to the answer entity E g The reasoning path of

[0132] Get the answer entities E1~E from the question entity respectively G The reasoning path.

[0133] In some embodiments, considering the storage cost, in step S42, after obtaining the updated paths, the paths are pruned according to the scores of the paths, and only the paths with the highest scores are retained.

[0134] In some embodiments, after obtaining the updated T path sets 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 time, from the question entity to the answer entity E1~E G There are a total of G reasoning paths.

[0135] The following is a detailed description of this process.

[0136] Based on weighted entity distribution Select G answer entities E1, E2, ..., E with the largest 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 g 1-hop, 2-hop, ..., T-hop reasoning paths to the problem entity, where each initial path set Where path0 = E m Represents the answer entity E m is the 0-hop path of the tail entity, score0 is the confidence score of the current path, and the initial value is 0 (since the initialization starts from the answer entity, it can be regarded as the answer entity E m A path that is the tail entity and has no preceding entity. New preceding entities will be added to form a path based on it during the backtracking process.

[0137] For the backtracking step step=t,t-1,......,1, for the path set Each path in (x is the number of the current path), take out the tail entity V of the path and the entity number index(V) of the entity, then you can trace back the inference transfer matrix W of step step step Find the current path x The set of all predecessor entities Specifically: Take out the inference transfer matrix W of the backtracking step step step The index(V)th column of (where j = index(V), Z is the number of entities in the local knowledge subgraph), if If the value of is not 0, it means that there is an edge starting from entity i∈{i} along the relationship M ij , arrive at entity j(M ij It is the relationship number between the head entity i and the tail entity j. Entity j is the current path path. x Then, entity i is regarded as the previous node of the current path and added to the current path path x , updated It can be expressed as:

[0138]

[0139] k=M ij

[0140]

[0141] → means adding entity i as the preceding entity to the path path x , R step is the relationship distribution matrix of the backtracking step step, M ij Number the relationship between the head entity i and the tail entity j, the new path The confidence score of is the original confidence score score x Plus the relationship M between entity i and entity j ij Probability

[0142] Step S5: Use the reasoning path to assist the large language model in predicting the answer to the original question text.

[0143] The final reasoning path P1, P2, ..., P obtained in the previous step S4 G , which is the thinking chain prompt from the question entity to the answer entity. We call these final reasoning paths thinking chain prompts based on knowledge graph enhancement. We call the question text q and the thinking chain prompts based on knowledge graph enhancement P1, P2, ..., P GInput into the large language model LLM to generate the final answer:

[0144] Answer=LLM(q,P1,P2,......,P G )

[0145] 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 at the power function level O(n T ), where n is the number of all knowledge triples in the local knowledge subgraph, and T is the number of jump steps in the multi-hop neighborhood. That is, as the number of knowledge triples n in the local knowledge subgraph increases, the running time of the algorithm grows at the power of n to the Tth power, which is unacceptable for the program. Therefore, the present invention proposes the above path backtracking algorithm based on beam search. For candidate entities with higher confidence, the search tree can be pruned in combination with the reasoning transfer matrix, and then a multi-hop reasoning process is generated by backtracking from the answer entity, and a multi-hop reasoning path is generated from the question entity to the answer entity, reducing the time complexity of the power function level to linear time complexity.

[0146] In the present invention, by extracting the question entity in the original question text, all knowledge triples within the multi-hop neighborhood of the question entity are extracted from the knowledge graph to form a local knowledge subgraph; the large language model is used to explicitly decompose and encode complex problems; the question encoder is combined to obtain the embedded representation of the original question and sub-problem in the high-dimensional vector space; the cross-attention module and the representation fusion module are combined to focus on the hierarchy and continuity of the graph reasoning process; based on the matrix transformation module and the matrix transfer module, multi-hop reasoning on the local knowledge subgraph is implemented to obtain the final entity distribution; then, based on the entity distribution, the reasoning process of each answer entity is traced back using the reasoning transfer matrix, and the reasoning path from the question entity to the corresponding answer entity is generated as a knowledge graph enhanced thinking chain prompt, guiding the large language model to use these retrieved external knowledge to perform continuous and reasonable question reasoning, thereby improving the accuracy and interpretability of the predicted answer.

[0147] Example 2

[0148] The present invention also relates to an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the above method when executing the computer program.

[0149] The electronic device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The memory may be used to store computer programs and / or modules, and the processor may perform various functions of the electronic device by running or executing computer programs and / or modules stored in the memory, and calling data stored in the memory.

[0150] Example 3

[0151] The present invention also relates to a computer-readable storage medium having a computer program stored thereon, and the computer program implements the steps of the above method when executed by a processor.

[0152] Specifically, the memory may include a high-speed random access memory, and may also include a non-volatile memory, such as a hard disk, an internal memory, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.

[0153] Example 4

[0154] The embodiment of the present invention provides a computer program product or a computer program, which 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 the processor executes the computer instructions, so that the computer device performs the steps of the method of the above embodiment of the present invention.

[0155] The technical features of the above-mentioned embodiments can be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above-mentioned embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification. It should be noted that "in one embodiment", "for example", "for example", etc. of the present invention are intended to illustrate the present invention, rather than to limit the present invention.

[0156] The above-mentioned embodiments only express several implementation methods of the present invention, and the description is relatively specific and detailed, but it cannot be understood as limiting the scope of the patent application. It should be pointed out that for ordinary technicians in this field, several modifications and improvements can be made without departing from the concept of the present invention, which all belong to the protection scope of the present invention.

Claims

1. A large language model joint reasoning method based on knowledge graph enhanced thought chain prompts, characterized in that: include: Extract the question entity in the original question text, and 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, each step corresponds to a reasoning stage, and T is a positive integer greater than 1; Decomposing 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; Input the concatenated question text into the graph reasoning model to obtain the weighted entity distribution The graph reasoning model includes: Question encoder, used to convert the concatenated question text into a question embedding representation p and a hidden layer representation H q ; T cross-attention modules, used to calculate the cross-attention representation of p t is the number of the reasoning stage, t = 1, 2, ..., T; Represents the fusion module, used for fusion and p t-1 , and get the reasoning embedding representation p at stage t t ; A matrix transformation module is used to make the p t After being processed by multi-layer perceptron and nonlinear activation function, the relationship distribution matrix R is obtained. t , R t Different elements in represent the confidence of different connection edges in the knowledge graph; Matrix transfer module for t Construct the inference transfer matrix W t , the W t Different elements in represent the confidences of different connecting edges in the local knowledge subgraph; Entity distribution output module, used to distribute entity t-1 With the W t Multiply them together to get the entity distribution e representing the confidence of each entity in the tth step t Finally, the entity distributions of all stages are weighted and summed to obtain the weighted entity distribution And output, Each element in represents the confidence that a different entity is the answer entity; From the weighted entity distribution Extract the first G answer entities with the highest confidence, use the reasoning transfer matrix to trace back the reasoning process of each answer entity, and generate a reasoning path from the question entity to the corresponding answer entity, where G is a positive integer; The reasoning path is used to assist the large language model in predicting the answer to the original question text.

2. The large language model joint reasoning method according to claim 1, characterized in that: The graph reasoning model is obtained through training, and the training method includes: Construct an initial natural language question-answering sample set, where each sample in the sample set contains the original text question, the knowledge graph, and the corresponding answer entity; Extract the question entity in the original question text, extract all knowledge triples in the multi-hop neighborhood of the question entity from the knowledge graph, form a local knowledge subgraph, the local knowledge subgraph contains the corresponding answer entity, and obtain the target entity distribution a as a label; Decomposing 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: Where L is the graph reasoning model training loss, is the weighted entity distribution, and a is the target entity distribution.

3. The large language model joint reasoning method according to claim 1, characterized in that: In the entity distribution output module, the weighted summation of entity distributions in all stages includes: The problem embedding representation p is processed by a multi-layer perceptron and a normalization function in turn to obtain T weights β t ~β T ; The weighted entity distribution is obtained by weighting the entity distribution of all stages through the following formula: In the formula, β t is the tth weight.

4. The large language model joint reasoning method according to claim 1, characterized in that: The tth cross attention module calculates the cross attention representation of p The process includes: Compute the attention query Q for p t And calculate the H q Attention key K t and attention value V t , Regarding the Q t , K t and V t Perform attention calculation to obtain cross attention representation The calculation formula is: In the formula, (K t ) T Indicates K t Perform matrix transposition, dim represents the dimension of the problem embedding representation p.

5. The large language model joint reasoning method according to claim 1, characterized in that: The relationship distribution matrix R t Contains the confidence of all directed connections between entities in the knowledge graph, R t The kth element in Represents the confidence of the edge with index k in the knowledge graph; According to the R t Construct the inference transfer matrix W t The process includes: Get 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 is the index of the connecting edge between the head entity i and the tail entity j; Construct the inference transfer matrix W t , W t The elements in the i-th and j-th rows are Among them, the inference transfer matrix W t The matrix dimensions of are the same as the matrix dimensions of the adjacency matrix representation M.

6. The large language model joint reasoning method according to claim 1, characterized in that: From the weighted entity distribution Extract the top G answer entities with the highest confidence; For the g-th extracted answer entity E g , g = 1, 2, ..., G; use the reasoning transfer matrix to trace back the reasoning process of each answer entity and generate the equation from the question entity to the answer entity E g The reasoning path of the process includes: Set T path sets Store from question entity to answer entity E g The path length is a path of t hops, path,score are The path set and score set in implement: Step S41: Initialization operation, set path = E g , score = 0, step = t; Step S42: for each path in the current path x , x is the path index, with the current path x The entity at the end of the backtracking direction is the tail entity V, which is inferred by the transfer matrix W step Find all head entities that have connecting edges with the tail entity V, and add the found head entities to the current path along the backtracking direction x , get the updated path, and change the current path x score x Add the confidence score of the newly added connection edge to get the score of the path where the newly added connection edge is located; Step S43: Determine whether 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 Get the updated set of T paths Select the preset number of paths with the highest scores as the paths from the question entity to the answer entity E g The reasoning path of Get the answer entities E1~E from the question entity respectively G The reasoning path.

7. The large language model joint reasoning method according to claim 6, characterized in that: For each answer entity E g , select a path with the highest confidence as prompt information to assist the large language model prediction.

8. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer program product comprising a computer program or instructions, characterized in that When the computer program or instruction is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Time sequence knowledge graph completion method based on block decomposition

    CN116226402A

  • Open domain natural language reasoning question-answering system and method driven by large language model

    CN116932708A

  • Intelligent query reasoning method and device based on knowledge graph and large language model collaboration

    CN117743531A

  • Visual question and answer method, system and device based on thinking chain and storage medium

    CN117891965A

  • Multi-modal reasoning method and device based on large language model and knowledge graph

    CN118193684A

Cited By

  • Prediction time coding method based on large language model prior

    CN119669745A

  • Automatic test vector generation method and system based on decision tree

    CN119780685A

  • Large model reasoning method and system based on tree diagram and knowledge graph retrieval enhancement

    CN119961377A

  • Personalized cognitive path extraction method based on large language model

    CN120067299A

  • A personalized cognitive path extraction method based on a large language model

    CN120067299B