Single-attribute controllable text generation method based on continuous prompt contrast learning

By using the contrastive learning method in text generation to train the cue vectors of opposing attributes and the cue vectors of target attributes, the problem of attribute confusion in the cue vectors during the training phase is solved, and the controllability and semantic coherence of text generation are improved.

CN118535694APending Publication Date: 2024-08-23TIANJIN UNIV
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202410596476.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-14
Publication Date
2024-08-23

AI Technical Summary

Technical Problem

In attribute-based controllable text generation, the prompt vector is prone to learn other attribute features besides the target attribute during the training phase, leading to confusion of the attributes of the generated text and reducing the usability of the text.

Method used

Using a method based on continuous cue contrast learning, by training the cue vector of the opposing attribute and the cue vector of the target attribute, a contrast loss function is introduced to ensure that the cue vector of the target attribute focuses on the target attribute during the training process and avoids interference from other attributes. Trained cue vectors generate text.

Benefits of technology

It improves the controllability of the prompt vector, reduces the interference of generated text from other non-target attributes in the training data, and improves the semantic coherence of the text and the usability of the generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118535694A
    Figure CN118535694A
Patent Text Reader

Abstract

The invention discloses a single-attribute controllable text generation method based on continuous prompt contrast learning. The method comprises the following steps: S1, training continuous prompts of opposite attributes; s2, training the continuous prompts of the target attributes in combination with the continuous prompts of the opposite attributes; and S3, generating a text by utilizing the continuous prompts of the trained target attributes. According to the method, the prompt vector of the opposite attribute is introduced to train the prompt vector of the target attribute. According to the method, the prompt vector of the target attribute learns the relation between the opposite attributes in the training process, meanwhile, the prompt vector is not interfered by other attributes in the training data, the problem of attribute confusion is relieved, and the controllability of the prompt vector is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the controllable text generation direction in the field of natural language processing (NLP), and in particular to a single-attribute controllable text generation method based on continuous prompt contrast learning. Background Art

[0002] Attribute-based controllable text generation aims to generate natural language sentences that meet specific attributes such as themes, emotions, keywords, and styles. In some scenarios, users need to control some attributes of the sentences generated by the model. For example, when simulating the generation of a merchant's reply to a user, the generated content cannot be toxic and the emotions must be positive. In the research field of attribute-based controllable text generation, the controlled generation of single-attribute text is the most critical and basic. In most scenarios, the generated text only needs to have one or two key attributes to meet the needs; secondly, the generation of multi-attribute text is generally based on the generation of single-attribute text, so it is necessary to first conduct research on the generation of single-attribute text. At present, the research on controllable text generation is combined with the pre-trained language model. The research routes can be basically divided into three: the first is to fine-tune the pre-trained language model, which aims to fine-tune part or all of the parameters of the pre-trained language model to generate text that meets the conditions. This route includes methods such as adapted network modules, prompt learning, and reinforcement learning inspiration; the second is to retrain or reconstruct the pre-trained language model. This technical route is expected to greatly improve the quality and controllability of text generation, but it will be limited by computing resources and data volume; the third technical route is to reorder the generated text in a post-processing manner. The most important thing about this technical route is to use appropriate decoding algorithms, such as greedy search, constrained beam search, top-k sampling, etc. Continuous prompts are a new method proposed in recent years. This method freezes the parameters of the pre-trained language model and optimizes a small continuous task-specific vector by back-propagating the error. This vector appears at the prefix of the input text and is also called soft prompts. This method has the following advantages: 1. Compared with manually crafted prompt templates, this method is simpler, has low initialization requirements, and has better experimental results; 2. Compared with discrete text prompts, continuous prompts can contain higher-density information; 3. Using this method, you only need to adjust about 0.1 percent of the parameters of the pre-trained language model, which shortens the training time and requires less computing power resources.

[0003] Recently, there has been some work on attribute-based controlled text generation using continuous vectors as prompts. [1][2]A problem that is ignored is that during the training phase of the prompt vector, the prompt vector will inevitably learn other features in the data set while learning the target attribute, which makes it easy to fit other attributes of the data (such as text style, theme, etc.) other than the target attribute. This means that the prompt vector trained to represent a certain target attribute is actually confused, so in the text generation phase, the generated text often has other attributes of the training data set in addition to the target attribute, which limits the richness of the generated text and reduces the usability of the generated text. For example, if a prompt vector representing positive emotions is trained on a dataset related to rating restaurants (such as the YELP dataset), in the generation phase using the prompt vector, even if the prompt text has nothing to do with the objects described in the training dataset, such as restaurants and food, the generated text will usually be related to restaurants and food. Summary of the invention

