Knowledge-driven large language model reasoning method and device, equipment and medium
Patent Information
- Application Number
- CN202410527975.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-29
- Publication Date
- 2026-08-21
- Estimated Expiration
- 2044-04-29
AI Technical Summary
[0007]本发明提供一种知识驱动的大语言模型推理方法、装置、设备及介质,解决了相关技术中大语言模型可解释性不足、特定领域知识不足、知识更新难度大以及对知识图谱质量高度依赖的问题
[0049] This application addresses several issues encountered by large language models during reasoning, including a lack of specific knowledge, the generation of illusionary and harmful text, high knowledge update costs, and over-reliance on the quality of knowledge graphs. By introducing external knowledge, this application provides ample knowledge support for large language models, enabling them to reason more comprehensively and accurately in specific knowledge-based situations. Furthermore, by combining knowledge graphs with large language models for reasoning, the transparency and interpretability of reasoning are improved, the accuracy of reasoning is enhanced, and the cost of knowledge updates is reduced. This application provides strong support for the reasoning capabilities of large language models, promoting the development and application of artificial intelligence technology.
Smart Images

Figure CN118333169B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of natural language processing technology, and in particular to a knowledge-driven large language model reasoning method, apparatus, device, and medium. Background Technology
[0002] With the development of artificial intelligence technology in the field of natural language processing, Large Language Models (LLMs), as an advanced deep learning architecture, have made significant progress in understanding and generating human language, and have shown outstanding performance in instruction understanding and knowledge response generation.
[0003] Large language models enhance the reasoning mechanism by using techniques such as thought chains and thought trees, and expand the intermediate steps in the reasoning process. This improves the reasoning ability of large models to a certain extent, but it cannot improve the interpretability of the models because they mainly rely on the model's own knowledge and lack the ability to deeply understand and update specific topics in real time. Therefore, this limits the further improvement of their reasoning efficiency to a certain extent.
[0004] Existing large language models, when dealing with specialized domains or time-sensitive knowledge not covered in the pre-training phase, are prone to incomplete or outdated knowledge coverage due to their reliance on pre-trained text data for reasoning and generation. This affects their ability to provide accurate information in specific scenarios. In the absence of sufficient relevant knowledge, they may generate seemingly reasonable but actually fictitious "illusory text," as well as potentially harmful information. Users may be confused because they cannot accurately understand the specific reasons or logic behind the model's text generation, potentially leading to misunderstandings or misinterpretations, posing a significant risk to users.
[0005] However, updating knowledge in large language models is a costly and time-consuming process, making it difficult for the models to update in a timely and cost-effective manner when faced with rapidly changing knowledge environments, thereby reducing their responsiveness to the latest knowledge and information.
[0006] Among the related technologies known to the inventor, the patent application document with patent number CN117575026A discloses a "large model reasoning analysis method system and product based on external knowledge enhancement". It improves the knowledge completeness and accuracy of the model by combining a large language model with a knowledge graph for reasoning. The large language model is used to extract entity information from unstructured text and convert it into a form suitable for knowledge graph query. However, it does not really participate in the core links of the reasoning process. Once the structural integrity of the knowledge graph itself is insufficient or some knowledge points are missing, even with such a combination method, the large language model still cannot ensure the accuracy of the reasoning results. Therefore, it relies too much on the quality of the knowledge graph. Summary of the Invention
[0007] This invention provides a knowledge-driven method, apparatus, device, and medium for reasoning using large language models, which solves the problems of insufficient interpretability of large language models, insufficient knowledge in specific domains, difficulty in knowledge updating, and high dependence on the quality of knowledge graphs in related technologies.
[0008] To achieve the above objectives, this application adopts the following technical solution:
[0009] Firstly, a knowledge-driven reasoning method for large language models is provided, including the following steps:
[0010] Reasoning subgraph generation: Extract the main entity through the large language model, match the related information in the external database, build and optimize the knowledge structure, and generate a queryable subgraph;
[0011] Subgraph search reasoning: Construct a large language model capable of converting natural language questions into Cypher queries, and perform subgraph retrieval in the external database;
[0012] Joint graph reasoning: If the subgraph search reasoning does not retrieve an answer, the knowledge of the previous hop of the question is used as input to obtain the most relevant knowledge from the external database. The large language model then performs joint reasoning based on the most relevant knowledge and the question to generate the final answer.
[0013] In a first possible implementation of the first aspect, the reasoning subgraph generation step specifically includes the following steps:
[0014] Main entity extraction: Identify and analyze keywords or phrases for a given question using a large language model, perform semantic understanding on the keywords or phrases, and determine the entity most relevant to the question;
[0015] Entity relationship matching: Interact with the external database using a predefined query language to obtain a set of knowledge triples related to the problem;
[0016] Reasoning subgraph generation: The large language model generates a subgraph structure description based on the knowledge triple set, and converts the subgraph structure description into a graph query language expression; at the same time, the knowledge triple set is imported into the graph database to construct the corresponding nodes and relations, and a reasoning subgraph is generated.
[0017] Based on any of the possible implementations of the first aspect described above, in the second possible implementation of the first aspect, the entity relationship matching step specifically includes the following steps:
[0018] The main entity is used as the subject and object respectively to perform relation queries, and the corresponding relations are obtained and a relation set is formed.
[0019] Perform a tail entity query to obtain the tail entity element;
[0020] The knowledge triple set is constructed based on the main entity, the relation set, and the tail entity elements.
[0021] Based on any of the possible implementations of the first aspect described above, in the third possible implementation of the first aspect, the subgraph search reasoning step specifically includes the following steps:
[0022] Seed dataset generation: Extract and filter domain-related questions from the original data source to generate a seed dataset;
[0023] Coarse dataset generation: The large language model is used to generalize the problems in the seed dataset to generate Cypher data and a coarse dataset; wherein, based on the generated generalized problems, a corresponding domain data structure is constructed to generate the seed dataset;
[0024] Selected dataset generation: Cypher validation is performed on the problems in the coarse dataset, the validated data is manually judged, and a selected dataset is generated by combining it with other types of Cypher data;
[0025] The pedestal model is fine-tuned using supervised learning with an instruction dataset to obtain a Cypher LLM, and the Cypher LLM is optimized with human feedback; wherein, the instruction dataset includes the selected dataset;
[0026] Based on the Cypher LLM, the problem is transformed into a query statement that the graph database can understand, and the query is performed in the subgraph of the graph database.
[0027] Based on any of the possible implementations of the first aspect described above, in the fourth possible implementation of the first aspect, the joint graph reasoning step specifically includes the following steps:
[0028] If the subgraph search reasoning fails to retrieve an answer, a Cypher query statement for the previous hop knowledge of the question is generated, and the most relevant knowledge is obtained from the graph database; combined with the knowledge of the large language model itself, joint reasoning is performed to generate the final answer.
[0029] Secondly, a knowledge-driven large language model reasoning device is provided, including:
[0030] The reasoning subgraph generation module is used to extract main entities through a large language model, match related information in an external database, build and optimize the knowledge structure, and generate queryable subgraphs.
[0031] The subgraph search reasoning module is used to construct a large language model capable of converting natural language questions into Cypher queries and to perform subgraph retrieval in the external database.
[0032] The joint graph reasoning module is used to obtain the most relevant knowledge from the external database by taking the previous hop knowledge of the question as input when the subgraph search reasoning fails to retrieve the answer. The module then performs joint reasoning based on the most relevant knowledge and the question through the large language model to generate the final answer.
[0033] In a first possible implementation of the second aspect, the inference subgraph generation module includes:
[0034] The main entity extraction module is used to identify and analyze keywords or phrases for a given question using a large language model, perform semantic understanding on the keywords or phrases, and determine the entity most relevant to the question.
[0035] The entity relationship matching module is used to interact with the external database using a predefined query language to obtain a set of knowledge triples related to the problem;
[0036] The reasoning subgraph generation module is used to generate a subgraph structure description based on the knowledge triple set using the large language model, and convert the subgraph structure description into a graph query language expression; at the same time, the knowledge triple set is imported into the graph database to construct the corresponding nodes and relations, and generate the reasoning subgraph.
[0037] Based on any of the possible implementations of the second aspect described above, in the second possible implementation of the first aspect, the entity relationship matching module is specifically used for:
[0038] The main entity is used as the subject and object respectively to perform relation queries, and the corresponding relations are obtained and a relation set is formed.
[0039] Perform a tail entity query to obtain the tail entity element;
[0040] The knowledge triple set is constructed based on the main entity, the relation set, and the tail entity elements.
[0041] Based on any of the possible implementations of the second aspect described above, in the third possible implementation of the first aspect, the subgraph search reasoning module includes:
[0042] The seed dataset generation module is used to extract and filter domain-related questions from the original data source to generate a seed dataset.
[0043] The coarse dataset generation module is used to generalize the problems in the seed dataset using the large language model to generate Cypher data and a coarse dataset; wherein, based on the generated generalized problems, a corresponding domain data structure is constructed to generate the seed dataset;
[0044] The selected dataset generation module is used to perform Cypher validation on the problems in the coarse dataset, manually judge the validated data, and combine it with other types of Cypher data to generate a selected dataset.
[0045] The fine-tuning module is used to perform supervised learning fine-tuning of the base model using the instruction dataset to obtain the Cypher LLM, and to optimize the Cypher LLM through human feedback; wherein the instruction dataset includes the selected dataset;
[0046] The retrieval module is used to transform the problem into a query statement that the graph database can understand based on the Cypher LLM, and to perform retrieval in the subgraphs of the graph database.
[0047] Thirdly, an electronic device is proposed, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the knowledge-driven large language model reasoning method as described in the first aspect.
[0048] Fourthly, a readable storage medium is proposed, on which a program or instructions are stored, which, when executed by a processor, implement the steps of the knowledge-driven large language model reasoning method as described in the first aspect.
[0049] This application addresses several issues encountered by large language models during reasoning, including a lack of specific knowledge, the generation of illusionary and harmful text, high knowledge update costs, and over-reliance on the quality of knowledge graphs. By introducing external knowledge, this application provides ample knowledge support for large language models, enabling them to reason more comprehensively and accurately in specific knowledge-based situations. Furthermore, by combining knowledge graphs with large language models for reasoning, the transparency and interpretability of reasoning are improved, the accuracy of reasoning is enhanced, and the cost of knowledge updates is reduced. This application provides strong support for the reasoning capabilities of large language models, promoting the development and application of artificial intelligence technology. Attached Figure Description
[0050] Figure 1 A schematic flowchart illustrating a knowledge-driven large language model reasoning method provided in an embodiment of this application;
[0051] Figure 2A schematic flowchart illustrating another knowledge-driven large language model reasoning method provided in an embodiment of this application;
[0052] Figure 3 A schematic flowchart for generating a reasoning subgraph is provided in an embodiment of this application;
[0053] Figure 4 A schematic flowchart illustrating entity relationship matching provided for an embodiment of this application;
[0054] Figure 5 A schematic flowchart illustrating another entity relationship matching method provided in this application embodiment;
[0055] Figure 6 A schematic flowchart illustrating another inference subgraph generation provided in this application embodiment;
[0056] Figure 7 A schematic flowchart illustrating subgraph search reasoning provided in an embodiment of this application;
[0057] Figure 8 A schematic flowchart illustrating the construction of a dataset as provided in an embodiment of this application;
[0058] Figure 9 A schematic flowchart illustrating model fine-tuning provided for an embodiment of this application;
[0059] Figure 10 This is a schematic flowchart illustrating a joint graph reasoning graph provided in an embodiment of this application.
[0060] Figure 11 A schematic diagram of the structure of a knowledge-driven large language model reasoning device provided in an embodiment of this application;
[0061] Figure 12 This is a schematic diagram of the structure of a reasoning subgraph generation module provided in an embodiment of this application;
[0062] Figure 13 This is a schematic diagram of the structure of a subgraph search reasoning module provided in an embodiment of this application;
[0063] Figure 14 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0064] To further illustrate the technical means and effects adopted by the present invention to achieve its intended purpose, the technical solutions in the embodiments of this application are clearly described. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art are within the scope of protection of this application.
[0065] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such terms can be used interchangeably where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0066] The steps described in the specification and the flowcharts in the accompanying drawings of this invention are not necessarily strictly executed according to the step numbers; the execution order of the method steps can be changed. Furthermore, certain steps can be omitted, multiple steps can be combined into one step, and / or one step can be broken down into multiple steps.
[0067] The following detailed description of a knowledge-driven large language model reasoning method and apparatus provided in the present invention, in conjunction with the accompanying drawings and preferred embodiments, is as follows.
[0068] Compared to language models with fewer parameters, large language models have demonstrated stronger generalization capabilities across various natural language processing tasks. However, current inference techniques for large models primarily focus on developing thought chains, thought trees, and mind maps. While these methods extend the intermediate steps in the inference process and improve the inference capabilities of large models to some extent, they fail to enhance interpretability because they rely heavily on the model's own knowledge, thus limiting the inference power of large models to some extent.
[0069] First, large language models typically fail to accurately answer questions requiring expertise beyond the pre-training phase, especially concerning outdated knowledge, as they rely solely on pre-learned text data for reasoning and generation. Second, the lack of interpretability and transparency in large language models increases user concerns about the risks of "illusory text" and "harmful text." Finally, the training process for large language models is often both expensive and time-consuming, making it difficult for them to maintain up-to-date knowledge.
[0070] Among the known methods for reasoning using knowledge graphs to assist large language models, such as the "System and Product of Large Model Reasoning Analysis Method Based on External Knowledge Enhancement" disclosed in patent application CN117575026A, the large model extracts knowledge contained in the statement to be analyzed, obtaining internal knowledge graph triples; the statement to be analyzed is input into a knowledge retrieval module to obtain external knowledge graph triples; based on the internal and external knowledge graph triples, a context subgraph is obtained, and the context subgraph is input into a pre-trained graph neural network reasoning analysis module to obtain the statement analysis result. It is evident that in this method, the large language model only plays the role of knowledge extraction and translation, i.e., entity extraction and participation in the translation of the knowledge graph query language, but it does not directly participate in the reasoning process of the knowledge graph. This method may fail to find answers when searching large-scale databases due to insufficient reasoning paths or knowledge, leading to erroneous reasoning.
[0071] In other words, (1) large language models have a problem of specific knowledge deficiency: that is, large language models mainly rely on pre-learned text data for reasoning and generation. In this case, the model will provide relevant information, but it may not be comprehensive or accurate enough because it lacks the ability to have a deep understanding of specific topics and to update in real time.
[0072] Large language models suffer from the problems of generating illusionary and harmful text: due to their lack of relevant knowledge, large language models may generate illusionary answers uncontrollably. Users may be confused because they cannot accurately understand the specific reasons or logic behind the text generated by the model, which may lead to misunderstandings or misinterpretations. Moreover, the lack of specific behavioral norms for the model may result in the generation of inaccurate or harmful information that users cannot understand or discern.
[0073] Large language models suffer from high knowledge update costs: knowledge updates often require pre-training or fine-tuning, a process that is both expensive and time-consuming.
[0074] Large language models suffer from the problem of over-reliance on the quality of knowledge graphs in their reasoning results: in reasoning methods that combine large language models with knowledge graphs, the large language model often only performs the work of knowledge extraction and translation, without participating in the reasoning process. Therefore, if the reasoning path or knowledge in the knowledge graph is lacking, the correct answer cannot be reasoned.
[0075] Therefore, in view of the shortcomings in (1) to (4) above, this application provides a knowledge-driven large language model reasoning method and apparatus, which provides external knowledge for the large language model so that it has sufficient knowledge to support its reasoning of specific knowledge; makes the large language model have a basis to follow when reasoning, and enhances its transparency and interpretability; introduces external knowledge to update the reasoning knowledge of the large model, which greatly saves time and cost; at the same time, the knowledge graph and the large language model jointly perform reasoning, and use the large language model to construct knowledge into a knowledge subgraph with an effective reasoning path and combine the knowledge of the knowledge graph and the knowledge of the large language model itself for joint reasoning, which greatly improves the accuracy of reasoning.
[0076] Please see Figure 1-12 This application provides a knowledge-driven large language model reasoning method, such as... Figure 2 As shown, the knowledge-driven large language model reasoning method of this application embodiment includes the following steps:
[0077] Step 110, Reasoning Subgraph Generation: Extract the main entity through the large language model, match the related information in the external database, construct and optimize the knowledge structure, and generate a queryable subgraph.
[0078] Extracting the principal entities is a crucial step in deep reasoning on a problem. The principal entity refers to the core and most representative entity or concept in the problem, through which relevant knowledge can be retrieved from an external knowledge base, thereby constructing a reasoning subgraph. Utilizing a large language model to perform this operation allows for efficient and accurate extraction of the principal entities.
[0079] See Figure 3 The generation of the above-mentioned reasoning subgraph specifically includes the following steps:
[0080] Step 111, Main Entity Extraction: Identify and analyze keywords or phrases for the given question using a large language model, perform semantic understanding on the keywords or phrases, and determine the entities most relevant to the question.
[0081] Specifically, first, the model needs to deeply understand the given problem, including identifying key information, themes, and context to determine potential principal entities. Second, the model can identify potential principal entities by recognizing keywords or phrases in the problem that are typically associated with the problem's theme and focus. Finally, after identifying keywords, the model needs to perform semantic understanding on these keywords to determine their meaning and importance in a specific context, used to eliminate irrelevant entities and find the principal entity most relevant to the problem.
[0082] Step 112, Entity Relationship Matching: Interact with an external database using a predefined query language to obtain a set of knowledge triples related to the problem.
[0083] After identifying the main entity, knowledge related to the main entity is retrieved, thereby effectively extracting relevant entities and relationships from the database.
[0084] See Figure 4-5 Specifically, this can be done by inputting it into an external RDF database to perform knowledge retrieval and obtain relevant information. For example, using the predefined SPARQL query language to interact with the database to retrieve knowledge related to the main entity can include the following steps:
[0085] 112a, use the main entity as the subject and object respectively to perform relation queries, obtain the corresponding relations respectively, and form a relation set;
[0086] 112b, perform a tail entity query to obtain the tail entity element;
[0087] 112c, constructs a set of knowledge triples based on the main entity, the set of relations, and the tail entity elements.
[0088] By following the above entity relationship matching process and steps, relevant entities and relationships can be effectively extracted from the database, thereby supporting deeper knowledge mining and analysis.
[0089] Step 113, Inference Subgraph Generation: Generate a subgraph structure description based on the knowledge triple set using a large language model, and convert the subgraph structure description into a graph query language expression; at the same time, import the knowledge triple set into the graph database to construct the corresponding nodes and relationships, and generate the inference subgraph.
[0090] See Figure 6 In other words, after obtaining the set of knowledge triples related to the problem, a large language model is used to perform professional subgraphization processing on the obtained triples. This subgraphization process mainly covers two core aspects.
[0091] First, a detailed description of the subgraph structure is generated using a large language model. This description not only accurately reflects the logical relationships between triples but also provides sufficient contextual information and reasoning paths to ensure a smooth NL2Cypher transformation of the corresponding subgraph (see explanation below). This step ensures the logical coherence and accuracy of the subgraph structure, laying a solid foundation for subsequent graph queries.
[0092] Simultaneously, a subgraph import operation is performed, importing the processed set of knowledge triples into the graph database. This process fully leverages the efficient storage and query capabilities of the graph database, transforming triples into nodes and relations within the database, thus constructing a queryable subgraph. This not only improves data accessibility but also enables efficient retrieval of the subgraph using the graph database's query language. Through these two processes, relevant triple knowledge is retrieved from external databases, and a query subgraph with a clear reasoning path is generated using a large language model and imported into the graph database, providing strong data support for subsequent problem-solving.
[0093] Step 120, Subgraph Search Inference: Construct a large language model capable of converting natural language questions into Cypher queries, and perform subgraph retrieval in an external database.
[0094] After obtaining the queryable subgraph, we first perform a K-hop subgraph search inference. If the answer is found, the inference process ends, and the relevant search results are output.
[0095] See Figure 7-9 Specifically, this step employs the NL2Cypher technique to ensure the accuracy and efficiency of reasoning. This technique is a method for converting natural language into Cypher query statements, and Cypher is the query language used by the Neo4j graph database. Based on this, user-input questions can be transformed into query statements that the Neo4j graph database can understand, thereby enabling precise retrieval within the subgraph.
[0096] Furthermore, in order to achieve efficient application of NL2Cypher technology, the knowledge-driven large language model reasoning method of this application embodiment has fine-tuned the general large language model, mainly including two key steps: data construction and model fine-tuning.
[0097] For example, the first step is the construction of the dataset, see... Figure 7-8 Specifically, it includes the following steps:
[0098] Step 121, Seed dataset generation: Extract domain-related questions from the original data source and filter them to generate a seed dataset.
[0099] Data is loaded from the original data source. Based on the loaded data, domain-related questions are posed. After question filtering, an initial seed dataset is generated. Prompt can create hints or guiding statements for these questions.
[0100] Step 122, Coarse Dataset Generation: The problems in the seed dataset are generalized using a large language model to generate Cypher data and a coarse dataset. Specifically, based on the generated generalized problems, corresponding domain data structures can be constructed to load the data and further generate the seed dataset.
[0101] Step 123, Selected Dataset Generation: Cypher validation is performed on the problems in the coarse dataset. The validated data is then manually reviewed and combined with other types of Cypher data to generate a selected dataset. This final selected dataset is used to train the model.
[0102] In the aforementioned data construction process, based on 20,000 12345 data entries, the generated training data underwent screening and inspection to select high-quality data as the training set, including 3,000 NL2Cypher question-answer pairs (12345 domain data: other types of data = 7:3), ensuring the high quality of the final dataset. The Cypher data refers to data from the 12345 domain, while the other types of Cypher data include other types of Cypher data besides the 12345 domain.
[0103] Next, see Figure 7 , Figure 9 After obtaining the selected datasets mentioned above, the open-source model was fine-tuned using LoRa. The specific steps are as follows:
[0104] Step 124: Use the instruction dataset to perform supervised learning fine-tuning on the pedestal model to obtain the Cypher LLM, and optimize the Cypher LLM through human feedback. The instruction dataset includes a selected dataset.
[0105] Based on a pre-trained base model, such as the Tongyi Qianwen open-source model, which has been pre-trained on a large amount of text data and possesses a certain general language understanding capability, a dataset containing instructions and corresponding target outputs is needed to fine-tune the model for specific tasks. In this embodiment, the instruction dataset contains natural language questions and corresponding Cypher query statements. Supervised learning fine-tuning of the base model is performed using the instruction dataset. Through this step and process, the model learns to map the input natural language question to the correct Cypher query statement. Fine-tuning typically involves running multiple training iterations on the instruction dataset, adjusting the model parameters to minimize the difference between the predicted output and the target output. After fine-tuning, the resulting model can be called a Cypher LLM (Large Language Model), indicating that the model has the ability to convert natural language questions into Cypher queries. Finally, in practical applications, the performance of Cypher LLM can be evaluated and improved through human feedback. Users can provide feedback on whether the Cypher queries generated by the model are accurate and meet their needs, further contributing to the continuous improvement and optimization of the model.
[0106] Step 125: Based on Cypher LLM, the problem is transformed into a query statement that the graph database can understand, and then retrieved within the subgraph of the graph database. In other words, the input problem is converted into a Cypher statement and retrieved within the subgraph of the graph database.
[0107] Through the above fine-tuning steps and processes, the large language model is customized to adapt to specific tasks. That is, the fine-tuned large language model has NL2Cypher capabilities, which can be used to convert questions into Cypher query statements to retrieve data from the database and complete reasoning. Querying and reasoning are performed in the Neo4j graph database, which can more effectively handle specific types of questions. If the answer is retrieved, the reasoning process ends and the relevant search results are output. Otherwise, the next step of joint reasoning is performed. The joint reasoning is explained below.
[0108] Step 130, Joint Graph Reasoning: If the subgraph search reasoning fails to retrieve the answer, the knowledge of the previous hop of the question is used as input to obtain the most relevant knowledge from the external database. The large language model then performs joint reasoning based on this most relevant knowledge and the question to generate the final answer.
[0109] If subgraph retrieval fails to find the expected result when searching for a question's answer, it means that the constructed knowledge subgraph has knowledge gaps in some aspects. In this case, simply relying on the knowledge graph for reasoning may not achieve satisfactory results. Therefore, we need to combine the rich knowledge of the large language model itself for joint reasoning.
[0110] See Figure 10 Considering that the problem is K-hop, meaning the answer may require traversing multiple knowledge nodes to find, the most relevant knowledge in the knowledge graph with an effective reasoning path is likely distributed in the knowledge of the previous or next hop of the problem. Therefore, this application focuses on knowledge nodes that are directly or indirectly related to the problem to find potential answer clues. To effectively utilize the large language model for joint reasoning, this application chooses to use the knowledge of the previous hop of the problem as input.
[0111] In the specific implementation process, if the subgraph search reasoning fails to retrieve the answer, a Cypher query statement for the previous hop knowledge of the query question is generated and the most relevant knowledge is obtained from the graph database. Then, combined with the knowledge of the large language model itself, joint reasoning is performed to generate the final answer.
[0112] The principle behind this approach is that the previous-hop knowledge is usually more directly related to the question. It may contain background information, preconditions, or related concepts, which are crucial for the large language model to understand the question and provide an accurate answer. By inputting the previous-hop knowledge into the large language model and combining it with other relevant information from the knowledge graph, a complete reasoning environment can be constructed. The large language model can then perform deep reasoning within this environment, generating answers or explanations relevant to the question. Based on this, it can compensate for the shortcomings of the knowledge graph and provide more comprehensive and accurate answers.
[0113] Compared with the related technologies known to the inventors, the knowledge-driven large language model reasoning method of the present application integrates multiple steps such as problem main entity extraction, entity relationship matching, queryable subgraph generation, subgraph search reasoning, and joint reasoning to form a complete and coherent external knowledge-driven reasoning process, which significantly improves the reasoning accuracy.
[0114] This application's embodiments construct a knowledge subgraph closely related to the problem. This subgraph enables the model to combine specific knowledge to more accurately understand the problem's background, analyze logical relationships, and solve unanswerable questions. Simultaneously, the knowledge subgraph provides the model with a reliable source of knowledge, effectively avoiding the generation of illusion problems and improving the quality and security of the generated text.
[0115] This application's embodiments divide the reasoning process into two key steps. First, direct search reasoning is performed on the subgraph. When the information contained in the knowledge subgraph is sufficient, this step can directly deduce the answer. However, if the constructed knowledge subgraph has missing or insufficient information, relying solely on subgraph search reasoning will not yield accurate conclusions and may lead to reasoning errors. In this case, this application's embodiments introduce a second reasoning process: retrieving the higher-level knowledge related to the question and combining it with the knowledge base within the large language model for joint reasoning. This approach not only compensates for the lack of information in the knowledge subgraph but also leverages the powerful semantic understanding and reasoning capabilities of the large language model to improve the overall accuracy and robustness of the reasoning.
[0116] Please see Figure 11 This application provides a knowledge-driven large language model reasoning device, which corresponds to the knowledge-driven large language model reasoning method provided in this application. The knowledge-driven large language model reasoning device of this application implements the various processes of the above method embodiments and can achieve the same technical effect, including:
[0117] The reasoning subgraph generation module 1 is used to extract the main entity through a large language model, match related information in an external database, construct and optimize the knowledge structure, and generate a queryable subgraph.
[0118] Subgraph search reasoning module 2 is used to construct a large language model with the ability to convert natural language questions into Cypher queries and to perform subgraph retrieval in the external database.
[0119] The joint graph reasoning module 3 is used to obtain the most relevant knowledge from the external database by taking the previous hop knowledge of the question as input when the subgraph search reasoning fails to retrieve the answer. The module then uses the large language model to perform joint reasoning based on the most relevant knowledge and the question to generate the final answer.
[0120] See Figure 12 The reasoning subgraph generation module 1 includes:
[0121] The main entity extraction module 11 is used to identify and analyze keywords or phrases for a given question through a large language model, perform semantic understanding on the keywords or phrases, and determine the entity most relevant to the question.
[0122] The entity relationship matching module 12 is used to interact with the external database using a predefined query language to obtain a set of knowledge triples related to the problem;
[0123] The reasoning subgraph generation module 13 is used to generate a subgraph structure description based on the knowledge triple set through the large language model, and convert the subgraph structure description into a graph query language expression; at the same time, the knowledge triple set is imported into the graph database to construct the corresponding nodes and relations, and generate the reasoning subgraph.
[0124] The entity relationship matching module 12 is specifically used for:
[0125] The main entity is used as the subject and object respectively to perform relation queries, and the corresponding relations are obtained and a relation set is formed.
[0126] Perform a tail entity query to obtain the tail entity element;
[0127] The knowledge triple set is constructed based on the main entity, the relation set, and the tail entity elements.
[0128] See Figure 13 The subgraph search reasoning module 2 includes:
[0129] The seed dataset generation module 21 is used to extract and filter domain-related questions from the original data source to generate a seed dataset.
[0130] The coarse dataset generation module 22 is used to generalize the problems in the seed dataset using the large language model to generate Cypher data and a coarse dataset; wherein, based on the generated generalized problems, a corresponding domain data structure is constructed to generate the seed dataset;
[0131] The selected dataset generation module 23 is used to perform Cypher verification on the problems in the coarse dataset, manually judge the verified data, and combine it with other types of Cypher data to generate a selected dataset;
[0132] Fine-tuning module 24 is used to perform supervised learning fine-tuning of the base model using the instruction dataset to obtain Cypher LLM, and to optimize the Cypher LLM through human feedback; wherein, the instruction dataset includes the selected dataset;
[0133] The retrieval module 25 is used to convert the problem into a query statement that the graph database can understand based on the Cypher LLM, and to perform retrieval in the subgraphs of the graph database.
[0134] Please see Figure 14 This application provides an electronic device that corresponds to the knowledge-driven large language model reasoning method provided in this application. The electronic device implements the various processes of the above method embodiments and achieves the same technical effects; therefore, to avoid repetition, further details are omitted here. Figure 14 As shown, the electronic device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, it implements the steps of the knowledge-driven large language model reasoning method of the above embodiments.
[0135] The memory 1009 can be used to store software programs and various data. The memory 1009 may primarily include a first storage area for storing programs or instructions and a second storage area for storing data. The first storage area may store the operating system, application programs or instructions required for at least one function (such as sound playback, image playback, etc.). Furthermore, the memory 1009 may include volatile memory or non-volatile memory, or both. The non-volatile memory may be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct memory bus RAM (DRRAM). The memory 1009 in this embodiment includes, but is not limited to, these and any other suitable types of memory.
[0136] The processor 1010 may include one or more processing units; optionally, the processor 1010 integrates an application processor and a modem processor, wherein the application processor mainly handles operations involving the operating system, user interface, and applications, and the modem processor mainly handles wireless communication signals, such as a baseband processor. It is understood that the aforementioned modem processor may also not be integrated into the processor 1010.
[0137] This application embodiment also provides a readable storage medium, which corresponds to the knowledge-driven large language model reasoning method provided in this application embodiment. The readable storage medium of this application embodiment implements the various processes of the above method embodiment. The readable storage medium stores a program or instructions. When the program or instructions are executed by the processor, they implement the various processes of the readable storage medium embodiment of the above embodiment and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0138] The processor is the processor in the electronic device described in the above embodiments of this application. The readable storage medium includes a computer-readable storage medium, such as a computer read-only memory (ROM), random access memory (RAM), a magnetic disk, or an optical disk.
[0139] In summary, this application addresses several issues in large language models during reasoning, including a lack of specific knowledge, the generation of illusionary and harmful text, high knowledge update costs, and over-reliance on knowledge graph quality for reasoning results. By introducing external knowledge, this application provides ample knowledge support for large language models, enabling them to reason more comprehensively and accurately in specific knowledge-based situations. Furthermore, by combining knowledge graphs with large language models for reasoning, the transparency and interpretability of reasoning are improved, the accuracy of reasoning is enhanced, and the cost of knowledge updates is reduced. This application provides strong support for the reasoning capabilities of large language models, promoting the development and application of artificial intelligence technology.
[0140] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
[0141] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0142] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
Claims
1. A knowledge-driven large language model reasoning method, characterized in that, Includes the following steps: Reasoning subgraph generation: Extract the main entities of the text through a large language model, match related information in an external database, construct and optimize the knowledge structure, and generate a queryable subgraph; Subgraph search reasoning: Construct a large language model capable of converting natural language questions into Cypher queries, and perform subgraph retrieval in the external database; Joint graph reasoning: If the subgraph search reasoning does not retrieve an answer, the knowledge of the previous hop of the question is used as input to obtain the most relevant knowledge from the external database. The large language model then performs joint reasoning based on the most relevant knowledge and the question to generate the final answer.
2. The knowledge-driven large language model reasoning method according to claim 1, characterized in that, The inference subgraph generation step specifically includes the following steps: Main entity extraction: Identify and analyze keywords or phrases for a given question using a large language model, perform semantic understanding on the keywords or phrases, and determine the entity most relevant to the question; Entity relationship matching: Interact with the external database using a predefined query language to obtain a set of knowledge triples related to the problem; Reasoning subgraph generation: The large language model generates a subgraph structure description based on the knowledge triple set, and converts the subgraph structure description into a graph query language expression; at the same time, the knowledge triple set is imported into the graph database to construct the corresponding nodes and relations, and a reasoning subgraph is generated.
3. The knowledge-driven large language model reasoning method according to claim 2, characterized in that, The entity relationship matching step specifically includes the following steps: The main entity is used as the subject and object respectively to perform relation queries, and the corresponding relations are obtained and a relation set is formed. Perform a tail entity query to obtain the tail entity element; The knowledge triple set is constructed based on the main entity, the relation set, and the tail entity elements.
4. The knowledge-driven large language model reasoning method according to claim 1, characterized in that, The subgraph search reasoning steps specifically include the following steps: Seed dataset generation: Extract and filter domain-related questions from the original data source to generate a seed dataset; Coarse dataset generation: The large language model is used to generalize the problems in the seed dataset to generate Cypher data and a coarse dataset; wherein, based on the generated generalized problems, a corresponding domain data structure is constructed to generate the seed dataset; Selected dataset generation: Cypher validation is performed on the problems in the coarse dataset, the validated data is manually judged, and a selected dataset is generated by combining it with other types of Cypher data; The pedestal model is fine-tuned using supervised learning with an instruction dataset to obtain a Cypher LLM, and the Cypher LLM is optimized with human feedback; wherein, the instruction dataset includes the selected dataset; Based on the Cypher LLM, the problem is transformed into a query statement that the graph database can understand, and the query is performed in the subgraph of the graph database.
5. The knowledge-driven large language model reasoning method according to claim 1, characterized in that, The joint graph reasoning steps specifically include the following steps: If the subgraph search reasoning fails to retrieve an answer, a Cypher query statement for the previous hop knowledge of the question is generated, and the most relevant knowledge is obtained from the graph database; combined with the knowledge of the large language model itself, joint reasoning is performed to generate the final answer.
6. A knowledge-driven large language model reasoning device, characterized in that, The reasoning subgraph generation module is used to extract the main entities of the text through a large language model, match related information in an external database, build and optimize the knowledge structure, and generate a queryable subgraph. The subgraph search reasoning module is used to construct a large language model capable of converting natural language questions into Cypher queries and to perform subgraph retrieval in the external database. The joint graph reasoning module is used to obtain the most relevant knowledge from the external database by taking the previous hop knowledge of the question as input when the subgraph search reasoning fails to retrieve the answer. The module then performs joint reasoning based on the most relevant knowledge and the question through the large language model to generate the final answer.
7. The knowledge-driven large language model reasoning device according to claim 6, characterized in that, The reasoning subgraph generation module includes: The main entity extraction module is used to identify and analyze keywords or phrases for a given question using a large language model, perform semantic understanding on the keywords or phrases, and determine the entity most relevant to the question. The entity relationship matching module is used to interact with the external database using a predefined query language to obtain a set of knowledge triples related to the problem; The reasoning subgraph generation module is used to generate a subgraph structure description based on the knowledge triple set using the large language model, and convert the subgraph structure description into a graph query language expression; at the same time, the knowledge triple set is imported into the graph database to construct the corresponding nodes and relations, and generate the reasoning subgraph.
8. The knowledge-driven large language model reasoning device according to claim 6, characterized in that, The subgraph search and reasoning module includes: The seed dataset generation module is used to extract and filter domain-related questions from the original data source to generate a seed dataset. The coarse dataset generation module is used to generalize the problems in the seed dataset using the large language model to generate Cypher data and a coarse dataset; wherein, based on the generated generalized problems, a corresponding domain data structure is constructed to generate the seed dataset; The selected dataset generation module is used to perform Cypher validation on the problems in the coarse dataset, manually judge the validated data, and combine it with other types of Cypher data to generate a selected dataset. The fine-tuning module is used to perform supervised learning fine-tuning of the base model using the instruction dataset to obtain the Cypher LLM, and to optimize the Cypher LLM through human feedback; wherein the instruction dataset includes the selected dataset; The retrieval module is used to transform the problem into a query statement that the graph database can understand based on the Cypher LLM, and to perform retrieval in the subgraphs of the graph database.
9. An electronic device, characterized in that, The electronic device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the knowledge-driven large language model reasoning method as described in any one of claims 1 to 4.
10. A readable storage medium, characterized in that, The readable storage medium stores a program or instructions that, when executed by a processor, implement the steps of the knowledge-driven large language model reasoning method as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Multi-hop knowledge base question and answer IR-MT model based on intermediate reasoning attention
CN116166779A
Large model reasoning analysis method, system and product based on external knowledge enhancement
CN117575026A