A multi-attribute controllable text generation method based on combined sampling and joint optimization
By introducing 'pseudo-combination' data into multi-attribute controllable text generation and conducting joint training, the generalization ability of the generative language model is improved, the shortcomings of existing methods in combination generalization are solved, and stronger Text generation control capabilities.
Patent Information
- Application Number
- CN202410885707.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-03
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2044-07-03
AI Technical Summary
Existing multi-attribute controllable text generation methods perform poorly in terms of combinatorial generalization. It is difficult to generate text with attribute combinations not seen during the training phase. Especially when it is difficult to collect data sets in real scenarios, effective combinatorial generalization is lacking. ability.
A method based on combined sampling and joint optimization is adopted to introduce 'pseudo-combination' data in the training phase, and through joint training, the parameter update direction of the generative language model considers data other than the training data distribution, thereby improving the model's generalization to new attribute combinations. ization ability. Specific steps include initializing the generative language model, setting the objective function, randomly sampling training data, calculating losses and optimizing model parameters, and introducing pseudo-combination data for further optimization until the set number of training steps is reached.
Through this method, the generative language model not only fits the training data, but also considers data outside the data distribution, thereby improving the generalization ability under the control conditions of new attribute combinations and improving the combinatorial generalization of multi-attribute controllable text generation. ization ability.
Smart Images