[0004] The purpose of the present invention is to overcome the deficiencies in the prior art, solve the attribute confusion problem generated in the prompt vector training stage, and provide a single-attribute controllable text generation method based on continuous prompt contrast learning. The method introduces the prompt vector of the opposing attribute to train the prompt vector of the target attribute. For example, if the target attribute is positive emotion, then its opposing attribute is negative emotion. The data used in the training process of the prompt vector of the opposing attribute and the prompt vector of the target attribute are derived from the same data set, with the purpose of making the training data used by the two consistent except that the target attribute is in an opposing relationship. The method enables the prompt vector of the target attribute to learn the relationship between the opposing attributes during the training process, and at the same time makes it not interfered by other attributes in the training data, alleviates the problem of attribute confusion, and improves the controllability of the prompt vector.

[0005] The objective of the present invention is achieved through the following technical solutions:

[0006] A single-attribute controllable text generation method based on continuous prompt contrastive learning, comprising:

[0007] S1. Training of continuous prompts of opposing attributes;

[0008] S2. Combine the continuous prompts of the opposing attributes to train the continuous prompts of the target attribute;

[0009] S3. Generating text using continuous prompts from trained target attributes.

[0010] Furthermore, in step S1, continuous prompts of opposing attributes are trained using a prompt tuning method; the following steps are included:

[0011] S101. Initialize a continuous prompt P of length l for describing the opposing attribute A A, formally expressed as:

[0012]

[0013] in, represents a parameter matrix, d emb is the word embedding dimension of the pre-trained language model;

[0014] S102. In the training data set x 1:n ={x1,x2,...,x n}, where n is the number of data in the training dataset, and is fed into the pre-trained language model for text embedding to obtain a word sequence matrix Then, the P A With the matrix X emb Do the concatenation as the input of the pre-trained language model; the learning objective based on the pre-trained language model is formally expressed as:

[0015]

[0016] Among them, θ g and denote the parameters of the pre-trained language model and the continuous prompt P used to describe the opposing attribute A. A During training, the parameters of the pre-trained language model will be frozen, and only the continuous prompt P A The parameters will be updated.

[0017] Further, step S2 includes the following steps:

[0018] S201. Extract continuous hints of the target attribute: first initialize a continuous hint P of length l for describing the target attribute B. B , formally expressed as:

[0019]

[0020] represents a parameter matrix; l is a continuous prompt P describing the opposing attribute B B Length;

[0021] S202. Continuously prompt P B , continuous prompt P A The concatenated data is concatenated with the embedded text data, and the concatenated result is input into the pre-trained language model for training; during the training process, only the continuous prompt P of the target attribute is B The relevant parameters will be updated, and the continuous prompt of the opposing attributes P A And the parameters of the pre-trained language model will be frozen.

[0022] Furthermore, in the training phase of step S202, in order to prevent the target attribute from being contaminated by other attributes during generation, the loss function of the pre-trained language model Based on this, a new contrast loss is introduced The total loss function for and The weighted sum of:

[0023]

[0024]

[0025]

[0026] Among them, ω1 and ω2 represent the pre-trained language model and contrast loss The weight of represents a continuous prompt P used to describe the opposing attribute A A Parameters; represents a continuous prompt P used to describe the opposing attribute B B Parameters; x is the input training data, y is the attribute label of x; It is defined as the negative of the cosine similarity between consecutive cues of two attributes A and B plus one; the cosine similarity is obtained by calculating the dot product of two consecutive cues and then dividing it by the product of their moduli; when P B and P A The closer the cosine similarity of P is to 1, the smaller the contrast loss is; conversely, when P B and P A The closer the cosine similarity is to -1, the greater the contrast loss.

[0027] Furthermore, the pre-trained language model uses Gpt-2, and the attention mechanism of Gpt-2 is modified to ensure that only the continuous prompts of the target attribute will pay attention to the continuous prompts of the opposing attribute during the training phase, so that Gpt-2 can capture the relationship between the attributes;

