ERNIE-GEN: An Enhanced Multi-Flow Pre-training and Fine-tuning Framework for Natural Language Generation

Dongling Xiao, Han Zhang, Yukun Li, Yu Sun, Hao Tian, Hua Wu, Haifeng Wang

Introduction

Pre-trained on large-scale unlabeled text corpora and fine-tuned on downstream tasks, self-supervised representation models such as GPT Radford et al. (2018), BERT Devlin et al. (2019) and XLNet Yang et al. (2019b) have achieved remarkable improvements in natural language understanding (NLU). Different from encoder-only pre-training like BERT or decoder-only pre-training like GPT, natural language generation (NLG) relies on the sequence to sequence generation framework (seq2seq) which consists of a bidirectional encoder and a unidirectional decoder. Current pre-training works in NLG such as MASS Song et al. (2019) and UNILM Dong et al. (2019) mainly focus on jointly pre-training encoder and decoder on different self-supervised tasks. However, these works pay little attention to the exposure bias issue Ranzato et al. (2016), a major drawback of teacher-forcing training. This issue is due to the fact that groundtruth words are used during training, while generated words, whether predicted correctly or not, are used for inference where mistakes tend to accumulate.

To alleviate this issue, we present ERNIE-GEN, an enhanced multi-flow seq2seq training framework characterized by a carefully-designed Multi-Flow Attention architecture based on Transformer Vaswani et al. (2017), as illustrated in Figure 2. ERNIE-GEN incorporates a novel infilling generation mechanism and a noise-aware generation method into pre-training and fine-tuning, which is proved to be effective through experiments in §4.3.

Infilling generation. Instead of using last groundtruth word in training or last generated word in inference, we adopt an inserted artificial symbol [ATTN] along with its position to gather history contextual representations at each step in both training and inference, which diverts model’s attention away from last word and coerces it into focusing on all former representations, thus alleviating negative influence of previous mistakes to subsequent generation, as shown in Figure 1(b).

Noise-Aware generation. We corrupt the input target sequence by randomly replacing words to arbitrary words in the vocabulary. This setup, despite its simplicity, proves to be an effective way to make the model be aware of mistakes in training, so that the model is able to detect mistakes and ignore them during inference.

Moreover, in light of the fact that entities, phrases and sentences in human writing are organized in a coherent manner, we incorporate a span-by-span generation task into ERNIE-GEN as a new generation flow to train the model to predict semantically-complete spans consecutively rather than predicting word by word as traditional models do. This task is implemented through the infilling generation mechanism in parallel with an infilling-based word-by-word generation flow to facilitate convergence in training, as shown in Figure 1b.

In addition, as shown in Figure 1(c-d), recent pre-training works for NLG like UNILM and MASS only sample a single continuous segment as target sequence. However, this sampling method compromises the correlation between encoder and decoder when it comes to pre-training of long texts (typically 512 words), given that adjacent segments are often relevant semantically. ERNIE-GEN adopts a multi-granularity target fragments sampling strategy to force decoder to rely more on the encoder representations other than the previous generated words, thus enhancing the correlation between encoder and decoder, as shown in Figure 1e.

Empirically, ERNIE-GEN is particularly effective and achieves state-of-the-art results on a range of NLG tasks including abstractive summarization (Gigaword and CN- N/DailyMail), question generation (SQuAD), dialogue response generation (Persona-Chat) and generative question answering (CoQA), utilizing a much smaller amount of pre-training data and parameters.

Related Work

Recently, pre-training methods have achieved state-of-the-art results in multiple NLU tasks. ELMo Peters et al. (2018) pre-trains two unidirectional language models (LMs) with forward and backward direction respectively to feature downstream tasks. GPT utilizes an adjusted Transformer Vaswani et al. (2017) to learn a forward LM and then fine-tunes the forward LM on supervised datasets. BERT proposes a masked language modeling (MLM) task to learn deep bidirectional representations. Nevertheless, above methods are usually implemented by just one encoder or decoder, which is less effective in encoder-decoder based generation tasks, thus several works have preliminarily explored the pre-training towards NLG by incorporating BERT’s MLM into the seq2seq framework and shown excellent performance on a range of generation tasks. MASS masks a consecutive fragment (50%) of the input sentence with [MASK] symbols to predict. UNILM masks several words in the input sequence which is a pair of segments for encoder and decoder, and then predicts the masked words in accordance with BERT’s MLM.

