Question and answer model training method and device and question and answer method and device

By converting sample problems into logically consistent pseudo-code and using the hallucination evaluation model to generate correct answers and wrong answers, the logical consistency problem of large language models in natural language processing is solved, achieving the accuracy of generated answers and the improvement of user experience.

CN119849622APending Publication Date: 2025-04-18TSINGHUA UNIVERSITY +1
View PDF 0 Cites 5 Cited by

Patent Information

Application Number
CN202411849535.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-16
Publication Date
2025-04-18

AI Technical Summary

Technical Problem

Existing large language models face severe challenges in natural language processing, which are manifested as ‘illusion’ phenomenon, including the inconsistency between the model generation content and the input information and the inconsistency between the output logic.

Method used

By obtaining sample Q&A data, the sample questions are converted into logically consistent pseudo-code, and the hallucination evaluation model is used to generate sample correct answers and wrong answers corresponding to the pseudo-code to train the logical consistency of the Q&A model.

Benefits of technology

It realizes the logical consistency between input and output in natural language generation tasks, and ensures the accuracy of generated answers, avoids hallucinations, and improves the credibility of the model and user interaction experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119849622A_ABST
    Figure CN119849622A_ABST
Patent Text Reader

Abstract

The invention provides a question and answer model training method and device and a question and answer method and device. The method comprises the steps of obtaining sample question and answer data; the sample question and answer data comprises sample questions and real answers corresponding to the sample questions; based on the pre-training model, the semantic information of the sample problem is applied, the sample problem is converted into a pseudo code in a preset format, and the logic of the pseudo code is consistent with the logic of the corresponding sample problem; based on the illusion evaluation model, generating a sample correct answer and a sample wrong answer of the sample question by applying a pseudo code; and training a pre-training model by taking the sample question and answer data, the sample correct answers and the sample wrong answers as training samples to obtain a question and answer model. According to the question and answer model, the logic consistency of input and output in the natural language generation task can be guaranteed, the accuracy of generated answers can be guaranteed, and the illusion problem is avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a question-answering model training, a question-answering method and a device. Background Art

[0002] With the continuous advancement of deep learning technology, large language models (LLM, hereinafter referred to as "models") have made remarkable achievements in the field of natural language processing. Through training with massive text data, the models have mastered the ability to understand and generate natural language, and have demonstrated excellent performance in a variety of tasks such as text generation, translation, and question answering. However, despite the models' powerful expression and generation potential, they still face severe challenges in logical consistency.

[0003] Among them, a highly-watched issue is the "hallucination" phenomenon, which mainly includes two types: one is that the content generated by the model is inconsistent with the input information, that is, the model fails to accurately follow the input instructions or information, such as ignoring the output format required by the instructions, or misunderstanding key information in the input (such as the duration of the patient's cold); the other is that the model's own output is logically inconsistent, for example, when describing the patient's symptoms, it first mentions headaches, and then denies the existence of headache symptoms. This type of "hallucination" phenomenon not only seriously damages the user interaction experience, but also greatly weakens the credibility and reliability of the model in practical applications. Summary of the invention

[0004] The present invention provides a question-answering model training, a question-answering method and a device to solve the defects in the prior art.

[0005] The present invention provides a question-answering model training method, comprising the following steps: Obtaining sample question and answer data; the sample question and answer data includes sample questions and real answers corresponding to the sample questions; Based on the pre-trained model, the semantic information of the sample question is applied to convert the sample question into a pseudocode in a preset format, wherein the logic of the pseudocode is consistent with the logic of the corresponding sample question; Based on the hallucination assessment model, applying the pseudocode, generating a sample correct answer and a sample incorrect answer to the sample question; The sample question and answer data, the sample correct answers and the sample incorrect answers are used as training samples to train the pre-trained model to obtain a question and answer model.

[0006] According to a question-answering model training method provided by the present invention, the pre-trained model is trained based on the following steps: Acquire a first sample text, and perform semantic analysis on the first sample text based on an initial model to extract multiple key elements of the first sample text and logic between the key elements; Based on the initial model, applying the key elements and the logic between the key elements, converting the first sample text into the first sample pseudo code in the preset format; The initial model is trained based on the first sample pseudocode and the real pseudocode corresponding to the first sample text to obtain the pre-trained model.

[0007] According to a question-answering model training method provided by the present invention, the initial model is trained based on the sample pseudocode and the real pseudocode corresponding to the first sample text to obtain the pre-trained model, including: Based on the initial model, converting the real pseudo code into a first sample generated text, wherein the first sample generated text has the same format as the first sample text; Based on the initial model, converting the real pseudo code into a second sample pseudo code, wherein the format of the second sample pseudo code is the preset format; Based on the initial model, converting the first sample text into a second sample generated text, wherein the second sample generated text has the same format as the first sample text; Based on the difference between the first sample pseudocode and the real pseudocode, the difference between the first sample generated text and the first sample text, the difference between the second sample pseudocode and the real pseudocode, and the difference between the second sample generated text and the first sample text, the initial model is trained to obtain the pre-trained model.

[0008] According to a question-answering model training method provided by the present invention, the hallucination assessment model is trained based on the following steps: Acquire a second sample text, and construct a prompt text based on the second sample text; Based on the evaluation initial model, applying the prompt text, generating an answer text for the second sample text, the answer text including a correct answer text and an incorrect answer text; Based on the answer text and the answer text label, the initial evaluation model is trained to obtain the hallucination evaluation model.

[0009] According to a question-answering model training method provided by the present invention, the initial evaluation model is trained based on the answer text and the answer text label to obtain the hallucination evaluation model, including: Based on the answer text, the parsed text of the answer text and the answer text label, the initial evaluation model is trained to obtain the hallucination evaluation model.

[0010] According to a question-answering model training method provided by the present invention, the hallucination evaluation model is based on the pseudo code to generate a sample correct answer and a sample wrong answer to the sample question, including: Based on the hallucination assessment model, applying the pseudocode, generating the sample correct answer, the sample incorrect answer and the answer analysis; The method of training the pre-trained model using the sample question and answer data, the sample correct answers, and the sample incorrect answers as training samples to obtain a question and answer model includes: The sample question and answer data, the sample correct answers, the sample incorrect answers and the answer analysis are used as training samples to train the pre-trained model to obtain a question and answer model.

[0011] The present invention also provides a question-answering method, comprising the following steps: Identify the target problem; Based on the question-answering model, generating a target answer to the target question; The question-answering model is trained based on the question-answering model training method as described in any of the above items.

[0012] The present invention also provides a question-answering model training device, comprising the following modules: An acquisition unit, configured to acquire sample question and answer data; the sample question and answer data includes sample questions and real answers corresponding to the sample questions; A conversion unit, configured to convert the sample question into a pseudo code in a preset format based on a pre-trained model and applying the semantic information of the sample question, wherein the logic of the pseudo code is consistent with the logic of the corresponding sample question; A first generating unit, configured to generate a sample correct answer and a sample incorrect answer to the sample question by applying the pseudo code based on a hallucination assessment model; A training unit is used to train the pre-trained model using the sample question and answer data, the sample correct answers and the sample incorrect answers as training samples to obtain a question and answer model.

[0013] The present invention also provides a question-answering device, comprising the following modules: A determination unit, used to determine the target problem; A second generating unit, configured to generate a target answer to the target question based on the question-answering model; The question-answering model is trained based on the question-answering model training method as described in any of the above items.

[0014] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, it implements any one of the question-answering model training methods or question-answering methods described above.

[0015] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the question-answering model training methods or question-answering methods described above.

[0016] The present invention also provides a computer program product, including a computer program, which, when executed by a processor, implements any of the question-answering model training methods or question-answering methods described above.

[0017] The question-answering model training, question-answering method and device provided by the present invention convert sample questions into pseudocodes with the same logic to train the logical consistency of the question-answering model, and use the hallucination evaluation model to generate sample correct answers and sample incorrect answers corresponding to the pseudocodes, so that the question-answering model can recognize hallucination questions, thereby ensuring that the question-answering model finally trained can not only ensure the logical consistency of input and output in the natural language generation task, but also ensure the accuracy of the generated answers to avoid hallucination problems. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] In order to more clearly illustrate the technical solutions in the present invention or the prior art, a brief introduction will be given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0019] Figure 1 It is a flowchart of the question-answering model training method provided by the present invention.

