Knowledge question and answer method, device and equipment and storage medium
By generating and rewriting the target heuristic answers, decomposing them into sub-problem declaration pairs for searching, the problem that traditional search algorithms in LLM cannot understand the semantics of user problems is solved, and the accuracy and retrieval efficiency of question and answer are improved.
Patent Information
- Application Number
- CN202411317065.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-20
- Publication Date
- 2025-01-17
AI Technical Summary
The traditional search algorithm used in LLM based on RAG technology in the prior art cannot accurately understand the semantics of user problems, resulting in low accuracy of question-and-answer, poor retrieval granularity and accuracy, and lack of interactivity and efficiency.
By generating the target heuristic answer, we judge whether the question to be answered needs to be retrieved, and query and rewrite it, decompose it into several sub-question declaration pairs, and search the external knowledge base to obtain the final answer.
It improves the accuracy and retrieval efficiency of question-and-answer, solves the problems of insufficient semantic understanding and low accuracy of traditional search algorithms, and enhances the accuracy and interactivity of retrieval.
Smart Images

Figure CN119322827A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of large language models, and in particular to knowledge question answering methods, devices, equipment and storage media. Background Art
[0002] Nowadays, Large Language Models (LLMs) have made significant progress in various natural language processing tasks, including question answering (QA) tasks. However, due to the uniqueness of thousands of people and the real-time updating of knowledge, LLMs face serious hallucination problems and time misalignment problems, which affect the reliability of LLMs and hinder their wider practical applications.
[0003] At present, RAG (Retrieval-Augmented Generation) technology can be used to supplement knowledge learning of external knowledge bases to effectively solve this problem. RAG is a deep learning model that combines retrieval and generation. It retrieves relevant information and integrates it into the generation process to improve the relevance and accuracy of the generated content. Taking the open domain question answering task as an example, the retriever first searches the knowledge base for an input query (question) to find relevant document fragments, and then gives the retrieved document fragment content as a reference knowledge joint question to the LLM through the prompt engineering, so that the LLM receives the query and the document to generate the answer. However, due to the variety of user question expressions, and the query submitted by the user may be ambiguous, incomplete or not specific enough, the traditional retrieval algorithm currently used in the LLM based on RAG technology is usually unable to accurately understand the semantics of the query, resulting in low relevance of the retrieval results, and then leads to low accuracy of question answering. At the same time, the traditional retrieval algorithm has poor retrieval granularity and retrieval accuracy, lacks interactivity, and is inefficient.
[0004] The above contents are only used to assist in understanding the technical solution of the present invention and do not constitute an admission that the above contents are prior art. Summary of the invention
[0005] The main purpose of this application is to provide a knowledge question answering method, device, equipment and storage medium, aiming to solve the technical problems that the traditional retrieval algorithm used in the LLM based on RAG technology in the prior art is usually unable to accurately understand the semantics of the question, which leads to low accuracy of the question answering, and the traditional retrieval algorithm has poor retrieval granularity and accuracy, lacks interactivity and is inefficient.
[0006] To achieve the above objectives, the present application proposes a knowledge question answering method, wherein the method comprises:
[0007] Determining whether the question to be answered needs to be retrieved based on the question to be answered and the target heuristic answer corresponding to the question to be answered;
[0008] If necessary, performing query rewriting processing on the target heuristic answer to obtain a plurality of groups of sub-question statement pairs;
[0009] Determine the sub-problem to be queried from each sub-problem statement pair, and perform an external knowledge base search on the sub-problem to be queried to obtain target search information;
[0010] A final answer to the question to be answered is obtained based on the sub-question to be queried and the target retrieval information.
[0011] In one embodiment, the step of judging whether the question to be answered needs to be retrieved based on the question to be answered and the target heuristic answer corresponding to the question to be answered includes:
[0012] Generate a target heuristic answer corresponding to the question to be answered through a preset proxy model;
[0013] generating a question-answer pair based on the question to be answered and the target heuristic answer;
[0014] The question-answer pair is input into a search necessity judgment model to judge whether the question to be answered needs to be retrieved through the search necessity judgment model.
[0015] In one embodiment, before the step of generating a target heuristic answer corresponding to the question to be answered by using a preset proxy model, the method further includes:
[0016] Get a set of question samples from the question-answering dataset;
[0017] Inputting each question sample in the question sample set into the initial large language model to obtain a heuristic answer corresponding to each question sample;
[0018] Constructing a discriminant data set based on the question samples and the heuristic answers;
[0019] The initial large language model is trained using the judgment data set to obtain a retrieval necessity judgment model.
[0020] In one embodiment, before the step of constructing a discriminant data set based on each of the question samples and the heuristic answers, the method further includes:
[0021] Obtaining the standard answer corresponding to each question sample from the question sample set;
[0022] Determine a matching rate between the standard answer and the heuristic answer corresponding to each question sample;
[0023] Determine the discriminant label corresponding to each of the problem samples based on the matching rate and a preset matching rate threshold;
[0024] The step of constructing a discriminant data set based on the question samples and the heuristic answers comprises:
[0025] A discriminant data set is constructed based on the question samples, the heuristic answers and the discriminant labels.
[0026] In one embodiment, the step of determining the matching rate between the standard answer and the heuristic answer corresponding to each question sample includes:
[0027] Constructing a first answer set and a second answer set based on the standard answer and the heuristic answers corresponding to each of the question samples;
[0028] determining a sub-answer set between the first answer set and the second answer set;
[0029] Get the number of elements in the first answer set;
[0030] A matching rate between the standard answer and the heuristic answer corresponding to each question sample is determined based on the sub-answer set and the number of elements.
[0031] In one embodiment, before the step of generating a target heuristic answer corresponding to the question to be answered by using a preset proxy model, the method further includes:
[0032] The heuristic answer is decomposed through the initial question rewriting model to obtain a number of sub-questions and statements corresponding to each sub-question;
[0033] Generate a query rewriting result based on the sub-questions and the statement by the initial question rewriting model;
[0034] Training the initial question rewriting model based on the query rewriting result to obtain a preset question rewriting model;
[0035] The step of performing query rewriting processing on the target heuristic answer to obtain a plurality of groups of sub-question statement pairs includes:
[0036] The target heuristic answer is query rewritten using the preset question rewriting model to obtain several groups of sub-question statement pairs.
[0037] In one embodiment, the step of determining the sub-problem to be queried from each sub-problem statement pair includes:
[0038] Performing a search necessity judgment on the target sub-problem in each sub-problem statement by using the search necessity judgment model;
[0039] Determine the target discrimination label corresponding to the target sub-problem according to the judgment result;
[0040] All target sub-problems whose target discrimination labels are unknown labels are determined as sub-problems to be queried.
[0041] In addition, to achieve the above purpose, the present application also proposes a knowledge question answering device, the device comprising:
[0042] A retrieval judgment module, used to judge whether the question to be answered needs to be retrieved based on the question to be answered and the target heuristic answer corresponding to the question to be answered;
[0043] A query rewriting module, configured to perform query rewriting processing on the target heuristic answer if necessary, to obtain a plurality of groups of sub-question statement pairs;
[0044] A knowledge base retrieval module is used to determine the sub-problem to be queried from each sub-problem statement pair, and perform an external knowledge base search on the sub-problem to be queried to obtain target retrieval information;
[0045] The answer acquisition module is used to acquire the final answer to the question to be answered based on the sub-question to be queried and the target retrieval information.
[0046] In addition, to achieve the above-mentioned purpose, the present application also proposes a knowledge question and answer device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, and the computer program is configured to implement the steps of the knowledge question and answer method described above.
[0047] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the knowledge question and answer method described above are implemented.
[0048] The present application provides a knowledge question answering method, which discloses judging whether the question to be answered needs to be retrieved based on the question to be answered and the target heuristic answer corresponding to the question to be answered; if necessary, performing query rewriting processing on the target heuristic answer to obtain several groups of sub-question statement pairs; determining the sub-questions to be queried from each sub-question statement pair, and performing external knowledge base retrieval on the sub-questions to be queried to obtain target retrieval information; obtaining the final answer to the question to be answered based on the sub-questions to be queried and the target retrieval information; compared with the prior art, due to the various expressions of user questions and the possibility that the queries submitted by users are ambiguous, incomplete or not specific enough, Traditional retrieval algorithms are usually unable to accurately understand the semantics of the query, resulting in low relevance of the retrieval results. The present invention performs query rewriting processing on the corresponding target heuristic answer when the question to be answered needs to be retrieved, obtains a sub-question statement pair, and obtains the answer to the question to be answered based on the sub-question to be queried in the sub-question statement pair and its retrieval information, thereby solving the technical problems that the traditional retrieval algorithm used in the LLM based on RAG technology in the prior art is usually unable to accurately understand the semantics of the question, which in turn results in low accuracy of question and answer, as well as the coarse granularity and poor retrieval accuracy of the traditional retrieval algorithm, and lacks interactivity and low efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0050] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0051] Figure 1 A flowchart of the first embodiment of the knowledge question answering method of this application is provided;
[0052] Figure 2 This is a schematic diagram of the framework of the knowledge question answering method of this application;
[0053] Figure 3 This is a schematic diagram of the overall process of the knowledge question answering method of this application;
[0054] Figure 4 A flowchart diagram of the second embodiment of the knowledge question answering method of this application;
[0055] Figure 5 A diagram showing fine-tuning data of the judgment model provided in Example 2 of the knowledge question answering method of this application;
[0056] Figure 6 A flowchart diagram of the third embodiment of the knowledge question answering method of this application;
[0057] Figure 7 A diagram showing fine-tuning data of the question rewriting model provided in Example 3 of the knowledge question answering method of this application;
[0058] Figure 8 This is a schematic diagram of the module structure of the knowledge question answering device according to an embodiment of the present application;
[0059] Fig. 9 Schematic diagram of the device structure of the hardware operating environment involved in the knowledge question and answer method in the embodiment of the present application.
[0060] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0061] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0062] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0063] The main solution of the embodiment of the present application is: based on the question to be answered and the target heuristic answer corresponding to the question to be answered, determine whether the question to be answered needs to be retrieved; if necessary, perform query rewriting processing on the target heuristic answer to obtain several groups of sub-question statement pairs; determine the sub-questions to be queried from each sub-question statement pair, and perform an external knowledge base search on the sub-questions to be queried to obtain target retrieval information; based on the sub-questions to be queried and the target retrieval information, obtain the final answer to the question to be answered.
[0064] In the prior art, due to the variety of expressions of user questions and the fact that the queries submitted by users may be ambiguous, incomplete or not specific enough, the traditional retrieval algorithms currently used in LLM based on RAG technology are usually unable to accurately understand the semantics of the query, resulting in low relevance of the retrieval results, and thus low accuracy of question and answer.
[0065] The present application provides a solution, which can perform query rewriting processing on the corresponding target heuristic answer when the question to be answered needs to be retrieved, obtain a sub-question statement pair, and obtain the answer to the question to be answered based on the sub-question to be queried in the sub-question statement pair and its retrieval information, thereby solving the technical problems in the prior art that the traditional retrieval algorithm used in the LLM based on RAG technology usually cannot accurately understand the semantics of the question, which leads to low accuracy of question and answer, and the traditional retrieval algorithm has coarse granularity and poor retrieval accuracy, lacks interactivity and is inefficient.
[0066] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, a knowledge question and answer device, etc. The following takes the knowledge question and answer device as an example (hereinafter referred to as the device) to illustrate this embodiment and the following embodiments.
[0067] Based on this, the present application embodiment provides a knowledge question answering method, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the knowledge question and answer method of this application.
[0068] In this embodiment, the knowledge question answering method includes steps S10 to S40:
[0069] Step S10: judging whether the question to be answered needs to be retrieved based on the question to be answered and the target heuristic answer corresponding to the question to be answered.
[0070] It is understandable that the above-mentioned questions to be answered can be any questions that can be answered using a large language model, and this embodiment does not limit information such as the specific field of the questions to be answered.
[0071] It should be noted that the above target heuristic answer can be an answer quickly generated by a large language model without the guidance of explicit rules or algorithms.
[0072] It should be noted that RAG is a deep learning model that combines retrieval and generation. It retrieves relevant information and integrates it into the generation process to improve the relevance and accuracy of the generated content. By combining external knowledge (non-parametric knowledge) with internal knowledge (parametric knowledge), it can effectively alleviate the hallucination problem, especially for knowledge-intensive tasks. In this embodiment, in order to improve the efficiency and accuracy of retrieval, a retrieval necessity judgment model based on heuristic answers can be constructed, so that it can accurately identify which questions require further information retrieval.
[0073] In this embodiment, the target heuristic answer corresponding to the question to be answered can be used to determine whether the question to be answered is well answered, and then determine whether it is necessary to search for the question to be answered. Specifically, if the question to be answered can be well answered, then the question to be answered is not necessary to search; if the question to be answered cannot be well answered, then the question to be answered is considered to be necessary to search.
[0074] Furthermore, the step S10 includes:
[0075] Step S101: Generate a target heuristic answer corresponding to the question to be answered through a preset proxy model.
[0076] It should be noted that the above-mentioned preset proxy model can be a lightweight large language model, such as Qwen2-1.5B, or other large language models with the same or similar functions as Qwen2-1.5B, and this embodiment does not impose any limitation on this.
[0077] In a specific implementation, for a given user input question and an external knowledge base D (such as any knowledge base on the Internet), where: Y is the size of the knowledge base. Considering the need to get a quick response, in this embodiment, a small language model can be used as the above-mentioned preset proxy model to receive the input question to be answered and generate the answer:
[0078]
[0079] In the formula, is a heuristic answer, q is the input question, i.e., the question to be answered, and AM is the proxy model. In this embodiment, a lightweight large language model (such as Qwen2-1.5B) can be used as a proxy model to quickly obtain an answer response. In this embodiment, this heuristic answer has two functions: 1) determine whether the current user question q needs to be retrieved, where the logic of this judgment is implemented through the subsequent retrieval necessity judgment model; 2) In addition, it also provides information for Query (question) rewriting. The result of Query rewriting will help identify knowledge deficiencies in the large language model that need further retrieval.
[0080] Step S102: Generate a question-answer pair based on the question to be answered and the target heuristic answer.
[0081] It should be noted that the above question-answer pair may be a whole consisting of the question to be answered and its corresponding heuristic answer.
[0082] Step S103: inputting the question-answer pair into a search necessity judgment model to judge whether the question to be answered needs to be searched through the search necessity judgment model.
[0083] It should be understood that the above-mentioned search necessity judgment model can be a model for determining the degree of necessity of additional search for the query question. In this embodiment, the search necessity judgment model can be a large language model using a Transformer decoder-based architecture, and then a small parameter LLM of the same decoding framework can be used to judge the knowledge mastered by the larger LLMs and determine whether additional search is necessary.
[0084] In actual applications, for the questions to be answered input by the user, the device can first receive the questions to be answered through a proxy model and generate their corresponding target heuristic answers. Then, all the questions to be answered input by the user and their corresponding target heuristic answers can be combined into question-answer pairs, and these question-answer pairs can be used as input to the retrieval necessity judgment model. After receiving the question-answer pairs, the retrieval necessity judgment model can perform retrieval necessity judgment on the questions to be answered in these question-answer pairs to determine whether the questions to be answered need to be retrieved.
[0085] Step S20: If necessary, query rewriting is performed on the target heuristic answer to obtain several groups of sub-question statement pairs.
[0086] It should be noted that query rewriting of the target heuristic answer can be a process of decomposing the question to be answered and the target heuristic answer into multiple claims and sub-questions, wherein each claim generates a query that aims to capture different aspects of the question for accurate retrieval.
[0087] In this embodiment, the target heuristic answer can be decomposed into multiple statements (i.e., the target heuristic answer can be decomposed into multiple sub-answers), each of which can be associated with a sub-question. At this time, each statement and its associated sub-question can constitute the above-mentioned sub-question statement pair.
[0088] Step S30: determining the sub-problem to be queried from each sub-problem statement pair, and performing an external knowledge base search on the sub-problem to be queried to obtain target search information.
[0089] It should be noted that the above-mentioned sub-problem to be queried can be a sub-problem that needs further retrieval for the missing external knowledge in the sub-problem statement. In practical applications, after determining the necessity of retrieval, the next question is how to perform effective retrieval. In this embodiment, question q can be used as a query to retrieve relevant information from corpus D, but considering that the retrieved information may lose details and introduce redundant content, this solution can propose a query rewriting method based on heuristic answers and a query filtering method to improve these rewritten queries.
[0090] It should be understood that searching the external knowledge base for the query sub-question is to search the query question through the external knowledge base, so that relevant information of the query question can be retrieved from the external knowledge base, that is, the above-mentioned target retrieval information is obtained. In this embodiment, the device can pre-read, segment and vectorize the data in the external knowledge base and store it in the ES vector library. The retrieval process is to vectorize the input and perform knowledge base retrieval and recall the current input vector to obtain the top k document fragments with the highest relevance.
[0091] In practical applications, refer to Figure 2 , Figure 2 This is a schematic diagram of the framework of the knowledge question answering method of this application. Figure 2 As shown, for the input user query (i.e., the above-mentioned question to be answered), the retrieval necessity judgment model can first be used to determine whether the question to be answered needs to be retrieved. If no retrieval is required, the answer corresponding to the question to be answered is directly generated and output in response through the large language model; if retrieval is required, the target heuristic answer corresponding to the question to be answered is query rewritten to rewrite the target heuristic answer to obtain several sub-question statement pairs, and the sub-questions that need to be retrieved in these sub-question statement pairs are retrieved to obtain target retrieval information. Finally, the target retrieval information is combined with the original question of the user through the large language model to obtain and output the final answer.
[0092] Step S40: obtaining a final answer to the question to be answered based on the sub-question to be queried and the target retrieval information.
[0093] In this embodiment, after obtaining the target search information, the search content obtained by each sub-question to be searched can be used as a new question statement pair, and these contents can be combined as knowledge supplements, combined with the user's original question q (i.e., the question to be answered) as a prompt to call the large model to generate a response. Specifically, the device can prompt the retrieved relevant information and the original information (conversation context, system prompt words), and call the general LLMs to generate, and obtain the final answer to the question to be answered.
[0094] In the specific implementation, refer to Figure 3 , Figure 3 This is a schematic diagram of the overall process of the knowledge question answering method of this application. Figure 3As shown, step one of the scheme is heuristic answer generation, which can specifically receive user questions through the proxy model and generate heuristic answers corresponding to the questions, and then proceed to step two to perform retrieval necessity judgment. In this step, the question-answer pair consisting of the user question and its corresponding heuristic answer can be used as the input of the retrieval necessity judgment model. At this time, the retrieval necessity judgment model can perform retrieval necessity judgment on the question-answer pair. If the judgment result is known, it means that the user question can be well answered but does not need to be retrieved. At this time, the final answer to the user question can be directly generated through the LLM model; if the judgment result is unknown, it means that the user question cannot be well answered and it is necessary to retrieve it. At this time, step three can be entered. Step three is retrieval enhanced generation, which is a generation paradigm enhanced by combining external knowledge. In this step, the heuristic answer corresponding to the user's question can first be decomposed into multiple statements through the question rewriting model, where each statement is associated with a sub-question, and several groups of sub-question statement pairs are obtained based on the statement and its associated sub-question. Then, the retrieval necessity judgment model can be used to perform retrieval necessity judgment on each group of sub-question statement pairs to determine the sub-questions to be queried in these sub-question statement pairs, that is, the sub-questions that need to be retrieved. Finally, the retrieval engine can be called to perform an external knowledge base search on the sub-questions to be queried to obtain retrieval information, and combined with the original question, it can be input into the large language model to summarize and obtain the final answer to the user's question.
[0095] The present embodiment provides a knowledge question answering method, which discloses judging whether the question to be answered needs to be retrieved based on the question to be answered and the target heuristic answer corresponding to the question to be answered; if necessary, performing query rewriting processing on the target heuristic answer to obtain a plurality of groups of sub-question statement pairs; determining the sub-questions to be queried from each sub-question statement pair, and performing an external knowledge base search on the sub-questions to be queried to obtain target retrieval information; obtaining the final answer to the question to be answered based on the sub-questions to be queried and the target retrieval information; compared with the prior art, due to the various expressions of user questions and the possibility that the queries submitted by users are ambiguous, incomplete or not specific enough, Traditional retrieval algorithms are usually unable to accurately understand the semantics of the query, resulting in low relevance of the retrieval results. Since this embodiment performs query rewriting processing on the corresponding target heuristic answer when the question to be answered needs to be retrieved, a sub-question statement pair is obtained, and the answer to the question to be answered is obtained based on the sub-question to be queried in the sub-question statement pair and its retrieval information, thereby solving the technical problems that the traditional retrieval algorithm used in the LLM based on RAG technology in the prior art is usually unable to accurately understand the semantics of the question, which in turn results in low accuracy of question and answer, as well as the coarse granularity and poor retrieval accuracy of the traditional retrieval algorithm, and lack of interactivity and low efficiency.
[0096] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction, and will not be repeated in the following. Figure 4 , Figure 4 A flowchart diagram is provided for Example 2 of the knowledge question and answer method of this application.
[0097] In this embodiment, before step S101, the knowledge question answering method further includes steps S01 to S04:
[0098] Step S01: Obtain a set of question samples from the question-answering dataset.
[0099] It should be noted that the above-mentioned question-answering dataset can be a dataset consisting of several questions and their corresponding answers. Correspondingly, the above-mentioned question sample set can be a dataset consisting of samples with short answers in the question-answering dataset. In addition, this solution can also generalize the model to different datasets, such as long-form question-answering datasets.
[0100] Step S02: input each question sample in the question sample set into the initial large language model to obtain a heuristic answer corresponding to each question sample.
[0101] It should be noted that the initial large language model may be an untrained large language model. Generated by the agent model AM, at this time, the retrieval necessity judgment model can be constructed by the judgment model RJ obtained by supervised fine-tuning (such as using the lightweight general large model Qwen2-1.5B as the base model for supervised training (SFT)). In this embodiment, refer to Figure 5 , Figure 5 This is a diagram showing the fine-tuning data of the judgment model provided in Example 2 of the knowledge question answering method of this application. This solution uses the user input question q and the heuristic answer Process the data into Figure 5 The format shown is fine-tuned, where Figure 5 Each piece of data is in JSON format. Figure 5As shown in the figure, the fine-tuning data of the judgment model contains a key-value pair, the key is message, and the value is an array of conversation records, where each element in the array is a json data, containing two key-value pairs, namely role (role) and corresponding text (content); the first role is system, which is the system role in the large model. The content in content indicates the role of the large model and its corresponding task (parse the user input into a structured format and complete the task according to the heuristic answer). This part of the content is consistent for the same fine-tuning task; the second role is user, which is the user role, and the content contains questions and heuristic answers; the third role is assistant, and the content is the data label, that is, the real label (known / unknown) of the question and answer pair obtained by annotation. Different role information has different effects on parameter adjustment during the fine-tuning process.
[0102] Among them, the fine-tuning data of the judgment model contains three types of roles. The system role specifies the tasks and specifications that the LLM needs to perform, the user role passes in the user question and heuristic answer, and the assistant is the discriminant label of the question and answer pair. Unknown means unknown, that is, further question rewriting optimization is required, and known means clear, so no retrieval is required. After fine-tuning, the retrieval necessity judgment model can infer the discriminant label based on the given question and answer pair, and then decide whether the current user input question q needs to be further retrieved with help.
[0103] Step S03: construct a discriminant data set based on the question samples and the heuristic answers.
[0104] It should be understood that the above-mentioned discriminant dataset may be a dataset with reliable labels (ie, labels used to determine whether a question needs to be retrieved) used to train an initial large language model.
[0105] Furthermore, before step S03, the method further includes:
[0106] Step S031: Obtaining the standard answer corresponding to each question sample from the question sample set.
[0107] It can be understood that since the question sample set is a data set composed of samples with short answers in the question and answer data set, the answer corresponding to each question sample can be directly obtained from the question sample set, and the answer can be used as the standard answer to the question sample.
[0108] Step S032: Determine the matching rate between the standard answer and the heuristic answer corresponding to each question sample.
[0109] Specifically, the step S032 includes: constructing a first answer set and a second answer set based on the standard answer and the heuristic answers corresponding to the question samples respectively; determining a sub-answer set between the first answer set and the second answer set; obtaining the number of elements in the first answer set; and determining a matching rate between the standard answer and the heuristic answers corresponding to the question samples based on the sub-answer set and the number of elements.
[0110] It should be understood that the first answer set may be a set consisting of standard answers to the question samples; the second answer set may be a set consisting of heuristic answers to the question samples. Correspondingly, the sub-answer set may be a set consisting of elements belonging to both the first answer set and the second answer set.
[0111] In the specific implementation, the device can collect samples with short answers from the existing question-answering dataset and use the matching ratio between the heuristic answer and the standard answer as the metric. This metric can better match the evaluation and reflect the generation quality. It is worth noting that although this scheme uses short answers in label collection, the resulting model can be well generalized to different datasets, such as long question-answering datasets. Formally, for a question with multiple short answers Y = {y1, y2, …, y n},at this time The calculation formula for the matching rate r with Y is:
[0112]
[0113] In the formula, r represents the matching rate, n represents the number of problem samples, and |·| represents the size of the set, that is, the number of elements in the set. represents a set (i.e., the above sub-answer set), in which the element y satisfies two conditions at the same time: belongs to the second answer set It also belongs to the first answer set Y. The numerator of the original formula is the sum of the elements in Y that meet the conditions, and |Y| represents the size of the set Y.
[0114] Step S033: Determine the discriminant label corresponding to each of the problem samples based on the matching rate and a preset matching rate threshold.
[0115] It should be noted that the above-mentioned matching rate can be a value used to characterize the degree of matching between the heuristic answer and the standard answer of the question in the question sample set. The above-mentioned discriminant label can be a label used to determine whether it is necessary to retrieve the question sample. In practical applications, in order to achieve fine-tuning of the retrieval necessity judgment model, this scheme needs to collect a large number of training samples with reliable labels, so a labeling strategy can be proposed here, that is, comparing the model output generated by using retrieval and not using retrieval. In the research process, it can be found that this strategy is greatly affected by the ability of the retriever and the integrity of the corpus, resulting in the inability to accurately reflect the necessity of the model for search. In order to solve this problem, this scheme can use the quality of the heuristic answer generated in step 1, that is, if the quality of the heuristic answer is higher than the predefined threshold (that is, the above-mentioned preset matching rate threshold), it is inferred that the question can be well answered instead of having to be retrieved; otherwise, it is considered that retrieval is necessary. Among them, this embodiment can characterize the quality of the heuristic answer by the matching rate between the heuristic answer and the standard answer of the question. Generally speaking, the higher the matching rate between the heuristic answer and the standard answer of the question, the higher its quality. In addition, the preset matching rate threshold in this embodiment can be set according to actual conditions, and this embodiment does not limit this.
[0116] In this embodiment, an initial value may be set in advance for the preset matching rate threshold, and dynamically adjusted through iteration and result feedback to achieve the optimal boundary:
[0117]
[0118] In the formula, Known and Unknown are both discriminant labels, and a represents the preset matching rate threshold.
[0119] Accordingly, the step S03 includes: Step S03': constructing a discriminant data set based on the question samples, the heuristic answers and the discriminant labels.
[0120] Step S04: training the initial large language model using the judgment data set to obtain a retrieval necessity judgment model.
[0121] In a specific implementation, after determining the discriminant label corresponding to each question sample, it can be labeled according to the discriminant label, and a discriminant data set can be constructed based on the labeled question samples and their corresponding heuristic answers, so as to facilitate the subsequent training of the initial large language model through the discriminant data set and obtain a retrieval necessity judgment model when the training is completed.
[0122] In this embodiment, it is disclosed that a question sample set is obtained from a question and answer data set; each question sample in the question sample set is input into an initial large language model to obtain a heuristic answer corresponding to each question sample; a discriminant data set is constructed based on each question sample and the heuristic answer; the initial large language model is trained with the judgment data set to obtain a retrieval necessity judgment model, so that the quality of the retrieval necessity judgment model can be improved, so that questions that need further retrieval can be accurately screened out, thereby improving the efficiency and accuracy of the large language model in question and answering.
[0123] Based on the first embodiment and / or the second embodiment of the present application, in the third embodiment of the present application, the same or similar contents as those in the above embodiments can be referred to the above introduction, and will not be described in detail later. Figure 6 , Figure 6 A flowchart diagram of the third embodiment of the knowledge question answering method of this application is provided.
[0124] In this embodiment, before step S101, the knowledge question answering method further includes steps S001 to S003:
[0125] Step S001: Decompose the heuristic answer through the initial question rewriting model to obtain a number of sub-questions and statements corresponding to each sub-question.
[0126] It can be understood that the above-mentioned initial question rewriting model can be a large language model used to decompose the original question answer into multiple groups of sub-questions and sub-answers, such as: the large language model Qwen-110B, or other large language models with the same or similar functions as Qwen-110B. This embodiment does not limit this.
[0127] In practical applications, in order to train the initial question rewriting model, it is necessary to construct and collect quantitative annotated data as fine-tuning training samples. Therefore, this embodiment can use the large language model Qwen-110B as the generation model, and use the general capabilities brought by its ultra-large-scale parameter volume combined with the prompt word engineering to decompose the heuristic into multiple sub-question query and claim pairs. Each pair consists of a sub-question and a corresponding sub-answer claim, thereby collecting training data for the initial question rewriting model. Figure 7 , Figure 7 This is a diagram showing the fine-tuning data of the question rewriting model provided in Example 3 of the knowledge question answering method of this application.
[0128] in, Figure 7 and Figure 5The constructed training data format is consistent, and training is performed through the model base. It also includes 3 types of roles with the same functions, but the difference is that the content is different, that is, the assigned tasks are different, and the training results and purposes are also different. Here, the system role specifies the task of decomposing the given answer-question pair into multiple groups of sub-question-statement pairs, and the user role is given the data required for the task: heuristic answer-question pair, and the assistant role is the label data, that is, the expected response (sub-question-statement pair) given by the model, and output at the "Query RewriteQuput:" position. Therefore, this embodiment can input the heuristic answer corresponding to the question sample into the initial question rewriting model, so that the initial question rewriting model decomposes it and obtains multiple groups of sub-questions and statements corresponding to the sub-questions.
[0129] Step S002: Generate a query rewriting result based on the sub-questions and the statement through the initial question rewriting model.
[0130] It should be understood that after obtaining multiple sets of sub-questions and statements corresponding to the sub-questions, the initial question rewriting model can combine them to generate and output multiple sets of sub-question statement pairs, that is, to obtain the above query rewriting results. Decompose into multiple statements (sub-answers) {c1, c2, ..., c n}, where each statement can be associated with a sub-question In this embodiment, the question rewriting model QR can convert the user question q and its corresponding heuristic answer As input, and output all query rewriting results
[0131]
[0132] Step S003: training the initial question rewriting model based on the query rewriting result to obtain a preset question rewriting model.
[0133] It is understandable that after obtaining multiple groups of sub-problem statement pairs, these sub-problem statement pairs can be used as training data for the initial problem rewriting model to train it, and finally the above-mentioned preset problem rewriting model is obtained when the training is completed.
[0134] Accordingly, the step of performing query rewriting processing on the target heuristic answer to obtain a plurality of groups of sub-question statement pairs includes:
[0135] Step S201: performing query rewriting processing on the target heuristic answer through the preset question rewriting model to obtain several groups of sub-question statement pairs.
[0136] In this embodiment, when a question to be answered input by a user needs to be retrieved, the device can perform query rewriting processing on the target heuristic answer corresponding to the question to be answered through a trained preset question rewriting model, so as to decompose the question and the heuristic answer into several groups of sub-question statement pairs, so as to facilitate the subsequent retrieval of the sub-questions in the sub-question statement pairs and improve the accuracy of the retrieval.
[0137] Furthermore, the step of determining the sub-question to be queried from each sub-question statement pair includes:
[0138] The retrieval necessity judgment model is used to judge the retrieval necessity of the target subproblem in each subproblem statement; the target discrimination label corresponding to the target subproblem is determined according to the judgment result; and all target subproblems with the target discrimination label as an unknown label are determined as subproblems to be queried.
[0139] It should be understood that the above target sub-problem is the sub-problem in each sub-problem statement. Accordingly, the above target discrimination tag can be a tag used to determine whether it is necessary to search for the target sub-problem.
[0140] In practical applications, the preset question rewriting model can generate several rewritten sub-questions and statement pairs after query rewriting the target heuristic answer. For these sub-questions, the device can reuse the retrieval necessity judgment model RJ, where the input of the retrieval necessity judgment model is the sub-questions and corresponding statements obtained by rewriting, so that the retrieval necessity judgment model can be used to predict which of the rewritten sub-questions need to be retrieved, that is, which lack external knowledge, and these sub-questions that need to be retrieved are determined as the above-mentioned sub-questions to be queried, where the retrieval is only performed when the result is True, that is, all target sub-questions with target discrimination labels as unknown can be determined as sub-questions to be queried, thereby obtaining the set corresponding to the sub-questions to be queried that need to be retrieved:
[0141]
[0142] In this embodiment, it is disclosed that the heuristic answer is disassembled through the initial question rewriting model to obtain several sub-questions and statements corresponding to each sub-question; the query rewriting results are generated based on the sub-questions and statements through the initial question rewriting model; the initial question rewriting model is trained based on the query rewriting results to obtain a preset question rewriting model; the target heuristic answer is query rewritten through the preset question rewriting model to obtain several groups of sub-question statement pairs, so that the heuristic question can be disassembled through the preset question rewriting model to facilitate the subsequent retrieval necessity judgment, thereby improving the retrieval accuracy.
[0143] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the knowledge question and answer method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.
[0144] This application also provides a knowledge question answering device, please refer to Figure 8 , the knowledge question answering device comprises:
[0145] A retrieval judgment module 10 is used to judge whether the question to be answered needs to be retrieved based on the question to be answered and the target heuristic answer corresponding to the question to be answered;
[0146] A query rewriting module 20, configured to perform query rewriting processing on the target heuristic answer, if necessary, to obtain a plurality of groups of sub-question statement pairs;
[0147] A knowledge base search module 30 is used to determine the sub-problem to be queried from each sub-problem statement pair, and perform an external knowledge base search on the sub-problem to be queried to obtain target search information;
[0148] The answer acquisition module 40 is used to acquire the final answer to the question to be answered based on the sub-question to be queried and the target retrieval information.
[0149] The knowledge question and answer device provided by the present application adopts the knowledge question and answer method in the above-mentioned embodiment, which can solve the technical problems that the traditional retrieval algorithm used in the LLM based on RAG technology in the prior art usually cannot accurately understand the semantics of the question, which leads to low accuracy of the question and answer, as well as the coarse granularity and poor retrieval accuracy of the traditional retrieval algorithm, lack of interactivity and low efficiency. Compared with the prior art, the beneficial effects of the knowledge question and answer device provided by the present application are the same as the beneficial effects of the knowledge question and answer method provided by the above-mentioned embodiment, and the other technical features in the knowledge question and answer device are the same as the features disclosed in the above-mentioned embodiment method, which will not be repeated here.
[0150] The present application provides a knowledge question and answer device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the knowledge question and answer method in the above-mentioned embodiment one.
[0151] Reference below Fig. 9, which shows a schematic diagram of the structure of a knowledge question-answering device suitable for implementing the embodiment of the present application. The knowledge question-answering device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Fig. 9 The knowledge question and answer device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0152] like Fig. 9 As shown, the knowledge question answering device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the knowledge question answering device are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the knowledge question answering device to communicate wirelessly or wired with other devices to exchange data. Although the figure shows a knowledge question answering device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.
[0153] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0154] The knowledge question answering device provided by this application adopts the knowledge question answering method in the above embodiment, which can solve the technical problem of knowledge question answering. Compared with the prior art, the beneficial effects of the knowledge question answering device provided by this application are the same as the beneficial effects of the knowledge question answering method provided by the above embodiment, and the other technical features in the knowledge question answering device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0155] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0156] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0157] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, wherein the computer-readable program instructions are used to execute the knowledge question-answering method in the above-mentioned embodiment.
[0158] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0159] The computer-readable storage medium may be included in the knowledge question answering device; or may exist independently without being assembled into the knowledge question answering device.
[0160] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by the knowledge question and answer device, the knowledge question and answer device: determines whether the question to be answered needs to be retrieved based on the question to be answered and the target heuristic answer corresponding to the question to be answered; if necessary, performs query rewriting processing on the target heuristic answer to obtain several groups of sub-question statement pairs; determines the sub-question to be queried from each sub-question declaration pair, and performs an external knowledge base search on the sub-question to be queried to obtain target retrieval information; and obtains the final answer to the question to be answered based on the sub-question to be queried and the target retrieval information.
[0161] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0162] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0163] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0164] The readable storage medium provided by the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned knowledge question-answering method, and can solve the technical problems that the traditional retrieval algorithm used in the LLM based on RAG technology in the prior art usually cannot accurately understand the semantics of the question, which leads to low accuracy of the question and answer, as well as the coarse granularity and poor retrieval accuracy of the traditional retrieval algorithm, lack of interactivity, and low efficiency. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as the beneficial effects of the knowledge question-answering method provided by the above-mentioned embodiment, which will not be repeated here.
[0165] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A knowledge question answering method, characterized in that: The method includes: Determining whether the question to be answered needs to be retrieved based on the question to be answered and the target heuristic answer corresponding to the question to be answered; If necessary, performing query rewriting processing on the target heuristic answer to obtain a plurality of groups of sub-question statement pairs; Determine the sub-problem to be queried from each sub-problem statement pair, and perform an external knowledge base search on the sub-problem to be queried to obtain target search information; A final answer to the question to be answered is obtained based on the sub-question to be queried and the target retrieval information.
2. The method according to claim 1, characterized in that The step of judging whether the question to be answered needs to be retrieved based on the question to be answered and the target heuristic answer corresponding to the question to be answered includes: Generate a target heuristic answer corresponding to the question to be answered through a preset proxy model; generating a question-answer pair based on the question to be answered and the target heuristic answer; The question-answer pair is input into a search necessity judgment model to judge whether the question to be answered needs to be retrieved through the search necessity judgment model.
3. The method according to claim 2, characterized in that Before the step of generating a target heuristic answer corresponding to the question to be answered by using the preset proxy model, the method further includes: Get a set of question samples from the question-answering dataset; Inputting each question sample in the question sample set into the initial large language model to obtain a heuristic answer corresponding to each question sample; Constructing a discriminant data set based on the question samples and the heuristic answers; The initial large language model is trained using the judgment data set to obtain a retrieval necessity judgment model.
4. The method according to claim 3, characterized in that Before the step of constructing a discriminant data set based on each of the question samples and the heuristic answers, the method further includes: Obtaining the standard answer corresponding to each question sample from the question sample set; Determine a matching rate between the standard answer and the heuristic answer corresponding to each question sample; Determine the discriminant label corresponding to each of the problem samples based on the matching rate and a preset matching rate threshold; The step of constructing a discriminant data set based on the question samples and the heuristic answers comprises: A discriminant data set is constructed based on the question samples, the heuristic answers and the discriminant labels.
5. The method according to claim 4, characterized in that The step of determining the matching rate between the standard answer and the heuristic answer corresponding to each question sample includes: Constructing a first answer set and a second answer set based on the standard answer and the heuristic answers corresponding to each of the question samples; determining a sub-answer set between the first answer set and the second answer set; Get the number of elements in the first answer set; A matching rate between the standard answer and the heuristic answer corresponding to each question sample is determined based on the sub-answer set and the number of elements.
6. The method according to claim 3, characterized in that Before the step of generating a target heuristic answer corresponding to the question to be answered by using the preset proxy model, the method further includes: The heuristic answer is decomposed through the initial question rewriting model to obtain a number of sub-questions and statements corresponding to each sub-question; Generate a query rewriting result based on the sub-questions and the statement by the initial question rewriting model; Training the initial question rewriting model based on the query rewriting result to obtain a preset question rewriting model; The step of performing query rewriting processing on the target heuristic answer to obtain a plurality of groups of sub-question statement pairs includes: The target heuristic answer is query rewritten using the preset question rewriting model to obtain several groups of sub-question statement pairs.
7. The method according to any one of claims 2 to 6, characterized in that The step of determining the sub-problem to be queried from each sub-problem statement pair comprises: Performing a search necessity judgment on the target sub-problem in each sub-problem statement by using the search necessity judgment model; Determine the target discrimination label corresponding to the target sub-problem according to the judgment result; All target sub-problems whose target discrimination labels are unknown labels are determined as sub-problems to be queried.
8. A knowledge question-answering device, characterized in that: The device comprises: A retrieval judgment module, used to judge whether the question to be answered needs to be retrieved based on the question to be answered and the target heuristic answer corresponding to the question to be answered; A query rewriting module, configured to perform query rewriting processing on the target heuristic answer if necessary, to obtain a plurality of groups of sub-question statement pairs; A knowledge base retrieval module is used to determine the sub-problem to be queried from each sub-problem statement pair, and perform an external knowledge base search on the sub-problem to be queried to obtain target retrieval information; The answer acquisition module is used to acquire the final answer to the question to be answered based on the sub-question to be queried and the target retrieval information.
9. A knowledge question-answering device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the knowledge question answering method according to any one of claims 1 to 7.
10. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the knowledge question and answer method as described in any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Answer generation method and device, equipment, storage medium and product
CN119760101A
Government affair question and answer method and product based on knowledge enhancement large model
CN120256598A
Question answering method and device based on large model, electronic equipment and medium
CN120781968A
Model capability alignment method and device, electronic equipment and medium
CN121457603A