Exposure Bias Issue.

NLG tasks suffer from the exposure bias which is caused by teacher-forcing training. To address such issue, RNN-based variational autoencoders (VAEs) are leveraged in Yang et al. (2019a); Wang et al. (2019), whereas it requires inference for both posterior and prior distribution. Reinforcement learning is also adopted to text generation against exposure bias issue Ranzato et al. (2016); Wang et al. (2018), which is, however, inefficient during training because of the word-by-word sampling procedure. These methods are inefficient and less practical for pre-training that relies on large-scale unlabeled text corpora.

Span-level Pre-training.

Sun et al. (2019, 2020); Joshi et al. (2019) verify that predicting spans reaches substantially better performance on NLU tasks. Meanwhile, inspired by characteristics of human expression, we hope the model have the foresight to generate a semantically-complete span at each step rather than a word. Consequently, a span-by-span generating task is proposed to make the model capable of generating texts more human-like.

Proposed Framework

Built on infilling generation mechanism, ERNIE-GEN adopts a Multi-Flow Attention architecture to train the model on word-by-word and span-by-span generation tasks in parallel. In this section, we describe ERNIE-GEN according to the training process shown in Figure 2.

Given an input sequence S={s1,...,sn}\bm{S}=\{s_{1},...,s_{n}\}, we first sample a length distribution DiD_{i} from a distribution set D={D1,...,D∣D∣}\bm{D}=\{D_{1},...,D_{|\bm{D}|}\} with probability pip_{i} for target fragments, and then select fragments according to DiD_{i} in S\bm{S} iteratively until the fragment budget has been spent (e.g. 25% of S\bm{S}). We denote SjiS_{j}^{i} as the jj-th fragment which is sampled in length distribution DiD_{i}. Sampled fragments are then removed from S\bm{S} and stitched together to form target sequence T=[T1,...,Tk]=[S1i,...,Ski]\bm{T}=[T_{1},...,T_{k}]=[S_{1}^{i},...,S_{k}^{i}]. We denote S′\bm{S}^{\prime} as the left input sequence after removing sampled fragments.

ERNIE-GEN performs pre-training by predicting the fragmented target sequence T\bm{T} and minimizing the negative log likelihood:

where the target sequence T\bm{T} is sorted by the positions of sampled fragments. For each fragment T={t1,...,t∣T∣}T=\{t_{1},...,t_{|T|}\} in T\bm{T}, we have P(T)=∏j=1∣T∣P(tj∣t<j)P(T)=\prod_{j=1}^{|T|}P(t_{j}|t_{<j}).

Following preliminary trials, we set a hyperparameter γ=0.25\gamma=0.25, which denotes the ratio of length of all fragments to that of the input sequence S\bm{S}. Besides, we introduce two uniform distributions D={U(1,4),U(4,32)}\bm{D}=\{U(1,4),U(4,32)\} with probability of 0.40.4 and 0.60.6 respectively to sample fragments, which aims to learn representations from different perspectives. On the one hand, short fragments benefit learning of semantic relation between words; on the other hand, longer fragments help to memorize sentence-level expressions.

2 Noise-Aware Generation

To train a generation model which can detect the false prediction and mitigate its impact on subsequent generation, we corrupt the groundtruth sequence T\bm{T} with a procedure where words are being replaced randomly, and the corrupted T\bm{T} is represented as T′\bm{T}^{\prime}. There are two hyperparameters, ρp\rho_{p} and ρf\rho_{f}, denoting the noising rate in pre-training and fine-tuning respectively.

3 Architecture: Multi-Flow Attention

Formally, given a source sequence S={s1,...,sn}\bm{S}=\{s_{1},...,s_{n}\}, a noised target sequence T′={t1,...,tm}\bm{T}^{\prime}=\{t_{1},...,t_{m}\}, we denote the inference of seq2seq network based on shared Transformer as follows:

where QQ, KK, VV denote the query, key, and value in Multi-Head attention Vaswani et al. (2017). si(l)\displaystyle{\bm{s}_{i}^{(l)}} and ti(l)\bm{t}_{i}^{(l)} indicate the ii-th vector representations of the ll-th layer of Multi-Head Attention for the encoder and the decoder respectively, [⋅][\cdot] denotes the concatenation operation. In this work, we call the above procedure the Contextual Flow.