[0020] Figure 2 It is a flowchart of the pre-training model training method provided by the present invention.

[0021] Figure 3 It is a flow chart of the hallucination assessment model training method provided by the present invention.

[0022] Figure 4 It is a flowchart of another question-answering model training method provided by the present invention.

[0023] Figure 5 It is a flow chart of the question-answering method provided by the present invention.

[0024] Figure 6 It is a structural schematic diagram of the question-answering model training device provided by the present invention.

[0025] Figure 7 It is a structural schematic diagram of the question-answering device provided by the present invention.

[0026] Figure 8 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION

[0027] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0028] In the field of natural language processing (NLP), a variety of solutions have been proposed to solve the problem of logical inconsistency in the generation phase of specific tasks such as "data-to-text" conversion, dialogue generation, machine translation, question-answering systems, and text summarization. Some solutions are dedicated to improving the network structure of the model, for example, by introducing hierarchical attention mechanisms or graph neural networks to enhance the model's ability to capture and understand complex logical relationships. Some solutions focus on designing specific training strategies to improve the logical consistency of the model in the decision-making process, by building a training set with logical annotations to help the model better perceive the implicit logical relationships in the language. Alternatively, advanced technologies such as reinforcement learning and adversarial training are used to train and optimize the data set to enhance the logical consistency of the model.

[0029] However, although these task-specific solutions have achieved certain results in alleviating the problem of logical inconsistency, their scope of application is significantly limited. The above solutions often focus on a specific type of task, such as "data-to-text" conversion or dialogue generation, which makes it difficult to effectively transfer the effect of improving logical consistency to other types of NLP tasks. In addition, the above solutions rely heavily on carefully labeled training data to ensure that the model can accurately understand the implicit logical relationships. However, building high-quality logically labeled datasets is not only time-consuming and labor-intensive, but also subject to many restrictions in practical applications, which seriously affects the popularity and application of these solutions.

[0030] In addition, unlike the above-mentioned solutions for specific tasks, there are also solutions for general tasks, namely, by building synthetic code datasets to train models, the mathematical reasoning ability and logical rigor of the models can be enhanced. However, the effects of synthetic code datasets are often limited to specific application areas, and their effectiveness and flexibility in the face of a wider range of tasks are still unclear. In particular, in non-English contexts, the effect of improving logical consistency may drop sharply.

[0031] In this regard, an embodiment of the present invention provides a question-answering model training method, which converts sample questions into pseudocodes with the same logic to train the logical consistency of the question-answering model, and uses a hallucination evaluation model to generate sample correct answers and sample incorrect answers corresponding to the pseudocodes, so that the question-answering model can identify hallucination questions, thereby ensuring that the question-answering model finally trained can not only ensure the logical consistency of input and output in the natural language generation task, but also ensure the accuracy of the generated answers to avoid hallucination problems.

