Method and apparatus for controllable generation
By obtaining user constraint information and pre-trained models to generate candidate text, assessing its satisfaction level and updating the model, the accuracy problem of generative language models in controlling text length, style and format is solved, and user experience and computing resource utilization is improved.
Patent Information
- Application Number
- PCT/CN2024/092543
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-05-19
- Filing Date
- 2024-05-11
- Publication Date
- 2024-11-28
AI Technical Summary
The existing generative language model lacks high precision in controlling the length, style and format of generated text, resulting in poor user experience and wasted computing resources, especially in multiple rounds of conversations, which is difficult to effectively control the number of conversation rounds.
By obtaining the constraint information input by the user, using the pre-trained model to generate candidate text, and scoring and reward value calculations are performed based on the constraint information, the model is updated to improve control accuracy, and the satisfaction of candidate text is evaluated using neural networks and functional functions, combined with reinforcement learning Optimize the model.
High-precision control of generated text is realized, user waiting time and computing resource consumption are reduced, and model multi-round dialogue capabilities are improved.
Smart Images

Figure CN2024092543_28112024_PF_FP_ABST
Abstract
Description
A controllable generation method and device
[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office on May 19, 2023, with application number 202310574303.3 and invention name “A method and device for controllable generation”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the field of artificial intelligence, and in particular to a controllable generation method and device thereof. Background Art
[0003] Artificial Intelligence (AI) is the theory, methods, techniques, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, to perceive the environment, acquire knowledge, and use that knowledge to achieve optimal results. In other words, AI is a branch of computer science that seeks to understand the essence of intelligence and develop new intelligent machines that can respond in a manner similar to human intelligence. AI also studies the design principles and implementation methods of various intelligent machines, enabling them to possess the capabilities of perception, reasoning, and decision-making.
[0004] Generative language models often require control over the length, style, and format of generated sequences. For example, the word count, sentence count, paragraph count, and layout format of generated summaries or responses can be controlled. The effectiveness of this control largely determines the user experience and the efficient utilization of computing resources.
[0005] For example, existing large models tend to generate long answers. However, because generating long answers requires a lot of time and computing resources and is prone to introducing factual errors, they don't always meet user needs. In multi-turn conversations, the length of each reply determines the number of turns the model can handle. Effectively controlling the length of generated answers can help users reduce reading and waiting time, save computing power required for inference and generation, and enhance the model's multi-turn capabilities.
[0006] Prior art uses prompt-based control methods to control the length, style, or format of text generated by a model. Specifically, constraints on the length, style, or format of the generated text are added to prompt control instructions. These prompt control instructions are then processed by a large model, and supervised fine-tuning is performed based on the processing results and the corresponding annotations of the prompt control instructions. However, this approach lacks feedback information based on constraint errors, making it difficult to achieve high control accuracy.
[0007] Summary of the Invention
[0008] This application provides a controllable generation method that can enable the trained model to achieve higher control accuracy.
[0009] In a first aspect, the present application provides a method for controllable generation, the method comprising: obtaining constraint information, the constraint information being directly input by a user or extracted from a text generation request input by a user; the constraint information being at least one feature item of the generated text and a constraint on a key value of each feature item; obtaining a plurality of candidate generated texts through a pre-trained model according to the text generation request; obtaining a score for each candidate generated text according to the constraint information and the plurality of candidate generated texts, the score being related to the degree to which the corresponding candidate generated text satisfies the constraint information; and determining a target text from the plurality of candidate generated texts according to the score.
[0010] In one possible implementation, the constraint information may only include feature items and key-value constraints corresponding to the feature items. Compared with the text generation request, the constraint information eliminates the semantic requirements of the corresponding generated text, and retains the requirements within a limited space such as quantity, style and format (that is, the requirements are selected within a limited range). Therefore, the constraint information can also be called standardized format control instructions.
[0011] Standardization can be understood as information in a fixed format. For example, the constraint information includes feature items and their corresponding key-value constraints, and the positional relationship between the various pieces of information (e.g., feature items and their corresponding key-value constraints) in the constraint information is fixed.
[0012] Through standardization, the reward value can be directly calculated through rules in the future, and the standardized constraint information can also enable the model to better learn the effective information after being input into the model.
[0013] By directly obtaining or extracting constraint information from the user's input in the above manner, and determining the score for determining the output text by the degree of satisfaction between the constraint information and the generated text output by the large model, higher control accuracy can be achieved.
[0014] In a possible implementation, the key value constraint is specifically input by the user through an input box or input control of an interface, and the interface includes multiple feature items and an input box or input control corresponding to each feature item.
[0015] In a possible implementation, the constraint of the key value is a constraint on the value range of the key value, and the constraint of the value range includes at least one of the following: greater than a first value, less than a second value, equal to a third value, and between two values.
[0016] In one possible implementation, obtaining a score for each of the candidate generated texts based on the constraint information and the multiple candidate generated texts includes: obtaining a score for each of the candidate generated texts through a neural network based on the constraint information and the multiple candidate generated texts; or obtaining an actual value of each feature item of each of the candidate generated texts through a functional function based on the constraint information and the multiple candidate generated texts, and determining a score based on the relationship between the actual value and the constraint of the corresponding key value.
[0017] In a possible implementation, the feature item is quantity, style or format.
[0018] In a second aspect, the present application provides a controllable generation method, which includes: obtaining constraint information, wherein the constraint information is directly input by the user or extracted from a text generation request input by the user; the constraint information is at least one feature item of the generated text, and a constraint on the key value of each feature item; according to the text generation request, a target generated text is obtained through a pre-trained model; according to the constraint information and the target generated text, a reward value corresponding to the target generated text is obtained, and the reward value is related to the degree to which the target generated text satisfies the constraint information; according to the reward value, the pre-trained model is updated.
[0019] Through the above method, the constraint information is directly obtained or extracted from the user's input, and the reward value used to update the model is determined by the degree of satisfaction between the constraint information and the generated text output by the large model. Compared with determining the reward value only by using the generated text and annotations, the reward value in this application can better express the degree of satisfaction of the generated text with the constraint information, so that the trained model can achieve higher control accuracy.
[0020] In a possible implementation, updating the pre-trained model according to the reward value includes: updating the pre-trained model through reinforcement learning according to the reward value.
[0021] In a possible implementation, the constraint of the key value is a constraint on the value range of the key value, and the constraint of the value range includes at least one of the following: greater than a first value, less than a second value, equal to a third value, and between two values.
[0022] In one possible implementation, generating text according to the constraint information and the target to obtain a reward value corresponding to the target-generated text includes: generating text according to the constraint information and the target through a neural network to obtain a reward value corresponding to the target-generated text; or generating text according to the constraint information and the target through a functional function to obtain a reward value corresponding to the target-generated text.
[0023] In a possible implementation, the feature item is quantity, style or format.
[0024] In a possible implementation, the method further includes: constructing a loss based on the target generated text and the corresponding true value; and updating the pre-trained model based on the reward value includes: updating the pre-trained model based on the reward value and the loss.
[0025] In a possible implementation, the constraint information is information in a fixed format.
[0026] In a third aspect, the present application provides a controllable generation device, the device comprising:
[0027] An acquisition module is configured to acquire constraint information, wherein the constraint information is directly input by a user or extracted from a text generation request input by a user; the constraint information is at least one feature item of the generated text and a constraint on a key value of each feature item;
[0028] A processing module, configured to generate a plurality of candidate generated texts based on the text generation request through a pre-trained model;
[0029] Obtaining a score for each candidate generated text based on the constraint information and the plurality of candidate generated texts, wherein the score is related to the degree to which the corresponding candidate generated text satisfies the constraint information;
[0030] According to the scoring, a target text is determined from the multiple candidate generated texts.
[0031] In a possible implementation, the constraint information is information in a fixed format.
[0032] In a possible implementation, the key value constraint is specifically input by the user through an input box or input control of an interface, and the interface includes multiple feature items and an input box or input control corresponding to each feature item.
[0033] In a possible implementation, the constraint of the key value is a constraint on the value range of the key value, and the constraint of the value range includes at least one of the following: greater than a first value, less than a second value, equal to a third value, and between two values.
[0034] In a possible implementation, the processing module is specifically configured to:
[0035] According to the constraint information and the plurality of candidate generated texts, a score for each candidate generated text is obtained through a neural network; or,
[0036] According to the constraint information and the multiple candidate generated texts, the actual value of each candidate generated text in each feature item is obtained through a functional function, and a score is determined according to the relationship between the actual value and the constraint of the corresponding key value.
[0037] In a possible implementation, the feature item is quantity, style or format.
[0038] In a fourth aspect, the present application provides a controllable generation device, comprising:
[0039] An acquisition module is configured to acquire constraint information, wherein the constraint information is directly input by a user or extracted from a text generation request input by a user; the constraint information is at least one feature item of the generated text and a constraint on a key value of each feature item;
[0040] A processing module is used to generate a target generated text based on the text generation request through a pre-trained model;
[0041] Obtaining a reward value corresponding to the target-generated text according to the constraint information and the target-generated text, wherein the reward value is related to the degree to which the target-generated text satisfies the constraint information;
[0042] The pre-trained model is updated according to the reward value.
[0043] In a possible implementation, the constraint information is information in a fixed format.
[0044] In a possible implementation, the processing module is specifically configured to:
[0045] The pre-trained model is updated through reinforcement learning according to the reward value.
[0046] In a possible implementation, the constraint of the key value is a constraint on the value range of the key value, and the constraint of the value range includes at least one of the following: greater than a first value, less than a second value, equal to a third value, and between two values.
[0047] In a possible implementation, the processing module is specifically configured to:
[0048] According to the constraint information and the target generated text, a reward value corresponding to the target generated text is obtained through a neural network; or
[0049] According to the constraint information and the target generation text, a reward value corresponding to the target generation text is obtained through a functional function.
[0050] In a possible implementation, the feature item is quantity, style or format.
[0051] In a possible implementation, the processing module is further configured to:
[0052] Construct a loss based on the target generated text and the corresponding ground truth;
[0053] The processing module is specifically used to:
[0054] The pre-trained model is updated according to the reward value and the loss.
[0055] In the fifth aspect, an embodiment of the present application provides a controllable generation device, which may include a memory, a processor, and a bus system, wherein the memory is used to store programs, and the processor is used to execute the programs in the memory to perform the first aspect and any optional method thereof, as well as the second aspect and any optional method thereof.
[0056] In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer-readable storage medium is run on a computer, the computer executes the above-mentioned first aspect and any optional method thereof, and the above-mentioned second aspect and any optional method thereof.
[0057] In a seventh aspect, an embodiment of the present application provides a computer program which, when executed on a computer, enables the computer to execute the above-mentioned first aspect and any optional method thereof, and the above-mentioned second aspect and any optional method thereof.
[0058] In an eighth aspect, the present application provides a chip system comprising a processor for supporting a device for executing controllable generation to implement the functions described in the above aspects, such as transmitting or processing data or information described in the above methods. In one possible design, the chip system further comprises a memory for storing program instructions and data necessary for executing the device or training the device. The chip system may consist of a chip alone or may include a chip and other discrete components. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] FIG1A is a schematic diagram of a structure of an artificial intelligence main framework;
[0060] Figures 1B to 1C are schematic diagrams of the application system framework of the present application;
[0061] FIG1D is a schematic diagram of an optional hardware structure of a terminal;
[0062] FIG2 is a schematic diagram of the structure of a server;
[0063] FIG3 is a schematic diagram of a system architecture of the present application;
[0064] Figure 4 shows a process of cloud services;
[0065] FIG5 is a schematic diagram of a process of a controllable generation method provided in an embodiment of the present application;
[0066] FIG6 is a schematic diagram of a standard instruction extraction;
[0067] 7 to 9 are schematic diagrams of a process of a controllable generation method provided in an embodiment of the present application;
[0068] Figures 10 and 11A are schematic diagrams of an interface;
[0069] FIG11B is a schematic diagram of a process of a controllable generation method provided in an embodiment of the present application;
[0070] FIG11C is a diagram illustrating a beneficial effect;
[0071] FIG12 is a schematic structural diagram of a controllable generation device provided in an embodiment of the present application;
[0072] FIG13 is a schematic diagram of a structure of an execution device provided in an embodiment of the present application;
[0073] FIG14 is a schematic diagram of a structure of a training device provided in an embodiment of the present application;
[0074] FIG15 is a schematic structural diagram of a chip provided in an embodiment of the present application. DETAILED DESCRIPTION
[0075] The following describes the embodiments of the present application in conjunction with the accompanying drawings. The terms used in the implementation methods of the present application are only used to explain the specific embodiments of the present application and are not intended to limit the present application.
[0076] The embodiments of the present application are described below in conjunction with the accompanying drawings. Those skilled in the art will appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0077] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, and this is merely a way of distinguishing the objects of the same attributes when describing them in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.
[0078] As used herein, the terms "substantially," "about," and similar terms are used as terms of approximation, not as terms of degree, and are intended to take into account the inherent deviations in measurements or calculations that one of ordinary skill in the art would recognize. Furthermore, the use of "may" when describing embodiments of the present application refers to "one or more possible embodiments." As used herein, the terms "use," "using," and "used" may be considered synonymous with the terms "utilize," "utilizing," and "utilized," respectively. Additionally, the term "exemplary" is intended to refer to an example or illustration.
[0079] First, let's describe the overall workflow of an AI system. See Figure 1A, which shows a schematic diagram of the main AI framework. This AI framework will be explained from two perspectives: the "intelligent information chain" (horizontal axis) and the "IT value chain" (vertical axis). The "intelligent information chain" reflects the entire process from data acquisition to processing. For example, it could be the general process of intelligent information perception, intelligent information representation and formation, intelligent reasoning, intelligent decision-making, and intelligent execution and output. Throughout this process, data undergoes a condensed journey from "data-information-knowledge-wisdom." The "IT value chain," spanning the underlying infrastructure of human intelligence, information (provided and processed by technology), and the system's industrial ecosystem, reflects the value that AI brings to the information technology industry.
[0080] (1) Infrastructure
[0081] Infrastructure provides computing power for AI systems, enabling communication with the outside world and supporting this through a foundational platform. External communication occurs through sensors; computing power is provided by intelligent chips (CPUs, NPUs, GPUs, ASICs, FPGAs, and other hardware accelerators). The foundational platform includes a distributed computing framework and network-related platform guarantees and support, including cloud storage and computing, and interconnected networks. For example, sensors communicate with the outside world to acquire data, which is then fed into the intelligent chips within the distributed computing system provided by the foundational platform for computation.
[0082] (2) Data
[0083] Data above the infrastructure layer represents data sources for AI. This data includes graphics, images, voice, and text, as well as IoT data from traditional devices. This includes business data from existing systems and sensor data such as force, displacement, liquid level, temperature, and humidity.
[0084] (3) Data processing
[0085] Data processing generally includes data training, machine learning, deep learning, search, reasoning, decision-making, etc.
[0086] Among them, machine learning and deep learning can symbolize and formalize data for intelligent information modeling, extraction, preprocessing, and training.
[0087] Reasoning refers to the process of simulating human intelligent reasoning in computers or intelligent systems, using formalized information to perform machine thinking and solve problems based on reasoning control strategies. Typical functions are search and matching.
[0088] Decision-making refers to the process of making decisions after intelligent information is reasoned, and usually provides functions such as classification, sorting, and prediction.
[0089] (4) General ability
[0090] After the data has undergone the data processing mentioned above, some general capabilities can be further formed based on the results of the data processing, such as algorithms or a general system, for example, translation, text analysis, computer vision processing, speech recognition, image recognition, etc.
[0091] (5) Smart products and industry applications
[0092] Smart products and industry applications refer to the products and applications of artificial intelligence systems in various fields. They are the encapsulation of the overall artificial intelligence solution, which productizes intelligent information decision-making and realizes practical application. Its application areas mainly include: smart terminals, smart transportation, smart medical care, autonomous driving, smart cities, etc.
[0093] This application can be applied to the field of text processing in the field of artificial intelligence. Taking text processing as an example, the following will introduce multiple application scenarios that have been implemented in products.
[0094] First, the application scenario of this application is introduced.
[0095] This application can be applied to, but is not limited to, applications with text generation functions (hereinafter referred to as text generation applications) or cloud services provided by cloud-side servers, etc., which are described below:
[0096] 1. Text generation applications:
[0097] The product form of the embodiment of the present application can be a text generation application. The application with text generation function can be run on a terminal device or a cloud-side server.
[0098] In a possible implementation, a text generation application may implement a task of generating text based on an input text generation request (or may be referred to as a prompt control instruction) to obtain a processing result.
[0099] Among them, text generation requests can indicate generative tasks such as summarization, dialogue, question answering, and translation.
[0100] For example, the text generation request may specify constraints on some feature items of the generated text, such as quantity feature constraints, style feature constraints, and format feature constraints.
[0101] For example, a text generation request may be: Please summarize the following text into an abstract of no more than 100 words.
[0102] For example, a text generation request may be: Use the four characters "Pangu Zhizi" to start each sentence, and write a seven-character quatrain with hidden acrostic poetry, rhyming with "a".
[0103] In one possible implementation, a user may open a text generation application installed on a terminal device and input text processing instructions (or directly input constraint information for generating text). The text generation application may process the text processing instructions (or directly input constraint information for generating text) using the method provided in an embodiment of the present application and present the processing results to the user (the presentation method may be, but is not limited to, display, saving, uploading to the cloud, etc.).
[0104] In one possible implementation, a user can open a text generation application installed on a terminal device and enter text processing instructions (or directly enter constraint information for generating text). The text generation application can send the text processing instructions (or directly enter constraint information for generating text) to a server on the cloud side. The server on the cloud side processes the text processing instructions (or directly enter constraint information for generating text) using the method provided in an embodiment of the present application, and transmits the processing results back to the terminal device. The terminal device can present the processing results to the user (the presentation method can be but is not limited to display, saving, uploading to the cloud side, etc.).
[0105] Optionally, the input and output may occur on a payment dialogue interface, a terminal application service that calls a related interface, or a built-in function of the terminal device.
[0106] Next, the text generation application in the embodiment of this application is introduced from the perspective of functional architecture and product architecture that implements the functions.
[0107] Referring to FIG. 1B , FIG. 1B is a schematic diagram of the functional architecture of a text generation application in an embodiment of the present application:
[0108] In one possible implementation, as shown in FIG1B , a text generation application 102 may receive input parameters 101 (e.g., including text processing instructions (or directly input constraint information for generating text)) and generate processing results 103. The text generation application 102 may be executed on (for example) at least one computer system and include computer code that, when executed by one or more computers, causes the computers to execute the method provided in the embodiments of the present application.
[0109] Referring to FIG. 1C , FIG. 1C is a schematic diagram of the entity architecture for running a text generation application in an embodiment of the present application:
[0110] Referring to FIG1C , FIG1C shows a schematic diagram of a system architecture. The system may include a terminal 100 and a server 200. The server 200 may include one or more servers (FIG1C illustrates one server as an example), and the server 200 may provide the method provided in the embodiments of the present application to one or more terminals.
[0111] Among them, a text generation application can be installed on the terminal 100. The above application and web page can provide an interface. The terminal 100 can receive relevant parameters entered by the user on the text generation interface and send the above parameters to the server 200. The server 200 can obtain processing results based on the received parameters and return the processing results to the terminal 100.
[0112] It should be understood that in some optional implementations, the terminal 100 can also complete the action of obtaining the processing result based on the received parameters by itself without the need for the cooperation of the server, and the embodiments of the present application are not limited to this.
[0113] Next, the product form of the terminal 100 in FIG1C is described;
[0114] The terminal 100 in the embodiment of the present application can be a mobile phone, a tablet computer, a wearable device, an in-vehicle device, an augmented reality (AR) / virtual reality (VR) device, a laptop computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), etc., and the embodiment of the present application does not impose any restrictions on this.
[0115] FIG1D shows a schematic diagram of an optional hardware structure of the terminal 100 .
[0116] 1D , the terminal 100 may include components such as a radio frequency unit 110, a memory 120, an input unit 130, a display unit 140, a camera 150 (optional), an audio circuit 160 (optional), a speaker 161 (optional), a microphone 162 (optional), a processor 170, an external interface 180, and a power supply 190. Those skilled in the art will appreciate that FIG1D is merely an example of a terminal or multi-function device and does not limit the terminal or multi-function device. The terminal or multi-function device may include more or fewer components than shown, or may combine certain components or have different components.
[0117] The input unit 130 can be used to receive input digital or character information and generate key signal input related to user settings and function control of the portable multifunction device. Specifically, the input unit 130 may include a touch screen 131 (optional) and / or other input devices 132. The touch screen 131 can detect user touch operations on or near it (for example, operations performed on or near the touch screen using a finger, joint, stylus, or any other suitable object) and drive corresponding connected devices according to pre-set programs. The touch screen can detect user touch actions on the touch screen, convert the touch actions into touch signals and transmit them to the processor 170. It can also receive and execute commands sent by the processor 170; the touch signals include at least touch point coordinate information. The touch screen 131 provides an input interface and an output interface between the terminal 100 and the user. Touch screens can be implemented using various types, including resistive, capacitive, infrared, and surface acoustic wave. In addition to the touch screen 131, the input unit 130 may also include other input devices. Specifically, the other input devices 132 may include, but are not limited to, one or more of a physical keyboard, function keys (such as a volume control key, a switch key, etc.), a trackball, a mouse, a joystick, and the like.
[0118] The input device 132 may receive input text processing instructions (or directly input constraint information for generating text), etc.
[0119] The display unit 140 may be used to display information input by the user or provided to the user, various menus of the terminal 100, interactive interfaces, file display, and / or playback of any multimedia file. In an embodiment of the present application, the display unit 140 may be used to display the interface of a text generation application, processing results, etc.
[0120] Memory 120 can be used to store instructions and data. It primarily includes an instruction storage area and a data storage area. The data storage area can store various data, such as multimedia files and text. The instruction storage area can store software units such as the operating system, applications, and instructions required for at least one function, or subsets or extensions thereof. It may also include non-volatile random access memory (RAM). It provides processor 170 with management functions for the hardware, software, and data resources within the computing and processing device, supporting control software and applications. It is also used to store multimedia files and running programs and applications.
[0121] The processor 170 is the control center of the terminal 100. It connects all components of the terminal 100 using various interfaces and circuits. By executing instructions stored in the memory 120 and accessing data stored therein, it executes various functions of the terminal 100 and processes data, thereby providing overall control of the terminal device. Optionally, the processor 170 may include one or more processing units. Preferably, the processor 170 may integrate an application processor and a modem processor, with the application processor primarily processing the operating system, user interface, and application programs, while the modem processor primarily handles wireless communications. It is understood that the modem processor may not be integrated into the processor 170. In some embodiments, the processor and memory may be implemented on a single chip; in other embodiments, they may be implemented on separate chips. The processor 170 may also generate corresponding operational control signals and send them to the corresponding components of the computing and processing device. It may also read and process data in the software, particularly the data and programs in the memory 120, to enable the various functional modules therein to perform their corresponding functions, thereby controlling the corresponding components to operate as instructed.
[0122] Among them, the memory 120 can be used to store software codes related to the controllable generation method, the processor 170 can execute the steps of the controllable generation method of the chip, and can also schedule other units (such as the above-mentioned input unit 130 and display unit 140) to implement corresponding functions.
[0123] The RF unit 110 (optional) can be used to send and receive information or receive and send signals during a call. For example, after receiving downlink information from the base station, it is passed to the processor 170 for processing; in addition, it sends the designed uplink data to the base station. Generally, the RF circuit includes but is not limited to an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier (LNA), a duplexer, etc. In addition, the RF unit 110 can also communicate with network devices and other devices via wireless communication. This wireless communication can use any communication standard or protocol, including but not limited to Global System of Mobile communication (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Long Term Evolution (LTE), email, Short Messaging Service (SMS), etc.
[0124] In the embodiment of the present application, the RF unit 110 may send a text processing instruction (or directly input constraint information for generating text) to the server 200 and receive a processing result sent by the server 200.
[0125] It should be understood that the radio frequency unit 110 is optional and can be replaced by other communication interfaces, such as a network port.
[0126] The terminal 100 also includes a power supply 190 (such as a battery) for supplying power to various components. Preferably, the power supply can be logically connected to the processor 170 through a power management system, thereby managing functions such as charging, discharging, and power consumption through the power management system.
[0127] The terminal 100 further includes an external interface 180 , which may be a standard Micro USB interface or a multi-pin connector, and may be used to connect the terminal 100 to other devices for communication, or to connect a charger to charge the terminal 100 .
[0128] Although not shown, the terminal 100 may also include a flash, a wireless fidelity (WiFi) module, a Bluetooth module, sensors with different functions, etc., which are not described in detail here. Some or all of the methods described below may be applied to the terminal 100 shown in FIG1D .
[0129] Next, the product form of the server 200 in FIG1C is described;
[0130] FIG2 provides a schematic diagram of the structure of a server 200. As shown in FIG2, the server 200 includes a bus 201, a processor 202, a communication interface 203, and a memory 204. The processor 202, the memory 204, and the communication interface 203 communicate with each other via the bus 201.
[0131] Bus 201 may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. Buses can be categorized as address buses, data buses, and control buses. For ease of illustration, FIG2 shows only one thick line, but this does not imply that there is only one bus or only one type of bus.
[0132] The processor 202 may be any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).
[0133] The memory 204 may include volatile memory, such as random access memory (RAM). The memory 204 may also include non-volatile memory, such as read-only memory (ROM), flash memory, hard drive (HDD), or solid state drive (SSD).
[0134] The memory 204 may be used to store software codes related to the controllable generation method, and the processor 202 may execute the steps of the controllable generation method of the chip, and may also schedule other units to implement corresponding functions.
[0135] It should be understood that the above-mentioned terminal 100 and server 200 can be centralized or distributed devices, and the processors in the above-mentioned terminal 100 and server 200 (such as processor 170 and processor 202) can be hardware circuits (such as application specific integrated circuit (ASIC), field-programmable gate array (FPGA), general-purpose processor, digital signal processor (DSP), microprocessor or microcontroller, etc.), or a combination of these hardware circuits. For example, the processor can be a hardware system with an instruction execution function, such as a CPU, DSP, etc., or a hardware system without an instruction execution function, such as an ASIC, FPGA, etc., or a combination of the above-mentioned hardware systems without an instruction execution function and hardware systems with an instruction execution function.
[0136] It should be understood that the steps related to the model reasoning process in the embodiments of this application involve AI-related operations. When performing AI operations, the instruction execution architecture of the terminal device and server is not limited to the processor-memory architecture described above. The system architecture provided in the embodiments of this application is described in detail below with reference to Figure 3.
[0137] FIG3 is a schematic diagram of the system architecture provided by an embodiment of the present application. As shown in FIG3 , the system architecture 500 includes an execution device 510 , a training device 520 , a database 530 , a client device 540 , a data storage system 550 , and a data acquisition system 560 .
[0138] The execution device 510 includes a calculation module 511, an I / O interface 512, a pre-processing module 513, and a post-processing module 514. The calculation module 511 may include the target model / rule 501, and the pre-processing module 513 and the post-processing module 514 are optional.
[0139] The execution device 510 may be a terminal device or a server that runs the above-mentioned text generation application.
[0140] The data collection device 560 is used to collect training samples. After collecting the training samples, the data collection device 560 stores these training samples in the database 530.
[0141] The training device 520 can train the neural network to be trained (such as the pre-trained model, neural network, etc. in the embodiment of the present application) based on the training samples maintained in the database 530 to obtain the target model / rule 501.
[0142] It should be understood that the training device 520 can perform a pre-training process on the neural network to be trained based on the training samples maintained in the database 530, or fine-tune the model based on the pre-training.
[0143] It should be noted that, in actual applications, the training samples maintained in the database 530 may not all be collected by the data acquisition device 560, but may also be received from other devices. It should also be noted that the training device 520 may not train the target model / rule 501 entirely based on the training samples maintained in the database 530, but may also obtain training samples from the cloud or other places for model training. The above description should not be used as a limitation on the embodiments of the present application.
[0144] The target model / rule 501 obtained through training with the training device 520 can be applied to different systems or devices, such as the execution device 510 shown in FIG3 . The execution device 510 can be a terminal, such as a mobile phone terminal, a tablet computer, a laptop computer, an augmented reality (AR) / virtual reality (VR) device, an in-vehicle terminal, etc., or a server, etc.
[0145] Specifically, the training device 520 may transfer the trained model to the execution device 510 .
[0146] In Figure 3, the execution device 510 is configured with an input / output (I / O) interface 512 for data interaction with external devices. The user can input data (such as text processing instructions in the embodiment of the present application (or directly input constraint information for generating text)) to the I / O interface 512 through the client device 540.
[0147] Preprocessing module 513 and preprocessing module 514 are used to preprocess the input data received by I / O interface 512. It should be understood that preprocessing module 513 and preprocessing module 514 may be absent or only one preprocessing module may be present. If preprocessing module 513 and preprocessing module 514 are absent, computing module 511 may be used directly to process the input data.
[0148] When the execution device 510 preprocesses the input data, or when the computing module 511 of the execution device 510 performs calculations and other related processing, the execution device 510 can call the data, code, etc. in the data storage system 550 for corresponding processing, and can also store the data, instructions, etc. obtained from the corresponding processing in the data storage system 550.
[0149] Finally, the I / O interface 512 provides the processed results to the client device 540 and thus to the user.
[0150] In the scenario shown in FIG3 , the user can manually input data, and this "manual input data" can be operated through the interface provided by I / O interface 512. In another scenario, client device 540 can automatically send input data to I / O interface 512. If user authorization is required for client device 540 to automatically send input data, the user can set the corresponding permissions in client device 540. The user can view the results output by execution device 510 on client device 540, and the specific presentation form can be a display, sound, action, or other specific method. Client device 540 can also serve as a data acquisition terminal, collecting input data input into I / O interface 512 and output results output from I / O interface 512 as new sample data, and storing them in database 530. Of course, collection can also be performed without client device 540, and instead the I / O interface 512 directly stores the input data input into I / O interface 512 and output results output from I / O interface 512 as new sample data in database 530.
[0151] It is worth noting that FIG3 is merely a schematic diagram of a system architecture provided by an embodiment of the present application, and the positional relationships between the devices, components, modules, etc. shown in the figure do not constitute any limitation. For example, in FIG3 , the data storage system 550 is an external memory relative to the execution device 510. In other cases, the data storage system 550 can also be placed in the execution device 510. It should be understood that the execution device 510 can be deployed in the client device 540.
[0152] From the inference side of the model:
[0153] In the embodiment of the present application, the computing module 511 of the above-mentioned execution device 510 can obtain the code stored in the data storage system 550 to implement the steps related to the model reasoning process in the embodiment of the present application.
[0154] In an embodiment of the present application, the computing module 511 of the execution device 510 may include a hardware circuit (such as an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA), a general-purpose processor, a digital signal processor (DSP), a microprocessor or a microcontroller, etc.), or a combination of these hardware circuits. For example, the training device 520 may be a hardware system with an instruction execution function, such as a CPU, DSP, etc., or a hardware system without an instruction execution function, such as an ASIC, FPGA, etc., or a combination of the above-mentioned hardware systems without an instruction execution function and hardware systems with an instruction execution function.
[0155] Specifically, the computing module 511 of the execution device 510 can be a hardware system with an execution instruction function, and the steps related to the model reasoning process provided in the embodiment of the present application can be software codes stored in the memory. The computing module 511 of the execution device 510 can obtain the software code from the memory and execute the obtained software code to implement the steps related to the model reasoning process provided in the embodiment of the present application.
[0156] It should be understood that the computing module 511 of the execution device 510 can be a combination of a hardware system that does not have the function of executing instructions and a hardware system that has the function of executing instructions. Some of the steps related to the model reasoning process provided in the embodiment of the present application can also be implemented by the hardware system that does not have the function of executing instructions in the computing module 511 of the execution device 510, which is not limited here.
[0157] From the training side of the model:
[0158] In an embodiment of the present application, the above-mentioned training device 520 can obtain the code stored in the memory (not shown in Figure 3, which can be integrated into the training device 520 or deployed separately from the training device 520) to implement the steps related to model training in the embodiment of the present application.
[0159] In an embodiment of the present application, the training device 520 may include a hardware circuit (such as an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA), a general-purpose processor, a digital signal processor (DSP), a microprocessor or a microcontroller, etc.), or a combination of these hardware circuits. For example, the training device 520 may be a hardware system with an instruction execution function, such as a CPU, DSP, etc., or a hardware system without an instruction execution function, such as an ASIC, FPGA, etc., or a combination of the above-mentioned hardware systems without an instruction execution function and hardware systems with an instruction execution function.
[0160] It should be understood that the training device 520 can be a combination of a hardware system that does not have the function of executing instructions and a hardware system that has the function of executing instructions. Some of the steps related to model training provided in the embodiments of the present application can also be implemented by the hardware system in the training device 520 that does not have the function of executing instructions, which is not limited here.
[0161] 2. Text generation cloud services provided by the server:
[0162] In a possible implementation, the server may provide a text generation service to the terminal side through an application programming interface (API).
[0163] Among them, the terminal device can send relevant parameters (such as text processing instructions (or directly input constraint information for generating text)) to the server through the API provided by the cloud. The server can obtain processing results based on the received parameters, etc., and return the processing results to the terminal.
[0164] The description of the terminal and the server can be the same as that of the above embodiments, and will not be repeated here.
[0165] FIG4 shows a process of using a text generation cloud service provided by a cloud platform.
[0166] 1. Activate and purchase content review services.
[0167] 2. Users can download the software development kit (SDK) corresponding to the content review service. Usually, the cloud platform provides multiple development versions of the SDK for users to choose according to the requirements of the development environment, such as JAVA version SDK, Python version SDK, PHP version SDK, Android version SDK, etc.
[0168] 3. After the user downloads the corresponding version of the SDK to the local computer as needed, import the SDK project into the local development environment, configure and debug it in the local development environment. The local development environment can also be used to develop other functions, forming an application that integrates text generation capabilities.
[0169] 4. When a text generation application is in use and needs to generate text, it can trigger a text generation API call. When the application triggers the text generation function, it initiates an API request to the running instance of the text generation service in the cloud environment. The API request carries text processing instructions (or directly input constraint information for text generation). The running instance in the cloud environment processes the text processing instructions (or directly input constraint information for text generation) and obtains the processing results.
[0170] 5. The cloud environment returns the processing results to the application, thereby completing a method call provided in an embodiment of the present application.
[0171] Since the embodiments of the present application involve the application of a large number of neural networks, in order to facilitate understanding, the relevant terms and related concepts such as neural networks involved in the embodiments of the present application are first introduced below.
[0172] (1) Neural Network
[0173] A neural network can be composed of neural units. A neural unit can refer to an operation unit that takes xs (i.e., input data) and intercept 1 as input. The output of the operation unit can be:
[0174] Where s = 1, 2, ... n, n is a natural number greater than 1, Ws is the weight of xs, and b is the bias of the neural unit. f is the activation function of the neural unit, which is used to introduce nonlinear characteristics into the neural network to convert the input signal of the neural unit into the output signal. The output signal of the activation function can be used as the input of the next convolutional layer, and the activation function can be a sigmoid function. A neural network is a network formed by connecting multiple single neural units mentioned above, that is, the output of one neural unit can be the input of another neural unit. The input of each neural unit can be connected to the local receptive field of the previous layer to extract the features of the local receptive field. The local receptive field can be an area composed of several neural units.
[0175] (2) Deep Neural Networks
[0176] Deep Neural Network (DNN), also known as multi-layer neural network, can be understood as a neural network with many hidden layers. There is no special metric for "many" here. Based on the position of different layers in DNN, the neural network inside DNN can be divided into three categories: input layer, hidden layer, and output layer. Generally speaking, the first layer is the input layer, the last layer is the output layer, and the layers in between are all hidden layers. The layers are fully connected, that is, any neuron in the i-th layer must be connected to any neuron in the i+1-th layer. Although DNN looks complicated, the work of each layer is actually not complicated. Simply put, it is the following linear relationship expression: in, is the input vector, is the output vector, is the offset vector, W is the weight matrix (also called coefficient), and α() is the activation function. Each layer is just an input vector After such a simple operation, the output vector Since there are many DNN layers, the coefficient W and the offset vector The definition of these parameters in DNN is as follows: Take the coefficient W as an example: Assume that in a three-layer DNN, the linear coefficient from the 4th neuron in the second layer to the 2nd neuron in the third layer is defined as The superscript 3 represents the layer number of the coefficient W, while the subscript corresponds to the output of the third layer index 2 and the input of the second layer index 4. In summary, the coefficient from the kth neuron in the L-1th layer to the jth neuron in the Lth layer is defined as It's important to note that the input layer has no W parameter. In deep neural networks, more hidden layers allow the network to better capture complex real-world situations. Theoretically, a model with more parameters has higher complexity and greater "capacity," meaning it can handle more complex learning tasks. Training a deep neural network is essentially the process of learning the weight matrix, with the ultimate goal of obtaining the weight matrices for all layers of a trained deep neural network (a weight matrix formed by the vectors W across many layers).
[0177] (3) Backpropagation algorithm
[0178] Convolutional neural networks can use the back propagation (BP) algorithm to correct the size of the parameters in the initial super-resolution model during training, reducing the reconstruction error loss of the super-resolution model. Specifically, the forward propagation of the input signal to the output generates an error loss. This error loss information is then backpropagated to update the parameters of the initial super-resolution model, thereby converging the error loss. The BP algorithm is a backward propagation movement dominated by the error loss, aiming to obtain the optimal super-resolution model parameters, such as the weight matrix.
[0179] (4) Loss function
[0180] During the training of a deep neural network, because we want the output of the deep neural network to be as close as possible to the desired predicted value, we can compare the current network's predicted value with the desired target value and then update the weight vector of each layer of the neural network based on the difference between the two. (Of course, there is usually an initialization process before the first update, which is to pre-configure the parameters for each layer in the deep neural network.) For example, if the network's predicted value is too high, the weight vector is adjusted to make it predict a lower value. This adjustment is continued until the deep neural network can predict the desired target value or a value very close to the desired target value. Therefore, it is necessary to predefine "how to compare the difference between the predicted value and the target value." This is the loss function (or objective function), which is an important equation used to measure the difference between the predicted value and the target value. For example, the loss function output value (loss) indicates a greater difference, so training a deep neural network becomes a process of minimizing this loss as much as possible.
[0181] (5) Prompt: refers to the template or prompt information used to define downstream tasks, which can help the model better identify the tasks to be processed when input into the model.
[0182] (6) Embedding: Low-dimensional embedding representation of high-dimensional words or sentences, so that words and sentences corresponding to the embedding vectors of words and sentences with similar distances have similar meanings.
[0183] (7) Token: The element generated by word segmentation of text.
[0184] (8) Tokenizer: A tokenizer that is used to segment text into words based on a vocabulary and generate corresponding indicators.
[0185] (9) Foundation model: A foundation model usually refers to a large language model that has been pre-trained on a large scale using data from different fields.
[0186] (10) Pre-training: Pre-training is to use self-supervised methods to learn from a large amount of (text) input information without labeling. The models used are usually divided into autoregressive models and autoencoding models.
[0187] (11) Rule-based discriminator: A rule-based discriminator that infers rules from the input information and gives a score.
[0188] (12) Discriminator: A discriminator uses a discriminative model to perform classification or scoring. This is in contrast to a generator or generative model.
[0189] (13)EOS: The end symbol of a sentence or generated text. When the generation model outputs this symbol at a certain step, the generation process ends.
[0190] Generative language models often require control over the length, style, and format of generated sequences. For example, the word count, sentence count, paragraph count, and layout format of generated summaries or responses can be controlled. The effectiveness of this control largely determines the user experience and the efficient utilization of computing resources.
[0191] For example, existing large models tend to generate long answers. However, because generating long answers requires a lot of time and computing resources and is prone to introducing factual errors, they don't always meet user needs. In multi-turn conversations, the length of each reply determines the number of turns the model can handle. Effectively controlling the length of generated answers can help users reduce reading and waiting time, save computing power required for inference and generation, and enhance the model's multi-turn capabilities.
[0192] Prior art uses prompt-based control methods to control the length, style, or format of text generated by a model. Specifically, constraints on the length, style, or format of the generated text are added to prompt control instructions. These prompt control instructions are then processed by a large model, and supervised fine-tuning is performed based on the processing results and the corresponding annotations of the prompt control instructions. However, this approach lacks feedback information based on constraint errors, making it difficult to achieve high control accuracy.
[0193] In order to solve the above problems, the embodiment of the present application provides a controllable generation method. The controllable generation method of the embodiment of the present application is described in detail below with reference to the accompanying drawings.
[0194] First, the text generation method in the embodiment of the present application is introduced from the perspective of model training, with reference to Figure 5, which is a flow chart of a controllable generation method provided in the embodiment of the present application. As shown in Figure 5, the controllable generation method provided in the embodiment of the present application may include steps 501 to 504, and these steps are described in detail below.
[0195] 501. Obtain constraint information, where the constraint information is directly input by a user or extracted from a text generation request input by a user; the constraint information is at least one feature item of the generated text and a constraint on a key value of each feature item.
[0196] In a possible implementation, a text generation request (or prompt control instruction) input by a user may be obtained. For example, the text generation request may instruct to generate a text that meets specific requirements.
[0197] Taking summary generation as an example, text summarization often involves summarizing and condensing longer input text. Since no additional information is involved, whether the degree of simplification (that is, the length requirement for the generated text) meets the user's specific needs is an important metric for summarization. The following are some examples of inputs that control summary length based on prompts:
[0198] Summarize the following text in a 100-word summary (**original content**);
[0199] Generate a summary of no more than 100 words based on the "**original content**";
[0200] Generate a summary based on the "**original content**", with a length between 100 and 150 words.
[0201] For example, large models are often used for knowledge retrieval and knowledge-based question answering. Because different users have different knowledge backgrounds and require different levels of detail in their answers in specific situations, the length and format of answers must be tailored to the user's individual needs. Some input examples are as follows:
[0202] Introduce Liu Bei in about 100 words;
[0203] List the ten most skilled warriors in the Romance of the Three Kingdoms, using no less than 39 words to describe each.
[0204] Taking poetry generation as an example, poetry generation is one of the important demonstrable functions of the Chinese language model. It requires controlling elements such as acrostic, genre, rhyme, and imagery. Some input samples are as follows:
[0205] Use the four characters Pangu Zhizi to start each sentence, and write a seven-character quatrain with hidden acrostic poetry, rhyming with a;
[0206] Write a cryptic poem with the title "Wen Xin Yi Yan".
[0207] A text generation request may instruct the generation of a text that meets specific requirements.
[0208] The "specific requirements" may include at least one feature item and a constraint on the key value of each feature item. "At least one feature item and a constraint on the key value of each feature item" may be referred to as constraint information. In one possible implementation, the feature item is quantity, style, or format.
[0209] For example, the feature item is a quantitative feature of the generated text, such as the number of sentences, the number of entries, the total number of words, the number of paragraphs, etc. of the generated text.
[0210] For example, the feature item is a format feature of the generated text, such as genre, feature (such as acrostic poem), rhyme method, font, character shape, etc.
[0211] For example, the feature item is a style feature of the generated text, such as literary style, humorous style, etc.
[0212] In one possible implementation, the constraint of the key value of the feature item can be within a limited space, for example, the constraint of the feature item is a numerical range, and the constraint of the numerical range can include at least one of the following: greater than a first numerical value, less than a second numerical value, equal to a third numerical value, and between two numerical values.
[0213] In a possible implementation, the key value of the feature item may be constrained within a limited space. For example, the feature item may be constrained by a style feature. For example, the key value of the style feature may be: whether it is an acrostic poem, whether rhyme is required, etc.
[0214] In one possible implementation, the constraint information may only include feature items and key-value constraints corresponding to the feature items. Compared with the text generation request, the constraint information eliminates the semantic requirements of the corresponding generated text, and retains the requirements within a limited space such as quantity, style and format (that is, the requirements are selected within a limited range). Therefore, the constraint information can also be called standardized format control instructions.
[0215] Standardization can be understood as information in a fixed format. For example, the constraint information includes feature items and their corresponding key-value constraints, and the positional relationship between the various pieces of information (e.g., feature items and their corresponding key-value constraints) in the constraint information is fixed.
[0216] Through standardization, the reward value can be directly calculated through rules in the future, and the standardized constraint information can also enable the model to better learn the effective information after being input into the model.
[0217] In one possible implementation, the text generation instructions can be processed by a neural network to extract constraint information.
[0218] For example, the neural network can be a prompt extractor module. As a standardized control instruction extractor, the prompt extractor module can extract standardized format control instructions from the user input text, thereby realizing rule-based discriminant model inference or reducing the training difficulty of the trainable discriminant model. Figure 6 is a schematic diagram of the function of this module, with the original input text on the left and the extracted standardized control instructions on the right. The model can use a small generative model such as GPT-2, BART structure, etc. to directly generate standardized control instructions. Discriminant models such as BERT and XLNet can also be used to learn and reason about the selection of standardized control instructions (including instruction type, maximum and minimum values, etc.) under a finite set as a classification problem.
[0219] The training of this model can use data augmentation technology. For example, the following method can be used to obtain relevant labeled data:
[0220] By manually traversing possible standardized control instructions, several non-standard instruction texts are manually given for each standardized control instruction. For each standardized control instruction and the corresponding non-standardized instruction text, they are randomly combined with other content information to form a large number of complete input samples. Synonymous text data enhancement methods such as back-translation or rewriting models are used to enhance the data of each complete input sample. For each sample after data enhancement, the standardized instruction or the category of standardized instruction corresponding to the control instruction part in its original text is the extracted standardized instruction label. The standardized instruction extraction model is trained based on a large number of complete input samples and their standardized instruction labels. In addition to using the standardized control instruction extraction module, standardized control instructions can also be obtained through methods such as constraining user input through the interactive interface.
[0221] In one possible implementation, the constraint information may also be directly input by the user, for example, specifically through an input box or input control on an interface, wherein the interface may include multiple feature items and an input box or input control corresponding to each feature item.
[0222] For example, users can specify the quantitative characteristics, format, style, etc. of the content generated by the large model during the conversation by selecting and filling in parameters. Type options include but are not limited to the total number of words, total number of sentences, number of paragraphs, number of entries, number of entities, etc., and relationship options include but are not limited to greater than, less than, equal to, between, etc. The value input can be, but is not limited to, one or more numbers. For example, if you do not want to generate content that is too long, you can select "Total Number of Words" under "Type", select "Less than" under "Relationship", and select the maximum length you want to generate under "Value". When "Between" is selected as the relationship, two fill-in options, maximum value and minimum value, appear.
[0223] Based on the user's input on the interface, constraint information can be obtained, which improves the user experience and meets the user's personalized needs, avoids repeating the input of control instructions in each sentence, and saves computing power loss and waiting time during inference.
[0224] 502. Obtain target generated text through a pre-trained model according to the text generation request;
[0225] In a possible implementation, similarly, the implementation in the prior art can be referred to, and the text generation request can be input into the pre-trained model. The pre-trained model can process the text generation request to obtain the target generated text.
[0226] 503. Obtain a reward value corresponding to the target-generated text based on the constraint information and the target-generated text, wherein the reward value is related to the degree to which the target-generated text satisfies the constraint information.
[0227] In a possible implementation, text may be generated according to the constraint information and the target, and a reward value corresponding to the target-generated text may be obtained through a neural network.
[0228] In one possible implementation, the above-mentioned neural network can also be called a discriminant model, which is mainly used to score the degree to which the text generated by the large model (such as the target generated text in the embodiment of the present application) satisfies the constraint information. The score can be used as reward information to train the pre-trained model (for example, it can be used for the training of the reinforcement learning fine-tuning part).
[0229] Next, we introduce the discriminant model in the embodiment of this application:
[0230] In one possible implementation, the trainable discriminant model needs to be trained so that when the model inputs a standardized prompt (that is, the constraint information introduced above) and a large model-generated text sequence (that is, the text generation instruction introduced above), it can output the degree to which the generated text satisfies the constraint information, that is, the score or reward.
[0231] A schematic diagram of its training process can be shown in Figure 7. The specific process is as follows: randomly sample standardized control instructions, randomly construct or sample simulated content sequences, randomly match standardized control instructions with simulated content sequences, construct input data, and construct loss or reward indicators through rule methods and certain loss or reward calculation methods. The input data passes through the discriminant model to obtain the output score, and the output score is compared with the label generated based on the rule method to calculate the gap between the two. MSE Loss can usually be used to minimize the above loss steps to train the discriminant model.
[0232] To optimize the ability of large-scale generative models to manage constraints on the quantity, format, and style of generated text, it is necessary to obtain a reward value for each input example generated after the model passes through it. If a trainable discriminant model is used, the score predictions provided by the trained discriminant model can be directly used as the reward value.
[0233] In a possible implementation, a text may be generated according to the constraint information and the target, and a reward value corresponding to the target generated text may be obtained through a functional function.
[0234] Among them, the method of determining reward values based on performance functions can also be called a rule-based method. This method can determine whether the constraints are met and the associated deviations. Taking text length as an example, the output of a large model generates a sequence of token indicators corresponding to the output text, starting from the indicator at the end of the input length. This sequence ends with the tokenizer terminator. The number of tokens before the terminator can be measured using PyTorch's built-in .shape() function. If the instruction requires the actual number of characters or words, the tokenizer.decode() function can be used to decode the token indicator sequence before the terminator to obtain the output text or words in raw character form. The text length can then be calculated using techniques such as string length. The computation time of the tokenizer.decode() and length measurement functions is essentially negligible compared to the inference time of the large model. Using a rule-based discriminative model can significantly improve the efficiency of fine-tuning and inference.
[0235] In rule-based approaches, reward values are also calculated using rule formulas. For example, a performance function can determine the actual value of the target generated text on a given feature. For example, if the feature is text length, the performance function can determine the actual length of the target generated text. Based on the actual text length and the key constraint of the text length, a reward value can be calculated using a rule formula. The rule formula quantifies the degree to which the actual value satisfies the key constraint.
[0236] Optionally, the rule formula can refer to the calculation method of the loss function, and the inverse of the loss function can be used as the reward function.
[0237] Exemplarily, length constraints can include five types, including greater than a certain length, less than a certain length, equal to a certain length, strictly equal to a certain length, and between two lengths. The relevant loss functions that can be used in the embodiments of the present application can be defined as shown in Table 1 below. Table 1 shows a schematic diagram of constraint information and loss function, where the opposite of the loss function can be used as a reward function.
[0238] Table 1
[0239] 504. Update the pre-trained model according to the reward value.
[0240] In a possible implementation, the pre-trained model can be updated through reinforcement learning according to the reward value.
[0241] Optionally, reinforcement learning may include but is not limited to the Acter-Critic based PPO method, which is the method adopted by RLHF in InstructGPT. The basic calculation process can be shown as follows:
[0242] a. Assume that a large language model with fine-tuned or fine-tunable parameters θ exists and is used as the actor model. Also, initialize a separately trained critic model with the same parameters. Assume that a pre-trained standardized instruction extraction module and discriminant model exist.
[0243] b. User inputs raw text with control information;
[0244] c. The original text is passed through the standardized instruction extraction module to obtain standardized control instructions;
[0245] d. The original text is input into the large language model LLM to obtain the output sequence;
[0246] e. Combine the standardized control instructions and output sequence and input them into the discriminant model to obtain the reward score;
[0247] f. Repeat steps be to accumulate a certain number of samples and store them in memory;
[0248] g. According to the reward score R given by the discriminant model in e, and the output V of the critic model θ (s t ) to make the difference and calculate the estimated value of the advantage function
[0249] h. Through the probability proportion formula and the estimated value of the advantage function Get the policy function optimization target or policy loss:
[0250] i. According to the critic output value V θ (s t ) and the true reward value reward given by the discriminant model to calculate the value loss corresponding to the critic model:
[0251] j. Optimization by gradient methods and
[0252] k. Repeat steps gj multiple times;
[0253] l. Clear the memory sample, return to step b and continue;
[0254] m. Stop training and store the model node when the actual control reward value no longer increases or when the original evaluation indicators such as ROUGE show a significant decrease.
[0255] Refer to FIG8 , which is a schematic diagram of reinforcement learning fine-tuning based on constraint information.
[0256] In addition, the embodiments of the present application may also adopt non-reinforcement learning methods, such as connecting a trainable discriminant model to a generative model and performing end-to-end training based on maximizing the output score (minimizing the loss).
[0257] The embodiment of the present application provides a method for controllable generation, the method comprising: obtaining constraint information, the constraint information being directly input by the user or extracted from a text generation request input by the user; the constraint information being at least one feature item of the generated text and a constraint on the key value of each feature item; obtaining a target generated text through a pre-trained model according to the text generation request; obtaining a reward value corresponding to the target generated text according to the constraint information and the target generated text, the reward value being related to the degree of satisfaction of the target generated text with the constraint information; and updating the pre-trained model according to the reward value. In the above manner, the constraint information is directly obtained or extracted from the user's input, and the reward value for updating the model is determined by the degree of satisfaction between the constraint information and the generated text output by the large model. Compared with determining the reward value by only using the generated text and annotations, the reward value in the present application can better express the degree of satisfaction of the generated text with the constraint information, so that the trained model can achieve higher control accuracy.
[0258] In addition, from the perspective of model reasoning, the embodiment of the present application further provides a controllable generation method. Referring to FIG. 9 , FIG. 9 is a flow chart of a controllable generation method provided by the embodiment of the present application. As shown in FIG. 9 , the method includes:
[0259] 901. Obtain constraint information, where the constraint information is directly input by a user or extracted from a text generation request input by a user; the constraint information is at least one feature item of the generated text and a constraint on a key value of each feature item.
[0260] In a possible implementation, the feature item is quantity, style or format.
[0261] For more information about step 901, please refer to the introduction of step 501 in the above embodiment, and the similarities will not be repeated here.
[0262] In a possible implementation, the constraint of the key value is a constraint on the value range of the key value, and the constraint of the value range includes at least one of the following: greater than a first value, less than a second value, equal to a third value, and between two values.
[0263] In a possible implementation, the key value constraint is specifically input by the user through an input box or input control of an interface, and the interface includes multiple feature items and an input box or input control corresponding to each feature item.
[0264] As shown in Figure 10, Figure 10 is a schematic diagram of an interface (the constraint information in Figure 10 is described as a standardized control instruction). Taking the constraint information as length constraint and format constraint as an example, the user can specify the length and format of the content generated by the large model during the conversation by selecting and filling in the system parameters, without having to add prompt information of the desired length and format in each sentence. Type options include but are not limited to the total number of words, the total number of sentences, the number of paragraphs, the number of entries, the number of entities, etc., and relationship options include but are not limited to greater than, less than, equal to, between, etc. The value input can be but is not limited to one or more numbers. For example, if you do not want to generate too long content, you can select "Total Number of Words" under "Type", select "Less than" under "Relationship", and select the maximum length you want to generate under "Value". When the relationship is selected as "Between", two fill-in options for maximum value and minimum value appear.
[0265] Since standardized control instructions are accessible to the system after the user selects and fills in the relevant fields, these instructions can be combined with the user input and then fed into a large model fine-tuned through reinforcement learning. The large model then generates candidate examples. Finally, a rule-based discriminant model assigns scores and rankings based on the standardized control instructions and the model-generated text, ultimately selecting the appropriate generated examples and returning them to the user.
[0266] The genre, rhyme, and acrostic information of the poem can all be judged and scored through a rule-based method, and can be improved using an instruction extraction module, a rule-based discrimination module, and reinforcement learning. As shown in Figure 11A, Figure 11A is a schematic diagram of an interface. When the user inputs the four characters "Pangu Zhizi" as the beginning of each sentence, a seven-character quatrain acrostic poem is written, and the rhyme is a. The standardized instruction extraction module extracts the content of the standardized control instructions about the poem: the genre is a seven-character quatrain, the feature is acrostic poem (hidden head Pangu Zhizi), and the rhyme is a. At the same time, the large model generates the poem in the figure, and the discrimination model gives the satisfaction score of the control instruction based on the standardized control instruction and the generated poem. According to the score and sorting, the appropriate generated sample is finally selected and returned to the user.
[0267] 902. Obtain multiple candidate generated texts using a pre-trained model according to the text generation request;
[0268] The pre-trained model can obtain multiple candidate generated texts, and each candidate generated text can be an output for a text generation request.
[0269] 903. Obtain a score for each candidate generated text based on the constraint information and the multiple candidate generated texts, where the score is related to the degree to which the corresponding candidate generated text satisfies the constraint information.
[0270] In a possible implementation, a score for each candidate generated text may be obtained through a neural network based on the constraint information and the multiple candidate generated texts.
[0271] In one possible implementation, the actual value of each feature item of each candidate generated text can be obtained based on the constraint information and the multiple candidate generated texts through a functional function, and a score can be determined based on the relationship between the actual value and the corresponding key value constraint.
[0272] For more information about step 903, please refer to the introduction of step 503 in the above embodiment, and the similarities will not be repeated here.
[0273] 904. Determine a target text from the multiple candidate generated texts based on the scoring.
[0274] For more information about step 904, please refer to the introduction of step 504 in the above embodiment, and the similarities will not be repeated here.
[0275] By directly obtaining or extracting constraint information from the user's input in the above manner, and determining the score for determining the output text by the degree of satisfaction between the constraint information and the generated text output by the large model, higher control accuracy can be achieved.
[0276] After model training, during the reasoning process, the large model itself can have a controllable generation capability with strong quantity constraints, format constraints, and style constraints after inputting a text with control instructions (that is, constraint information). In order to ensure the accuracy of the control, a standardized instruction extraction module and a discrimination module (that is, a module for determining the score) can still be used on the basis of the large language model to select and sort the multiple candidate generated texts. In addition, a memory module is introduced to store all samples that have been generated during the decoding generation process. Referring to Figure 11B, Figure 11B is a schematic diagram of the reasoning process of a model, and the specific reasoning process is as follows:
[0277] The user inputs raw text containing control instructions. Standardized control instructions are extracted from the raw text using a prompt extractor. The raw text is then passed through a large generative language model to generate an output sequence. Using EOS as the terminating token, all completed output samples within a maximum length (a value greater than the target length) are stored in a memory bank. Because the model has been fine-tuned for control enhancement, the majority of samples are distributed around the length specified by the standardized control instructions. Using the standardized control instructions, each output sequence is combined with a discriminant module to assign a score to each completed output sequence. The output sequence with the highest score is then sorted and selected as the output to the user.
[0278] In addition, the controllable generation method (training phase) proposed in the embodiment of this application can be used in addition to the existing model. Considering the fixed nature of the large model structure, it is usually possible to first use the prompt fine-tuning method that adds length, format, or style control in the fine-tuning phase to learn the basic length, format, or style control capabilities. Then, after the supervised fine-tuning is completed, the controllable generation method (training phase) proposed in the embodiment of this application is adopted.
[0279] Next, we will introduce the beneficial effects of this application in conjunction with experiments. For example, we can use GPT-2-medium to train a baseline model based on the traditional prompt with controllable length on the CNNDM summary dataset, use the inverse of the loss function in Table 1 as the reward, and use the PPO-based reinforcement learning method to further fine-tune the GPT-2-medium that has been fine-tuned for the summary task. The change in its average verification reward with the number of training steps is shown in Figure 11C. It can be seen that the original controllable length summary model based on the existing method has a control reward of -0.10, and after further reinforcement learning fine-tuning of this solution, its control reward rises to -0.02. Since the deviation is calculated using a linear term, the accuracy of the length control is equivalent to a five-fold increase, which verifies the effect of the embodiment of this application.
[0280] Referring to FIG. 12 , FIG. 12 is a schematic diagram of the structure of a controllable generation device provided in an embodiment of the present application. As shown in FIG. 12 , a controllable generation device 1200 provided in an embodiment of the present application includes:
[0281] Acquisition module 1201 is used to acquire constraint information, where the constraint information is directly input by the user or extracted from a text generation request input by the user; the constraint information is at least one feature item of the generated text and a constraint on a key value of each feature item;
[0282] The specific description of the acquisition module 1201 can refer to the description of step 501 in the above embodiment, which will not be repeated here.
[0283] The processing module 1202 is configured to obtain a target generated text through a pre-trained model according to the text generation request;
[0284] Obtaining a reward value corresponding to the target-generated text according to the constraint information and the target-generated text, wherein the reward value is related to the degree to which the target-generated text satisfies the constraint information;
[0285] The pre-trained model is updated according to the reward value.
[0286] The specific description of the processing module 1202 can refer to the description of steps 502 to 504 in the above embodiment, which will not be repeated here.
[0287] In a possible implementation, the processing module is specifically configured to:
[0288] The pre-trained model is updated through reinforcement learning according to the reward value.
[0289] In a possible implementation, the constraint information is information in a fixed format.
[0290] In a possible implementation, the constraint of the key value is a constraint on the value range of the key value, and the constraint of the value range includes at least one of the following: greater than a first value, less than a second value, equal to a third value, and between two values.
[0291] In a possible implementation, the processing module is specifically configured to:
[0292] According to the constraint information and the target generated text, a reward value corresponding to the target generated text is obtained through a neural network; or
[0293] According to the constraint information and the target generation text, a reward value corresponding to the target generation text is obtained through a functional function.
[0294] In a possible implementation, the feature item is quantity, style or format.
[0295] In a possible implementation, the processing module is further configured to:
[0296] Construct a loss based on the target generated text and the corresponding ground truth;
[0297] The processing module is specifically used to:
[0298] The pre-trained model is updated according to the reward value and the loss.
[0299] In addition, an embodiment of the present application further provides a controllable generation device, including:
[0300] An acquisition module is configured to acquire constraint information, wherein the constraint information is directly input by a user or extracted from a text generation request input by a user; the constraint information is at least one feature item of the generated text and a constraint on a key value of each feature item;
[0301] A processing module, configured to generate a plurality of candidate generated texts based on the text generation request through a pre-trained model;
[0302] Obtaining a score for each candidate generated text based on the constraint information and the plurality of candidate generated texts, wherein the score is related to the degree to which the corresponding candidate generated text satisfies the constraint information;
[0303] According to the scoring, a target text is determined from the multiple candidate generated texts.
[0304] In a possible implementation, the constraint information is information in a fixed format.
[0305] In a possible implementation, the key value constraint is specifically input by the user through an input box or input control of an interface, and the interface includes multiple feature items and an input box or input control corresponding to each feature item.
[0306] In a possible implementation, the constraint of the key value is a constraint on the value range of the key value, and the constraint of the value range includes at least one of the following: greater than a first value, less than a second value, equal to a third value, and between two values.
[0307] In a possible implementation, the processing module is specifically configured to:
[0308] According to the constraint information and the plurality of candidate generated texts, a score for each candidate generated text is obtained through a neural network; or,
[0309] According to the constraint information and the multiple candidate generated texts, the actual value of each candidate generated text in each feature item is obtained through a functional function, and a score is determined according to the relationship between the actual value and the constraint of the corresponding key value.
[0310] In a possible implementation, the feature item is quantity, style or format.
[0311] Next, an execution device provided in an embodiment of the present application is introduced. Please refer to Figure 13. Figure 13 is a structural diagram of an execution device provided in an embodiment of the present application. The execution device 1300 can be specifically manifested as a virtual reality VR device, a mobile phone, a tablet, a laptop computer, a smart wearable device, a monitoring data processing device or a server, etc., which is not limited here. Specifically, the execution device 1300 includes: a receiver 1301, a transmitter 1302, a processor 1303 and a memory 1304 (wherein the number of processors 1303 in the execution device 1300 can be one or more, and Figure 13 takes one processor as an example), wherein the processor 1303 may include an application processor 13031 and a communication processor 13032. In some embodiments of the present application, the receiver 1301, the transmitter 1302, the processor 1303 and the memory 1304 may be connected via a bus or other means.
[0312] Memory 1304 may include read-only memory and random access memory, and provides instructions and data to processor 1303. A portion of memory 1304 may also include non-volatile random access memory (NVRAM). Memory 1304 stores processor and operation instructions, executable modules, or data structures, or subsets or extended sets thereof. The operation instructions may include various operation instructions for implementing various operations.
[0313] Processor 1303 controls the operation of the execution device. In specific applications, the various components of the execution device are coupled together via a bus system. In addition to a data bus, the bus system may also include a power bus, a control bus, and a status signal bus. However, for clarity, all bus systems are referred to as a bus system in the figure.
[0314] The methods disclosed in the above embodiments of the present application can be applied to or implemented by processor 1303. Processor 1303 can be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by hardware integrated logic circuits or software instructions in processor 1303. The above processor 1303 can be a general-purpose processor, a digital signal processor (DSP), a microprocessor, or a microcontroller, and can further include an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The processor 1303 can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in conjunction with the embodiments of the present application can be directly implemented as being executed by a hardware decoding processor, or can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium well-known in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. This storage medium is located in memory 1304. Processor 1303 reads information from memory 1304 and, in conjunction with its hardware, completes the steps involved in the model inference process in the above method.
[0315] Receiver 1301 can be used to receive input digital or character information and generate signal input related to executing device-related settings and function control. Transmitter 1302 can be used to output digital or character information through the first interface. Transmitter 1302 can also be used to send instructions to the disk pack through the first interface to modify data in the disk pack. Transmitter 1302 can also include a display device such as a display screen.
[0316] The present application also provides a training device. Please refer to FIG. 14 , which is a schematic diagram of a structure of a training device provided by an embodiment of the present application. Specifically, the training device 1400 is implemented by one or more servers. The training device 1400 may vary significantly due to different configurations or performance. It may include one or more central processing units (CPUs) 1414 (e.g., one or more processors), a memory 1432, and one or more storage media 1430 (e.g., one or more mass storage devices) storing application programs 1442 or data 1444. The memory 1432 and storage medium 1430 may be either ephemeral or persistent storage. The program stored in the storage medium 1430 may include one or more modules (not shown), each of which may include a series of instruction operations on the training device. Furthermore, the CPU 1414 may be configured to communicate with the storage medium 1430 to execute the series of instruction operations in the storage medium 1430 on the training device 1400.
[0317] The training device 1400 may also include one or more power supplies 1426, one or more wired or wireless network interfaces 1450, one or more input and output interfaces 1458; or, one or more operating systems 1441, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, etc.
[0318] In the embodiment of the present application, the central processing unit 1414 is used to execute actions related to model training in the above embodiments.
[0319] An embodiment of the present application also provides a computer program product, which, when running on a computer, enables the computer to execute the steps executed by the aforementioned execution device, or enables the computer to execute the steps executed by the aforementioned training device.
[0320] A computer-readable storage medium is also provided in an embodiment of the present application, which stores a program for signal processing. When the computer-readable storage medium is run on a computer, it enables the computer to execute the steps executed by the aforementioned execution device, or enables the computer to execute the steps executed by the aforementioned training device.
[0321] The execution device, training device or terminal device provided in the embodiments of the present application can specifically be a chip, and the chip includes: a processing unit and a communication unit, the processing unit can be, for example, a processor, and the communication unit can be, for example, an input / output interface, a pin or a circuit, etc. The processing unit can execute the computer execution instructions stored in the storage unit, so that the chip in the execution device executes the controllable generation method described in the above embodiment, or so that the chip in the training device executes the controllable generation method described in the above embodiment. Optionally, the storage unit is a storage unit in the chip, such as a register, a cache, etc. The storage unit can also be a storage unit located outside the chip in the wireless access device, such as a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM), etc.
[0322] Specifically, see Figure 15 , which is a schematic diagram of the structure of a chip provided in an embodiment of the present application. The chip can be represented as a neural network processor NPU 1500. NPU 1500 is mounted on the host CPU (host CPU) as a coprocessor and is assigned tasks by the host CPU. The core of the NPU is arithmetic circuit 1503, which is controlled by controller 1504 to extract matrix data from memory and perform multiplication operations.
[0323] In some implementations, arithmetic circuit 1503 includes multiple processing units (PEs). In some implementations, arithmetic circuit 1503 is a two-dimensional systolic array. Arithmetic circuit 1503 can also be a one-dimensional systolic array or other electronic circuitry capable of performing mathematical operations such as multiplication and addition. In some implementations, arithmetic circuit 1503 is a general-purpose matrix processor.
[0324] For example, assume there are input matrix A, weight matrix B, and output matrix C. The arithmetic circuit retrieves the corresponding data of matrix B from weight memory 1502 and caches it on each PE in the arithmetic circuit. The arithmetic circuit retrieves the data of matrix A from input memory 1501 and performs a matrix operation on matrix B. The partial or final matrix result is stored in accumulator 1508.
[0325] Unified memory 1506 is used to store input and output data. Weight data is directly transferred to weight memory 1502 through the Direct Memory Access Controller (DMAC) 1505. Input data is also transferred to unified memory 1506 through the DMAC.
[0326] BIU stands for Bus Interface Unit 1510 , which is used for interaction between the AXI bus, DMAC, and instruction fetch buffer (IFB) 1509 .
[0327] The bus interface unit 1510 (BIU) is used for the instruction fetch memory 1509 to obtain instructions from the external memory, and is also used for the storage unit access controller 1505 to obtain the original data of the input matrix A or the weight matrix B from the external memory.
[0328] DMAC is mainly used to transfer input data in the external memory DDR to the unified memory 1506 or transfer weight data to the weight memory 1502 or transfer input data to the input memory 1501.
[0329] The vector calculation unit 1507 includes multiple operation processing units. When necessary, it further processes the output of the operation circuit 1503, such as vector multiplication, vector addition, exponential operation, logarithmic operation, size comparison, etc. It is mainly used for non-convolutional / fully connected layer network calculations in neural networks, such as batch normalization, pixel-level summation, and upsampling of feature planes.
[0330] In some implementations, the vector calculation unit 1507 can store the processed output vector in the unified memory 1506. For example, the vector calculation unit 1507 can apply a linear function or a nonlinear function to the output of the operation circuit 1503, such as linear interpolation of the feature plane extracted by the convolution layer, or accumulate a vector of values to generate an activation value. In some implementations, the vector calculation unit 1507 generates a normalized value, a pixel-level summed value, or both. In some implementations, the processed output vector can be used as an activation input to the operation circuit 1503, for example, for use in subsequent layers in a neural network.
[0331] An instruction fetch buffer 1509 connected to the controller 1504 is used to store instructions used by the controller 1504;
[0332] Unified memory 1506, input memory 1501, weight memory 1502, and instruction fetch memory 1509 are all on-chip memories. External memories are private to the NPU hardware architecture.
[0333] The processor mentioned in any of the above places can be a general-purpose central processing unit, a microprocessor, an ASIC, or one or more integrated circuits for controlling the execution of the above program.
[0334] It should also be noted that the device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed across multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment. In addition, in the drawings of the device embodiments provided in this application, the connection relationship between the modules indicates that there is a communication connection between them, which can be specifically implemented as one or more communication buses or signal lines.
[0335] Through the description of the above embodiments, those skilled in the art can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course can also be implemented by special hardware including application-specific integrated circuits, special CPUs, special memories, special components, etc. In general, all functions performed by computer programs can be easily implemented with corresponding hardware, and the specific hardware structures used to implement the same function can also be diverse, such as analog circuits, digital circuits or special circuits, etc. However, for the present application, software program implementation is a better implementation method in most cases. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer's floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk or optical disk, etc., and includes a number of instructions to enable a computer device (which can be a personal computer, training equipment, or network equipment, etc.) to execute the methods described in each embodiment of the present application.
[0336] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware, or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.
[0337] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website, a computer, a training device or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website, a computer, a training device or a data center. The computer-readable storage medium can be any available medium that a computer can store or a data storage device such as a training device, a data center, etc. that includes one or more available media integrations. The available medium can be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)).
Claims
1. A controllable generation method, characterized in that: The method comprises: Obtaining constraint information, where the constraint information is directly input by a user or extracted from a text generation request input by a user; the constraint information is at least one feature item of the generated text and a constraint on a key value of each feature item; According to the text generation request, a plurality of candidate generated texts are obtained through a pre-trained model; Obtaining a score for each of the candidate generated texts according to the constraint information and the plurality of candidate generated texts, wherein the score is related to the degree to which the corresponding candidate generated text satisfies the constraint information; According to the scoring, a target text is determined from the multiple candidate generated texts.
2. The method according to claim 1, characterized in that The key value constraint is specifically input by a user through an input box or an input control of an interface, and the interface includes a plurality of feature items and an input box or an input control corresponding to each of the feature items.
3. The method according to claim 1 or 2, characterized in that: The constraint of the key value is a constraint of a numerical range of the key value, and the constraint of the numerical range includes at least one of the following: greater than a first numerical value, less than a second numerical value, equal to a third numerical value, and between two numerical values.
4. The method according to any one of claims 1 to 3, characterized in that: The step of obtaining a score for each candidate generated text according to the constraint information and the plurality of candidate generated texts includes: According to the constraint information and the plurality of candidate generated texts, a score for each candidate generated text is obtained through a neural network; or, According to the constraint information and the multiple candidate generated texts, the actual value of each candidate generated text in each feature item is obtained through a functional function, and the score is determined according to the relationship between the actual value and the constraint of the corresponding key value.
5. The method according to any one of claims 1 to 4, characterized in that: The feature item is quantity, style or format.
6. The method according to any one of claims 1 to 4, characterized in that: The constraint information is information in a fixed format.
7. A controllable generation method, characterized in that: The method comprises: Obtaining constraint information, where the constraint information is directly input by a user or extracted from a text generation request input by a user; the constraint information is at least one feature item of the generated text and a constraint on a key value of each feature item; According to the text generation request, a target generated text is obtained through a pre-trained model; According to the constraint information and the target generated text, a reward value corresponding to the target generated text is obtained, wherein the reward value is related to the degree to which the target generated text satisfies the constraint information; The pre-trained model is updated according to the reward value.
8. The method according to claim 7, characterized in that The updating of the pre-trained model according to the reward value includes: The pre-trained model is updated through reinforcement learning according to the reward value.
9. The method according to claim 7 or 8, characterized in that: The constraint of the key value is a constraint of a numerical range of the key value, and the constraint of the numerical range includes at least one of the following: greater than a first numerical value, less than a second numerical value, equal to a third numerical value, and between two numerical values.
10. The method according to any one of claims 7 to 9, characterized in that: The step of obtaining a reward value corresponding to the target generation text according to the constraint information and the target generation text includes: According to the constraint information and the target generated text, a reward value corresponding to the target generated text is obtained through a neural network; or , According to the constraint information and the target generation text, a reward value corresponding to the target generation text is obtained through a functional function.
11. The method according to any one of claims 7 to 10, characterized in that: The feature item is quantity, style or format.
12. The method according to any one of claims 7 to 11, characterized in that: The key value constraint is specifically input by a user through an input box or an input control of an interface, and the interface includes a plurality of feature items and an input box or an input control corresponding to each of the feature items.
13. The method according to any one of claims 7 to 12, characterized in that: The constraint information is information in a fixed format.
14. A controllable generation device, characterized in that: The device comprises: An acquisition module, used to acquire constraint information, wherein the constraint information is directly input by a user or extracted from a text generation request input by a user; the constraint information is at least one feature item of the generated text and a constraint on a key value of each feature item; A processing module, configured to obtain a plurality of candidate generated texts according to the text generation request through a pre-trained model; Obtaining a score for each of the candidate generated texts according to the constraint information and the plurality of candidate generated texts, wherein the score is related to the degree to which the corresponding candidate generated text satisfies the constraint information; According to the scoring, a target text is determined from the multiple candidate generated texts.
15. The device according to claim 14, characterized in that The key value constraint is specifically input by a user through an input box or an input control of an interface, and the interface includes a plurality of feature items and an input box or an input control corresponding to each of the feature items.
16. The device according to claim 14 or 15, characterized in that The constraint of the key value is a constraint of a numerical range of the key value, and the constraint of the numerical range includes at least one of the following: greater than a first numerical value, less than a second numerical value, equal to a third numerical value, and between two numerical values.
17. The device according to any one of claims 14 to 16, characterized in that The feature item is quantity, style or format.
18. The device according to any one of claims 14 to 17, characterized in that The constraint information is information in a fixed format.
19. A controllable generation device, characterized in that: The device comprises: An acquisition module, used to acquire constraint information, wherein the constraint information is directly input by a user or extracted from a text generation request input by a user; the constraint information is at least one feature item of the generated text and a constraint on a key value of each feature item; A processing module, used to generate a target generated text according to the text generation request through a pre-trained model; According to the constraint information and the target generated text, a reward value corresponding to the target generated text is obtained, wherein the reward value is related to the degree to which the target generated text satisfies the constraint information; The pre-trained model is updated according to the reward value.
20. The device according to claim 19, characterized in that The processing module is specifically used for: The pre-trained model is updated through reinforcement learning according to the reward value.
21. A computer storage medium, characterized in that The computer storage medium stores one or more instructions which, when executed by one or more computers, cause the one or more computers to perform the operations of the method of any one of claims 1 to 13.
22. A computer program product, characterized in that The method comprises computer-readable instructions, and when the computer-readable instructions are executed on a computer device, the computer device is caused to execute the method according to any one of claims 1 to 13.
23. A system comprising at least one processor and at least one memory; the processor and the memory are connected via a communication bus and communicate with each other; The at least one memory is used to store code; The at least one processor is configured to execute the code to perform the method according to any one of claims 1 to 13.
Citation Information
Patent Citations
Text processing method and device
CN114138947A
Text generation method, model training method, equipment and storage medium
CN114330251A
Method and device for determining prompt vector of pre-training model and electronic equipment
CN114792097A
Model training method and related equipment
CN115630297A
Controllable generation method and device
CN117077653A