Based on infilling generation mechanism, this flow utilizes an inserted [ATTN] symbol to gather history representations word by word (see Figure 1b). To facilitate this process, we place all inserted [ATTN] together to construct an artificial symbol sequence AW ⁣= ⁣{\bm{A}_{W}\!=\!\{[ATTN]1,...,{}_{1},...,[ATTN]m}{}_{m}\} which has the same length as T′\bm{T}^{\prime}, as shown in Figure 3b. To be specific, the word-by-word generation flow is updated as follow:

where ai(l)\bm{a}_{i}^{(l)} indicates the ii-th vector representation of the ll-th layer for the artificial symbol sequence AW\bm{A}_{W}.

Span-by-span Generation Flow.

Different from word-by-word generation flow, span-by-span flow uses [ATTN] symbols to predict spans consecutively, as shown in Figure 3c. Formally, given a list of span boundaries B ⁣= ⁣{b1,...,b∣B∣}B\!=\!\{b_{1},...,b_{|B|}\}, we conduct the span-by-span generation flow as:

where j∈[bi,bi+1)j\in[b_{i},b_{i+1}), and aj(l)\bm{a}_{j}^{(l)} denotes the (j−bi)(j-b_{i})-th vector representation of the ii-th span. Essentially, the model is trained to predict a whole span {tbi,...,tbi+1−1}\{t_{b_{i}},...,t_{b_{i+1}-1}\} with the same history context [S,t<bi]\left[\bm{S},\bm{t}_{<b_{i}}\right]. Instead of randomly sampling spans, we prefer sampling spans with semantical information and knowledge. Specifically, we consider the following two steps to sample spans consecutively in T′\bm{T}^{\prime}:

Firstly, we implement a T-test to compute t-statistic scores of all bigrams and trigrams, which is based on an initial hypothesis H0H_{0}: a random span of nn arbitrary words w ⁣= ⁣{w1,...,wn}\bm{w}\!=\!\{w_{1},...,w_{n}\} with probability p′(w) ⁣= ⁣∏i=1np(wi)p^{\prime}(\bm{w})\!=\!\prod_{i=1}^{n}p(w_{i}) cannot be a statistical nn-gram. The t-statistic score is calculated by (p(w)−p′(w))σ2/N{\frac{(p(\bm{w})-p^{\prime}(\bm{w}))}{\sqrt{\sigma^{2}/N}}}, where p(w) ⁣= ⁣Count(w)Np(\bm{w})\!=\!\frac{\texttt{Count}(\bm{w})}{N} and σ2 ⁣ ⁣= ⁣p(w)(1−p(w))\sigma^{2}\!\!=\!p(\bm{w})(1-p(\bm{w})), indicating the statistic probability and the standard deviation of w\bm{w} respectively, NN denotes the total number of nn-grams appearing in the training data. According to the t-statistic scores, we select the top 200,000 bigrams, top 50,000 trigrams and all unigrams to construct a specific vocabulary of spans, which is represented as Vspan\bm{V}_{span}.

Secondly, we search the trigram, bigram and unigram in order, starting with current word until a span (nn-gram, n≤3n\leq 3) is retrieved in Vspan\bm{V}_{span}.

Multi-Flow Attention.

To integrate the word-by-word generation flow and span-by-span generation flow, we apply them in parallel with a shared contextual flow by leveraging the multi-flow attention architecture, as Figure 3a describes. The multi-flow attention is computed as:

where X\bm{X} denotes the concatenation of S\bm{S} and T′\bm{T}^{\prime}, X(l)\bm{X}^{(l)} is the vector sequence of the ll-th layer for the contextual flow. AW(l)\bm{A}_{W}^{(l)}, AS(l)\bm{A}_{S}^{(l)} are vector sequences of the ll-th layer for the word-by-word and span-by-span generation flow respectively. As shown in Figure 3d, attention mask matrix MM determines whether query and key can attend to each other by modifying the attention weight W ⁣ ⁣= ⁣softmax(QKTdk+M)W\!\!=\!\texttt{softmax}(\frac{QK^{T}}{\sqrt{d_{k}}}+M) Vaswani et al. (2017) . Specifically, MM is assigned as:

While training, we add the loss of the word-by-word and span-by-span generation flow with an coefficient λ\lambda:

