{'fraction_non_alphanumeric': 0.028079710144927536, 'fraction_numerical': 0.01166213768115942, 'mean_word_length': 4.792960209881941, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 0, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
A Comparison of Techniques for Language Model Integration in Encoder-Decoder Speech Recognition

Attention-based recurrent neural encoder-decoder models present an elegant solution to the automatic speech recognition problem. This approach folds the acoustic model, pronunciation model, and language model into a single network and requires only a parallel corpus of speech and text for training. However, unlike in conventional approaches that combine separate acoustic and language models, it is not clear how to use additional (unpaired) text. While there has been previous work on methods addressing this problem, a thorough comparison among methods is still lacking. In this paper, we compare a suite of past methods and some of our own proposed methods for using unpaired text data to improve encoder-decoder models. For evaluation, we use the medium-sized Switchboard data set and the large-scale Google voice search and dictation data sets. Our results confirm the benefits of using unpaired text across a range of methods and data sets. Surprisingly, for first-pass decoding, the rather simple approach of shallow fusion performs best across data sets. However, for Google data sets we find that cold fusion has a lower oracle error rate and outperforms other approaches after second-pass rescoring on the Google voice search data set.


INTRODUCTION
Attention-based recurrent neural encoder-decoder models provide an elegant end-to-end framework for speech recognition, machine translation, and other sequence transduction tasks [1,2]. In automatic speech recognition (ASR), the model folds the traditionally separately learned acoustic model, pronunciation model, and language model (LM) into a single network that can be trained endto-end. The encoder maps the input speech to a sequence of higherlevel learned features, while the decoder maps these higher-level features to output labels with assistance from the attention mechanism that provides an alignment between speech and text. The model can be learned end-to-end and requires just paired speech and text data. Encoder-decoder models for speech recognition have become quite popular recently and perform competitively on a number of ASR tasks [3][4][5].
While end-to-end training offers several advantages, it also restricts the training data to have both input and output sequences, for example the paired speech and text data in the case of speech recognition. Conventional ASR models leverage a separate LM trained on all available text, which can be orders of magnitude larger than just the transcripts of transcribed audio. Decoder of an encoder-decoder model is exposed only to the audio transcripts.
Previous work addressing the issue of utilizing unpaired text has proposed ways of integrating an external pretrained LM, trained on all of the text data, with the ASR model [6][7][8]. The main LM integration approaches from past work have been referred to as shallow [6], deep [6], and cold fusion [7]. The three approaches differ in two important criteria: • Early/late model integration: At what point in the ASR model's computation should the LM be integrated? In deep and cold fusion, the external LM is fused directly into the ASR model by combining their hidden states, resulting in a single model with tight integration. In contrast, in shallow fusion the LM and ASR model remain separate and only their scores are combined, similarly to an ensemble. The shallow fusion score combination is also similar to the interpolation of acoustic and language models done in traditional ASR.
• Early/late training integration: At what point in the ASR model's training should the LM be integrated? Deep and shallow fusion use a late integration where both the ASR and LM models are trained separately and then combined, while cold fusion uses the external pretrained LM model from the very start of the ASR model training. An important point is that early training integration approaches are computationally costlier if either of the two models is frequently changing.
A thorough comparison between these LM integration techniques is, to the best of our knowledge, currently lacking. In this paper, we compare the three fusion approaches mentioned above on (a) the medium-sized Switchboard data set [9] and (b) the large-scale Google voice search and dictation data sets used in [5]. Our aim is to shed light on how the LM integration approaches compare, as well as how they scale up with data size. We also propose some novel LM integration approaches and compare them against the three prior fusion approaches on Switchboard.
Our results show that almost all of the LM integration approaches improve over a baseline encoder-decoder model for all data sets, confirming the benefit of utilizing unpaired text. We also make several other findings: (a) the rather simple approach of shallow fusion works best for first-pass decoding on all of our data sets, (b) our best proposed approach performs similarly to deep and cold fusion on the Switchboard data set, (c) deep fusion doesn't scale well, obtaining no or negligible gains over baseline for large-scale Google data sets, and (d) cold fusion produces high-quality and diverse beam outputs resulting in lowest oracle word error rate on Google data sets and edges ahead when coupled with second-pass LM rescoring on Google voice search.

RELATED WORK
Previous work on using unpaired text for encoder-decoder models can be categorized along two major themes: Using an external language model This approach consists of training an external LM on the unpaired text and integrating it into the encoder-decoder model, which is the focus of this paper. An early study along these lines was by Gulcehre et al. [6], who proposed the shallow and deep fusion methods in the context of neural machine translation (NMT) models. In that work both shallow and deep fusion improved performance, with deep fusion somewhat outperforming shallow fusion, especially for lowresource language pairs. Another previous work in context of NMT models by Ramachandran et al. [10] proposed initializing the lower layer of both encoder and decoder with separate pretrained LMs followed by joint training using both language modeling and machine translation losses. Shallow fusion has largely been the method of choice for ASR [3,4,8,11], getting significant performance gains, although in some cases with slight modifications to the decoding objective function [4,8,11]. Cold fusion, a modification of deep fusion, was proposed for ASR by Sriram et al. [7]. This work found that, on medium-scale data sets of ∼300-400K training utterances, cold fusion outperforms deep fusion, especially in a cross-domain setting, but did not compare with shallow fusion. None of these studies compared all three fusion approaches.
Generating paired data from unpaired text A second line of research is to use unpaired text to synthetically generate matching input sequences, thus expanding the paired data set. In machine translation this process of generating paired data from monolingual data is referred to as backtranslation-that is, generating source-language text from unpaired target-language text-and has been used in the context of neural machine translation by Sennrich et al. [12]. The directly analogous approach for ASR would be to use text-to-speech synthesis to generate speech from unpaired text. The complexity of the text-to-speech (TTS) task means that there has been limited work exploring the use of speech generated from unpaired text, often in limited settings [13]. A workaround of "translating" the text to phoneme sequences and using the resulting paired data in a multitask learning setup has been explored by Renduchintala et al. [14].

MODEL
Our model is based on the Listen, Attend and Spell (LAS) attentionbased encoder-decoder ASR model proposed by [1]. We begin by reviewing this model, and then describe the techniques we consider for LM integration with the LAS model.

LAS Model
The LAS model consists of three components: an encoder, a decoder, and an attention network which are trained jointly to predict the output sequence. The transcription can be decoded as a sequence of graphemes/characters, wordpieces, or words from a sequence of acoustic feature frames. Based on the recent success of wordpiecebased models in a variety of ASR tasks and machine translation tasks [2,3,5,15], we choose wordpieces as output unit in all our models.
The encoder consists of a stacked (bidirectional) recurrent neural network (RNN) [16] which reads in acoustic features x = (x1, · · · , xT ) and outputs a sequence of high-level features h. The sequence of high-level features h could either be the same length as the acoustic feature sequence or be downsampled if a pyramidal structure is used as in [1].
The decoder is a stacked unidirectional RNN that computes the probability of a sequence of output units y as follows: At every time step t, the conditional dependence of the output on the encoder features h is calculated via the attention mechanism. The attention mechanism, which is a function of the current decoder hidden state and the encoder features, condenses the encoder features into a context vector ct via the following mechanism: where the vectors v, ba and the matrices Wh, Wd are learnable parameters; dt is the hidden state of the decoder at time step t. The hidden state of the decoder, dt, which captures the previous output context y<t, is given by: where dt−1 is the previous hidden state of the decoder, andỹ t−1 is a learned embedding vector for yt−1, as is typical practice in RNNbased language models. The posterior distribution of the output at time step t is given by: where Ws and bs are again learnable parameters. The model is trained to minimize the discriminative loss:

LM Integration Approaches
Below we discuss the various LM integration approaches for encoder-decoder models that we study.

Shallow Fusion
In shallow fusion [6], the external LM is incorporated via log-linear interpolation at inference time only. So while for the baseline model, beam search is used to approximate the solution for: in the most basic version of shallow fusion [6], we instead use the following criterion: Recently some additional penalty terms have been introduced in the criterion [2,4,8,11]. For example, Chorowski and Jaitly [4] use a coverage penalty term c(x, y) to ensure all of the input frames have been "well attended" during decoding.
Illustration of a single decoding step of deep fusion.

Deep Fusion
Like shallow fusion, deep fusion [6] is a late training integration procedure, i.e. it assumes the encoder-decoder and language models to be pretrained. The key difference is that it integrates the external LM into the encoder-decoder model by fusing together the hidden states of the external LM (assuming a neural LM) and the decoder in the following way: where the scalar bg, vectors vg and bDF , and matrix WDF are all learned while keeping all other model parameters fixed. Fixing most of the model parameters reduces the backpropagation computation cost, and the fine-tuning procedure converges quickly in comparison to the cost of training the baseline model.

Cold Fusion
Cold fusion [7] builds on the idea of deep fusion and proposes a modified LM integration procedure shown below: where all of the parameters introduced in the above equations are learned. Some of the key differences between cold fusion and deep fusion are: Fig. 2: Illustration of a single decoding step of cold fusion. Note that unlike deep fusion, there is fine-grained gating in cold fusion and hence, gate g t is a vector. Note that, since cold fusion is an early training integration approach, in a dynamic setting with frequent changes of LM and ASR models the approach would be computationally costlier than the previous two fusion approaches, especially shallow fusion.

LM as lower decoder layer
Previous work in machine translation has suggested the utility of using a pretrained LM as a lower layer of the decoder [10]. Similarly, [17] used a pretrained LM to initialize the decoder in an RNN transducer model for speech recognition. The motivation for this approach is that it can provide better contextualized word embeddings, as is the case with the recently proposed Embeddings from Language Models (ELMo) [18]. We propose introducing the external LM as a lower layer in the decoder of a pretrained LAS model. All of the model parameters, including the LM parameters, are fine-tuned for a few epochs with the LAS objective.

LM integration via multitask learning
Going back to equation 1 of the decoder: the decoder can be seen as a conditional LM, conditioned on the encoder features that represent the speech input. The exact dependence of the decoder on the speech features is captured by the context vector ct which, from equation 2, affects the output posterior distribution as follows: Now, unpaired text has no corresponding speech signal. In the LAS model, this can be represented by a zero context vector. A zero context vector reduces the decoder from a conditional LM to a plain LM as shown below 4 : In this way, the decoder can also be used for the task of language modeling. Based on this observation, we propose a multitask learning approach for using the unpaired text, where the decoder of the LAS model is shared for the primary ASR task and the auxiliary LM task. In each iteration of multitask learning, we sample one of the tasks among the ASR and LM task based on the prior probability for picking each task. Note that when the decoder is trained for LM, the encoder and attention components of LAS model are unaffected. One important aspect to note is that, unlike all of the previous approaches discussed, this approach has no external LM; rather, the decoder itself is trained for both tasks.

Data
We use the Switchboard corpus (LDC97S62) [9], which contains roughly 300 hours of conversational telephone speech as our choice of medium-scale training set. The first 4K utterances from the training set are reserved as validation set for hyperparameter tuning and early stopping. Since the training set has a large number of repetitions of short utterances (yeah, uh-huh, etc.), we remove duplicates beyond a count threshold of 300. After these preprocessing steps, the final training set has about 192K utterances. For evaluation, we use the HUB5 Eval2000 data set (LDC2002S09), that consists of two subsets: Switchboard (SWB), which is similar in style to the training set, and CallHome (CH), which contains unscripted conversations between close friends and family. For acoustic features, we use 40-dimensional log-mel filterbank features along with their deltas, with per-speaker mean and variance normalization. For all of the above data processing, we use the EESEN toolkit's recipe [19] which is based on the Kaldi toolkit's recipe [20].
For external LM training, we combine the Switchboard training set with the Fisher corpus (LDC200{4,5}T19) [21]. To avoid domain mismatch, we process Fisher utterances to (a) remove noise/hesitation markers not used in Switchboard, and (b) filter out utterances not covered by the wordpiece model trained on Switchboard 5 . The filtering process removes ∼400K utterances out of 2.2 million Fisher utterances. Thus, combined with the Switchboard training utterances, the LM is trained on ∼2 million utterances.

Model Details
The encoder is a 4-layer pyramidal bidirectional long short-term memory (LSTM) network [22], resulting in an 8-fold reduction in time resolution. For the 2-fold reduction done at each layer below the topmost, we max-pool over 2 consecutive hidden states and feed the result into the layer above. We use 256 hidden units in each direction of each layer.
The decoder in the baseline LAS model is a single-layer unidirectional LSTM network with 256 hidden units. We use a 1K wordpiece output vocabulary, which includes all the characters to ensure open-vocabulary coverage. The vocabulary is generated using a variant of the byte pair encoding (BPE) algorithm [15] implemented in the SentencePiece library by Google 6 . We represent the wordpieces with 256-dimensional embeddings learned jointly with the rest of the model. For regularization we use: (a) label smoothing [23], where we uniformly distribute 0.1 probability mass among labels other than the ground-truth label, and (b) dropout [24] with probability 0.1 applied on outputs all of the RNN layers. We also use scheduled sampling [25] with a fixed schedule, where each timestep's decoder input is either the ground-truth previous label with probability 0.9 or sampled from the model's posterior distribution for the previous label with probability 0.1.
For inference, we use beam search with beam size of 10. We observed that for some of the models increasing the beam size to 10 resulted in escalation of insertion errors compared to a lower beam size. To counter this, we add a wordpiece insertion reward ∈ {0, 0.1, 0. The external LM is a single-layer 512 hidden unit RNN with LSTM cells. The RNN hidden state is first passed through a projection layer with 256 hidden units and finally fed into the softmax layer. The LM is trained with the same output vocabulary as the LAS model. The LM is trained for 20 epochs with early stopping based 5 Some utterances in Fisher have symbols such as period sign which are not present in Switchboard and hence are not covered by the wordpiece model trained on Switchboard transcripts. 6 https://github.com/google/sentencepiece on development set perplexity and attains a perplexity of ∼15 on the Switchboard development set.

Training Details
We bucket our training data by utterance length into 5 buckets, restricting utterances within a minibatch to come from a single bucket for training efficiency. Different minibatch sizes are used for different buckets, with a batch size of 128 used for the shortest utterances and a 32 batch size used for the bucket with longest ones. Preliminary experiments suggested a performance benefit by proceeding through the training set from the bucket with smallest utterances to the one with longest utterances in each epoch. We use this order for training all of our models. (A similar training order scheme was also used in [26].) All models are trained using the Adam optimizer [27] with an initial learning rate of 0.001. For the baseline LAS model and models with early LM training integration, we train for 12 epochs and start halving the learning rate every epoch after 7 epochs. For the models with late LM training integration, we start halving the learning rate every epoch after 4 epochs and train for a total of 8 epochs. For all models, we use early stopping based on development set WER when using greedy decoding.
To speed up training, the encoder of all models is initialized with the encoder of a LAS model trained for predicting phone sequences, similarly to [26]. All models are trained on a single NVIDIA Ti-tanX GPU and finish training within 2 days, with each epoch taking 3-4 hours. Finally, all of our models are implemented in Tensor-Flow [28].

Data
The training data consists of approximately 22 million anonymized, human-transcribed utterances representative of live Google traffic, both Voice Search and dictation. Clean utterances are artificially corrupted using a room simulator, adding varying degrees of noise and reverberation such that the overall SNR is between 0dB and 30dB, with an average SNR of 12dB. The noise sources are from YouTube and daily life noisy environmental recordings. The models are evaluated on two data sets: VS14K, which consists of about 14K Voice Search utterances, and D15K, which contains about 15K dictation utterances.
The external LM is trained on a variety of text data sources, including untranscribed anonymized voice queries (both search and dictation), anonymized typed queries from Google Search, as well as the transcribed training utterances mentioned above. Since these component data sources have varying sizes, we up-and downsample to mix them at a 1:1:1 ratio.

Model Details
Our LAS model is consistent with [5]: The encoder is composed of 5 unidirectional LSTM layers of 1400 hidden units each, the attention mechanism is a multi-headed additive attention with four heads, the decoder consists of 2 unidirectional LSTM layers of 1024 hidden units each, and the output vocabulary is 16384 wordpieces. We use 80-dimensional log-mel filterbank features, computed with a 25ms window and shifted every 10ms. Similarly to [29,30], at each frame t, these features are stacked with 3 frames to the left and downsampled to a 30ms frame rate.
The external recurrent LM is composed of 2 LSTM layers of 2048 hidden units each. It has the same wordpiece output vocabulary as the LAS model.

Training Details
LAS models are trained in two stages. First, they are trained to convergence with a cross-entropy criterion using synchronous replica training [5]. We use tensor processing units (TPUs) [31] with a topology of 8x8, for a total of 128 synchronous replicas and an effective batch size of 4096. We found that having a very large batch size was critical to seeing any improvement from cold fusion. Our learning rate schedule includes an initial warm-up phase, a constant phase, and a decay, consistent with [5].
Next, we conduct a second training phase with a minimum word error rate (MWER) criterion [32]. This phase is performed on 16 synchronous GPU replicas to convergence, which is typically about one epoch. Note that for deep fusion we effectively have four training phases: cross-entropy training of LAS, MWER training of LAS, cross-entropy training of deep fusion, MWER training of deep fusion.
The external LM is also trained on TPUs with a topology of 4x4. All models are trained using the Adam optimizer [27] and are implemented in TensorFlow [28].  Table 1 shows the results of a baseline LAS model and the three fusion approaches on Switchboard and CallHome. All of the fusion approaches improve over the baseline model with a relative WER reduction of 3-7% on Eval2000. Among the fusion approaches, shallow fusion is a clear winner with almost double the gains over baseline compared to deep and cold fusion. Finally, deep and cold fusion have comparable performance on Switchboard. Table 2 shows the corresponding results for VS14K and D15K. All of the fusion approaches improve performance over the baseline model for VS14K, but for D15K deep fusion suffers a minor degradation compared to baseline. As with Switchboard, on both of these data sets shallow fusion is again the best performer, although it is tied with cold fusion on VS14K. Finally, deep fusion has no or negligible gain over baseline, suggesting that deep fusion does not scale well with data.   Table 3 and compare them against the earlier Switchboard results from Table 1. The multitask learning approach achieves minor gains over the LAS baseline. While these gains are more modest than those of the three fusion approaches, it is important to note that unlike the fusion approaches, the LM multitask approach introduces no new parameters.

Fusion Approaches
Next we evaluate the approach of introducing the LM as a lower decoder layer (making the decoder two layers deep in the case of our Switchboard models). To account for the confounding variable of a deeper decoder, we also compare it to a version where a randomly initialized RNN is introduced instead of the pretrained RNN LM. As can be seen from the table, the performance of this approach is comparable to that of deep and cold fusion. In addition, the marginal gains from introducing a randomly initialized RNN instead demonstrate the benefit of LM pretraining. The promising performance we see here is consistent with the findings of [17] using a pretrained LM as the decoder, and this simple approaches of using a LM to initialize parts of the decoder warrants further investigation in future work. While shallow and cold fusion have very similar top-1 WER on the Google data sets, we can investigate the quality of the top-8 to better understand the strengths of each approach. For each of the fusion methods, Table 4 shows the WER after second pass rescoring with a large, production-scale LM (as used in [5]), as well as the oracle WER in parentheses.

Second Pass Rescoring
As the table shows, cold fusion has significantly better oracle WER on VS14K than the baseline and other fusion methods and, as a result, benefits the most from a second pass LM. While shallow fusion is unaffected by the second pass, the cold fusion WER drops from 5.3 to 5.0. This suggests that the improvements provided by shallow fusion are redundant with the benefits of second pass rescoring, whereas cold fusion does something distinct, improving the overall quality and diversity of the top 8 decoded transcripts.
Cold fusion also has the lowest oracle WER on D15K, but none of the models benefit much from the second pass on this data set. The lack of improvement is likely because the second pass LM is primarily designed to improve performance on Voice Search. Shallow fusion therefore remains best on this data set.
Finally, we note that shallow fusion actually has higher oracle WER than the baseline LAS system on both data sets. This may be because shallow fusion can actually pull poor transcripts into the beam if they are heavily favored by the LM.

CONCLUSION
We perform a thorough investigation of the problem of LM integration in encoder-decoder based ASR models. We compare some of the most prominent past methods and a few of our own proposed methods on the medium-scale and publicly available Switchboard dataset and the large-scale Google voice search and dictation data sets. Our results show that for first-pass scoring, the simple approach of shallow fusion performs best on all of our data sets. However, cold fusion produces lower oracle error rates among the top-8 decoded transcripts, and outperforms shallow fusion after second pass rescoring on Google voice search. Deep fusion is comparable to cold fusion on Switchboard but gets no or negligible gains over the baseline on Google data sets, suggesting that it does not scale well with data. Among our proposed methods, the simple approach of using a pretrained language model as a lower layer of the decoder performs comparably to cold and deep fusion on Switchboard, suggesting that further investigation of the approach may be fruitful.