[0032] Figure 1 It is a flow chart of the question-answering model training method provided by the present invention. Figure 1 As shown, the method includes step 110, step 120, step 130 and step 140.

[0033] Step 110: Obtain sample question and answer data; the sample question and answer data includes sample questions and real answers corresponding to the sample questions.

[0034] Specifically, sample question and answer data is question and answer data used to train the question and answer model, and the sample question and answer data includes sample questions and real answers corresponding to the sample questions. The sample question and answer data can be obtained through web crawlers, public data sets, manual creation, etc.

[0035] In addition, the sample question and answer data can also be question and answer data collected from different fields, that is, the sample question and answer data can cover multiple different fields, so that the question and answer model can learn knowledge in different fields, and then can better adapt to problems in different fields and generate more accurate answers.

[0036] Step 120: Based on the pre-trained model, the semantic information of the sample question is applied to convert the sample question into a pseudocode in a preset format, and the logic of the pseudocode is consistent with the logic of the corresponding sample question.

[0037] Specifically, the pre-trained model here refers to the ability to extract semantic information from the original text, rewrite the original text through format conversion, and generate a rewritten text that is logically consistent with the original text. In other words, the pre-trained model can ensure the logical consistency of input and output.

[0038] In addition, the pseudocode can be a clear logical expression to represent the logic of the sample problem. The pre-trained model can perform word segmentation, part-of-speech tagging, entity recognition, and logical relationship recognition on the sample problem based on the semantic information of the sample problem, extract the entities in the sample problem and the logical relationship between the entities, and convert the sample problem into a pseudocode in a preset format based on the extracted entities and the logical relationship between the entities. The pseudocode can clearly represent the logic of the sample problem. Among them, the logic can include causal relationships, conditional relationships, comparative relationships, etc.

[0039] For example, a sample question is "If the customer's purchase amount is greater than 200 yuan, the customer can get a 15% discount; if the purchase amount is between 100 yuan and 200 yuan, the customer can get a 10% discount; if the purchase amount is between 50 yuan and 100 yuan, the customer will get a 5% discount; if the amount is less than 50 yuan, no discount is provided."

[0040] After semantic analysis of the above sample questions, the logical relationship between entities extracted is "Purchase amount > 200 yuan → 15% discount; 100 yuan ≤ purchase amount ≤ 200 yuan → 10% discount; 50 yuan ≤ purchase amount < 100 yuan → 5% discount; purchase amount < 50 yuan → no discount".

[0041] Based on the logical relationship between the above entities, the corresponding pseudo code is generated as "If the input amount > 200, then discount = 0.15; otherwise if 100 ≤ input amount ≤ 200, then discount = 0.1; otherwise if 50 ≤ input amount < 100, then discount = 0.05; otherwise discount = 0.00".

[0042] Exemplarily, a pseudocode prompt text can be constructed based on a sample problem, the pseudocode prompt text is used to prompt the logical requirements of the pre-trained model pseudocode, and the pseudocode prompt text is input into the pre-trained model so that the pre-trained model generates pseudocode.

[0043] Also based on the above sample text example, the corresponding pseudocode prompt text can be "Please generate pseudocode according to the following logical requirements: if the purchase amount is greater than 200 yuan, the discount is 15%; if it is between 100 yuan and 200 yuan, the discount is 10%; if it is between 50 and 100 yuan, the discount is 5%; otherwise there is no discount."

[0044] In addition, if the generated pseudocode does not meet the requirements, pseudocode prompt text can be appended to the pre-trained model so that the pre-trained model can be improved into pseudocode according to the improvement requirements prompted in the appended pseudocode prompt text.

[0045] Step 130: Based on the hallucination evaluation model, apply pseudocode to generate sample correct answers and sample incorrect answers to sample questions.

[0046] Specifically, the hallucination assessment model can be a classifier or generator based on deep learning. The pseudocode is input into the hallucination assessment model, and the hallucination assessment model generates sample correct answers and sample wrong answers to sample questions based on the logic in the pseudocode. Among them, the sample wrong answers can be understood as answers to hallucination questions.

[0047] Exemplarily, the hallucination assessment model can generate a sample correct answer and three sample incorrect answers based on pseudocode, and each sample incorrect answer corresponds to a different hallucination type. For example, the corresponding hallucination type may include not following instructions, not following input content, inconsistent output context, etc.

[0048] In addition, a generation prompt text can be constructed based on the pseudocode, and the generation prompt text is used to prompt the hallucination evaluation model to generate an answer requirement, and the generation prompt text is input into the hallucination evaluation model, so that the hallucination evaluation model generates sample correct answers and sample wrong answers according to the answer generation requirement indicated by the generation prompt text. For example, the generation prompt text can be "Please generate a correct answer and three wrong answers for the following question, ensuring that the logic of the correct answer is clear, and the types of wrong answers can be: 1) inconsistent with the input instructions; 2) inconsistent with the input content; 3) inconsistent with the output context; randomly select one of these three. Question: XXXXX" Step 140: Use the sample question and answer data, sample correct answers, and sample incorrect answers as training samples to train the pre-trained model to obtain a question and answer model.

[0049] Specifically, when training the pre-trained model, sample question and answer data is used as input, sample correct answers are used as positive labels, and sample incorrect answers are used as negative labels. In this way, the pre-trained model can not only learn the generation logic of correct answers, but also identify and reject incorrect answers, thereby enhancing the model's ability to distinguish correct and incorrect answers and avoiding the problem of hallucinations in the trained question and answer model.

