Training method and device for natural language generation model
By using the reinforcement learning model, advantage function, and difference in prior probability distribution to construct the objective function in the natural language generation model, the problem of model instability caused by excessive gradient variance is solved, a more stable and efficient training process is achieved, and the efficiency is improved Generate effects.
Patent Information
- Application Number
- CN202110395155.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-04-13
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2041-04-13
AI Technical Summary
Excessive gradient variance in natural language generation model training causes the model training to be unstable or non-convergent, resulting in poor generation results.
A reinforcement learning model is used to model natural language generation processing as a Markov decision process. The objective function is constructed through the difference between the advantage function and the prior probability distribution. The weighted average of the policy gradient and KL divergence is used to train the model to reduce the gradient variance. and improve model stability.
By reducing gradient variance, the stability and convergence of model training are improved, and more accurate and diverse natural language texts are generated.
Smart Images

Figure CN113111638B
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a natural language generation model training method, a natural language generation model training device, a natural language generation method, a natural language generation device and a non-volatile computer-readable storage medium. Background Art
[0002] In recent years, AI (Artificial Intelligence) technology has developed rapidly, and its applications are spread across all areas of human production and life. NLP (Natural Language Processing) is an important application in the field of artificial intelligence, which is mainly divided into two branches: natural language understanding and NLG (Natural Language Generation).
[0003] Natural language generation is an important scientific technology that integrates artificial intelligence, computer science and computational linguistics. Its main purpose is to enable computers to have the same expression and writing functions as humans, that is, computers can automatically generate a high-quality text based on some key input information through a series of processing and planning processes. The application of this technology has been very extensive, and the most common applications include machine translation, chatbots and voice assistants.
[0004] In the related art, information input into a computer is modeled based on statistical machine learning methods to generate text. Summary of the invention
[0005] The inventors of the present disclosure have discovered that the above-mentioned related technologies have the following problems: the gradient variance of the natural language generation model training is too large, causing the model training to be unstable or non-convergent, thereby resulting in poor natural language generation effect.
[0006] In view of this, the present disclosure proposes a technical solution for training a natural language generation model, which can improve the natural language generation effect.
[0007] According to some embodiments of the present disclosure, a training method for a natural language generation model is provided, including: taking the generated words at each historical moment as the state at the current moment and the output of the generated words at the current moment as the action, modeling the natural language generation process as a reinforcement learning model; determining a first objective function according to the advantage function of the generated words at each moment output by the reinforcement learning model; determining a second objective function according to the difference between the probability distribution of the labeling results at each moment and the probability distribution of the generated words at each moment; and training the reinforcement learning model according to the weighted average of the first objective function and the second objective function.
[0008] In some embodiments, determining the first objective function according to the advantage function of the generated word at each moment output by the reinforcement learning model includes: determining the advantage function according to the difference between the state-action function at each moment and the state-action function at the previous moment.
[0009] In some embodiments, determining the advantage function includes: according to actions a0 to a1 at time 0 to t-1 t-1 , action a at time t t , predict multiple action combinations a from time t+1 to L-1 t+1 ~a L-1 ; Calculate each action combination a t+1 ~a L-1 reward value; determine the state-action function at time t based on the weighted average of each reward value.
[0010] In some embodiments, determining the first objective function based on the advantage function of the generated words at each moment output by the reinforcement learning model includes: using the reinforcement learning model to output the generation probability of the generated words at each moment; and determining the first objective function based on the advantage function and generation probability of the generated words at each moment.
[0011] In some embodiments, determining the second objective function based on the difference between the probability distribution of the annotation results at each moment and the probability distribution of the generated words at each moment includes: determining the prior probability at each moment based on the difference between the annotation results at each moment and the words in the corpus; using a reinforcement learning model to output the generation probability of the generated words at each moment; and determining the second objective function based on the weighted average of the difference between the prior probability and the generation probability at each moment.
[0012] In some embodiments, determining the prior probability at each moment based on the difference between the annotation results at each moment and the words in the corpus includes: determining the prior probability at each moment based on the similarity between the word vector of the annotation results at each moment and the vector of each word in the corpus.
[0013] In some embodiments, determining the second objective function based on the weighted average of the difference between the prior probability and the generated probability at each moment includes: determining the weight of the difference between the prior probability and the generated probability at the corresponding moment based on the advantage function of the generated word at each moment, and the weight is negatively correlated with the advantage function.
[0014] In some embodiments, training the reinforcement learning model according to the weighted average of the first objective function and the second objective function includes: determining a comprehensive objective function according to the weighted average of the first objective function and the second objective function; and training the reinforcement learning model on the condition of minimizing the comprehensive objective function.
[0015] In some embodiments, the training method further includes: generating natural language data using the trained reinforcement learning model.
[0016] In some embodiments, generating natural language data includes: using a trained reinforcement learning model to translate input first language data into second language data.
[0017] According to some other embodiments of the present disclosure, a natural language generation method is provided, including: taking the generated words at each historical moment as the state at the current moment and the output of the generated words at the current moment as the action, modeling the natural language generation process as a reinforcement learning model; determining a first objective function according to the advantage function of the generated words at each moment output by the reinforcement learning model; determining a second objective function according to the difference between the probability distribution of the labeling results at each moment and the probability distribution of the generated words at each moment; training the reinforcement learning model according to the weighted average of the first objective function and the second objective function; and generating natural language data using the trained reinforcement learning model.
[0018] In some embodiments, generating natural language data includes: using a trained reinforcement learning model to translate input first language data into second language data.
[0019] According to some other embodiments of the present disclosure, a training device for a natural language generation model is provided, comprising: a modeling unit, used to model the natural language generation process as a reinforcement learning model, taking the generated words at each historical moment as the state at the current moment and the output of the generated words at the current moment as the action; a determination unit, used to determine a first objective function according to the advantage function of the generated words at each moment output by the reinforcement learning model, and to determine a second objective function according to the difference between the probability distribution of the labeling results at each moment and the probability distribution of the generated words at each moment; and a training unit, used to train the reinforcement learning model according to a weighted average of the first objective function and the second objective function.
[0020] In some embodiments, the determination unit determines the advantage function according to the difference between the state-action function at each moment and the state-action function at the previous moment.
[0021] In some embodiments, the determination unit determines the actions a0 to a1 at time 0 to t-1. t-1 , action a at time t t , predict multiple action combinations a from time t+1 to L-1 t+1 ~a L-1 ; Calculate each action combination a t+1 ~a L-1 reward value; determine the state-action function at time t based on the weighted average of each reward value.
[0022] In some embodiments, the determination unit uses a reinforcement learning model to output the generation probability of a generated word at each moment, and determines the first objective function according to the advantage function and the generation probability of the generated word at each moment.
[0023] In some embodiments, the determination unit determines the prior probability at each moment according to the similarity between the word vector of the annotation result at each moment and the vector of each word in the corpus.
[0024] In some embodiments, the determination unit determines the prior probability at each moment based on the difference between the annotation results at each moment and the words in the corpus, uses the reinforcement learning model to output the generation probability of the generated words at each moment, and determines the second objective function based on the weighted average of the difference between the prior probability at each moment and the generation probability.
[0025] In some embodiments, the determination unit determines the weight of the difference between the prior probability and the generated probability at the corresponding moment according to the advantage function of the generated word at each moment, and the weight is negatively correlated with the advantage function.
[0026] In some embodiments, the training unit determines a comprehensive objective function based on a weighted average of the first objective function and the second objective function, and trains the reinforcement learning model on the condition that the comprehensive objective function is minimized.
[0027] In some embodiments, the training device further includes: a generation unit for generating natural language data using a trained reinforcement learning model.
[0028] In some embodiments, the generation unit uses a trained reinforcement learning model to translate input first language data into second language data.
[0029] According to some further embodiments of the present disclosure, a natural language generation device is provided, including: a modeling unit, used to model the natural language generation process as a reinforcement learning model, taking the generated words at each historical moment as the state at the current moment and the output of the generated words at the current moment as the action; a determination unit, used to determine a first objective function according to the advantage function of the generated words at each moment output by the reinforcement learning model, and to determine a second objective function according to the difference between the probability distribution of the labeling results at each moment and the probability distribution of the generated words at each moment; a training unit, used to train the reinforcement learning model according to the weighted average of the first objective function and the second objective function; and a generation unit, used to generate natural language data using the reinforcement learning model that has completed the training.
[0030] According to some further embodiments of the present disclosure, there is provided a training device for a natural language generation model, comprising: a memory; and a processor coupled to the memory, wherein the processor is configured to execute the training method for the natural language generation model in any one of the above embodiments based on instructions stored in the memory device.
[0031] According to some further embodiments of the present disclosure, there is provided a natural language generation device, comprising: a memory; and a processor coupled to the memory, wherein the processor is configured to execute the natural language generation method in any one of the above embodiments based on instructions stored in the memory device.
[0032] According to some further embodiments of the present disclosure, a non-volatile computer-readable storage medium is provided, on which a computer program is stored, and when the program is executed by a processor, the method for training a natural language generation model or the method for generating natural language in any of the above-mentioned embodiments is implemented.
[0033] In the above embodiment, the objective function is constructed based on the policy gradient of the advantage function, which has a smaller gradient variance; the objective function is constructed based on the difference between the annotation result and the model output result, which can solve the problem of training bias ignorance. In this way, the model training can be guaranteed to be more stable and easier to converge, and the training effect of the model can be improved, thereby improving the natural language generation effect. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] The accompanying drawings, which constitute a part of the specification, illustrate embodiments of the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0035] The present disclosure may be more clearly understood from the following detailed description with reference to the accompanying drawings:
[0036] Figure 1 A flowchart showing some embodiments of the training method of the natural language generation model of the present disclosure;
[0037] Figure 2 Show Figure 1 A flowchart of some embodiments of step 140;
[0038] Figure 3 Schematic diagrams showing some embodiments of the training method of the natural language generation model disclosed in the present invention;
[0039] Figure 4 A block diagram showing some embodiments of a training apparatus for a natural language generation model of the present disclosure;
[0040] Figure 5 A block diagram showing some embodiments of a training device for a natural language generation model or a natural language generation device of the present disclosure;
[0041] Figure 6 A block diagram showing some other embodiments of a natural language generation model training device or a natural language generation device of the present disclosure. DETAILED DESCRIPTION
[0042] Various exemplary embodiments of the present disclosure will now be described in detail with reference to the accompanying drawings. It should be noted that the relative arrangement of components and steps, numerical expressions and numerical values set forth in these embodiments do not limit the scope of the present disclosure unless otherwise specifically stated.
[0043] At the same time, it should be understood that for the convenience of description, the sizes of the various parts shown in the drawings are not drawn according to the actual proportional relationship.
[0044] The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the present disclosure, its application, or uses.
[0045] Technologies, methods and equipment known to ordinary technicians in the relevant field may not be discussed in detail, but where appropriate, the technologies, methods and equipment should be considered part of the authorization specification.
[0046] In all examples shown and discussed herein, any specific values should be interpreted as merely exemplary and not as limiting. Therefore, other examples of the exemplary embodiments may have different values.
[0047] It should be noted that like reference numerals and letters refer to similar items in the following figures, and therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.
[0048] As mentioned above, deep neural networks are used to model the information input into the computer using decoder-encoder neural networks (such as Transformer and Seq2Seq models). When training such models, the cross entropy loss function is generally used to train the natural language generation model through MLE (Maximum Likelihood Estimation). This method has the following technical problems: inconsistency between model training and model testing and reasoning; exposure bias of the model; and negative diversity ignorance.
[0049] The reason for the inconsistency between model training, model testing, and reasoning is that the MLE method trains the model by maximizing conditional probability at the word level, and selects each optimal word to form a text through the greedy sampling method. However, the text generated by the words obtained in each step of the greedy sampling method is not necessarily optimal.
[0050] In addition, the model testing or reasoning stage often uses sequence-level evaluation criteria (such as the commonly used BLEU (Bilingual Evaluation Understudy) to evaluate the quality of text generation from the perspective of the entire sequence. Therefore, the natural language generation model often performs well during training, but performs poorly during testing or reasoning.
[0051] The exposure bias problem of the model mainly exists in the autoregressive decoder-encoder neural network. Each decoding of the autoregressive decoding needs to rely on the output of the previous step. However, when generating each word in the text sequence in the decoding stage, the MLE training method inputs the label word into the model as the input information required to output the next word.
[0052] This method is called teacher-forcing training. The drawback of this method is that the model has no labels when testing or reasoning. Therefore, the information output by the model at each step needs to be used as the input information required to output the next word. However, when the model is trained, this information has never been exposed (that is, it has never been included in the training), which leads to poor performance of the model during testing and reasoning.
[0053] Regarding the problem of negative diversity ignorance, the MLE training method usually uses the cross entropy loss function as the optimization target. However, the cross entropy loss function usually treats samples that are incorrectly predicted by the model equally, that is, no matter how big the gap between the model's predicted error and the true label is, the cross entropy loss function will give these incorrect samples the same "score". Such a training method will reduce the diversity of the text generated by the model.
[0054] In addition, the natural language generation algorithm based on reinforcement learning has the following problems: the problem of ignorance of negative diversity and the problem of excessive variance of training gradients.
[0055] The problem of negative diversity ignorance is that in the training of natural language generation models, reinforcement learning often uses evaluation annotations such as BLEU as reward values to score the predicted text. However, these evaluation criteria still give the same score to prediction samples with different degrees of error.
[0056] The problem of excessive training gradient variance is because reinforcement learning uses the policy gradient method. However, the policy gradient algorithm can easily lead to excessive gradient variance during model training when estimating reward values, resulting in unstable or non-convergent model training.
[0057] In view of the above technical problems, the present invention enables the model to give more reasonable scores to different wrongly predicted samples during training, thereby obtaining a more accurate and more diverse natural language generation model through training.
[0058] Moreover, the present disclosure trains the model by designing a reinforcement learning algorithm with a smaller gradient variance, so that the model training process is more stable and a more accurate natural language generation model is obtained. For example, the technical solution of the present disclosure can be implemented through the following embodiments.
[0059] Figure 1 A flowchart showing some embodiments of the method for training a natural language generation model of the present disclosure.
[0060] like Figure 1 As shown, in step 110, the generated words at each historical moment are taken as the state at the current moment, and the output of the generated words at the current moment is taken as the action, and the natural language generation process is modeled as a reinforcement learning model.
[0061] In some embodiments, the training process of the natural language generation model can be defined as a reinforcement learning problem. The reinforcement learning process is a Markov decision process, so the natural language generation process needs to be defined as a Markov decision process.
[0062] In some embodiments, the Markov decision process includes a five-tuple (S, A, T, R, γ), where S is the state space, A is the action space, T is the state transition function, R is the reward value, and γ is the discount factor. The natural language generation model can be trained using a reinforcement learning method by maximizing the reward value.
[0063] For example, the evaluation method of the reward value may be BLEU, ROUGE (Recall-Oriented Understudy for Gisting Evaluation), METEOR, and the like.
[0064] For example, regarding state S, the state S at time t t is the words w0~w generated from time 0 to time t-1 t-1 And the output Z of the decoder of the machine learning model, 0≤t≤L, L is the length of the sentence to be generated (corresponding to the time when each word is generated).
[0065] For example, regarding the action space A, the model generates a word to represent an action, and the action at time t is represented as a t , that is, w t =a t , different actions constitute the action space A. In the problem of natural language generation, the action space A is equivalent to a dictionary, which contains all the words available in the generation process.
[0066] For example, regarding the state transition function T, it defines the state S from the current moment tTransfer to the next state S t+1 Once the agent performs an action a t , the transition will be determined. The state at time t can be expressed as:
[0067] S t =(w0,w1,…,w t-1 ,Z)
[0068] For example, regarding the reward value R, when the length of the sentence generated at the current moment is less than L, the reward value is 0; when the length of the sentence generated at the current moment is equal to L, an EOS (end identifier) is generated to indicate that the entire sentence has been generated and the current reward value is calculated. The reward value at time t can be calculated according to various evaluation methods:
[0069]
[0070] In some embodiments, different evaluation methods may be used to determine the reward value r according to different types of natural language generation tasks. For example, for machine translation tasks, the BLEU method may be used to determine the reward value r; for summary and summarization tasks, the ROUGE method may be used to determine the reward value r.
[0071] For example, regarding the state transition probability T, the state transition probability P(S t+1 |S t ,a t ) indicates that in action a t Under the action of state S t Transfer to S t+1 In the natural language generation task, according to the definition of state, P(S t+1 |S t ,a t ) is always equal to 1.
[0072] For example, regarding the discount factor γ, its role is to assign different weights to different moments t. In the natural language generation task, it can be considered that the importance of each word is the same, that is, γ is always equal to 1.
[0073] In step 120, a first objective function is determined according to the advantage function of the generated word at each moment output by the reinforcement learning model.
[0074] In some embodiments, the advantage function is determined based on the difference between the state-action function at each moment and the state-action function at the previous moment.
[0075] For example, the advantage function at time t is A π (S t ,a t ), which measures the quality of the words generated at time t, and the state value V at time tπ (S t ) and reward value r t That is, to compute the advantage function, we need to estimate the value of the state.
[0076] However, there is no separate value network in the natural language generation model to estimate the state value V π (S t ). Therefore, in reinforcement learning, it is necessary to calculate the action state value Q π (s t ,a t ) to replace the state value V π (S t (。
[0077] For example, Q π (s t ,a t ) is the value of the state action function at time t (also called Q value), and the Q value is the expected reward value, which measures the quality of the word output at time t. π (s t ,a t ) can be expressed as:
[0078]
[0079] From the above formula, we can see that V π (S t ) can be obtained through Q π (s t ,a t ) is calculated. Moreover, as mentioned above, based on the definition of the natural language generation problem of reinforcement learning, it can be seen that the state transition probability and the discount factor are always equal to 1, and the reward value r at time t t is 0, so the state value at time t+1 is equal to the Q value at time t:
[0080] V π (S t )=Q π (s t ,a t )
[0081] Therefore, the advantage function can be determined by the following calculation formula:
[0082] A π (S t ,a t )=Q π (s t ,a t )-Q π (s t-1 ,a t-1 )
[0083] In this way, only the Q value needs to be estimated to determine the advantage function at the corresponding moment.
[0084] In some embodiments, in the definition of reinforcement learning, the Q value is the expected reward value. t ) continue to reason backwards for each word (such as w t+1 ~w L ), we can get a complete sentence containing L words.
[0085] In some embodiments, for each word output, a complete sentence can be predicted. Therefore, each complete reward value can be calculated for calculating the Q value.
[0086] For example, according to the actions a0 to a0 at time 0 to t-1 t-1 , action a at time t t , predict multiple action combinations a from time t+1 to L-1 t+1 ~a L-1 (i.e., multiple complete sentences); calculate each action combination a t+1 ~a L-1 reward value; determine the state-action function at time t based on the weighted average of each reward value.
[0087] For example, you can use the K-step Monte Carlo simulation method to predict K sentences from time t+1 to the entire end time L when outputting a word at time t, and calculate the average reward value of these K sentences as the Q value at time t:
[0088]
[0089] a 0:t-1 is the action taken from time 0 to t-1 (i.e., the words generated), is the action a taken from the predicted time t+1 to L t+1:L There are k combinations of .
[0090] In some embodiments, the generation probability of the generated word at each moment is output by using the reinforcement learning model; the first objective function is determined according to the advantage function and generation probability of the generated word at each moment. For example, the first objective function L can be calculated by the following formula RL (θ):
[0091]
[0092] E P [ ] indicates P θ (w t ) Find the expected value, P θ(w t ) is the generated word w at time t output by the reinforcement learning model t The generation probability of , θ is a model parameter that can be adjusted according to actual conditions.
[0093] In step 130, a second objective function is determined according to the difference between the probability distribution of the labeling results at each time and the probability distribution of the generated words at each time.
[0094] In some embodiments, the prior probability at each moment is determined based on the difference between the labeling result at each moment and each word in the corpus. For example, the prior probability at each moment is determined based on the similarity between the word vector of the labeling result at each moment and the vector of each word in the corpus.
[0095] The reinforcement learning model is used to output the generation probability of the generated word at each moment; and the second objective function is determined according to the weighted average of the difference between the prior probability and the generation probability at each moment.
[0096] For example, according to the advantage function of the generated word at each moment, the weight of the difference between the prior probability and the generated probability at the corresponding moment is determined, and the weight is negatively correlated with the advantage function.
[0097] In some embodiments, the second objective function may be calculated based on the adaptive factor and the KL divergence of the prior distribution.
[0098] For example, first, the word2vec pre-training algorithm can be used to pre-train the corpus to obtain pre-trained word vectors; then, based on the pre-trained word vectors, the prior probability P at time t is calculated. * (w t ):
[0099]
[0100] w* t is the label word pre-marked at time t, w t is the generated word output by the model at time t, w is the word in the dictionary (corpus), =mb() is the function of taking word vector, σ() is the Softmax function, and cos_sim() is the cosine similarity function.
[0101] That is to say, when the model outputs a generated word w at time t t When w is calculated, the label words at that time are used t The prior probability of .
[0102] For example, the cosine similarity between the word vector of the label word and all the words in the dictionary can be calculated. The words with closer semantics to the label have higher cosine similarity. The Softmax function is used to normalize all the calculated similarities to obtain the prior distribution p at time t. * (w t ).
[0103] In some embodiments, the prior probability P is obtained. * (w t ), we can calculate the prior probability p * (w t ) and the generation probability p of the model output θ (w t ) to determine the second objective function:
[0104]
[0105] is the adaptive factor, α is the weight parameter set according to the actual situation, P θ (w t ) is the generation probability of the model output at time t, and KL[ ] is the calculation of the KL divergence function.
[0106] In some embodiments, the adaptive factor and the advantage function A π (S t ,a t ), that is, the larger the advantage function value, the smaller the adaptive factor value. In other words, based on the word w generated at time t t , when the predicted complete sentence can obtain a higher reward value, the weight of KL divergence will be automatically reduced. Thus, over-correction of KL divergence to outputs with higher reward values can be avoided, and the accuracy of model training can be improved.
[0107] In step 140, the reinforcement learning model is trained according to the weighted average of the first objective function and the second objective function.
[0108] In some embodiments, the trained reinforcement learning model is used to generate natural language data. For example, the trained reinforcement learning model is used to translate input first language data into second language data.
[0109] In some embodiments, Figure 2 The embodiment in implements step 140.
[0110] Figure 2 Show Figure 1 Flowchart of some embodiments of step 140.
[0111] like Figure 2 As shown, in step 1410, a comprehensive objective function is determined based on the weighted average of the first objective function and the second objective function.
[0112] In some embodiments, a first objective function (policy gradient loss function) based on an advantage function and a second objective function based on a KL divergence are used to determine a comprehensive objective function as follows:
[0113] L(θ)=-L RL (θ)+βL KL (θ)
[0114] β is a weight parameter that can be adjusted according to actual conditions.
[0115] In step 1420, the reinforcement learning model is trained under the condition of minimizing the comprehensive objective function. For example, the natural language generation model can be trained using the gradient descent method based on the comprehensive objective function.
[0116] Figure 3 A schematic diagram showing some embodiments of the training method of the natural language generation model of the present disclosure.
[0117] like Figure 3 The overall training process shown in the figure uses the Monte Carlo simulation method to generate w at time t during the reinforcement learning training process. t , perform K expansions and predict K complete sentences. For example, w t-1 For "The", w t For "cat", based on w t-1 、w t K complete sentences can be predicted.
[0118] The advantage function is calculated based on the K reward values and Q values of each predicted sentence, and the policy gradient training target is weighted by the advantage function.
[0119] In some embodiments, in order to solve the problem of bias ignorance, the dictionary can be pre-trained to obtain trained word vectors. For example, when training the model, at each moment, the pre-trained word vector is used to calculate the prior probability distribution according to the labeling results at the current moment. For example, the labeling results at each moment are "The", "cat", "is", "eating", "an", and "apple".
[0120] In some embodiments, the KL divergence between the generated probability distribution of the model output and the prior probability distribution is calculated to measure the closeness between the generated probability distribution of the model output and the prior probability distribution. For example, in order to prevent the KL divergence from over-correcting the output, the KL divergence can be weighted using an advantage function and used as part of the optimization target.
[0121] In some embodiments, the technical solution of the present disclosure may be four steps: step A, step B, step C, and step D. Steps A and B are used to calculate the policy gradient objective function based on the advantage function as the first objective function; step C calculates the second objective function based on the KL divergence of the adaptive factor; and step D adds the above optimization objectives to obtain a comprehensive objective function to train the model.
[0122] In step A, the training process of the natural language generation model can be defined as a reinforcement learning problem. The reinforcement learning process is a Markov decision process, so the natural language generation process needs to be defined as a Markov decision process.
[0123] In some embodiments, the Markov decision process includes a five-tuple (S, A, T, R, γ), where S is the state space, A is the action space, T is the state transition function, R is the reward value, and γ is the discount factor. The natural language generation model can be trained using a reinforcement learning method by maximizing the reward value.
[0124] For example, the evaluation method of the reward value may be BLEU, ROUGE (Recall-Oriented Understudy for Gisting Evaluation), METEOR, and the like.
[0125] For example, regarding state S, the state S at time t t is the words w0~w generated from time 0 to time t-1 t-1 And the output Z of the decoder of the machine learning model, 0≤t≤L, L is the length of the sentence to be generated (corresponding to the time when each word is generated).
[0126] For example, regarding the action space A, the model generates a word to represent an action, and the action at time t is represented as a t , that is, w t =a t , different actions constitute the action space A. In the problem of natural language generation, the action space A is equivalent to a dictionary, which contains all the words available in the generation process.
[0127] For example, regarding the state transition function T, it defines the state S from the current moment t Transfer to the next state S t+1 Once the agent performs an action a t , the transfer will be confirmed.
[0128] For example, regarding the reward value R, when the length of the sentence generated at the current moment is less than L, the reward value is 0; when the length of the sentence generated at the current moment is equal to L, EOS (end identifier) is generated to indicate that the entire sentence has been generated and the current reward value is calculated.
[0129] In some embodiments, different evaluation methods may be used to determine the reward value r according to different types of natural language generation tasks. For example, for machine translation tasks, the BLEU method may be used to determine the reward value r; for summary and summarization tasks, the ROUGE method may be used to determine the reward value r.
[0130] For example, regarding the state transition probability T, the state transition probability P(S t+1 |S t ,a t ) indicates that in action a t Under the action of state S t Transfer to S t+1 In the natural language generation task, according to the definition of state, P(S t+1 |S t ,a t ) is always equal to 1.
[0131] For example, regarding the discount factor γ, its role is to assign different weights to different moments t. In the natural language generation task, it can be considered that the importance of each word is the same, that is, γ is always equal to 1.
[0132] In step B, the advantage function at time t is A π (S t ,a t ), which measures the quality of the words generated at time t, and the state value V at time t π (S t ) and reward value r t That is, to compute the advantage function, we need to estimate the value of the state.
[0133] However, there is no separate value network in the natural language generation model to estimate the state value V π (S t ). Therefore, in reinforcement learning, it is necessary to calculate the action state value Q π (s t ,a t ) to replace the state value V π (S t ).
[0134] For example, Q π (s t ,a t) is the value of the state action function at time t (also called Q value), and the Q value is the expected reward value, which measures the quality of the word output at time t. π (S t ) can be obtained through Q π (s t ,a t ) calculated.
[0135] Moreover, as mentioned above, the definition of the natural language generation problem based on reinforcement learning shows that the state transition probability and the discount factor are always equal to 1, and the reward value r at time t t is 0, therefore, the state value at time t+1 is equal to the Q value at time t.
[0136] Therefore, the advantage function can be determined by the following calculation formula:
[0137] A π (S t ,a t )=Q π (s t ,a t )-Q π (s t-1 ,a t-1 )
[0138] In this way, only the Q value needs to be estimated to determine the advantage function at the corresponding moment.
[0139] In some embodiments, in the definition of reinforcement learning, the Q value is the expected reward value. t ) continue to reason backwards for each word (such as w t+1 ~w L ), we can get a complete sentence containing L words.
[0140] In some embodiments, for each word output, a complete sentence can be predicted. Therefore, each complete reward value can be calculated for calculating the Q value.
[0141] For example, according to the actions a0 to a0 at time 0 to t-1 t-1 , action a at time t t , predict multiple action combinations a from time t+1 to L-1 t+1 ~a L-1 (i.e., multiple complete sentences); calculate each action combination a t+1 ~a L-1 reward value; determine the state-action function at time t based on the weighted average of each reward value.
[0142] For example, you can use the K-step Monte Carlo simulation method to predict K sentences from time t+1 to the entire end time L when outputting a word at time t, and calculate the average reward value of these K sentences as the Q value at time t.
[0143] In some embodiments, a reinforcement learning model is used to output the generation probability of a generated word at each moment; and a first objective function is determined based on the advantage function and the generation probability of the generated word at each moment.
[0144] In step C, the word2vec pre-training algorithm can be used to pre-train the corpus to obtain pre-trained word vectors; then, based on the pre-trained word vectors, the prior probability P at time t is calculated. * (w t ).
[0145] That is to say, when the model outputs a generated word w at time t t When w is calculated, the label words at that time are used t The prior probability of .
[0146] For example, the cosine similarity between the word vector of the label word and all the words in the dictionary can be calculated. The words with closer semantics to the label have higher cosine similarity. The Softmax function is used to normalize all the calculated similarities to obtain the prior distribution p at time t. * (w t ).
[0147] In some embodiments, the prior probability P is obtained. * (w t ), we can calculate the prior probability p * (w t ) and the generation probability p of the model output θ (w t ) to determine the second objective function.
[0148] In some embodiments, the adaptive factor and the advantage function A π (S t ,a t ), that is, the larger the advantage function value, the smaller the adaptive factor value. In other words, based on the word w generated at time t t , when the predicted complete sentence can obtain a higher reward value, the weight of KL divergence will be automatically reduced. Thus, over-correction of KL divergence to outputs with higher reward values can be avoided, and the accuracy of model training can be improved.
[0149] In step D, a comprehensive objective function is determined using a first objective function (policy gradient loss function) based on an advantage function and a second objective function based on KL divergence. For example, a natural language generation model can be trained using a gradient descent method based on the comprehensive objective function.
[0150] In the above embodiment, the policy ladder objective function based on the advantage function solves the problem that the gradient variance is too large during the training process of the existing method, which makes it difficult for the model training to converge; the KL divergence objective function based on the adaptive factor measures the distance between the model output distribution and a pre-trained prior distribution, and solves the bias ignorance problem existing in the traditional cross entropy loss function and the policy gradient objective function.
[0151] In addition, the adaptive factor based on the advantage function can automatically adjust the weight of the KL divergence, so that the two optimization objectives can be better trained together. This prevents the KL divergence objective of the adaptive factor from overtraining the model at the word level.
[0152] Figure 4 A block diagram showing some embodiments of a training apparatus for a natural language generation model of the present disclosure.
[0153] like Figure 4 As shown, the training device 4 for the natural language generation model includes a modeling unit 41 , a determination unit 42 , and a training unit 43 .
[0154] The modeling unit 41 takes the generated words at each historical moment as the state at the current moment and the output of the generated words at the current moment as the action, and models the natural language generation process as a reinforcement learning model.
[0155] The determination unit 42 determines the first objective function according to the advantage function of the generated words at each moment output by the reinforcement learning model; and determines the second objective function according to the difference between the probability distribution of the labeling results at each moment and the probability distribution of the generated words at each moment.
[0156] In some embodiments, the determination unit 42 determines the advantage function according to the difference between the state-action function at each moment and the state-action function at the previous moment.
[0157] In some embodiments, the determination unit 42 determines the actions a0 to a1 at time 0 to t-1. t-1 , action a at time t t , predict multiple action combinations a from time t+1 to L-1 t+1 ~a L-1 ; Calculate each action combination a t+1 ~a L-1 reward value; determine the state-action function at time t based on the weighted average of each reward value.
[0158] In some embodiments, the determination unit 42 uses a reinforcement learning model to output the generation probability of a generated word at each moment, and determines the first objective function according to the advantage function and the generation probability of the generated word at each moment.
[0159] In some embodiments, the determination unit 42 determines the prior probability at each moment according to the similarity between the word vector of the annotation result at each moment and the vector of each word in the corpus.
[0160] In some embodiments, the determination unit 42 determines the prior probability at each moment based on the difference between the annotation results at each moment and the words in the corpus, uses the reinforcement learning model to output the generation probability of the generated words at each moment, and determines the second objective function based on the weighted average of the difference between the prior probability at each moment and the generation probability.
[0161] In some embodiments, the determination unit 42 determines the weight of the difference between the prior probability and the generated probability at the corresponding moment according to the advantage function of the generated word at each moment, and the weight is negatively correlated with the advantage function.
[0162] The training unit 43 trains the reinforcement learning model according to the weighted average of the first objective function and the second objective function.
[0163] In some embodiments, the training unit 43 determines the comprehensive objective function according to the weighted average of the first objective function and the second objective function, and trains the reinforcement learning model on the condition of minimizing the comprehensive objective function.
[0164] In some embodiments, the training device 4 further includes: a generation unit 44 for generating natural language data using the trained reinforcement learning model.
[0165] In some embodiments, the generation unit 44 uses a trained reinforcement learning model to translate the input first language data into second language data.
[0166] Figure 5 A block diagram showing some embodiments of a natural language generation model training device or a natural language generation device of the present disclosure.
[0167] like Figure 5 As shown, in some embodiments, the training device 5 for the natural language generation model includes: a memory 51 and a processor 52 coupled to the memory 51, and the processor 52 is configured to execute the training method for the natural language generation model in any embodiment of the present disclosure based on instructions stored in the memory 51.
[0168] In some embodiments, the natural language generation device 5 includes: a memory 51 and a processor 52 coupled to the memory 51, and the processor 52 is configured to execute the natural language generation method in any embodiment of the present disclosure based on instructions stored in the memory 51.
[0169] The memory 51 may include, for example, a system memory, a fixed non-volatile storage medium, etc. The system memory may store, for example, an operating system, an application program, a boot loader, a database, and other programs.
[0170] Figure 6 A block diagram showing some other embodiments of a natural language generation model training device or a natural language generation device of the present disclosure.
[0171] like Figure 6 As shown, in some embodiments, the training device 6 for the natural language generation model includes: a memory 610 and a processor 620 coupled to the memory 610, and the processor 620 is configured to execute the training method for the natural language generation model in any one of the aforementioned embodiments based on instructions stored in the memory 610.
[0172] In some embodiments, the natural language generation device 6 includes: a memory 610 and a processor 620 coupled to the memory 610 , and the processor 620 is configured to execute the natural language generation method in any one of the aforementioned embodiments based on instructions stored in the memory 610 .
[0173] The memory 610 may include, for example, a system memory, a fixed non-volatile storage medium, etc. The system memory may store, for example, an operating system, an application program, a boot loader, and other programs.
[0174] The device 6 may also include an input / output interface 630, a network interface 640, a storage interface 650, etc. These interfaces 630, 640, 650, the memory 610, and the processor 620 may be connected, for example, via a bus 860. The input / output interface 630 provides a connection interface for input / output devices such as a display, a mouse, a keyboard, a touch screen, a microphone, and a speaker. The network interface 640 provides a connection interface for various networked devices. The storage interface 650 provides a connection interface for external storage devices such as an SD card and a USB flash drive.
[0175] Those skilled in the art will appreciate that the embodiments of the present disclosure may be provided as methods, systems, or computer program products. Therefore, the present disclosure may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present disclosure may take the form of a computer program product implemented on one or more computer-usable non-transient storage media including but not limited to disk storage, CD-ROM, optical storage, etc., which contain computer-usable program code.
[0176] So far, the training method of the natural language generation model, the training device of the natural language generation model, the natural language generation method, the natural language generation device and the non-volatile computer-readable storage medium according to the present disclosure have been described in detail. In order to avoid obscuring the concept of the present disclosure, some details known in the art are not described. Based on the above description, those skilled in the art can fully understand how to implement the technical solution disclosed herein.
[0177] The method and system of the present disclosure may be implemented in many ways. For example, the method and system of the present disclosure may be implemented by software, hardware, firmware, or any combination of software, hardware, and firmware. The above order of steps for the method is for illustration only, and the steps of the method of the present disclosure are not limited to the order specifically described above, unless otherwise specifically stated. In addition, in some embodiments, the present disclosure may also be implemented as a program recorded in a recording medium, which includes machine-readable instructions for implementing the method according to the present disclosure. Therefore, the present disclosure also covers a recording medium storing a program for executing the method according to the present disclosure.
[0178] Although some specific embodiments of the present disclosure have been described in detail by way of example, it should be understood by those skilled in the art that the above examples are for illustration only and are not intended to limit the scope of the present disclosure. It should be understood by those skilled in the art that the above embodiments may be modified without departing from the scope and spirit of the present disclosure. The scope of the present disclosure is defined by the appended claims.
Claims
1. A training method for a natural language generation model, comprising: The generated words at each historical moment are used as the state at the current moment, and the output of the generated words at the current moment is used as the action, and the natural language generation process is modeled as a reinforcement learning model; Determining a first objective function according to the advantage function of the generated word at each moment output by the reinforcement learning model; Determining a second objective function according to the difference between the probability distribution of the labeling results at each moment and the probability distribution of the generated words at each moment; Training the reinforcement learning model according to a weighted average of the first objective function and the second objective function; Wherein, determining the first objective function comprises: Using the reinforcement learning model, the generation probability of the generated word at each moment is output; Determining the first objective function according to the advantage function and generation probability of the generated word at each moment; Determining the second objective function comprises: Determine the prior probability at each moment based on the difference between the annotation results at each moment and the words in the corpus; Using the reinforcement learning model, the generation probability of the generated word at each moment is output; The second objective function is determined according to a weighted average of differences between the prior probability and the generated probability at each moment.
2. The training method according to claim 1, wherein: Determining the first objective function according to the advantage function of the generated word at each moment output by the reinforcement learning model includes: The advantage function is determined according to the difference between the state-action function at each moment and the state-action function at the previous moment.
3. The training method according to claim 2, wherein: Determining the advantage function comprises: According to the action a0~a from time 0 to t-1 t-1 , action a at time t t , predict multiple action combinations a at time t+1~L-1 t+1 ~a L -1 ; Calculate each action combination a t+1 ~a L-1 The reward value of Determine the state-action function at time t based on the weighted average of each reward value.
4. The training method according to claim 1, wherein: Determining the prior probability at each moment according to the difference between the annotation result at each moment and each word in the corpus includes: The prior probability at each moment is determined based on the similarity between the word vector of the annotation result at each moment and the vector of each word in the corpus.
5. The training method according to claim 1, wherein: Determining the second objective function according to the weighted average of the differences between the prior probability and the generated probability at each moment includes: According to the advantage function of the generated word at each moment, the weight of the difference between the prior probability and the generated probability at the corresponding moment is determined, and the weight is negatively correlated with the advantage function.
6. The training method according to claim 1, wherein: The step of training the reinforcement learning model according to the weighted average of the first objective function and the second objective function includes: Determine a comprehensive objective function according to a weighted average of the first objective function and the second objective function; The reinforcement learning model is trained on the condition that the comprehensive objective function is minimized.
7. The training method according to any one of claims 1 to 6, further comprising: Generate natural language data using the trained reinforcement learning model.
8. The training method according to claim 7, wherein: Generating natural language data comprises: The input first language data is translated into second language data using the trained reinforcement learning model.
9. A method for generating natural language, comprising: The generated words at each historical moment are used as the state at the current moment, and the output of the generated words at the current moment is used as the action, and the natural language generation process is modeled as a reinforcement learning model; Determining a first objective function according to the advantage function of the generated word at each moment output by the reinforcement learning model; Determining a second objective function according to the difference between the probability distribution of the labeling results at each moment and the probability distribution of the generated words at each moment; Training the reinforcement learning model according to a weighted average of the first objective function and the second objective function; Generate natural language data using the trained reinforcement learning model; Wherein, determining the first objective function comprises: Using the reinforcement learning model, the generation probability of the generated word at each moment is output; Determining the first objective function according to the advantage function and generation probability of the generated word at each moment; Determining the second objective function comprises: Determine the prior probability at each moment based on the difference between the annotation results at each moment and the words in the corpus; Using the reinforcement learning model, the generation probability of the generated word at each moment is output; The second objective function is determined according to a weighted average of differences between the prior probability and the generated probability at each moment.
10. The generation method according to claim 9, wherein: Generating natural language data comprises: The input first language data is translated into second language data using the trained reinforcement learning model.
11. A training device for a natural language generation model, comprising: A modeling unit, used to model the natural language generation process as a reinforcement learning model by taking the generated words at each historical moment as the state at the current moment and the output of the generated words at the current moment as the action; A determination unit, configured to determine a first objective function according to an advantage function of a generated word at each moment output by the reinforcement learning model, and determine a second objective function according to a difference between a probability distribution of annotated results at each moment and a probability distribution of a generated word at each moment; A training unit, configured to train the reinforcement learning model according to a weighted average of the first objective function and the second objective function; in, The determination unit uses the reinforcement learning model to output the generation probability of the generated words at each moment, and determines the first objective function according to the advantage function and the generation probability of the generated words at each moment; the determination unit determines the prior probability at each moment according to the difference between the annotation results at each moment and the words in the corpus, and uses the reinforcement learning model to output the generation probability of the generated words at each moment, and determines the second objective function according to the weighted average of the difference between the prior probability and the generation probability at each moment.
12. The training device according to claim 11, wherein: The determining unit determines the advantage function according to the difference between the state-action function at each moment and the state-action function at the previous moment.
13. The training device according to claim 12, wherein: The determination unit determines the actions a0~a at time 0~t-1 t-1 , action a at time t t , predict multiple action combinations a at time t+1~L-1 t+1 ~a L -1 ; Calculate each action combination a t+1 ~a L-1 reward value; determine the state-action function at time t based on the weighted average of each reward value.
14. The training device according to claim 11, wherein: The determination unit determines the prior probability at each moment according to the similarity between the word vector of the annotation result at each moment and the vector of each word in the corpus.
15. The training device according to claim 11, wherein: The determination unit determines the weight of the difference between the prior probability and the generated probability at the corresponding moment according to the advantage function of the generated word at each moment, and the weight is negatively correlated with the advantage function.
16. The training device according to claim 11, wherein: The training unit determines a comprehensive objective function according to a weighted average of the first objective function and the second objective function, and trains the reinforcement learning model on the condition that the comprehensive objective function is minimized.
17. The training device according to any one of claims 11 to 16, further comprising: A generation unit is used to generate natural language data using the reinforcement learning model that has completed training.
18. The training device according to claim 17, wherein: The generating unit uses the trained reinforcement learning model to translate the input first language data into second language data.
19. A natural language generation device, comprising: A modeling unit, used to model the natural language generation process as a reinforcement learning model by taking the generated words at each historical moment as the state at the current moment and the output of the generated words at the current moment as the action; A determination unit, configured to determine a first objective function according to an advantage function of a generated word at each moment output by the reinforcement learning model, and determine a second objective function according to a difference between a probability distribution of annotated results at each moment and a probability distribution of a generated word at each moment; A training unit, configured to train the reinforcement learning model according to a weighted average of the first objective function and the second objective function; A generating unit, configured to generate natural language data using the trained reinforcement learning model; in, The determination unit uses the reinforcement learning model to output the generation probability of the generated words at each moment, and determines the first objective function according to the advantage function and the generation probability of the generated words at each moment; the determination unit determines the prior probability at each moment according to the difference between the annotation results at each moment and the words in the corpus, and uses the reinforcement learning model to output the generation probability of the generated words at each moment, and determines the second objective function according to the weighted average of the difference between the prior probability and the generation probability at each moment.
20. A training device for a natural language generation model, comprising: Memory; and A processor coupled to the memory, the processor being configured to execute the training method for the natural language generation model according to any one of claims 1-8 based on instructions stored in the memory.
21. A natural language generation device, comprising: Memory; and A processor coupled to the memory, wherein the processor is configured to execute the natural language generation method according to claim 9 or 10 based on instructions stored in the memory.
22. A non-volatile computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the training method for a natural language generation model described in any one of claims 1 to 8, or the natural language generation method described in claim 9 or 10.