[0028] The native attention mechanism Attention is:

[0029]

[0030] Where Q, K, and V represent the three sequence vectors of query, key, and value respectively. is the dimension of sequence representation Q and K, T represents the transposition operation, softmax() is an activation function, and the opposing attributes continuously prompt P A and target attribute continuous prompt P B The lengths are l A, l B , i, j represent the row index and column index of the attention matrix M, and the attention matrix M is initialized as:

[0031]

[0032] Modified attention module Attention mod for:

[0033]

[0034] in, Represents the output matrix of the attention mechanism.

[0035] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method for generating single-attribute controllable text based on continuous prompt contrast learning when executing the program.

[0036] The present invention also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the method for generating single-attribute controllable text based on continuous prompt contrast learning are implemented.

[0037] Compared with the prior art, the technical solution of the present invention has the following beneficial effects:

[0038] 1. The existing technology of continuous prompts of opposing attributes after training is actually attribute confusion, because the pre-trained language model does not have the ability to capture specific attributes in the training data, resulting in the continuous prompts aimlessly absorbing various features of the training data during the training stage. For example, after training a continuous prompt representing negative emotions on a data set describing food with negative emotions, the text generated by the continuous prompt is not only negative in emotion, but also related to food.

[0039] The method of the present invention introduces a new error module, so that in the continuous prompt stage of training target attributes, the continuous prompt can focus on the target attribute without being disturbed by other attributes in the training data. The degree to which the text generated by using the continuous prompt is disturbed by other non-target attributes in the training data is greatly reduced, and the semantic coherence between the prompt text and the input is greatly improved compared with the existing methods.

[0040] 2. The continuous prompts obtained by training using the method of the present invention can be plug-and-play. In the text generation stage, the continuous prompts can be directly spliced ​​with the prompt text and then sent to the pre-trained language model for generation. Compared with the existing methods, the practicality of this method is improved.

[0041] 3. The method of the present invention touches on the use and optimization of deep learning, especially pre-trained language models (such as the GPT series), to achieve text generation with specific attributes (such as emotions, styles, etc.). By introducing continuous prompts (soft prompts) and contrastive learning methods, it is committed to improving the quality and controllability of text generation while reducing the demand for computing resources. This method demonstrates innovative technical applications and methodological development in the direction of controllable text generation in the field of natural language processing. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 It is a schematic diagram of the process of the present invention

[0043] Figure 2 It is a schematic diagram of the mask mechanism involved in the present invention. DETAILED DESCRIPTION

[0044] The present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.

[0045] The goal of this invention is to guide the pre-trained language model to generate text that satisfies a specific single attribute. Specifically, given a prompt text x 1:t ={x1,x2,...,x t}, where t is the dimension of the prompt text after text embedding. The task of this method is to generate a continuation text X based on the prompt text. t+1:n ={X t+1 ,X t+2 ,...X n}, n is the dimension of the continuation text after text embedding, so that the entire text meets the target attribute T a The formal definition of the task is as follows:

[0046] P(X|T a )=M(X t+1:n |X 1:t ,T a ) (1-1)

[0047] Where M is the pre-trained language model.

[0048] The single-attribute controllable text generation method based on continuous prompt contrast learning proposed in the present invention is mainly aimed at paired attributes such as emotion and toxicity. Before generating text of a specified attribute, it is necessary to first obtain continuous prompts of the opposite attribute of the attribute. For example, before training continuous prompts of the target attribute of positive emotion, it is necessary to first train continuous prompts of the opposite attribute of negative emotion. The method of training continuous prompts of opposite attributes is similar to that of Lester et al. [3]The proposed prompts are tuned consistently. After obtaining the continuous prompts of the opposing attribute, this method will randomly initialize a vector as the continuous prompt of the specified attribute, and then sequentially concatenate the continuous prompts of the opposing attribute and the text data from the specified dataset, and send them to the pre-trained language model for training. The goal of training is to make the initialized continuous prompts represent the target attribute while staying away from the continuous prompts of the opposing attribute.

[0049] Specifically, this embodiment provides a single-attribute controllable text generation method based on continuous prompt contrast learning, see Figure 1 ,include:

[0050] S1. Training of continuous prompts of opposing attributes;