[0050] Exemplarily, during training, sample question and answer data can be input into a pre-trained model to obtain the correct generated answers and incorrect generated answers output by the pre-trained model. Based on the difference between the correct generated answers and the sample correct answers and the difference between the incorrect generated answers and the sample incorrect answers, the parameters of the pre-trained model are updated to obtain a question and answer model.

[0051] The question-answering model training method provided in the embodiment of the present invention converts sample questions into pseudocodes with the same logic to train the logical consistency of the question-answering model, and uses the hallucination evaluation model to generate sample correct answers and sample incorrect answers corresponding to the pseudocodes, so that the question-answering model can recognize hallucination questions, thereby ensuring that the question-answering model finally trained can not only ensure the logical consistency of input and output in the natural language generation task, but also ensure the accuracy of the generated answers to avoid hallucination problems.

[0052] Based on the above embodiments, Figure 2 It is a flowchart of the pre-training model training method provided by the present invention, such as Figure 2 As shown in the figure, the pre-trained model is trained based on the following steps: Step 210: Obtain a first sample text, and perform semantic analysis on the first sample text based on the initial model to extract multiple key elements of the first sample text and logic between the key elements.

[0053] Specifically, the first sample text can be a question text, an answer text, or a description text used to describe facts, that is, the form and content of the first sample text are not limited here, because the pre-trained model that needs to be trained here has the ability to ensure the logical consistency of input and output. Among them, the first sample text can be obtained from a web crawler, or from an open source data set, or can be created manually, and the embodiment of the present invention does not specifically limit this.

[0054] After obtaining the first sample text, a semantic analysis is performed on the first sample text, such as word segmentation, part-of-speech tagging, entity recognition, syntactic analysis, etc., to extract multiple key elements of the first sample text and the logic between the key elements. Among them, the key elements are used to characterize the key information in the first sample text, which can be the key entities in the first sample text. The logic between the key elements is used to describe the causal relationship, conditional relationship, comparative relationship, etc. between the key elements.

[0055] Step 220: Based on the initial model, the key elements and the logic between the key elements are applied to convert the first sample text into a first sample pseudo code in a preset format.

[0056] Specifically, the first sample pseudocode may be a logic that uses a clear logical expression to represent the first sample text. The initial model uses the key elements and the logic between the key elements to convert the first sample text into a first sample pseudocode in a preset format. The first sample pseudocode is intended to retain the logical structure in the first sample text and remove specific implementation details.

[0057] Step 230: Based on the first sample pseudocode and the real pseudocode corresponding to the first sample text, the initial model is trained to obtain a pre-trained model.

[0058] Specifically, the first sample pseudocode is generated by the initial model based on the first sample text, and the real pseudocode has the same logic as the first sample text. If the difference between the first sample pseudocode and the real pseudocode is small, it indicates that the logic of the first sample pseudocode is also the same as the first sample text, which further indicates that the initial model has a strong ability to ensure the consistency of input and output logic. At this time, the convergence condition is met and the pre-trained model is obtained.

[0059] Exemplarily, a loss value can be determined based on the difference between the first sample pseudocode and the real pseudocode, and the initial model parameters can be updated based on the loss value until the loss value is less than a threshold or the number of update iterations reaches a threshold, thereby obtaining a pre-trained model.

[0060] The embodiment of the present invention trains the initial model based on the first sample text and its corresponding real pseudocode, so that the pre-trained model obtained by training can ensure that the original text logic remains unchanged and convert the original text into a preset format text with the same logic, that is, the pre-trained model can ensure the logical consistency of input and output.

[0061] Based on any of the above embodiments, the initial model is trained based on the sample pseudocode and the real pseudocode corresponding to the first sample text to obtain a pre-trained model, including: Based on the initial model, the real pseudo code is converted into a first sample generated text, and the first sample generated text has the same format as the first sample text; Based on the initial model, the real pseudo code is converted into a second sample pseudo code, where the format of the second sample pseudo code is a preset format; Based on the initial model, the first sample text is converted into a second sample generated text, and the second sample generated text has the same format as the first sample text; Based on the difference between the first sample pseudocode and the real pseudocode, the difference between the first sample generated text and the first sample text, the difference between the second sample pseudocode and the real pseudocode, and the difference between the second sample generated text and the first sample text, the initial model is trained to obtain a pre-trained model.

[0062] Specifically, the first sample text is converted into a first sample pseudocode in a preset format, and training is performed based on the difference between the first sample pseudocode and the real pseudocode, so that the pre-trained model can understand the logic in the first sample text and generate a logically consistent first sample pseudocode based on the logic in the first sample text, that is, the ability of the training model to generate pseudocode based on text.

[0063] The real pseudocode is converted into the first sample generated text, and training is performed based on the difference between the first sample generated text and the first sample text, so that the pre-trained model can understand the logic in the preset format pseudocode, and generate a logically consistent first sample generated text based on the logic of the real pseudocode, that is, the ability of the training model to generate text based on pseudocode.

[0064] The real pseudocode is converted into a second sample pseudocode, and training is performed based on the difference between the second sample pseudocode and the real pseudocode, so that the pre-trained model can understand the logic in the preset format pseudocode, and generate a second sample pseudocode with consistent logic based on the logic of the real pseudocode, that is, the ability of the training model to generate another pseudocode based on the original pseudocode. Among them, the second sample pseudocode is in a preset format, but the expression method and expression terms of the second sample pseudocode and the real pseudocode can be different.

