Question answering method, device, equipment and storage medium based on knowledge graph
By generating a multi-hop and constrained path set in the knowledge graph, combined with similarity calculation, the existing technology is difficult to analyze the answers to complex problems, and efficient and accurate answers to complex problems are achieved.
Patent Information
- Application Number
- CN202310081010.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-16
- Publication Date
- 2025-08-08
- Estimated Expiration
- 2043-01-16
AI Technical Summary
The existing knowledge graph question-and-answer methods are difficult to effectively deal with complex problems, especially multi-hop questions and constraints, and cannot accurately analyze the answers to complex problems.
By searching through hop-by-hop paths in the knowledge graph, a multi-hop path set and a constraint path set are generated, and combined with similarity calculations, the answer entity with the highest similarity to the question sentence is selected.
Effectively eliminate paths that are not related to question sentences, avoid the explosion of the number of paths, and improve the feasibility of complex questions and the comprehensiveness and accuracy of answer entity retrieval.
Smart Images

Figure CN116069876B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of natural language processing. More specifically, it relates to a question-answering method, device, equipment, and storage medium based on a knowledge graph. Background Art
[0002] With the wide application of computers and the Internet, the amount of data generated and created by humans has increased explosively, and the cost required to understand and apply this data has also increased accordingly. Therefore, how to efficiently and accurately process massive heterogeneous data has become an urgent problem to be solved. The knowledge graph stores and represents massive data in the form of structured "knowledge". As an important carrier for carrying underlying massive knowledge and supporting upper-layer intelligent applications, it plays an extremely important role in the intelligent era. However, due to the highly structured characteristics of the knowledge graph, we often need to construct structured query statements (such as SPARQL, etc.) to find relevant knowledge, which causes inconvenience for ordinary users to use the knowledge graph. Therefore, natural language question answering (KBQA) on the knowledge graph has become one of the popular applications of the former in recent years.
[0003] Existing knowledge graph question-answering methods mainly focus on solving simple questions. A simple question refers to a question that can infer the answer using a single triple. For example, for the question "What is the capital city of Zhejiang?", we can obtain the answer as the entity <Hangzhou> through the single triple <Zhejiang, capital, Hangzhou> in the knowledge graph. However, complex questions are more in line with complex scenarios in reality. Complex questions mainly have two types. One is the question with constraints: for example, "Who is the men's singles champion of the first Wimbledon?" The "first" in this question represents a constraint on the answer entity. The other is the multi-hop question: for example, "Who are the directors of the movies starring Zhang San?" This question requires using a multi-hop reasoning path formed by multiple triples to answer. For example, through these triples <Zhang San, starred in, xx story>, <xx story, directed by, Li Si>, we infer that is a correct answer.
[0004] Existing knowledge graph question answering mainly adopts semantic parsing (Semantic Parsing) methods, aiming to parse the question into an executable graph database query statement (such as SPARQL), and then find the answer by executing this statement. For simple questions, semantic parsing methods aim to parse the question into a head entity h and a relationship r, that is, in the form of (h,r,?). For example, for the question "Where is Zhang San's place of birth?", the head entity <Zhang San> and the relationship <place of birth> can be parsed, and the pseudo-query statement <Zhang San, place of birth,?> can be obtained. Subsequently, the answer <Shanghai> is obtained by executing this query statement. However, for complex questions, since they cannot be simply parsed into the form of the above single triple, the existing technology is difficult to handle complex questions. Summary of the Invention
[0005] In view of the above problems, this application is proposed to provide a knowledge graph-based question-answering method, apparatus, device, and storage medium to achieve the purpose of providing answers to given simple or complex questions based on the knowledge graph. The specific solution is as follows:
[0006] First, a question-answering method based on a knowledge graph is provided, including:
[0007] Determine the candidate entities in the knowledge graph pointed to by the question sentence;
[0008] Filtering the target entity linked to the question sentence from the candidate entities;
[0009] In the knowledge graph, a multi-hop path set is searched in a hop-by-hop path search manner with the target entity as the starting point, wherein, in each hop path search process, a current multi-hop path is combined with each one-hop path of the answer entity of the current multi-hop path to obtain a plurality of combined paths, and a combined path whose similarity to the question sentence meets a set condition is selected as the multi-hop path for the next moment;
[0010] Obtaining a constrained path set based on combinations of any two multi-hop paths in the multi-hop path set;
[0011] The similarity between each path in the multi-hop path set and the constraint path set and the question sentence is calculated, and the answer entity of the path with the highest similarity is selected as the final answer.
[0012] In a second aspect, a question-answering device based on a knowledge graph is provided, comprising:
[0013] The candidate entity determination unit is used to determine the candidate entity in the knowledge graph pointed to by the question sentence;
[0014] An entity linking unit, configured to select a target entity linked to the question sentence from among the candidate entities;
[0015] a multi-hop path search unit, configured to search for a set of multi-hop paths in the knowledge graph using the target entity as a starting point and in a hop-by-hop path search manner, wherein, in each hop path search process, the current multi-hop path is combined with each one-hop path of the answer entity of the current multi-hop path to obtain a plurality of combined paths, and the combined path whose similarity to the question sentence satisfies a set condition is selected as the multi-hop path for the next moment;
[0016] a constrained path acquisition unit, configured to obtain a constrained path set based on a combination of any two multi-hop paths in the multi-hop path set;
[0017] The answer entity selection unit is used to calculate the similarity between each path in the multi-hop path set and the constraint path set and the question sentence, and select the answer entity of the path with the highest similarity as the final answer.
[0018] In a third aspect, a knowledge graph-based question-answering device is provided, comprising: a memory and a processor;
[0019] The memory is used to store programs;
[0020] The processor is used to execute the program to implement the various steps of the knowledge graph-based question-answering method as described above.
[0021] In a fourth aspect, a storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the various steps of the question-answering method based on the knowledge graph as described above are implemented.
[0022] By means of the above technical solution, the present application determines the candidate entity in the knowledge graph to which the question sentence points, and further selects the target entity linked to the question sentence from each candidate entity through entity linking. Considering that some complex problems are multi-hop problems or problems with constraints, for multi-hop problems, their answers correspond to multi-hop paths in the knowledge graph. Therefore, the present application uses the target entity as the starting point in the knowledge graph and adopts a hop-by-hop path search method to search for a multi-hop path set. In each hop path search process, the current multi-hop path is combined with each hop path of the answer entity of the current multi-hop path to obtain several combined paths, and the combined path whose similarity with the question sentence meets the set conditions is selected as the multi-hop path of the next moment. The hop-by-hop path search method can effectively combine the structural information of the knowledge graph itself, and embed the similarity score into the multi-hop path generation process. Each hop only screens the paths whose similarity with the question sentence meets the set conditions, which can effectively eliminate the paths irrelevant to the question sentence and avoid the explosion of the number of paths. For constrained questions, the answers correspond to constraint paths in the knowledge graph, and constraint paths can be converted based on multi-hop paths. Therefore, after obtaining the multi-hop path set, this application obtains the constraint path set based on the combination of two multi-hop paths in the multi-hop path set. Thus, the multi-hop path set and the constraint path set can contain all possible answer paths to the question sentence. Finally, the similarity between each path in the above two sets and the question sentence is calculated, and the answer entity of the path with the highest similarity is selected as the final answer.
[0023] The solution of this application uses a hop-by-hop path search approach when generating a multi-hop path set, eliminating paths irrelevant to the question sentence and preventing an explosion in the number of paths, ensuring the feasibility of the solution in addressing complex problems. Furthermore, by generating a multi-hop path set and a constrained path set, all possible answer paths to the question sentence can be obtained. Ultimately, by calculating the similarity with the question sentence, the answer entity with the path with the highest similarity is selected as the final answer, improving the comprehensiveness and accuracy of answer entity retrieval. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] Various other advantages and benefits will become apparent to those skilled in the art upon reading the detailed description of the preferred embodiment below. The accompanying drawings are for illustration purposes only and are not to be considered as limiting the present application. The same reference symbols are used throughout the drawings to represent the same components. In the drawings:
[0025] Figure 1 A schematic diagram of a process flow of a question-answering method based on a knowledge graph provided in an embodiment of the present application;
[0026] Figure 2 Schematic diagrams of some multi-hop paths and constrained paths are shown;
[0027] Figure 3 A flowchart of a method for searching a multi-hop path set provided in an embodiment of the present application;
[0028] Figure 4 A flowchart of a method for obtaining a constrained path set provided in an embodiment of the present application;
[0029] Figure 5 This example illustrates a process flow diagram for question answering based on knowledge graphs.
[0030] Figure 6 A flowchart of another method for obtaining a constrained path set provided in an embodiment of the present application;
[0031] Figure 7 A schematic diagram illustrating a training sample instance of a sentence similarity calculation model;
[0032] Figure 8 This example illustrates a schematic diagram of an entity keyword recognition model using a sequence tagging structure;
[0033] Figure 9 An example of a seq2seq-based entity generation model diagram;
[0034] Figure 10 An example of an entity linking model diagram is given;
[0035] Figure 11A schematic diagram of the structure of a question-answering device based on a knowledge graph provided in an embodiment of the present application;
[0036] Figure 12 A schematic diagram of the structure of a knowledge graph-based question-answering device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0037] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0038] This application provides a question-answering solution based on a knowledge graph, which can search for answer entities that match the question sentence based on the knowledge graph.
[0039] The present application solution can be implemented based on a terminal with data processing capabilities, which can be a mobile phone, computer, server, cloud, etc.
[0040] Before introducing the solution of this application, let’s first explain the concept of knowledge graph:
[0041] A knowledge graph can be viewed as a collection of triples, where each triple consists of a subject, a predicate, and an object. There are two main types of triples in a knowledge graph: relation triplets and attribute triples. In relation triples, the subject and object are both entities, and the predicate represents the relationship. In attribute triples, the subject is the entity, and the object is the attribute value (i.e., an attribute node), which is usually a number or text, and the predicate represents the attribute. For example, "Zhang San's father is Zhang Er," where "Zhang Er" is an entity. "Zhang San's age is twenty-four," where "twenty-four" is an attribute node.
[0042] In this case, when conducting question-answering based on the knowledge graph, there is no need to distinguish between entity and attribute nodes. Therefore, for the sake of convenience, the subject and object in the two types of triples are collectively referred to as entities.
[0043] Next, combine Figure 1 The knowledge graph-based question-answering method of the present application may include the following steps:
[0044] Step S100: Determine the candidate entity in the knowledge graph pointed to by the question sentence.
[0045] The question sentence is the sentence text corresponding to the question raised. For example, "Which city is the capital of Hangzhou?" is a question sentence.
[0046] The knowledge graph is a pre-built knowledge graph, which can be a domain knowledge graph that matches the current question scenario. The knowledge graph contains a large number of entities. To answer questions based on the knowledge graph, this step first identifies the entities in the knowledge graph that the question sentence refers to as candidate entities. This step can also be understood as the process of recalling candidate entities, that is, recalling entities in the knowledge graph that the question sentence may refer to. This step can be understood as a coarse-grained process of screening candidate entities.
[0047] Step S110: Filter the candidate entities to obtain a target entity linked to the question sentence.
[0048] Specifically, considering that the candidate entities determined in the previous step may contain noise entities, which will interfere with the subsequent process of searching for answer entities, and too many candidate entities will also cause the subsequent calculation to take too long, therefore, in this step, the candidate entities can be sorted and filtered through entity linking to obtain the target entity linked to the question sentence.
[0049] The entity linking process can be understood as the process of linking a "reference" in the question sentence to a correct entity in the knowledge graph. "Reference" refers to a text fragment in the question sentence that may be an entity. Because the knowledge graph contains a large number of entities, the entity linking process requires preliminary screening to obtain candidate entities through step S100 described above before entity linking. The candidate entities are further screened to obtain the target entity linked to the "reference" in the question sentence, referred to as obtaining the target entity linked to the question sentence.
[0050] It should be noted that the number of target entities linked to a "reference" can be one or more. In order to ensure the fault tolerance rate, a "reference" can be linked to multiple target entities with higher probability scores.
[0051] Step S120: Starting from the target entity in the knowledge graph, a multi-hop path set is searched in a hop-by-hop path search manner.
[0052] In each hop path search process, the current multi-hop path is combined with each one-hop path of the answer entity of the current multi-hop path to obtain several combined paths, and the combined path whose similarity with the question sentence meets the set conditions is selected as the multi-hop path for the next moment.
[0053] In this step, the multi-hop paths at each moment may be combined into a multi-hop path set.
[0054] The essence of knowledge graph question answering is to find answer entities around the target entity linked to the question sentence. The relationships and nodes connecting the target and answer entities are called paths. For some complex questions, the paths between the target and answer entities can be categorized into two types: multi-hop paths and constrained paths.
[0055] Among them, a multi-hop path includes a path corresponding to a triplet, and also includes paths corresponding to multiple triples. For example, (Zhejiang, provincial capital,?) is a multi-hop path, and (Anhui, provincial capital, Hefei)-(Hefei, famous attractions,?) is also a multi-hop path. Figure 2 , Figure 2 The left side illustrates a partial multi-hop path, where E represents an entity, P represents a predicate (relationship or attribute), and A represents an answer entity.
[0056] A constraint path is a path that includes common constraints for multiple entities. Figure 2 , Figure 2 The right side shows some examples of constraint paths. The meanings of E, P, and A refer to the above introduction.
[0057] by Figure 2 Taking the first constraint path on the right as an example, the corresponding question sentence can be "Which component of the match head is an accelerant?" or "What is both a component of the match head and an accelerant?", etc.
[0058] For multi-hop paths, if all paths to each node are traversed, the total number of paths will grow exponentially as the number of intermediate nodes increases, which is almost unbearable for the algorithm. Therefore, this step proposes a hop-by-hop path search method to simulate human reasoning strategies and gradually generate multi-hop paths.
[0059] This hop-by-hop path search method can effectively combine the structural information of the knowledge graph itself and embed similarity scoring into the multi-hop path generation process. Each hop only screens paths whose similarity with the question sentence meets the set conditions, which can effectively eliminate paths irrelevant to the question sentence and avoid an explosion in the number of paths. The search can be terminated after the set termination condition is reached to obtain the final multi-hop path set.
[0060] Step S130: Obtain a constrained path set based on the combination of every two multi-hop paths in the multi-hop path set.
[0061] Specifically, combined Figure 2From the analysis of the constraint path and multi-hop path of the example, it can be seen that the constraint path can be obtained by converting the multi-hop path. Specifically, the constraint path can be represented by a combination of multi-hop paths.
[0062] for example Figure 2 The first constraint path can be obtained by merging two one-hop paths, the second constraint path can be obtained by merging a one-hop path and a two-hop path, the third constraint path can be obtained by merging two three-hop paths, and the third constraint path can be obtained by merging two four-hop paths. There are more constraint paths that are not listed above. Figure 2 For example, a three-entity constraint path can be obtained by merging two two-entity constraint paths.
[0063] To this end, in this step, based on the multi-hop path set obtained in the previous step, the multi-hop paths are combined in pairs to obtain a constrained path set.
[0064] Therefore, the multi-hop path set and the constraint path set can contain all possible answer paths for the question sentence.
[0065] Step S140: Calculate the similarity between each path in the multi-hop path set and the constraint path set and the question sentence, and select the answer entity of the path with the highest similarity as the final answer.
[0066] Specifically, the similarity between each path in the above two sets and the question sentence is calculated, and the answer entity of the path with the highest similarity is selected as the final answer, which improves the comprehensiveness and accuracy of answer entity retrieval.
[0067] The question-answering method based on the knowledge graph provided in the embodiment of the present application uses a hop-by-hop path search method in the process, which can effectively combine the structural information of the knowledge graph itself, and embed the similarity score into the multi-hop path generation process. Each hop only screens the paths that meet the set conditions for similarity with the question sentence, which can effectively eliminate the paths that are irrelevant to the question sentence and avoid the explosion of the number of paths. For questions with constraints, the answers correspond to the constraint paths in the knowledge graph, and the constraint paths can be obtained based on the multi-hop path conversion. Therefore, after obtaining the multi-hop path set, the present application obtains the constraint path set based on the combination of two multi-hop paths in the multi-hop path set. Thus, the multi-hop path set and the constraint path set can contain all possible answer paths for the question sentence. Finally, the similarity between each path in the above two sets and the question sentence is calculated, and the answer entity of the path with the highest similarity is selected as the final answer.
[0068] The method of this application uses a hop-by-hop path search approach when generating a multi-hop path set, eliminating paths irrelevant to the question sentence, preventing an explosion in the number of paths and ensuring the feasibility of the solution in addressing complex problems. Furthermore, by generating a multi-hop path set and a constrained path set, all possible answer paths to the question sentence can be obtained. Ultimately, by calculating the similarity with the question sentence, the answer entity with the path with the highest similarity is selected as the final answer, improving the comprehensiveness and accuracy of answer entity retrieval.
[0069] In some embodiments of the present application, the above step S120 is described, in which the target entity is used as the starting point in the knowledge graph and a multi-hop path set is searched in a hop-by-hop manner. Figure 3 As shown, it may include the following steps:
[0070] Step S200: Recall the one-hop path of the answer entity of the current multi-hop path in the knowledge graph.
[0071] Specifically, multi-hop paths at different times can be obtained by searching the hop-by-hop path. A multi-hop path can be understood as a path from the target entity to the currently searched entity.
[0072] It should be noted that the multi-hop path at the initial moment is empty, and there is only the target entity linked to the question sentence in the knowledge graph. Therefore, the answer entity of the multi-hop path at the initial moment is the target entity, and what is recalled is the one-hop path to the target entity.
[0073] The one-hop path recalled in this step can be one or more, depending on the number of next-hop paths of the answer entity of the current multi-hop path in the knowledge graph.
[0074] Step S210: Combine each one-hop path with the current multi-hop path to obtain several combined paths.
[0075] Specifically, after the one-hop paths of the answer entity of the multi-hop path are recalled in the previous step, each one-hop path is combined with the current multi-hop path to obtain several combined paths.
[0076] Step S220: Calculate the similarity between each combination path and the question sentence.
[0077] Specifically, in the previous step, each one-hop path is combined with a multi-hop path, resulting in multiple combined paths. However, some of these one-hop paths may not be correct. Therefore, in this step, to reduce the number of multi-hop paths, the similarity between the combined paths and the question sentence is calculated. This similarity measures the likelihood that the combined path is the correct path for the question sentence.
[0078] The calculation process of the similarity between the path and the question sentence is detailed below.
[0079] Step S230: Select the top-K1 combined paths with the highest similarity as the multi-hop paths for the next moment and add them to the multi-hop path set.
[0080] Specifically, in this step, the similarity between the combined path and the question sentence is used as the screening condition. The top-K1 combined paths with the highest similarity are selected as the multi-hop paths to continue searching, that is, as the multi-hop paths for the next moment, and are added to the multi-hop path set.
[0081] Here, K1 can be set according to the algorithm's requirement for balancing calculation speed and accuracy. Generally, to prevent error accumulation, K1 can be set to 10 or other values.
[0082] Furthermore, considering that some answer entities contain a large number of entities, for example, "What delicacies are in the knowledge base?", there may be many types of delicacies in the knowledge graph, such as "Mapo Tofu," "Cola Chicken Wings," "Cake," and so on, resulting in a large number of answer entities. Furthermore, few question sentences have multiple entities as intermediate nodes. Therefore, a quantity threshold can be set. Before calculating similarity in step S220, combination paths whose number of answer entities exceeds the set quantity threshold can be removed. This eliminates these combination paths that are likely to be incorrect, reducing the amount of subsequent calculations.
[0083] Step S240: Determine whether the first termination condition is met. If so, the algorithm ends and the final multi-hop path set is obtained. If not, return to the above step S200.
[0084] In this embodiment, various first termination conditions may be set. For example, the first termination condition may include any one or more combinations of the following conditions:
[0085] 1) The hop count of the longest multi-hop path in the multi-hop path set reaches a set hop count threshold N1, that is, the application may specify a maximum of N1 hop paths to be recalled.
[0086] 2) The similarity between each combination path and the question sentence is less than the set similarity threshold.
[0087] The similarity threshold can be set according to actual needs, for example, to 0.5 or other values.
[0088] By setting the above first termination condition, the purpose of reducing the amount of calculation can be achieved.
[0089] In some embodiments of the present application, the process of obtaining the constrained path set based on the combination of two multi-hop paths in the multi-hop path set in step S130 is described. Figure 4 As shown, it may include the following steps:
[0090] Step S300: Calculate the intersection of answer entities of two multi-hop paths in the multi-hop path set.
[0091] Specifically, as previously explained, a constraint path can be formed by combining multi-hop paths. For two multi-hop paths to be combined into a constraint path, the answer entities of the two multi-hop paths must intersect. To this end, in this step, the answer entities of each pair of multi-hop paths in the previously obtained multi-hop path set are intersected to determine whether the intersection is empty.
[0092] Step S310: Calculate the union of any two multi-hop paths whose intersections are not empty, and use the union as the constraint path.
[0093] Specifically, if the answer entity intersection of two multi-hop paths exists and is not empty, the two multi-hop paths can be unioned, and the result is used as the constraint path.
[0094] Step S320: Calculate the similarity between each constraint path and the question sentence, select the top-K2 constraint paths with the highest similarity, and add them to the constraint path set.
[0095] Next, the process of obtaining the constraint path set is described through a specific example.
[0096] Define the question sentence as "Which country is the philosopher who proposed the categorical directive from?" Some entities and relationships in the knowledge graph are as follows Figure 5 shown.
[0097] First, through entity linking, it is determined that the target entities linked to the question sentence in the knowledge graph include "absolute instruction" and "philosopher".
[0098] Starting from the above two target entities, the multi-hop path set obtained based on the knowledge graph is as follows Figure 5 As shown, two multi-hop paths are exemplified, namely: "Categorical Directive-Proposer-Kant-Nationality-Germany" and "Philosopher-Occupation-(Kant, Confucius, Descartes)-Nationality-(Germany, China, France)".
[0099] On this basis, we find the intersection of the answer entities of the two multi-hop paths above, and we can determine that the intersection includes "Germany", that is, the union is not empty. Then we find the union of the two multi-hop paths and get the constraint path as follows: Figure 5 Shown at the bottom.
[0100] Furthermore, the above Figure 4 The example solution can obtain a path constrained by two entities. However, some complex problems may involve a path constrained by three or more entities as the correct path. For this reason, the embodiment of the present application further provides another implementation method for obtaining a set of constrained paths, combining Figure 6 As shown, based on the above steps S300-S320, the method may further include the following processing steps:
[0101] Step S330: finding the intersection of the answer entities of each two constraint paths in the constraint path set.
[0102] Step S340: Calculate the union of any two constraint paths whose intersections are not empty, and use the union as a new constraint path.
[0103] Step S350: Calculate the similarity between each of the new constraint paths and the question sentence, select the top-K2 new constraint paths with the highest similarity, and add them to the constraint path set.
[0104] Step S360, determine whether the second termination condition is met, if so, end and obtain the final constraint path set, if not, return to execute the aforementioned step S330, and calculate the intersection of the answer entities of each two constraint paths in the constraint path set.
[0105] In this embodiment, various second termination conditions may be set. For example, the second termination condition may include any one or more combinations of the following conditions:
[0106] 1) The algorithm iteration count reaches a set iteration threshold. This means that the application can specify a maximum number of iterations. By setting this iteration threshold, paths constrained by more than three entities can be obtained. Furthermore, as the number of iterations increases, the number of entities constraining the resulting constrained path increases.
[0107] Considering the number of entities serving as constraints in the constraint path corresponding to the actual problem, the present application may choose to set the above-mentioned iteration threshold to 2 or other values.
[0108] 2) The similarity between each new constraint path and the problem sentence is less than the set similarity threshold.
[0109] The similarity threshold can be set according to actual needs, for example, to 0.5 or other values.
[0110] In the knowledge graph-based question-answering method introduced in the above embodiment, there are multiple places where it is necessary to calculate the similarity between a path and a question sentence. For example, in the aforementioned step S140, the similarity between each path in the multi-hop path set and the constraint path set and the question sentence is calculated; in the aforementioned step S220, the similarity between each combined path and the question sentence is calculated; in the aforementioned step S320, the similarity between each constraint path and the question sentence is calculated, etc. For this reason, this embodiment provides an optional implementation method for calculating the similarity between a path and a question sentence.
[0111] This embodiment provides a solution for scoring the similarity between a path and a question sentence using a pre-trained model. The pre-trained model can use a BERT or other neural network model. Here, the pre-trained model is defined as a sentence similarity calculation model. The process of calculating the similarity between a path and a question sentence can include:
[0112] First, the question sentence and path are concatenated into input information, where the path includes the information of each triple.
[0113] The input information can be expressed in the form of: Question[SEP]Entity1$relationship1$? a#Entity2$relationship2$? a#? b$relationship3$Entity3…
[0114] Where Question is the question sentence, [SEP] is the separator between the question sentence and the path, and a path consists of several triples, separated by "#". Entities and relationships within a triple are separated by "$". Intermediate and final answer entities in a path are represented by "? + a letter".
[0115] Furthermore, the input information is processed using a pre-trained sentence similarity calculation model to obtain a similarity score between the path to be calculated and the problem sentence predicted by the model.
[0116] Specifically, taking the sentence similarity calculation model using the BERT pre-trained model structure as an example, the input training is input into the model, and the CLS position vector output is taken, passing through the fully connected layer, and finally the sigmoid activation to obtain the similarity score between the path and the question sentence.
[0117] Next, the training process of the above sentence similarity calculation model is explained.
[0118] The model training process can include the following processing steps:
[0119] S1. Obtain training samples.
[0120] The training samples include the correct path corresponding to the training question in the knowledge graph, a partial path within the correct path, and an incorrect path different from the correct path. The correct path is the path from the target entity linked to the training question to the answer entity that matches the training question.
[0121] Among the three types of paths included in the training samples (incorrect paths, partial paths of correct paths, and correct paths), incorrect paths refer to paths that cannot lead to the correct answer entity corresponding to the training question. Incorrect paths can be generated randomly. For example, for a two-hop question, k incorrect one-hop paths are first generated, and then k incorrect paths are generated based on the correct one-hop question. The above 2k incorrect paths are used as training samples for the first type of incorrect paths.
[0122] Reference Figure 7 , which illustrates the three types of training samples generated for the question sentence "Which country is the philosopher who proposed the absolute directive from?", where the first type is the wrong path, the second type is the partial path of the correct path, and the third type is the correct path ( Figure 7 Only some paths are shown in the examples, not all training samples).
[0123] S2. Different sample labels are set for the correct path, partial path in the correct path, and incorrect path in the training sample.
[0124] Specifically, in order to have a supervised training model, different sample labels need to be set for different types of training samples. For example, a first sample label is set for the wrong path, such as the label is set to 0, a second sample label is set for part of the correct path, such as the label is set to 1, and a third sample label is set for the correct path, such as the label is set to 2.
[0125] S3. Concatenate the training question with each training sample and input the concatenated concatenation results into a sentence similarity calculation model to obtain a similarity score between the training sample and the training question predicted by the model.
[0126] S4. Based on the similarity score between the training sample predicted by the model and the training question, and the sample label of the training sample, calculate the loss back-propagation training model parameters.
[0127] Specifically, the loss can be calculated using cross entropy loss according to the sample labels of the training samples, and the training model parameters can be back-propagated until the set convergence conditions are reached to obtain the trained sentence similarity calculation model.
[0128] Considering that the recall of candidate entities will also directly affect the accuracy of subsequent entity links and path generation, and natural language question answering often encounters problems such as users' descriptions of question sentences are not standardized, and the question sentences may not literally contain entities in the knowledge graph, this increases the difficulty of recalling candidate entities.
[0129] To this end, this embodiment provides a candidate entity recall method, that is, the aforementioned step S100, an optional implementation method for determining the candidate entity in the knowledge graph pointed to by the question sentence.
[0130] This embodiment provides several different candidate entity recall strategies, and you can choose any one or a combination of several of these recall strategies. Next, different recall strategies will be introduced respectively.
[0131] The first candidate entity recall strategy: candidate entity recall based on entity keyword recognition model.
[0132] For candidate entity recall, each word in the question sentence is not equally important, so in this embodiment, the key information in the question sentence can be accurately captured first, so as to accurately understand and reason about the question sentence. In this embodiment, an entity keyword recognition model can be pre-trained, which can adopt the network structure of the sequence labeling model BERT+CRF, or other optional neural network structures. The entity keyword recognition model is different from the traditional named entity recognition model. The entity keyword recognition model only focuses on the overlapping words of the question sentence and the correct answer entity, rather than continuous and complete words. For example, "Can the flagship store of the Unicorn Starry Sky Museum in City A be cheaper?", the answer entity is "Flagship Store of Unicorn Starry Sky Art Museum in City A". The answer entity is not only discontinuous but also incomplete in the question sentence. It cannot be correctly labeled using the traditional named entity recognition model. Using the entity keyword recognition model of this embodiment, the words "Nanjing Unicorn Starry Sky Museum Flagship Store" will be labeled, and the correct answer entity can be found later through fuzzy matching.
[0133] To this end, the candidate entity recall process based on the entity keyword recognition model can include:
[0134] S1. Use a pre-trained entity keyword recognition model to process the problem sentence, obtain keywords belonging to entity words in the problem sentence output by the model, and form a target text segment with each keyword.
[0135] The entity keyword recognition model is obtained by training using training questions as training samples and using words that overlap between the training questions and corresponding entity words as keyword sample labels.
[0136] S2. Use fuzzy matching to determine candidate entities in the knowledge graph that match the target text segment.
[0137] Figure 8 It exemplifies a schematic diagram of an entity keyword recognition model using a sequence annotation structure.
[0138] Its input includes the word embedding representations corresponding to each word segment in the question sentence, Tok1 - TokN, where N represents the length of the question sentence. The main body of the entity keyword recognition model uses the BERT pre-trained model as the backbone network and adopts the form of sequence annotation to output the annotation results of each word segment in the question sentence.
[0139] Figure 8 Among them, the entity keywords in the question sentence are labeled as 1, and the remaining words are labeled as 0.
[0140] When training the above entity keyword recognition model, the training data can be constructed first. Specifically, the intersection of the training question sentence and the corresponding answer entity is obtained to get the entity keywords in the training question sentence, and the entity keywords and the remaining words in the training question sentence are respectively marked with different labels. For example, the entity keywords are marked as 1, and the remaining words are labeled as 0.
[0141] The above training question sentence is input into the model, and the context-related vector representation of each word segment in the training question sentence is obtained by the model, so as to obtain a state score. This score is then modeled by the conditional random field CRF to represent the constraint relationship between the annotations, and the model parameters are trained by backpropagation through the constructed labels.
[0142] The candidate entity recall strategy based on the entity keyword recognition model provided in this embodiment can obtain the entity keywords in the question sentence through the pre-trained entity keyword recognition model, and further obtain the matching candidate entities in the knowledge graph by using the fuzzy matching method, which can improve the accuracy of candidate entity recall.
[0143] The second candidate entity recall strategy: candidate entity recall based on entity generation.
[0144] Specifically, in the actual scenario, some question sentences may not contain words overlapping with the target entity linked by the sentence, and the candidate entity needs to be correctly obtained through understanding. For example, the question sentence is "What are the delicious foods in the database?", and the target entity that this question sentence should link to should be "delicious food", but the words of this target entity do not appear in the question sentence, and only the alias "delicious" of the target entity appears in the question sentence.
[0145] To address such problems, a solution for generating candidate entities through a model is provided in this embodiment. Specifically, this embodiment can pre-train a fuzzy entity generation model, which is trained with the training question sentence as the training sample and the entity and entity alias referred to by the training question sentence as the fuzzy entity sample label.
[0146] Considering that entities and entity aliases used as sample labels do not require sequence length equality, a seq2seq-based entity generation model can be used in this embodiment. The model structure is as follows: Figure 9 shown.
[0147] Seq2Seq is an encoder-decoder neural network whose input is a sequence and whose output is also a sequence. The Seq2Seq model consists of three basic components: the encoder, the decoder, and the intermediate state vector C (also called the semantic code C) connecting the two. The encoder learns the input and encodes it into a fixed-size state vector C, which is then passed to the decoder. The decoder then learns from the state vector C to output the corresponding sequence.
[0148] In this embodiment, the process of recalling candidate entities based on entity generation may specifically include:
[0149] S1. Use a pre-trained fuzzy entity generation model to process the problem sentence, and obtain the fuzzy entity referred to by the problem sentence output by the model.
[0150] S2. Use fuzzy matching to determine candidate entities in the knowledge graph that match the fuzzy entity.
[0151] The candidate entity recall strategy based on entity generation provided in this embodiment can generate the fuzzy entity referred to by the question sentence through a pre-trained fuzzy entity generation model, and then use fuzzy matching to obtain the candidate entity matching the fuzzy entity in the knowledge graph. For the case where the question sentence does not contain subwords of the target entity linked to the sentence, the strategy of this embodiment can improve the accuracy of candidate entity recall.
[0152] The first and second candidate entity recall strategies mentioned above both involve the process of using fuzzy matching to determine the candidate entities that match in the knowledge graph. The first strategy is to use fuzzy matching to determine the candidate entities in the knowledge graph that match the target text fragment composed of entity keywords. The second strategy is to use fuzzy matching to determine the candidate entities in the knowledge graph that match the fuzzy entity.
[0153] To facilitate understanding of the solution, the fuzzy matching process is further explained in this embodiment.
[0154] Neither the target text fragment composed of entity keywords obtained through entity keyword recognition using the first strategy nor the fuzzy entity generated through entity generation using the second strategy can be guaranteed to be complete and accurate. For example, the question sentence "What categories can the earliest Chinese poetry collection be divided into?" has the target entity linked to it in the knowledge graph as "<The earliest Chinese poetry collection>". However, the text fragment obtained through the aforementioned entity keyword recognition model may be "The earliest poetry collection". Therefore, to compensate for possible errors in the model and improve fault tolerance, after obtaining the target text fragment composed of entity keywords and the fuzzy entity, fuzzy matching can be used to obtain matching candidate entities in the knowledge graph.
[0155] The target text segment to be fuzzy matched and the fuzzy entity are collectively referred to as the text to be matched.
[0156] The fuzzy matching process can include:
[0157] S1. Establish an inverted index from words to entities in the knowledge graph, and recall the higher matching preliminary candidate entities in the knowledge graph according to the words that appear in the text to be matched.
[0158] S2. If the text to be matched is a target text segment, calculate the Jaccard similarity coefficient between each subsegment in the target text segment and the preliminary candidate entity, obtain the target subsegment and the target preliminary candidate entity with the highest coefficient score, and use the target subsegment as the referent of the target preliminary candidate entity. If the text to be matched is a fuzzy entity, directly use the fuzzy entity as the referent.
[0159] S3. Calculate the edit distance between the reference obtained in the previous step and the preliminary candidate entity obtained in S1, and select the top-M preliminary candidate entities with the shortest distance according to the edit distance as the final candidate entity to complete the fuzzy matching process.
[0160] The third candidate entity recall strategy: dictionary and rule-based candidate entity recall.
[0161] Match the question sentence with entities in a preset dictionary to obtain matching candidate entities in the dictionary as candidate entities in the knowledge graph pointed to by the question sentence, wherein the preset dictionary includes entities in the knowledge graph.
[0162] Specifically, entities in the knowledge graph can be normalized in terms of case, time / date, and punctuation, and then added to the dictionary to improve the recall rate of candidate entities.
[0163] In some embodiments of the present application, the process of selecting the target entity linked to the question sentence from the candidate entities in step S110 is further described. The specific process may include the following steps:
[0164] For each candidate entity, perform the following processing operations S1-S3:
[0165] S1. Search for all one-hop paths of the candidate entity and its answer entity in the knowledge graph.
[0166] S2. Calculate the character similarity between the text consisting of the candidate entity, the one-hop path and its answer entity and the question sentence, and select the one-hop path and its answer entity that meet the set character similarity condition, and each selected one-hop path and its answer entity form a one-degree relationship.
[0167] Specifically, in order to filter out valid information around candidate entities in the knowledge graph, this step calculates the character similarity between the text consisting of the candidate entity, one-hop path and its answer entity and the question sentence, and selects the one-hop path and answer entity that meet the conditions to form a first-degree relationship. This first-degree relationship can be understood as the valid information obtained by filtering.
[0168] It is understandable that there may be more than one one-hop path and its answer entity that meet the set character similarity condition. Therefore, each one-hop path and its answer entity form a first-degree relationship, and several first-degree relationships can be obtained.
[0169] S3. Based on the question sentence, the candidate entities, and each of the first-degree relationships, determine the probability of the candidate entity being the target entity.
[0170] Specifically, in this step, the probability score of the candidate entity as the target entity can be determined based on the candidate entity and the effective information filtered around it, as well as the question sentence.
[0171] Alternatively, the probability score of a candidate entity as a target entity can be calculated based on a pre-trained entity linking model.
[0172] Specifically, an entity linking model can be pre-trained, which is trained using entities to which training questions are linked in the knowledge graph as positive samples and entities to which training questions cannot be linked in the knowledge graph as negative samples.
[0173] The question sentence, candidate entities and each of the first-degree relationships are concatenated and input into an entity linking model to obtain the probability that the candidate entity output by the model is the target entity.
[0174] The process of splicing the question sentence, candidate entities and the first-degree relationships can be expressed as: Question[SEP]Entity$relationship1#relationship2#relationship3, where Question represents the question sentence, [SEP] represents a separator, Entity represents a candidate entity, and relationship represents a first-degree relationship. Multiple different first-degree relationships can be separated by #.
[0175] Figure 10 This example illustrates a schematic diagram of an entity linking model, primarily based on the BERT pre-trained model. The question sentence, candidate entities, and first-degree relationships are concatenated and fed into the model to generate embeddings for each word in the input. After model processing, the CLS position vector is output, passed through a fully connected layer, and finally a sigmoid activation to determine the probability score of the candidate entity as the target entity. Based on this probability score, the candidate entity's classification result, i.e., whether it belongs to the target entity, is output as the Class Label.
[0176] S4. Filter candidate entities whose probabilities satisfy set probability conditions as target entities linked to the question sentence.
[0177] According to the aforementioned steps S1-S3, the probability score of each candidate entity can be obtained. In this step, the candidate entities that meet the set probability conditions can be screened as the target entities linked to the question sentence.
[0178] The set probability condition may be that the probability score exceeds a set score threshold, or that the TOP-K3 candidate entities with the highest probability scores are screened as target entities.
[0179] It's understandable that the larger K3 is, the higher the recall rate of subsequent answer entities will be, but the computational complexity of subsequent search for answer entities will also increase. Therefore, the number of K3 can be set based on the actual situation to balance the recall rate of answer entities and the computational complexity. For example, it can be set to 2 or other values.
[0180] The following describes the knowledge graph-based question-answering device provided in an embodiment of the present application. The knowledge graph-based question-answering device described below and the knowledge graph-based question-answering method described above can refer to each other.
[0181] See also Figure 11 , Figure 11 This is a schematic diagram of the structure of a question-answering device based on a knowledge graph disclosed in an embodiment of the present application.
[0182] like Figure 11 As shown, the device may include:
[0183] A candidate entity determination unit 11 is used to determine the candidate entity in the knowledge graph pointed to by the question sentence;
[0184] An entity linking unit 12 is configured to select a target entity linked to the question sentence from among the candidate entities;
[0185] A multi-hop path search unit 13 is configured to search for a set of multi-hop paths in the knowledge graph using the target entity as a starting point in a hop-by-hop path search manner. In each hop path search process, the current multi-hop path is combined with each one-hop path of the answer entity of the current multi-hop path to obtain a plurality of combined paths, and the combined path whose similarity to the question sentence satisfies a set condition is selected as the multi-hop path for the next moment.
[0186] A constrained path acquisition unit 14 is configured to obtain a constrained path set based on a combination of any two multi-hop paths in the multi-hop path set;
[0187] The answer entity selection unit 15 is used to calculate the similarity between each path in the multi-hop path set and the constraint path set and the question sentence, and select the answer entity of the path with the highest similarity as the final answer.
[0188] Optionally, the process of the multi-hop path search unit searching for a multi-hop path set in the knowledge graph using the target entity as a starting point in a hop-by-hop path search manner may include:
[0189] Recalling one-hop paths of the answer entity of the current multi-hop path in the knowledge graph, and combining each one-hop path with the current multi-hop path to obtain a plurality of combined paths, wherein the multi-hop path at the initial moment is empty, and the answer entity of the multi-hop path at the initial moment is the target entity;
[0190] Calculate the similarity between each combination path and the question sentence;
[0191] The top-K1 combined paths with the highest similarity are selected as the multi-hop paths for the next moment, added to the multi-hop path set, and the step of recalling the one-hop path of the answer entity of the current multi-hop path in the knowledge graph is returned until the first termination condition is met to obtain the final multi-hop path set.
[0192] Optionally, before calculating the similarity between each combined path and the question sentence, the multi-hop path search unit may further be used to:
[0193] The combination paths whose answer entities exceed the set threshold are removed.
[0194] Optionally, the first termination condition may include:
[0195] The hop count of the longest multi-hop path in the multi-hop path set reaches the set hop count threshold;
[0196] and / or,
[0197] The similarity between each combined path and the question sentence is less than the set similarity threshold.
[0198] Optionally, the process of obtaining the constrained path set by the constrained path acquisition unit based on the combination of any two multi-hop paths in the multi-hop path set may include:
[0199] Calculate the intersection of answer entities of two multi-hop paths in the multi-hop path set;
[0200] The union of the two multi-hop paths whose intersection is not empty is taken as the constraint path, and the similarity between each constraint path and the question sentence is calculated. The top-K2 constraint paths with the highest similarity are selected and added to the constraint path set.
[0201] Optionally, the constraint path acquisition unit may also be used to:
[0202] Calculate the intersection of answer entities of each constraint path in the constraint path set;
[0203] The union of the pairwise constraint paths whose intersection is not empty is taken as the new constraint path, and the similarity between each new constraint path and the question sentence is calculated. The top-K2 new constraint paths with the highest similarity are selected and added to the constraint path set. The step of intersecting the answer entities of the pairwise constraint paths in the constraint path set is returned to execute until the second termination condition is met to obtain the final constraint path set.
[0204] Optionally, the second termination condition may include:
[0205] The number of algorithm iterations reaches the set iteration threshold;
[0206] and / or,
[0207] The similarity between each new constraint path and the problem sentence is less than the set similarity threshold.
[0208] Optionally, the process of calculating the similarity between the multi-hop path search unit, the constraint path acquisition unit, and the answer entity selection unit and the question sentence may include:
[0209] Splicing the question sentence and the path to be calculated into input information, wherein the path to be calculated includes information of each triple;
[0210] The input information is processed using a pre-trained sentence similarity calculation model to obtain a similarity score between the path to be calculated and the problem sentence predicted by the model.
[0211] Optionally, the apparatus of the present application may further include: a sentence similarity calculation model training unit, wherein the process of training the sentence similarity calculation model may include:
[0212] Obtaining a training sample, wherein the training sample includes a correct path corresponding to the training question in the knowledge graph, a partial path in the correct path, and an incorrect path different from the correct path, wherein the correct path is a path from a target entity linked to the training question to an answer entity matching the training question;
[0213] Setting different sample labels for the correct path, partial path in the correct path, and incorrect path in the training sample;
[0214] The training question is concatenated with each training sample and input into a sentence similarity calculation model to obtain a similarity score between the training sample and the training question predicted by the model;
[0215] Based on the similarity scores between the training samples predicted by the model and the training questions, and the sample labels of the training samples, the loss is calculated and the model parameters are trained through backpropagation.
[0216] Optionally, the process of the candidate entity determination unit determining the candidate entity in the knowledge graph pointed to by the question sentence may include:
[0217] Processing the problem sentence using a pre-trained entity keyword recognition model to obtain keywords belonging to entity words in the problem sentence output by the model, and forming a target text segment with each keyword;
[0218] The entity keyword recognition model is obtained by training using training questions as training samples and using words that overlap between the training questions and the corresponding entity words as keyword sample labels;
[0219] A fuzzy matching method is used to determine candidate entities in the knowledge graph that match the target text segment.
[0220] Optionally, the process of the candidate entity determination unit determining the candidate entity in the knowledge graph pointed to by the question sentence may further include:
[0221] Processing the problem sentence using a pre-trained fuzzy entity generation model to obtain the fuzzy entity referred to by the problem sentence as output by the model;
[0222] The fuzzy entity generation model is obtained by training using training questions as training samples and the entities and entity aliases referred to by the training questions as fuzzy entity sample labels;
[0223] A fuzzy matching method is used to determine candidate entities in the knowledge graph that match the fuzzy entity.
[0224] Optionally, the process of the candidate entity determination unit determining the candidate entity in the knowledge graph pointed to by the question sentence may further include:
[0225] The question sentence is matched with entities in a preset dictionary to obtain matching candidate entities in the dictionary as candidate entities in the knowledge graph pointed to by the question sentence, wherein the preset dictionary includes entities in the knowledge graph.
[0226] Optionally, the process of the entity linking unit screening the target entity linked to the question sentence from the candidate entities may include:
[0227] For each candidate entity, searching for all one-hop paths of the candidate entity and its answer entities in the knowledge graph;
[0228] Calculating the character similarity between the text consisting of the candidate entity, the one-hop path and its answer entity and the question sentence, and selecting the one-hop path and its answer entity that meet the set character similarity condition, and forming a first-degree relationship with each selected one-hop path and its answer entity;
[0229] Determining a probability of the candidate entity being a target entity based on the question sentence, the candidate entity, and each of the first-degree relationships;
[0230] Candidate entities whose probabilities satisfy set probability conditions are screened as target entities linked to the question sentence.
[0231] Optionally, the process of determining the probability of the candidate entity being the target entity based on the question sentence, the candidate entity, and each of the first-degree relationships by the entity linking unit may include:
[0232] The question sentence, the candidate entity, and each of the first-degree relationships are concatenated and input into a pre-trained entity linking model to obtain a probability of the candidate entity being a target entity output by the model;
[0233] The entity linking model is trained by using entities to which the training questions are linked in the knowledge graph as positive samples and entities to which the training questions cannot be linked in the knowledge graph as negative samples.
[0234] The question-answering device based on knowledge graph provided in the embodiment of the present application can be applied to question-answering devices based on knowledge graph, such as terminals: mobile phones, computers, etc. Optionally, Figure 12 The hardware structure diagram of the question-answering device based on the knowledge graph is shown. Figure 12 ,The hardware structure of the knowledge graph-based question-answering device may include: at least one processor 1, at least one communication interface 2, at least one memory 3 and at least one communication bus 4;
[0235] In the embodiment of the present application, the number of the processor 1, the communication interface 2, the memory 3, and the communication bus 4 is at least one, and the processor 1, the communication interface 2, and the memory 3 communicate with each other through the communication bus 4;
[0236] The processor 1 may be a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present invention;
[0237] The memory 3 may include a high-speed RAM memory, and may also include a non-volatile memory, such as at least one disk memory;
[0238] Among them, the memory stores a program, and the processor can call the program stored in the memory, and the program is used to: implement each step of the question-answering method based on the knowledge graph in the aforementioned embodiment.
[0239] An embodiment of the present application further provides a storage medium, which may store a program suitable for execution by a processor, wherein the program is used to:
[0240] Implement each step of the knowledge graph-based question-answering method in the aforementioned embodiment.
[0241] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or device comprising the element.
[0242] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The various embodiments can be combined as needed, and the same or similar parts can be referenced to each other.
[0243] The above description of the disclosed embodiments will enable those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application is not limited to the embodiments shown herein, but is to be construed in the widest manner consistent with the principles and novel features disclosed herein.
Claims
1. A question-answering method based on knowledge graph, characterized in that: include: Determine the candidate entities in the knowledge graph pointed to by the question sentence; Filtering the target entity linked to the question sentence from the candidate entities; In the knowledge graph, a multi-hop path set is searched in a hop-by-hop path search manner with the target entity as the starting point, wherein, in each hop path search process, a current multi-hop path is combined with each one-hop path of the answer entity of the current multi-hop path to obtain a plurality of combined paths, and a combined path whose similarity to the question sentence meets a set condition is selected as the multi-hop path for the next moment; Obtaining a constrained path set based on combinations of any two multi-hop paths in the multi-hop path set; Calculating the similarity between each path in the multi-hop path set and the constrained path set and the question sentence, and selecting the answer entity of the path with the highest similarity as the final answer; The process of obtaining the constrained path set based on the combination of two multi-hop paths in the multi-hop path set includes: Calculate the intersection of answer entities of two multi-hop paths in the multi-hop path set; The union of the two multi-hop paths whose intersection is not empty is taken as the constraint path, and the similarity between each constraint path and the question sentence is calculated. The top-K2 constraint paths with the highest similarity are selected and added to the constraint path set.
2. The method according to claim 1, characterized in that The process of searching for a multi-hop path set in the knowledge graph using the target entity as a starting point and in a hop-by-hop path search manner includes: Recalling one-hop paths of the answer entity of the current multi-hop path in the knowledge graph, and combining each one-hop path with the current multi-hop path to obtain a plurality of combined paths, wherein the multi-hop path at the initial moment is empty, and the answer entity of the multi-hop path at the initial moment is the target entity; Calculate the similarity between each combination path and the question sentence; The top-K1 combined paths with the highest similarity are selected as the multi-hop paths for the next moment, added to the multi-hop path set, and the step of recalling the one-hop path of the answer entity of the current multi-hop path in the knowledge graph is returned until the first termination condition is met to obtain the final multi-hop path set.
3. The method according to claim 2, characterized in that Before calculating the similarity between each combined path and the question sentence, the method further includes: The combination paths whose answer entities exceed the set threshold are removed.
4. The method according to claim 2, characterized in that The first termination condition includes: The hop count of the longest multi-hop path in the multi-hop path set reaches the set hop count threshold; and / or, The similarity between each combined path and the question sentence is less than the set similarity threshold.
5. The method according to claim 1, wherein Also includes: Calculate the intersection of answer entities of each constraint path in the constraint path set; The union of the pairwise constraint paths whose intersection is not empty is taken as the new constraint path, and the similarity between each new constraint path and the question sentence is calculated. The top-K2 new constraint paths with the highest similarity are selected and added to the constraint path set. The step of intersecting the answer entities of the pairwise constraint paths in the constraint path set is returned to execute until the second termination condition is met to obtain the final constraint path set.
6. The method according to claim 5, characterized in that The second termination condition includes: The number of algorithm iterations reaches the set iteration threshold; and / or, The similarity between each new constraint path and the problem sentence is less than the set similarity threshold.
7. The method according to claim 1, characterized in that The process of calculating the similarity between any path and the question sentence includes: Splicing the question sentence and the path to be calculated into input information, wherein the path to be calculated includes information of each triple; The input information is processed using a pre-trained sentence similarity calculation model to obtain a similarity score between the path to be calculated and the problem sentence predicted by the model.
8. The method according to claim 7, characterized in that The training process of the sentence similarity calculation model includes: Obtaining a training sample, wherein the training sample includes a correct path corresponding to the training question in the knowledge graph, a partial path in the correct path, and an incorrect path different from the correct path, wherein the correct path is a path from a target entity linked to the training question to an answer entity matching the training question; Setting different sample labels for the correct path, partial path in the correct path, and incorrect path in the training sample; The training question is concatenated with each training sample and input into a sentence similarity calculation model to obtain a similarity score between the training sample and the training question predicted by the model; Based on the similarity scores between the training samples predicted by the model and the training questions, and the sample labels of the training samples, the loss is calculated and the model parameters are trained through backpropagation.
9. The method according to any one of claims 1 to 8, characterized in that Determining the candidate entity in the knowledge graph pointed to by the question sentence includes: Processing the problem sentence using a pre-trained entity keyword recognition model to obtain keywords belonging to entity words in the problem sentence output by the model, and forming a target text segment with each keyword; The entity keyword recognition model is obtained by training using training questions as training samples and using words that overlap between the training questions and the corresponding entity words as keyword sample labels; A fuzzy matching method is used to determine candidate entities in the knowledge graph that match the target text segment.
10. The method according to claim 9, characterized in that The step of determining the candidate entity in the knowledge graph pointed to by the question sentence further includes: Processing the problem sentence using a pre-trained fuzzy entity generation model to obtain the fuzzy entity referred to by the problem sentence as output by the model; The fuzzy entity generation model is obtained by training using training questions as training samples and the entities and entity aliases referred to by the training questions as fuzzy entity sample labels; A fuzzy matching method is used to determine candidate entities in the knowledge graph that match the fuzzy entity.
11. The method according to claim 9, characterized in that The step of determining the candidate entity in the knowledge graph pointed to by the question sentence further includes: The question sentence is matched with entities in a preset dictionary to obtain matching candidate entities in the dictionary as candidate entities in the knowledge graph pointed to by the question sentence, wherein the preset dictionary includes entities in the knowledge graph.
12. The method according to any one of claims 1 to 8, characterized in that The process of selecting a target entity linked to the question sentence from the candidate entities includes: For each candidate entity, searching for all one-hop paths of the candidate entity and its answer entities in the knowledge graph; Calculating the character similarity between the text consisting of the candidate entity, the one-hop path and its answer entity and the question sentence, and selecting the one-hop path and its answer entity that meet the set character similarity condition, and forming a first-degree relationship with each selected one-hop path and its answer entity; Determining a probability of the candidate entity being a target entity based on the question sentence, the candidate entity, and each of the first-degree relationships; Candidate entities whose probabilities satisfy set probability conditions are screened as target entities linked to the question sentence.
13. The method according to claim 12, characterized in that The determining, based on the question sentence, the candidate entity, and each of the first-degree relationships, a probability of the candidate entity being a target entity includes: The question sentence, the candidate entity, and each of the first-degree relationships are concatenated and input into a pre-trained entity linking model to obtain a probability of the candidate entity being a target entity output by the model; The entity linking model is trained by using entities to which the training questions are linked in the knowledge graph as positive samples and entities to which the training questions cannot be linked in the knowledge graph as negative samples.
14. A question-answering device based on knowledge graph, characterized in that: include: The candidate entity determination unit is used to determine the candidate entity in the knowledge graph pointed to by the question sentence; An entity linking unit, configured to select a target entity linked to the question sentence from among the candidate entities; a multi-hop path search unit, configured to search for a set of multi-hop paths in the knowledge graph using the target entity as a starting point and in a hop-by-hop path search manner, wherein, in each hop path search process, the current multi-hop path is combined with each one-hop path of the answer entity of the current multi-hop path to obtain a plurality of combined paths, and the combined path whose similarity to the question sentence satisfies a set condition is selected as the multi-hop path for the next moment; A constraint path acquisition unit is configured to intersect the answer entities of each pair of multi-hop paths in the multi-hop path set; obtain the union of each pair of multi-hop paths whose intersection is not empty as the constraint path, calculate the similarity between each constraint path and the question sentence, select the top-K2 constraint paths with the highest similarity, and add them to the constraint path set; The answer entity selection unit is used to calculate the similarity between each path in the multi-hop path set and the constraint path set and the question sentence, and select the answer entity of the path with the highest similarity as the final answer.
15. A question-answering device based on knowledge graph, characterized in that: include: memory and processor; The memory is used to store programs; The processor is used to execute the program to implement each step of the knowledge graph-based question-answering method as described in any one of claims 1 to 13.
16. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, each step of the question-answering method based on a knowledge graph as described in any one of claims 1 to 13 is implemented.
Citation Information
Patent Citations
Mongolian multi-hop question and answer method based on three-channel cognitive map and map attention network
CN113779220A
Knowledge graph embedding-based interpretable multi-hop question and answer method and system
CN114168719A