[0051] S2. Combine the continuous prompts of the opposing attributes to train the continuous prompts of the target attribute;

[0052] S3. Generating text using continuous prompts from trained target attributes.

[0053] Specifically, in S1, Lester et al. [3] The proposed prompt tuning method uses pre-trained continuous vectors to guide large-scale pre-trained language models to generate text, and each continuous vector represents a specific attribute. This embodiment refers to Yang et al. [1] Specifically, we first initialize a continuous prompt P of length l for describing attribute A. A , is a parameter matrix, which can be formally expressed as:

[0054]

[0055] Among them, d emb is the word embedding dimension of the pre-trained language model. Then, in the training dataset x 1:n ={x1,x2,...,x n} and feed it into the pre-trained language model for text embedding. As the parameter matrix, we get a word sequence matrix Then, the P A Concatenate with this matrix as the input of the pre-trained language model. Finally, the learning goal based on the language model It can be formally expressed as:

[0056]

[0057] Among them, θ g and Represent the parameters of the pre-trained language model and the continuous prompt P used to describe the attribute A. A During training, the parameters of the pre-trained language model will be frozen, and only the parameters of the continuous prompt will be updated. This is why the subsequent experiments of this method will not occupy a lot of computing resources. This embodiment follows the work of predecessors. [1][4] , set the prompt text to the following 15 texts: "Once upon a time", "The book", "The chicken", "Thecity", "The country", "The lake", "The movie", "The painting", "The weather", "Thefood", "While this is happening", "The pizza", "The potato", "The president of the country", "The year is 1910".

[0058] In step S2, after obtaining the continuous hints of the opposing attribute, the continuous hint extraction process of the target attribute begins. Specifically, similar to the process in step S1, a continuous hint P of length l for describing attribute B is initialized. B , which can also be formalized as:

[0059]

[0060] Then, the P B , continuous prompt P A It is concatenated with the embedded text data, and the subsequent process is the same as step S1. However, in training, only the continuous prompt P of the target attribute is B The relevant parameters will be updated, and the continuous prompt of the opposing attributes P A And the parameters of the pre-trained language model will be frozen.

[0061] In the training phase, in order to avoid attribute contamination in the generation of the target attribute, this embodiment uses the language model loss function Based on this, a new contrast loss function is introduced The loss function of the model is for and The weighted sum of:

[0062]

[0063]

[0064]

[0065] Among them, ω1 and ω2 represent the pre-trained language models respectively. and contrast loss The weight of ; x is the input training data, y and x are attribute labels; It is defined as the negative of the cosine similarity between two attribute hint vectors plus one. Cosine similarity is obtained by calculating the dot product of two vectors and then dividing by the product of their moduli. B and P A The more similar (i.e., the cosine similarity approaches 1), the smaller the contrast loss; conversely, when P B and P A The greater the difference (i.e., the cosine similarity approaches -1), the greater the contrast loss. In the text generation stage, the continuous prompts of the target attributes obtained through training are directly used to guide GPT-2 to generate text.

[0066] Because in the training stage of the continuous prompt of the target attribute, the continuous prompt of the opposing attribute is spliced ​​with the continuous prompt of the target attribute. [1] The MAP Mask (Multi-Attribute Prompt Mask) used modifies the attention mechanism of the pre-trained language model Gpt-2, thereby ensuring that only the continuous prompt vector of the target attribute will pay attention to the continuous prompt vector of the opposing attribute during the training phase, allowing the model to capture the relationship between the attributes. Figure 2 As shown in Figure 2. Since the attention mechanism of GPT-2 is unidirectional, the input in the training phase continues to maintain the order of the continuous prompt vector of the opposing attribute, the continuous prompt vector of the target attribute, and the input text embedding. It should be noted that Yang et al. [1] The purpose of implementing MAP Mask is to minimize the gap between continuous prompts in the training stage and the generation stage, while the purpose of the mask strategy implemented in this embodiment is to make the prompt vector of the opposing attribute only concerned by the prompt vector of the target attribute, so as to avoid it from guiding subsequent text generation. In addition, this embodiment only uses the mask strategy in the training stage. In the text generation stage, the continuous prompts of the target attribute are directly used to guide GPT-2 to generate text, realizing a simple plug-and-play strategy.