[0065] The first sample text is converted into a second sample generated text, and training is performed based on the difference between the second sample generated text and the first sample text, so that the pre-trained model can understand the logic in the first sample text and generate a second sample generated text with consistent logic based on the logic of the first sample text, that is, the ability of the training model to generate another text based on the original text. Among them, the second sample generated text has the same format as the first sample text, but the second sample generated text and the first sample text may have different expressions and expressions.

[0066] The embodiment of the present invention trains the initial model based on the difference between the first sample pseudocode and the real pseudocode, the difference between the first sample generated text and the first sample text, the difference between the second sample pseudocode and the real pseudocode, and the difference between the second sample generated text and the first sample text. The obtained pre-trained model has the ability to generate pseudocode based on text, the ability to generate text based on pseudocode, the ability to generate another pseudocode based on the original pseudocode, and the ability to generate another text based on the original text.

[0067] Exemplarily, the training loss value can be determined based on the difference between the first sample pseudocode and the real pseudocode, the difference between the first sample generated text and the first sample text, the difference between the second sample pseudocode and the real pseudocode, and the difference between the second sample generated text and the first sample text, and the parameters of the initial model are updated based on the training loss value to obtain a pre-trained model.

[0068] Based on any of the above embodiments, Figure 3 is a flow chart of the hallucination assessment model training method provided by the present invention, such as Figure 3 As shown, the hallucination assessment model is trained based on the following steps: Step 310: Obtain a second sample text, and construct a prompt text based on the second sample text.

[0069] Step 320: Based on the evaluation of the initial model, the prompt text is applied to generate the answer text of the second sample text, and the answer text includes the correct answer text and the incorrect answer text.

[0070] Specifically, the second sample text may be a question text or a description text for describing facts, that is, the form and content of the second sample text are not limited here. The second sample text may be obtained from a web crawler, from an open source data set, or may be manually created, and the embodiment of the present invention does not specifically limit this. In addition, the first sample text may be the same as the second sample text, or may be different from the second sample text, and the embodiment of the present invention does not specifically limit this.

[0071] After obtaining the second sample text, a prompt text can be constructed, and the prompt text is used to prompt the answer generation requirement, so that the evaluation initial model can generate the answer text of the second sample text according to the prompt text. In addition, if the second sample text is a description text or a theme text, a question generation prompt text can be constructed first, and the question generation prompt text can be input into the evaluation initial model, and the evaluation initial model can generate the question corresponding to the description text or theme text based on the question generation prompt text, and then construct the prompt text based on the question. Among them, the question generation prompt text is used to prompt the question generation requirement.

[0072] For example, if the second sample text is themed "Space Laboratory Launch Situation", a text generation prompt text can be constructed: "Please generate a paragraph to describe the space laboratory launch situation, ensuring that all time information is accurate and logically related", and the text generation prompt text can be input into the evaluation initial model. The evaluation initial model generates a description text for the corresponding topic, and then a question generation prompt text is constructed based on the description text: "Based on the generated description text, write a question about which spacecraft docked with the space laboratory in XXXX", and the question generation prompt text is input into the evaluation initial model to generate the corresponding question text. Finally, a prompt text is constructed based on the question text: "Please generate a correct answer and three wrong answers for the question just now, ensuring that the logic of the correct answer is clear. The types of wrong answers can be: 1) inconsistent with the input instructions; 2) inconsistent with the input content; 3) inconsistent with the output context; randomly select one of these three", so that the evaluation initial model generates the answer text of the second sample text according to the prompt text requirements.

[0073] It is understandable that after obtaining the answer text for generating the second sample text, the accuracy of the answer text can be tested by experts, for example, whether the correct answer text is correct, whether the wrong answer text covers the wrong answer types required to be covered in the prompt text, and the tested answer text can be used for model training to ensure the reliability of the training data.

[0074] Step 330: Based on the answer text and the answer text label, the initial evaluation model is trained to obtain a hallucination evaluation model.

[0075] Specifically, the answer text label can be understood as the label corresponding to the correct answer text and the label corresponding to the incorrect answer text in the answer text. The smaller the difference between the correct answer text and the label corresponding to the correct answer text, the more accurately the evaluation initial model can generate the correct answer. The smaller the difference between the incorrect answer text and the label corresponding to the incorrect answer text, the more accurately the evaluation initial model can identify the incorrect answer, that is, the more accurately the evaluation initial model can generate hallucination data (i.e., incorrect answers).

[0076] Based on the difference between the answer text and the answer text label, the initial evaluation model is trained so that the obtained hallucination evaluation model can not only accurately generate correct answer data, but also accurately generate hallucination data.

[0077] Exemplarily, a training loss value may be determined based on the difference between the answer text and the answer text label, and the initial evaluation model may be trained based on the training loss value to obtain a hallucination evaluation model.

[0078] Based on any of the above embodiments, the initial evaluation model is trained based on the answer text and the answer text label to obtain a hallucination evaluation model, including: Based on the answer text, the parsed text of the answer text and the answer text label, the initial evaluation model is trained to obtain the hallucination evaluation model.

[0079] Considering that if the initial evaluation model is trained only based on the answer text and the answer text label, the resulting hallucination evaluation model may be too dependent on the training data and training method, resulting in the model being able to only generate answer text corresponding to the training data pattern, and the generated answer text is too rigid and cannot adapt to broader and more complex training data.

[0080] In this regard, the embodiment of the present invention also introduces the parsed text of the answer text during training, and the parsed text is used to illustrate the reasoning process of generating the answer, so that when the initial evaluation model is trained, the initial evaluation model can improve the logical reasoning ability based on the parsed text of the answer text, thereby enabling the trained hallucination evaluation model to effectively perform learning reasoning and accurately generate the corresponding answer text when facing complex inputs.

