A knowledge graph question and answer retrieval method based on a large language model and an MCTS algorithm
By constructing a knowledge tree and introducing the Monte Carlo tree search algorithm, the knowledge graph question answering system of the large language model is optimized, which solves the problem of insufficient multi-hop path error correction capability and improves the hit rate and accuracy of the answers.
Patent Information
- Application Number
- CN202410204422.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-23
- Publication Date
- 2026-02-17
- Estimated Expiration
- 2044-02-23
AI Technical Summary
Large language models have insufficient error correction capabilities when determining multi-hop relationship paths in knowledge graph question answering. Greedy search or beam search algorithms cannot effectively correct erroneous paths, leading to a decrease in answer accuracy.
We employ a large language model and Monte Carlo search strategy. By constructing a knowledge tree and performing pre-pruning, combined with the Monte Carlo tree search algorithm, we balance the selection probability of multi-hop paths and use the upper confidence interval formula to optimize path selection and improve error correction capabilities.
It improves the answer hit rate of knowledge graph question answering systems in multi-hop paths, reduces the possibility of erroneous paths being permanently excluded, enhances the error correction capability of large language models, and outputs answers that are more in line with human language understanding.
Smart Images

Figure CN118296114B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of knowledge base question answering, and particularly relates to a knowledge graph question answering retrieval method based on a large language model (LLM) and a Monte Carlo search (MCTS) strategy. BACKGROUND
[0002] Knowledge graphs include a lot of factual knowledge, so data can be retrieved from the knowledge graph to obtain answers to factual questions of users. A knowledge graph question answering (KGQA) system is a system in which users can express their information needs in the form of natural language questions (NLQ) instead of expressing precise queries in a specific formal query language, so as to obtain answers to user questions from a knowledge graph (KG).
[0003] The first step of a knowledge graph question answering system is usually entity connection, that is, identifying a topic in a question Q and mapping it to a topic entity e in a knowledge graph G q . The next step is to predict an answer A q . Traditional methods of predicting answers mainly fall into two categories. A method based on semantic parsing will parse Q and generate an intermediate parsing expression L q , and execute the parsing expression to obtain the answer to the question. A method based on information retrieval will extract a subgraph G q from the entire knowledge graph, and then perform reasoning on the subgraph to select an entity with a high ranking in the subgraph as the answer. The predicted answer will be returned to the user as the output of the system. With the continuous improvement of the size of large language models, the semantic understanding and judgment ability of large language models have shown an "emergence" type of improvement. Since large language models learn a large amount of knowledge during training, there are many knowledge question answering systems that use large language models.
[0004] KGQA mainly uses entities, attributes and other single specific objects, but in actual application scenarios, users no longer satisfy single-hop knowledge question answering, such as the consulting question "How tall is Yao Ming's daughter?" in the entertainment field. Knowledge graph multi-hop question answering is a task of performing multi-step reasoning on a knowledge graph to infer an answer to a question containing multi-hop relationships.
[0005] However, most methods of KGQA based on information retrieval on the basis of semantic understanding of large language models use greedy search or beam search algorithms to determine multi-hop relationship paths. In the case of using large language models, there is an inevitable illusion phenomenon. Once a correct multi-hop relationship path is determined by a large language model as an incorrect path, the large language model cannot determine the correctness again, and the error correction ability is insufficient. SUMMARY
[0006] The purpose of the present application is to overcome the shortcomings of the prior art and provide a knowledge graph question and answer retrieval method based on a large language model (LLM) and a Monte Carlo search strategy (MCTS). To optimize the computational complexity, the knowledge graph is converted into a knowledge tree when searching for knowledge. The node attributes of the knowledge tree include entity name, entity relationship, evaluation score, access frequency, related entity transformed child nodes, and other information. To build an effective knowledge tree, a large language model is introduced to perform the pre-pruning task of the knowledge tree. By eliminating irrelevant entity relationships that do not affect the answer to the question, the computational complexity of the subsequent steps is reduced. The nodes selected by the large language model to be added to the knowledge tree can also be given an initial score based on the judgment of the large language model. In addition, the large language model can also judge the possibility of answering the existing reasoning chain and score the possibility of solving the problem, so as to output the answer when the correct entity is found. The introduction of the Monte Carlo tree search algorithm can balance the selection probability of the multi-hop path that is more likely to solve the problem and the multi-hop path with low exploration degree under the judgment of the upper confidence interval formula, thereby improving the error correction capability of the tree search algorithm. Specifically, the present application obtains the topic entity in the original question as the starting node of the knowledge subgraph based on the semantic entity recognition model, obtains information from the knowledge graph to construct a knowledge tree containing knowledge subgraph information, and enhances the required capabilities of the large language model in a prompt learning manner, thereby accelerating the speed of the Monte Carlo tree search algorithm through pre-pruning of the knowledge tree with the help of the enhanced large language model. The Monte Carlo tree search algorithm for the pre-pruned knowledge tree can balance the selection weight between high access nodes and low access nodes, and avoid the situation where the correct path is permanently excluded from the candidate queue under the selection strategy of greedy algorithm and other selection strategies once it is determined to be a low probability multi-hop path.
[0007] The technical solution adopted by the present application to solve its technical problems comprises the following steps:
[0008] Step one, semantic analysis of the original question, for the input question Q, use the mature model Efficient one-pass end-to-end entity linking for questions (ELQ) model as the semantic analysis module to extract the entity E in the question.
[0009] Further, the specific steps of step 1 include:
[0010] Step 1.1, use the public dataset of the knowledge question and answer task to divide the original question and the answer.
[0011] Step 1.2, use the ELQ model to perform semantic analysis on the original question and obtain the entity E in the original question Q as the initial node to build a knowledge tree.
[0012] Step two, knowledge tree construction, for the acquired entity E, if the knowledge tree is not created, the entity E is constructed as a root node, if the knowledge tree is created, the entity E is constructed as a child node.
[0013] Further, the specific steps of step 2 include:
[0014] Step 2.1, knowledge graph connection. Search for entity E from the public knowledge graph to obtain the associated entity set L of entity E. The associated entity set L is composed of triples (E, r, E'), E' is the associated entity, and r is the relationship between E and E'. In the case of successful search of entity E on the knowledge graph, if the knowledge tree is not created, the entity E is constructed as a root node root; if the knowledge tree is created, the node corresponding to the entity E is taken as the parent node so as to construct the child node according to the associated entity set in the future, and the node of the entity E is recorded as node.
[0015] Step 2.2, large language model pre-pruning. For the associated entity set L of node, in order to accelerate the Monte Carlo tree search algorithm, it is necessary to pre-prune to reduce the algorithm size. The prompt P used for pruning cut ={p cut1 ,p cut2 ,p cut3}, the associated entity set L, and the original question Q are combined into a text S cut ={p cut1 ,L,p cut2 ,Q,p cut3} as input, and the large language model LLM selects k most relevant triples set lk as child node options. The process can be represented as follows:
[0016] l k =LLM(S cut )=LLM({p cut1 ,L,p cut2 ,Q,p cut3})
[0017] Through multiple independent pruning judgments, the initial score of the corresponding triple can be assigned according to the number of times the triple appears in the pre-pruning result.
[0018] Step 2.3, child node expansion. According to the triple set l k k parent nodes are constructed as child nodes of node, added to the knowledge tree, and the access frequency and score value and other attributes of the child node are initialized.
[0019] Step three, Monte Carlo tree search algorithm on the knowledge tree. Continuously and orderly select, expand and evaluate, and backtrack under the given total access times and knowledge tree access depth limit. This three steps will be executed multiple times until the decision condition is met.
[0020] Further, the specific steps of step 3 include:
[0021] Step 3.1, selection. The goal of this step is to find a leaf node that has not been searched. The specific selection rule is determined by the upper confidence interval (UCB) formula, which can be expressed as follows:
[0022]
[0023] Where score node is the score of node node, c is a self-determined coefficient, N is the total access times, n node is the access times of node node.
[0024] This algorithm will calculate a score for each child node according to the upper confidence interval formula. When selecting a child node, the node with the highest UCB is selected continuously until a leaf node is reached.
[0025] Step 3.2, expansion and evaluation. After continuously iterating to select a leaf node, the problem to be considered is whether the leaf node can be expanded and add child nodes. Because the leaf node represents a choice of multi-hop path, all feasible steps in this state are determined by the knowledge tree. The multi-hop path r can be expressed as follows:
[0026] r=(e root ,a1,e1,a2,e2)
[0027] Where e root represents the entity corresponding to the root node, e1 and e2 also represent an entity respectively, and e root has a relationship a1 with e1, e1 has a relationship a2 with e2. Other multi-hop paths can be similarly extended.
[0028] That is, if the current multi-hop path from e root to e n is r=(e root ,a1,e1,…,a n ,e n) is not sufficient for the large language model to give an answer to the original question, and the end node of the path is determined as a non-final node if the search tree depth limit or the total search number limit is exceeded when the sub-nodes are searched and expanded according to the multi-hop path, the sub-nodes can be selected and established according to step 2 with the end node as the parent node. If the search tree depth limit or the total search number limit is exceeded when the sub-nodes are searched and expanded according to the multi-hop path r = (e root ,a1,e1,…,a n ,e n ) is sufficient for the large language model to give an answer to the original question, the node is determined as a final node if any one of the above three conditions is met, and step 3.4 is jumped to for decision making.
[0029] Step 3.3, backtracking. After the leaf node is expanded, one step that needs to be considered is backtracking. Because a multi-hop path r = (e root ,a1,e1,…,a n ,e n ) is obtained from the root node in the path just now, after the leaf node is updated, the influence of the expansion of the leaf node on the parent node needs to be considered. The score of the leaf node score = LLM(Q, r) is given by the large language model LLM according to the original question Q and the multi-hop path r corresponding to the leaf node. Here, the corresponding multi-hop path needs to be backtracked from the leaf node, the scores of the corresponding nodes are updated, and then the search is restarted from the root node. The score function used here is the maximum value of the scores of all the leaf nodes reached. The formula can be expressed as follows:
[0030] score parent =max({score1,…..,score k})
[0031] Where score i represents the score of the i-th child node of the parent node parent.
[0032] Step 3.4, decision making. In the Monte Carlo tree search algorithm, the three steps of selection, expansion and evaluation, and backtracking are performed in order, and this process is repeated multiple times until the decision making condition is met.
[0033] The decision making condition includes the following: 1. The large language model determines that the multi-hop path r = (e root ,a1,e1,…,a n ,e n ) of the node has provided sufficient information to answer the original question, and step 4 is jumped to for result output.
[0034] 2. The total number of accesses has reached the limit, that is, the three steps of selection, expansion and evaluation, backtracking are repeated to reach the specified number of times. In this case, the knowledge tree accumulates a lot of game data, and at the same time updates the scores of as many possible child nodes under the root node as possible, which represent the importance of different nodes. Generally speaking, the higher the score, the more facts contained in the multi-hop path represented by the current node can help answer the original question, and the higher the score, the more it should be selected. Therefore, the node with the highest score under the root node and the highest score of the child node of the high-score node, the highest score of the child node of the child node, until the child node as a leaf node is selected, the corresponding final multi-hop path r=(e root ,a1,e1,…,a n ,e n ) can be obtained. If the lowest score of the path node is higher than the set threshold, jump to step 4 for result output, otherwise output no result.
[0035] 3. The access depth of the knowledge tree has reached the limit, then return to the root node and continue the operation of step 3.
[0036] Step four, according to the Monte Carlo tree search, the result output of the question and answer retrieval is carried out.
[0037] The prompt P out ={p out1 ,p out2 ,p out3} for result output, multi-hop path r=(e root ,a1,e1,…,a n ,e n ), and the original question Q are combined into a text S out ={p out1 ,r,p out2 ,Q,p out3} as input, and the natural language form of the answer text Answer is output by the large language model LLM. The process can be represented as follows:
[0038] Answer=LLM(S out )=LLM({p out1 ,r,p out2 ,Q,p out3})
[0039] The beneficial effects of the present application are as follows:
[0040] The application provides a knowledge graph question and answer retrieval method based on a large language model and a Monte Carlo search strategy. The large language model and the Monte Carlo tree search algorithm are introduced for knowledge tree search, thereby improving the search capability in the knowledge graph for knowledge question and answer problems. First, a mature entity recognition model ELQ is used to improve the semantic understanding accuracy of the problem, thereby correctly performing entity recognition. Second, the large language model performs pre-pruning based on semantic understanding, thereby providing fast data purification processing for converting a knowledge graph subgraph into a knowledge tree. After the knowledge graph subgraph is converted into the knowledge tree, the Monte Carlo tree search algorithm is introduced on the knowledge tree, thereby balancing the selection probability of a multi-hop path that is more likely to solve the problem and a multi-hop path with low exploration degree under the judgment of the upper confidence interval formula, and improving the error correction capability of the tree search algorithm. Compared with the greedy algorithm and the beam search algorithm, the candidate sequence contains only one option or a custom number n of options regardless of the access depth, and the number of candidate options is still dominant even if each node has at most k child nodes after pruning. The correct node is permanently excluded from the candidate queue after being determined as a low-probability multi-hop path, thereby improving the hit rate of the answer. Finally, the natural language generation capability of the large language model is used to obtain an answer that is more consistent with the human language understanding capability. BRIEF DESCRIPTION OF DRAWINGS
[0041] Figure 1 A model overall architecture of the application;
[0042] Figure 2 A Monte Carlo tree search flowchart of the application. DETAILED DESCRIPTION
[0043] A knowledge graph question and answer retrieval method based on a large language model and an MCTS algorithm, the architecture is as shown in Figure 1 The specific process is as follows:
[0044] Step one, original problem semantic analysis, for the input question Q, a mature model ELQ model is used as a semantic analysis module to extract the entity E in the question.
[0045] Further, the specific steps of step 1 include:
[0046] Step 1.1, using the public dataset webQSP of the knowledge question and answer task to divide the original question and the answer into data to provide basic data support for subsequent experiments.
[0047] Step 1.2, using the ELQ model to perform semantic understanding on the original question, and obtaining the entity E in the original question text Q as an initial node to construct a knowledge tree.
[0048] The process can be represented as follows:
[0049] E=ELQ(Q)
[0050] wherein E is the result of entity recognition of the large language model.
[0051] Step two, knowledge tree construction, using the treelib library of Python3 as the basis of tree construction, searching for entity E from the public knowledge graph DBpedia to obtain the associated entity set L of entity E. If the knowledge tree is not created, entity E is used as the root node root to construct under the condition that entity E is successfully searched on the knowledge graph; if the knowledge tree has been created, the node corresponding to entity E is used as the parent node of the subsequent child nodes constructed according to the associated entity set, and the node of entity E is recorded as node. The initial value of the access times is 0, and the initial score is the number of occurrences of the triple in the pre-pruning result.
[0052] Further, the specific steps of step 2 include:
[0053] Step 2.1, knowledge graph connection. In order to obtain the flexibility of knowledge, the application uses the api interface of the public knowledge graph dbpedia as the knowledge graph source, which can be used at any time. DBpedia is a structured data extracted from the entries of Wikipedia, which enhances the search function of Wikipedia and connects other data sets to Wikipedia. Uniform Resource Locator (URL) is a concise representation of the location and access method of resources available on the Internet, and is the address of standard resources on the Internet. Search for entity E from the api interface of dbpedia, get the csv file of the associated entity set L of entity E, and the data in the file is saved in the form of triples (Object, Predicate, Subject) according to the RDF (Resource Description Framework) rule. Object is the url in dbpedia, which points to the storage address of an entity in dbpedia. If Subject is a url, it also represents an entity, and if it is not a url, it represents a certain attribute of the entity corresponding to Object. Predicate is the url corresponding to the relationship between the entity corresponding to Object and the entity or attribute corresponding to Subject. The csv file is cleaned up, and the triples with Predicate items such as wikiPageUsesTemplate, type, sameAs, depiction, wikiPageRedirects, wikiPageExternalLink, wikiPageLength, wikiPageID and other irrelevant attributes are removed. In addition, if the Object corresponding to an entity in the csv is entity E and the Subject corresponds to an attribute, the corresponding Subject needs to be marked, so that the node corresponding to the triple can be marked as not expandable when expanding the subsequent child nodes. In addition, if the Object corresponding to an entity in the csv is entity E and the subject corresponding entity is the associated node of entity E, the Predicate needs to be adjusted to passive voice, so that the large language model can correctly understand the active and passive relationship between entities when inputting gpt-3.5-turbo in the subsequent. Finally, the url in the triple is converted into text and the associated entity set L is constructed. The associated entity set L is composed of triples and the triple structure is (Subject, Predicate, Object).If the entity E succeeds in searching on the knowledge graph, if the knowledge tree is not created, the entity E is constructed as the root node root, and the initial value of the access times is 0 and the initial score is 5 when constructing; if the knowledge tree has been created, the node corresponding to the entity E is taken as the parent node of the subsequent child nodes constructed according to the associated entity set, and the node of the entity E is recorded as node. If the entity E fails in searching on the knowledge graph, steps 1.3 to 1.5 are repeated until the search succeeds or the number of failures reaches the specified number of times, which is generally set to 3 times.
[0054] Step 2.2, pre-pruning of the large language model. For the associated entity set L of node, in order to accelerate the Monte Carlo tree search algorithm, it is necessary to pre-prune to reduce the algorithm size. The prompt P cut cut1 cut2 cut3 for pruning, the associated entity set L, and the original problem Q are combined into a text S cut cut1 cut2 cut3 , and the large language model gpt-3.5-turbo selects a list l k of k most relevant triple sets as child node options, generally set to 5 child nodes. After learning from the prompt, gpt-3.5-turbo can output structured text similar to the example in the prompt, so it is still necessary to decode the text to convert it into the required data structure. A pruning judgment process can be represented as follows:
[0055] l k = func cutdecode (GPT(S cut )) = func cutdecode (GPT({p cut1 , L, p cut2 , Q, p cut3}))
[0056] Where GPT() refers to the gpt-3.5-turbo model, func cutdecode is a program method for decoding structured text, which converts structured text into a list through position, special symbol, etc.
[0057] Through 3 independent pruning judgments, the initial score (from 1 to 3) can be assigned to the corresponding triple according to the total number of triple occurrences. All the triplets that have appeared are sorted in descending order of total number of occurrences, and the top k are taken as the final l k .
[0058] Step 2.3, child node expansion. Add the triple set l k to the knowledge tree as the child node of the k parent nodes node, and initialize the attributes of the child node such as the access frequency and score value. The initial value of the access frequency is 0, and the initial score is the number of times the triple appears in the pre-pruning result. The expandability is set to True by default if there is no special marking in Predicate.
[0059] Step three, as shown in Figure 2 , a Monte Carlo tree search algorithm is performed on the knowledge tree. The number of iterations of the Monte Carlo tree search algorithm is set to limit the total access frequency. Under the given number of iterations and the depth limit of the knowledge tree, the selection, expansion and evaluation, and backtracking processes are continuously performed in order. The three steps are executed multiple times in a loop until the decision condition is met. The maximum number of iterations is set to 1500, and the maximum tree depth is set to 6.
[0060] Further, the specific steps of step 3 include:
[0061] Step 3.1, selection, the goal of this step is to find a leaf node that has not been searched, and the specific selection rule is determined by the Upper Confidence Bound (UCB1) formula, which can be expressed as follows:
[0062]
[0063] where score node represents the score of node node, c represents a self-defined coefficient, generally set to 2, N represents the total access frequency, and n node represents the access frequency of node node.
[0064] This algorithm will calculate a score for each child node of the node according to the Upper Confidence Bound formula when selecting the next path, and will execute the current UCB highest child node search in a loop until a leaf node is reached.
[0065] Step 3.2, expansion and evaluation, after selecting a leaf node in an iterative manner, the problem to be considered is whether the leaf node can be expanded and a child node is added. Because the leaf node represents a choice of a multi-hop path, all feasible steps in this state are determined by the knowledge tree, and whether the multi-hop path contains enough facts to answer the original question is determined by gpt-3.5-turbo. The multi-hop path r can be represented by the following formula:
[0066] r = (e root , a1, e1, a2, e2)
[0067] where e root represents the entity corresponding to the root node, e1 and e2 also represent an entity, and eroot There is a relationship a1 between e1 and e2, and a relationship a2 between e1 and e2. Other multi-hop paths can be similarly extended.
[0068] The following formula is used to determine whether the current multi-hop path provides sufficient facts to answer the original question:
[0069] bool = func booldecode (GPT(p bool ,Q,r)
[0070] where GPT() refers to the gpt-3.5-turbo model, func booldecode is a program method for decoding structured text, which converts structured text into digital 0 and 1 to represent the judgment result of False or True through position, special symbol, etc.
[0071] That is, if gpt-3.5-turbo judges bool as 0, i.e. the current multi-hop path r = (e root ,a1,e1,…,a n ,e root ) from e n to e n does not have enough facts to answer the original question, and according to this multi-hop path to continue to find and expand the child node does not exceed the search tree depth limit node, and the expandable attribute of the node is True, the end node of the path is determined as a non-final node, then the end node can be taken as the parent node to select and establish child nodes according to step 2. After establishing the child nodes, the first child node of the current node is selected to join the current multi-hop path to form a new path r' = (e root ,a1,e1,…,a n+1 ,e root ) from e n+1 to e n+1 . If gpt-3.5-turbo judges bool as 1, i.e. the current multi-hop path r = (e root ,a1,e1,…,a n ,e n ) is sufficient for GPT-3.5 to answer the original question or to continue to find and expand child nodes according to this multi-hop path to exceed the search tree depth limit or the expandable attribute of the node is False, any one of the above three conditions is met, the node is determined as a final node, and step 3.4 is jumped to make a decision.
[0072] Step 3.3, backtracking. After expanding the leaf node, one step that needs to be considered is backtracking. Because in the path just now, a new path from e root to e n+1multi-hop path r′=(e root ,a1,e1,…,a n+1 ,e n+1 After updating the leaf nodes of the path, the impact of leaf node expansion on the parent node needs to be considered. The score of the leaf node is GPT(Q,r′). Based on the original problem Q and the corresponding multi-hop path r′ of the leaf node, three independent gpt-3.5-turbo programs score the probability of solving the original problem with the multi-hop path r′, and the average score is used as the final score. node Store the data in the node. After learning from the prompts, gpt-3.5-turbo can output structured text similar to the example provided. Therefore, the text still needs to be decoded to convert it into the required data structure. The formula is as follows:
[0073]
[0074] GPT m Let p represent the m-th independent gpt-3.5-turbo model. score This represents the prompt text used for scoring. (func) scoredecode It is a programmatic method for targeted decoding of structured text, which converts structured text into integers using information such as position and special symbols.
[0075] Then, starting from the leaf node, the search proceeds backward along the corresponding multi-hop path until the root node is reached. During backtracking, the score of the corresponding node is updated, and then the search returns to the root node to begin again. The score function here uses the maximum score of all child nodes. The formula can be expressed as follows:
[0076] score parent =max({score1,…..,score k})
[0077] Among them, score i This represents the score of the i-th child node of the parent node.
[0078] Step 3.4, Decision Making. In the Monte Carlo Tree Search algorithm, the three steps of selection, expansion and evaluation, and backtracking are repeated multiple times until the decision conditions are met.
[0079] The decision conditions are as follows: 1. gpt-3.5-turbo determines the multi-hop path of this node r = (e root ,a1,e1,…,a n ,e nSufficient information has been provided to answer the original question. To avoid a single path being insufficient to answer multiple-answer questions, it will be combined with e n The nodes share a common Predicate property a n sibling node e′ n Also build from e root Depart for e′ n multi-hop path r′=(e root ,a1,e1,…,a n ,e′ n If the lowest score of a path node is higher than the set threshold, proceed to step 4 to output the result; otherwise, output no result.
[0080] 2. The search algorithm has reached its loop limit, meaning the three steps of selection, expansion and evaluation, and backtracking have been repeated a specified number of times. In this situation, the knowledge tree has accumulated a lot of game-theoretic data and updated the scores of as many possible child nodes as possible under the root node. These scores represent the importance of different nodes. Generally, the higher the score, the more helpful the facts contained in the multi-hop path represented by the current node are in answering the original question, and the more it should be selected. Therefore, the node with the highest score under the root node, its highest-scoring child node, and the highest-scoring child node of that high-scoring node are selected, until a leaf node's child node is selected, yielding the corresponding final multi-hop path r = (e root ,a1,e1,…,a n ,e n ), and will be with e n The nodes share a common Predicate property a n sibling node e′ n Also construct a multi-hop path r′=(e root ,a1,e1,…,a n ,e′ n If the lowest score of a path node is higher than the set threshold, jump to step 4 to output the result; otherwise, output no result.
[0081] 3. If the knowledge tree access depth has reached the limit, return to the root node, increment the loop count by 1, and continue with step 3.
[0082] 4. If the node's expandable property is False, it means that the node has been confirmed to have no related nodes other than its parent node. Return to the root node, increment the loop count by 1, and continue with step 3.
[0083] Step 4: Output the results of the question-and-answer retrieval based on the Monte Carlo tree search.
[0084] The prompt P used for the result output out ={p out1 ,p out2,p out3}、Multi-hop path r=(e root ,a1,e1,…,a n ,e n ), r′=(e root ,a1,e1,…,a n ,e′ n The original question Q is combined into text S. out ={p out1 ,r,..,r′,p out2 ,Q,p out3 The input is the given text, "Answer," which is output by gpt-3.5-turbo. Having learned through prompts, gpt-3.5-turbo can output structured text similar to the examples provided. Therefore, targeted decoding of the text is needed to convert it into the required data structure. This process can be represented as follows:
[0085] Answer = func answerdecode (GPT(S out ))
[0086] =func answerdecode (GPT({p out1 ,r,..,r′,p out2 ,Q,p out3}))
[0087] func answerdecode It is a programmatic method for targeted decoding of structured text, which converts structured text into a list of strings by using information such as position and special symbols.
[0088] To illustrate the effect of the present application, the present application is compared with existing models and tested on the public dataset WebQSP of the multi-hop knowledge graph question answering task, which can be used in the Question Answering, Semantic Parsing and Entity Linking tasks. Each example has multiple fields: for example, utterance: natural language question, targetValue: answer. The data of DBpedia is derived from the information box and article of Wikipedia, while the data of Wikidata is based on DBpedia, further providing information support for Wikipedia, which can be considered that the two knowledge graph data acquisition methods are different but the contents are the same. In addition, the present application uses the probability of the first result hitting the correct answer (hit@1) as the experimental evaluation index. The comparative experimental results of four existing methods, namely gpt-3.5-turbo itself, gpt-3.5-turbo using the chain-of-thought technology (COT), TOG (THINK-ON-GRAPH: deep and responsible reasoning of large language model on knowledge graph) using the beam search algorithm, and KD-COT (Knowledge-Driven CoT: Exploring Faithful Reasoning in LLMs for Knowledge-intensive Question Answering) using the knowledge retrieval chain-of-thought algorithm, in the case of using gpt-3.5-turbo in the large language model on the WebQSP dataset are shown in Table 1.
[0089] Table 1 Comparative experimental results
[0090] Cited knowledge graph hit@1 Chatgpt3.5 No 61.0 CoT No 62.2 TOG Wikidata 68.6 KD-COT Freebase+wikidata 68.6 The invention Dbpedia(wikidata) 70.3
[0091] As can be seen from Table 1, compared with other methods based on large language models, the hit@1 of the method proposed in the present application is improved, which indicates that with the help of the Monte Carlo algorithm, enough factual information can be obtained to make correct judgments for the multi-hop knowledge graph question answering task.
Claims
1. A knowledge graph question and answer retrieval method based on a large language model and an MCTS algorithm, characterized in that, Comprising the following steps: Step 1, original question semantic analysis, for the input question Q, using ELQ model as the semantic analysis module, extracting the entity E in the question; Step 2, knowledge tree construction, for the obtained entity E, if the knowledge tree has not been created, the entity E is constructed as the root node, and if the knowledge tree has been created, the entity E is constructed as the child node; Step 3, Monte Carlo tree search algorithm on the knowledge tree, constantly and orderly selecting, expanding and evaluating, and backtracking under the given total access times and knowledge tree access depth limit until the decision condition is met, the specific process is as follows: Step 3.1, selection, find the leaf node that has not been searched, the selection rule is determined by the upper confidence interval UCB formula, which is expressed as: where score node represents the score of node node, c represents a self-determined coefficient, N represents the total number of visits, n node represents the number of visits of node node; a score is calculated for each sub-node according to the upper confidence interval formula, and the node with the highest current UCB is continuously selected when selecting a sub-node until a leaf node is reached; Step 3.2, expansion and evaluation, after constantly iterating to select a leaf node, check whether the leaf node is expanded and a child node is added, the leaf node represents a selection of a multi-hop path, and all steps in this state are determined by the knowledge tree, and the multi-hop path r is expressed by the following formula: r = (e root , a1, e1, a2, e2) where e root represents the entity corresponding to the root node, e1 and e2 also respectively refer to an entity, and e root has a relationship a1 with e1, e1 has a relationship a2 with e2; other multi-hop paths are similar. If the current source is e root Departure to e n multi-hop path r = (e root ,a1,e1,…,a n ,e n If the current multi-hop path is insufficient for the large language model to provide an answer to the original question, and further searching and expanding child nodes based on this multi-hop path does not exceed the search tree depth limit or the total search count limit, the terminal node of this path is determined to be a non-final node. Then, using the terminal node as the parent node, child nodes are selected and established following step 2. If further searching and expanding child nodes based on this multi-hop path exceeds the search tree depth limit or the total search count limit, or if the current multi-hop path r = (e root ,a1,e1,…,a n ,e n If a node is deemed a final node and the large language model provides an answer to the original question that satisfies any of the above conditions, then the process proceeds to step 3.4 for decision-making. Step 3.3, backtracking, after expanding the leaf node, a multi-hop path r = (e root , a1, e1, …, a n , e n ) is obtained from the root node, after updating the leaf node of the path, the score of the leaf node score = LLM(Q, r) is given by the large language model LLM according to the original problem Q and the multi-hop path r corresponding to the leaf node; from the leaf node, the corresponding multi-hop path is updated by backtracking in reverse, the score of the corresponding node is updated, and then the search starts from the root node again; the score function uses the maximum value of the scores of all the leaf nodes reached, and the formula is as follows: score parent = max({score1, …, score k}) where score i represents the score of the i-th child of the parent node parent; Step 3.4, decision making, in the Monte Carlo tree search algorithm, the three processes of selection, expansion and evaluation, and backtracking are constantly and orderly performed, and this process is repeatedly executed for multiple times until the decision condition is met; Step 4, according to the Monte Carlo tree search, the result output of the question and answer retrieval is performed.
2. The knowledge graph question and answer retrieval method based on a large language model and an MCTS algorithm according to claim 1, characterized in that, The specific process of step 1 is as follows: Step 1.1, using the public data set of knowledge question and answer task to divide the original question and answer data; Step 1.2, using the ELQ model to perform semantic analysis on the original question, and obtaining the entity E in the original question Q as an initial node to construct a knowledge tree.
3. The knowledge graph question and answer retrieval method based on a large language model and an MCTS algorithm according to claim 2, characterized in that, The specific process of step 2 is as follows: Step 2.1, searching for the entity E from the public knowledge graph to obtain the associated entity set L of the entity E; the associated entity set L is composed of triples (E, r, E'), E' is an associated entity, and r is the relationship between E and E'; in the case that the entity E is successfully searched on the knowledge graph, if the knowledge tree has not been created, the entity E is constructed as the root node root; If the knowledge tree has been created, the node corresponding to the entity E is taken as the parent node, and the node of the entity E is denoted as node; Step 2.2: For the set of associated entities L of a node, perform pre-pruning, and use the pruning hints P... cut ={p cut1 ,p cut2 ,p cut3 The associated entity set L and the original question Q are combined into text S. cut ={P cut1 ,L,P cut2 Q,P cut3 As input, the Large Language Model (LLM) selects a custom set of k most relevant triples. k As a child node option; Through multiple independent pruning judgments, the initial score is assigned to the corresponding triple according to the number of times of appearance of the triple in the pre-pruning result; Step 2.3, add the child node of k parent nodes as node into the knowledge tree, and initialize the access times and score value of the child node. k Step 2.3, add the child node of k parent nodes as node into the knowledge tree, and initialize the access times and score value of the child node.
4. The knowledge graph question and answer retrieval method based on a large language model and an MCTS algorithm according to claim 3, characterized in that, The decision condition is specifically: If the large language model determines that the multi-hop path r = (e root ,a1,e1,…,a n ,e n ) of the node has provided sufficient information to answer the original question, jump to step 4 to output the result; If the large language model determines that the multi-hop path r = (e root ,a1,e1,…,a n ,e n ) of the node has provided sufficient information to answer the original question, jump to step 4 to output the If the total number of visits has reached the limit, the three steps of selection, expansion and evaluation, backtracking are repeated to reach the specified number of times; at this time, the knowledge tree accumulates the data of the game, and the scores of the child nodes under the root node are updated, the node with the highest score under the root node is selected, and the child node with the highest score of the high-score node, the child node with the highest score of the child node, until the child node as the leaf node is selected into, get the corresponding final multi-hop path r=(e root ,a1,e1,…,a n ,e n ); if the lowest score of the path node is higher than the set threshold, jump to step 4 to output the result, otherwise output no result; If the knowledge tree access depth has reached the limit, return to the root node and continue the operation of step 3.
5. The knowledge graph question and answer retrieval method based on a large language model and an MCTS algorithm according to claim 4, characterized in that, The specific process of step 4 is as follows: The prompt P used for result output... out ={p out1 ,p out2 ,p out3 }、Multi-hop path r=(e root ,a1,e1,…,a n ,e n The original question Q is combined into text S. out ={p out1 ,r,p out2 ,Q,p out3 As input, the Large Language Model (LLM) outputs the response text in natural language form as output.
Citation Information
Patent Citations
Method for identifying a named entity based on policy value network and tree search
CN110209770A
Knowledge graph question and answer method and system based on machine reading understanding
CN115878814A