Vector database-based question and answer reasoning method and device
By constructing a vector database and using the matching of subgraph vectors and enhanced query vectors, the problem of insufficient subgraph representation and question and answer text representation in the knowledge graph is solved, and the accuracy and performance of question and answer reasoning are improved.
Patent Information
- Application Number
- CN202411074787.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-06
- Publication Date
- 2024-10-25
AI Technical Summary
When existing technologies use knowledge graphs for question and answer reasoning, the expressive capabilities of subgraph representations and question and answer text representations in the knowledge graph are insufficient, resulting in a need to improve the accuracy of question and answer reasoning.
By sampling the subgraphs in the knowledge graph, generate subgraph vectors, and build a vector database, combine the graph encoder and text encoder to encode the subgraphs and texts, generate subgraph vectors, and then perform question and answer reasoning based on the vector database. Knowledge retrieval by enhancing the matching of query vectors and subgraph vectors.
It improves the accuracy of question-answer reasoning and the fine-grained knowledge retrieval, and improves the performance and result quality of question-answer reasoning.
Smart Images

Figure CN118839005A_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of the present specification relate to the field of knowledge graphs and subgraph retrieval technology, and in particular, to a method and device for question-answering reasoning based on a vector database. Background Art
[0002] With the rapid development of information technology, network data has shown explosive growth. These data are characterized by large scale, loose structure and obvious heterogeneity, which brings challenges to people's efficient use of data and acquisition of knowledge.
[0003] Common sense question answering, as a core challenge in the field of natural language understanding, requires machines to not only have a broad grasp of common sense knowledge in multiple fields, but also be able to perform complex reasoning based on this knowledge. Although many pre-trained language models have achieved impressive performance in this task, learning common sense knowledge from text corpora is still a difficult task, because common sense knowledge is intuitive to humans, but it often lacks direct and clear expressions in natural language, making it difficult to extract and utilize.
[0004] Therefore, we hope to have an improved solution that can effectively combine supplementary knowledge to achieve higher accuracy in question-answering reasoning. Summary of the invention
[0005] One or more embodiments of this specification describe a method and device for question-answering reasoning based on a vector database, which extracts subgraphs from a knowledge graph, converts the knowledge graph into multiple subgraph vectors, and constructs a vector database. Based on the vector database, the question-answering reasoning process is converted into subgraph retrieval, which can achieve finer-grained and more accurate knowledge retrieval and promote question-answering reasoning.
[0006] According to a first aspect, a method for question-answering reasoning based on a vector database is provided, wherein the vector database stores a plurality of subgraph vectors corresponding to a plurality of subgraphs sampled from a knowledge graph, and each subgraph vector is obtained by encoding a subgraph and a corresponding graph description text; the method comprises:
[0007] A target question-answer pair is obtained, wherein the target question-answer pair includes a target question and a first candidate answer.
[0008] In the knowledge graph, several relevant triples related to the target problem are determined.
[0009] An enhanced query text is generated, which includes the question-answer text of the target question-answer pair and the description texts corresponding to the several related triples.
[0010] The enhanced query text is input into a text encoder for encoding to obtain an enhanced query vector.
[0011] Based on the enhanced query vector, a number of similar subgraph vectors are recalled from the vector database.
[0012] A target score is determined according to the plurality of similar subgraph vectors and the enhanced query vector, where the target score reflects the rationality of the first candidate answer to the target question.
[0013] According to one embodiment, the determining of a number of related triples related to the target problem includes:
[0014] A number of keywords in the target question-answer pair are determined.
[0015] For any keyword, a set of semantic triples is extracted from the knowledge graph, which includes triples with the keyword as the head entity or the tail entity.
[0016] In the semantic triple set, triples semantically related to the target question are retrieved and classified into the several related triples.
[0017] According to an implementation of the above embodiment, retrieving triples semantically related to the target question from the set of semantic triples includes:
[0018] A text retrieval model is adopted to retrieve the several related triples from the semantic triple set based on the text vector corresponding to the target question.
[0019] According to one embodiment, any subgraph vector in the vector database is obtained by the following steps:
[0020] From the knowledge graph, obtain a target subgraph.
[0021] The target subgraph is encoded using a graph encoder to obtain a subgraph representation.
[0022] The graph description text corresponding to the target subgraph is encoded using the text encoder to obtain a text representation; wherein the graph encoder and the text encoder are aligned to the same representation space.
[0023] The subgraph representation and the text representation are combined as a subgraph vector corresponding to the target subgraph.
[0024] According to one embodiment, obtaining the target subgraph includes:
[0025] Taking any target entity in the knowledge graph as a starting point, a breadth-first search based on search rules is performed to obtain the target subgraph; the search rules include a pre-set search depth and search width.
[0026] According to one embodiment, the graph description text corresponding to the target subgraph is obtained by the following steps:
[0027] For any triple in the target subgraph, the natural language texts of the elements contained therein are concatenated to obtain the text corpus corresponding to the triple.
[0028] Several text corpora corresponding to several triples contained in the target subgraph are concatenated to obtain the graph description text.
[0029] According to one embodiment, the recalling of a plurality of similar subgraph vectors includes:
[0030] For the enhanced query vector, the cosine similarity is calculated respectively with each subgraph vector in the vector database.
[0031] According to the order of cosine similarity, the first K subgraph vectors similar to the enhanced query vector are determined.
[0032] According to one embodiment, determining the target score includes:
[0033] The several similar subgraph vectors and the enhanced query vector are input into the processing model together, and fusion encoding based on the attention mechanism is performed to obtain a fusion vector.
[0034] The fusion vector and the enhanced query vector are input into a first multi-layer perceptron to obtain a first score.
[0035] The target score is determined according to the first score.
[0036] According to an implementation of the above embodiment, determining the target score according to the first score includes:
[0037] The target question-answer pair is input into the text encoder for encoding to obtain a corresponding question-answer pair text vector.
[0038] The question-answer pair text vector is input into a second multi-layer perceptron to obtain a second score.
[0039] The target score is determined according to a weighted sum of the first score and the second score.
[0040] According to one embodiment, the first candidate answer is selected from a candidate answer set; the method further comprises:
[0041] Calculate the target score of each candidate answer in the candidate answer set for the target question.
[0042] According to the ranking of the target scores, the target answer corresponding to the target question is determined.
[0043] According to a second aspect, a device for question-answering reasoning based on a vector database is provided, wherein the vector database stores a plurality of subgraph vectors corresponding to a plurality of subgraphs sampled from a knowledge graph, each subgraph vector being obtained by encoding a subgraph and a corresponding graph description text; the device comprises:
[0044] The acquisition module is configured to acquire a target question-answer pair, wherein the target question-answer pair includes a target question and a first candidate answer.
[0045] A determination module is configured to determine, in the knowledge graph, a number of relevant triples related to the target problem.
[0046] A generation module is configured to generate an enhanced query text, which includes the question-answer text of the target question-answer pair and the description texts corresponding to the several related triples.
[0047] The encoding module is configured to input the enhanced query text into a text encoder for encoding to obtain an enhanced query vector.
[0048] The recall module is configured to recall a number of similar subgraph vectors from the vector database based on the enhanced query vector.
[0049] The scoring module is configured to determine a target score based on the plurality of similar subgraph vectors and the enhanced query vector, wherein the target score reflects the rationality of the first candidate answer to the target question.
[0050] According to a third aspect, a computer program product is provided, comprising a computer program / instruction, which, when executed by a processor, implements the steps of the method described in the first aspect.
[0051] According to a fourth aspect, a computing device is provided, comprising a memory and a processor, wherein an executable code is stored in the memory, and when the processor executes the executable code, the method described in the first aspect is implemented.
[0052] Using the method and device provided in the embodiments of this specification, on the one hand, subgraph sampling is performed on the knowledge graph, and subgraph representation vectors are obtained through feature extraction of the subgraphs to construct a vector database. On the other hand, by performing text semantic enhancement on the question-answer pairs and the related triples in the knowledge graph, an enhanced query vector with strong expressiveness is obtained. Then, by retrieving the subgraph representation vector that is most similar to the enhanced query vector, the answer that matches the question is assisted in being inferred. Furthermore, by selecting a graph encoder and a text encoder that are aligned in the representation space, the equivalence between the subgraph representation vector and the enhanced query vector is increased, thereby obtaining high-quality equivalent subgraph-text representation pairs, thereby improving the quality of the retrieval results.
[0053] Compared with the question-answering reasoning method in related solutions, the embodiments in this specification transform question-answering reasoning into an enhanced question-answering matching problem between text representation vectors and subgraph representation vectors, so that knowledge graphs can be retrieved in a more fine-grained manner, thereby improving the accuracy of question-answering reasoning. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0055] Figure 1 A schematic diagram of a subgraph retrieval architecture provided according to an embodiment;
[0056] Figure 2 A schematic diagram of a prediction scoring architecture provided according to an embodiment;
[0057] Figure 3 A schematic diagram of steps for constructing a subgraph vector in a vector database according to an embodiment;
[0058] Figure 4A A schematic diagram of a sub-image sampling process provided according to an embodiment;
[0059] Figure 4B A schematic diagram of a sub-image sampling process provided according to an embodiment;
[0060] Figure 5 A schematic diagram for generating a triple sentence according to an embodiment;
[0061] Figure 6 A flow chart of a method for question-answering reasoning based on a vector database provided according to an embodiment;
[0062] Figure 7 A schematic diagram of prediction scoring provided according to an embodiment;
[0063] Figure 8 A device for question-answering reasoning based on a vector database is provided according to an embodiment of this specification. DETAILED DESCRIPTION
[0064] Recently, knowledge graphs, with their powerful semantic processing capabilities, have become a powerful tool for describing various knowledge entities, concepts and their relationships in the real world. With the development of artificial intelligence technology, knowledge graphs have been combined with various models and have begun to be applied to multiple fields such as intelligent search, common sense question answering, and personalized recommendations.
[0065] Compared with unstructured text corpora, structured data such as knowledge graphs are more efficient in expressing common sense knowledge. Introducing external common sense knowledge, especially external knowledge graphs, helps machines to more accurately understand the connection between questions and answers, and then infer answers that match the questions. Therefore, in related technologies, various external common sense knowledge graphs (e.g., ConceptNet) are considered to be applied to common sense question answering reasoning.
[0066] However, in the current methods of using knowledge graphs for question-answering reasoning, there is still a problem of insufficient representation capabilities for the representation of subgraphs in the knowledge graphs and the representation of question-answering texts, which means that the accuracy of the final question-answering reasoning needs to be further improved.
[0067] In order to improve the expressive power of extracting representations of knowledge graphs and question-answer texts, thereby achieving higher accuracy and stronger performance in question-answering reasoning, the inventors proposed a method and device for question-answering reasoning based on a vector database. According to the technical concept, in the preparatory stage, multiple subgraphs are sampled from the knowledge graph to form "knowledge points", and each subgraph and its graph description text are encoded and represented to obtain a subgraph vector. The subgraph vectors of each subgraph are stored in a vector database. The vector database can be used as a knowledge base for storing knowledge points. Question-answering reasoning is divided into two stages, the subgraph retrieval stage and the prediction and scoring stage. In the subgraph retrieval stage, the question-answer text is semantically enhanced based on the relevant triples in the knowledge graph, and the aforementioned vector database is retrieved based on the enhanced query vector corresponding to the enhanced text to obtain a similar subgraph vector. In this way, by smoothing the expression differences between the question-answer text and the subgraph vector representation, the quality of subgraph retrieval and query performance are improved. Optionally, in the prediction scoring stage, a weighted scoring method based on the attention mechanism is used to score the question-candidate answer based on similar subgraph vectors and enhanced query vectors to improve the accuracy of the scoring, thereby promoting question-answering reasoning to select the correct answer.
[0068] According to one embodiment, Figure 1 Provides a schematic diagram of the subgraph retrieval architecture. Figure 1 For the knowledge graph, two aspects are processed respectively.
[0069] On the one hand, a vector database is constructed. Specifically, a subgraph sampling operation is performed in the knowledge graph, and the obtained subgraphs and their graph description texts are input into the corresponding encoder, and the encoding process is performed to obtain several subgraph vectors corresponding to the subgraphs, which are stored in the vector database. It should be noted that the subgraph vector generation involved in the above description contains multiple related actions, which will not be expanded here. This step will be described in detail below.
[0070] On the other hand, when conducting common sense question-answering, a triple search operation is performed on the knowledge graph based on the question-answer pair to retrieve triples that are semantically related to the question-answer pair. This search operation may retrieve one or more related triples. The natural language text corresponding to the obtained related triples is concatenated with the question-answer pair text to obtain an enhanced query text. The enhanced query text is then input into the text encoder, and after encoding processing, an enhanced query vector is obtained.
[0071] It should be noted that the triple search operation involved in the above description includes multiple search-related actions, which will not be expanded here. This step will be described in detail below.
[0072] Through the above enhancement operations, the subgraph information in the knowledge graph is introduced, and the equivalence between the subgraph vector and the enhanced query vector is increased. It should be understood that the text encoder used in the above operations and the encoder used to generate the subgraph vector have been aligned to the same representation space.
[0073] After obtaining the enhanced query vector, several similar subgraph vectors can be retrieved and recalled from the vector database based on the enhanced query vector. In the subsequent prediction and scoring stage, the candidate answers in the question-answer pair will be scored based on the similar subgraph vectors and the enhanced query vector. The following will briefly describe the operations performed in the prediction and scoring stage.
[0074] According to one embodiment, Figure 2 Provides a schematic diagram of the prediction scoring architecture. Figure 2 In the prediction and scoring stage, the similar subgraph vectors and enhanced query vectors obtained in the previous stage will be input into the attention network for fusion encoding based on the attention mechanism to obtain a fusion vector. The fusion vector and the enhanced query vector are scored by a multi-layer perceptron, which can reflect the rationality of the candidate answers to the question in the question-answer pair.
[0075] During the entire question-answering reasoning process, by scoring the rationality of multiple candidate answers to the target question and sorting them according to their respective scores, the correct answer corresponding to the target question can be determined and the question-answering reasoning can be completed.
[0076] The above is a general description of a method for question-answering reasoning based on a vector database provided in an embodiment of this specification. The following will first introduce the construction process of a vector database in an embodiment in conjunction with the accompanying drawings, and then describe in detail a specific implementation method of a method for question-answering reasoning based on a vector database provided in an embodiment.
[0077] In one embodiment, the vector database stores subgraph vectors corresponding to a plurality of subgraphs sampled from the knowledge graph. Each subgraph vector is obtained by encoding the subgraph and the corresponding graph description text. Specifically, Figure 3 The steps of constructing any subgraph vector in the vector database are shown.
[0078] Step S301: Obtain a target subgraph from the knowledge graph.
[0079] According to an implementation of this embodiment, the target subgraph is obtained by performing subgraph sampling on the knowledge graph, and the subgraph sampling includes: taking any target entity in the knowledge graph as a starting point, performing a breadth-first search to obtain the target subgraph.
[0080] Since there are associations between nodes representing entities in the knowledge graph, if random sampling of nodes is used when sampling subgraphs, the directed edges between nodes will be lost, destroying the association information between nodes in the subgraph and affecting the quality of subsequent representation extraction. Therefore, it is necessary to design a certain sampling mechanism to preserve the complete association relationship between nodes in the subgraph as much as possible.
[0081] In this implementation, considering the topological structure between nodes in the knowledge graph and the graph neural network message passing mechanism that is relied on when performing graph encoding in subsequent steps, breadth-first search is used for subgraph sampling, which can fully retain the associated edges and corresponding associated nodes of the sampled nodes to the greatest extent. In other words, in this step, based on the breadth-first search method, subgraph sampling is performed with each entity node as the center in the knowledge graph.
[0082] For example, Figure 4A An exemplary sub-graph sampling process is shown in Figure 4A The exemplary knowledge graph given contains 11 nodes representing entities. Taking node 1 as the sampling starting point, a breadth-first search is performed in sequence according to the directed edges of the knowledge graph (the search process is indicated by circle numbers in the figure). The target subgraph can be sampled. According to the search sampling order, the nodes contained in the subgraph are: node 1, node 5, node 3, node 2, node 6, node 10, node 11, node 8, node 4, and node 9.
[0083] In one example, in order to avoid the sampled subgraph being too large, the breadth-first search performed on the knowledge graph is performed based on certain search rules, and the search rules include a pre-set search depth and search width. Figure 4B The sub-graph sampling process in this example is shown. Figure 4BThe given exemplary knowledge graph contains 11 nodes representing entities. Node 1 is used as the sampling starting point. According to the directed edges of the knowledge graph, a breadth-first search is performed in sequence. The search rule is set as follows: the search width is less than or equal to 2, and the search depth is less than or equal to 2. In the figure, the search process is marked with circle numbers, and the stop symbol is The search step marked does not meet the search rule and stops. For example, when searching from node 6 to node 4 in the figure, the search step cannot be executed because the search depth of the search step is 3, which exceeds the 2 set by the search rule. Thus, a subgraph with controllable scale can be obtained. The right side of the figure shows that the target subgraph obtained by sampling under the search rule in this example contains the following nodes in the search sampling order: node 1, node 5, node 3, node 6, and node 10.
[0084] It should be noted that in this implementation, only a specific node in the knowledge graph is used as the target node for subgraph sampling. In actual business scenarios, the subgraph sampling of the knowledge graph is not limited to a certain node. Any node of interest can be used as the target node to implement subgraph sampling, thereby obtaining multiple subgraphs. In addition, in the process of subgraph sampling, the setting of the search rule will determine the scale of the sampled subgraph. In the above implementation, the search rules cited are only used as examples to illustrate the subgraph sampling process and do not represent a limitation on the rules.
[0085] For the sake of clarity, a sampled subgraph (target subgraph) is taken as an example for explanation below.
[0086] For the target subgraph, in step S303: a graph encoder is used to encode the target subgraph to obtain a subgraph representation.
[0087] It should be understood that the graph encoder can be any graph neural network (GNN) that uses deep learning to directly learn graph structure data and generate representation vectors, such as graph convolution networks (GCN), graph attention networks (GAT), etc. The embodiments of this specification do not specifically limit the selection of the graph encoder.
[0088] Generally, when the target subgraph is input into the graph encoder, the graph encoder aggregates and represents each node according to the initial features of each node in the target subgraph and the graph structure information of the subgraph (node connection relationship, or triples), and obtains the subgraph representation of the entire subgraph by fusing the representations of each node.
[0089] On the other hand, in step S305, a text encoder is used to encode the graph description text corresponding to the target subgraph to obtain a text representation corresponding to the target subgraph.
[0090] In this step, the graph description text refers to the natural language text that describes the graph information of the target subgraph. In one embodiment, the graph description text can be obtained in the following manner: first, the natural language texts corresponding to the head node representing the entity, the connecting edge representing the relationship, and the tail node representing the entity contained in any triple in the target subgraph are spliced together to form a sentence corresponding to the triple. Then, the sentences converted from the several triples contained in the target subgraph are spliced together to form a paragraph. This paragraph is the graph description text corresponding to the target subgraph.
[0091] Specifically, there are many ways to generate sentences based on the nodes and edges in the triples. For example, in actual application scenarios, different sentence generation templates can be selected to splice the elements in the triples according to the category of the knowledge graph, the characteristics of the subgraph, or the semantics contained in the triples. Generally speaking, the generated sentence structure is a "subject + predicate + object + object complement" structure, and each part is taken from the elements in the triples, including but not limited to the type and name of the elements and the relationship between the elements. Figure 5 The triples contained in an exemplary subgraph are shown. Taking this graph as an example, the generation method of triple sentences is briefly introduced.
[0092] According to one implementation, Figure 5 Take the triple "node 1, edge 1, node 2" in the example. The sentence generation uses the relationship type of the edge in the triple as the predicate, the name of the tail node as the object, and the name of the head node as the object complement. This triple can generate the sentence "Use chopsticks to eat breakfast".
[0093] According to one implementation, Figure 5 Take the triple "node 1, edge 2, node 3" in the example. The sentence generation uses the name of the head node in the triple as the subject, the relationship type of the edge as the predicate, and the name of the tail node as the object. This triple can generate the sentence "eating breakfast can fill your stomach".
[0094] According to one implementation, Figure 5 Take the triple "node 1, edge 1, node 2" in the example. The sentence generation uses the relationship type of the edge in the triple as the predicate, the type of the tail node as the object, and the type of the head node as the object complement. This triple can generate the sentence "use cutlery to eat".
[0095] It should be understood that the several embodiments listed above are merely illustrative examples to illustrate the generation method of triple sentences. In actual scenarios, there are many different ways to generate triple sentences, which are not limited to this and are not listed one by one in the embodiments of this specification.
[0096] Thus, for each triple contained in the target subgraph, a sentence can be generated, and then the obtained sentences can be concatenated to form a paragraph. This paragraph is the graph description text corresponding to the target subgraph.
[0097] In other embodiments, the graph description text of the target subgraph may also be obtained in other ways. For example, in one case, the target subgraph may be input into a graph description tool (such as an existing large model) or provided to annotators to obtain the graph description text.
[0098] The above is a brief introduction to the method of obtaining the graph description text of the target subgraph. Next, the graph description text corresponding to the target subgraph is input into the text encoder, and the text representation corresponding to the target subgraph can be determined through the encoding process. The text representation is represented in the form of a vector.
[0099] In some embodiments, the text encoder is a pre-trained text encoder, which can fully utilize the training accumulation of historical text corpus for the text encoder, obtain a text representation with stronger expressive ability, and avoid training the text encoder from scratch.
[0100] According to one implementation, the graph encoder and the text encoder have been aligned to the same representation space. Aligning encoders of different modalities can discover and establish correspondences between different data modalities. The graph-structured knowledge graph and text data may contain complementary information. The graph encoder is good at processing structured data and exploring the associations and structures between data, while the text encoder is good at processing natural language text and exploring semantic expressions and the relative importance between word units. By aligning encoders of two different modalities, it is possible to prepare for the fusion of features under different modalities and realize cross-modal representation processing and understanding, thereby enhancing the expressiveness of the model and improving the explanatory power of the representation.
[0101] It should be noted that the above alignment of the graph encoder and the text encoder can be performed in a variety of ways. For example, rule-based entity alignment can be used to determine whether the multimodal representations of the entities generated by the multimodal encoder can be aligned with each other by determining whether one or more key attribute values of the entities in the knowledge graph meet the specified rule conditions (for example, manual annotation). Entity alignment based on representation learning can also be used. By using the entity attributes and structural information in the knowledge graph, the representations generated by encoders of different modalities of the knowledge graph are represented in the same Euclidean space, and the similarity between the multimodal representations is determined, so that the multimodal representations of positive samples have a higher similarity, and the multimodal representations of negative samples have a lower similarity, thereby achieving the purpose of aligning the multimodal encoders. In the embodiments of this specification, the alignment method of the encoder is not specifically limited.
[0102] S307: Combine the sub-graph representation with the text representation to obtain a sub-graph vector corresponding to the target sub-graph.
[0103] Based on the above determination of the subgraph representation and the text representation, a feature fusion operation is performed on them to obtain a subgraph vector corresponding to the target subgraph. The above fusion operation can be a vector combination operation such as concatenating the vectors of the subgraph representation and the text representation, vector dot multiplication or vector addition. In one example, the subgraph representation and the text representation are input into a multi-layer perceptron (MLP) for feature fusion, and the resulting vector is output as the subgraph vector of the target subgraph.
[0104] After completing the above operations on all subgraphs sampled from the knowledge graph, the obtained subgraph vectors are stored in the vector database, thus completing the construction of the vector database.
[0105] The following will describe in detail a specific implementation method of a question-answering reasoning method based on a vector database in conjunction with an embodiment.
[0106] After the vector database is constructed, question-answering reasoning can be performed based on the vector database. Figure 6 A flowchart of a method for question-answering reasoning based on a vector database according to an embodiment is shown. It can be understood that the method can be executed by any device, equipment, platform, or device cluster with computing and processing capabilities. Figure 6As shown, in this embodiment, a plurality of subgraph vectors corresponding to a plurality of subgraphs sampled from a knowledge graph are stored in a vector database, and each subgraph vector is obtained by encoding a subgraph and a corresponding graph description text. The method comprises at least the following steps: Step S601: Obtain a target question-answer pair, wherein the target question-answer pair comprises a target question and a first candidate answer. Step S603: In the knowledge graph, determine a number of related triples related to the target question. Step S605: Generate an enhanced query text, which comprises the question-answer text of the target question-answer pair and the description text corresponding to the several related triples. Step S607: Input the enhanced query text into a text encoder for encoding to obtain an enhanced query vector. Step S609: Based on the enhanced query vector, recall a number of similar subgraph vectors from the vector database. Step S611: Determine a target score based on the several similar subgraph vectors and the enhanced query vector, wherein the target score reflects the rationality of the first candidate answer to the target question.
[0107] The following will introduce each step of the above question-answering reasoning method in detail in conjunction with an embodiment.
[0108] Step S601, obtaining a target question-answer pair, wherein the target question-answer pair includes a target question and a first candidate answer.
[0109] Question-answering reasoning refers to the task of giving the correct answer through reasoning given a natural language question. For a typical question-answering reasoning process, multiple candidate answers are usually given in various ways for natural language questions. The reasoning engine semantically understands and parses the question, and then uses supplementary knowledge (such as knowledge graphs) to reason and select the correct answer from multiple candidate answers. The above process can be expressed as: given a question Q and a set of candidate answers A with N numbers, select the correct answer a from A that matches question Q. i ∈A.
[0110] In this step, question Q is compared with any candidate answer a in the candidate answer set A. i Make up a question and answer pair <Q,a i >, with any of the questions and answers<Q,a> As an example, the subsequent steps are introduced in detail. The target question-answer pair includes the target question Q and the first candidate answer a.
[0111] Based on the target question-answer pair, in step S603, several relevant triples related to the target question are determined in the knowledge graph.
[0112] In this step, several keywords in the target question-answer pair are first determined.
[0113] For example, for a target question-answer pair, 〈Q: What is the goal of an employee's work? , a: Complete the task〉, the keywords can be extracted: employee, work, goal, task.
[0114] Then, based on any keyword, a set of semantic triples is extracted from the knowledge graph, which includes triples with the keyword as the head entity or the tail entity.
[0115] Finally, in the set of semantic triples, triples semantically related to the target question Q contained in the target question-answer pair are retrieved and classified into the several related triples.
[0116] According to one implementation, the retrieval of triples semantically related to the target question Q described above is performed through a text retrieval model. Specifically, the target question Q is processed through a text encoder to obtain a corresponding text vector, which is input into the text retrieval model, and the triples included in the semantic triple set are input together to retrieve one or more related triples.
[0117] Next, based on the description texts corresponding to the respective related triples, an enhanced query vector generation operation is performed. In step S605 and step S607: an enhanced query text is generated, which includes the question and answer text of the target question and answer pair and the description texts corresponding to the several related triples. For example, the enhanced query text can be a direct concatenation of the question and answer text and the description texts of each related triple. Then, the enhanced query text is input into a text encoder for encoding to obtain an enhanced query vector.
[0118] It should be understood that the text encoder here is the same as the text encoder used in the sub-graph vector generation stage. The text encoder and the aforementioned graph encoder are aligned to the same representation space.
[0119] Therefore, based on the obtained enhanced query vector, in step S609, several similar subgraph vectors are recalled from the vector database.
[0120] The construction of the vector database and the generation method of sub-graph vectors therein have been explained in detail in the previous article and will not be repeated here.
[0121] In this step, various methods can be used to recall similar subgraph vectors based on the enhanced query vector.
[0122] In one example, for the enhanced query vector, the cosine similarity is calculated with each subgraph vector in the vector database. According to the order of the cosine similarity, the first K subgraph vectors similar to the enhanced query vector are determined. In other examples, the similar subgraph vectors to be recalled can also be determined by calculating the distance between the enhanced query vector and each subgraph vector. This embodiment of the specification does not expand on this example.
[0123] At this point, the subgraph retrieval phase has been completed and several similar subgraph vectors have been obtained.
[0124] Next, in step S611: a target score is determined according to the plurality of similar subgraph vectors and the enhanced query vector, wherein the target score reflects the rationality of the first candidate answer to the target question.
[0125] Figure 7 FIG. 1 is a schematic diagram of prediction scoring provided according to this embodiment. Figure 7 In the dotted box, in this step, the similar subgraph vectors and the enhanced query vector are input into the processing model (marked with attention network in the figure), and fusion encoding based on the attention mechanism is performed to obtain a fusion vector. Then, the fusion vector and the enhanced query vector are input into the multi-layer perceptron to obtain the target score (marked with the first score in the figure).
[0126] According to an implementation of this embodiment, considering that in some scenarios, the rationality of some question-answer pairs can be judged to a certain extent by their own texts, in this implementation, on the basis of the scores obtained based on the above steps, the question-answer pair texts are also sent to the multi-layer perceptron model for scoring. The two scores are weighted and summed to obtain the final score.
[0127] Specifically, see Figure 7 In this implementation, the target question-answer pair is encoded into a text encoder to obtain a corresponding question-answer pair text vector. The question-answer pair text vector is input into a multilayer perceptron (the multilayer perceptron is generally different from the multilayer perceptron that outputs the first score) to obtain a second score. The target score (indicated by the score in the figure) is determined by taking the weighted sum of the first score and the second score obtained according to the above steps. It can be understood that in the weighted summation, the weights of each factor can be set according to the application scenario and computing requirements, and are not specifically limited here.
[0128] Through the above operations, the target score of the target question and answer pair can be obtained, and the target score can reflect the rationality of the candidate answers included in the target question and answer pair for the target question.
[0129] Going back to the question-answering reasoning mentioned in step S601, for any question Q and candidate answer a i The question-answer pairs can all obtain the target scores corresponding to the question-answer pairs through the above steps. Therefore, in a specific embodiment, the target scores of the candidate answers in the candidate answer set for the target question are calculated respectively. According to the ranking of the target scores, the target answer corresponding to the target question is determined.
[0130] In one example, the candidate answer with the highest target score can be taken as the target answer. In other examples, the target scores can be sorted from high to low, and the top k candidate answers can be taken as the target answer. The method used to determine the target answer should be determined by the specific application scenario, and is not limited in any way in the embodiments of this specification.
[0131] The foregoing describes certain embodiments of the present specification, and other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims may be performed in an order different from that in the embodiments, and the desired results may still be achieved. In addition, the processes depicted in the accompanying drawings do not necessarily have to be performed in the specific order or sequential order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0132] Figure 8 A device for question-answering reasoning based on a vector database is provided according to an embodiment of this specification. The device 800 is deployed in a computing device, and the computing device can be implemented by any device, equipment, platform, device cluster, etc. with computing and processing capabilities. Figure 6 The method embodiment shown corresponds to the embodiment of the invention, wherein the vector database stores a plurality of subgraph vectors corresponding to a plurality of subgraphs sampled from the knowledge graph, and each subgraph vector is obtained by encoding the subgraph and the corresponding graph description text. The device 800 includes:
[0133] The acquisition module 801 is configured to acquire a target question-answer pair, wherein the target question-answer pair includes a target question and a first candidate answer.
[0134] The determination module 802 is configured to determine a number of relevant triples related to the target problem in the knowledge graph.
[0135] The generation module 803 is configured to generate an enhanced query text, which includes the question-answer text of the target question-answer pair and the description texts corresponding to the several related triples.
[0136] The encoding module 804 is configured to input the enhanced query text into a text encoder for encoding to obtain an enhanced query vector.
[0137] The recall module 805 is configured to recall a number of similar subgraph vectors from the vector database based on the enhanced query vector.
[0138] The scoring module 806 is configured to determine a target score based on the plurality of similar subgraph vectors and the enhanced query vector, wherein the target score reflects the rationality of the first candidate answer to the target question.
[0139] According to another embodiment of the present specification, there is also provided a computer program product, including a computer program / instruction, which implements the aforementioned combination when executed by a processor. Figure 6 The steps of the method.
[0140] According to another embodiment, the present specification further provides a computing device, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the aforementioned combination is implemented. Figure 6 The steps of the method.
[0141] Those skilled in the art should be aware that in one or more of the above examples, the functions described in the embodiments of the present invention may be implemented using hardware, software, firmware, or any combination thereof. When implemented using software, these functions may be stored in a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium.
[0142] The specific implementation methods described above further describe the purpose, technical solutions and beneficial effects of the embodiments of the present invention in detail. It should be understood that the above description is only a specific implementation method of the embodiments of the present invention and is not intended to limit the scope of protection of the present invention. Any modification, equivalent replacement, improvement, etc. made on the basis of the technical solution of the present invention shall be included in the scope of protection of the present invention.
Claims
1. A method for question-answering reasoning based on a vector database, wherein: The vector database stores a plurality of subgraph vectors corresponding to a plurality of subgraphs sampled from the knowledge graph, each subgraph vector being obtained by encoding a subgraph and a corresponding graph description text; the method comprises: Obtain a target question-answer pair, wherein the target question-answer pair includes a target question and a first candidate answer; In the knowledge graph, determining a number of relevant triples related to the target problem; Generate an enhanced query text, which includes the question-answer text of the target question-answer pair and description texts corresponding to the plurality of related triples; Inputting the enhanced query text into a text encoder for encoding to obtain an enhanced query vector; Based on the enhanced query vector, recalling a number of similar subgraph vectors from the vector database; A target score is determined according to the plurality of similar subgraph vectors and the enhanced query vector, where the target score reflects the rationality of the first candidate answer to the target question.
2. The method according to claim 1, wherein: The determining of a number of related triples related to the target problem includes: Determining a number of keywords in the target question-answer pair; For any keyword, a set of semantic triples is extracted from the knowledge graph, which includes triples with the keyword as the head entity or the tail entity; In the semantic triple set, triples semantically related to the target question are retrieved and classified into the several related triples.
3. The method according to claim 2, wherein: In the set of semantic triples, triples semantically related to the target question are retrieved, including: A text retrieval model is adopted to retrieve the several related triples from the semantic triple set based on the text vector corresponding to the target question.
4. The method according to claim 1, wherein: Any subgraph vector in the vector database is obtained by the following steps: From the knowledge graph, obtain a target subgraph; Encoding the target subgraph using a graph encoder to obtain a subgraph representation; Using the text encoder to encode the graph description text corresponding to the target subgraph to obtain a text representation; wherein the graph encoder and the text encoder are aligned to the same representation space; The subgraph representation and the text representation are combined as a subgraph vector corresponding to the target subgraph.
5. The method according to claim 4, wherein: The obtaining of the target subgraph comprises: Taking any target entity in the knowledge graph as a starting point, a breadth-first search based on search rules is performed to obtain the target subgraph; The search rules include a preset search depth and a preset search width.
6. The method according to claim 4, wherein: The graph description text corresponding to the target subgraph is obtained by the following steps: For any triple in the target subgraph, concatenate the natural language texts of the elements contained therein to obtain the text corpus corresponding to the triple; Several text corpora corresponding to several triples contained in the target subgraph are concatenated to obtain the graph description text.
7. The method according to claim 1, wherein: The recalling of a plurality of similar subgraph vectors includes: For the enhanced query vector, respectively calculate the cosine similarity with each subgraph vector in the vector database; According to the order of cosine similarity, the first K subgraph vectors similar to the enhanced query vector are determined.
8. The method according to claim 1, wherein: Determining the target score includes: Inputting the plurality of similar subgraph vectors and the enhanced query vector into a processing model, performing fusion encoding based on an attention mechanism, and obtaining a fusion vector; Inputting the fusion vector and the enhanced query vector into a first multi-layer perceptron to obtain a first score; The target score is determined according to the first score.
9. The method according to claim 8, wherein: Determining the target score according to the first score includes: Input the target question-answer pair into the text encoder for encoding to obtain a corresponding question-answer pair text vector; Inputting the question-answer pair text vector into a second multilayer perceptron to obtain a second score; The target score is determined according to a weighted sum of the first score and the second score.
10. The method according to claim 1, wherein: The first candidate answer is selected from a candidate answer set; the method further comprises: Calculate the target score of each candidate answer in the candidate answer set for the target question respectively; According to the ranking of the target scores, the target answer corresponding to the target question is determined.
11. A device for question-answering reasoning based on a vector database, wherein: The vector database stores a plurality of subgraph vectors corresponding to a plurality of subgraphs sampled from the knowledge graph, each subgraph vector being obtained by encoding a subgraph and a corresponding graph description text; the device comprises: An acquisition module is configured to acquire a target question-answer pair, wherein the target question-answer pair includes a target question and a first candidate answer; A determination module, configured to determine, in the knowledge graph, a number of relevant triples related to the target problem; A generation module configured to generate an enhanced query text, which includes the question-answer text of the target question-answer pair and description texts corresponding to the plurality of related triples; An encoding module configured to input the enhanced query text into a text encoder for encoding to obtain an enhanced query vector; A recall module, configured to recall a number of similar subgraph vectors from the vector database based on the enhanced query vector; The scoring module is configured to determine a target score based on the plurality of similar subgraph vectors and the enhanced query vector, wherein the target score reflects the rationality of the first candidate answer to the target question.
12. A computer program product, comprising a computer program / instruction, which, when executed by a processor, implements the steps of the method according to any one of claims 1 to 10.
13. A computing device comprising a memory and a processor, characterized in that: The memory stores executable codes, and when the processor executes the executable codes, the method according to any one of claims 1 to 10 is implemented.
Citation Information
Cited By
Literature information retrieval and analysis system and method based on AI intelligence
CN120492636A
An AI intelligence-based literature information retrieval analysis system and method
CN120492636B
