Contextual answer generation method and device, computer device, and storage medium
By combining retrieval and generative models and using preset evaluation metrics to select the optimal result to generate contextual answers, the problem of inaccurate and misleading information retrieval in the RAG model is solved, and more accurate contextual answer generation is achieved.
Patent Information
- Application Number
- CN202411463414.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-18
- Publication Date
- 2025-11-18
- Estimated Expiration
- 2044-10-18
AI Technical Summary
Existing RAG models produce inaccurate retrieval results during the retrieval phase, leading to inaccurate generated contextual answers and significant retrieval limitations, which can easily include misleading information.
The method combines retrieval and generative models, evaluates retrieval and generative results using preset evaluation metrics, selects the optimal result as the target result, and uses a preset generator to generate contextual answers.
It improves the accuracy and stability of search results, generates more accurate contextual answers, and solves the problems of search limitations and misleading information.
Smart Images

Figure CN119322838B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and more specifically to a method, apparatus, computer device, and storage medium for generating contextual answers. Background Technology
[0002] Retrieval-Augmented Generation (RAG) models combine language generation models and information retrieval techniques. When a RAG model needs to generate text or answer a question, it first retrieves relevant information from a large document collection and then uses this retrieved information to guide the generation of contextual answers, thereby improving the quality and accuracy of predictions. However, if the retrieval results in the RAG model's retrieval phase are inaccurate, the contextual answers generated in the subsequent generation phase will also be inaccurate. Currently, the retrieval phase generally uses a single retrieval method, performing semantic searches in the document collection based on retrieval requirements to obtain retrieval results, which cannot effectively improve the accuracy of retrieval results and is prone to including misleading information.
[0003] Therefore, the relevant technologies have significant limitations in retrieval, and the search results are prone to including misleading information, which affects the accuracy of generating contextual answers. Summary of the Invention
[0004] In view of this, the present invention provides a method, apparatus, computer device and storage medium for generating contextual answers, in order to solve the problems of large limitations in retrieval and the easy inclusion of misleading information in retrieval results, which affect the accuracy of generating contextual answers.
[0005] In a first aspect, the present invention provides a method for generating contextual answers, comprising:
[0006] Based on the question to be answered and the retrieval model, the retrieval results are obtained. The retrieval model is used to obtain the first text information corresponding to the question to be answered in the corpus and generate retrieval results containing the first text information.
[0007] Based on the question to be answered and the generative model, the generated result is obtained. The generative model is used to generate the second text information corresponding to the question to be answered and to generate the generated result containing the second text information.
[0008] Based on preset evaluation indicators, a first evaluation score and a second evaluation score are generated for the search results. If the first evaluation score is greater than the second evaluation score, the search results are taken as the target results; otherwise, the generated results are taken as the target results. The preset evaluation indicators are used to determine the probability that the search results and the generated results are the target results.
[0009] Input the target result into the preset generator to generate the context answer to the question to be answered. The preset generator is used to construct and generate the context answer based on the target result.
[0010] The context answer generation method provided in this embodiment incorporates a retrieval model and a generative model in the retrieval phase. The retrieval model retrieves the retrieval results corresponding to the question to be answered, while the generative model generates the corresponding results. The retrieval and generative results are evaluated using preset evaluation metrics to obtain the optimal target result, significantly improving the accuracy of the retrieval phase results. By utilizing a preset generator to generate context answers based on the target results, the generated context information exhibits high retrieval accuracy, and the generated results are more stable and accurate. This solves the problems of significant limitations in retrieval and the potential for misleading information in retrieval results, which negatively impacts the accuracy of the generated context answers.
[0011] In some optional implementations, search results are obtained based on the question to be answered and the search query model, including:
[0012] Input the question to be answered into the retrieval model to obtain the retrieval results;
[0013] The retrieval model is used to perform feature extraction on the question to be answered, obtain question features, match the question features with the question and answer texts in the corpus, obtain intermediate text information containing a first preset number of question and answer texts, and determine a second preset number of target question and answer texts from the first preset number of question and answer texts in the intermediate text information according to preset indicators. The target question and answer texts are used as the first text information to generate retrieval results containing the first text information, wherein the second preset number is less than or equal to the first preset number.
[0014] In this embodiment, the question to be answered is input into the retrieval model, and the retrieval model is used to determine the target question and answer text corresponding to the question to be answered from the corpus to obtain the retrieval results. The preset generator can generate contextual answers based on the retrieval results to improve the quality and accuracy of the contextual answers.
[0015] In some optional implementations, a first evaluation score and a second evaluation score for the search results are generated based on preset evaluation indicators, including:
[0016] Identify the relevant text information related to the question to be answered in the first text information of the search results, and determine the first quantity of relevant text information;
[0017] Obtain relevant question-and-answer texts related to the question to be answered from the corpus, and determine a second number of relevant question-and-answer texts;
[0018] The accuracy of the search results is obtained by dividing the first quantity by the second quantity.
[0019] The recall rate of the search results is obtained by dividing the first quantity by the second preset quantity.
[0020] Based on precision, recall, and a pre-defined formula, the harmonic mean of the search results is obtained, and the first evaluation score is obtained based on the harmonic mean.
[0021] The preset formula satisfies:
[0022]
[0023] Where F is the harmonic mean, α is the preset parameter, P is the precision, and R is the recall.
[0024] Determine the perplexity and entropy of the second text information in the generated results, and determine the average response length of the second text information;
[0025] Determine the total number of words, the third number of unary words, and the fourth number of bigary words in the second text information of the generated result;
[0026] Divide the third quantity by the total number of words to obtain the first proportion of unary words, and divide the fourth quantity by the total number of words to obtain the second proportion of binary words. Based on the first and second proportions, obtain the response diversity index of the generated results.
[0027] The second evaluation score is obtained based on perplexity, entropy, response diversity, average response length, and preset weights.
[0028] In this embodiment, an evaluation model is used to assess the search results and generated results based on preset evaluation indicators, resulting in a first evaluation score for the search results and a second evaluation score for the generated results. By using these evaluation scores, the optimal target result can be easily obtained, greatly improving the accuracy of the results in the search stage.
[0029] In some optional implementations, a first evaluation score and a second evaluation score for the search results are generated based on preset evaluation indicators, including:
[0030] The search results are input into the evaluation model to obtain the first evaluation score. The evaluation model is used to determine the probability that the search result is the target result according to the preset evaluation index. The evaluation model is obtained by training the initial evaluation model based on the first training sample. The initial evaluation model is constructed based on the preset evaluation index.
[0031] The generated result is input into the evaluation model to obtain a second evaluation score. The evaluation model is used to determine the probability that the generated result is the target result based on the preset evaluation index.
[0032] In this embodiment, an evaluation model is constructed using preset evaluation indicators. This model then evaluates the retrieval and generated results based on these indicators, outputting corresponding evaluation scores. These scores facilitate obtaining the optimal target result, significantly improving the accuracy of the retrieval process.
[0033] In some alternative implementations, the method further includes, before obtaining the generated result based on the question to be answered and the generative model:
[0034] An initial model is constructed based on a preset algorithm;
[0035] Obtain a second training sample, and train the initial model based on the second training sample to obtain a generative model.
[0036] In this embodiment, an initial model is constructed according to a preset algorithm; and the initial model is trained using a second training sample to obtain a generative model. The generative model automatically generates results that match the question to be answered, and these generated results can compensate for any information gaps or awkward expressions that may exist in the search results.
[0037] In some alternative implementations, the generated results are obtained based on the question to be answered and the generative model, including:
[0038] Input the question to be answered into the generative model to obtain the generated result;
[0039] Generative models consist of an encoder and a decoder. The encoder in a generative model is used to determine the semantic features of the question to be answered, and the decoder in a generative model is used to generate second text information based on the semantic features and generate a result containing the second text information.
[0040] In some alternative implementations, the method further includes:
[0041] Obtain new evaluation indicators, including: the accuracy of the first text information in the top third preset number of search results and / or the average accuracy of the search results, wherein the third preset number is less than or equal to the second preset number;
[0042] Update the preset evaluation indicators based on the newly added evaluation indicators;
[0043] The average accuracy meets the following requirements:
[0044]
[0045] Where MAP is the average accuracy, AP is the average precision of the first text information, and Q is the average precision of the first text information. R q represents the total number of the first text messages, and q is the sequence number.
[0046] In this embodiment, new evaluation indicators are added to the preset evaluation indicators to further refine the evaluation indicators of the search results and generated results, thereby improving the reliability of the evaluation, determining more accurate target results, and ultimately improving the accuracy of the constructed contextual answers.
[0047] Secondly, the present invention provides a context answer generation apparatus, comprising:
[0048] The retrieval results module is used to obtain retrieval results based on the question to be answered and the retrieval model. The retrieval model is used to obtain the first text information corresponding to the question to be answered in the corpus and generate retrieval results containing the first text information.
[0049] The result generation module is used to obtain the generation result based on the question to be answered and the generative model. The generative model is used to generate the second text information corresponding to the question to be answered and generate the generation result containing the second text information.
[0050] The evaluation module is used to generate a first evaluation score and a second evaluation score for the search results based on preset evaluation indicators. If the first evaluation score is greater than the second evaluation score, the search results are used as the target results; otherwise, the generated results are used as the target results. The preset evaluation indicators are used to determine the probability that the search results and the generated results are the target results.
[0051] The generation module is used to input the target result into the preset generator to generate the context answer corresponding to the question to be answered. The preset generator is used to construct and generate the context answer based on the target result.
[0052] Thirdly, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the computer instructions to perform the context answer generation method of the first aspect or any corresponding embodiment described above.
[0053] Fourthly, the present invention provides a computer-readable storage medium storing computer instructions for causing a computer to execute the context answer generation method of the first aspect or any corresponding embodiment thereof.
[0054] Fifthly, the present invention provides a computer program product, including computer instructions for causing a computer to execute the context answer generation method of the first aspect or any corresponding embodiment thereof. Attached Figure Description
[0055] To more clearly illustrate the technical solutions in the specific embodiments or related technologies of the present invention, the drawings used in the description of the specific embodiments or related technologies will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0056] Figure 1 This is a flowchart illustrating a context answer generation method according to an embodiment of the present invention;
[0057] Figure 2 This is a flowchart of an efficient retrieval and generation collaborative optimization method according to an embodiment of the present invention;
[0058] Figure 3 This is a structural block diagram of a context answer generation apparatus according to an embodiment of the present invention;
[0059] Figure 4 This is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. Detailed Implementation
[0060] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0061] Existing RAG models suffer from insufficient co-optimization between the retrieval and generation phases, limiting their overall performance. Particularly in the retrieval phase, inaccurate retrieval results lead to inaccurate contextual information generated in the subsequent generation phase. Current retrieval methods are generally singular, resulting in significant limitations and a tendency to generate misleading information. For example, the process might involve: obtaining the user's search query; generating multiple search results based on the query, including multiple textual messages and historical dialogues; calculating the target semantic distance between each search result and the query query; sorting each target semantic distance to obtain an array of search queries; and then processing each element in the array byte-wise to obtain the contextual information of the large language model. While this approach can reduce crashes in large language models, it does not effectively improve the accuracy of retrieval results.
[0062] Based on the above, this invention provides a context answer generation method. In the retrieval phase, a retrieval model and a generative model are designed. Evaluation metrics for both the retrieval and generative models are also designed to evaluate the results, facilitating the acquisition of the optimal result and significantly improving the accuracy of the retrieval results. Then, a generator constructs the context answer based on the optimal result. Furthermore, new evaluation metrics can be added to the retrieval model evaluation metrics to further refine their accuracy, improve the reliability of the evaluation results, and ultimately determine more precise retrieval results, thereby enhancing the accuracy of the constructed context answer. This solves the problem that existing RAG models use a single retrieval method in the retrieval phase, resulting in significant limitations and a tendency to generate misleading information. The goal is to achieve higher retrieval accuracy in the generated context information and more stable and accurate results.
[0063] According to an embodiment of the present invention, a context answer generation embodiment is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer device with data processing capabilities, such as a computer, server, etc., and although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0064] This embodiment provides a method for generating contextual answers. Figure 1 This is a flowchart of a context answer generation method according to an embodiment of the present invention, such as... Figure 1 As shown, the process includes the following steps:
[0065] Step S101: Based on the question to be answered and the retrieval model, obtain the retrieval results, wherein the retrieval model is used to obtain the first text information corresponding to the question to be answered in the corpus and generate retrieval results containing the first text information.
[0066] Specifically, in this embodiment, a dialogue corpus consisting of a large number of inter-answer pairs is first constructed. The corpus can be either open or closed domain.
[0067] The question to be answered is input into a retrieval model. The retrieval model extracts features from the input question and matches a small number of question-answer pairs in the corpus based on the extracted features as a candidate set. Finally, an appropriate metric is used to select the best response, i.e., the first text information, from the candidate set, and a retrieval result containing the first text information is generated. Examples of questions to be answered include: sentiment analysis questions, text classification questions, and language acceptability questions (whether the sentence is reasonable and grammatically correct).
[0068] Step S102: Based on the question to be answered and the generative model, a generation result is obtained, wherein the generative model is used to generate the second text information corresponding to the question to be answered and to generate a generation result containing the second text information.
[0069] Specifically, the BERT algorithm is used to construct the model, which is then trained on a large-scale corpus to obtain a generative model. During the large-scale corpus training process, the generative model learns the patterns and features of human dialogue, enabling it to generate responses that match the target audience, thus compensating for potential information gaps or awkward expressions in retrieval-based responses.
[0070] The question to be answered is input into the generative model, which generates second text information corresponding to the question to be answered and generates a result containing the second text information.
[0071] Step S103: Based on the preset evaluation index, generate a first evaluation score for the search result and a second evaluation score for the generated result. If the first evaluation score is greater than the second evaluation score, the search result is taken as the target result; otherwise, the generated result is taken as the target result. The preset evaluation index is used to determine the probability that the search result and the generated result are the target results.
[0072] Specifically, the pre-defined evaluation metrics include metrics for evaluating retrieval results and metrics for evaluating generated results. Metrics for evaluating retrieval results include, for example, precision (P), recall (R), and the harmonic mean of recall and precision (F). Metrics for evaluating generated results include, for example, perplexity, entropy, response diversity, and average response length. The evaluation metrics for retrieval models focus on recall and precision, while the evaluation metrics for generative models focus on the length of generated responses, and models that generate longer sentences are considered to be of higher quality. Based on this, in specific evaluations, the retrieval results from the retrieval model or the generated results from the generative model can be selected according to the characteristics of the required response content.
[0073] Based on preset evaluation indicators, the retrieval results of the retrieval model and the generated results of the generative model are evaluated to determine the similarity or quality between the retrieval results and the generated results and the best response. This determines the probability that the retrieval results and generated results are the target results, and generates a first evaluation score for the retrieval results and a second evaluation score for the generated results to reflect the evaluation results. The target result is determined based on the first and second evaluation scores. If the first evaluation score is greater than the second evaluation score, it indicates that the retrieval results of the retrieval model are better, and the retrieval results are used as the target results. Otherwise, it indicates that the generated results of the generative model are better, and the generated results are used as the target results.
[0074] Step S104: Input the target result into the preset generator to generate the context answer corresponding to the question to be answered. The preset generator is used to construct and generate the context answer based on the target result.
[0075] Specifically, a preset generator is a system or model that can automatically generate output based on a specific input (such as a target result). The target result is input into the preset generator, which then organizes all contextual information related to the question to be answered, and constructs and generates the contextual answer corresponding to the question.
[0076] The context answer generation method provided in this embodiment incorporates a retrieval model and a generative model in the retrieval phase. The retrieval model retrieves the retrieval results corresponding to the question to be answered, while the generative model generates the corresponding results. The retrieval and generative results are evaluated using preset evaluation metrics to obtain the optimal target result, significantly improving the accuracy of the retrieval phase results. By utilizing a preset generator to generate context answers based on the target results, the generated context information exhibits high retrieval accuracy, and the generated results are more stable and accurate. This solves the problems of significant limitations in retrieval and the potential for misleading information in retrieval results, which negatively impacts the accuracy of the generated context answers.
[0077] In some optional implementations, search results are obtained based on the question to be answered and the search query model, including:
[0078] Input the question to be answered into the retrieval model to obtain the retrieval results;
[0079] The retrieval model is used to perform feature extraction on the question to be answered, obtain question features, match the question features with the question and answer texts in the corpus, obtain intermediate text information containing a first preset number of question and answer texts, and determine a second preset number of target question and answer texts from the first preset number of question and answer texts in the intermediate text information according to preset indicators. The target question and answer texts are used as the first text information to generate retrieval results containing the first text information, wherein the second preset number is less than or equal to the first preset number.
[0080] Specifically, the question to be answered is input into the retrieval model, which extracts features from the input question. The corpus consists of a large amount of question-and-answer text, such as dialogue information. The retrieval model matches the question features with the question-and-answer text in the corpus, identifying successfully matched text information as intermediate text information. There is a first preset number of intermediate text information, representing a small number, such as 5, 8, or 10, with the specific value set according to actual needs. Alternatively, the retrieval model can be trained using deep learning technology (NLP, Natural Language Processing) to conduct question-and-answer dialogue training on the corpus.
[0081] Preset metrics include, for example, semantic similarity, relevance, fluency, and information richness. Based on these preset metrics, a second preset number of target question-and-answer texts with optimal preset metrics are determined from a first preset number of question-and-answer texts in the intermediate text information. These target question-and-answer texts are then used as the first text information. The second preset number is a value less than or equal to the first preset number.
[0082] In this embodiment, the question to be answered is input into the retrieval model, and the retrieval model is used to determine the target question and answer text corresponding to the question to be answered from the corpus to obtain the retrieval results. The preset generator can generate contextual answers based on the retrieval results to improve the quality and accuracy of the contextual answers.
[0083] In some optional implementations, a first evaluation score and a second evaluation score for the search results are generated based on preset evaluation indicators, including:
[0084] Identify the relevant text information related to the question to be answered in the first text information of the search results, and determine the first quantity of relevant text information;
[0085] Obtain relevant question-and-answer texts related to the question to be answered from the corpus, and determine a second number of relevant question-and-answer texts;
[0086] The accuracy of the search results is obtained by dividing the first quantity by the second quantity.
[0087] The recall rate of the search results is obtained by dividing the first quantity by the second preset quantity.
[0088] Based on precision, recall, and a pre-defined formula, the harmonic mean of the search results is obtained, and the first evaluation score is obtained based on the harmonic mean.
[0089] The preset formula satisfies:
[0090]
[0091] Where F is the harmonic mean, α is the preset parameter, P is the precision, and R is the recall.
[0092] Determine the perplexity and entropy of the second text information in the generated results, and determine the average response length of the second text information;
[0093] Determine the total number of words, the third number of unary words, and the fourth number of bigary words in the second text information of the generated result;
[0094] Divide the third quantity by the total number of words to obtain the first proportion of unary words, and divide the fourth quantity by the total number of words to obtain the second proportion of binary words. Based on the first and second proportions, obtain the response diversity index of the generated results.
[0095] The second evaluation score is obtained based on perplexity, entropy, response diversity, average response length, and preset weights.
[0096] Specifically, the system identifies relevant text information related to the question to be answered within the first set of text information in the search results, and determines the first quantity of such relevant text information. When identifying relevant text information, a threshold can be set; text information with a score higher than this threshold is considered relevant to the question to be answered. By counting the first quantity of relevant text information with a score higher than the threshold, the number of relevant responses retrieved by the system can be obtained. Similarly, question-and-answer texts in the corpus with scores higher than this threshold are identified as relevant question-and-answer texts related to the question to be answered, and a second quantity of such relevant question-and-answer texts is determined, which yields the total number of all relevant responses from the system.
[0097] Precision (P) is used to see what proportion of the responses given by the system are truly relevant. P = Relevant responses retrieved by the system / Total number of all relevant responses in the system. That is, P = First number / Second number. Therefore, by dividing the first number by the second number, we get the precision P of the search results.
[0098] As can be seen from the above embodiments, the search results contain a second preset number of first text information entries. Therefore, the total number of all responses retrieved by the system is equal to the second preset number. Recall (abbreviated R) is used to view the system's ability to find all relevant responses. R = number of relevant responses retrieved by the system / total number of responses retrieved by the system, i.e., R = first number / second preset number. Therefore, by dividing the first number by the second preset number, the recall rate R of the search results is obtained.
[0099] Input the accuracy rate P and the recall rate R into the above preset formula to calculate the harmonic mean F corresponding to the retrieval result. The F value is the harmonic mean of the recall rate and the accuracy rate, which is used to comprehensively evaluate the performance of the retrieval system. The higher the F value, the better the performance of the retrieval system in terms of both the accuracy rate and the recall rate. In addition, the recall rate examines the ability of the system to find all relevant responses, while the accuracy rate examines the ability of the system to find the correct responses. The two complement each other and comprehensively reflect the system performance from two different aspects. When a = 1, it means that the system achieves a better balance between precision and recall, that is, the F1 value, which is the harmonic mean of the recall rate and the accuracy rate, as shown in formula (1).
[0100]
[0101] Obtain the first evaluation score according to the harmonic mean. For example: directly use the harmonic mean as the first evaluation score, adjust the harmonic mean according to actual needs as the first evaluation score, use the ratio of the harmonic mean to the harmonic mean of the artificially generated standard result as the first evaluation score, etc.
[0102] In a language model, perplexity is usually used to measure the probability of a sentence appearing and is also often used in dialogue generation evaluation to evaluate the language quality of the generated response sentences. The basic idea is that the higher the quality of the generated response language, the smaller the perplexity, and the closer it is to normal human speech, the better the model. The disadvantage of the perplexity metric is that it cannot evaluate the relevance of the response to the previous context in the dialogue. Entropy can be used to measure the information content of the generated response. The average length is used to measure the dialogue generation effect, and it is considered that the model generating longer sentences has relatively higher quality.
[0103] Determine the perplexity and entropy of the second text information of the generated result, and determine the average response length of the second text information. The calculation steps of perplexity can include include include include: calculating the conditional probability. For each word (x_t) in the second text information, calculate its conditional probability (p(x_t|x_{<t})) given the prefix (x_{<t}). Take the logarithm of the conditional probability of each word to obtain the log probability. Calculate the average of the log probabilities of all words as the average log probability. The final perplexity is: exp(average log probability). The calculation steps of entropy can include: for each word in the second text information, calculate its conditional probability (p(x_n|x_{<n})) given the prefix (x_{<n}). For each word (x_n), calculate the entropy of its conditional probability distribution.
[0104] Unigrams are sets of single words or symbols. In language models, unigrams are typically used to count the frequency of individual words in text. Bigrams are combinations of two consecutive words or symbols. In language models, bigrams are typically used to capture the order relationships between words and to calculate the probability of word pairs. The second set of information used to determine the generated text includes the total number of words, the third set includes the number of unigrams, and the fourth set includes the number of bigrams.
[0105] Dividing the third quantity by the total number of words yields the first proportion of unigrams (Distinct-1), and dividing the fourth quantity by the total number of words yields the second proportion of bigrams (Distinct-2). Based on the first and second proportions, the response diversity index of the generated results is obtained. The response diversity indexes Distinct-1 & 2, addressing the problem of universal responses in dialogue systems, measure the diversity of responses by calculating the ratio of unigrams (the richness of vocabulary in the generated response) to bigrams (the influence of word order and phrases on response diversity).
[0106] The second evaluation score is obtained based on perplexity, entropy, response diversity index, average response length, and preset weights. For example, the preset weights for perplexity, entropy, response diversity index, and average response length are 0.2, 0.2, 0.3, and 0.3, respectively. These preset weights can be set according to actual needs, but the sum of the preset weights for each item must be 1. In determining the second evaluation score, the perplexity, entropy, response diversity index, and average response length of the user-generated standard result can be obtained first. The calculated perplexity, entropy, response diversity index, and average response length are then divided by the perplexity, entropy, response diversity index, and average response length of the standard result, respectively. Finally, the four results are multiplied by their corresponding preset weights, and the final result is used as the second evaluation score.
[0107] In this embodiment, an evaluation model is used to assess the search results and generated results based on preset evaluation indicators, resulting in a first evaluation score for the search results and a second evaluation score for the generated results. By using these evaluation scores, the optimal target result can be easily obtained, greatly improving the accuracy of the results in the search stage.
[0108] In some optional implementations, a first evaluation score and a second evaluation score for the search results are generated based on preset evaluation indicators, including:
[0109] The search results are input into the evaluation model to obtain the first evaluation score. The evaluation model is used to determine the probability that the search result is the target result according to the preset evaluation index. The evaluation model is obtained by training the initial evaluation model based on the first training sample. The initial evaluation model is constructed based on the preset evaluation index.
[0110] The generated result is input into the evaluation model to obtain a second evaluation score. The evaluation model is used to determine the probability that the generated result is the target result based on the preset evaluation index.
[0111] Specifically, in this embodiment, an initial evaluation model is constructed using a neural network based on the aforementioned preset evaluation metrics. The neural network, for example, is a recurrent neural network (RNN), which can be used for text quality evaluation. The initial evaluation model is trained using a first training sample, which includes: manually generated standard results and corresponding evaluation scores; and incorrect results and their corresponding evaluation scores. The steps for creating the evaluation model based on the preset evaluation metrics may include: collecting the first training sample; preprocessing the first training sample, including word segmentation, stop word removal, and conversion to lowercase; feature extraction, converting the text to numerical form, with each word represented by a vector. Common methods include using word embeddings, or using the RNN's own encoder to extract features; model construction, using one or more RNN layers to process the input word vector sequence, where the RNN can capture sequential information and contextual dependencies in the text; and the type of RNN, such as a standard RNN, LSTM (Long Short-Term Memory), or GRU (Gated Recurrent Unit). Finally, the model is trained using the labeled first training sample. The goal is to adjust the model parameters to minimize the difference between the predicted quality and the actual quality. Choose an appropriate loss function, such as mean squared error (MSE) or cross-entropy loss.
[0112] The search results and generated results are input into the evaluation model. The evaluation model evaluates the search results and generated results according to preset evaluation indicators, and outputs a first evaluation score for the search results and a second evaluation score for the generated results. The evaluation scores reflect the similarity or quality of the results with the best results.
[0113] In this embodiment, an evaluation model is constructed using preset evaluation indicators. This model then evaluates the retrieval and generated results based on these indicators, outputting corresponding evaluation scores. These scores facilitate obtaining the optimal target result, significantly improving the accuracy of the retrieval process.
[0114] In some alternative implementations, the method further includes, before obtaining the generated result based on the question to be answered and the generative model:
[0115] An initial model is constructed based on a preset algorithm;
[0116] Obtain a second training sample, and train the initial model based on the second training sample to obtain a generative model.
[0117] Specifically, the preset algorithm is, for example, the BERT algorithm, a deep learning technique based on the Transformer architecture. An initial model is built using the BERT algorithm. Secondary training samples are obtained, such as a large-scale corpus, including large-scale unlabeled text data such as encyclopedia entries, news articles, web pages, question-and-answer databases, and dialogues. The initial model is then trained on this large-scale corpus based on the secondary training samples, enabling the model to learn patterns and features of human dialogue. This allows the model to automatically generate results that match the question to be answered, compensating for potential information gaps or awkward expressions in retrieval-based responses.
[0118] Additionally, the steps for creating a generative model may include: data preparation, collecting a second training sample and preprocessing it, including word segmentation, stop word removal, and adding special markers (such as [CLS], [SEP]). A BERT architecture is built as the initial model using deep learning frameworks (such as TensorFlow, PyTorch), including components such as multi-layer Transformer encoders, self-attention mechanisms, and positional encoding. The initial model is pre-trained on the second training sample using Masked Language Modeling (MLM) and Next Sentence Prediction (NSP) tasks, adjusting model parameters through backpropagation to enable it to learn general language representations. The initial model is then fine-tuned for a specific NLP task (text generation) by adding task-specific output layers to the pre-trained BERT model, and then fine-tuning on a small-scale labeled dataset to optimize the model's adaptability to the specific task.
[0119] In this embodiment, an initial model is constructed according to a preset algorithm; and the initial model is trained using a second training sample to obtain a generative model. The generative model automatically generates results that match the question to be answered, and these generated results can compensate for any information gaps or awkward expressions that may exist in the search results.
[0120] In some alternative implementations, the generated results are obtained based on the question to be answered and the generative model, including:
[0121] Input the question to be answered into the generative model to obtain the generated result;
[0122] Generative models consist of an encoder and a decoder. The encoder in a generative model is used to determine the semantic features of the question to be answered, and the decoder in a generative model is used to generate second text information based on the semantic features and generate a result containing the second text information.
[0123] Specifically, the generative model in this embodiment includes an encoder and a decoder.
[0124] After the question to be answered is input into the generative model, the encoder of the generative model learns the semantic features of the question. Then, the decoder of the generative model generates second text information based on the semantic features and generates a result containing the second text information.
[0125] In some alternative implementations, the method further includes:
[0126] Obtain new evaluation indicators, including: the accuracy of the first text information in the top third preset number of search results and / or the average accuracy of the search results, wherein the third preset number is less than or equal to the second preset number;
[0127] Update the preset evaluation indicators based on the newly added evaluation indicators;
[0128] The average accuracy meets the following requirements:
[0129]
[0130] Where MAP is the average accuracy, AP is the average precision of the first text information, and Q is the average precision of the first text information. R q represents the total number of the first text messages, and q is the sequence number.
[0131] Specifically, as the size of the test set increases and the understanding of the test results deepens, this embodiment can add new evaluation indicators that can more accurately reflect the system performance to the preset evaluation indicators. The process includes: obtaining the new evaluation indicators and updating the preset evaluation indicators based on the new evaluation indicators.
[0132] New evaluation metrics may include: the accuracy of the first text information in the top three preset number of search results, the average accuracy of search results, and the accuracy of the top 10 responses in a single result.
[0133] The third preset quantity is a value W that is less than or equal to the second preset quantity. The accuracy of the first text information in the first three preset quantities of the search results represents how many of the first text information are relevant to the question to be answered, that is, the accuracy of the first W positions of the search results.
[0134] As can be seen from the formula for average precision above, calculating average precision requires calculating AP. The method for calculating AP is to directly perform numerical integration on the PR curve (precision-recall curve).
[0135] In this embodiment, new evaluation indicators are added to the preset evaluation indicators to further refine the evaluation indicators of the search results and generated results, thereby improving the reliability of the evaluation, determining more accurate target results, and ultimately improving the accuracy of the constructed contextual answers.
[0136] In some optional implementations, an efficient retrieval and generation collaborative optimization method is provided, which can solve the same technical problems and produce the same technical effects as steps S101 to S104, such as... Figure 2 As shown, the method includes: Step S1, constructing a retrieval model; Step S2, constructing a generative model; Step S3, constructing model evaluation metrics; Step S4, evaluating the retrieval and generative model algorithms; Step S5, constructing a generative context answer.
[0137] Specifically, retrieval-based and generative models are used in parallel to evaluate the response design algorithms of both models. If the retrieval-based response performs better, it is adopted as the target result; otherwise, a generative response is returned as the target result. Based on the final determined target result, a generator is used to construct the contextual answer. This approach achieves high retrieval accuracy, and the generated results are also more stable and accurate.
[0138] In this implementation, by designing both a retrieval model and a generative model during the retrieval phase, and separately designing evaluation metrics for the retrieval model and the generative model to evaluate their retrieval results, the optimal result can be easily obtained. Then, a generator is used to construct and generate contextual answers, greatly improving the accuracy of the retrieval results. This solves the problem that existing RAG models use a single retrieval method during the retrieval phase, resulting in significant limitations and a tendency to generate misleading information.
[0139] In some optional implementations, the specific process of obtaining the search results corresponding to the question to be answered by the retrieval model may also include steps A1 to A3.
[0140] Step A1: Input the question to be answered into the first retrieval module and search the pre-stored database to obtain a first set number of candidate samples.
[0141] Specifically, after obtaining the questions to be answered, a shared index is built in a pre-stored database using a pre-constructed first searcher based on the questions. Based on this shared index, a first set number of candidate samples are retrieved from the pre-stored database. This first set number can be 100 or 150. In this stage, the first searcher needs to retrieve k candidate samples from a large-scale external dataset. Classic searchers such as BM25, BERT, or SimCSE are used, a large-scale index is built using the Faiss open-source framework, and MIPS is used for retrieval. It is important to note that the first searcher is shared across all tasks. Because the first searcher used in this stage is relatively small, high efficiency can be achieved.
[0142] Step A2: Input the candidate samples and the questions to be answered into the second retrieval module. In response to the task prompt, sort the candidate samples and obtain the second set number of retrieval samples.
[0143] Specifically, after obtaining a first set number of candidate samples, the second retrieval unit rearranges the k samples retrieved in the previous stage and selects d samples as the final retrieval samples. This stage uses task-specific prompts and pre-built language models (LLMs) such as OPT13b for task-specific retrieval. After obtaining the first set number of candidate samples, task prompts are first obtained. For the k candidate samples and the query in the question to be answered, the prompting method is first used for transformation. The prompts can transform various tasks into language model tasks. The prompting method can unify different forms of NKI tasks and obtain task-specific representations. For example, if the question to be answered is whether this sentence has a positive or negative sentiment? The pre-built language model will first transform it into an input-output task that requires sentence completion, and the output prompt will indicate that the answer is negative. After calculating the sample similarity of each prompt-annotated candidate sample, the prompt-annotated candidate samples are rearranged according to the sample similarity in a preset order, and the first second set number of prompt-annotated candidate samples are selected as retrieval samples. The preset order can be from largest to smallest.
[0144] Step A3: Input the search sample into the pre-stored answer generation module to obtain the search results.
[0145] Specifically, after obtaining the retrieval sample, the retrieval sample is input into the pre-stored answer generation module to read the retrieval sample, obtain the reading results, and generate retrieval results based on the reading results. In some embodiments, the answer generation module includes a reader / generator; specifically, FiD (Fusion in Decoder) can be used as the generator.
[0146] In this implementation, a shared index is constructed using a task-oriented first retrieval tool in the first stage, and candidate samples are extracted. In the second stage, a prompt-guided pre-trained language model is used to rearrange the candidate samples and select the retrieval samples. Finally, the retrieval samples are used as input to the answer generation module, which generates the retrieval results. This two-stage approach can achieve better performance on various NKI tasks while saving considerable computational overhead.
[0147] This embodiment also provides a context answer generation device for implementing the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0148] This embodiment provides a context answer generation device, such as... Figure 3 As shown, it includes:
[0149] The retrieval result acquisition module 301 is used to obtain retrieval results based on the question to be answered and the retrieval model, wherein the retrieval model is used to obtain the first text information corresponding to the question to be answered in the corpus and generate retrieval results containing the first text information;
[0150] The generation result module 302 is used to obtain the generation result based on the question to be answered and the generative model, wherein the generative model is used to generate the second text information corresponding to the question to be answered and generate the generation result containing the second text information;
[0151] The evaluation module 303 is used to generate a first evaluation score and a second evaluation score of the search result based on preset evaluation indicators. If the first evaluation score is greater than the second evaluation score, the search result is taken as the target result; otherwise, the generated result is taken as the target result. The preset evaluation indicators are used to determine the probability that the search result and the generated result are the target results.
[0152] The generation module 304 is used to input the target result into the preset generator to generate the context answer corresponding to the question to be answered. The preset generator is used to construct and generate the context answer based on the target result.
[0153] In some optional implementations, the search results obtaining module 301 obtains search results based on the question to be answered and the search query model, including:
[0154] Input the question to be answered into the retrieval model to obtain the retrieval results;
[0155] The retrieval model is used to perform feature extraction on the question to be answered, obtain question features, match the question features with the question and answer texts in the corpus, obtain intermediate text information containing a first preset number of question and answer texts, and determine a second preset number of target question and answer texts from the first preset number of question and answer texts in the intermediate text information according to preset indicators. The target question and answer texts are used as the first text information to generate retrieval results containing the first text information, wherein the second preset number is less than or equal to the first preset number.
[0156] In some optional implementations, the evaluation module 303 generates a first evaluation score and a second evaluation score for the search results based on preset evaluation indicators, including:
[0157] Identify the relevant text information related to the question to be answered in the first text information of the search results, and determine the first quantity of relevant text information;
[0158] Obtain relevant question-and-answer texts related to the question to be answered from the corpus, and determine a second number of relevant question-and-answer texts;
[0159] The accuracy of the search results is obtained by dividing the first quantity by the second quantity.
[0160] The recall rate of the search results is obtained by dividing the first quantity by the second preset quantity.
[0161] Based on precision, recall, and a pre-defined formula, the harmonic mean of the search results is obtained, and the first evaluation score is obtained based on the harmonic mean.
[0162] The preset formula satisfies:
[0163]
[0164] Where F is the harmonic mean, α is the preset parameter, P is the precision, and R is the recall.
[0165] Determine the perplexity and entropy of the second text information in the generated results, and determine the average response length of the second text information;
[0166] Determine the total number of words, the third number of unary words, and the fourth number of bigary words in the second text information of the generated result;
[0167] Divide the third quantity by the total number of words to obtain the first proportion of unary words, and divide the fourth quantity by the total number of words to obtain the second proportion of binary words. Based on the first and second proportions, obtain the response diversity index of the generated results.
[0168] The second evaluation score is obtained based on perplexity, entropy, response diversity, average response length, and preset weights.
[0169] In some optional implementations, the evaluation module 303 generates a first evaluation score and a second evaluation score for the search results based on preset evaluation indicators, including:
[0170] The search results are input into the evaluation model to obtain the first evaluation score. The evaluation model is used to determine the probability that the search result is the target result according to the preset evaluation index. The evaluation model is obtained by training the initial evaluation model based on the first training sample. The initial evaluation model is constructed based on the preset evaluation index.
[0171] The generated result is input into the evaluation model to obtain a second evaluation score. The evaluation model is used to determine the probability that the generated result is the target result based on the preset evaluation index.
[0172] In some alternative implementations, the apparatus is used to: Before obtaining the generated result based on the question to be answered and the generative model, the apparatus is used to:
[0173] An initial model is constructed based on a preset algorithm;
[0174] Obtain a second training sample, and train the initial model based on the second training sample to obtain a generative model.
[0175] In some optional implementations, the result generation module 302 generates results based on the question to be answered and the generative model, including:
[0176] Input the question to be answered into the generative model to obtain the generated result;
[0177] Generative models consist of an encoder and a decoder. The encoder in a generative model is used to determine the semantic features of the question to be answered, and the decoder in a generative model is used to generate second text information based on the semantic features and generate a result containing the second text information.
[0178] In some alternative implementations, the device is also used for:
[0179] Obtain new evaluation indicators, including: the accuracy of the first text information in the top third preset number of search results and / or the average accuracy of the search results, wherein the third preset number is less than or equal to the second preset number;
[0180] Update the preset evaluation indicators based on the newly added evaluation indicators;
[0181] The average accuracy meets the following requirements:
[0182]
[0183] Where MAP is the average accuracy, AP is the average precision of the first text information, and Q is the average precision of the first text information. R q represents the total number of the first text messages, and q is the sequence number.
[0184] Further functional descriptions of the above modules and units are the same as those in the corresponding embodiments described above, and will not be repeated here.
[0185] In this embodiment, the context answer generation device is presented in the form of a functional unit. Here, a unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that execute one or more software or fixed programs, and / or other devices that can provide the above functions.
[0186] This invention also provides a computer device having the above-described features. Figure 3 The context answer generation device shown.
[0187] Please see Figure 4 , Figure 4 This is a schematic diagram of the structure of a computer device provided in an optional embodiment of the present invention, such as... Figure 4 As shown, the computer device includes one or more processors 10, memory 20, and interfaces for connecting the components, including high-speed interfaces and low-speed interfaces. The components communicate with each other via different buses and can be mounted on a common motherboard or otherwise installed as needed. The processors can process instructions executed within the computer device, including instructions stored in or on memory to display graphical information of a GUI on external input / output devices (such as display devices coupled to the interfaces). In some alternative implementations, multiple processors and / or multiple buses can be used with multiple memories and multiple memory modules, if desired. Similarly, multiple computer devices can be connected, each providing some of the necessary operations (e.g., as a server array, a group of blade servers, or a multiprocessor system). Figure 4 Take a processor 10 as an example.
[0188] Processor 10 may be a central processing unit, a network processor, or a combination thereof. Processor 10 may further include an integrated circuit, a programmable logic device, or a combination thereof. The programmable logic device may be a complex programmable logic device, a field-programmable gate array (FPGA), a general-purpose array logic (GPA), or any combination thereof.
[0189] The memory 20 stores instructions executable by at least one processor 10 to cause at least one processor 10 to perform the method shown in the above embodiments.
[0190] The memory 20 may include a program storage area and a data storage area. The program storage area may store the operating system and applications required for at least one function; the data storage area may store data created based on the use of the computer device. Furthermore, the memory 20 may include high-speed random access memory and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some alternative embodiments, the memory 20 may optionally include memory remotely located relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0191] The memory 20 may include volatile memory, such as random access memory; the memory may also include non-volatile memory, such as flash memory, hard disk or solid-state drive; the memory 20 may also include a combination of the above types of memory.
[0192] The computer device also includes a communication interface 30 for communicating with other devices or communication networks.
[0193] This invention also provides a computer-readable storage medium. The methods described above according to embodiments of the invention can be implemented in hardware or firmware, or implemented as computer code that can be recorded on a storage medium, or implemented as computer code downloaded via a network and originally stored on a remote storage medium or a non-transitory machine-readable storage medium and then stored on a local storage medium. Thus, the methods described herein can be processed by software stored on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. The storage medium can be a magnetic disk, optical disk, read-only memory, random access memory, flash memory, hard disk, or solid-state drive, etc.; further, the storage medium can also include combinations of the above types of memory. It is understood that computers, processors, microprocessor controllers, or programmable hardware include storage components capable of storing or receiving software or computer code, which, when accessed and executed by the computer, processor, or hardware, implements the methods shown in the above embodiments.
[0194] A portion of this invention can be applied as a computer program product, such as computer program instructions, which, when executed by a computer, can invoke or provide the methods and / or technical solutions according to the invention through the operation of the computer. Those skilled in the art will understand that the forms in which computer program instructions exist in a computer-readable medium include, but are not limited to, source files, executable files, installation package files, etc. Correspondingly, the ways in which computer program instructions are executed by a computer include, but are not limited to: the computer directly executing the instructions, or the computer compiling the instructions and then executing the corresponding compiled program, or the computer reading and executing the instructions, or the computer reading and installing the instructions and then executing the corresponding installed program. Here, the computer-readable medium can be any available computer-readable storage medium or communication medium accessible to a computer.
[0195] Although embodiments of the invention have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the invention, and such modifications and variations all fall within the scope defined in this application.
Claims
1. A method for generating contextual answers, characterized in that, The method includes: Based on the question to be answered and the retrieval model, the retrieval results are obtained, wherein the retrieval model is used to obtain the first text information corresponding to the question to be answered in the corpus and generate the retrieval results containing the first text information; Based on the question to be answered and the generative model, a generation result is obtained, wherein the generative model is used to generate second text information corresponding to the question to be answered and to generate the generation result containing the second text information; Based on preset evaluation indicators, a first evaluation score and a second evaluation score are generated for the search results. If the first evaluation score is greater than the second evaluation score, the search results are taken as the target results; otherwise, the generated results are taken as the target results. The preset evaluation indicators are used to determine the probability that the search results and the generated results are the target results. According to the preset evaluation indicators, a first evaluation score for the search results is generated, including: determining relevant text information related to the question to be answered in the first text information of the search results, and determining a first quantity of the relevant text information; obtaining relevant question-and-answer text related to the question to be answered in the corpus, and determining a second quantity of the relevant question-and-answer text; dividing the first quantity by the second quantity to obtain the precision of the search results; dividing the first quantity by a second preset quantity to obtain the recall of the search results; obtaining the harmonic mean corresponding to the search results based on the precision, the recall, and a preset formula, and obtaining the first evaluation score based on the harmonic mean; the preset formula satisfies: in, To achieve the harmonic mean, These are preset parameters. For accuracy, Recall rate; Based on the preset evaluation indicators, a second evaluation score is generated for the generated result, including: determining the perplexity and entropy of the second text information of the generated result, and determining the average response length of the second text information; determining the total number of words, the third number of unary words, and the fourth number of bigrams in the second text information of the generated result; dividing the third number by the total number of words to obtain a first proportion of unary words, dividing the fourth number by the total number of words to obtain a second proportion of bigrams, obtaining a response diversity index of the generated result based on the first proportion and the second proportion; and obtaining the second evaluation score based on the perplexity, the entropy, the response diversity index, the average response length, and the preset weights. The target result is input into a preset generator to generate a contextual answer to the question to be answered. The preset generator is used to construct and generate the contextual answer based on the target result.
2. The method according to claim 1, characterized in that, The process of obtaining search results based on the question to be answered and the search query model includes: The question to be answered is input into the retrieval model to obtain the retrieval results; The retrieval model is used to perform feature extraction on the question to be answered, obtain question features, match the question features with the question and answer texts in the corpus, obtain intermediate text information containing a first preset number of question and answer texts, determine a second preset number of target question and answer texts from the first preset number of question and answer texts in the intermediate text information according to preset indicators, use the target question and answer texts as the first text information, and generate the retrieval result containing the first text information, wherein the second preset number is less than or equal to the first preset number.
3. The method according to claim 1, characterized in that, The step of generating a first evaluation score and a second evaluation score for the search results based on preset evaluation indicators includes: The search results are input into the evaluation model to obtain the first evaluation score. The evaluation model is used to determine the probability that the search results are the target results according to the preset evaluation indicators. The evaluation model is obtained by training an initial evaluation model based on the first training samples. The initial evaluation model is constructed based on the preset evaluation indicators. The generated result is input into the evaluation model to obtain the second evaluation score, wherein the evaluation model is used to determine the probability that the generated result is the target result based on the preset evaluation index.
4. The method according to claim 1, characterized in that, The step of obtaining the generation result based on the question to be answered and the generative model includes: The question to be answered is input into the generative model to obtain the generation result; The generative model includes an encoder and a decoder. The encoder of the generative model is used to determine the semantic features of the question to be answered, and the decoder of the generative model is used to generate the second text information based on the semantic features and generate the generation result containing the second text information.
5. The method according to claim 1, characterized in that, The method further includes: Obtain new evaluation indicators, wherein the new evaluation indicators include: the accuracy rate of the first third preset number of first text information in the search results and / or the average accuracy rate of the search results, wherein the third preset number is less than or equal to the second preset number; Update the preset evaluation indicators based on the newly added evaluation indicators; The average accuracy satisfies: in, The average accuracy rate is mentioned above. The average accuracy of the first text information. The total number of the first text information. For serial numbers.
6. A context-based answer generation device, characterized in that, The device includes: The retrieval result obtaining module is used to obtain retrieval results based on the question to be answered and the retrieval model, wherein the retrieval model is used to obtain the first text information corresponding to the question to be answered in the corpus and generate the retrieval results containing the first text information; The result generation module is used to obtain a generation result based on the question to be answered and the generative model, wherein the generative model is used to generate second text information corresponding to the question to be answered and generate the generation result containing the second text information; An evaluation module is used to generate a first evaluation score and a second evaluation score of the search result based on a preset evaluation index. If the first evaluation score is greater than the second evaluation score, the search result is taken as the target result; otherwise, the generated result is taken as the target result. The preset evaluation index is used to determine the probability that the search result and the generated result are the target results. The evaluation module generates a first evaluation score for the search results based on the preset evaluation indicators, including: determining relevant text information related to the question to be answered in the first text information of the search results, and determining a first quantity of the relevant text information; obtaining relevant question-and-answer text related to the question to be answered in the corpus, and determining a second quantity of the relevant question-and-answer text; dividing the first quantity by the second quantity to obtain the accuracy of the search results; dividing the first quantity by a second preset quantity to obtain the recall of the search results; obtaining the harmonic mean corresponding to the search results based on the accuracy, the recall, and a preset formula, and obtaining the first evaluation score based on the harmonic mean; the preset formula satisfies: in, To achieve the harmonic mean, These are preset parameters. For accuracy, Recall rate; The evaluation module generates a second evaluation score for the generated result based on the preset evaluation indicators, including: determining the perplexity and entropy of the second text information of the generated result, and determining the average response length of the second text information; determining the total number of words, the third number of unary words, and the fourth number of bigrams in the second text information of the generated result; dividing the third number by the total number of words to obtain a first proportion of unary words, dividing the fourth number by the total number of words to obtain a second proportion of bigrams, obtaining a response diversity index of the generated result based on the first proportion and the second proportion; and obtaining the second evaluation score based on the perplexity, the entropy, the response diversity index, the average response length, and the preset weights. The generation module is used to input the target result into a preset generator to generate a contextual answer corresponding to the question to be answered, wherein the preset generator is used to construct and generate the contextual answer based on the target result.
7. A computer device, characterized in that, include: A memory and a processor are communicatively connected, the memory storing computer instructions, and the processor executing the computer instructions to perform the context answer generation method of any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing a computer to perform the context answer generation method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Retrieval type chat method and device and computer equipment
CN110750616A
Question and answer result processing method and device, equipment, medium and program product
CN118503389A