Question and answer generation method, device and equipment based on large language model and medium
By introducing the thinking chain model into the question-answering model, the thinking process of the large language model is compressed, solving the problem of long output time of the large language model and realizing the rapid generation of accurate answers.
Patent Information
- Application Number
- CN202410405618.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-03
- Publication Date
- 2025-11-04
- Estimated Expiration
- 2044-04-03
AI Technical Summary
Large language models have long output times and slow response times due to the introduction of thought chains during the generation process, and existing technologies cannot effectively compress the generation time of thought chains.
By inputting the output characters of the question-and-answer model into the thought chain model, a corresponding thought representation is generated, and then input into the question-and-answer model for further character-by-character prediction, thus compressing the thought process of the question-and-answer model and achieving rapid answer generation.
While ensuring the accuracy of the answers, it significantly shortens the output response time of the question-answering model and improves the decoding speed.
Smart Images

Figure CN118093830B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure relates to the technical field of artificial intelligence, and particularly relates to a question answer generation method and device based on a large language model, equipment and a medium. BACKGROUND
[0002] Existing large language models have the ability of a chain of thought (COT), which can improve the performance of a series of downstream tasks such as mathematical reasoning, agent communication and tool use by introducing the process of large model thinking in the generation process.
[0003] However, the large language model with the chain of thought also makes the output of the large language model consume more time, because the large language model adopts a streaming decoding strategy, which will cause the large language model to generate one more character, one more unit of time, that is, the length of the generated character and the generation time are in a linear relationship, thereby causing the response time of the large language model to be slow. SUMMARY
[0004] In order to solve the above technical problems or at least partially solve the above technical problems, the embodiments of the present disclosure provide a question answer generation method and device based on a large language model, equipment and a medium.
[0005] According to an aspect of the present disclosure, a question answer generation method based on a large language model is provided, comprising:
[0006] obtaining a question text to be answered;
[0007] inputting the question text into a pre-trained question and answer model, and performing character-by-character prediction based on the question text by the question and answer model and outputting a current predicted character;
[0008] in response to the current predicted character being a preset target character, inputting the current predicted character and all previous predicted characters output by the question and answer model into a pre-trained chain of thought model, and generating a thinking representation corresponding to the current predicted character based on the current predicted character and all previous predicted characters by the chain of thought model and outputting the thinking representation;
[0009] obtaining the thinking representation output by the chain of thought model and inputting the thinking representation into the question and answer model, and continuing to perform character-by-character prediction based on the question text and the thinking representation by the question and answer model;
[0010] in response to the question and answer model ending character-by-character prediction, generating an answer corresponding to the question text based on all predicted characters output by the question and answer model.
[0011] According to another aspect of the present disclosure, there is provided a question answer generation apparatus based on a large language model, comprising:
[0012] a question obtaining module configured to obtain a question text to be answered;
[0013] a first input module configured to input the question text into a pre-trained question and answer model, and to cause the question and answer model to perform character-by-character prediction based on the question text and output a current predicted character;
[0014] a second input module configured to, in response to the current predicted character being a preset target character, input the current predicted character and all previous predicted characters output by the question and answer model into a pre-trained thought chain model, and to cause the thought chain model to generate a thinking representation corresponding to the current predicted character based on the current predicted character and all previous predicted characters and output the thinking representation;
[0015] a third input module configured to obtain the thinking representation output by the thought chain model and input the thinking representation into the question and answer model, and to cause the question and answer model to continue performing character-by-character prediction based on the question text and the thinking representation;
[0016] an answer generation module configured to, in response to the question and answer model completing character-by-character prediction, generate an answer corresponding to the question text based on all predicted characters output by the question and answer model.
[0017] According to another aspect of the present disclosure, there is provided an electronic device, comprising:
[0018] a processor; and
[0019] a memory storing a program,
[0020] wherein the program includes instructions that, when executed by the processor, cause the processor to perform the question answer generation method based on a large language model according to the foregoing aspect.
[0021] According to another aspect of the present disclosure, there is provided a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause the computer to perform the question answer generation method based on a large language model according to the foregoing aspect.
[0022] According to another aspect of the present disclosure, there is provided a computer program product comprising a computer program, wherein the computer program, when executed by a processor, implements the question answer generation method based on a large language model according to the foregoing aspect.
[0023] One or more technical solutions provided in this disclosure involve obtaining the question text to be answered, inputting the question text into a pre-trained question-answering model, having the question-answering model predict characters one by one based on the question text and outputting the current predicted character, and in response to the current predicted character being a preset target character, inputting the current predicted character output by the question-answering model and all previous predicted characters into a pre-trained thought chain model, having the thought chain model generate and output the thought representation corresponding to the current predicted character based on the current predicted character and all previous predicted characters, then obtaining the thought representation output by the thought chain model and inputting the thought representation into the question-answering model, having the question-answering model continue to predict characters one by one based on the question text and the thought representation, and in response to the end of the character-by-character prediction by the question-answering model, generating the answer corresponding to the question text based on all predicted characters output by the question-answering model. By adopting the scheme disclosed herein, when the question-answering model predicts the target character, it obtains the thought representation corresponding to the target character from the thought chain model and inputs it into the question-answering model to continue the subsequent character prediction. The thought representation can guide the question-answering model to make the correct output. By compressing the thought process of the question-answering model into the target character, and obtaining the corresponding thought representation from the thought chain model when the target character is predicted to guide the subsequent output of the question-answering model, the prediction effect of the question-answering model is guaranteed, while the thought process of the question-answering model is compressed, improving the decoding speed of the question-answering model and thus shortening the output response time of the question-answering model. Attached Figure Description
[0024] Further details, features, and advantages of this disclosure are disclosed in the following description of exemplary embodiments in conjunction with the accompanying drawings, in which:
[0025] Figure 1 A flowchart of a question-answer generation method based on a large language model according to an exemplary embodiment of the present disclosure is shown;
[0026] Figure 2 A flowchart illustrating the training process of a thought chain model and a question-answering model according to an exemplary embodiment of the present disclosure is shown;
[0027] Figure 3 A schematic block diagram of a question-answer generation apparatus based on a large language model according to an exemplary embodiment of the present disclosure is shown;
[0028] Figure 4 A structural block diagram of an exemplary electronic device that can be used to implement embodiments of the present disclosure is shown. Detailed Implementation
[0029] Embodiments of the present disclosure will be described herein below with reference to the drawings. Although certain embodiments of the present disclosure are shown in the drawings, it is understood that the present disclosure can be implemented in various forms and should not be interpreted as being limited to the embodiments set forth herein, but rather these embodiments are provided so as to more thoroughly and completely understand the present disclosure. It is understood that the drawings and embodiments of the present disclosure are merely for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.
[0030] It should be understood that each step recited in the method embodiments of the present disclosure can be performed in different orders and / or in parallel. In addition, the method embodiments can include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.
[0031] The term “comprising” and variations thereof as used herein are open-ended, that is “including but not limited to”. The term “based on” is “based, at least in part, on”. The term “one embodiment” means “at least one embodiment”; the term “another embodiment” means “at least one additional embodiment”; the term “some embodiments” means “at least some embodiments”. Related terms are defined in the following description. It should be noted that the concepts mentioned in the present disclosure are merely for distinguishing different apparatuses, modules or units, and are not intended to limit the functions of these apparatuses, modules or units.
[0032] It should be noted that the modification of “one” or “multiple” mentioned in the present disclosure is illustrative rather than restrictive, and those skilled in the art should understand that “one or more” should be understood unless otherwise explicitly indicated in the context.
[0033] The names of the messages or information exchanged between the plurality of apparatuses in the embodiments of the present disclosure are merely for illustrative purposes, and are not intended to limit the scope of the messages or information.
[0034] Before the embodiments of the present disclosure are explained, the professional terms that can be involved in the embodiments of the present disclosure are explained as follows:
[0035] COT: Chain of Thought, thought chain, refers to the internal and step-by-step reasoning process when solving a problem. When humans solve problems or make decisions, they often go through a series of logical steps or reasoning chains in their minds. Each step is based on the result of the previous step. This process can be conscious or unconscious. In the field of artificial intelligence, especially in natural language processing and machine learning, Chain of Thought refers to a technique that simulates the human thinking process to improve the performance of models on complex tasks.
[0036] PEFT: Parameter Efficient Fine-Tuning, a deep learning technique commonly used to fine-tune a pre-trained large model for specific tasks or datasets while minimizing the need for additional parameters. This approach is particularly popular in natural language processing (NLP) and computer vision (CV) as it leverages the power of large language models while avoiding the massive computational resources required to train a model from scratch. In parameter-efficient fine-tuning, one or more of the following strategies are often employed:
[0037] (1) Adaptive Embedding: In this strategy, only a small portion of the model's weights (usually those most directly related to input or output) are updated during fine-tuning, while the rest remain unchanged;
[0038] (2) Parameter Sharing: In this approach, certain parts of the model share parameters across multiple tasks or datasets to reduce the total number of parameters that need to be trained;
[0039] (3) Compression or Distillation: By distilling the knowledge of a large language model into a smaller one, the number of parameters required for fine-tuning can be reduced;
[0040] (4) Low-Rank Approximation: Decomposing the model's weight matrix into a lower rank to reduce the number of model parameters;
[0041] (5) Parameter Sparsification: Making the weight matrix sparse (i.e., most weights are zero) to reduce the number of parameters that need to be stored and updated;
[0042] (6) Using additional small networks (such as adaptive networks): Instead of directly modifying the pre-trained model's parameters, adding a small trainable network to adjust the pre-trained model's output.
[0043] The goal of these parameter fine-tuning techniques is to maintain the power of pre-trained models while enabling them to quickly adapt to new tasks and reducing computational and storage requirements, which is particularly useful for applications with limited resources or those that want to deploy models on edge devices.
[0044] Existing large language models (LLMs) have the ability to think in chains, which can improve the performance of a variety of downstream tasks such as mathematical reasoning, agent communication, and tool usage by incorporating the process of large model thinking during generation. For example:
[0045] The input question to be solved is: solve (12+3)×15=
[0046] The output of the LLM without a thought chain is: 150
[0047] The output of the LLM with a thought chain is: I need to first calculate 12+3 equals 15, then calculate 15×15, and finally the result is 225.
[0048] As can be seen from the above example, in the second output, the thought chain of the LLM divides the calculation into steps, and the final correct calculation result is obtained. Compared with the output without a thought chain, it has a more accurate result, but generates more characters, which means that it takes more time to generate the final result. Compared with the output of the LLM without a thought chain, the output of the second LLM with a thought chain takes at least 5 times longer, because each character in the output result is generated one by one, and each additional character generated will take one unit of time, that is, the length of the generated characters and the generation time are in a linear relationship. However, the process of the thought chain (i.e., the self-thinking process of the large language model) has some parts that are not visible to the user, such as when the user wants to use the large language model to generate a certain segment of code, before generating the actual code, the large language model will generate some self-thinking processes related to the thought chain, similar to the ideas in the human brain, and then write the code. Therefore, it is necessary to compress the time of the thought chain of the large language model, so that the user can quickly get the accurate answer they want. Based on this, the present disclosure provides a solution that can effectively compress the generation time of the thought chain, while achieving better or the same effect as the generation of the thought chain.
[0049] The problem answer generation method based on a large language model provided by the present disclosure is described below with reference to the accompanying drawings.
[0050] Figure 1 A flowchart of a problem answer generation method based on a large language model according to an example embodiment of the present disclosure is shown, which can be executed by a problem answer generation device based on a large language model provided by an embodiment of the present disclosure. The device can be implemented in software and / or hardware, and can be integrated in an electronic device, such as a computer, a mobile phone, a tablet computer, a server, etc.
[0051] As Figure 1 shown, the problem answer generation method based on a large language model can include the following steps:
[0052] Step 101, obtaining a question text to be solved.
[0053] The user can input a question to be answered into the electronic device through text input, voice input, etc. The electronic device can obtain the question text input by the user or obtain the question text to be answered through voice recognition.
[0054] In step 102, the question text is input into a pre-trained question and answer model, and the question and answer model performs character-by-character prediction based on the question text and outputs a current predicted character.
[0055] The question and answer model is pre-trained, a large language model is trained using constructed question and answer training data, and a trained question and answer model is obtained. The trained question and answer model is used to generate corresponding analysis and answers based on a given question through a character-by-character output method.
[0056] In the embodiments of the present disclosure, the obtained question text can be input into the trained question and answer model, and the question and answer model performs character-by-character prediction based on the received question text and outputs a current predicted character. When the question and answer model performs character prediction, the last predicted character is used as input to predict the current character, and the current predicted character is also used as input to predict the next character.
[0057] In step 103, in response to the current predicted character being a preset target character, the current predicted character and all previous predicted characters output by the question and answer model are input into a pre-trained thought chain model, and the thought chain model generates a thinking representation corresponding to the current predicted character based on the current predicted character and all previous predicted characters and outputs the thinking representation.
[0058] The thought chain model is pre-trained, a large language model is trained using constructed thought chain training data, and a trained thought chain model is obtained. The trained thought chain model is responsible for generating a thinking process, which compresses the thinking process into a special character (i.e., the target character of the embodiments of the present disclosure). The thought chain model can output a thinking representation corresponding to the target character according to the input target character and the characters before it. The thinking representation can represent the thinking process of the question and answer model.
[0059] In the embodiments of the present disclosure, the question and answer model performs character-by-character prediction and outputs a current predicted character in real time. For the current predicted character output by the question and answer model, it is compared with a preset target character (for example, the target character is designed in advance as <special_token>). If the two are identical, it is determined that the current predicted character is the target character. Then, the current predicted character output by the question and answer model and all previous predicted characters, i.e., all predicted characters output by the question and answer model, are input into the pre-trained thought chain model. The thought chain model generates a thinking representation corresponding to the current predicted character based on the input current predicted character and all previous predicted characters, and outputs the thinking representation.
[0060] Step 104: Obtain the thinking representation output by the thinking chain model and input the thinking representation into the question-answering model. The question-answering model then performs character-by-character prediction based on the question text and the thinking representation.
[0061] In this embodiment, after inputting all the predicted characters output by the question-answering model into the thinking chain model, we can wait to obtain the output results of the thinking chain model. When the thinking representation corresponding to the current predicted character output by the thinking chain model is obtained, the thinking representation can be input into the question-answering model, and the question-answering model can continue to perform character-by-character prediction based on the thinking representation and the previously input question text.
[0062] It is understood that in this embodiment, during the process of the question-answering model continuing to predict characters, if the currently predicted character is not the target character, the current character is input into the question-answering model to predict the next character. If the currently predicted character is the target character, all the predicted characters currently output by the question-answering model (including the currently predicted character) are input into the thought chain model, which outputs the thought representation corresponding to the currently predicted character and inputs the thought representation into the question-answering model to predict the next character. The above process is repeated until the question-answering model finishes predicting characters one by one.
[0063] In this embodiment, when the current predicted character output by the question-answering model is the target character, the thinking chain model is used to obtain the thinking representation corresponding to the current predicted character, and the thinking representation is input into the question-answering model to guide the subsequent output results of the question-answering model. This makes the thinking process in the result generated by the question-answering model replaced by the target character, thereby reducing the number of characters that need to be generated, improving the decoding speed, and shortening the output response time of the question-answering model. At the same time, by obtaining the thinking representation corresponding to the target character to guide the output of the question-answering model, the accuracy of the output results of the question-answering model can be guaranteed.
[0064] Step 105: In response to the end of character-by-character prediction by the question-answering model, the answer corresponding to the question text is generated based on all the predicted characters output by the question-answering model.
[0065] In this embodiment of the disclosure, after the question-answering model finishes its character-by-character prediction, for example, when the question-answering model does not output any more predicted characters after a preset time interval, i.e., the timing starts from the last time the question-answering model outputs a predicted character, if no new predicted character is detected when the preset time interval is reached, it is determined that the question-answering model has finished its character-by-character prediction. At this time, the answer corresponding to the question text can be generated based on all the predicted characters output by the question-answering model.
[0066] As an example, the order of each predicted character output by the question and answer model can be spliced in sequence to obtain an answer corresponding to the question text. In this case, the output answer contains the preset target character.
[0067] As another example, the order of each predicted character output by the question and answer model can be spliced in sequence, and the target character therein can be removed to obtain an answer corresponding to the question text. In this case, the output answer does not contain the preset target character, and this output effect is more user-friendly.
[0068] The question and answer generation method based on a large language model according to the embodiments of the present disclosure includes: obtaining a question text to be answered, inputting the question text into a pre-trained question and answer model, and outputting a current predicted character by the question and answer model based on the question text; in response to the current predicted character being a preset target character, inputting the current predicted character and all previous predicted characters output by the question and answer model into a pre-trained thought chain model, and outputting a thought representation corresponding to the current predicted character by the thought chain model based on the current predicted character and all previous predicted characters; then obtaining the thought representation output by the thought chain model and inputting the thought representation into the question and answer model, and continuing to perform character-by-character prediction by the question and answer model based on the question text and the thought representation; in response to the character-by-character prediction by the question and answer model ending, generating an answer corresponding to the question text based on all predicted characters output by the question and answer model. When the question and answer model predicts the target character, the thought representation corresponding to the target character is obtained from the thought chain model and input into the question and answer model to continue to predict the next character. The thought representation can guide the question and answer model to output correctly. By compressing the thinking process of the question and answer model into the target character, the corresponding thought representation is obtained from the thought chain model when the target character is predicted to guide the subsequent output of the question and answer model, so as to ensure the prediction effect of the question and answer model, compress the thinking process of the question and answer model, improve the decoding speed of the question and answer model, and shorten the output response time of the question and answer model.
[0069] In an optional embodiment of the present disclosure, the thought chain model and the question and answer model used in the embodiments of the present disclosure can be obtained by training through the steps shown in Figure 2
[0070] Step 201, obtaining original sample data, the original sample data including a sample question and an analysis text corresponding to the sample question.
[0071] In the embodiments of the present disclosure, data can be obtained from an existing data set as original sample data according to application requirements. For example, the application requirement is to solve mathematical problems by using a large language model, and the original sample data can be obtained from the GSM8K data set, so that the trained question and answer model can generate corresponding analysis and answers according to the input mathematical problem text.
[0072] In the embodiments, the original sample data includes a sample question and analysis text corresponding to the sample question, and can also include a corresponding answer. For example, one of the original sample data obtained from the GSM8K data set is as follows:
[0073] Question: Mr. Sam shared a certain amount of money between his two sons, Ken and Tony. If Ken got $1750, and Tony got twice as much as Ken, how much was the money shared?
[0074] Analysis: Tony got twice $1750 which is 2 * $1750 = $3500 The total amount shared was $1750 + $3500 = $5250 Answer: 5250.
[0075] In the above example, the text corresponding to Question is the sample question, and the text corresponding to Analysis is the analysis text corresponding to the sample question.
[0076] In step 202, a format conversion prompt text is generated based on the analysis text and a preset format conversion template, the format conversion prompt text being used to instruct a pre-trained conversion model to convert the analysis text into a text in a target format.
[0077] The format conversion template can be pre-designed according to actual requirements, and the format conversion template includes target format requirements and an input field that the conversion model needs to output, the input field being used to receive the analysis text. The format conversion template can also include an output example for the conversion model to better learn the target format. Using the format conversion template to guide the output of the conversion model can obtain the text in the desired target format. The format conversion template can be obtained when training the conversion model.
[0078] Exemplarily, the conversion model can employ GPT4. When training GPT4 with training data to obtain the conversion model, a format conversion template can be pre-written, the analysis text to be converted in the training data can be added to the format conversion template, and GPT4 can be trained by inputting the format conversion template. By continuously adjusting the parameters of GPT4 and optimizing the format conversion template, a final trained conversion model and a high-quality format conversion template can be obtained. The current format conversion template can be saved for use in actual question and answer scenarios.
[0079] In this embodiment, after obtaining the original sample data, the analysis text in the original sample data can be added to the input field in the format conversion template to obtain a format conversion prompt text. The format conversion prompt text is used to instruct the pre-trained conversion model to convert the analysis text into a text in a target format.
[0080] In step 203, the format conversion prompt text is input into the conversion model, and a target format text obtained by the conversion model converting the analysis text under the guidance of the format conversion prompt text is acquired. The target format text includes a preset character group, and the text wrapped by the preset character group represents a thinking process.
[0081] In the embodiments of the present disclosure, after obtaining the format conversion prompt text, the format conversion prompt text can be input into the pre-trained conversion model. The conversion model converts the analysis text under the guidance of the format conversion prompt text to obtain a target format text, and outputs the target format text.
[0082] The target format text includes a preset character group, and the text wrapped by the preset character group represents a thinking process. For example, the preset character group can be pre-set as <thought>< / thought> , and the text located between <thought>And< / thought> represents a thinking process and can be compressed.
[0083] Continuing with the above example of the original sample data, after generating the format conversion prompt text based on the above analysis text (i.e., the content of Analysis) and the pre-set format conversion template, the content of Analysis can be rewritten into a target format text by inputting the format conversion prompt text into the trained conversion model. Specifically, the target format text is: "The problem involves finding out how much money Mr. Sam shared between his two sons, given that Ken received a certain amount, and Tony received twice as much as Ken.\\n <thought>Firstly, since Tony got twice as much money as Ken did, we can find out how much Tony got by multiplying Ken's share by 2.< / thought> \\n<equation>Tony's share = 2 * $1750 = $3500< / equation> \\n <thought>Next, to find out the total amount of money shared by Mr. Sam between his two sons, we add up what each son received.< / thought> \\n <equation>Total amount shared = $1750 (Ken's share) + $3500 (Tony's share) = $5250< / equation> So, Mr. Sam shared a total of $5250 between his two sons. The target format text contains the preset character group " <thought>< / thought> "The text in the package represents the thought process. The target format text contains two paragraphs representing the thought process, which can be compressed. The remaining text can serve as useful model response content, i.e., the content that the user wants to see."
[0084] Step 204: Construct mind chain training data and question-answering training data based on the sample questions and the target format text.
[0085] In this embodiment of the disclosure, after obtaining the target format text, thought chain training data and question-answering training data can be constructed based on the sample questions and the target format text.
[0086] In one optional embodiment of this disclosure, when constructing training data for a thought chain based on sample questions and target format text, a preset character group can be searched in the target format text. The current preset character group and the text it encloses are identified as the thought text, and all text preceding the thought text in the target format text is obtained as the description text. Then, the sample question and the description text are concatenated to obtain input data, and the target character is concatenated with the thought text to obtain output data. Based on the input data and the output data, a thought chain training data is constructed. The target character is consistent with the target character described in the preceding embodiments, for example, [example character].<special_token> .
[0087] Continuing with the example of the target format text mentioned above, when the first preset character group is found, the determined thought text is " <thought>Firstly, since Tony got twice as much money as Ken did, we can find out how much Tony got by multiplying Ken's share by 2.< / thought> Using all the preceding text, namely "The problem involves finding out how much money Mr. Sam shared between his two sons, given that Ken received a certain amount, and Tony received twice as much as Ken," as the descriptive text, the resulting training data for a thought chain is:
[0088] Input: Mr. Sam shared a certain amount of money between his two sons, Ken and Tony. If Ken got $1750, and Tony got twice as much as Ken, how much was the money shared?
[0089] The problem involves finding out how much money Mr. Sam shared between his two sons, given that Ken received a certain amount, and Tony received twice as much as Ken.
[0090] Output: <special_token> <thought>Firstly, since Tony got twice as much money as Ken did, we can find out how much Tony got by multiplying Ken's share by 2.< / thought> .
[0091] When the second preset character group is found, the determined thinking text is "Mr. Sam shared a certain amount of money between his two sons, Ken and Tony. If Ken got $1750, and Tony got twice as much as Ken, how much was the money shared?", and all the text before the text in the target format text is taken as the description text, which contains the previous thinking text. <thought>Next, to find out the total amount of money shared by Mr. Sam between his two sons, we add up what each son received.< / thought>
[0092] Further, in an optional embodiment of the present disclosure, in order to better compress the thinking process, when obtaining the description text, all the text before the thinking text in the target format text can be obtained first, and it is detected whether the preset character group is contained in all the text. In response to the fact that the preset character group is contained in all the text, the preset character group and the text wrapped by the preset character group contained in the current all text are replaced by the target character to obtain the description text; in response to the fact that the preset character group is not contained in all the text, all the text is determined as the description text.
[0093] Continue to take the above target format text as an example, when the first preset character group is found, it is determined that the preset character group is not contained in all the text before the thinking text, and the all text is the description text, and the generated thought chain training data is consistent with the foregoing. When the second preset character group is found, the determined thinking text is "Mr. Sam shared a certain amount of money between his two sons, Ken and Tony. If Ken got $1750, and Tony got twice as much as Ken, how much was the money shared?", and the generated thought chain training data is consistent with the foregoing. <thought>Next, to find out the total amount of money shared by Mr. Sam between his two sons, we add up what each son received.< / thought> ", all the text before the thinking text in the target format text is "The problem involves finding out how much money Mr. Sam shared between his two sons, given that Ken received a certain amount, and Tony received twice as much as Ken.\\n <thought>Firstly, since Tony got twice as much money as Ken did, we can find out how much Tony got by multiplying Ken's share by 2.< / thought> \\n <equation>Tony's share = 2 * $1750 = $3500< / equation> \\n", it can be seen that the all text contains a preset character group, so the preset character group and the text wrapped therein are replaced by a target character, and the description text is "The problem involves finding out how much money Mr. Sam shared between his two sons, given that Ken received a certain amount, and Tony received twice as much as Ken.\\n<special_token>\\n <equation>Tony's share = 2 * $1750 = $3500< / equation> \\n", and finally a piece of thinking chain training data is constructed:
[0094] Input: Mr. Sam shared a certain amount of money between his two sons, Ken and Tony. If Ken got $1750, and Tony got twice as much as Ken, how much was the money shared?
[0095] The problem involves finding out how much money Mr. Sam shared between his two sons, given that Ken received a certain amount, and Tony received twice as much as Ken.\\n<special_token>\\n <equation>Tony's share = 2 * $1750 = $3500< / equation> \\n
[0096] Output: <thought>Next, to find out the total amount of money shared by Mr. Sam between his two sons, we add up what each son received.< / thought> .
[0097] In an optional implementation of the present disclosure, when constructing the question and answer training data based on the sample question and the target format text, a preset character group in the target format text can be found, the found current preset character group and the text wrapped thereby are replaced by a target character, and in response to all preset character groups in the target format text and the text wrapped thereby being replaced by the target character, a thought chain compression text is obtained, and then based on the sample question and the thought chain compression text, a question and answer training data is constructed.
[0098] Continuing with the above example of the target format text, the preset character group is <thought>< / thought> , by finding the preset character group and the text wrapped thereby in the target format text and replacing it with a target character, the thought chain compression text is obtained as: "The problem involves finding out how much money Mr. Sam shared between his two sons, given that Ken received a certain amount, and Tony received twice as much as Ken. \\n<special_token>\\n <equation>Tony's share = 2 * $1750 = $3500< / equation> \\n<special_token>\\n <equation>Total amount shared = $1750 (Ken's share) + $3500 (Tony's share) = $5250< / equation> \\n\\nSo, Mr. Sam shared a total of $5250 between his two sons." Thus, a question and answer training data constructed is as follows:
[0099] Question: Mr. Sam shared a certain amount of money between his two sons, Ken and Tony. If Ken got $1750, and Tony got twice as much as Ken, how much was the money shared?
[0100] Output: The problem involves finding out how much money Mr. Sam shared between his two sons, given that Ken received a certain amount, and Tony received twice as much as Ken. \\n<special_token>\\n <equation>Tony's share = 2 * $1750 = $3500< / equation> \\n<special_token>\\n<equation>Total amount shared = $1750 (Ken's share) + $3500 (Tony's share) = $5250< / equation> \\n\\nSo,Mr.Sam shareda total of$5250between his two sons.
[0101] In step 205, the thought chain model is trained based on the thought chain training data.
[0102] In the embodiments of the present disclosure, after obtaining the thought chain training data, the model training can be performed based on the thought chain training data to obtain the thought chain model.
[0103] In an optional embodiment of the present disclosure, when the thought chain model is trained, the thought chain training data can be input into a pre-trained model for output prediction, and the character representation corresponding to the target character, the thinking representation corresponding to the thinking text and the prediction result output by the pre-trained model are obtained. Based on the prediction result, the character representation, the thinking representation and the output data in the thought chain training data, the loss value of the pre-trained model is determined, and in the case that the loss value of the pre-trained model is greater than a first preset value, the parameters of the pre-trained model are adjusted and iteratively trained until the loss value of the pre-trained model is not greater than the first preset value, thereby obtaining the trained thought chain model. The pre-trained model can use a commonly used large language model, the first preset value can be pre-set according to actual needs, the prediction result is the final output prediction result of the pre-trained model based on the input data, the thinking representation is the output representation generated by the pre-trained model based on the input thinking text, and the character representation is the output representation generated by the pre-trained model based on the input target character.
[0104] Further, in an optional embodiment of the present disclosure, in order to better align the target character with the thinking process and improve the effect of the trained thought chain model, the loss of the pre-training model can be designed to include two parts. One part is the LLM loss, which is calculated by cross-entropy based on the predicted output and the target output. The other part is the alignment loss, which is expected to align the target character in the thought chain training data with the corresponding thinking text. The alignment loss uses the mean square error (MSE). Finally, the loss value of the pre-training model is determined according to the two parts of the loss. Thus, in the present embodiment, when determining the loss value of the pre-training model, the cross-entropy loss of the pre-training model can be calculated based on the output data and the prediction result to obtain a first loss value. In addition, the obtained thinking representation is subjected to mean pooling to obtain a pooled representation. Then, based on the pooled representation and the character representation, the mean square error loss of the pre-training model is calculated to obtain a second loss value. Finally, the first loss value and the second loss value are weighted and summed to obtain the loss value of the pre-training model. The weight values corresponding to the cross-entropy loss (corresponding to the first loss value) and the mean square error loss (corresponding to the second loss value) can be pre-set according to actual requirements. For example, the weights of the two can be set to be consistent, both being 0.5. Alternatively, the weight value of the mean square error loss can be set to be greater than the weight value of the cross-entropy loss to ensure the alignment effect of the target character and the thinking process.
[0105] Step 206, based on the question and answer training data and the thought chain model, training the question and answer model.
[0106] In the embodiments of the present disclosure, after obtaining the question and answer training data, the question and answer model can be trained based on the question and answer training data and the thought chain model.
[0107] In an optional embodiment of the present disclosure, when training the question and answer model, the sample question can be input into the initial large language model, the initial large language model can perform character-by-character prediction based on the sample question, and output the current character; in the case that the current character is the target character, the characters that have been output by the initial large language model are input into the pre-trained thought chain model to obtain the thinking representation of the current character, and the thinking representation of the current character is input into the initial large language model to continue character-by-character prediction. If the predicted character is not the target character, the predicted character is input as the input for the prediction of the next character, and if the predicted character is the target character, the current character and all the characters before it are input into the thought chain model to obtain the thinking representation of the current character and input into the initial large language model to continue character-by-character prediction. In this way, after the initial large language model stops outputting characters, the loss value of the initial large language model is calculated based on all the characters output by the initial large language model and the thought chain compressed text, and in the case that the loss value of the initial large language model is greater than a second preset value, the parameters of the initial large language model are adjusted and iteratively trained until the loss value of the initial large language model is not greater than the second preset value, and a trained question and answer model is obtained. The initial large language model can use a commonly used large language model, and the second preset value can be pre-set according to actual needs. When calculating the loss value of the initial large language model, a conventional loss function of the large language model can be used for calculation, and the present disclosure does not limit the specific loss function used.
[0108] It should be noted that in the present embodiment, when training the question and answer model, the trained thought chain model is used to obtain the thinking representation corresponding to the target character during the training process. The thought chain model has been trained and completed, and therefore the parameters of the thought chain model are frozen and not updated during the training process of the question and answer model, and only the parameters of the initial large language model are fine-tuned.
[0109] The training manner of the thought chain model and the question and answer model provided by the embodiments of the present disclosure is as follows: original sample data is obtained, the original sample data including a sample question and analysis text corresponding to the sample question; a format conversion prompt text is generated based on the analysis text and a preset format conversion template, the format conversion prompt text being used to instruct a pre-trained conversion model to convert the analysis text into a text in a target format; the format conversion prompt text is input into the conversion model, and a target format text obtained by the conversion model converting the analysis text under the guidance of the format conversion prompt text is obtained, wherein the target format text includes a preset character group, and the text wrapped by the preset character group represents a thinking process; then, thought chain training data and question and answer training data are constructed based on the sample question and the target format text; then, the thought chain model is trained based on the thought chain training data; and the question and answer model is trained based on the question and answer training data and the thought chain model. In this way, the analysis text in the original sample data is converted into the target format text to construct the thought chain training data and the question and answer training data, thereby providing data support for subsequently training the thought chain model capable of compressing the thinking process into the target character and the question and answer model capable of outputting the compressed thought chain. Moreover, the thinking process corresponding to the thought chain model is provided by training the thought chain model to provide the question and answer model, so that the question and answer model can still obtain a result as good as or better than the thought chain generation without outputting the thinking process, and can quickly feed back an accurate answer to the user.
[0110] The present disclosure also provides a question and answer generation device based on a large language model. Figure 3 A schematic block diagram of a question and answer generation device based on a large language model according to an exemplary embodiment of the present disclosure is shown in FIG. 3. Figure 3 As shown in FIG. 3, the question and answer generation device 30 based on a large language model includes a question obtaining module 310, a first input module 320, a second input module 330, a third input module 340, and an answer generation module 350.
[0111] The question obtaining module 310 is configured to obtain a question text to be answered.
[0112] The first input module 320 is configured to input the question text into a pre-trained question and answer model, and to output a current predicted character by the question and answer model based on the question text.
[0113] The second input module 330 is configured to input the current predicted character and all previous predicted characters output by the question and answer model into a pre-trained thought chain model in response to the current predicted character being a preset target character, and to output a thinking representation corresponding to the current predicted character by the thought chain model based on the current predicted character and all previous predicted characters.
[0114] The third input module 340 is configured to acquire the thinking representation output by the thinking chain model and input the thinking representation into the question and answer model, and the question and answer model continues character-by-character prediction based on the question text and the thinking representation;
[0115] The answer generation module 350 is configured to, in response to the end of the character-by-character prediction of the question and answer model, generate an answer corresponding to the question text based on all predicted characters output by the question and answer model.
[0116] Optionally, the question and answer generation device based on a large language model 30 further comprises:
[0117] The original data acquisition module is configured to acquire original sample data, and the original sample data includes a sample question and analysis text corresponding to the sample question;
[0118] The prompt text generation module is configured to generate a format conversion prompt text based on the analysis text and a preset format conversion template, and the format conversion prompt text is used to instruct a pre-trained conversion model to convert the analysis text into a text in a target format;
[0119] The format conversion module is configured to input the format conversion prompt text into the conversion model, and acquire a target format text obtained by the conversion model in the guidance of the format conversion prompt text and based on format conversion of the analysis text, wherein the target format text includes a preset character group, and the text wrapped by the preset character group represents a thinking process;
[0120] The training data construction module is configured to construct thinking chain training data and question and answer training data based on the sample question and the target format text;
[0121] The thinking chain model training module is configured to train the thinking chain model based on the thinking chain training data;
[0122] The question and answer model training module is configured to train the question and answer model based on the question and answer training data and the thinking chain model.
[0123] Optionally, the training data construction module is further configured to:
[0124] Find the preset character group in the target format text, and determine the found current preset character group and the text wrapped by the current preset character group as a thinking text;
[0125] Acquire all texts before the thinking text in the target format text as a description text;
[0126] Splice the sample question and the description text to obtain input data;
[0127] Splice the target character with the thinking text to obtain output data;
[0128] Based on the input data and the output data, a thought chain training data is constructed.
[0129] Optionally, the training data construction module is further used to:
[0130] Obtain all texts before the thinking text in the target format text;
[0131] Detect whether the all texts contain the preset character set;
[0132] In response to the all texts containing the preset character set, the preset character set contained in the all texts and the text wrapped by the preset character set are replaced by the target character to obtain the description text;
[0133] In response to the all texts not containing the preset character set, the all texts are determined as the description text.
[0134] Optionally, the thought chain model training module is further used to:
[0135] Input the thought chain training data into a pre-training model for output prediction, and obtain character representation corresponding to the target character, thinking representation corresponding to the thinking text and prediction result output by the pre-training model;
[0136] Based on the prediction result, the character representation, the thinking representation and the output data, a loss value of the pre-training model is determined;
[0137] In the case that the loss value of the pre-training model is greater than a first preset value, the parameters of the pre-training model are adjusted and iteratively trained until the loss value of the pre-training model is not greater than the first preset value, and a trained thought chain model is obtained.
[0138] Optionally, the thought chain model training module is further used to:
[0139] Based on the output data and the prediction result, a cross-entropy loss of the pre-training model is calculated to obtain a first loss value;
[0140] Average pooling is performed on the thinking representation to obtain a pooling representation;
[0141] Based on the pooling representation and the character representation, a mean square error loss of the pre-training model is calculated to obtain a second loss value;
[0142] The first loss value and the second loss value are weighted and summed to obtain a loss value of the pre-training model.
[0143] Optionally, the training data construction module is further configured to:
[0144] find the preset character set in the target format text, and replace the found current preset character set and the text wrapped thereby with the target character;
[0145] obtain a thought chain compressed text in response to all the preset character sets and the text wrapped thereby in the target format text being replaced with the target character.
[0146] construct a piece of question and answer training data based on the sample question and the thought chain compressed text.
[0147] Optionally, the question and answer model training module is further configured to:
[0148] input the sample question into an initial large language model, perform character-by-character prediction based on the sample question by the initial large language model, and output a current character;
[0149] in a case where the current character is the target character, input the current character output by the initial large language model into the thought chain model to obtain a thinking representation of the current character;
[0150] input the thinking representation of the current character into the initial large language model to continue performing character-by-character prediction;
[0151] after the initial large language model stops outputting characters, calculate a loss value of the initial large language model based on all the characters output by the initial large language model and the thought chain compressed text;
[0152] in a case where the loss value of the initial large language model is greater than a second preset value, adjust parameters of the initial large language model and perform iterative training until the loss value of the initial large language model is not greater than the second preset value, to obtain a trained question and answer model.
[0153] The question and answer generation apparatus based on a large language model provided in the embodiments of the present disclosure can perform any question and answer generation method based on a large language model applicable to an electronic device provided in the embodiments of the present disclosure, and has function modules and beneficial effects corresponding to the execution method. The contents not described in detail in the apparatus embodiments of the present disclosure can be referred to the description in any method embodiments of the present disclosure.
[0154] The exemplary embodiments of the present disclosure further provide an electronic device, comprising: at least one processor; and a memory connected with the at least one processor in communication. The memory stores a computer program capable of being executed by the at least one processor, and the computer program, when executed by the at least one processor, is configured to cause the electronic device to perform the question-answer generation method based on a large language model according to the embodiments of the present disclosure.
[0155] The exemplary embodiments of the present disclosure further provide a non-transitory computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor of a computer, is configured to cause the computer to perform the question-answer generation method based on a large language model according to the embodiments of the present disclosure.
[0156] The exemplary embodiments of the present disclosure further provide a computer program product comprising a computer program, wherein the computer program, when executed by a processor of a computer, is configured to cause the computer to perform the question-answer generation method based on a large language model according to the embodiments of the present disclosure.
[0157] Reference Figure 4 A block diagram of the structure of an electronic device 1100 that can be a server or a client of the present disclosure, which is an example of a hardware device that can be applied to aspects of the present disclosure, will now be described. The electronic device is intended to represent a wide variety of digital electronic computer devices, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device can also represent a wide variety of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components, their connections, and their functions, as shown in the figures, and their functions, are by way of example only and without limitation, as described and / or claimed in the present disclosure.
[0158] As Figure 4 shown, the electronic device 1100 includes a computing unit 1101 that can perform various appropriate actions and processes in accordance with a computer program stored in a read-only memory (ROM) 1102 or a computer program loaded from a storage unit 1108 into a random access memory (RAM) 1103. In the RAM 1103, various programs and data required for the operation of the device 1100 can also be stored. The computing unit 1101, the ROM 1102, and the RAM 1103 are connected to each other through a bus 1104. An input / output (I / O) interface 1105 is also connected to the bus 1104.
[0159] The plurality of components in the electronic device 1100 are connected to the I / O interface 1105, including an input unit 1106, an output unit 1107, a storage unit 1108, and a communication unit 1109. The input unit 1106 can be any type of device that can input information to the electronic device 1100, and can receive inputted digital or character information, and generate key signal inputs related to user settings and / or function controls of the electronic device. The output unit 1107 can be any type of device that can present information, and can include, but is not limited to, a display, a speaker, a video / audio output terminal, a vibrator, and / or a printer. The storage unit 1108 can include, but is not limited to, a magnetic disk, an optical disk. The communication unit 1109 allows the electronic device 1100 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks, and can include, but is not limited to, a modem, a network card, an infrared communication device, a wireless communication transceiver, and / or a chipset, such as a Bluetooth™ device, a WiFi device, a WiMax device, a cellular communication device, and / or the like.
[0160] The computing unit 1101 can be various general and / or special purpose processing components with processing and computing capabilities. Some examples of the computing unit 1101 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The computing unit 1101 performs various methods and processes described above. For example, in some embodiments, the large language model based question answer generation method can be implemented as a computer software program, which is tangibly embodied in a machine-readable medium, such as the storage unit 1108. In some embodiments, part or all of the computer program can be loaded and / or installed onto the electronic device 1100 via the ROM 1102 and / or the communication unit 1109. In some embodiments, the computing unit 1101 can be configured to perform the large language model based question answer generation method by any other appropriate means, such as by means of firmware.
[0161] Program code for carrying out methods of the present disclosure can be written in any combination of one or more programming languages. The program code can be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the program code, when executed by the processor or controller, produces a function / operation specified in the flowchart and / or block diagram. The program code can be executed entirely on a machine, partially on a machine, partially on a machine as a stand-alone software package, partially on a machine and partially on a remote machine or entirely on a remote machine or server.
[0162] In the context of this disclosure, a machine-readable medium can be a tangible medium that contains or stores a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include but is not limited to an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium will include one or more lines of electrical connections, portable computer disks, hard disk drives, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or Flash memory), optical fibers, portable compact disc read-only memories (CD-ROMs), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0163] As used in this disclosure, the terms "machine-readable medium" and "computer- readable medium" refer to any computer program product, apparatus and / or device (e.g., magnetic discs, optical disks, memory, Programmable Logic Devices (PLDs)) used to provide machine instructions and / or data to a programmable processor, including a machine-readable medium that receives machine instructions as a machine-readable signal. The term "machine-readable signal" refers to any signal used to provide machine instructions and / or data to a programmable processor.
[0164] To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the computer. Other kinds of devices can be used to provide for interaction with a user as well; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form, including acoustic, speech, or tactile input.
[0165] The systems and techniques described here can be implemented in a computing system that includes a back end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front end component (e.g., a user computer having a graphical user interface or a Web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back end, middleware, or front end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network (LAN), a wide area network (WAN), and the Internet.
[0166] The computing system can include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other.
Claims
1. A question answer generation method based on a large language model, wherein, The method comprises: acquiring a question text to be answered; inputting the question text into a pre-trained question and answer model, performing character-by-character prediction based on the question text by the question and answer model, and outputting a current predicted character; in response to the current predicted character being a preset target character, inputting the current predicted character and all previous predicted characters output by the question and answer model into a pre-trained thought chain model, generating a thinking representation corresponding to the current predicted character based on the current predicted character and all previous predicted characters by the thought chain model, and outputting the thinking representation; acquiring the thinking representation output by the thought chain model and inputting the thinking representation into the question and answer model, continuing to perform character-by-character prediction based on the question text and the thinking representation by the question and answer model; in response to the question and answer model ending character-by-character prediction, generating an answer corresponding to the question text based on all predicted characters output by the question and answer model; wherein the thought chain model is obtained based on thought chain training data, and the thought chain training data comprises output data obtained by splicing the target character and a thinking text; training the thought chain model based on the thought chain training data comprises: inputting the thought chain training data into a pre-training model to perform output prediction, and acquiring a character representation corresponding to the target character, a thinking representation corresponding to the thinking text, and a prediction result output by the pre-training model; determining a loss value of the pre-training model based on the prediction result, the character representation, the thinking representation corresponding to the thinking text, and the output data; in a case where the loss value of the pre-training model is greater than a first preset value, adjusting parameters of the pre-training model and performing iterative training until the loss value of the pre-training model is not greater than the first preset value, to obtain a trained thought chain model. 2.The large language model-based question answer generation method of claim 1, wherein, The thought chain model and the question and answer model are trained in the following manner: acquiring original sample data, the original sample data comprising a sample question and an analysis text corresponding to the sample question; generating a format conversion prompt text based on the analysis text and a preset format conversion template, the format conversion prompt text being used to instruct a pre-trained conversion model to convert the analysis text into a text in a target format; inputting the format conversion prompt text into the conversion model, and acquiring a target format text obtained by the conversion model performing format conversion on the analysis text under the guidance of the format conversion prompt text, wherein the target format text comprises a preset character group, and a text wrapped by the preset character group represents a thinking process; constructing thought chain training data and question and answer training data based on the sample question and the target format text; training the thought chain model based on the thought chain training data; training the question and answer model based on the question and answer training data and the thought chain model. 3.The method of claim 2, wherein, The constructing of the thought chain training data based on the sample question and the target format text comprises: finding the preset character set in the target format text, determining the found current preset character set and the text wrapped thereby as a thinking text; obtaining all texts before the thinking text in the target format text as a description text; splicing the sample question and the description text to obtain input data; splicing the target character and the thinking text to obtain output data; based on the input data and the output data, constructing a thought chain training data.
4. The large language model-based question answer generation method of claim 3, wherein, The method comprises the following steps: obtaining all texts before the thinking text in the target format text; detecting whether the all texts contain the preset character set; in response to the all texts containing the preset character set, replacing the preset character set contained in the all texts and the text wrapped thereby with a target character to obtain the description text; in response to the all texts not containing the preset character set, determining the all texts as the description text. 5.The method of claim 1, wherein, The method comprises the following steps: based on the output data and the prediction result, calculating the cross-entropy loss of the pre-training model to obtain a first loss value; averaging pooling the thinking representation to obtain a pooling representation; based on the pooling representation and the character representation, calculating the mean square error loss of the pre-training model to obtain a second loss value; weighting and summing the first loss value and the second loss value to obtain the loss value of the pre-training model.
6. The large language model-based question answer generation method of any one of claims 2-4, wherein, The method comprises the following steps: finding the preset character set in the target format text, replacing the found current preset character set and the text wrapped thereby with the target character; in response to all the preset character sets in the target format text and the texts wrapped thereby being replaced with the target character, obtaining a thought chain compressed text; based on the sample question and the thought chain compressed text, constructing a question and answer training data.
7. The large language model-based question answer generation method of claim 6, wherein, The method comprises the following steps: inputting the sample question into an initial large language model, performing character-by-character prediction based on the sample question by the initial large language model, and outputting a current character; in the case that the current character is the target character, inputting the characters currently output by the initial large language model into the thought chain model to obtain a thinking representation of the current character; inputting the thinking representation of the current character into the initial large language model to continue character-by-character prediction; after the initial large language model stops outputting characters, calculating a loss value of the initial large language model based on all characters output by the initial large language model and the thought chain compressed text; In a case where the loss value of the initial large language model is greater than a second preset value, parameters of the initial large language model are adjusted and iterative training is performed until the loss value of the initial large language model is not greater than the second preset value, so as to obtain the trained question and answer model.
8. A question answer generation apparatus based on a large language model, wherein, The device comprises: a question obtaining module configured to obtain a question text to be answered; a first input module configured to input the question text into a pre-trained question and answer model, and configured to cause the question and answer model to perform character-by-character prediction based on the question text and output a current predicted character; a second input module configured to, in response to the current predicted character being a preset target character, input the current predicted character output by the question and answer model and all previous predicted characters into a pre-trained thought chain model, and configured to cause the thought chain model to generate a thinking representation corresponding to the current predicted character based on the current predicted character and all previous predicted characters and output the thinking representation; a third input module configured to obtain the thinking representation output by the thought chain model and input the thinking representation into the question and answer model, and configured to cause the question and answer model to continue performing character-by-character prediction based on the question text and the thinking representation; an answer generating module configured to, in response to the question and answer model ending the character-by-character prediction, generate an answer corresponding to the question text based on all predicted characters output by the question and answer model; wherein the thought chain model is obtained based on thought chain training data, and the thought chain training data comprises output data obtained by splicing the target character and a thinking text; The device further comprises a thought chain model training module configured to: input the thought chain training data into a pre-training model to perform output prediction, and obtain a character representation corresponding to the target character, a thinking representation corresponding to the thinking text, and a prediction result output by the pre-training model; determine a loss value of the pre-training model based on the prediction result, the character representation, the thinking representation corresponding to the thinking text, and the output data; in a case where the loss value of the pre-training model is greater than a first preset value, adjust parameters of the pre-training model and perform iterative training until the loss value of the pre-training model is not greater than the first preset value, so as to obtain the trained thought chain model.
9. An electronic device comprising: a processor; and a memory storing a program, wherein the program includes instructions that, when executed by the processor, cause the processor to perform the question and answer generation method based on a large language model according to any one of claims 1-7.
10. A non-transitory computer readable storage medium having stored thereon computer instructions, wherein, The computer instructions are used to cause the computer to perform the question and answer generation method based on a large language model according to any one of claims 1-7.
Citation Information
Patent Citations
Human-computer dialogue method, dialogue network model training method, and apparatus
US20250252267A1