[0081] Based on any of the above embodiments, based on the hallucination assessment model, applying pseudo code to generate sample correct answers and sample incorrect answers to sample questions includes: Based on the hallucination evaluation model, pseudocode is applied to generate sample correct answers, sample wrong answers and answer analysis; The pre-trained model is trained using sample question-answering data, sample correct answers, and sample incorrect answers as training samples to obtain a question-answering model, including: The pre-trained model is trained using sample question and answer data, sample correct answers, sample incorrect answers, and answer analysis as training samples to obtain a question and answer model.

[0082] Specifically, answer parsing refers to the parsing corresponding to the sample correct answer and the parsing corresponding to the sample wrong answer, which is used to illustrate the reasoning process of generating the sample correct answer and the sample wrong answer. After applying pseudocode based on the hallucination evaluation model to generate the sample correct answer, the sample wrong answer and the answer parsing, since the answer parsing is used to illustrate the reasoning process of generating the sample correct answer and the sample wrong answer, when the pre-trained model is trained with the sample question and answer data, the sample correct answer, the sample wrong answer and the answer parsing as training samples, the pre-trained model can learn the logical reasoning process of generating answers, thereby making the trained question and answer model have strong logical reasoning ability.

[0083] After experiments, the question-answering model trained by the embodiment of the present invention is applied to auxiliary diagnosis tasks in the medical field. The question-answering model has good logical rigor, can effectively avoid hallucination problems, and significantly improves the credibility of the large language model and the user interaction experience.

[0084] Based on any of the above embodiments, Figure 4 It is a flowchart of another question-answering model training method provided by the present invention, such as Figure 4 As shown, the method includes: Obtain sample question and answer data; the sample question and answer data includes sample questions and the real answers corresponding to the sample questions; then based on the pre-trained model obtained from the first round of training, apply the semantic information of the sample questions to convert the sample questions into pseudocode in a preset format, and the logic of the pseudocode is consistent with the logic of the corresponding sample questions.

[0085] The pseudocode is input into the hallucination evaluation model for hallucination evaluation, that is, the pseudocode is applied to generate sample correct answers, sample incorrect answers, and answer analysis for sample questions. The sample question and answer data, sample correct answers, sample incorrect answers, and answer analysis are packaged as hallucination enhancement data, and the pre-trained model is trained based on the hallucination enhancement data (i.e., the second round of training) to obtain a question and answer model.

[0086] Among them, the first round of training is to train the initial model to obtain a pre-trained model. The training steps are as follows: Acquire a first sample text, and perform semantic analysis on the first sample text based on the initial model to extract multiple key elements of the first sample text and logic between the key elements; Based on the initial model, the first sample text is converted into a first sample pseudo code in a preset format by applying the key elements and the logic between the key elements. This step corresponds to the original data-pseudo code data generation task; Based on the initial model, the real pseudocode is converted into the first sample generated text, and the format of the first sample generated text is the same as that of the first sample text. This step corresponds to the pseudocode-original data generation task; Based on the initial model, the real pseudo code is converted into a second sample pseudo code, where the format of the second sample pseudo code is a preset format. This step corresponds to a pseudo code reasoning task; Based on the initial model, the first sample text is converted into the second sample generated text, and the format of the second sample generated text is the same as that of the first sample text. This step corresponds to the original data task reasoning; Based on the difference between the first sample pseudocode and the real pseudocode, the difference between the first sample generated text and the first sample text, the difference between the second sample pseudocode and the real pseudocode, and the difference between the second sample generated text and the first sample text, the initial model is trained to obtain a pre-trained model.

[0087] In addition, the hallucination assessment model is trained based on the following steps: Obtaining a second sample text, and constructing a prompt text based on the second sample text; Based on the evaluation of the initial model, the prompt text is applied to generate an answer text for the second sample text, the answer text including a correct answer text and an incorrect answer text; Based on the answer text, the parsed text of the answer text and the answer text label, the initial evaluation model is trained to obtain the hallucination evaluation model. Among them, the wrong answer text can correspond to three types of hallucinations: not following the instructions, not following the input content, and inconsistent input context.

[0088] In addition, when training and evaluating the initial model, you can select multiple tasks for training. The tasks may include data-to-text, dialogue generation, machine translation, question-answering system, text summarization, etc.

[0089] Based on any of the above embodiments, Figure 5 It is a flow chart of the question-answering method provided by the present invention, such as Figure 5 As shown, the method includes: Step 510: determine the target problem; Step 520: Generate a target answer to the target question based on the question-answering model; The question-answering model is trained based on the question-answering model training method described in any of the above embodiments.

[0090] Specifically, in the question-answering model training method described in any of the above embodiments, sample questions are converted into pseudocodes with the same logic to train the logical consistency of the question-answering model, and a hallucination evaluation model is used to generate sample correct answers and sample incorrect answers corresponding to the pseudocodes, so that the question-answering model can recognize hallucination questions, thereby ensuring that the question-answering model finally trained can not only ensure the logical consistency of input and output in the natural language generation task, but also ensure the accuracy of generating the target answer and avoid hallucination problems.

[0091] The question-answering model training device provided by the present invention is described below. The question-answering model training device described below and the question-answering model training method described above can be referenced to each other.