where T\bm{T} indicates the unnoised target sequence, and L(⋅)\mathcal{L}(\cdot) denotes the cross entropy loss function. In detail, we set λ=0.5\lambda=0.5 and λ=1.0\lambda=1.0 respectively in pre-training and fine-tuning.

4 Inference: Infilling Decoding

During inference, the target sequence T\bm{T} is unknown, we insert symbol [ATTN] step by step to gather the representation of history context instead of preparing an artificial symbol sequence A\bm{A} in advance. Meanwhile, for the purpose of efficiency, we need to drop the inserted [ATTN] after inference at each step, as detailed in Figure 4.

Experiments

In this section, we compare our ERNIE-GEN with previous works and conduct several ablation experiments to assess the performance of proposed methods in §3.

Analogous to BERT and UNILM, ERNIE-GEN is trained on English Wikipedia and BookCorpus Zhu et al. (2015), totaling 16GB. We also pre-train ERNIE-GEN on larger scaled text corpora, which is specifically described in appendix A. The input sequence is lowercased and truncated to a maximum length of 512. We train a base model ERNIE-GENBASE (LL=12, HH=768, AA=12, Total Parameters=110M)We donate the number of layers as LL, the hidden size as HH and the number of self-attention heads as AA. and a large model ERNIE-GENLARGE (LL=24, HH=1024, AA=16, Total Parameters=340M) with parameters initialized by BERTBASE and BERTLARGE respectively. Specifically, Adam optimizer with β1=0.9,β2=0.999,ϵ=10−9\beta_{1}=0.9,\beta_{2}=0.999,\epsilon=10^{-9} is employed. The peak learning rate is 5e-5 with warmup over the first 4,000 steps and linear decay scheduling. The noising rate ρp\rho_{p} for pre-training is 0.05. Batches are organized by limiting the maximum number of tokens to 196,608. Pre-training experiments are carried out on PaddlePaddle platformshttps://github.com/PaddlePaddle/Paddle and Nvidia Tesla V100 GPU. By virtue of float16 mixed precision training, it takes almost 4 days for 400,000 steps to train ERNIE-GENBASE while almost 7 days for 450,000 steps to train ERNIE-GENLARGE.

2 Fine-tuning on Downstream Tasks

aims at generating fluent and concise summaries without being constrained to extracting sub-sequences from the input articles. We execute experiments on Gigaword dataset Rush et al. (2015) and CNN/D-ailyMail dataset Hermann et al. (2015). Gigaword dataset contains 3.8M articles extracted from the Gigaword corpus, while CNN/DailyMail dataset consists of 93k articles and 220k articles from the CNN and Daily Mail respectively.

The results on Gigaword task with two scales (10k and 3.8M) are presented in Table 2, and the fine-tuning settings are shown in Table 1. On the low-resource task (Gigaword 10k), ERNIE-GENLARGE yields a gain of +1.94+1.94 ROUGE-L compared with UNILMLARGE. On the full training set, ERNIE-GENLARGE creates the state-of-the-art results, outperforming various previous methods. Specifically, ERNIE-GENBASE outperforms PEGASUS (568M and 750G) by using only 110M parameters and 16G training data.

Table 3 shows the performance on CNN/DailyMail. With a similar amount of pre-training data and parameters, ERNIE-GENBASE outperforms MASS by +0.67+0.67 ROUGE-L scores. Fairly compared with UNILMLARGE, ERNIE-GENLARGE obtains substantial gain of +0.73+0.73 ROUGE-L scores. Meanwhile, in spite of small pre-training data and parameters, our large model also achieves state-of-the-art result on ROUGE-L and comparable performance on ROUGE-1/2.

Question Generation

is to generate a question according to a given input passage and a corresponding answer. We evaluate on the SQuAD 1.1 dataset Rajpurkar et al. (2016) for question generation task (called SQuAD QG). Following UNILM, we redistribute the original dataset into a new training set and testing set with the original development set unchanged. We also conduct experiment with the reversed dev↔\leftrightarrowtest split as Zhao et al. (2018) indicates. In Table 4, we present the results of ERNIE-GEN and several previous works. Again, ERNIE-GEN outperforms UNILMLARGE and achieves a new state-of-the-art result on question generation by giving +1.82+1.82 BLEU-4 scores.

Generative Question Answering / Dialogue Response

