Knowledge question answering method, device, equipment and storage medium
By generating vector representations through the dual-tower model and combining it with a large language model, the problem of existing knowledge question-answering technologies being unable to understand user questions is solved, and more accurate knowledge question-answering responses are achieved.
Patent Information
- Application Number
- CN202310682070.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-08
- Publication Date
- 2025-10-03
- Estimated Expiration
- 2043-06-08
AI Technical Summary
Existing knowledge question-answering solutions cannot truly understand user questions through text similarity calculation, resulting in a high error rate in knowledge answers.
A dual-tower model is used to generate vector representations of user requests and knowledge passages. Combining coarse and fine ranking retrieval strategies, the knowledge passages with the highest similarity are recalled, and a large language model is used to understand user requests and generate response content.
The accuracy of knowledge questions and answers has been improved, the generated responses are more in line with user requests, and the occurrence of incorrect answers has been reduced.
Smart Images

Figure CN116680384B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of large language models, and more specifically, to a knowledge question answering method, apparatus, device, and storage medium. Background Art
[0002] Knowledge question answering refers to the process in which a user gives instructions to a machine and the machine gives corresponding responses to the instructions given by the user.
[0003] Most existing knowledge question-answering solutions are based on knowledge graphs or text similarity matching. The knowledge graph solution requires building a graph schema based on the business scenario in advance, and then organizing large amounts of structured or unstructured data into triples based on the schema. In the knowledge retrieval process, the entities in the user request are extracted, and the entity-related triples are matched in the knowledge graph, and then the entity attribute values in the triples are output as answers. The text similarity matching solution requires collecting various expressions and corresponding answers of the same type of questions in advance, and organizing the various expressions and answers into a knowledge base. In the knowledge retrieval process, the same or similar question expressions are searched in the knowledge base based on the user request, and the answers corresponding to the found question expressions are output.
[0004] Whether based on knowledge graphs or text similarity matching, these solutions all calculate text similarity based on user requests during knowledge retrieval and determine the final knowledge answer based on the similarity calculation results. This lack of understanding of the user's question leads to a high probability of incorrect answers. For example, for the following two user questions: "China's capital" and "US capital," the texts are highly similar, but the meanings expressed are completely different. Without a true understanding of the question, it is very easy to provide an incorrect knowledge answer. Summary of the Invention
[0005] In view of the above problems, this application proposes a knowledge question answering method, apparatus, device, and storage medium to address the problem that the existing method of determining knowledge answers based on text similarity calculations based on user requests does not truly understand the user's questions, resulting in the knowledge answers being prone to errors. The specific solution is as follows:
[0006] In a first aspect, a knowledge question answering method is provided, comprising:
[0007] Obtaining a user request and generating a target query vector representation corresponding to the user request;
[0008] Performing a similarity calculation based on the target query vector representation and the vector representations of each knowledge article in the pre-built knowledge base, and recalling the top K knowledge articles with the highest similarity, wherein each knowledge article in the knowledge base has a corresponding vector representation;
[0009] Cross-mix coding is performed on the vector representation of each knowledge chapter in the topK knowledge chapters and the target query vector representation, and similarity is calculated based on the cross-mix coding results, and the topN knowledge chapters with the highest similarity are recalled, N <K;
[0010] The pre-configured large language model is called to generate reply content based on the user request and the topN knowledge articles.
[0011] Preferably, the vector representation corresponding to each knowledge chapter in the knowledge base is obtained by encoding through the second encoder in the pre-trained dual-tower model, and the dual-tower model encodes the user input through the first encoder and encodes the knowledge chapter through the second encoder during the training process;
[0012] Generating a target query vector representation corresponding to the user request includes:
[0013] The first encoder in the dual-tower model is used to encode the user request to obtain a target query vector representation.
[0014] Preferably, cross-mixing encoding is performed on the vector representation of each knowledge passage in the topK knowledge passages and the target query vector representation, and similarity is calculated based on the cross-mixing encoding results, including:
[0015] The vector representation of each knowledge article in the topK knowledge articles is spliced with the target query vector representation into sentence pairs, and input into the pre-trained BERT model, and the similarity is calculated based on the cross-mixed encoding results of the sentence pairs output by the BERT model.
[0016] Preferably, a pre-configured large language model is called to generate reply content based on the user request and the topN knowledge passages, including:
[0017] Obtaining a preconfigured first prompt format template, the first prompt format template including a user request information slot and a knowledge information slot, the first prompt format template being used to instruct the large language model to reference the knowledge information in the knowledge information slot to generate a response that matches the user request in the user request information slot;
[0018] Fill the user request into the user request information slot, fill the topN knowledge chapters into the knowledge information slot, obtain the edited first prompt instruction prompt, and input the large language model to obtain the reply content output by the large language model.
[0019] Preferably, before generating the target vector representation corresponding to the user request, the method further comprises:
[0020] Generating a user query intent corresponding to the user request based on the large language model;
[0021] Then, generating a target query vector representation corresponding to the user request includes:
[0022] Generate a vector representation corresponding to the user query intent as the target query vector representation.
[0023] Preferably, calling a preconfigured large language model to generate reply content based on the user request and the topN knowledge passages includes:
[0024] The pre-configured large language model is called to generate reply content based on the user's query intent and the topN knowledge articles.
[0025] Preferably, calling a preconfigured large language model to generate reply content based on the user's query intent and the topN knowledge passages includes:
[0026] Obtain a preconfigured second prompt format template, the second prompt format template including a user query intent slot and a knowledge information slot, the second prompt format template being used to instruct the large language model to reference the knowledge information in the knowledge information slot to generate a response that matches the user query intent in the user query intent slot;
[0027] Fill the user query intention into the user query intention slot, fill the topN knowledge chapters into the knowledge information slot, obtain the edited second prompt instruction prompt, and input the large language model to obtain the reply content output by the large language model.
[0028] Preferably, generating a user query intention corresponding to the user request based on the large language model includes:
[0029] Obtaining a preconfigured third prompt format template, the third prompt format template including a user request information slot, the third prompt format template being used to instruct the large language model to understand the user's query intent based on the user request in the user request information slot;
[0030] The user request is filled into the user request information slot to obtain the edited third prompt instruction prompt, and is input into the large language model to obtain the user query intention output by the large language model.
[0031] In a second aspect, a knowledge question-answering device is provided, comprising:
[0032] A user request acquisition unit, configured to acquire a user request and generate a target query vector representation corresponding to the user request;
[0033] a coarse sorting retrieval unit, configured to perform similarity calculation based on the target query vector representation and the vector representations of each knowledge article in the pre-built knowledge base, and to recall the top K knowledge articles with the highest similarity, wherein each knowledge article in the knowledge base has a corresponding vector representation;
[0034] The refined sorting retrieval unit is used to perform cross-mixed coding on the vector representation of each knowledge chapter in the topK knowledge chapters and the target query vector representation, and calculate the similarity based on the cross-mixed coding, and recall the topN knowledge chapters with the highest similarity, N <K;
[0035] The first large language model calling unit is used to call a preconfigured large language model to generate reply content based on the user request and the topN knowledge chapters.
[0036] In a third aspect, a knowledge question answering device is provided, comprising: a memory and a processor;
[0037] The memory is used to store programs;
[0038] The processor is used to execute the program to implement the various steps of the knowledge question answering method as described above.
[0039] 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 knowledge question and answer method as described above are implemented.
[0040] With the help of the above technical solution, the present application solution does not directly output the topN knowledge passages recalled from the knowledge base as answers, but further combines them with user requests and inputs them into the large language model, making full use of the text understanding ability of the large language model to understand the user requests, and based on the recalled relevant knowledge passages, assists in generating reply content that matches the user request, so that the generated reply content is more accurate and better meets the user's request.
[0041] Furthermore, in the process of recalling knowledge chapters, this application adopts a combination of coarse sorting retrieval and fine sorting retrieval strategies, that is, first based on the target query vector representation corresponding to the user request, the similarity between the vector representation of each knowledge chapter in the knowledge base is calculated, and the topK knowledge chapters with the highest similarity are recalled, thereby ensuring the recall rate of relevant knowledge chapters (corresponding to the coarse sorting retrieval process). However, there may be some non-relevant or low-relevance knowledge chapters in the recalled topK knowledge chapters. For this reason, this application further cross-mixes the target query vector with the vector representation of each knowledge chapter, fully considering the contextual information between the user request and the knowledge chapter to recalculate the similarity, which can improve the accuracy of the similarity calculation, and then re-recall the topN knowledge chapters with the highest similarity (corresponding to the fine sorting retrieval process), thereby realizing the simplification of the recalled knowledge chapters. The large language model is more conducive to generating accurate reply content based on the knowledge chapters after the fine sorting retrieval. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] 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:
[0043] Figure 1 A flowchart of a knowledge question answering method provided in an embodiment of the present application;
[0044] Figure 2 A schematic diagram of a knowledge base is illustrated;
[0045] Figure 3 An example of a dual-tower model based on the BERT structure;
[0046] Figure 4 A schematic diagram illustrating a BERT model calculating the similarity between a user request and a knowledge passage;
[0047] Figure 5 An example of a schematic diagram of the implementation process of the knowledge problem method is given;
[0048] Figure 6 A schematic diagram of the structure of a knowledge question-answering device provided in an embodiment of the present application;
[0049] Figure 7 A schematic diagram of the structure of a knowledge question-answering device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0050] Before introducing this application plan, let me first explain the English terms involved in this article:
[0051] Prompt: Instructions. When communicating with an AI (such as a large language model), you need to send instructions to the AI. This can be a text description, such as "Please recommend me a pop song" when you are talking to the AI, or it can be a parameter description in a certain format, such as asking the AI to draw a picture according to a certain format, which requires describing the relevant drawing parameters.
[0052] Large language model (LLM): A large language model (LLM) is a generative deep neural network model based on the Transformer structure. It has strong semantic understanding and multi-round dialogue capabilities. Common large language models include GT4 and large language models developed by other companies.
[0053] 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.
[0054] This application provides a knowledge question answering solution that can be applied to various forms of knowledge question answering scenarios, such as: knowledge question answering scenarios in the financial field, knowledge question answering scenarios in the medical field, etc.
[0055] The present application solution can be implemented based on a terminal with data processing capabilities, which can be a mobile phone, computer, learning machine, intelligent robot, etc.
[0056] Next, combine Figure 1 The knowledge question answering method of the present application may include the following steps:
[0057] Step S100: Obtain a user request and generate a target query vector representation corresponding to the user request.
[0058] Specifically, during a knowledge question-and-answer conversation between a user and a machine, the user can enter a corresponding request in each round of conversation to describe the question raised by the user.
[0059] The user may input a request in various forms, such as voice, text, etc. In this step, the user request in various forms may be converted into text for processing in subsequent steps.
[0060] In this embodiment, a vector form can be used to calculate the similarity between the user request and the knowledge chapter, thereby realizing the recall of the knowledge chapter. To this end, in this step, a target query vector representation corresponding to the user request needs to be generated.
[0061] Step S110 : performing similarity calculation based on the target query vector representation and the vector representation of each knowledge chapter in the pre-built knowledge base, and recalling the top K knowledge chapters with the highest similarity.
[0062] Among them, this application is pre-configured with a knowledge base, which can contain relevant knowledge chapters expressed in a descriptive language that can be understood by natural language, and the number of knowledge chapters can be multiple. Figure 2 , which illustrates a schematic diagram of a knowledge base, where each row can be regarded as a knowledge chapter.
[0063] Each knowledge chapter in the knowledge base has a corresponding vector representation, and the vector representation of each knowledge chapter can be stored in the vector library.
[0064] Optionally, to facilitate vector similarity calculation, an index can be constructed for the vector representation of each knowledge article in the knowledge base and stored in the vector library. Subsequently, a vector retrieval algorithm can be used to retrieve the top K knowledge articles with the highest similarity from the vector library based on the target query vector representation. For example, a vector retrieval algorithm based on the HNSW (Hierarchical Navigable Small World) or other vector retrieval algorithms can be used.
[0065] Among them, the similarity between the knowledge chapter and the user request represents the contribution of the knowledge chapter in supporting the generation of matching reply content. The higher the similarity between the knowledge chapter and the user request, the greater its contribution to the generation of reply content, that is, the greater the probability that it contains relevant knowledge reply content.
[0066] This embodiment introduces an optional implementation method for generating corresponding vector representations for each knowledge chapter in the knowledge base and for user requests.
[0067] In this embodiment, a dual-tower model can be used to generate vector representations. Specifically, the dual-tower model includes two tower models, a left tower model and a right tower model, which are defined as a first encoder and a second encoder, respectively. The first encoder is used to encode user input requests, and the second encoder is used to encode knowledge passages.
[0068] During training, the Twin Tower model collects user requests and related knowledge passages to form positive pairs, and collects user requests and unrelated knowledge passages to form negative pairs. Positive or negative pairs are input into the Twin Tower model. The user request is fed into the first encoder to generate the corresponding vector representation of the user request, the User Embedding, and the knowledge passage is fed into the second encoder to generate the corresponding vector representation of the knowledge passage, the Item Embedding. The User Embedding and Item Embedding are then calculated using the inner product or cosine similarity to bring the embedding spaces of positive pairs closer together and the embedding spaces of negative pairs further apart. The standard cross-entropy loss can be used as the loss function.
[0069] Through training data, the first encoder and the second encoder are trained so that they can each accept user requests or knowledge passage inputs and independently output accurate vector representations.
[0070] Based on the trained dual-tower model, each knowledge article in the knowledge base can be input into the second encoder of the dual-tower model to obtain the vector representation corresponding to each knowledge article. The user request is input into the first encoder of the dual-tower model to obtain the output vector representation of the target query.
[0071] Reference Figure 3 As shown, it illustrates a dual-tower model based on the BERT structure, where the first encoder is as follows Figure 3 E shown on the left q , the second encoder is as follows Figure 3 E shown on the right p .
[0072] User request question is represented as: q (l) …q (k) . The knowledge passage is represented by: p (l) …p (f) .
[0073] The first encoder is used to encode the user request, and the output vector corresponding to the [CLS] position is taken to represent the target query vector representation E corresponding to the user request. q (q), use the second encoder to encode each knowledge chapter in the knowledge base, and take the output vector corresponding to the [CLS] position to represent the vector representation E corresponding to each knowledge chapter p (p).
[0074] Represent the target query vector E q (q) and the vector representation E of each knowledge chapter in the knowledge base p (p) Perform dot product similarity calculation and recall the K most similar knowledge chapters.
[0075] Step S120: Perform cross - hybrid encoding on the vector representations of each of the top - K knowledge passages and the target query vector representation, calculate the similarity based on the cross - hybrid encoding result, and recall the top - N knowledge passages with the highest similarity.
[0076] Specifically, the above steps S100 - S110 achieve a rough - ranking retrieval from the knowledge base based on the user request and recall the top - K knowledge passages with the highest similarity. This can ensure the recall rate, but may include some non - relevant or low - relevant knowledge passages. In this step, in order to further select the top - K knowledge passages to reduce the amount of knowledge information input to the large - language model, a fine - ranking retrieval process can be further performed on the top - K knowledge passages. Specifically, in this step, cross - hybrid encoding is performed on the target query vector and the vector representation of each knowledge passage, and the similarity between each knowledge passage and the user request is calculated based on the encoding result. Based on this, the context information between the user request and the knowledge passage can be fully considered, improving the accuracy of similarity calculation, and then re - recalling the top - N knowledge passages with the highest similarity, where N < K. This achieves the refinement of the recalled knowledge passages and ensures that relevant knowledge passages are not lost.
[0077] An optional way of cross - hybrid encoding can be implemented using a pre - trained BERT model. That is, the vector representation of each of the top - K knowledge passages is concatenated with the target query vector representation to form a sentence pair, and the sentence pair is input into the BERT model. The similarity is calculated based on the cross - hybrid encoding vector of the sentence pair output by the BERT model. Exemplarily, as shown in Figure 4 Shown, the target query vector representation "question" and each knowledge passage "passage" are concatenated, separated by [SEP], and the identifier [CLS] is added at the beginning of the concatenated sentence pair. Then, the sentence pair is input into the BERT model for hybrid cross - encoding, and the similarity between the input sentence pairs is calculated based on the encoding vector at the [CLS] position output by BERT.
[0078] Step S130: Invoke a pre - configured large - language model to generate a response content based on the user request and the top - N knowledge passages.
[0079] Specifically, the top - N knowledge passages screened in the previous step can only support generating a response content that matches the user request, and may also contain some interference information. If directly output as the response content, it may cause a situation of not matching or even being incorrect with the user request. Therefore, in this step, a large - language model is further is further invoked, and the user request and the top - N knowledge passages are input into the large - language model. The large - language model is used to understand the user's true query intention and give an accurate response content by referring to the knowledge information.
[0080] The knowledge question-answering method provided in the embodiment of the present application does not directly output the top N knowledge passages recalled from the knowledge base as answers, but further combines them with user requests and inputs them into a large language model, making full use of the text comprehension ability of the large language model to understand the user requests, and based on the recalled relevant knowledge passages, assists in generating reply content that matches the user request, so that the generated reply content is more accurate and better meets the user's request.
[0081] Furthermore, in the process of recalling knowledge chapters, this application adopts a combination of coarse sorting retrieval and fine sorting retrieval strategies, that is, first based on the target query vector representation corresponding to the user request, the similarity between the vector representation of each knowledge chapter in the knowledge base is calculated, and the topK knowledge chapters with the highest similarity are recalled, thereby ensuring the recall rate of relevant knowledge chapters (corresponding to the coarse sorting retrieval process). However, there may be some non-relevant or low-relevance knowledge chapters in the recalled topK knowledge chapters. For this reason, this application further cross-mixes the target query vector with the vector representation of each knowledge chapter, fully considering the contextual information between the user request and the knowledge chapter to recalculate the similarity, which can improve the accuracy of the similarity calculation, and then re-recall the topN knowledge chapters with the highest similarity (corresponding to the fine sorting retrieval process), thereby realizing the simplification of the recalled knowledge chapters. The large language model is more conducive to generating accurate reply content based on the knowledge chapters after the fine sorting retrieval.
[0082] In some embodiments of the present application, the process of calling a preconfigured large language model in step S130 and generating reply content based on the user request and the topN knowledge passages is described.
[0083] Specifically, the present application may pre-configure a first prompt format template, which includes a user request information slot and a knowledge information slot. The first prompt format template is used to instruct the large language model to refer to the knowledge information in the knowledge information slot to generate a response that matches the user request in the user request information slot. For example, the first prompt format template may be: "Please refer to the knowledge information to generate content that matches the user request. <User request information slot>, <Knowledge information slot>"
[0084] Furthermore, the user request is filled into the user request information slot, and the topN knowledge chapters are filled into the knowledge information slot to obtain the edited first prompt instruction prompt, which is then input into the large language model to obtain the reply content output by the large language model.
[0085] For example, assume that the user's request is "Which is longer, the Yangtze River or the Yellow River?"
[0086] Assume that the top N recalled knowledge passages include: "The Yellow River originates in the Yugur Basin at the northern foot of the Bayankala Mountains on the Qinghai-Tibet Plateau, flows from west to east through nine provinces (autonomous regions) including Qinghai, Sichuan, Gansu, Ningxia, Inner Mongolia, Shanxi, Shaanxi, Henan and Shandong, and finally flows into the Bohai Sea. The Yellow River is about 5,464 kilometers long, and its basin area is about 752,443 square kilometers according to People's Daily Online. The Ministry of Water Resources website "Yellow River Net" records it as: a total basin area of 795,000 square kilometers (including an inland area of 42,000 square kilometers). Yangtze River (the Changjiang River / the Yangtze The Yangtze River, part of the Pacific system, is China's largest river. Its main stream runs west to east across central China, with hundreds of tributaries flowing north and south. Its total length is 6,363 kilometers (according to the State Council). Other estimates include 6,397 kilometers (according to the Anhui Provincial People's Government), 6,403 kilometers (according to the Sanjiangyuan National Park website), and 6,380 kilometers (according to the journal "Talking about the Yangtze River"). A figure of over 6,300 kilometers is generally considered more appropriate.
[0087] After filling the user request information and the recalled knowledge chapter into the first prompt format template, the edited first prompt instruction prompt is:
[0088] "Please refer to the knowledge information to generate content that matches the user's request. <Which is longer, the Yangtze River or the Yellow River?>, <The Yellow River originates from... Generally, more than 6,300 kilometers is more appropriate.>" (Some knowledge information has been omitted here for the purpose of presentation. Please refer to the previous text for details).
[0089] After inputting the above prompt into the large language model, the large language model output is:
[0090] The Yangtze River and the Yellow River are two major rivers in China. The Yellow River is approximately 5,464 kilometers long and has a drainage basin area of approximately 752,443 square kilometers, while the Yangtze River is approximately 6,363 kilometers long and is China's largest river. Therefore, the Yangtze River is longer than the Yellow River.
[0091] In some embodiments of this application, given the varying expressive abilities of users, a user's input request may not always accurately, comprehensively, or accurately express the user's true query intent. Therefore, in this embodiment, a large language model can be used to understand the user request and summarize and output the user's query intent. The large language model outputs a more standardized, comprehensive, and accurate expression of the user's query intent than the original user request.
[0092] Therefore, the knowledge question answering method provided in this embodiment may further include the following steps before generating the target vector representation corresponding to the user request in step S100:
[0093] Generate user query intent corresponding to user requests based on the large language model.
[0094] On this basis, in step S100 above, the process of generating the target query vector representation corresponding to the user request may specifically include:
[0095] Generate a vector representation corresponding to the user query intent as the target query vector representation.
[0096] It is understandable that compared with the original user request, the expression of the user's query intent is more standardized, comprehensive, and accurate. Therefore, the target query vector representation generated corresponding to the user's query intent is more representative of the user's request. In this way, when performing similarity calculations and recalling knowledge chapters in the knowledge base, knowledge chapters that are more relevant to the user's request can be recalled.
[0097] Furthermore, based on the generation of the user query intent corresponding to the user request in the above embodiment, the process of calling the preconfigured large language model to generate the reply content based on the user request and the top N knowledge passages in step S130 may include:
[0098] The pre-configured large language model is called to generate reply content based on the user's query intent and the topN knowledge articles.
[0099] That is, when calling the large language model to generate a response, the original user request and the top N knowledge passages can be combined into a prompt and input into the large language model. Alternatively, the user query intent and the top N knowledge passages can be combined into a prompt and input into the large language model. Because this user query intent is more standardized, comprehensive, and accurate than the original user request, it is easier for the large language model to understand and, therefore, better supports the large language model in generating response content.
[0100] Taking the method of generating reply content based on the user query intent and the topN knowledge passages as an example, this application introduces a specific implementation method:
[0101] Specifically, the present application can pre-configure a second prompt format template, which includes a user query intent slot and a knowledge information slot. The second prompt format template is used to instruct the large language model to refer to the knowledge information in the knowledge information slot to generate a response that matches the user query intent in the user query intent slot. Exemplarily, the second prompt format template can be: "Please refer to the knowledge information to generate content that matches the user query intent. <User query intent slot>, <Knowledge information slot>"
[0102] Furthermore, the user query intent is filled into the user query intent slot, and the topN knowledge chapters are filled into the knowledge information slot to obtain the edited second prompt instruction prompt, which is then input into the large language model to obtain the reply content output by the large language model.
[0103] In some embodiments of the present application, an optional implementation method of generating a user query intention corresponding to a user request based on a large language model in the above steps is introduced.
[0104] Specifically, the present application may pre-configure a third prompt format template, which includes a user request information slot. The third prompt format template is used to instruct the large language model to understand the user's query intent based on the user request in the user request information slot. For example, the third prompt format template may be: "Please understand the query intent of the user request. <User request information slot>"
[0105] Furthermore, the user request is filled into the user request information slot to obtain the edited third prompt instruction prompt, and is input into the large language model to obtain the user query intention output by the large language model.
[0106] Let's take the aforementioned user request "Which is longer, the Yangtze River or the Yellow River?" as an example:
[0107] The edited third prompt is:
[0108] "Please understand the user's query intent. <Which is longer, the Yangtze River or the Yellow River?>"
[0109] After inputting the above prompt into the large language model, the large language model output is:
[0110] User query intention: Compare the scene and the length of the Yellow River, and ask which one is longer.
[0111] On this basis, the user's query intent can be vector-encoded to obtain a target query vector representation. Furthermore, when the large language model is called to generate a response, the user's query intent and the recalled knowledge passages can be combined into a prompt and fed into the large language model. This allows the large language model to generate a response based on the user's query intent and the referenced knowledge passages.
[0112] Reference Figure 5 , which illustrates an optional implementation process of a knowledge question answering method, which may specifically include:
[0113] A knowledge base storing knowledge chapters is pre-organized. Based on the double-tower model, each piece of knowledge in the knowledge base is vector-encoded and stored in the vector library.
[0114] For user query requests, we can directly perform vector encoding based on the dual-tower model to obtain the target query vector representation. Alternatively, we can use a large language model to identify the user's query intent, and then use the dual-tower model to perform vector encoding on the user's query intent to obtain the target query vector representation.
[0115] According to the target query vector representation obtained by encoding, a rough search is performed from the vector library to obtain the topK knowledge chapters with the highest vector similarity.
[0116] Cross-coding-based precise ranking retrieval involves cross-coding the top K knowledge articles with the target query vector representation, calculating the similarity between each knowledge article and the user request, and recalling the top N knowledge articles with the highest similarity.
[0117] The top N knowledge passages and user query intent are fed into the large language model through a specified prompt. Through the large language model's understanding and summarizing capabilities, the response content output by the large language model is obtained.
[0118] The knowledge question and answer device provided in an embodiment of the present application is described below. The knowledge question and answer device described below and the knowledge question and answer method described above can be referenced to each other.
[0119] See also Figure 6 , Figure 6 This is a schematic diagram of the structure of a knowledge question-answering device disclosed in an embodiment of the present application.
[0120] like Figure 6 As shown, the device may include:
[0121] A user request acquisition unit 11 is configured to acquire a user request and generate a target query vector representation corresponding to the user request;
[0122] A coarse sorting and retrieval unit 12 is configured to perform similarity calculation based on the target query vector representation and the vector representations of each knowledge article in the pre-built knowledge base, and recall the top K knowledge articles with the highest similarity, wherein each knowledge article in the knowledge base has a corresponding vector representation;
[0123] The refined sorting retrieval unit 13 is used to perform cross-mixed coding on the vector representation of each knowledge chapter in the topK knowledge chapters and the target query vector representation, and calculate the similarity based on the cross-mixed coding, and recall the topN knowledge chapters with the highest similarity, N <K;
[0124] The first large language model calling unit 14 is configured to call a pre-configured large language model and generate reply content based on the user request and the topN knowledge passages.
[0125] Optionally, the vector representation corresponding to each knowledge passage in the knowledge base is obtained by encoding using the second encoder in a pre-trained dual-tower model. During the training process, the dual-tower model encodes user input using the first encoder and encodes the knowledge passage using the second encoder. Based on this, the process of the user request acquisition unit generating the target query vector representation corresponding to the user request may include:
[0126] The first encoder in the dual-tower model is used to encode the user request to obtain a target query vector representation.
[0127] Optionally, the process of the refined ranking retrieval unit performing cross-mixed coding on the vector representation of each of the topK knowledge passages and the target query vector representation, and calculating similarity based on the cross-mixed coding results, may include:
[0128] The vector representation of each knowledge article in the topK knowledge articles is spliced with the target query vector representation into sentence pairs, and input into the pre-trained BERT model, and the similarity is calculated based on the cross-mixed encoding results of the sentence pairs output by the BERT model.
[0129] Optionally, the process of the first large language model calling unit calling a preconfigured large language model to generate reply content based on the user request and the topN knowledge passages may include:
[0130] Obtaining a preconfigured first prompt format template, the first prompt format template including a user request information slot and a knowledge information slot, the first prompt format template being used to instruct the large language model to reference the knowledge information in the knowledge information slot to generate a response that matches the user request in the user request information slot;
[0131] Fill the user request into the user request information slot, fill the topN knowledge chapters into the knowledge information slot, obtain the edited first prompt instruction prompt, and input the large language model to obtain the reply content output by the large language model.
[0132] Optionally, the device of the present application may further include:
[0133] The second large language model calling unit is configured to generate a user query intent corresponding to the user request based on the large language model before the user request acquisition unit generates a target vector representation corresponding to the user request. Based on this, the process of the user request acquisition unit generating a target query vector representation corresponding to the user request may include:
[0134] Generate a vector representation corresponding to the user query intent as the target query vector representation.
[0135] Optionally, the process of the first large language model calling unit calling a preconfigured large language model to generate reply content based on the user request and the topN knowledge passages may include:
[0136] The pre-configured large language model is called to generate reply content based on the user's query intent and the topN knowledge articles.
[0137] Optionally, the process of the first large language model calling unit calling a preconfigured large language model to generate reply content based on the user query intent and the topN knowledge passages may include:
[0138] Obtain a preconfigured second prompt format template, the second prompt format template including a user query intent slot and a knowledge information slot, the second prompt format template being used to instruct the large language model to reference the knowledge information in the knowledge information slot to generate a response that matches the user query intent in the user query intent slot;
[0139] Fill the user query intention into the user query intention slot, fill the topN knowledge chapters into the knowledge information slot, obtain the edited second prompt instruction prompt, and input the large language model to obtain the reply content output by the large language model.
[0140] Optionally, the process of generating, by the second large language model calling unit, a user query intention corresponding to the user request based on the large language model may include:
[0141] Obtaining a preconfigured third prompt format template, the third prompt format template including a user request information slot, the third prompt format template being used to instruct the large language model to understand the user's query intent based on the user request in the user request information slot;
[0142] The user request is filled into the user request information slot to obtain the edited third prompt instruction prompt, and is input into the large language model to obtain the user query intention output by the large language model.
[0143] The knowledge question answering device provided in the embodiment of the present application can be applied to knowledge question answering devices, such as mobile phones, computers, learning machines, intelligent robots, etc. Optionally, Figure 7 The hardware structure diagram of the knowledge question answering device is shown. Figure 7 ,The hardware structure of the knowledge question and answer 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;
[0144] 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;
[0145] 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;
[0146] 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;
[0147] The memory stores a program, and the processor can call the program stored in the memory, wherein the program is used to:
[0148] Obtaining a user request and generating a target query vector representation corresponding to the user request;
[0149] Performing a similarity calculation based on the target query vector representation and the vector representations of each knowledge article in the pre-built knowledge base, and recalling the top K knowledge articles with the highest similarity, wherein each knowledge article in the knowledge base has a corresponding vector representation;
[0150] Cross-mix coding is performed on the vector representation of each knowledge chapter in the topK knowledge chapters and the target query vector representation, and similarity is calculated based on the cross-mix coding results, and the topN knowledge chapters with the highest similarity are recalled, N <K;
[0151] The pre-configured large language model is called to generate reply content based on the user request and the topN knowledge articles.
[0152] Optionally, the detailed functions and extended functions of the program may refer to the above description.
[0153] 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:
[0154] Obtaining a user request and generating a target query vector representation corresponding to the user request;
[0155] Performing a similarity calculation based on the target query vector representation and the vector representations of each knowledge article in the pre-built knowledge base, and recalling the top K knowledge articles with the highest similarity, wherein each knowledge article in the knowledge base has a corresponding vector representation;
[0156] Cross-mix coding is performed on the vector representation of each knowledge chapter in the topK knowledge chapters and the target query vector representation, and similarity is calculated based on the cross-mix coding results, and the topN knowledge chapters with the highest similarity are recalled, N <K;
[0157] The pre-configured large language model is called to generate reply content based on the user request and the topN knowledge articles.
[0158] Optionally, the detailed functions and extended functions of the program may refer to the above description.
[0159] 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.
[0160] 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.
[0161] 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 knowledge question answering method, characterized in that: include: Obtain a user request, understand the user request based on a large language model, generate a user query intent corresponding to the user request, and generate a vector representation corresponding to the user query intent as a target query vector representation corresponding to the user request; Performing a similarity calculation based on the target query vector representation and the vector representations of each knowledge article in the pre-built knowledge base, and recalling the top K knowledge articles with the highest similarity, wherein each knowledge article in the knowledge base has a corresponding vector representation; Cross-mix coding is performed on the vector representation of each knowledge chapter in the topK knowledge chapters and the target query vector representation, and similarity is calculated based on the cross-mix coding results, and the topN knowledge chapters with the highest similarity are recalled, N <K; Obtain a preconfigured second prompt format template, the second prompt format template including a user query intent slot and a knowledge information slot, the second prompt format template being used to instruct the large language model to reference the knowledge information in the knowledge information slot to generate a response that matches the user query intent in the user query intent slot; Fill the user query intention into the user query intention slot, fill the topN knowledge chapters into the knowledge information slot, obtain the edited second prompt instruction prompt, and input the large language model to obtain the reply content output by the large language model.
2. The method according to claim 1, characterized in that The vector representation corresponding to each knowledge chapter in the knowledge base is obtained by encoding through the second encoder in the pre-trained dual-tower model. During the training process, the dual-tower model encodes the user input through the first encoder and encodes the knowledge chapter through the second encoder; Generating a target query vector representation corresponding to the user request includes: The first encoder in the dual-tower model is used to encode the user request to obtain a target query vector representation.
3. The method according to claim 1, characterized in that Cross-mix coding is performed on the vector representation of each knowledge passage in the topK knowledge passages and the target query vector representation, and similarity is calculated based on the cross-mix coding results, including: The vector representation of each knowledge article in the topK knowledge articles is spliced with the target query vector representation into sentence pairs, and input into the pre-trained BERT model, and the similarity is calculated based on the cross-mixed encoding results of the sentence pairs output by the BERT model.
4. The method according to claim 1, wherein The pre-configured large language model is called to generate a response based on the user request and the top N knowledge articles, including: Obtaining a preconfigured first prompt format template, the first prompt format template including a user request information slot and a knowledge information slot, the first prompt format template being used to instruct the large language model to reference the knowledge information in the knowledge information slot to generate a response that matches the user request in the user request information slot; Fill the user request into the user request information slot, fill the topN knowledge chapters into the knowledge information slot, obtain the edited first prompt instruction prompt, and input the large language model to obtain the reply content output by the large language model.
5. The method according to claim 1, wherein Generating a user query intention corresponding to the user request based on the large language model includes: Obtaining a preconfigured third prompt format template, the third prompt format template including a user request information slot, the third prompt format template being used to instruct the large language model to understand the user's query intent based on the user request in the user request information slot; The user request is filled into the user request information slot to obtain the edited third prompt instruction prompt, and is input into the large language model to obtain the user query intention output by the large language model.
6. A knowledge question-answering device, characterized in that: include: A user request acquisition unit is configured to acquire a user request, understand the user request based on a large language model, generate a user query intent corresponding to the user request, and generate a vector representation corresponding to the user query intent as a target query vector representation corresponding to the user request; a coarse sorting retrieval unit, configured to perform similarity calculation based on the target query vector representation and the vector representations of each knowledge article in the pre-built knowledge base, and to recall the top K knowledge articles with the highest similarity, wherein each knowledge article in the knowledge base has a corresponding vector representation; The refined sorting retrieval unit is used to perform cross-mixed coding on the vector representation of each knowledge chapter in the topK knowledge chapters and the target query vector representation, and calculate the similarity based on the cross-mixed coding, and recall the topN knowledge chapters with the highest similarity, N <K; The first large language model calling unit is configured to obtain a preconfigured second prompt format template, wherein the second prompt format template includes a user query intent slot and a knowledge information slot, and the second prompt format template is configured to instruct the large language model to refer to the knowledge information in the knowledge information slot to generate a response that matches the user query intent in the user query intent slot; Fill the user query intention into the user query intention slot, fill the topN knowledge chapters into the knowledge information slot, obtain the edited second prompt instruction prompt, and input the large language model to obtain the reply content output by the large language model.
7. A knowledge question-answering device, characterized in that: include: memory and processor; The memory is used to store programs; The processor is configured to execute the program to implement each step of the knowledge question answering method according to any one of claims 1 to 5.
8. 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 knowledge question answering method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Question and answer model training method and device, equipment and storage medium
CN113761152A
Question and answer processing method and device, electronic equipment and computer readable medium
CN115114419A
Dialogue system off-line and on-line fusion application method and system
CN115795017A