A knowledge graph-enhanced large-model multi-hop reasoning method and system
By introducing external knowledge graphs into the big model, extracting entities, searching for multi-hop path knowledge and aggregating them into global knowledge, the problem of hallucination phenomena and multi-hop reasoning difficulties in complex inference tasks is solved, and the reasoning ability is significantly improved.
Patent Information
- Application Number
- CN202411795064.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-09
- Publication Date
- 2025-03-07
- Estimated Expiration
- 2044-12-09
AI Technical Summary
Large models face hallucinations and multi-hop reasoning difficulties when dealing with complex inference tasks, and lack an effective internal structured reasoning mechanism.
By introducing an external knowledge graph, extracting entities in the question, searching for multi-hop path knowledge, filtering path knowledge with semantic similarity to the question, and aggregate it into global knowledge, injecting it into a big model to provide answers.
It significantly improves the inference ability of large models in complex queries, reduces the occurrence of hallucinations, and helps large models understand and reason the implicit relationships and logical links in inference problems.
Smart Images

Figure CN119293218B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of natural language processing technology, and specifically to a large-model multi-hop reasoning method and system enhanced by a knowledge graph. Background Art
[0002] Large models usually face some challenges when dealing with complex reasoning tasks, mainly including hallucination phenomena and multi-hop reasoning problems. Hallucination phenomena refer to the generation of unreal or inaccurate content by the model. This is because the text generated by the large model is based on statistical associations and pattern recognition, rather than on causal relationships or logical reasoning in the real world. Multi-hop reasoning refers to the need to reason and connect across multiple related information when answering complex questions. Large models show difficulties in this regard because they usually lack effective internal structured reasoning mechanisms. Existing studies have shown that retrieval enhancement systems based on text data can reduce the generation of large model hallucinations by introducing external knowledge. Knowledge graphs store facts and relationships in a naturally structured way, providing a simple and clear entity relationship framework. How to inject the clear entity relationships in the knowledge graph into the large model, help the large model understand and reason about the implicit relationships and logical links in the problem, and improve the ability of the large model to complete complex reasoning tasks is a key problem that the present invention needs to solve. Summary of the invention
[0003] In order to effectively reduce the phenomenon of hallucination caused by large models and improve the reasoning ability of large models in solving complex queries, the present invention proposes a knowledge graph-enhanced large model multi-hop reasoning method and system.
[0004] The objective of the present invention is achieved through the following technical solutions:
[0005] The present invention provides a large model multi-hop reasoning method enhanced by a knowledge graph, comprising the following steps:
[0006] Step 1: Extract entities in the question based on the given question;
[0007] Step 2: Based on the problem entities obtained in step 1, search for K_1-hop path knowledge P_1 starting from all problem entities from the external knowledge graph, and search for path knowledge P_2 starting from all problem entity pairs and ending at a length not exceeding K_2, and use the obtained path knowledge as candidate path knowledge;
[0008] Step 3: Based on the candidate path knowledge obtained in step 2, convert each path knowledge into a text string, use the same encoder to calculate the embedding vector of the given question and path knowledge and calculate the similarity between them, retaining N_1 P_1 path knowledge with the highest similarity and N_2 P_2 path knowledge with the highest similarity;
[0009] Step 4: Based on the filtered path knowledge obtained in step 3, use the large model to aggregate these path knowledge to obtain global knowledge;
[0010] Step 5: Use predefined instruction templates to integrate the filtered path knowledge and aggregated global knowledge into the prompt words, stimulating the large model to provide answers to given questions based on external knowledge.
[0011] Furthermore, the step 1 comprises:
[0012] Input the given question into the entity naming recognition algorithm or tool, and use the extracted entities as the question entities; or construct the given question with the input prompt "You are an expert in entity extraction. Extract all entities from the following text. Text: Q"; where is a line break character, Q is a given question, and the question entity is obtained based on the answer of the large model.
[0013] Furthermore, the step 2 comprises:
[0014] Based on the problem entity obtained in step 1, use the breadth-first search algorithm or the depth-first search algorithm, take each problem entity as the starting point, search its K_1 jump path knowledge from the external knowledge graph, and after the retrieval is completed, obtain the path knowledge P_1; at the same time, take all problem entity pairs as the starting and ending points, search for path knowledge with a length not exceeding K_2, and after the retrieval is completed, obtain the path knowledge P_2; use all the obtained path knowledge as candidate path knowledge; where K_1 and K_2 are both predefined hyperparameters.
[0015] Furthermore, the step 2 further comprises:
[0016] Depending on the questions that need to be answered, the external knowledge graphs used include general knowledge graphs and domain knowledge graphs built for specific fields; the general knowledge graphs include Wikidata KG, FreeBase and YAGO.
[0017] Furthermore, the step 2 further comprises:
[0018] When searching for path knowledge, if the number of entities in the problem exceeds the first threshold and the density of the knowledge graph exceeds the second threshold, the length of the path is limited or only the paths related to the key entities in the problem are searched; among which, the length of the path is positively correlated with the complexity of the problem.
[0019] Furthermore, the step 3 comprises:
[0020] Based on the candidate path knowledge obtained in step 2, each path knowledge is converted into a text string by connecting the head entity, relationship and tail entity. The same encoder is used to calculate the embedding vectors of the given question and path knowledge and calculate the similarity between them. The similarity is calculated by the inner product of the embedding vectors of the given question and path knowledge. Then, N_1 P_1 path knowledge with the highest similarity and N_2 P_2 path knowledge with the highest similarity are retained, where N_1 and N_2 are both predefined hyperparameters.
[0021] Furthermore, the step 4 comprises:
[0022] Based on the filtered path knowledge obtained in step 3, relying on the reasoning and generation capabilities of the large model, the path knowledge is aggregated in an explicit manner and global knowledge is generated using natural language descriptions.
[0023] The present invention also provides a large model multi-hop reasoning system for implementing the knowledge graph enhancement of the above method, comprising:
[0024] Entity recognition module, used to identify entities mentioned in the given question;
[0025] A path knowledge search module is used to search for multi-hop path knowledge starting from a problem entity and multi-hop path knowledge starting from and ending at a problem entity pair;
[0026] The filtering module is used to filter candidate path knowledge with high semantic similarity to the given question;
[0027] The path knowledge aggregation module is used to aggregate the path knowledge obtained through screening to form global knowledge;
[0028] The knowledge injection module is used to inject path knowledge and aggregated global knowledge into the large model, so that the large model can provide answers to given questions based on external knowledge.
[0029] The present invention also provides an electronic device, comprising a memory and a processor, wherein the memory is coupled to the processor; wherein the memory is used to store program data, and the processor is used to execute the program data to implement the above-mentioned knowledge graph enhanced large model multi-hop reasoning method.
[0030] The present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the above-mentioned knowledge graph-enhanced large-model multi-hop reasoning method.
[0031] The beneficial effects of the present invention are as follows: the present invention provides a knowledge graph-enhanced large model multi-hop reasoning method, which provides an effective solution for enhancing the reasoning ability of large models in solving complex queries and effectively reducing the generation of large model hallucinations. The present invention introduces an external knowledge graph, and before answering a given question, it screens relevant local knowledge through entity-centric path knowledge exploration and semantic-based filtering, then aggregates local knowledge to obtain hidden global knowledge, and finally injects this external knowledge into the large model to help the large model reasoning. When the present invention is applied to the reasoning of a large model, it significantly improves the reasoning ability of the large model. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 This is a flow chart of the knowledge graph-enhanced large model multi-hop reasoning method proposed in the present invention;
[0033] Figure 2 It is a schematic diagram of the structure of a large model multi-hop reasoning system enhanced by a knowledge graph provided by the present invention;
[0034] Figure 3 It is a schematic diagram of an electronic device provided by the present invention. DETAILED DESCRIPTION
[0035] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Instead, they are merely examples of systems and methods consistent with some aspects of the present invention as detailed in the appended claims.
[0036] The terms used in the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. The singular forms "a", "the" and "the" used in the present invention and the appended claims are also intended to include plural forms unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0037] It should be understood that although the terms first, second, third, etc. may be used in the present invention to describe various information, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present invention, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0038] In order to make the objectives, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in combination with specific implementation cases and with reference to the accompanying drawings.
[0039] See also Figure 1 , the present invention proposes a large model multi-hop reasoning method enhanced by knowledge graph, and its main steps include:
[0040] Step 1: Extract entities in the question based on the given question.
[0041] Specifically, the given question is input into the entity naming recognition algorithm or tool, and the entities extracted are used as question entities. The given question can also be constructed by inputting the prompt words "You are an expert in entity extraction. Extract all entities from the following text. Text: Q"; where is a line break character, Q is a given question, and the question entity is obtained based on the answer of the large model.
[0042] Step 2: Based on the problem entities obtained in step 1, search the external knowledge graph for K_1-hop path knowledge P_1 starting from all problem entities, and search for path knowledge P_2 with a length not exceeding K_2 starting from all problem entity pairs. The obtained path knowledge P_1 and P_2 are used as candidate path knowledge.
[0043] Specifically, based on the problem entity obtained in step 1, using the breadth-first search algorithm or the depth-first search algorithm, with each problem entity as the starting point, search its K_1 jump path knowledge from the external knowledge graph, where K_1 is a predefined hyperparameter. After the search is completed, the path knowledge P_1 is obtained; at the same time, with all problem entity pairs as the starting and ending points, search for path knowledge with a length not exceeding K_2, where K_2 is a predefined hyperparameter. After the search is completed, the path knowledge P_2 is obtained. All the obtained path knowledge is used as candidate path knowledge.
[0044] It should be noted that, depending on the question to be answered, the external knowledge graph used can be a general knowledge graph, including Wikidata KG, FreeBase or YAGO, or a domain knowledge graph built for a specific field. The specific field is the field to which the given question belongs.
[0045] It should be noted that when searching for path knowledge, the path is limited to undirected or directed according to the needs of answering the question.
[0046] It should be noted that when searching for path knowledge, the length of the path can be adjusted according to the needs of answering the question. Generally speaking, the more complex the problem, the more reasoning steps are required and the longer the path.
[0047] It should be noted that when searching for path knowledge, considering the efficiency of the search, when there are many entities in the problem and the knowledge graph is relatively dense, that is, when the number of entities exceeds the first threshold and the density of the knowledge graph exceeds the second threshold, it is necessary to limit the length of the path or only search for paths related to the key entities in the problem. The first threshold and the second threshold can be set manually according to the actual situation.
[0048] Step 3: Based on the candidate path knowledge obtained in step 2, each path knowledge is converted into a text string, and the same encoder is used to calculate the embedding vector of the given question and path knowledge and calculate the similarity between them, retaining N_1 P_1 path knowledge with the highest similarity and N_2 P_2 path knowledge with the highest similarity.
[0049] Specifically, based on the candidate path knowledge obtained in step 2, each path knowledge is converted into a text string, which can be achieved by connecting the head entity, relationship and tail entity. Then, the same encoder is used to calculate the embedding vectors of the given question and path knowledge and calculate the similarity between them. The similarity can be calculated by the inner product of the embedding vectors of the given question and path knowledge. Then, N_1 P_1 path knowledge with the highest similarity and N_2 P_2 path knowledge with the highest similarity are retained. Here, N_1 and N_2 are both predefined hyperparameters.
[0050] It should be noted that considering the limitations of large model input and the negative impact of introducing noise data on the large model, the specific sizes of N_1 and N_2 need to be determined based on expert experience or experiments.
[0051] Step 4: Based on the filtered path knowledge obtained in step 3, the large model is used to aggregate the path knowledge to obtain more generalized global knowledge.
[0052] Specifically, based on the filtered path knowledge obtained in step 3, relying on the powerful reasoning and generation capabilities of the large model, the path knowledge is aggregated in an explicit way, and the generated global knowledge is described in natural language. This can be achieved by a simple summary, using the path knowledge to construct the prompt word "What can you infer from the following path knowledge? Path knowledge: P"; where is a line break, P is the filtered path knowledge, and the answer of the large model is taken as the global knowledge. The large model can also be prompted to group the path knowledge according to the information of the path knowledge, and then summarize and reason each group of path knowledge to obtain the corresponding global knowledge.
[0053] Step 5: Use predefined instruction templates to integrate the filtered path knowledge and aggregated global knowledge into the prompt words to stimulate the large model to generate answers based on the provided knowledge.
[0054] Specifically, a predefined instruction template is used to integrate the filtered path knowledge and the aggregated global knowledge, and then the prompt is placed in front of the input question to stimulate the large model to generate answers based on the provided external knowledge.
[0055] The knowledge graph enhanced large model multi-hop reasoning system provided by the present invention is described below. The knowledge graph enhanced large model multi-hop reasoning system described below and the knowledge graph enhanced large model multi-hop reasoning method described above can be referenced to each other.
[0056] Figure 2 The schematic diagram of the structure of the large model multi-hop reasoning system enhanced by the knowledge graph provided by the present invention is as follows: Figure 2 As shown, the present invention provides a set of knowledge graph enhanced large model multi-hop reasoning system, the system includes:
[0057] Entity recognition module, used to identify entities mentioned in the given question;
[0058] A path knowledge search module is used to search for multi-hop path knowledge starting from a problem entity and multi-hop path knowledge starting from and ending at a problem entity pair;
[0059] The filtering module is used to filter candidate path knowledge with high semantic similarity to the given question;
[0060] The path knowledge aggregation module is used to aggregate the path knowledge obtained through screening to form more generalized global knowledge;
[0061] The knowledge injection module is used to inject path knowledge and aggregated global knowledge into the large model, so that the large model can provide answers to given questions based on external knowledge.
[0062] This embodiment uses the clear entity relationships in the knowledge graph to inject path knowledge into the large model, effectively improving the reasoning ability of the large model and reducing the generation of hallucinations.
[0063] For the system embodiment, since it basically corresponds to the method embodiment, the relevant parts can refer to the partial description of the method embodiment. The system embodiment described above is only schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present application solution.
[0064] Corresponding to the embodiment of the large model multi-hop reasoning method enhanced by the aforementioned knowledge graph, the embodiment of the present application also provides an electronic device, including: one or more processors; a memory for storing one or more programs; when the one or more programs are executed by the one or more processors, the one or more processors implement the large model multi-hop reasoning method enhanced by the aforementioned knowledge graph. Figure 3 As shown, it is a hardware structure diagram of any device with data processing capability in the knowledge graph enhanced large model multi-hop reasoning method provided in the embodiment of the present application, except Figure 3 In addition to the processor, memory, DMA controller, disk, and non-volatile memory shown, any device with data processing capabilities in which the apparatus in the embodiment is located may also include other hardware, which will not be described in detail, generally based on the actual functions of the device with data processing capabilities.
[0065] Corresponding to the embodiment of the aforementioned knowledge graph enhanced large model multi-hop reasoning method, an embodiment of the present invention also provides a computer-readable storage medium on which a program is stored. When the program is executed by a processor, the knowledge graph enhanced large model multi-hop reasoning method in the above embodiment is implemented.
[0066] The computer-readable storage medium may be an internal storage unit of any device with data processing capability described in any of the aforementioned embodiments, such as a hard disk or a memory. The computer-readable storage medium may also be any device with data processing capability, such as a plug-in hard disk, a smart media card (SMC), an SD card, a flash card, etc. equipped on the device. Furthermore, the computer-readable storage medium may also include both an internal storage unit of any device with data processing capability and an external storage device. The computer-readable storage medium is used to store the computer program and other programs and data required by any device with data processing capability, and may also be used to temporarily store data that has been output or is to be output.
[0067] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
[0068] The above embodiments are only used to illustrate the design ideas and features of the present invention, and their purpose is to enable those skilled in the art to understand the content of the present invention and implement it accordingly. The protection scope of the present invention is not limited to the above embodiments. Therefore, any equivalent changes or modifications made based on the principles and design ideas disclosed by the present invention are within the protection scope of the present invention.
Claims
1. A large model multi-hop reasoning method enhanced by knowledge graph, characterized in that: The following steps are involved: Step 1: Extract entities in the question based on the given question; Step 2: Based on the problem entities obtained in step 1, search for K_1-hop path knowledge P_1 starting from all problem entities from the external knowledge graph, and search for path knowledge P_2 starting from all problem entity pairs and ending at a length not exceeding K_2, and use the obtained path knowledge as candidate path knowledge; Step 3: Based on the candidate path knowledge obtained in step 2, convert each path knowledge into a text string, use the same encoder to calculate the embedding vector of the given question and path knowledge and calculate the similarity between them, retaining N_1 P_1 path knowledge with the highest similarity and N_2 P_2 path knowledge with the highest similarity; Step 4: Based on the filtered path knowledge obtained in step 3, use the large model to aggregate these path knowledge to obtain global knowledge; Step 5: Use predefined instruction templates to integrate the filtered path knowledge and aggregated global knowledge into the prompt words, stimulating the large model to provide answers to given questions based on external knowledge.
2. The large-model multi-hop reasoning method enhanced by knowledge graph according to claim 1, characterized in that: The step 1 comprises: Input the given question into the entity naming recognition algorithm or tool, and use the extracted entities as the question entities; or construct the given question with the input prompt "You are an expert in entity extraction. Extract all entities from the following text. Text: Q"; where is a line break character, Q is a given question, and the question entity is obtained based on the answer of the large model.
3. The large-model multi-hop reasoning method enhanced by knowledge graph as claimed in claim 1, characterized in that: The step 2 comprises: Based on the problem entity obtained in step 1, use the breadth-first search algorithm or the depth-first search algorithm, take each problem entity as the starting point, search its K_1 jump path knowledge from the external knowledge graph, and after the retrieval is completed, obtain the path knowledge P_1; at the same time, take all problem entity pairs as the starting and ending points, search for path knowledge with a length not exceeding K_2, and after the retrieval is completed, obtain the path knowledge P_2; use all the obtained path knowledge as candidate path knowledge; where K_1 and K_2 are both predefined hyperparameters.
4. The knowledge graph-enhanced large model multi-hop reasoning method according to claim 1, characterized in that: The step 2 further comprises: Depending on the questions that need to be answered, the external knowledge graphs used include general knowledge graphs and domain knowledge graphs built for specific fields; the general knowledge graphs include Wikidata KG, FreeBase and YAGO.
5. The large-model multi-hop reasoning method enhanced by knowledge graph according to claim 1, characterized in that: The step 2 further comprises: When searching for path knowledge, if the number of entities in the problem exceeds the first threshold and the density of the knowledge graph exceeds the second threshold, the length of the path is limited or only the paths related to the key entities in the problem are searched; among which, the length of the path is positively correlated with the complexity of the problem.
6. The knowledge graph-enhanced large model multi-hop reasoning method according to claim 1, characterized in that: The step 3 comprises: Based on the candidate path knowledge obtained in step 2, each path knowledge is converted into a text string by connecting the head entity, relationship and tail entity. The same encoder is used to calculate the embedding vectors of the given question and path knowledge and calculate the similarity between them. The similarity is calculated by the inner product of the embedding vectors of the given question and path knowledge. Then, N_1 P_1 path knowledge with the highest similarity and N_2 P_2 path knowledge with the highest similarity are retained, where N_1 and N_2 are both predefined hyperparameters.
7. The knowledge graph-enhanced large model multi-hop reasoning method according to claim 1, characterized in that: The step 4 comprises: Based on the filtered path knowledge obtained in step 3, relying on the reasoning and generation capabilities of the large model, the path knowledge is aggregated in an explicit manner and global knowledge is generated using natural language descriptions.
8. A large model multi-hop reasoning system that implements the knowledge graph enhancement method of claim 1, characterized in that: include: Entity recognition module, used to identify entities mentioned in the given question; A path knowledge search module is used to search for multi-hop path knowledge starting from a problem entity and multi-hop path knowledge starting from and ending at a problem entity pair; The filtering module is used to filter candidate path knowledge with high semantic similarity to the given question; The path knowledge aggregation module is used to aggregate the path knowledge obtained through screening to form global knowledge; The knowledge injection module is used to inject path knowledge and aggregated global knowledge into the large model, so that the large model can provide answers to given questions based on external knowledge.
9. An electronic device, comprising a memory and a processor, characterized in that: The memory is coupled to the processor; wherein the memory is used to store program data, and the processor is used to execute the program data to implement the knowledge graph enhanced large model multi-hop reasoning method described in any one of claims 1-7 above.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the large-model multi-hop reasoning method enhanced by the knowledge graph as described in any one of claims 1-7 is implemented.
Citation Information
Patent Citations
Knowledge graph multi-hop question and answer reasoning method and device and computer equipment
CN116992008A
Query method integrating AI large model and knowledge graph
CN118916499A