SlowGuess/NAACL_2021_OCR huggingface dataset:
Bowen Tan $^{1}$ , Zichao Yang $^{1}$ , Maruan Al-Shedivat $^{1}$ , Eric P. Xing $^{1,2,3}$ , Zhiting Hu $^{1,4}$
$^{1}$ Carnegie Mellon University,  $^{2}$ Petuum Inc.,  $^{3}$ MBZUAI,  $^{4}$ UC San Diego
{btan2, zichaoy, alshedivat, epxing}@andrew.cmu.edu, zhh019@ucsd.edu
Large-scale language models (LMs) pretrained on massive corpora of text, such as GPT-2, are powerful open-domain text generators. However, as our systematic examination reveals, it is still challenging for such models to generate coherent long passages of text (e.g., 1000 tokens), especially when the models are fine-tuned to the target domain on a small corpus. Previous planning-then-generation methods also fall short of producing such long text in various domains. To overcome the limitations, we propose a simple but effective method of generating text in a progressive manner, inspired by generating images from low to high resolution. Our method first produces domain-specific content keywords and then progressively refines them into complete passages in multiple stages. The simple design allows our approach to take advantage of pretrained LMs at each stage and effectively adapt to any target domain given only a small set of examples. We conduct a comprehensive empirical study with a broad set of evaluation metrics, and show that our approach significantly improves upon the fine-tuned large LMs and various planning-then-generation methods in terms of quality and sample efficiency. Human evaluation also validates that our model generations are more coherent.<sup>1</sup>
Generating coherent long text (e.g., 1000s of tokens) is useful in myriad applications of creating reports, essays, and other long-form content. Yet the problem is particularly challenging as it demands models to capture global context, plan content, and produce local words in a consistent manner. Prior studies on "long" text generation have typically limited to outputs of 50-200 tokens (Shen et al., 2019; Bosselut et al., 2018; Zhao et al., 2020).
Figure 1: Results of large-scale LMs (GPT-2 and BART) fine-tuned on 10K stories. Coherence of text is evaluated by BERT next sentence prediction (NSP) score, where x-axis is the position of the evaluated sentences in the passage. There is a significant gap in coherence between text by human and text by large-scale LMs. Our proposed ProGen instead generates more coherent samples close to human text.
Recent large-scale pretrained language models (LMs), such as GPT-2 (Radford et al., 2019) and BART (Lewis et al., 2020), emerged as an impressive open-ended text generator capable of producing surprisingly fluent text. The massive LMs are typically pretrained on large corpora of generic text once, and then fine-tuned with small domain-specific data. The latest work has mostly focused on the regime of relatively short text with low hundreds of tokens. For example, Holtzman et al. (2020); See et al. (2019); Hua and Wang (2020) studied GPT-2 and BART generations with a maximum length ranging from 150 to 350 tokens. In this work, we study the problem of generating coherent, much longer passages of text (e.g., 1000 tokens). GPT-3 (Brown et al., 2020) was reported to produce long essays, yet the results seem to need extensive human curations (e.g., MarketMuse; Gardian), and the system is not publicly available to adapt to arbitrary desired domains.
In this work, we examine fine-tuning of large-scale LMs for domain-specific generation of extra
$^{1}$ Code available at https://github.com/tanyuqian/progressive-generation
Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, pages 4313-4324. June 6-11, 2021. ©2021 Association for Computational Linguistics
long text. We find that samples produced by GPT-2 fine-tuned on small domain-specific corpora exhibit various imperfections, including excessive repetitiveness and incoherence between sentences far apart. Figure 1 measures the coherence of text generated by the fine-tuned GPT-2 w.r.t the BERT next sentence prediction (Devlin et al., 2019) score. As the figure shows, GPT-2 models (regardless of the model size) exhibit a significant gap in the score compared with human text, hence falling short in generating coherent text.
We hypothesize that the problem is mainly caused by the sequential generation order of the LMs, which makes global content planning of the passage difficult, especially when the generated text is long and contains thousands of words. One could potentially adopt the recent planning-then-generation or non-monotonic methods (Sec 2), yet those methods either require specialized neural architectures that need costly retraining for each domain (Gu et al., 2019; Stern et al., 2019; Chan et al., 2019; Fan et al., 2019), or rely on dedicated intermediate content plans (e.g., summaries, SRL labels) (Fan et al., 2019; Yao et al., 2019) with limited flexibility and producing sub-optimal results as shown in our experiments.
To overcome the limitations, we introduce a new method for Progressive Generation of Text (ProGen). We observe that generation of some words (e.g., stop words) does not require many contexts, while other words are decisive and have long-term impact on the whole content of the passage. Motivated by this observation, our approach first produces a sequence of most informative words, then progressively refines the sequence by adding finer-grained details in multiple stages, until completing a full passage. The generation at each stage is conditioning on the output of the preceding stage which provides anchors and steers the current generation (Figure 2). The intermediate words produced at each stage are defined based on a simple TF-IDF informativeness metric.
The approach enjoys several core advantages: (1) Although the progressive approach implements a conceptually non-monotonic generation process, generation at each stage can still be performed in a left-to-right manner and thus is directly compatible with the powerful pretrained monotonic LMs. The LMs at different stages are easily fine-tuned to accommodate a target domain using only small, independently constructed data. Intuitively, each LM
is addressing a sub-task of mapping a sequence to a finer-resolution one, which is much simpler than the overall task of mapping from conditions to full passages of text. In this work, we use BART (Lewis et al., 2020) for generation at each stage, though one can also plug in other off-the-shelf LMs. As seen from Figure 1, ProGen can generate more much coherent text compared with GPT-2 and nearly match human text in terms of the BERT-NSP score; (2) In contrast to the typical 2-stage planning-then-generation in prior work, the simple progressive strategy offers added flexibility for an arbitrary number of intermediate stages, yielding improved results; (3) The training data for each stage is extracted from domain corpus using the simple TF-IDF metric, without need of additional resources (e.g., pretrained summarization models) as in prior work, making the method broadly applicable to various domains and languages.
We conduct extensive empirical studies on the CNN News (Hermann et al., 2015) and Writing-Prompts (Fan et al., 2018) corpora, evaluating various systems by a wide-range of automatic metrics as well as human judgement. Results show that ProGen achieves strongly improved performance by decomposing the generation into more progressive stages. Our method produces diverse text passages of higher quality and coherence than a broad set of models, including fine-tuned GPT-2, BART, and other various planning-then-generation strategies.
Content planning in generation. The idea of separate content planning and surface realization has been studied in early text generation systems (Reiter and Dale, 1997). Recent neural approaches have also adopted similar planning-then-generation strategies for data-to-text (Moryossef et al., 2019; Puduppully et al., 2019), storytelling (Fan et al., 2019; Yao et al., 2019; Xu et al., 2020), machine translation (Ford et al., 2018), and others (Hua and Wang, 2019; Yao et al., 2017). These models often involve customized architectures incompatible with the existing large LMs. Scaling those models for long text generation thus can require expensive training, which restricts systematic studies. On the other hand, it is possible to adopt some of the content planning strategies (e.g., summaries or SRL sequences as the plans (Fan et al., 2019)), and repurpose pretrained LMs for generation in each stage. However, these strategies
with dedicated intermediate plans and a pre-fixed number (typically 2) of stages can have limited flexibility, leading to sub-optimal results as shown in our empirical study. Besides, creating training data for planning requires additional resources (e.g., pretrained summarization models or SRL models) which are not always available (e.g., in certain domains or for low-resource languages). In contrast, we propose a simple way for designing the intermediate stages based on word informativeness, which can flexibly increase the number of stages for improved results, and easily create training data for all stages without additional models.
Non-monotonic generation and refinement. Another relevant line of research is non-monotonic generation (Welleck et al., 2019; Gu et al., 2019; Stern et al., 2019; Chan et al., 2019; Zhang et al., 2020), infilling (Zhu et al., 2019; Shen et al., 2020; Qin et al., 2020), or refinement (Lee et al., 2018; Novak et al., 2016; Mansimov et al., 2019; Kasai et al., 2020) that differs from the restricted left-to-right generation in conventional LMs. Again, those approaches largely depend on specialized architectures and inference, making them difficult to be integrated with the powerful pretrained LMs. The prior studies have focused on generating short text. Our proposed coarse-to-fine progressive generation conceptually presents a non-monotonic process built upon the pretrained monotonic LMs, which permits fast adaptation to any target domain and generation of much longer text.
Long text generation. Previous work has made attempts to generate text of up to two or three hundred tokens. Those methods often adopt the similar idea of planning-then-generation as above (Shen et al., 2019; Zhao et al., 2020; Bosselut et al., 2018; See et al., 2019; Hua and Wang, 2020; Rashkin et al., 2020). Another line of work instead focuses on extending the transformer architecture (Vaswani et al., 2017) to model longer text sequences (e.g., Dai et al., 2019; Wang et al., 2020; Choromanski et al., 2021, etc). For example, Liu et al. (2018) used a hybrid retrieval-generation architecture for producing long summaries; Dai et al. (2019) showed long text samples qualitatively. Our work systematically examines the pretrained LMs in generating long domain-specific text, and proposes a new approach that empowers pretrained LMs for producing samples of significantly higher-quality.
3 Progressive Generation of Text
One of the main challenges in generating long coherent passages is modeling long-range dependencies across the entire sequences (e.g., 1000 tokens). We propose a progressive generation approach that is conceptually simple yet effective. Intuitively, progressive generation divides the complex problem of generating the full passage into a series of much easier steps of generating coarser-grained intermediate sequences. Contrary to generating everything from left to right from scratch, our progressive generation allows the model to first plan globally and then shift attention to increasingly finer details, which results in more coherent text. Figure 2 illustrates the generation process.
3.1 Generation Process
Let  $\mathbf{y} \coloneqq [y_1, y_2, \ldots, y_T]$  be the output text, where each  $y_i$  is a token of language (a word or a subword). The output sequences are generated either conditionally on any other information  $\mathbf{x}$  (e.g., generations of a story given a prompt), or unconditionally (in which case we assume  $\mathbf{x} \equiv \emptyset$  while keeping the same notation).
Instead of generating the full passage  $\mathbf{y}$  directly, we propose to add multiple intermediate stages:  $\mathbf{x} \rightarrow \mathbf{c}_1 \rightarrow \mathbf{c}_2 \dots \rightarrow \mathbf{c}_K \rightarrow \mathbf{y}$ , where for each stage  $k \in \{1, \ldots, K\}$ ,  $\mathbf{c}_k$  is an intermediate sequence containing information of the passage at certain granularity. For instance, at the first stage,  $\mathbf{c}_1$  can be seen as a highest-level content plan consisting of the most informative tokens such as key entities. Then, based on the plan, we gradually refine them into subsequent  $\mathbf{c}_k$ , each of which contains finer-grained information than that of the preceding stage. At the final stage, we refine  $\mathbf{c}_K$  into the full passage by adding the least informative words (e.g., stop words). The generation process corresponds to a decomposition of the conditional probability as:
$$
\begin{array}{l} \mathbb {P} \left(\mathbf {y}, \left\{\mathbf {c} _ {k} \right\} | \mathbf {x}\right) = \mathbb {P} \left(\mathbf {c} _ {1} | \mathbf {x}\right) \\ \Pi_ {k = 2} ^ {K} \mathbb {P} \left(\mathbf {c} _ {k} | \mathbf {c} _ {k - 1}, \mathbf {x}\right) \mathbb {P} \left(\mathbf {y} | \mathbf {c} _ {K}, \mathbf {x}\right). \tag {1} \\ \end{array}
$$
As the above intuition,  $\mathbf{c}_k$  at early stages as the high-level content plans should contain informative or important words, to serve as skeletons for subsequent enrichment.
We next concretely define the order of generation, namely, which words should each stage generate. Specifically, we propose a simple method
Figure 2: Progressive generation of long text y given any condition x. Each stage refines the results from the previous stage by adding finer-grained details. Added content at each stage is highlighted in different colors.
that constructs a vocabulary  $\mathcal{V}_k$  for each stage  $k$ , based on the importance of words in the target domain. Each particular stage  $k$  only produces tokens belonging to its vocabulary  $\mathcal{V}_k$ . By the progressive nature of the generation process, we have  $\mathcal{V}_1 \subset \dots \subset \mathcal{V}_K \subset \mathcal{V}$ . That is,  $\mathcal{V}_1$  contains the smallest core set of words in the domain, and the vocabularies gradually expand at later stages until arriving the full vocabulary  $\mathcal{V}$ . Note that vocabularies in later stages are supersets of those in earlier stages. This allows the later stages to remedy and polish potential mistakes made in earlier stages when necessary. We discuss the construction of the vocabularies in the below.
Stage-wise vocabularies based on word importance. Given a text corpus  $\mathcal{D}$  of the target domain with the full vocabulary  $\nu$ , we define the importance scores of words in  $\nu$  based on the TF-IDF metric. We then rank all the words and assign the top  $V_{k}$  words to the intermediate vocabulary  $\nu_{k}$ . Here  $V_{k}$  is a hyper-parameter controlling the size of  $\nu_{k}$ .
More concretely, for each word  $w \in \mathcal{V}$ , we first compute its standard TF-IDF score (Salton and McGill, 1986) in each document  $\mathbf{d} \in \mathcal{D}$ , which essentially measures how important  $w$  is to  $\mathbf{d}$ . The importance of the word  $w$  in the domain is then defined as the average TF-IDF score across all documents containing  $w$ :
$$
\operatorname {i m p o r t a n c e} (w, \mathcal {D}) = \frac {\sum_ {\mathbf {d} \in \mathcal {D}} \operatorname {T F} _ {-} \operatorname {I D F} (w , \mathbf {d})}{\operatorname {D F} (w , \mathcal {D})}, \tag {2}
$$
where  $\mathrm{TF\_IDF}(w,\mathbf{d})$  is the TF-IDF score of word  $w$  in document  $\mathbf{d}$ ; and  $\mathrm{DF}(w,\mathcal{D})$  is the document
Algorithm 1 Training for Progressive Text Generation
Domain corpus  $\mathcal{D}$
Vocabulary sizes for  $K$  stages
$K$  pretrained LMs (e.g. GPT-2 or BART)
1: Construct stage-wise vocabularies  $\{\mathcal{V}_k\}$  based on word importance Eq.(2)
2: Extract intermediate sequences  $\{\mathbf{c}_k^*\}$  using  $\{\mathcal{V}_k\}$ ; add data noises (Sec 3.2)
3: Fine-tune all LMs independently (Sec 3.2)
Output: Fine-tuned LMs for generation at all stages in a progressive manner
frequency, i.e., the number of documents in the corpus that contain the word  $w$ .
Pretrained language models as building blocks.
Compared to many of the previous planning-then-generation and non-monotonic generation methods, one of the key advantages of our progressive generation design is the direct compatibility with the powerful pretrained LMs that perform left-to-right generation. Specifically, although our approach implements a non-monotonic generation process that produces importance words first, we can generate intermediate sequences  $\mathbf{c}_k$  at each stage still in a left-to-right manner. Thus, we can plug pretrained LM, such as GPT-2 or BART, into each stage to carry out the generation. As described more in section 3.2, for each stage  $k$ , we can conveniently construct stage-specific training data from the domain corpus  $\mathcal{D}$  using the stage-wise vocabulary  $\nu_{k}$ , and fine-tune the stage- $k$  LM in order to generate intermediate sequences at the stage that are pertaining to the target domain.
One can add masks on the pretrained LM's to
ken distributions to ensure the stage- $k$  LM only produces tokens belonging to  $\mathcal{V}_k$ . In practice, we found it is not necessary, as the pretrained LM can usually quickly learn the pattern through fine-tuning and generate appropriate tokens during inference. In our experiments we use BART for all stages, since BART is an encoder-decoder model which can conveniently take as inputs the resulting sequence from the preceding stage and generate new. (For the first stage in an unconditional generation task, we simply set  $\mathbf{x} = \varnothing$ .) We note that GPT-2, and other relevant pretrained LMs, can indeed also be used as a conditional generator (Radford et al., 2019; Liu et al., 2018) and thus be plugged into any of stages.
Our approach permits straightforward training/finetuning of the (pretrained) LMs at different stages given the domain corpus  $\mathcal{D}$ . In particular, we can easily construct independent training data for each stage, and train all LMs in parallel. Note that no additional resources such as pretrained summarization or semantic role labeling models are requested as in previous work, making our approach directly applicable to a potentially broader set of domains and languages. We plan to explore the use of our method in multi-lingual setting in the future.
More concretely, for each stage  $k$ , we use the stage vocabularies  $\mathcal{V}_{k-1}$  and  $\mathcal{V}_k$  to filter all relevant tokens in the documents as training data. That is, given a document, we extract the subsequence  $\mathbf{c}_{k-1}^*$  of all tokens from the document that are belonging to  $\mathcal{V}_{k-1}$ , and similarly extract sub-sequence  $\mathbf{c}_k^*$  belonging to  $\mathcal{V}_k$ . The  $\mathbf{c}_{k-1}^*$  and  $\mathbf{c}_k^*$  are then used as the input and the ground-truth output, respectively, for training the LM at stage  $k$  with maximum likelihood learning. Therefore, given the stage-wise vocabularies  $\{\mathcal{V}_k\}$ , we can automatically extract training data from the domain corpus  $\mathcal{D}$  for different stages, and train the LMs separately.
In the multi-stage generation, the intermediate sequences are not natural language. Yet we found that fine-tuning pretrained LMs (such as BART and GPT-2) to generate the intermediate sequences is indeed very efficient in terms of data and computation. We tried training other models such as small sequence-to-sequence models and n-gram models from scratch, which we found is much harder, requiring more data, or yielding inferior performance.
This again highlights the importance of using pretrained LMs, as enabled by our simple method design.
Stage-level exposure bias and data noising. In the above training process, the outputs of each LM are conditioning on the ground-truth input sequences extracted from the real corpus. In contrast, at generation time, the LM takes as inputs the imperfect sequences produced at the previous stage, which can result in new mistakes in the outputs since the LM has never be exposed to noisy inputs during training. Thus, the discrepancy between training and generation can lead to mistakes in generation accumulating through the stages. The phenomenon resembles the exposure bias issue (Ranzato et al., 2016) of sequential generation models at token level, where the model is trained to predict the next token given the previous ground-truth tokens, while at generation time tokens generated by the model itself are instead used to make the next prediction.
To alleviate the issue and increase the robustness of each intermediate LM, we draw on the rich literature of addressing token-level exposure bias (Xie et al., 2017; Tan et al., 2019). Specifically, during training, we inject noise into the ground-truth inputs at each stage by randomly picking an  $n$ -gram  $(n \in \{1, 2, 3, 4\})$  and replacing it with another randomly sampled  $n$ -gram. The data noisings encourage the LMs to learn to recover from the mistakes in inputs, leading to a more robust system during generation.
Domains. We evaluate on two text generation domains including: (1) CNN News (Hermann et al., 2015) for unconditional generation. (2) Writing-Prompts (Fan et al., 2018) for conditional story generation. The task is to generate a story given a prompt. The two datasets are chosen since they both contain long documents, with CNN's average and maximum length being 512 and 926, and WritingPrompts's being 437 and 942, respectively. To demonstrate the data efficiency of our approaches adapting to target domains, we sample 1,000 documents in each dataset for training.
Model config. We use BARTs for all stages of generation. Due to computation limitations, we experiment models with 2, 3, 4-stages generations. In
our 2-stage model, our first stage covers about  $25\%$  of all content; in the 3-stage model, the first and second stages cover  $15\%$  and  $25\%$  of all content, respectively; and in the 4-stage model, our first three stages cover  $15\%$ ,  $20\%$ ,  $25\%$  of all content. For model training, we follow the same protocol as (See et al., 2019) to fine-tune all pretrained models until convergence. To combat exposure bias, we add noise to the training data as described in Sec 3.2, with the probability of replacing 1,2,3,4-grams  $0.1 / 0.05 / 0.025 / 0.0125$ . In the generation phase, we use top-p decoding (Holtzman et al., 2020) with  $p = 0.95$  to generate 1024 tokens at maximum. Experiments were conducted with RTX6000 GPUs. It took around 4 hours for model fine-tuning and generation with a single GPU.