[0067] Given the native attention mechanism Attention [5] As follows, Q, K, and V represent three sequence vectors of query, key, and value respectively. represents the dimensions of Q and K in the sequence, T represents the transposition operation, and softmax() is an activation function:

[0068]

[0069] Given the opposing attributes continuous prompt P A and target attribute continuous prompt P B , whose lengths are l A , l B , i, j represent the row index and column index of the attention matrix M, and the attention matrix M is initialized as:

[0070]

[0071] Then in the modified attention module Attention mod In this example, n represents the length of the input text. is a parameter matrix, which can be formalized as:

[0072]

[0073] In order to prove the feasibility of the method of the present invention, this embodiment conducts experiments on the emotion control task, and introduces the specific evaluation indicators and experimental results as follows. In the content of this embodiment, the evaluation indicators are divided into two aspects: automatic evaluation indicators and manual evaluation indicators.

[0074] 1. Automatic evaluation: The text generated by the method of the present invention is tested from the following four aspects:

[0075] 1) The degree of correlation with the target attribute. Because the goal of the content of this embodiment is to generate text based on a single attribute, the degree of correlation between the text and the target attribute is summarized as the correctness of the text. In the emotion control task, in order to calculate this indicator, this embodiment fine-tuned a RoBERTa-based model for evaluation, and the training set, validation set, and test set used were 1300k, 1k, and 1k data, respectively. In the toxicity avoidance task, this embodiment used PerspectiveAPI (https: / / perspectiveapi.com) to calculate the average toxicity probability (AverageToxicityProbability).

[0076] 2) Text quality. This embodiment uses perplexity PPL (Perplexity) as an indicator to measure text quality.

[0077] It measures the uncertainty of the model on the test data, and a lower perplexity means that the model predicts the data more accurately. This embodiment uses Gpt2-Large to calculate the perplexity of the text.

[0078] 3) Diversity. This example uses Distinct-n [6] The specific formula for calculation is:

[0079]

[0080] 4) Attribute confusion. In order to more intuitively demonstrate that the content of the present invention solves the attribute contamination problem better than previous work, this embodiment designs the attribute confusion indicator. Its calculation method is very simple. For example, if continuous prompts related to emotional attributes are obtained by training on a data set of movie reviews, then in the text generation stage, data related to restaurant reviews are used as prompt texts, and then the attribute discriminator is used to determine the percentage of text related to movie reviews in the generated text. From the foregoing, it can be seen that it is most reasonable to keep the attribute confusion at a low level. This embodiment uses this indicator in the emotion control task.

[0081] This example uses Stanford Sentiment Treebank (SST-5) (https: / / huggingface.co / datasets / SetFit / sst5 / tree / main) as a training dataset. This dataset is based on movie reviews and aims to provide a resource for fine-grained sentiment analysis, that is, not only distinguishing positive and negative emotions, but also dividing the intensity and direction of emotions in more detail. SST-5 contains five label levels: very negative, negative, neutral, positive, and very positive. The amount of data contained in each label is shown in Table 1-1, which makes it a powerful tool for understanding and analyzing the nuances of emotions in text. In this section, the text data used in training continuous prompts of different emotional attributes is removed from the text marked as neutral. The data used to train the prompt vector representing positive emotions is extracted from the data marked as "very positive" and "positive", and the data used to train the prompt vector representing negative emotions is extracted from the data marked as "very negative" and "negative". The amount of training data is 2.5k.

[0082] Table 1-1 Dataset attribute distribution

[0083] Emotional Tags Data volume Very positive 1288 positive 2322 neutral 1624 negative 2218 Very negative 1092

[0084] In order to better demonstrate the performance advantages of the method of the present invention, this example introduces multiple models for comparison:

[0085] PromptTuning [3] : Use a set of pre-trained continuous vectors (continuous prompts) to guide the pre-trained language model to generate. The continuous prompts will be randomly initialized during training, and then concatenated with the word sequence matrix as input to GPT-2 for training. At this time, the parameters of GPT-2 will be frozen, and only the parameters of the continuous prompts will be updated.

[0086] GPT-2 Base: This example tests GPT-2 on training sets with different specific attributes. Base Fine-tuning was done, with the learning rate warmup step set to 0 and the learning rate set to 5e-3.