in multi-turn conversations are challenging because of complex background knowledge and diverse utterances. We conduct an experiment on Persona-Chat dataset Zhang et al. (2018) to generate responses according to given multi-turn conversations and persona profile. Table 5 shows that ERNIE-GEN outperforms current task-specific pre-training model on dialogue generation. Beside, we also execute an experiment on CoQA dataset Reddy et al. (2019) to generate free-form answers for input questions and conversations. As shown in Table 6, our generative question answering model works considerably better than early works by +2.0+2.0 F1-scores.

3 Ablation Studies

To better understand the importance of each proposed generation methods, we conduct experiments concerning the following two aspects:

The robustness of infilling generation mechanism and noise-aware generation method against the exposure bias.

The effectiveness of span-by-span generation task and the complete ERNIE-GEN model.

In Table 8, we compare two ERNIE-GENBASE variants that are pre-trained with typical generation mechanism and infilling generation mechanism and that generate word by word. Row 1-3 shows that without noising groundtruth texts, infilling generation outperforms typical generation across tasks. Furthermore, both variants achieve remarkable improvements by fine-tuning with noise-aware generation method (row 4-6). Specifically, Figure 5a shows the results with diverse choices of noising rate ρf\rho_{f} on two tasks, indicating that appropriate noising substantially benefits the training and alleviates the training-inference discrepancy. To further analyze the excellence of infilling generation mechanism with noising, we compute the average attention weights of source tokens, unnoised target tokens and noised target tokens in the last self-attention layer respectively on 1,000 samples. Average attention weights with diverse noising rate ρf\rho_{f} are shown in Figure 5b, which tells us that the model pays more attention on the decoder side to figure out noised points and assign them less attention weights as the noising rate ρf\rho_{f} increased in fine-tuning. Thereby, the model is able to detect and ignore the false predictions properly to alleviate accumulating mistakes while inference.

In column 1 of Table 7, we compare four base size variants on three tasks. We see that noise-aware generation method and span-by-span generation task (rows 2-3 of Table 7) play an important role in ERNIE-GEN pre-training and significantly outperform the baseline model which is only pre-trained with word-by-word infilling generation flow (row 4 of Table 7). After integrating noise-aware generation method and span-by-span generation task, ERNIE-GEN boosts the performance across all three tasks, as shown in row 1 of Table 7. In addition, UNILM is fine-tuned by masking words in the encoder and decoder to predict, which is also a case of noising for generation. To verify the idea that fine-tuning with masking language modeling like UNILM is inefficient due to the coupling of masking (noising) and predicting that only the masked (noised) position will be learned, we also list the fine-tuning results obtained by predicting masked words with masking probability of 0.7, as shown in column 2 of Table 7. We observe that our noise-aware generation method significantly outperforms the mask language modeling in seq2seq fine-tuning by predicting all words in the decoder side.

Conclusions

We present an enhanced multi-flow seq2seq pre-training and fine-tuning framework named ERNIE-GEN for language generation, which incorporates an infilling generation mechanism and a noise-aware generation method to alleviate the exposure bias. Besides, ERNIE-GEN integrates a new span-by-span generation task to train the model to generate texts like human writing, which further improves the performance on downstream tasks. Through extensive experiments, ERNIE-GEN achieves state-of-the-art results on a range of NLG tasks. Future work includes incorporating reinforcement learning into pre-training for exposure bias and applying ERNIE-GEN to more NLG tasks such as machine translation.

Acknowledgments

This work was supported by the National Key Research and Development Project of China (No. 2018AAA0101900).

References

Appendix A Appendix

Recent works for pre-training verify that larger scaled pre-training corpora can improve the performances on downstream tasks. We pre-train ERNIE-GENLARGE model on the 430GB text corpora with 1 epoch and 1M training steps. Our 430GB text corpora is extracted from the corpus used by RoBERTa Liu et al. , T5 Raffel et al. and ALBERT Lan et al. . We fine-tune ERNIE-GENLARGE on two abstractive summarization datasets including Gigaword and CNN/Daily Mail, the evaluation results are reported in Table 9. Notice that the performance increase significantly as ERNIE-GENLARGE pre-trains on larger scaled text corpora.

We also fine-tune ERNIE-GEN on the SQuAD 1.1 dataset for question generation task, the results are presented in Table 10. We observe that larger scaled pre-training corpora can slightly improve the Rouge-L score and BLEU-4 score for the SQuAD dataset.

The fine-tuning hyperparameters of ERNIE-GEN‡LARGE\ddagger_{LARGE} are presented in Table 11.