Text generation method, text generation model training method and device
By automatically generating a sequence of solution steps for a problem and utilizing a text generation model and a text generation model trained by reinforcement learning, the problem of inaccurate answers given by large language models in complex problem processing is solved, and efficient and low-cost thought chain prompt text generation is achieved.
Patent Information
- Application Number
- CN202410572183.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-30
- Publication Date
- 2025-09-09
- Estimated Expiration
- 2043-06-30
AI Technical Summary
In the existing technology, large language models lack logical basis or give factually incorrect answers when dealing with complex problems. In addition, the cost of constructing thought chain prompt text is high, making it difficult to quickly generate large amounts of data.
The text generation method automatically generates a sequence of solution steps for the problem. The text generation model and the text generation model trained by the reinforcement learning strategy are used to generate thought chain prompt text to guide the large language model to gradually infer the answer.
Efficiently constructing large quantities of machine question-answering prompt texts with answer steps improves the accuracy and generation efficiency of answers to complex questions and reduces manual labeling costs.
Smart Images

Figure CN118312598B_ABST
Abstract
Description
[0001] This application is a divisional application of the Chinese invention patent application with the application date of June 30, 2023, application number 202310797048.9, and invention name “Text generation method, training method and device for text generation model”. Technical Field
[0002] The present disclosure relates to the field of artificial intelligence technology, in particular to technical fields such as natural language processing, deep learning, and reinforcement learning, and specifically to a text generation method and device, a text generation model training method and device, an electronic device, a computer-readable storage medium, and a computer program product. Background Art
[0003] Artificial Intelligence (AI) is the study of how computers can simulate certain human thought processes and intelligent behaviors (such as learning, reasoning, thinking, and planning). This discipline encompasses both hardware and software technologies. AI hardware technologies generally include sensors, specialized AI chips, cloud computing, distributed storage, and big data processing. AI software technologies primarily encompass computer vision, speech recognition, natural language processing, machine learning / deep learning, big data processing, and knowledge graphs.
[0004] Large language models (LLMs) are deep learning models trained using large amounts of text data. They can generate natural language text or understand its meaning. Large language models can handle a variety of natural language tasks, such as text classification, text generation, question answering, and conversation, and are a key path to artificial intelligence.
[0005] The approaches described in this section are not necessarily approaches that have been previously conceived or employed. Unless otherwise indicated, it should not be assumed that any approach described in this section is prior art simply by virtue of its inclusion in this section. Similarly, unless otherwise indicated, the issues raised in this section should not be considered as having been recognized in any prior art. Summary of the Invention
[0006] The present disclosure provides a text generation method and device, a text generation model training method and device, an electronic device, a computer-readable storage medium, and a computer program product.
[0007] According to one aspect of the present disclosure, a text generation method is provided, comprising: obtaining a first question text, wherein the first question text represents a first question for which a sequence of answer steps is to be determined; initializing a historical step sequence text to a preset value; and updating the historical step sequence text at least once based on the first question text to obtain a target step sequence text, wherein the target step sequence text represents a sequence of answer steps for the first question, the target step sequence text comprising at least one step text, each step text in the at least one step text representing a step for answering the first question; wherein each update in the at least one update comprises: generating a current step text based on the first question text and a current historical step sequence text, wherein the current step text represents a current step for answering the first question; in response to the current step text not being a preset termination text, splicing the current historical step sequence text with the current step text to obtain an updated historical step sequence text; or in response to the current step text being the termination text, determining the current historical step sequence text as the target step sequence text.
[0008] According to one aspect of the present disclosure, a training method for a text generation model is provided, comprising: obtaining a question-answer text pair, wherein the question-answer text pair includes a sample question text representing a sample question and a sample answer text representing an answer to the sample question; initializing a historical step sequence text to a preset value; repeatedly performing the following operations to generate a target step sequence text, wherein the target step sequence text represents a sequence of steps for solving the sample question: inputting the sample question text and the current historical step sequence text into the text generation model to obtain a current step text output by the text generation model, wherein the current step text represents the current step for solving the sample question; in response to the current step text not being a preset termination text, concatenating the current historical step sequence text with the current step text to obtain an updated historical step sequence text; or in response to the current step text being the termination text, determining the current historical step sequence text as the target step sequence text; generating a predicted answer text for the sample question based on the target step sequence text; determining a reward for the text generation model based on the predicted answer text and the sample answer text; and adjusting parameters of the text generation model based on the reward.
[0009] According to one aspect of the present disclosure, a text generation device is provided, comprising: an acquisition module configured to acquire a first question text, wherein the first question text represents a first question for which a sequence of answer steps is to be determined; an initialization module configured to initialize a historical step sequence text to a preset value; and an update module configured to update the historical step sequence text at least once based on the first question text to obtain a target step sequence text, wherein the target step sequence text represents a sequence of answer steps for the first question, the target step sequence text comprising at least one step text, each step text in the at least one step text representing a step for answering the first question; wherein the update module comprises: a generation unit configured to generate a current step text based on the first question text and a current historical step sequence text, wherein the current step text represents a current step for answering the first question; an updating unit configured to, in response to the current step text not being a preset termination text, splice the current historical step sequence text with the current step text to obtain an updated historical step sequence text; and a determination unit configured to, in response to the current step text being the termination text, determine the current historical step sequence text as the target step sequence text.
[0010] According to one aspect of the present disclosure, a training device for a text generation model is provided, comprising: an acquisition module configured to acquire a question-answer text pair, wherein the question-answer text pair comprises a sample question text representing a sample question and a sample answer text representing an answer to the sample question; an initialization module configured to initialize a historical step sequence text to a preset value; a first generation module configured to repeatedly perform the following operations to generate a target step sequence text, wherein the target step sequence text represents a sequence of steps for answering the sample question: inputting the sample question text and the current historical step sequence text into the text generation model to obtain a current step text output by the text generation model, wherein the current step text represents Indicates the current answer steps of the sample question; in response to the current step text not being a preset termination text, concatenates the current historical step sequence text with the current step text to obtain an updated historical step sequence text; or in response to the current step text being the termination text, determines the current historical step sequence text as the target step sequence text; a second generation module is configured to generate a predicted answer text for the sample question based on the target step sequence text; a determination module is configured to determine a reward for the text generation model based on the predicted answer text and the sample answer text; and an adjustment module is configured to adjust parameters of the text generation model based on the reward.
[0011] According to one aspect of the present disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute any of the methods described above.
[0012] According to one aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to cause a computer to execute any of the above methods.
[0013] According to one aspect of the present disclosure, a computer program product is provided, comprising computer program instructions, which implement the method of any one of the above aspects when executed by a processor.
[0014] According to one or more embodiments of the present disclosure, a machine question-answering prompt text with answering steps is efficiently constructed.
[0015] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present disclosure, nor are they intended to limit the scope of the present disclosure. Other features of the present disclosure will become readily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The accompanying drawings illustrate exemplary embodiments and constitute a part of the specification. Together with the description of the specification, they serve to explain exemplary implementation of the embodiments. The illustrated embodiments are for illustrative purposes only and do not limit the scope of the claims. Throughout the drawings, the same reference numerals designate similar, but not necessarily identical, elements.
[0017] Figure 1 A schematic diagram illustrating an exemplary system in which the various methods described herein may be implemented according to an embodiment of the present disclosure;
[0018] Figure 2 A flowchart of a text generation method according to an embodiment of the present disclosure is shown;
[0019] Figure 3 A flowchart of a method for training a text generation model according to an embodiment of the present disclosure is shown;
[0020] Figure 4 shows a structural block diagram of a text generation device according to an embodiment of the present disclosure;
[0021] Figure 5 A structural block diagram of a training device for a text generation model according to an embodiment of the present disclosure is shown; and
[0022] Figure 6A structural block diagram of an exemplary electronic device that can be used to implement the embodiments of the present disclosure is shown. DETAILED DESCRIPTION
[0023] The following description of exemplary embodiments of the present disclosure is made in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be appreciated by those skilled in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0024] In this disclosure, unless otherwise specified, the use of terms such as "first" and "second" to describe various elements is not intended to limit the positional relationship, temporal relationship, or importance relationship of these elements. Such terms are only used to distinguish one element from another. In some examples, the first element and the second element may refer to the same instance of the element, while in some cases, based on the context of the description, they may also refer to different instances.
[0025] The terms used in the descriptions of the various examples in this disclosure are for the purpose of describing specific examples only and are not intended to be limiting. Unless the context clearly indicates otherwise, if the number of elements is not specifically limited, the element can be one or more. In addition, the term "and / or" used in this disclosure covers any one and all possible combinations of the listed items. "Multiple" refers to two or more.
[0026] In the technical solutions disclosed herein, the acquisition, storage, and application of user personal information involved comply with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0027] Large language model technology has made significant progress in recent years and has become a revolutionary breakthrough in the field of AI. Large language models, such as Wenxin Yiyan, ChatGPT (Chat Generative Pre-trained Transformer), and GPT-4, have demonstrated powerful task-solving capabilities and can handle a variety of natural language tasks such as text classification, text generation, question answering, and dialogue. In question-answering tasks, large language models can provide accurate answers to relatively simple questions, but due to their lack of memory and reasoning capabilities, they have difficulty effectively solving complex problems (such as complex mathematical and physical calculation problems). For complex problems, large language models may produce answers that lack logical basis or are factually incorrect, misleading users.
[0028] In related technologies, in order to improve the ability of large language models to handle complex problems, a chain-of-thought prompting method is usually used to guide the large language model to reason step by step and give answers.
[0029] A chain of thought (CoT) is a series of consecutive intermediate reasoning steps used to arrive at the final answer to a problem. In other words, a chain of thought is a sequence of solution steps. For example, the question "Who is older, Xiaoming or Xiaohua?" involves four steps: "Find Xiaoming's age," "Find Xiaohua's age," "Compare the two ages," and "Describe the comparison results." Therefore, the chain of thought for solving this problem is "Find Xiaoming's age → Find Xiaohua's age → Compare the two ages → Describe the comparison results."
[0030] Thinking chain prompts refer to inputting a reference question and the answer to the reference question with the solution process (i.e., thinking chain) as prompt text (Prompt) into the large language model together with the question to be answered, thereby guiding the large language model to gradually reason and give the answer to the question to be answered.
[0031] In the related art, thought chains are usually constructed by manually annotating the solution steps of a problem. This method has high labor costs, low annotation efficiency, and is difficult to quickly construct large amounts of thought chain data.
[0032] To address the above issues, the present disclosure provides a method for generating text that automatically generates a sequence of steps for answering questions, thereby efficiently constructing large quantities of machine question-answering prompt texts with step-by-step answers. The following describes the present disclosure in detail with reference to the accompanying drawings.
[0033] Figure 1 FIG2 is a schematic diagram of an exemplary system 100 in which the various methods and apparatuses described herein may be implemented according to an embodiment of the present disclosure. Figure 1 , the system 100 includes one or more client devices 101, 102, 103, 104, 105, and 106, a server 120, and one or more communication networks 110 coupling the one or more client devices to the server 120. The client devices 101, 102, 103, 104, 105, and 106 can be configured to execute one or more applications.
[0034] In an embodiment of the present disclosure, client devices 101 , 102 , 103 , 104 , 105 , and 106 and server 120 may run one or more services or software applications that enable execution of a text generation method or a training method of a text generation model.
[0035] In some embodiments, server 120 may also provide other services or software applications, which may include non-virtualized environments and virtualized environments. In some embodiments, these services may be provided as web-based services or cloud services, such as provided to users of client devices 101, 102, 103, 104, 105, and / or 106 under a software as a service (SaaS) model.
[0036] exist Figure 1 In the configuration shown, the server 120 may include one or more components that implement the functions performed by the server 120. These components may include software components, hardware components, or a combination thereof that can be executed by one or more processors. Users operating client devices 101, 102, 103, 104, 105, and / or 106 may, in turn, utilize one or more client applications to interact with the server 120 to utilize the services provided by these components. It should be understood that a variety of different system configurations are possible, which may differ from the system 100. Therefore, Figure 1 is one example of a system for implementing the various methods described herein and is not intended to be limiting.
[0037] Client devices 101, 102, 103, 104, 105, and / or 106 may provide an interface that enables a user of the client device to interact with the client device. The client device may also output information to the user via the interface. Figure 1 Only six client devices are depicted, but one skilled in the art will appreciate that the present disclosure can support any number of client devices.
[0038] Client devices 101, 102, 103, 104, 105, and / or 106 may include various types of computer devices, such as portable handheld devices, general-purpose computers (such as personal computers and laptops), workstation computers, wearable devices, smart screen devices, self-service terminal devices, service robots, in-vehicle devices, gaming systems, thin clients, various messaging devices, sensors or other sensing devices, and the like. These computer devices may run various types and versions of software applications and operating systems, such as Microsoft Windows, Apple iOS, UNIX-like operating systems, Linux, or Linux-like operating systems; or various mobile operating systems, such as Microsoft Windows Mobile OS, iOS, Windows Phone, and Android. Portable handheld devices may include cellular phones, smartphones, tablet computers, personal digital assistants (PDAs), and the like. Wearable devices may include head-mounted displays (such as smart glasses) and other devices. Gaming systems may include various handheld gaming devices and internet-enabled gaming devices. Client devices are capable of executing a variety of different applications, such as various internet-related applications, communication applications (such as email applications), and short message service (SMS) applications, and may utilize various communication protocols.
[0039] The network 110 may be any type of network known to those skilled in the art that can support data communications using any of a variety of available protocols, including but not limited to TCP / IP, SNA, IPX, etc. By way of example only, the one or more networks 110 may be a local area network (LAN), an Ethernet-based network, a token ring, a wide area network (WAN), the Internet, a virtual network, a virtual private network (VPN), an intranet, an extranet, a blockchain network, a public switched telephone network (PSTN), an infrared network, a wireless network (e.g., Bluetooth, Wi-Fi), and / or any combination of these and / or other networks.
[0040] Server 120 may include one or more general-purpose computers, specialized server computers (e.g., PC (personal computer) servers, UNIX servers, mid-range servers), blade servers, mainframe computers, server clusters, or any other suitable arrangement and / or combination. Server 120 may include one or more virtual machines running virtual operating systems, or other computing architectures involving virtualization (e.g., one or more flexible pools of logical storage devices that may be virtualized to maintain a server's virtual storage device). In various embodiments, server 120 may run one or more services or software applications that provide the functionality described below.
[0041] The computing units in the server 120 may run one or more operating systems including any of the operating systems described above as well as any commercially available server operating systems. The server 120 may also run any of a variety of additional server applications and / or middle-tier applications, including HTTP servers, FTP servers, CGI servers, JAVA servers, database servers, and the like.
[0042] In some implementations, server 120 may include one or more applications to analyze and consolidate data feeds and / or event updates received from users of client devices 101, 102, 103, 104, 105, and / or 106. Server 120 may also include one or more applications to display the data feeds and / or real-time events via one or more display devices of client devices 101, 102, 103, 104, 105, and / or 106.
[0043] In some embodiments, server 120 may be a distributed system server or a server integrated with blockchain. Server 120 may also be a cloud server, or an intelligent cloud computing server or intelligent cloud host equipped with artificial intelligence technology. A cloud server is a host product within the cloud computing service system that addresses the management difficulties and poor scalability of traditional physical hosts and virtual private servers (VPS) services.
[0044] The system 100 may also include one or more databases 130. In some embodiments, these databases may be used to store data and other information. For example, one or more of the databases 130 may be used to store information such as audio files and video files. The databases 130 may reside in a variety of locations. For example, the database used by the server 120 may be local to the server 120, or may be remote from the server 120 and communicate with the server 120 via a network-based or dedicated connection. The databases 130 may be of different types. In some embodiments, the databases used by the server 120 may be, for example, relational databases. One or more of these databases may store, update, and retrieve data to and from the databases in response to commands.
[0045] In some embodiments, one or more of the databases 130 may also be used by applications to store application data. The databases used by the applications may be different types of databases, such as a key-value store, an object store, or a conventional store backed by a file system.
[0046] Figure 1 The system 100 may be configured and operated in various ways to enable application of the various methods and apparatuses described in accordance with the present disclosure.
[0047] Figure 2 1 shows a flow chart of a text generation method 200 according to an embodiment of the present disclosure. The execution body of each step of the method 200 is usually a server, such as Figure 1 In some embodiments, the execution subject of method 200 may also be a client device, such as Figure 1 The client devices 101-106 are shown in FIG.
[0048] like Figure 2 As shown, the method 200 includes operations S210 - S230 .
[0049] In operation S210, a first question text is obtained, which represents the first question for which a sequence of answering steps is to be determined.
[0050] In operation S220 , the historical step sequence text is initialized to a preset value.
[0051] In operation S230, based on the first question text, the historical step sequence text is updated at least once to obtain a target step sequence text. The target step sequence text represents a sequence of steps for answering the first question. The target step sequence text includes at least one step text, each step text in the at least one step text representing a step for answering the first question.
[0052] Each of the at least one updating of the above-mentioned operation S230 includes operations S231 to S233.
[0053] In operation S231, a current step text is generated based on the first question text and the current historical step sequence text, wherein the current step text represents the current answer step of the first question.
[0054] In operation S232 , in response to the current step text not being a preset termination text, the current historical step sequence text is concatenated with the current step text to obtain an updated historical step sequence text.
[0055] In operation S233 , in response to the current step text being a termination text, the current historical step sequence text is determined as a target step sequence text.
[0056] According to an embodiment of the present disclosure, based on the first question text and the generated historical step sequence text, each step text is gradually generated, and then the target step sequence text is obtained, that is, the solution step sequence (i.e., the thought chain) of the first question is obtained. The embodiment of the present disclosure automatically generates the solution step sequence of the question through text generation, which can efficiently construct a large number of machine question and answer prompt texts with solution steps.
[0057] The following describes each step of method 200 in detail.
[0058] In an embodiment of the present disclosure, the first question is a question for which a sequence of answering steps is to be determined, that is, a question for which a chain of thinking is to be constructed. The first question is expressed in the form of text, that is, the first question is expressed as a first question text.
[0059] In an embodiment of the present disclosure, the historical step sequence text represents a sequence of solution steps generated during the text generation process, and the target step sequence text represents a sequence of solution steps for the generated first question, that is, a thought chain for the first question.
[0060] It can be understood that in the embodiment of the present disclosure, the historical step sequence text is a variable, and its initial value is a preset value. As operations S231-S233 are executed, the value of the historical step sequence text is continuously updated, and its termination value is the target step sequence text. Specifically, each time operation S231 is executed, a new step text will be generated, which represents the current solution step of the first question, that is, it represents the solution step to be executed in the next step currently determined based on the first question text and the generated historical step sequence text. By executing operation S232, the newly generated step text is continuously added to the historical step sequence text. Until the newly generated step text is the termination text, the updating process of the historical step sequence text is terminated, and the historical step sequence text at this time is the target step sequence text.
[0061] According to some embodiments, the preset value (initial value) of the historical step sequence text may be an empty string "Null", a string "Thought Chain:", etc. The preset termination text may be, for example, "Complete", "End", etc.
[0062] Regarding operation S231 , there are multiple methods for generating the current step text.
[0063] According to some embodiments, the first question text and the current historical step sequence text may be input into a text generation model to obtain the current step text output by the text generation model.
[0064] According to the above embodiment, the step text is generated by using a text generation model, which can improve the efficiency and generalization of text generation.
[0065] According to some embodiments, the text generation model can be a large language model, which typically includes an N-layer Transformer network with an encoder and a decoder. The large language model is pre-trained using a large amount of natural language data. Pre-training enables the large language model to have certain prior knowledge and common sense, thereby improving its performance on various tasks.
[0066] In other embodiments, the text generation model may also be other deep neural network models, such as Seq2Seq.
[0067] According to some embodiments, the text generation model can be obtained by training a pre-trained first language model using a reinforcement learning strategy. The training samples are question-answer text pairs, each of which includes a sample question text representing a sample question and a sample answer text representing the answer to the sample question. The first language model can, for example, be a large language model. The text generation model can, for example, be trained using the text generation model training method 300 of the presently disclosed embodiment.
[0068] According to the above embodiment, the text generation model is obtained by further training the question-answer text pairs based on the pre-trained first language model. Therefore, the text generation model not only has the language comprehension ability of the first language model, but also has the ability to accurately construct the thought chain of the problem. In addition, the text generation model is trained through a reinforcement learning strategy on a large number of training samples, so its behavior has global consistency. Therefore, the text generation model can generate correct and consistent thought chains for new tasks (such as mathematical calculations, physical calculations, etc.). The generated thought chain can be used as a prompt text (Prompt) to guide the large language model (such as the third language model below) to gradually reason and give the answer to the question to be answered, thereby improving the accuracy of the answer.
[0069] According to other embodiments, the text generation model may be a pre-trained second language model. The second language model may be, for example, a large language model. According to this embodiment, the pre-trained large language model is directly used as the text generation model, eliminating the need for additional training steps to adjust the parameters of the large language model. This avoids the consumption of computing resources and time caused by model training, and has strong practicality.
[0070] According to some embodiments, the second language model may be the same as the first language model above.
[0071] It can be understood that in the above embodiment, since the text generation model directly uses the pre-trained second language model and does not use the question-answer text to make targeted adjustments to the parameters of the second language model, the accuracy of the thought chain generated by the text generation model is relatively low. In this case, in order to ensure the accuracy of the generated thought chain, a preset executor can be used to execute the answer steps corresponding to each step text, and the generated thought chain can be verified based on the execution result of the last answer step. In this way, the accuracy of the generated thought chain can be guaranteed while improving efficiency and practicality.
[0072] Specifically, each update of the historical step sequence text further includes operation S234. In operation S234, the current solution step represented by the current step text is executed to obtain the current execution result text of the current solution step.
[0073] Corresponding to the above operation S234, operation S233 further includes: in response to the current step text being a termination text and the current execution result text being a first answer text representing an answer to the first question, determining the current historical step sequence text as a target step sequence text.
[0074] It can be understood that the above embodiment needs to obtain the first answer text corresponding to the first question text, and based on the first question text and the first answer text, generate the target step sequence text of the first question, that is, the thinking chain. The current step text is a termination text, indicating that the update process of the historical step sequence text has ended. Accordingly, the current step text represents the last solution step of the first question, and the execution result of the solution step is the predicted answer to the first question. If the execution result text corresponding to the last solution step is the same as the first answer text, it means that the predicted answer to the first question is the same as the correct answer, and the generated historical step sequence text can correctly answer the first question. Therefore, the generated historical step sequence text is considered correct and is used as the target step sequence text. On the contrary, if the execution result text corresponding to the last solution step is different from the first answer text, the generated historical step sequence text is considered to be wrong and is discarded and not used as the target step sequence text.
[0075] According to some embodiments, operation S234 may be implemented using a preset executor, which may be, for example, a large language model or a manually designed solution model.
[0076] According to some embodiments, operation S234 may include operations S2341 - S2343 .
[0077] In operation S2341 , the knowledge domain corresponding to the first question is identified.
[0078] In operation S2342 , an executor for executing the problem-solving step of the knowledge domain is obtained.
[0079] In operation S2343 , the current step text is input into the executor to obtain the current execution result text output by the executor.
[0080] According to the above embodiment, the steps of answering the first question are executed by using an executor corresponding to the knowledge domain to which the first question belongs, thereby improving the accuracy of the execution result.
[0081] According to some embodiments, in operation S2341, the first question text may be input into a trained classification model to obtain a knowledge domain to which the first question belongs, which is output by the classification model.
[0082] The classification model can be implemented as a neural network. In some embodiments, the classification model can be a large language model, such as the first language model, the second language model, etc.
[0083] The knowledge domains include, for example, general knowledge domain, mathematics knowledge domain, physics knowledge domain, medical knowledge domain, and the like.
[0084] According to some embodiments, executors corresponding to different knowledge domains may be pre-set, and the correspondence between knowledge domains and executors may be stored. Accordingly, in operation S2342, the corresponding executor may be found from the above correspondence based on the knowledge domain of the first question. It is understandable that the executors corresponding to different knowledge domains are usually different. For example, the executor of a general knowledge domain may be a large language model. Large language models lack the ability to solve professional knowledge domains such as mathematics and physics, so according to the characteristics of the professional knowledge domain, the solution model of each professional knowledge domain may be manually designed as an executor.
[0085] According to some embodiments, in operation S2343 , the executor may acquire external knowledge by calling an external interface, and generate a current execution result text based on the acquired external knowledge.
[0086] According to some embodiments, in operation S231, a question-and-answer step template may be used to generate the current step text. For example, multiple question-and-answer step templates may be preset. Each question-and-answer step template defines a correspondence between a question text and a step sequence text and a step text. By matching the first question text and the current historical step sequence text with multiple preset question-and-answer step templates, a target question-and-answer step template corresponding to the first question text and the current historical step sequence text is obtained. Further, based on the target question-and-answer step template, the current step text is determined.
[0087] According to some embodiments, in operation S231, a preset step database may be used to determine the current step text. For example, the first question text and the current historical step sequence text may be matched with multiple step texts in the step database, and the step text with the greatest matching degree may be used as the current step text.
[0088] In operations S231-S233, the text generation model continuously generates the step text of the next answer step based on the current state (including the first question text and the current historical step sequence text), and updates the current state based on the generated step text (i.e., updates the historical step sequence text) until the generated step text becomes the terminal text. The historical step sequence text at this point is the target step sequence text of the first text, that is, the thought chain of the first text.
[0089] The following table shows an exemplary text generation process according to an embodiment of the present disclosure:
[0090]
[0091] According to some embodiments, method 200 further includes operations S240 - S260 .
[0092] In operation S240 , each solution step in the target step sequence text is executed respectively to obtain an execution result text of each solution step.
[0093] In operation S250, a first answer text is generated based on the target step sequence text and the execution result text of each answer step, wherein the first answer text represents the answer process of the first question.
[0094] In operation S260 , the output of the third language model is optimized based on the first question text and the first answer text.
[0095] According to the above embodiment, by optimizing the output of the third language model using the first question text and the first answer text, the third language model can learn the answer process of the first question, thereby improving the accuracy of the answers to other questions output by the third language model.
[0096] According to some embodiments, operation S240 may include operations S2341-S2343 described above. That is, in operation S240, each solution step in the target step sequence text is executed separately using a preset executor to obtain an execution result text of each solution step.
[0097] According to some embodiments, in operation S250, the step text of each answer step can be combined with its execution result text to generate a first answer text. For example, the target step sequence text of the first question text "Who is older, Xiao Ming or Xiao Hua" is "Thinking chain: find Xiao Ming's age → find Xiao Hua's age → compare the two ages → describe the comparison result", which includes 4 step texts "Find Xiao Ming's age", "Find Xiao Hua's age", "Compare the two ages", "Describe the comparison result", and the corresponding execution result texts are "3", "5", "5 is older", and "Xiao Hua is older". The generated first answer text can be, for example, "Xiao Ming is 3 years old, Xiao Hua is 5 years old, 5 is greater than 3, so Xiao Hua is older."
[0098] According to some embodiments, operation S260 may include operations S261 and S262.
[0099] In operation S261 , a second question text is obtained, where the second question text represents a second question to be answered.
[0100] In operation S262, the first question text, the first answer text, and the second question text are input into the third language model to obtain a second answer text output by the third language model, wherein the second answer text represents the answer process of the second question.
[0101] According to the above embodiment, the first question text and the first answer text are used as reference examples for machine question answering and are input into the third language model together with the second question text. This enables the third language model to learn the answer process of the first question and answer the second question with reference to the answer process of the first question, thereby improving the accuracy of the answer to the second question.
[0102] According to some embodiments, the second question text may be user-specified. For example, the user may select the second question text from a client device (e.g., Figure 1 The client device 101-106 shown in FIG2 enters the second question text. In the case where the execution subject of method 200 is a server, the client device sends the second question text entered by the user to the server (eg Figure 1 In the case where the execution subject of the method 200 is a client device, the second question text is stored locally in the client device.
[0103] It should be noted that, according to operations S210-S250, multiple first question texts can be processed to obtain first answer texts for each of the multiple first question texts. The multiple first question texts may belong to different knowledge domains. Accordingly, according to some embodiments, in operation S262, the knowledge domain to which the second question belongs can be identified, and a first question text and its first answer text in the knowledge domain are input into the third language model together with the second question text.
[0104] The third language model can be a large language model. According to some embodiments, the third language model can be the same as the trained text generation model used to generate the current step text in operation S231 (i.e., the text generation model trained based on the pre-trained first language model). As a result, the third language model has the ability to both generate solution steps and answer questions, enabling it to better understand and learn the solution steps it generates, thereby improving the efficiency, accuracy, and consistency of question-answering.
[0105] According to some embodiments, the third language model may be a pre-trained large language model itself, such as the second language model mentioned above.
[0106] According to some embodiments, the first language model, the second language model, and the third language model may be the same large language model.
[0107] According to an embodiment of the present disclosure, a method for training a text generation model is also provided. The training method trains the text generation model based on a reinforcement learning strategy. The trained text generation model can be used to perform operation S231 above to generate step text corresponding to each solution step of the problem, thereby generating a thought chain for the problem.
[0108] Figure 3 The flowchart of the training method 300 of the text generation model according to the embodiment of the present disclosure is shown. The execution subject of the method 300 is usually a server. In some embodiments, the execution subject of the method 300 can also be a client device, which generally requires the client device to have a high hardware configuration and computing power. Figure 3 As shown, the method 300 includes operations S310 - S360 .
[0109] In operation S310, a question-answer text pair is obtained, wherein the question-answer text pair includes a sample question text representing a sample question and a sample answer text representing an answer to the sample question.
[0110] In operation S320, the historical step sequence text is initialized to a preset value.
[0111] In operation S330, the following operations S331-S333 are repeatedly performed to generate a target step sequence text, wherein the target step sequence text represents a sequence of steps for solving the sample problem.
[0112] In operation S331, the sample question text and the current historical step sequence text are input into the text generation model to obtain the current step text output by the text generation model. The current step text represents the current solution step of the sample question.
[0113] In operation S332 , in response to the current step text not being the preset termination text, the current historical step sequence text is concatenated with the current step text to obtain an updated historical step sequence text.
[0114] In operation S333 , in response to the current step text being a termination text, the current historical step sequence text is determined as a target step sequence text.
[0115] In operation S340 , a predicted answer text for the sample question is generated based on the target step sequence text.
[0116] In operation S350 , a reward of the text generation model is determined based on the predicted answer text and the sample answer text.
[0117] In operation S360 , parameters of the text generation model are adjusted based on the reward.
[0118] According to an embodiment of the present disclosure, a text generation model is trained using a reinforcement learning strategy based on episodic tasks. The text generation model is equivalent to the policy adopted by the agent in the reinforcement learning strategy. The text generation model takes the sample question text and the current historical step sequence text as the input state (State), and outputs the current step text as the next action (Action) taken under the input state. When the step text output by the text generation model is the termination text, the round ends. The generated target step sequence text (i.e., the thought chain) is the termination state at the end of the round. A predicted answer text is generated based on the target step sequence text, and the reward (Reward) of the text generation model is evaluated based on the predicted answer text and the sample answer text, and the parameters of the text generation model are adjusted accordingly, so that the text generation model always evolves in the direction of "making the thought chain lead to the correct answer", so that the thought chain can be accurately generated.
[0119] Since the agent's strategy (i.e., text generation model) is trained through reinforcement learning in a large number of training samples (i.e., question-answer text pairs), its behavior tends to have global consistency. Therefore, the text generation model trained according to the embodiment of the present disclosure can automatically and step by step generate correct and consistent thought chains for any new question, thereby being able to efficiently generate large-scale, high-quality thought chain data. The generated thought chain can be used as a prompt text for machine question answering to guide a large language model (such as the third language model mentioned above) to gradually reason and give the answer to the question to be answered, thereby improving the accuracy of the answer.
[0120] According to some embodiments, the initial value of the text generation model is a pre-trained language model. This language model is a large language model. According to this embodiment, the text generation model is trained based on the pre-trained large language model, giving it the powerful language understanding capabilities of the large language model, thereby facilitating the rapid learning of the ability to accurately generate thought chains for questions.
[0121] According to some embodiments, operation S340 may include operations S341 and S342.
[0122] In operation S341 , each solution step in the target step sequence text is executed respectively to obtain an execution result text of each solution step.
[0123] In operation S342 , the execution result text of the last solution step in the target step sequence text is determined as the predicted answer text.
[0124] According to the above embodiment, a predicted answer text can be quickly and automatically generated.
[0125] According to some embodiments, operation S341 may include operations S3411 - S3413 .
[0126] In operation S3411 , the knowledge domain corresponding to the sample question is identified.
[0127] In operation S3412 , an executor for executing the question-solving step of the knowledge domain is obtained.
[0128] In operation S3413 , the step text corresponding to the solution step is input into the executor to obtain the execution result text output by the executor.
[0129] According to the above embodiment, the accuracy of the execution result can be improved by using the executor corresponding to the knowledge domain to which the sample question belongs to execute the steps of solving the sample question.
[0130] The specific implementation of S3411-S3413 can refer to the relevant description of operations S2341-S2343 above, which will not be repeated here.
[0131] According to some embodiments, in operation S350, a reward for the text generation model may be determined based on the similarity between the predicted answer text and the sample answer text. The reward is positively correlated with the similarity; that is, the greater the similarity between the predicted answer text and the sample answer text, the greater the reward; the less similar the predicted answer text and the sample answer text, the smaller the reward. This can generate a feedback signal for the text generation model, guiding the text generation model to evolve towards generating correct predicted answer text.
[0132] The similarity between the predicted answer text and the sample answer text can be measured by their literal similarity, such as edit distance or maximum number of consecutive matching characters; it can also be measured by the cosine distance between their embedding vectors. The embedding vectors of the predicted answer text and the sample answer text can be obtained, for example, from a trained text representation model. Specifically, by inputting the predicted answer text or the sample answer text into the text representation model, the embedding vector of the predicted answer text or the sample answer text output by the text representation model can be obtained.
[0133] In operation S360 , the parameters of the text generation model are adjusted in a direction that increases the reward, so that the text generation model evolves in a direction of “making the thought chain lead to the correct answer”.
[0134] It is understood that operations S310-S360 may be executed multiple times in a loop until a predetermined termination condition is reached, and the text generation model training is completed. The termination condition may be, for example, the accuracy of the thought chain generated by the text generation model reaches a threshold, the number of loops reaches a threshold, the accuracy converges, etc.
[0135] According to an embodiment of the present disclosure, a text generation device is also provided. Figure 4 FIG. 4 shows a structural block diagram of a text generation device 400 according to an embodiment of the present disclosure. Figure 4 As shown, the apparatus 400 includes an acquisition module 410 , an initialization module 420 and an update module 430 .
[0136] The acquisition module 410 is configured to acquire a first question text, wherein the first question text represents a first question for which a sequence of answer steps is to be determined.
[0137] The initialization module 420 is configured to initialize the historical step sequence text to a preset value.
[0138] The updating module 430 is configured to update the historical step sequence text at least once based on the first question text to obtain a target step sequence text, wherein the target step sequence text represents a sequence of steps for answering the first question, and the target step sequence text includes at least one step text, and each step text in the at least one step text represents a step for answering the first question.
[0139] The updating module 430 includes a generating unit 431 , an updating unit 432 , and a determining unit 433 .
[0140] The generating unit 431 is configured to generate a current step text based on the first question text and the current historical step sequence text, wherein the current step text represents the current answer step of the first question;
[0141] The updating unit 432 is configured to, in response to the current step text not being a preset termination text, concatenate the current historical step sequence text with the current step text to obtain an updated historical step sequence text; and
[0142] The determining unit 433 is configured to determine the current historical step sequence text as the target step sequence text in response to the current step text being the termination text.
[0143] According to an embodiment of the present disclosure, based on the first question text and the generated historical step sequence text, each step text is gradually generated, and then the target step sequence text is obtained, that is, the solution step sequence (i.e., the thought chain) of the first question is obtained. The embodiment of the present disclosure automatically generates the solution step sequence of the question through text generation, which can efficiently construct a large number of machine question and answer prompt texts with solution steps.
[0144] According to some embodiments, the generating unit 431 is further configured to: input the first question text and the current historical step sequence text into a text generation model to obtain the current step text output by the text generation model.
[0145] According to some embodiments, the text generation model is obtained by training a pre-trained first language model through a reinforcement learning strategy, and the training samples of the training are question-answer text pairs, and the question-answer text pairs include sample question text representing a sample question and sample answer text representing the answer to the sample question.
[0146] According to some embodiments, the text generation model is a pre-trained second language model, and the update module 430 further includes: an execution unit configured to execute the current answer step represented by the current step text to obtain the current execution result text of the current answer step; and wherein the determination unit 433 is further configured to: in response to the current step text being the termination text and the current execution result text being the first answer text representing the answer to the first question, determine the current historical step sequence text as the target step sequence text.
[0147] According to some embodiments, the execution unit includes: an identification subunit, configured to identify the knowledge domain corresponding to the first question; an acquisition subunit, configured to acquire an executor for executing the problem-solving steps of the knowledge domain; and an execution subunit, configured to input the current step text into the executor to obtain the current execution result text output by the executor.
[0148] According to some embodiments, the apparatus 400 further includes: an execution module configured to respectively execute each answer step in the target step sequence text to obtain an execution result text of each answer step; a generation module configured to generate a first answer text based on the target step sequence text and the execution result text of each answer step, wherein the first answer text represents the answer process of the first question; and an optimization module configured to optimize the output of a third language model based on the first question text and the first answer text.
[0149] According to some embodiments, the optimization module includes: an acquisition unit configured to acquire a second question text, wherein the second question text represents a second question to be answered; and an input unit configured to input the first question text, the first answer text, and the second question text into the third language model to obtain a second answer text output by the third language model, wherein the second answer text represents the answer process of the second question.
[0150] According to some embodiments, the third language model is the same as the trained text generation model used to generate the current step text.
[0151] It should be understood that Figure 4 The modules and units of the apparatus 400 shown in FIG. 4 can be compared with those of the reference Figure 2 The steps in the method 200 described above correspond to each other. Therefore, the operations, features and advantages described above for the method 200 are also applicable to the apparatus 400 and the modules and units included therein. For the sake of brevity, some operations, features and advantages are not repeated here.
[0152] According to an embodiment of the present disclosure, a training device for a text generation model is also provided. Figure 5 FIG. 5 shows a structural block diagram of a training device 500 for a text generation model according to an embodiment of the present disclosure. Figure 5 As shown, the apparatus 500 includes an acquisition module 510 , an initialization module 520 , a first generation module 530 , a second generation module 540 , a determination module 550 and an adjustment module 560 .
[0153] The acquisition module 510 is configured to acquire a question-answer text pair, wherein the question-answer text pair includes a sample question text representing a sample question and a sample answer text representing an answer to the sample question.
[0154] The initialization module 520 is configured to initialize the historical step sequence text to a preset value.
[0155] The first generating module 530 is configured to repeatedly perform the following operations to generate a target step sequence text, wherein the target step sequence text represents a sequence of steps for answering the sample question:
[0156] Inputting the sample question text and the current historical step sequence text into the text generation model to obtain the current step text output by the text generation model, wherein the current step text represents the current solution step of the sample question;
[0157] In response to the current step text not being a preset termination text, concatenating the current historical step sequence text with the current step text to obtain an updated historical step sequence text; or
[0158] In response to the current step text being the termination text, the current historical step sequence text is determined as the target step sequence text.
[0159] The second generating module 540 is configured to generate a predicted answer text for the sample question based on the target step sequence text.
[0160] The determination module 550 is configured to determine a reward for the text generation model based on the predicted answer text and the sample answer text.
[0161] The adjustment module 560 is configured to adjust the parameters of the text generation model based on the reward.
[0162] According to an embodiment of the present disclosure, a text generation model is trained using a reinforcement learning strategy based on episodic tasks. The text generation model is equivalent to the policy adopted by the agent in the reinforcement learning strategy. The text generation model takes the sample question text and the current historical step sequence text as the input state (State), and outputs the current step text as the next action (Action) taken under the input state. When the step text output by the text generation model is the termination text, the round ends. The generated target step sequence text (i.e., the thought chain) is the termination state at the end of the round. A predicted answer text is generated based on the target step sequence text, and the reward (Reward) of the text generation model is evaluated based on the predicted answer text and the sample answer text, and the parameters of the text generation model are adjusted accordingly, so that the text generation model always evolves in the direction of "making the thought chain lead to the correct answer", so that the thought chain can be accurately generated.
[0163] Since the agent's strategy (i.e., text generation model) is trained through reinforcement learning in a large number of training samples (i.e., question-answer text pairs), its behavior tends to have global consistency. Therefore, the text generation model trained according to the embodiment of the present disclosure can automatically and step by step generate correct and consistent thought chains for any new question, generating large-scale, high-quality thought chain data. The generated thought chains can be used as prompt texts for machine question answering to guide the large language model (such as the third language model mentioned above) to gradually reason and give the answer to the question to be answered, thereby improving the accuracy of the answer.
[0164] According to some embodiments, the initial value of the text generation model is a pre-trained language model.
[0165] According to some embodiments, the second generation module 540 includes: an execution unit, configured to execute each answer step in the target step sequence text respectively to obtain the execution result text of each answer step; and a determination unit, configured to determine the execution result text of the last answer step in the target step sequence text as the predicted answer text.
[0166] According to some embodiments, the execution unit includes: an identification subunit, configured to identify the knowledge domain corresponding to the sample question; an acquisition subunit, configured to acquire an executor for executing the problem-solving steps in the knowledge domain; and an execution subunit, configured to input the step text corresponding to the solution step into the executor to obtain the execution result text output by the executor.
[0167] According to some embodiments, the determination module 550 is further configured to: determine a reward for the text generation model based on the similarity between the predicted answer text and the sample answer text, wherein the reward is positively correlated with the similarity.
[0168] It should be understood that Figure 5 The modules and units of the apparatus 500 shown in FIG. 5 can be compared with those of the reference Figure 3 The steps in the method 300 described above correspond to each other. Therefore, the operations, features and advantages described above for the method 300 are also applicable to the apparatus 500 and the modules and units included therein. For the sake of brevity, some operations, features and advantages are not repeated here.
[0169] Although specific functionality is discussed above with reference to specific modules, it should be noted that the functionality of the various modules discussed herein may be separated into multiple modules, and / or at least some functionality of multiple modules may be combined into a single module.
[0170] It should also be understood that various techniques may be described herein in the general context of software hardware elements or program modules. Figure 4、 Figure 5 The various units described can be implemented in hardware or in hardware in combination with software and / or firmware. For example, these units can be implemented as computer program code / instructions, which are configured to be executed in one or more processors and stored in a computer-readable storage medium. Alternatively, these units can be implemented as hardware logic / circuits. For example, in some embodiments, one or more of modules 410-560 can be implemented together in a system on chip (SoC). SoC can include an integrated circuit chip (which includes a processor (e.g., a central processing unit (CPU), a microcontroller, a microprocessor, a digital signal processor (DSP), etc.), a memory, one or more communication interfaces, and / or one or more components in other circuits), and can optionally execute the received program code and / or include embedded firmware to perform functions.
[0171] According to an embodiment of the present disclosure, an electronic device is also provided, including: at least one processor; and a memory communicatively connected to the at least one processor, the memory storing instructions executable by the at least one processor, the instructions being executed by the at least one processor so that the at least one processor can execute the text generation method and / or the text generation model training method of the embodiment of the present disclosure.
[0172] According to an embodiment of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is also provided, wherein the computer instructions are used to enable a computer to execute the text generation method and / or the text generation model training method of the embodiment of the present disclosure.
[0173] According to an embodiment of the present disclosure, a computer program product is also provided, including computer program instructions, which, when executed by a processor, implement the text generation method and / or the text generation model training method of the embodiment of the present disclosure.
[0174] refer to Figure 6, a block diagram of an electronic device 600 that can serve as a server or client of the present disclosure will now be described, which is an example of a hardware device that can be applied to various aspects of the present disclosure. The electronic device is intended to represent various forms of digital electronic computer devices, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0175] like Figure 6 As shown, the electronic device 600 includes a computing unit 601, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 602 or a computer program loaded from a storage unit 608 into a random access memory (RAM) 603. Various programs and data required for the operation of the electronic device 600 can also be stored in the RAM 603. The computing unit 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0176] Multiple components within electronic device 600 are connected to I / O interface 605, including an input unit 606, an output unit 607, a storage unit 608, and a communication unit 609. Input unit 606 can be any type of device capable of inputting information into electronic device 600. Input unit 606 can receive input numeric or character information and generate key signal input related to user settings and / or function control of the electronic device. It may include, but is not limited to, a mouse, keyboard, touch screen, trackpad, trackball, joystick, microphone, and / or remote control. Output unit 607 can be any type of device capable of presenting information, and may include, but is not limited to, a display, a speaker, a video / audio output terminal, a vibrator, and / or a printer. Storage unit 608 may include, but is not limited to, a magnetic disk or an optical disk. Communication unit 609 allows electronic device 600 to exchange information / data with other devices via computer networks such as the Internet and / or various telecommunication networks. It may include, but is not limited to, a modem, a network card, an infrared communication device, a wireless communication transceiver and / or chipset, such as a Bluetooth device, an 802.11 device, a Wi-Fi device, a WiMAX device, a cellular communication device, and / or the like.
[0177] The computing unit 601 can be a variety of general-purpose and / or specialized processing components with processing and computing capabilities. Some examples of the computing unit 601 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units that run machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The computing unit 601 performs the various methods and processes described above, such as method 200 or method 300. For example, in some embodiments, method 200 and method 300 can be implemented as a computer software program that is tangibly contained in a machine-readable medium, such as a storage unit 608. In some embodiments, part or all of the computer program can be loaded and / or installed on the electronic device 600 via the ROM 602 and / or the communication unit 609. When the computer program is loaded into the RAM 603 and executed by the computing unit 601, one or more steps of the methods 200 and 300 described above can be performed. Alternatively, in other embodiments, the computing unit 601 may be configured to execute the method 200 or the method 300 in any other appropriate manner (eg, by means of firmware).
[0178] Various embodiments of the systems and techniques described above can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), system-on-chip systems (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include being implemented in one or more computer programs that are executable and / or interpreted on a programmable system that includes at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0179] The program code for implementing the method of the present disclosure can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device so that when the program code is executed by the processor or controller, the functions / operations specified in the flow chart and / or block diagram are implemented. The program code can be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0180] In the context of the present disclosure, a machine-readable medium can be a tangible medium that can contain or store a program for use by or in conjunction with an instruction execution system, device or equipment. A 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, device or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium can include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0181] To provide interaction with a user, the systems and techniques described herein 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 pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the 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 input, voice input, or tactile input).
[0182] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, 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), the Internet, and a blockchain network.
[0183] A computer system may include a client and a server. The client and server are generally remote from each other and typically interact through a communication network. The client-server relationship arises through computer programs running on the respective computers and having a client-server relationship with each other. The server may be a cloud server, a server in a distributed system, or a server integrated with a blockchain.
[0184] It should be understood that the various forms of the processes shown above can be used to reorder, add, or delete steps. For example, the steps described in this disclosure can be performed in parallel, sequentially, or in a different order, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved. This is not limited herein.
[0185] Although the embodiments or examples of the present disclosure have been described with reference to the accompanying drawings, it should be understood that the above-mentioned methods, systems and devices are merely exemplary embodiments or examples, and the scope of the present disclosure is not limited by these embodiments or examples, but is only limited by the claims after authorization and their equivalents. Various elements in the embodiments or examples can be omitted or replaced by their equivalents. In addition, the steps can be performed in an order different from that described in the present disclosure. Further, the various elements in the embodiments or examples can be combined in various ways. It is important that as technology evolves, many of the elements described here can be replaced by equivalent elements that appear after the present disclosure.
Claims
1. A text generation method, comprising: Obtaining a first question text, wherein the first question text represents a first question of a sequence of answer steps to be determined; Initialize the history step sequence text to a preset value; and Based on the first question text, the historical step sequence text is updated at least once to obtain a target step sequence text, wherein the target step sequence text represents a sequence of steps for answering the first question, and the target step sequence text includes at least one step text, each step text in the at least one step text represents a step for answering the first question; Each update in the at least one update includes: Generating a current step text based on the first question text and the current historical step sequence text, comprising: inputting the first question text and the current historical step sequence text into a text generation model to obtain a current step text output by the text generation model, wherein the current step text represents a current step of answering the first question; In response to the current step text not being a preset termination text, concatenating the current historical step sequence text with the current step text to obtain an updated historical step sequence text; or In response to the current step text being the termination text, the current historical step sequence text is determined as the target step sequence text.
2. The method according to claim 1, wherein The text generation model is a pre-trained second language model, and each of the at least one update further includes: Execute the current solution step represented by the current step text to obtain the current execution result text of the current solution step; And wherein, in response to the current step text being the termination text, determining the current historical step sequence text as the target step sequence text includes: In response to the current step text being the termination text and the current execution result text being the first answer text indicating the answer to the first question, the current historical step sequence text is determined as the target step sequence text.
3. The method according to claim 2, wherein: The executing the current solution step represented by the current step text to obtain the current execution result text of the current solution step includes: Identify the knowledge domain corresponding to the first question; Obtaining an executor for executing the problem-solving steps of the knowledge domain; and The current step text is input into the executor to obtain the current execution result text output by the executor.
4. The method according to any one of claims 1 to 3, further comprising: Execute each solution step in the target step sequence text respectively to obtain an execution result text of each solution step; generating a first answer text based on the target step sequence text and the execution result text of each answer step, wherein the first answer text represents the answer process of the first question; as well as Based on the first question text and the first answer text, an output of a third language model is optimized.
5. The method according to claim 4, wherein Optimizing the output of the third language model based on the first question text and the first answer text includes: Obtaining a second question text, wherein the second question text represents a second question to be answered; and The first question text, the first answer text and the second question text are input into the third language model to obtain a second answer text output by the third language model, wherein the second answer text represents the answer process of the second question.
6. The method according to claim 4, wherein: The third language model is the same as the trained text generation model used to generate the current step text.
7. A text generation device, comprising: An acquisition module is configured to acquire a first question text, wherein the first question text represents a first question for which a sequence of answer steps is to be determined; an initialization module configured to initialize the historical step sequence text to a preset value; and an updating module configured to update the historical step sequence text at least once based on the first question text to obtain a target step sequence text, wherein the target step sequence text represents a sequence of steps for answering the first question, the target step sequence text includes at least one step text, and each step text in the at least one step text represents a step for answering the first question; The update module includes: a generating unit configured to generate a current step text based on the first question text and the current historical step sequence text, comprising: inputting the first question text and the current historical step sequence text into a text generation model to obtain a current step text output by the text generation model, wherein the current step text represents a current step of answering the first question; an updating unit configured to, in response to the current step text not being a preset termination text, concatenate the current historical step sequence text with the current step text to obtain an updated historical step sequence text; and The determining unit is configured to determine the current historical step sequence text as the target step sequence text in response to the current step text being the termination text.
8. The device according to claim 7, wherein The text generation model is a pre-trained second language model, and the update module further includes: an execution unit, configured to execute the current solution step represented by the current step text to obtain a current execution result text of the current solution step; And wherein, the determining unit is further configured to: In response to the current step text being the termination text and the current execution result text being the first answer text indicating the answer to the first question, the current historical step sequence text is determined as the target step sequence text.
9. The device according to claim 8, wherein The execution unit includes: an identification subunit, configured to identify the knowledge domain corresponding to the first question; an acquisition subunit configured to acquire an executor for executing a problem-solving step in the knowledge domain; and The execution subunit is configured to input the current step text into the executor to obtain the current execution result text output by the executor.
10. The apparatus according to any one of claims 7 to 9, further comprising: an execution module, configured to execute each solution step in the target step sequence text respectively to obtain an execution result text of each solution step; a generating module configured to generate a first answer text based on the target step sequence text and the execution result text of each answer step, wherein the first answer text represents the answer process of the first question; as well as The optimization module is configured to optimize the output of the third language model based on the first question text and the first answer text.
11. The device according to claim 10, wherein The optimization module includes: an acquiring unit configured to acquire a second question text, wherein the second question text represents a second question to be answered; and The input unit is configured to input the first question text, the first answer text and the second question text into the third language model to obtain a second answer text output by the third language model, wherein the second answer text represents the answer process of the second question.
12. The device according to claim 10, wherein The third language model is the same as the trained text generation model used to generate the current step text.
13. An electronic device comprising: at least one processor; as well as a memory communicatively coupled to the at least one processor; in The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 6.
14. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to enable a computer to execute the method according to any one of claims 1 to 6.
15. A computer program product comprising computer program instructions, wherein: When the computer program instructions are executed by a processor, the method of any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Answer prediction method and device for question and answer system, electronic equipment and storage medium
CN108733703A
Question and answer model training method and device, question and answer method and device, equipment and storage medium
CN114648021A