[0087] Gedi [7] :GeDi normalizes the two conditional distributions and calculates the classification probabilities of all possible next tokens through the Bayesian rule, thereby guiding the generation of each step. This embodiment uses the settings specified in the paper for experiments.

[0088] PPLM [8] : The core idea of ​​PPLM is to combine the pre-trained language model (LM) with one or more attribute classifiers to guide text generation. The model performs well on attributes such as topics and emotions, and can ensure the fluency of the text on the basis of controlling attributes.

[0089] DisCup [9] :DisCup uses both continuous prompts and a discriminator with attribute knowledge to generate controlled text. This example experiments on two tasks, sentiment and detoxification, using the settings in this paper.

[0090] Cnlg-cp single [2] :This work considers the relationship between prefix vectors and proposes supervised and unsupervised methods for single-attribute controllable text generation. These two methods can also be combined to generate text with multiple attributes. This embodiment uses a supervised method with better performance to compare with the method of the present invention, and uses the settings in the paper for experiments.

[0091] Automatic evaluation result analysis

[0092] The experimental results of the method proposed in this embodiment on the SST-5 dataset are analyzed, and the experimental results are shown in Table 1-2.

[0093] In terms of correctness and perplexity indicators, the method of the present invention outperforms most baseline models. Gedi performs best in the correctness indicator, but its perplexity is also the highest among all models, which means that the model sacrifices text fluency to ensure correctness. The reason for this phenomenon may be that the model decouples the generation model and the guidance model. The method of the present invention performs slightly worse in the diversity indicator, but it should be noted that Prompt Tuning and the SOTA model DisCup also perform poorly in this indicator, while Gedi and PPLM with higher perplexity indicators perform better. This may be because it is difficult for the model to take into account both text fluency and diversity. After experiments, the method of the present invention can improve text diversity by shortening the length of continuous prompt vectors, but the correctness and fluency of the generated text are reduced, as shown in Table 1-3.

[0094] Table 1-2 Main experimental results on emotion control tasks

[0095]

[0096] Table 1-3 Effect of hint vector length on automatic evaluation index

[0097]

[0098] In terms of the perplexity index, the model of the method of the present invention performs best because other baseline models except DisCup did not pay attention to the problem of attribute confusion and did not take measures in the training stage, resulting in a very high confusion of the model.

[0099] Preferably, in order to verify the effect of the masking mechanism proposed by the method of the present invention, this embodiment further conducts an ablation experiment on the emotion control task. The specific results are shown in Table 1-4:

[0100] Table 1-4 Mask mechanism effectiveness verification

[0101]

[0102] Tables 1-4 show the comparison of various indicators between the method using the masking mechanism (the method of the present invention) and the method not using the masking mechanism (w / o AM). Here, "w / o AM" means removing the masking mechanism (Prompt Mask) when executing the research method. From the results, it can be observed that although the removal of the masking mechanism has little effect on the diversity index and the perplexity index, the correctness index decreases significantly. The experimental results demonstrate the influence of the continuous prompt vector of opposing attributes on the controllability of text generation, and emphasize that the application of masks at the attention level can significantly improve the accuracy of the model. Therefore, the masking mechanism proposed in the present invention is an effective means to improve the performance of the emotion control text generation task.

[0103] Preferably, the embodiments of the present application also provide a specific implementation of an electronic device capable of implementing all steps in the single-attribute controllable text generation method based on continuous prompt contrast learning in the above embodiment, and the electronic device specifically includes the following contents:

[0104] Processor, memory, communications interface and bus;

[0105] Among them, the processor, memory, and communication interface communicate with each other through the bus; the communication interface is used to realize information transmission between related devices such as server-side devices, metering devices, and user-side devices.

[0106] The processor is used to call the computer program in the memory, and when the processor executes the computer program, all the steps in the single-attribute controllable text generation method based on continuous prompt contrast learning in the above embodiment are implemented.

[0107] The embodiments of the present application also provide a computer-readable storage medium capable of implementing all the steps of the method for generating single-attribute controllable text based on continuous prompt contrast learning in the above embodiments. The computer-readable storage medium stores a computer program, which, when executed by a processor, implements all the steps of the method for generating single-attribute controllable text based on continuous prompt contrast learning in the above embodiments.