Figure CN118428359B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of natural language generation, and in particular to a multi-attribute controllable text generation method based on combined sampling and joint optimization. Background Art
[0002] Multi-attribute controllable text generation aims to generate fluent text with a specified combination of multiple attributes. Compared with single-attribute controllable text generation, multi-attribute controllable text generation is more challenging and has gradually attracted research interest in academia in recent years.
[0003] For example, for the text data “I think this movie is good”, the attribute of its subject dimension is “movie”, and the attribute of its emotion dimension is “positive”.
[0004] The mainstream methods for generating multi-attribute controllable texts include: 1) decoding methods, which use a fine-tuned classifier to adjust the distribution of each output of the language model so that the generated text has the specified attributes; 2) generation methods based on individual optimization, which use single-attribute data to train a separate module for each attribute, and combine these trained modules in the generation phase to achieve the effect of multi-attribute control generation; 3) generation methods based on joint optimization, which set corresponding modules for each attribute at the same time, and use multi-attribute data sets to jointly optimize and train these modules at the same time to achieve the effect of multi-attribute controllable text generation. At present, the above three methods have achieved good results on this task.
[0005] However, there is currently little work focusing on combinatorial generalization, which is an important indicator for measuring a multi-attribute controllable text generation method. Combinatorial generalization refers to the ability of a model to generate text with other attribute combinations that have not been seen in the training phase after being trained on a dataset with some attribute combinations. For example, the present invention expects that the model can effectively generate text with the attribute combinations of (negative, male) and (positive, female) after being trained on a dataset with the attribute combinations of (positive, male) and (negative, female). Since it is difficult to collect datasets with all attribute combinations in real scenarios, the ability of combinatorial generalization is crucial for multi-attribute controllable text generation methods. Summary of the invention
[0006] In order to solve the above technical problems, the present invention provides a multi-attribute controllable text generation method based on combined sampling and joint optimization.
[0007] In order to solve the above technical problems, the present invention adopts the following technical solutions:
[0008] A multi-attribute controllable text generation method based on combined sampling and joint optimization, which takes the combination of multiple given attributes as control conditions and inputs them into different multi-attribute controllable text generation methods based on joint training. In the trained generative language model, text that satisfies all given attributes is generated; different multi-attribute controllable text generation methods based on joint training Generative language model The training process includes the following steps:
[0009] Step 1: Set the training step t=1 and generate the language model Initialize as a generative language model , and set the objective function : ; For generative language models The trainable parameters in that encode the control condition, For generative language models Parameters, Represents a batch of data, represents the calculation of conditional probability, and for The i-th text and the corresponding attribute combination in A multi-attribute controllable text generation method based on joint training additional losses;
[0010] Step 2: In the tth training step, a batch of training data is randomly sampled from the training data set, denoted as training data 1. , calculate the training data according to the objective function The generative language model obtained at the t-1th training step Loss on , for the generative language model Optimize and get the intermediate model , the intermediate model The trainable parameters for encoding the control condition are denoted by ;
[0011] Step 3: Sample a batch of training data from the training data set, recorded as training data 2 ; Any attribute in appears in The combination of attributes in Any attribute combination of is different; based on the objective function, the training data is calculated. In the middle model Loss on : ;
[0012] Step 4: Based on and The total loss of Generative language model Perform one step of optimization to obtain the generative language model outputted at the tth training step , Generative Language Model The trainable parameters for encoding the control condition for: ;in, is the second learning rate, For Find the gradient; update the training step: t=t+1;
[0013] Step 5: Repeat steps 2 to 4 until the set number of training steps is reached to obtain different multi-attribute controllable text generation methods based on joint training. The trained generative language model.
[0014] Furthermore, the intermediate model The trainable parameters for encoding the control condition for:
[0015] ;
[0016] in is the first learning rate.
[0017] Further, in step three, the Any attribute in appears in The combination of attributes in Any combination of attributes is different, including:
[0018] Training data 1 The set of attribute combinations in is , training data 2 The set of attribute combinations in is ,but:
[0019] ;
[0020] .
[0021] Represents attributes, Represents a combination of attributes.
[0022] Furthermore, the total loss for:
[0023] ;
[0024] in is a hyperparameter used to balance the two losses.
[0025] Compared with the prior art, the beneficial technical effects of the present invention are:
[0026] The present invention introduces "pseudo-combination" data in the training stage and conducts joint training, so that the update direction of the parameters of the generative language model not only focuses on fitting the training data itself, but also considers data outside the distribution of the training data, thereby improving the generalization ability of the generative language model when facing new attribute combinations as control conditions, and further realizing the improvement of the combinatorial generalization ability of the multi-attribute controllable text generation method. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1 Schematic diagram of the conventional joint training process;
[0028] Figure 2 This is a schematic diagram of the training process of the multi-attribute controllable text generation model based on combined sampling and joint optimization proposed in the present invention. DETAILED DESCRIPTION
[0029] A preferred embodiment of the present invention is described in detail below with reference to the accompanying drawings.
[0030] Existing methods for multi-attribute controllable text generation based on joint training Generative language model During the training process, for each data set, the present invention divides it into two mutually exclusive subsets: the in-distribution set and the reorganization set. The data in the in-distribution set is the training data, which is visible during the training of the generative language model; the data in the reorganization set is invisible during the training. The sets of attribute combinations contained in the in-distribution set and the reorganization set are defined as and , and define the set of attribute combinations contained in the entire data set as ,but , and The relationship is shown as follows:
[0031] ;
[0032] ;
[0033] The second formula represents All attribute combinations in , The individual attributes contained in They must appear The set of individual attributes contained in all attribute combinations in .
[0034] The generative language model is trained on the in-distribution set, and the subsequent generation phase is divided into two cases: 1) Generate The process is defined as in-distribution testing, which is used to test the learning ability of the generative language model on the training data within the distribution; 2) Generate text with The process is defined as the reorganization test, which is used to test the combinatorial generalization ability of the generative language model on out-of-distribution (i.e. reorganized) data. Under the premise of good performance on the in-distribution test, the smaller the performance gap between the two tests, the stronger the combinatorial generalization ability of the generative language model. Figure 1 shown.
[0035] The present invention analyzes that the reason why the existing multi-attribute controllable text generation method based on joint training performs poorly in the reorganization test is that the generative language model overfits the data of the distribution set during the training phase, resulting in that when the generative language model is input with the attribute combination in the reorganization set as a control condition, the generated text is difficult to meet all the given attributes.
[0036] The overall training framework structure of the present invention is as follows Figure 2 The present invention proposes a multi-attribute controllable text generation model training framework based on combined sampling and joint optimization, which improves the model combination generalization ability through multi-attribute combined sampling and joint optimization, and realizes the accurate controllability of generated text.
[0037] For a given multi-attribute controllable text generation method based on joint training , the objective function of the present invention is defined as ,in General Representative The trainable parameters used to encode the control conditions in the adopted generative language model, represent The parameters of the generative language model used (such as GPT-2, which is generally not trainable), Represents a batch of data. Generally speaking, this objective function can be decomposed into the following two items:
[0038] ;
[0039] The first term is the basic generative language model loss, where Represents text The second item is the combination of attributes. The additional losses caused.
[0040] In a preferred embodiment, the generative language model may select GPT-2 or other similar language models.
[0041] In a preferred embodiment, a multi-attribute controllable text generation method based on joint training The contrastive prefix method or the disentangled controllable generation (DCG) method can be used.
[0042] The Contrastive Prefix method adds a prefix parameter to each attribute combination through prefix tuning, and designs a contrast loss function using the idea of contrastive learning. When using the contrastive prefix method, The additional losses for:
[0043] ;
[0044] in, A collection representing a combination of attributes Middle A combination of attributes.
[0045] The DCG method vectorizes the text of attribute combinations first, and then encodes the obtained vectors using a multi-layer perceptron (MLP) network to obtain conditional prompts. Similarly, the DCG method also adopts the idea of contrastive learning, using different prompts obtained by encoding different attribute combinations as conditions and designing a contrastive loss function. When using the DCG method, The additional losses for:
[0046] ;
[0047] ;
[0048] ;
[0049] Represents the encoding result of the multi-layer perceptron, represents a multi-layer perceptron, represents the operation of vectorization using GPT-2, represents data sampling, Represents a collection of attribute combinations The attribute combination set obtained after data sampling in Is a collection of attribute combinations The A combination of attributes.
[0050] In the training framework proposed in this invention, it is mainly divided into the following three steps:
[0051] 1) In the tth training step, the present invention first randomly samples a set of multi-attribute text training data from the training data set, denoted as training data one ,calculate The generative language model obtained at the t-1th training step (The trainable parameters used to encode the control condition are ) , and perform a step optimization to obtain (The trainable parameters used to encode the control condition are ),in:
[0052] ;
[0053] in is the learning rate, For Find the gradient.
[0054] 2) The present invention further samples a batch of pseudo-combination training data from the training data set, which is recorded as training data 2. , as a simulation of the combined generalization scenario. Each individual attribute contained in appears, and there is no intersection between the attribute combinations of the two. The set of attribute combinations contained in is , The set of attribute combinations contained in is , then the relationship between the two is:
[0055] ;
[0056] .
[0057] Then calculate the training data two In the middle model Loss on :
[0058] .
[0059] 3) Joint loss and Get the total loss of the training framework :
[0060] ;
[0061] in is a hyperparameter used to balance the two losses.
[0062] Finally, the total loss is combined One step optimization to obtain (The trainable parameters used to encode the control condition are ), as the training result of the t-th training step, where :
[0063] ;
[0064] in is the learning rate.
[0065] The present invention utilizes loss To simulate the combined generalization scenario and evaluate the updated parameters Performance on the reorganization test. Intermediate model after further updating It can also fit well on the pseudo-combination training data, rather than just on Overfitting.
[0066] It is obvious to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the present invention can be implemented in other specific forms without departing from the spirit or essential features of the present invention. Therefore, from any point of view, the embodiments should be regarded as exemplary and non-limiting, and the scope of the present invention is defined by the appended claims rather than the above description, and it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present invention, and any reference numerals in the claims should not be regarded as limiting the claims involved.
[0067] In addition, it should be understood that although this specification is described in terms of implementation methods, not every implementation method contains only one independent technical solution. This narrative method of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment may also be appropriately combined to form other implementation methods that can be understood by those skilled in the art.
Claims
1. A multi-attribute controllable text generation method based on combined sampling and joint optimization, characterized in that: The combination of multiple given attributes is used as a control condition and input into different multi-attribute controllable text generation methods based on joint training. In the trained generative language model, text that satisfies all given attributes is generated; different multi-attribute controllable text generation methods based on joint training Generative language model The training process includes the following steps: Step 1: Set the training step t=1 and generate the language model Initialize as a generative language model , and set the objective function : ; For generative language models The trainable parameters in that encode the control condition, For generative language models Parameters, Represents a batch of data, represents the calculation of conditional probability, and for The i-th text and the corresponding attribute combination in A multi-attribute controllable text generation method based on joint training additional losses; Step 2: In the tth training step, a batch of training data is randomly sampled from the training data set, denoted as training data 1. , calculate the training data according to the objective function The generative language model obtained at the t-1th training step Loss on , for the generative language model Optimize and get the intermediate model , the intermediate model The trainable parameters for encoding the control condition are denoted by ; Step 3: Sample a batch of training data from the training data set, recorded as training data 2 ; Any attribute in appears in The combination of attributes in Any attribute combination of is different; based on the objective function, the training data is calculated. In the middle model Loss on : ; Step 4: Based on and The total loss of Generative language model Perform one step of optimization to obtain the generative language model outputted at the tth training step , Generative Language Model The trainable parameters for encoding the control condition for: ;in, is the second learning rate, For Find the gradient; update the training step: t=t+1; Step 5: Repeat steps 2 to 4 until the set number of training steps is reached to obtain different multi-attribute controllable text generation methods based on joint training. The trained generative language model; Intermediate Model The trainable parameters for encoding the control condition for: ; in is the first learning rate.
2. The multi-attribute controllable text generation method based on combined sampling and joint optimization according to claim 1 is characterized in that: In step three, the Any attribute in appears in The combination of attributes in Any combination of attributes is different, including: Training data 1 The set of attribute combinations in is , training data 2 The set of attribute combinations in is ,but: ; ; Represents attributes, Represents a combination of attributes.
3. The multi-attribute controllable text generation method based on combined sampling and joint optimization according to claim 1 is characterized in that: The total loss for: ; in is a hyperparameter used to balance the two losses.