[0092] Based on any of the above embodiments, Figure 6 : is a schematic diagram of the structure of the question-answering model training device provided by the present invention. Figure 6 As shown, the device comprises: An acquisition unit 610 is used to acquire sample question and answer data; the sample question and answer data includes sample questions and real answers corresponding to the sample questions; A conversion unit 620 is used to convert the sample question into a pseudo code in a preset format based on the pre-trained model and applying the semantic information of the sample question, wherein the logic of the pseudo code is consistent with the logic of the corresponding sample question; A first generating unit 630 is used to generate a sample correct answer and a sample wrong answer to a sample question by applying a pseudo code based on the hallucination evaluation model; The training unit 640 is used to train the pre-trained model using sample question and answer data, sample correct answers and sample incorrect answers as training samples to obtain a question and answer model.

[0093] Based on any of the above embodiments, the pre-trained model is trained based on the following steps: Acquire a first sample text, and perform semantic analysis on the first sample text based on the initial model to extract multiple key elements of the first sample text and logic between the key elements; Based on the initial model, applying the key elements and logic between the key elements, converting the first sample text into a first sample pseudo code in a preset format; Based on the first sample pseudocode and the real pseudocode corresponding to the first sample text, the initial model is trained to obtain a pre-trained model.

[0094] Based on any of the above embodiments, the initial model is trained based on the sample pseudocode and the real pseudocode corresponding to the first sample text to obtain a pre-trained model, including: Based on the initial model, the real pseudo code is converted into a first sample generated text, and the first sample generated text has the same format as the first sample text; Based on the initial model, the real pseudo code is converted into a second sample pseudo code, where the format of the second sample pseudo code is a preset format; Based on the initial model, the first sample text is converted into a second sample generated text, and the second sample generated text has the same format as the first sample text; Based on the difference between the first sample pseudocode and the real pseudocode, the difference between the first sample generated text and the first sample text, the difference between the second sample pseudocode and the real pseudocode, and the difference between the second sample generated text and the first sample text, the initial model is trained to obtain a pre-trained model.

[0095] Based on any of the above embodiments, the hallucination assessment model is trained based on the following steps: Obtaining a second sample text, and constructing a prompt text based on the second sample text; Based on the evaluation of the initial model, the prompt text is applied to generate an answer text for the second sample text, the answer text including a correct answer text and an incorrect answer text; Based on the answer text and the answer text label, the initial evaluation model is trained to obtain the hallucination evaluation model.

[0096] Based on any of the above embodiments, the initial evaluation model is trained based on the answer text and the answer text label to obtain a hallucination evaluation model, including: Based on the answer text, the parsed text of the answer text and the answer text label, the initial evaluation model is trained to obtain the hallucination evaluation model.

[0097] Based on any of the above embodiments, based on the hallucination assessment model, applying pseudo code to generate sample correct answers and sample incorrect answers to sample questions includes: Based on the hallucination evaluation model, pseudocode is applied to generate sample correct answers, sample wrong answers and answer analysis; The pre-trained model is trained using sample question-answering data, sample correct answers, and sample incorrect answers as training samples to obtain a question-answering model, including: The pre-trained model is trained using sample question and answer data, sample correct answers, sample incorrect answers, and answer analysis as training samples to obtain a question and answer model.

[0098] Based on any of the above embodiments, Figure 7 : is a schematic diagram of the structure of the question-answering device provided by the present invention. Figure 7 As shown, the device comprises: A determination unit 710, configured to determine a target problem; A second generating unit 720 is used to generate a target answer to a target question based on the question-answering model; The question-answering model is trained based on the question-answering model training method described in any of the above embodiments.

[0099] Figure 8 is a schematic diagram of the structure of the electronic device provided by the present invention, such as Figure 8 As shown, the electronic device may include: a processor 810, a communication interface 820, a memory 830 and a communication bus 840, wherein the processor 810, the communication interface 820 and the memory 830 communicate with each other through the communication bus 840. The processor 810 may call the logic instructions in the memory 830 to execute the question-answering model training method, which includes: obtaining sample question-answering data; the sample question-answering data includes a sample question and a real answer corresponding to the sample question; based on the pre-training model, applying the semantic information of the sample question, converting the sample question into a pseudo code in a preset format, the logic of the pseudo code is consistent with the logic of the corresponding sample question; based on the hallucination evaluation model, applying the pseudo code, generating a sample correct answer and a sample wrong answer of the sample question; using the sample question-answering data, the sample correct answer and the sample wrong answer as training samples, training the pre-training model to obtain a question-answering model.

[0100] In addition, the logic instructions in the above-mentioned memory 830 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.

[0101] On the other hand, the present invention also provides a computer program product, which includes a computer program, and the computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the question-answering model training method provided by the above methods, and the method includes: obtaining sample question-answering data; the sample question-answering data includes sample questions and real answers corresponding to the sample questions; based on a pre-trained model, applying the semantic information of the sample questions, converting the sample questions into pseudocodes in a preset format, and the logic of the pseudocodes is consistent with the logic of the corresponding sample questions; based on an illusion evaluation model, applying the pseudocodes, generating sample correct answers and sample incorrect answers for the sample questions; using the sample question-answering data, the sample correct answers and the sample incorrect answers as training samples, training the pre-trained model to obtain a question-answering model.

[0102] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the question-answering model training method provided by the above-mentioned methods, the method comprising: obtaining sample question-answering data; the sample question-answering data comprising sample questions and real answers corresponding to the sample questions; based on a pre-trained model, applying the semantic information of the sample questions, converting the sample questions into pseudocodes in a preset format, wherein the logic of the pseudocodes is consistent with the logic of the corresponding sample questions; based on an illusion evaluation model, applying the pseudocodes, generating sample correct answers and sample incorrect answers to the sample questions; using the sample question-answering data, the sample correct answers and the sample incorrect answers as training samples, training the pre-trained model to obtain a question-answering model.