[0108] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0109] Although the present application provides method operation steps such as embodiments or flow charts, more or fewer operation steps may be included based on conventional or non-creative labor. The order of steps listed in the embodiments is only one way of executing the order of many steps and does not represent the only execution order. When the actual device or client product is executed, it can be executed in the order of the method shown in the embodiments or the drawings or in parallel (for example, in a parallel processor or multi-threaded processing environment).

[0110] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0111] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0112] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0113] The present invention is not limited to the embodiments described above. The above description of the specific embodiments is intended to describe and illustrate the technical solution of the present invention. The above specific embodiments are merely illustrative and not restrictive. Without departing from the scope of the present invention and the scope of protection of the claims, a person of ordinary skill in the art can also make many forms of specific changes under the guidance of the present invention, which all fall within the scope of protection of the present invention.

[0114] References:

[0115] [1].YangK,LiuD,LeiW,etal.Tailor:ASoft-Prompt-BasedApproachtoAttribute-BasedControlledTextGeneration[C / OL] / / RogersA,Boyd-GraberJ,OkazakiN.InProceedingsofthe61stAnnualMeetingoftheAssociationforComputa-tionalLinguistics(Volume1:LongPapers),Toronto,Canada,July2023:410–427.https: / / aclanthology.org / 2023.acl-long.25.

[0116] [2]Qian J,Dong L,Shen Y,et al.Controllable Natural LanguageGeneration with Contrastive Prefixes[C / OL] / / Muresan S,Nakov P,VillavicencioA.In Findings of the Association for Computational Linguistics:ACL 2022,Dublin,Ireland,May 2022:2912–2924.https: / / aclanthology.org / 2022.findings-acl.229.

[0117] [3]Lester B,Al-Rfou R,Constant N.The Power of Scale for Parameter-Efficient Prompt Tuning [C / OL] / / Moens M-F,Huang X,Specia L,et al.In Proceed-ings of the 2021 Conference on Empirical Methods in Natural Language Process-ing,Online and Punta Cana,Dominican Republic,November 2021:3045–3059.https: / / aclanthology.org / 2021.emnlp-main.243.

[0118] [4]Huang X,Liu Z,Li P,et al.An extensible plug-and-play method formulti-aspect controllable text generation[C].In Proceedings of the 61stAnnual Meeting of the Association for Computational Linguistics(Volume 1:LongPapers),2023:15233–15256.

[0119] [5]Vaswani A,Shazeer N,Parmar N,et al.Attention is All You Need[C].InPro-ceedings of the 31st International Conference on Neural InformationProcessing Systems,Red Hook,NY,USA,2017:6000–6010.

[0120] [6]Li J,Galley M,Brockett C,et al.A Diversity-Promoting ObjectiveFunction for Neural Conversation Models[C / OL] / / Knight K,Nenkova A,Rambow O.InPro-ceedings of the 2016 Conference of the North American Chapter of theAssocia-tion for Computational Linguistics:Human Language Technologies,SanDiego,California,June 2016:110–119.https: / / aclanthology.org / N16-1014.

[0121] [7]Krause B,Gotmare A D,McCann B,et al.GeDi:Generative DiscriminatorGuided Sequence Generation[C / OL] / / Moens M-F,Huang X,Specia L,et al.InFindings of the Association for Computational Linguistics:EMNLP 2021,PuntaCana,Dominican Republic,November 2021:4929–4952.https: / / aclanthology.org / 2021.findings-emnlp.424.

[0122] [8]Dathathri S,Madotto A,Lan J,et al.Plug and Play Language Models:ASimple Approach to Controlled Text Generation[J / OL].CoRR,2019,abs / 1912.02164.http: / / arxiv.org / abs / 1912.02164.

[0123] [9]Zhang H,Song D.DisCup:Discriminator Cooperative UnlikelihoodPrompt-tuning for Controllable Text Generation[C / OL] / / Goldberg Y,Kozareva Z,Zhang Y.In Proceedings of the 2022 Conference on Empirical Methods in Nat-ural Language Processing,Abu Dhabi,United Arab Emirates,December 2022:3392–3406.https: / / aclanthology.org / 2022.emnlp-main.223.

Claims

1. A single-attribute controllable text generation method based on continuous prompt contrastive learning, It is characterized in that include: S1. Training of continuous prompting of opposing attributes; S2. Combine the continuous prompts of the opposing attributes to train the continuous prompts of the target attribute; S3. Generating text using continuous prompts from trained target attributes.

