Efficient Automatic Punctuation Restoration Using Bidirectional Transformers with Robust Inference (2020)

Abstract: Though people rarely speak in complete sentences, punctuation confers many benefits to the readers of transcribed speech. Unfortunately, most ASR systems do not produce punctuated output. To address this, we propose a solution for automatic punctuation that is both cost efficient and easy to train. Our solution benefits from the recent trend in fine-tuning transformer-based language models. We also modify the typical framing of this task by predicting punctuation for sequences rather than individual tokens, which makes for more efficient training and inference. Finally, we find that aggregating predictions across multiple context windows improves accuracy even further. Our best model achieves a new state of the art on benchmark data (TED Talks) with a combined F1 of 83.9, representing a 48.7% relative improvement (15.3 absolute) over the previous state of the art.

## introduction enabling computers to use speech as input has long been an aspirational goal in the field of human computer interaction. recent advances have had dramatic impact across multiple domains (e.g. relieving medical professionals from having to transcribe medical dictation @xcite , improving real-time spoken language translation @xcite , and affording convenience through conversational interfaces like those in virtual personal assistants @xcite ). for use cases that require reading transcribed speech, however, it is often still a challenge to recover meaningful clause boundaries from disfluent, errorful utterances. humans rely on punctuation for readability, perhaps because it lessens the burden of ambiguous phrasing. studies have found that removing punctuation from manual transcriptions can be even more detrimental to understanding than a word error rate of 15% or 20% @xcite . reading comprehension is also significantly slower without punctuation @xcite . for downstream nlp models, the lack of clausal boundaries can significantly decrease accuracy (e.g. a 4.6% bleu decrease in nmt; @xcite . this likely reflects the discrepancy between wellsegmented training corpora and asr output. to solve the lack of punctuation in asr output, we propose an automatic punctuation model, which leverages the recent trend in unsupervised pre-training @xcite and the parallel architecture of transformer networks @xcite . unsupervised pre-training dramatically reduces the amount of labeled data required for superior performance on this task. additionally, the model's departure from a recurrent architecture allows direct connections between all input tokens. this enables the network to more easily model longdistance dependencies (e.g. on one hand, ... on the other, ...) for improved punctuation performance. the departure from a recurrent architecture also allows computations to be performed in parallel for each layer with the speed of computations limited by the number of layers rather than the number of time steps (usually fewer). in addition to the parallel nature of the hidden layers, our network also predicts in parallel for all tokens in the input simultaneously. this helps significantly speed up inference compared with individual predictions for each token. during training, the parallel prediction task provides a richer signal compared with a sequential task, thereby making more efficient use of each example. furthermore, advancing the prediction window less than the window's width (e.g. steps of 20 with a window of 50) allows aggregating multiple windows of context to predict a token's label. this allows the network to effectively become its own prediction ensemble and boosts accuracy further. given that the aggregate predictions are independently obtained, these calculations too can be performed in parallel. ## related work our biggest departure from previous approaches lies in the parallel nature of inference and the deep bidirectional information flow of our model (for more detail, see @xcite . this is in contrast with the vast majority of previous approaches which use a variant of recurrent neural network architecture @xcite @xcite @xcite @xcite @xcite @xcite @xcite . this includes those that incorporate acoustic information (b. @xcite @xcite @xcite @xcite and those that apply attention on top @xcite @xcite @xcite . though non-sequential, several previous approaches use simpler network architectures (e.g. dnns @xcite or cnns (b. @xcite @xcite ), which have less predictive power. the handful of approaches that make use of transformer architectures are not bidirectional @xcite @xcite . our model also differs from the above in that it leverages pretraining to reduce training time and increase accuracy. the one previous work that uses a pretrained bidirectional transformer @xcite ) only predicts punctuation one token at a time, which significantly increases both training and inference time. it is also unable to aggregate predictions across multiple contexts, limiting performance. the first component of our network is a pre-trained language model (roberta base ; @xcite ) employing the recent deep bidirectional transformer architecture @xcite . the network's input is a sequence of unpunctuated lowercased words tokenized using roberta's tokeniza-tion scheme (see @xcite for more details). we then add two additional linear layers after the pre-trained network with each layer preserving the fully-connected nature of the entire network. the first linear layer maps from the masked language model output space to a hidden state space for each input token with parameters shared across tokens. the second linear layer concatenates the hidden state representations into a vector for the prediction window which allows the tokens to interact arbitrarily within the window. we then apply batch normalization (ioffe and szegedy, 2015) and dropout (best results obtained with a rate of 0.2; @xcite prior to predicting punctuation marks for all tokens in the window. when aggregating predictions across contexts, activations at the sequence layer are added for each token prior to classification (see figure 1 for visualization). prediction is performed in parallel during both training and inference with the output size of the final classifier being |classes| * length window . vocab ids vocabulary distributions (before fine-tuning) hidden token vectors concatenate batch norm and dropout linear classifier layer linear layer hidden sequence vector normalized sequence vector sequence distributions pre-trained lm aggregate across contexts punctuation labels o n+1 t n+1 t 2 tn o 2 on ... y n+1 advance sliding window and repeat for new context... figure 1 : the punctuation network takes as input a sequence of unpunctuated words tokenized in the same manner as roberta. it outputs predictions for these sequences individually during training (layer o n ). for validation and testing, however, these labels are aggregated across overlapping context windows to obtain the final punctuation predictions (layer y n ). note that while the pre-trained lm's output begins as vocabulary distributions, they cease to be so once the entire network undergoes fine-tuning. training schedule it is worth noting that we use only the ted talks dataset described below for training but enjoy significant benefits from a sizable pre-training corpus @xcite . although prediction is performed on multiple tokens at once, the same number of training samples are generated from the corpus by moving the sliding window one token at a time over the input. to perform gradient descent, we use lookahead @xcite with radam @xcite as the base optimizer. we use a simple cross-entropy function to calculate the loss for each token's classification prediction. our best performing model (see we train the top layers for nine epochs with a mini-batch size of 1000 (using 100-token sequences) while the transformer is frozen. the lowest validation loss for the top layers is usually achieved around the sixth epoch. we then unfreeze the transformer and fine-tune the entire network for three more epochs with a mini-batch size of 250. we typically observe the lowest validation loss midway through the first epoch while fine-tuning. it is worth noting that a highly competitive model (82.6 overall f1) can be trained with just 1 epoch each for the top layers and fine-tuning. this training can be completed in slightly less than 1 hour on a p3.16xlarge aws instance (with 8x tesla v100 gpus). for the lookahead optimizer, we use a sync rate of 0.5, and a sync period of 6. the radam optimizer-used as the model's base optimizerhas its learning rate set to 10 -5 , β 1 = 0.9, β 2 = 0.999, = 10 -8 . we do not use weight decay. data to train the network and evaluate its performance (both at test and validation time), we use the iwslt 2012 ted talks dataset @xcite . this dataset is a common benchmark in automatic punctuation (e.g. kim 2019) and consists of a 2.1m word training set, a 296k word validation set, and a 12.6k word test set (for reference transcription, 12.8k for asr output). each word is labeled with the punctuation mark that follows it, yielding a 4-class classification problem: comma, period, question mark, or no punctuation. the class balance of the training dataset is as follows: 85.7% no punctuation, 7.53% comma, 6.3% period, 0.47% question mark. ## results the results of our best performing model relative to previous results published on this benchmark can be found in in place of the pre-trained roberta base language model, which provided the best result, we also evaluated (in order of decreasing performance relative to roberta as implemented by @xcite al. (2020) @xcite ). full results from these models can be seen at the bottom of in addition to the lookahead optimizer using radam as its base, we also evaluated: lookahead with adam (-1.5%), radam alone (-1.6%), and adam alone (-2.9%; kingma and ba 2017). given the class imbalance inherent in the dataset between the no punctuation class and all the punctuation marks, we tested focal loss @xcite , class weighting, and their combination, but found that none outperformed simple cross-entropy loss. perhaps the most noteworthy result is the comparison between parallel prediction (described above) and sequential prediction, wherein the forward pass predicts punctuation for one token at a time using a context window centered on that token. sequential prediction requires longer inference times (>15x) yet yields only a marginal performance benefit (2.2%) relative to a parallel prediction without aggregation across multiple contexts. ensembling predictions over multiple contexts overcomes the performance gap, while retaining an advantage with respect to inference time. compared to the self-ensemble approach, sequential prediction @xmath0.4% less accurate. a less obvious choice must be made between a single parallel prediction and multiple aggregated predictions, given the additional runtime of multiple predictions (see in addition to the roberta base model whose results are reported here, we also trained with a roberta large model. there was no appreciable performance difference between the two sizes (the large being -0.4% worse) however the large model incurred a significant slowdown (≈1.5x). this may imply that the base model size is adequately powered for punctuation tasks, at least on manually transcribed english datasets similar to the benchmark. this is supported by the findings of @xcite , who found bert base to be overparameterized for most downstream tasks, implying roberta large would be extremely overparameterized. a smaller pre-trained language model option is distilroberta, a knowledge distilled version of roberta (analogous to distilbert: sanh et al. 2020). the distilroberta network is 12% smaller and performs inference ≈1.2x faster, but sacrifices 9.1% in accuracy on the benchmark. the previous state of the art approach was a multi-headed attention network on top of multiple stacked bidirectional gru layers @xcite . given the recurrent nature of the gru layers, the network is subject to the shortcomings of sequential computation discussed in the introduction. our findings illustrate yet another language task where transformers outperform previous recurrent neural network approaches. our approach enjoys a 48.7% relative improvement (15.3 absolute) over the previous state of the art @xcite . given the ablation results presented above, we attribute the performance gains to the deeply bi-directional transformer architecture, the benefit of leveraging roberta's pre-trained language model trained on ≈ 33b words, and the aggregation of multiple prediction contexts for robust inference. some performance gain may also be attributed to the addition of an encoding layer trained solely on the punctuation task. one of the more notable findings is that the nonrecurrent nature of the entire network allows for a large degree of parallelization resulting in a more competitive runtime compared to previous recurrent approaches. while source code was not openly available for benchmarking runtime against @xcite , we did compare against a similar approach from tilk and alumäe (2016) foot_1 , which was roughly 78.8x slower on gpus and 1.2x slower on a cpu, when evaluating the ted talks test set. the results presented here have not benefited from any rigorous hyperparameter tuning (e.g. grid search or bayesian optimization). we leave that to future work given that a rigorous systematic approach may yield appreciable improvements in accuracy. ## conclusion we have presented a state of the art automatic punctuation system which aggregates multiple prediction contexts for robust inference on transcribed speech. the use of multiple prediction contexts, unsupervised pre-training, and increased parallelism makes it possible to achieve significant performance gains without increased runtime or cost. on a different dataset, @xcite reported human agreement of around 76% for punctuation location and 70% for use of the same punctuation mark. although we have yet to make a direct comparison, it's possible our model is already competitive with human performance on this task. future work will explore how this performance