[0103] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0104] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0105] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A question-answering model training method, characterized in that: include: Get sample question and answer data; The sample question and answer data includes sample questions and real answers corresponding to the sample questions; Based on the pre-trained model, the semantic information of the sample question is applied to convert the sample question into a pseudo code in a preset format, wherein the logic of the pseudo code is consistent with the logic of the corresponding sample question; Based on the hallucination assessment model, applying the pseudocode, generating a sample correct answer and a sample incorrect answer to the sample question; The sample question and answer data, the sample correct answers and the sample incorrect answers are used as training samples to train the pre-trained model to obtain a question and answer model.

2. The question-answering model training method according to claim 1, characterized in that: The pre-trained model is trained based on the following steps: Acquire a first sample text, and perform semantic analysis on the first sample text based on an initial model to extract multiple key elements of the first sample text and logic between the key elements; Based on the initial model, applying the key elements and the logic between the key elements, converting the first sample text into the first sample pseudo code in the preset format; The initial model is trained based on the first sample pseudocode and the real pseudocode corresponding to the first sample text to obtain the pre-trained model.

3. The question-answering model training method according to claim 2, characterized in that: The training of the initial model based on the sample pseudocode and the real pseudocode corresponding to the first sample text to obtain the pre-trained model includes: Based on the initial model, converting the real pseudo code into a first sample generated text, wherein the first sample generated text has the same format as the first sample text; Based on the initial model, converting the real pseudo code into a second sample pseudo code, wherein the format of the second sample pseudo code is the preset format; Based on the initial model, converting the first sample text into a second sample generated text, wherein the second sample generated text has the same format as the first sample text; Based on the difference between the first sample pseudocode and the real pseudocode, the difference between the first sample generated text and the first sample text, the difference between the second sample pseudocode and the real pseudocode, and the difference between the second sample generated text and the first sample text, the initial model is trained to obtain the pre-trained model.

4. The question-answering model training method according to any one of claims 1 to 3, characterized in that: The hallucination assessment model is trained based on the following steps: Acquire a second sample text, and construct a prompt text based on the second sample text; Based on the evaluation initial model, applying the prompt text, generating an answer text for the second sample text, the answer text including a correct answer text and an incorrect answer text; Based on the answer text and the answer text label, the initial evaluation model is trained to obtain the hallucination evaluation model.

5. The question-answering model training method according to claim 4, characterized in that: The step of training the initial evaluation model based on the answer text and the answer text label to obtain the hallucination evaluation model includes: Based on the answer text, the parsed text of the answer text and the answer text label, the initial evaluation model is trained to obtain the hallucination evaluation model.

6. The question-answering model training method according to any one of claims 1 to 3, characterized in that: The method of applying the pseudo code to generate a sample correct answer and a sample wrong answer to the sample question based on the hallucination assessment model includes: Based on the hallucination assessment model, applying the pseudocode, generating the sample correct answer, the sample incorrect answer and the answer analysis; The method of training the pre-trained model using the sample question and answer data, the sample correct answers, and the sample incorrect answers as training samples to obtain a question and answer model includes: The sample question and answer data, the sample correct answers, the sample incorrect answers and the answer analysis are used as training samples to train the pre-trained model to obtain a question and answer model.

7. A question-answering method, characterized in that: include: Identify the target problem; Based on the question-answering model, generating a target answer to the target question; The question-answering model is trained based on the question-answering model training method described in any one of claims 1 to 6.

8. A question-answering model training device, characterized in that: include: An acquisition unit, used to acquire sample question and answer data; The sample question and answer data includes sample questions and real answers corresponding to the sample questions; A conversion unit, configured to convert the sample question into a pseudo code in a preset format based on a pre-trained model and applying the semantic information of the sample question, wherein the logic of the pseudo code is consistent with the logic of the corresponding sample question; A first generating unit, configured to generate a sample correct answer and a sample incorrect answer to the sample question by applying the pseudo code based on a hallucination assessment model; A training unit is used to train the pre-trained model using the sample question and answer data, the sample correct answers and the sample incorrect answers as training samples to obtain a question and answer model.

9. A question-answering device, characterized in that: include: A determination unit, used to determine the target problem; A second generating unit, configured to generate a target answer to the target question based on the question-answering model; The question-answering model is trained based on the question-answering model training method described in any one of claims 1 to 6.

10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that: When the processor executes the computer program, it implements the question-answering model training method as described in any one of claims 1 to 6, or, when the processor executes the computer program, it implements the question-answering method as described in claim 7.

11. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by the processor, it implements the question-answering model training method as described in any one of claims 1 to 6, or, when the computer program is executed by the processor, it implements the question-answering method as described in claim 7.

12. A computer program product, comprising a computer program, characterized in that When the computer program is executed by the processor, it implements the question-answering model training as described in any one of claims 1 to 6, or, when the computer program is executed by the processor, it implements the question-answering method as described in claim 7.

Citation Information

Cited By

  • Large language model negative sample enhancement preference optimization method based on preset error mode

    CN120448546A

  • Negative sample enhancement preference optimization method for large language models based on preset error patterns

    CN120448546B

  • Question and answer model training method and question and answer task processing method

    CN120744074A

  • Training sample generation and model training method and device, storage medium and product

    CN121525752A

  • Training sample generation and model training method and device, storage medium and product

    CN121525752B