2. According to the method for generating single-attribute controllable text based on continuous prompt contrastive learning as described in claim 1, It is characterized in that Step S1 uses a prompt tuning method to train continuous prompts of opposing attributes; the steps include: S101. Initialize a continuous prompt P of length l for describing the opposing attribute A A , formally expressed as: in, represents a parameter matrix, d emb is the word embedding dimension of the pre-trained language model; S102. In the training data set x 1:n ={x 1 ,x 2 ,...,x n }, where n is the number of data in the training dataset, and is fed into the pre-trained language model for text embedding to obtain a word sequence matrix Then, the P A With the matrix X emb Do concatenation as the input of the pre-trained language model; the learning objective based on the pre-trained language model is formally expressed as: Among them, θ g and denote the parameters of the pre-trained language model and the continuous prompt P used to describe the opposing attribute A. A During training, the parameters of the pre-trained language model will be frozen, and only the continuous prompt P A The parameters will be updated.

3. According to the method for generating single-attribute controllable text based on continuous prompt contrastive learning as described in claim 1, It is characterized in that Step S2 includes the following steps: S201. Extract continuous hints of the target attribute: first initialize a continuous hint P of length l for describing the target attribute B. B , formally expressed as: represents a parameter matrix; l is a continuous prompt P describing the opposing attribute B B Length; S202. Continuously prompt P B , continuous prompt P A The concatenated data is concatenated with the embedded text data, and the concatenated result is input into the pre-trained language model for training; during the training process, only the continuous prompt P of the target attribute is B The relevant parameters will be updated, and the continuous prompts of the opposing attributes P A And the parameters of the pre-trained language model will be frozen.

4. According to the method for generating single-attribute controllable text based on continuous prompt contrastive learning as described in claim 3, It is characterized in that In the training phase of step S202, in order to prevent the target attribute from being contaminated by other attributes during generation, the loss function of the pre-trained language model Based on this, a new contrast loss is introduced The total loss function for and The weighted sum of: Among them, ω 1 and ω 2 Represents the pre-trained language model and contrast loss The weight of represents a continuous prompt P used to describe the opposing attribute A A Parameters; represents a continuous prompt P used to describe the opposing attribute B B Parameters; x is the input training data, y is the attribute label of x; It is defined as the negative of the cosine similarity between consecutive cues of two attributes A and B plus one; the cosine similarity is obtained by calculating the dot product of two consecutive cues and then dividing it by the product of their moduli; when P B and P A The closer the cosine similarity of P is to 1, the smaller the contrast loss is; conversely, when P B and P A The closer the cosine similarity is to -1, the greater the contrast loss.

5. According to the method for generating single-attribute controllable text based on continuous prompt contrastive learning as described in claim 1, It is characterized in that The pre-trained language model uses Gpt-2, and the attention mechanism of Gpt-2 is modified to ensure that only the continuous prompts of the target attribute will pay attention to the continuous prompts of the opposing attribute during the training phase, so that Gpt-2 can capture the relationship between the attributes; The native attention mechanism Attention is: Where Q, K, and V represent the three sequence vectors of query, key, and value respectively. is the dimension of sequence representation Q and K, T represents the transposition operation, softmax() is an activation function, and the opposing attributes continuously prompt P A and target attribute continuous prompt P B The lengths are l A , l B , i, j represent the row index and column index of the attention matrix M, and the attention matrix M is initialized as: Modified attention module Attention mod for: in, Represents the output matrix of the attention mechanism.

6. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the program, the steps of the method for generating single-attribute controllable text based on continuous prompt contrast learning as described in any one of claims 1 to 5 are implemented.

7. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the steps of the method for generating single-attribute controllable text based on continuous prompt contrast learning as described in any one of claims 1 to 5 are implemented.

Citation Information

Patent Citations

  • Radiology report generation model training method and system based on multi-modal contrast learning

    CN115293128A

  • Heterogeneous information network keyword generation method based on comparative learning pre-training

    CN116662565A

  • Small sample text classification method based on knowledge contrast enhancement prompt

    CN116881457A

  • Controllable text generation method and device

    CN116881709A

  • Automatic news abstract generation method and device based on large language model and medium

    CN117875273A