Deep Sparse Conformer for Speech Recognitionthanks: Accepted by InterSpeech 2022.

Abstract

Conformer has achieved impressive results in Automatic Speech Recognition (ASR) by leveraging transformer’s capturing of content-based global interactions and convolutional neural network’s exploiting of local features. In Conformer, two macaron-like feed-forward layers with half-step residual connections sandwich the multi-head self-attention and convolution modules followed by a post layer normalization. We improve Conformer’s long-sequence representation ability in two directions, sparser and deeper. We adapt a sparse self-attention mechanism with in time complexity and memory usage. A deep normalization strategy is utilized when performing residual connections to ensure our training of hundred-level Conformer blocks. On the Japanese CSJ-500h dataset, this deep sparse Conformer achieves respectively CERs of 5.52%, 4.03% and 4.50% on the three evaluation sets and 4.16%, 2.84% and 3.20% when ensembling five deep sparse Conformer variants from 12 to 16, 17, 50, and finally 100 encoder layers.

\name

Xianchao Wu \addressNVIDIA \emailxianchaow@nvidia.com

Index Terms: speech recognition, human-computer interaction, computational paralinguistics

1 Introduction

End-to-end automatic speech recognition (ASR) systems leveraged on Transformers and their variants have achieved impressively low word/character error rates (WERs/CERs) in numerous languages during recent years [Miao2020TransformerBasedOC, conformer_gulati20_interspeech, DBLP:journals/corr/abs-2010-11395, Dong2018SpeechTransformerAN, Pham2019VeryDS]. The Transformer architecture includes multi-head self-attention (MHSA) and cross-attention layers that can represent long-distance interactions inside and between sound-text sequences. Alternatively, convolutions with predefined kernel sizes capturing local contexts have also been successfully utilized in ASR [Majumdar2021CitrinetCT].

Conformer [conformer_gulati20_interspeech], combines multi-head attentions and convolution modules, has achieved state-of-the-art accuracy in a list of benchmark datasets such as LibriSpeech. One Conformer encoder block comprises two macaron-like feed-forward network (FFN) layers with half-step residual connections. Inside these two FFNs, there is one MHSA module and one convolution module which are respectively designed for capturing global and local context information of input sound sequences. Layer normalization is further applied right after each residual connection. In the original Conformer S, M, and L models, there are 16, 16, and 17 Encoder blocks and with 10.3M, 30.7M and 118.8M parameters, respectively.

Our work is motivated by aiming at answering two questions: will deeper Conformers achieve better accuracy, and how can we train and inference them in efficient ways? For a sequence with length , MHSA module requires to compute the “similarity” between every two (subsampled) “frames” yielding a time and memory-usage complexity of . One intuitive way is to reduce the necessity of computing every pair and only compute a relatively small scale of ranges for each place in an input sequence.

We follow this sparse attention [informer-DBLP:conf/aaai/ZhouZPZLXZ21, Li2021EfficientCS_linear_conformer, wang21ha_interspeech_probsparse] direction and use a probability attention which defines a query importance measure in MHSA and then picks only the top- (=) query vectors for inner-product similarity computing with key vectors. For the other deeper Conformer direction, we borrow the deep normalization idea used for training 1,000-layer Transformers [deepnet-wang2022deepnet]. That is, the input tensor is weighted by an additional factor during residual connection to control and bound the model’s updating for convergence. Also, another factor is taken as the gains for initializing the parameters in MHSA using the Xavier initialization. We name this deep sparse Conformer and train 50-layer and 100-layer model variants under the Japanese CSJ-500h data. We report their convergence speeds during training, inference time and CERs.

2 Related Work

The ProbSparse self-attention mechanism [informer-DBLP:conf/aaai/ZhouZPZLXZ21] was first used in a Conformer-transducer for autoregressive end-to-end ASR [wang21ha_interspeech]. LSTM layers were used to encode each textual sequence and a multi-layer linear module was used to combine latent representations of audios and labels. Time/memory costs’ relative decrease rate reached 20% to 50% for long sequences from 20s to 180s. We follow their usage of ProbSparse. The differences are that, (1) we select a non-autoregressive architecture with transformer decoders, (2) we use CTC loss and attention losses for training and CTC+attention-rescoring for decoding, and (3) we use relative positional encoding for the Conformer encoder.

A low-rank transformer was proposed in [DBLP:journals/corr/abs-1910-13923] for lightweight and efficient end-to-end ASR. The linear layers used in MHSA and FFN are replaced by linear encoder-decoder units where a weight matrix is approximated by two smaller matrices , such that (). A linear self-attention mechanism [9423033-linear-attention] together with a low-rank FFN [DBLP:journals/corr/abs-1910-13923] were employed in [Li2021EfficientCS_linear_conformer] to build a linear-attention Conformer for ASR. The half-size models achieved comparable results with Conformer.

Compressed structures and speech attribute augmentations were used in [Li2019ImprovingTS] for improving Transformer-based ASR. Parameters were shared among layers of encoder and decoder blocks. Speaker information (gender, age, education-level, speaker ID) and speech utterance properties (duration of short and long, topic of the lecture) were used to augment the training data. Using the Japanese CSJ-500h dataset, they achieved CERs of 7.6%, 6.1% and 6.3% on the three test sets. We compare our models with this work since it uses CSJ dataset as well. The differences are that we do not use parameter sharing or additional speech information.

An online compressive Transformer was utilized in [leong21_interspeech] for end-to-end ASR. The input speech signal is separated into a number of blocks where the former block’s compressive memory is concatenated to current block’s encoder memory for decoding. Losses of CTC, RNN-transducer and attention reconstruction using transformers were minimized.

Adaptive span self-attention was used in [Chang2020EndtoEndAW] for end-to-end ASR. The motivation is to learn the appropriate span size at each self-attention head and layer during training. The limitation of spans is applied to the number of keys to be attached to each query.

On the other hand, very deep models with up to 48 Transformer layers were used in [Pham2019VeryDS] for end-to-end ASR. Stochastic residual connections fundamentally apply a mask on the MHSA or FFN function : and only takes discrete 0 or 1 values, generated from a Bernoulli distribution similar to dropout. The difference is that we apply a factor to and is a function of the depth of the architecture. That is, we do not explicitly skip a MHSA or a FFN layer. An ensemble of n-best outputs from 36, 48 and 60 encoding layers yielded the best result of 9.9% on the Switchboard test set.

Transformer-XL [transformer-xl-dai-etal-2019-transformer] with as many as 48 layers (model size = 185.7M) was adapted in [lu20g_interspeech2020_large_scale] for large-scale ASR. As the authors mentioned, the gains were not as large as they had expected and regularizing the deep transformers would be one direction for further improvements.

There are many more papers we are not able to mention here. A survey of transformer variants and their applications to end-to-end ASR can be found in [DBLP:journals/corr/abs-2106-04554, DBLP:journals/corr/abs-2009-06732].

3 Deeper and Sparser Conformer Blocks

The original Conformer [conformer_gulati20_interspeech] block contains two Feed Forward modules sandwiching the MHSA module and the Convolution module. This sandwich architecture is inspired by Macaron-Net [macaron-net-lu2019understanding], in which the original feed-forward layer in one Transformer layer is separated into two half-step feed-forward layers, one before the self-attention layer and another after. Mathematically, for an input sent to a Conformer block , the output is:

(1)
(2)
(3)
(4)

There are four residual connections in one Conformer block and a layer normalization (LN) is used finally (named as Post-LN). As has been observed and reported in [deepnet-wang2022deepnet, xiong-icml2020-DBLP:conf/icml/XiongYHZZXZLWL20], this Post-LN has a problem of unstable training. Furthermore, the MHSA network requires a time and memory-usage complexity of which is barely acceptable when we have relatively long sequences in our training data or during inferencing.

3.1 Sparser Attention

There are a list of work that proposed new attention mechanisms to replace the time/space complexities into or even [Li2021EfficientCS_linear_conformer, wang21ha_interspeech_probsparse]. Motivated by [informer-DBLP:conf/aaai/ZhouZPZLXZ21] for modeling long sequences for time-series forecasting, we adapt the ProbSparse self-attention mechanism to replace the MHSA function in Equation 2. In ProbSparse, the original tensor ( is batch size, is input sequence length, and is hidden dimension. For simplicity, we set and omit hereafter.) is replaced by a same shape tensor which only contains top- () queries under a sparsity measurement . That is, each key is only allowed to attend to dominant queries:

(5)
(6)
(7)

Here, are row vectors, and is selected to be an exponential kernel .

The query sparsity measure is motivated by (1) the dominant dot-product pairs encouraging the corresponding query’s attention probability distribution away from the uniform distribution, and (2) Kullback-Leibler divergence measuring the “distance” between and uniform distribution . An empirical approximation for efficiently computing the query sparsity measurement for is defined as the following “max-mean” equation:

(8)

The range of top- approximately holds as proved in [informer-DBLP:conf/aaai/ZhouZPZLXZ21]. Under the long tail distribution, it has been empirically testified that randomly sample dot-product pairs to compute the query sparsity measure and then select sparse top- from it and form yielded acceptable results [wang21ha_interspeech_probsparse].

We use the sparse attention function (MHSA-Sparse) defined by Equation 7 and assisted by Equation 8 to replace the original MHSA function used in Equation 2:

(9)
(10)

Here, the linear projections are trainable parameter matrices and , , and .

Algorithm 1 describes the pseudo-code of a multi-head attention layer using ProbSparse (lines 12 to 19, 21) and relative position encoding (lines 10, 11, 19). One additional linear layer with weight matrix is introduced to parameterize the memory tensors’ position information. Following [transformer-xl-dai-etal-2019-transformer], two learnable vectors , are used in shapes of in line 10 and 11. They are introduced to assist relative position encoding by alleviating attentive bias towards different words in different positions.

Equation 8 suggests an inner-product computation of between a query vector to all the key vectors to determine the importance of the query vector. This blocks the reduction of time complexity. Instead, we only use number of key vectors through sampling from the whole (line 12, 13). This ensures a time complexity of for computing Equation 8 in line 15. A hyper-parameter (= 5.0) determines the size of the key vector subset.

When the query sparseness measurement is computed, we can easily pick the top- queries where is the number of query vectors selected. A hyper-parameter (= 5.0) determines the size of the query vector subset. Line 19 combines the “similarity scores” between the reduced query vector set and the original key and position tensors. Then, the scores are masked by the lengths of sequences in a batch, normalized into probability-style scores under Softmax and finally dropped out with a given probability .

1 Given: X, , Y, , , ,
2 Trainable parameters: ,
3 Q, K, V, P = Y, X, X, is the relative position encoding tensor for X, and Y=X for self-attention
4 , , = Q.shape
5 = K.shape[1]
6 Q = Q.view(, , , )
7 K = K.view(, , , ).transpose(1,2)
8 V = V.view(, , , ).transpose(1,2)
9 P = P.view(, , , ).transpose(1,2)
10 = (Q + ).transpose(1,2)
11 = (Q + ).transpose(1,2)
12 =
13 = Sample(K, , dim=-2)
14 =
15 = ().max(dim=-1)[0] - ().sum(-1)/ Equation 8, omit
16 = .topk()[1] index of top- queries
17 = [, :]
18 = [, :]
19 S = ( + ) /
20 S = Dropout(Softmax(Mask(S, )), )
21 V[, :] = SV only change a part of V
22 V = V.transpose(1,2).contiguous().view(, -1, )
23 V = V
24 return V
Algorithm 1 ProbSparse+Relative Position Encode

3.2 Deeper Normalization

The Conformer-Large defined in [conformer_gulati20_interspeech] contains 118.8M parameters in which there are 17 encoder layers with encoder dimension of 512, 1 decoder layer with decoder dimension of 640. Deeper models alike (1) GPT-3 [gpt3_NEURIPS2020_1457c0d6] model with 175B parameters and 96 transformer layers has achieved impressive scores both for classification and generation tasks through few-shot prompt-based learning, (2) DeepNet [deepnet-wang2022deepnet] with 1,000 transformer layers has shown significantly better BLEU scores [papineni-etal-2002-bleu] in multilingual neural machine translation, compared with shallow architectures. Inspired by these, we aim at enlarging the number of layers in Conformer to as much as one-hundred levels and testifying its representation ability for ASR.

DeepNet [deepnet-wang2022deepnet] combines the good performance of Post-LN and stable training of Pre-LN by leveraging a new normalization function named DeepNorm when performing residual connections [resnet-He2016DeepRL] in a Transformer layer:

(11)

In order to ensure the model updating in DeepNet to be constrained by bounds for stable training, is assigned with various values alike for encoder-only framework (e.g., BERT [bert-devlin-etal-2019-bert]), and for decoder-only framework (e.g., GPT [gpt3_NEURIPS2020_1457c0d6]) where and respectively stand for the number of , such as self-attention, cross-attention or FFN sub-layers.

Encoder model architecture for our deep sparse Conformer. Updates are marked in red color:
Figure 1: Encoder model architecture for our deep sparse Conformer. Updates are marked in red color: on and using sparse attention in MHSA.

We adapt this DeepNorm function in our deep sparse Conformer. The updated Conformer block is mathematically expressed as:

(12)
(13)
(14)
(15)

Here, we utilize , all take a value of (/=encoder/decoder layer numbers), to scale the temporary output from former sub-layer for residual connection. MHSA-Sparse function is defined in Equation 7 and described in Algorithm 1. Figure 1 depicts the encoder model architecture of our deep sparse Conformer in which one Conformer block is extended into a pipeline of four modules with four residual connections controlled by DeepNorm.

4 Experiments

4.1 Setup

Our experiments are performed under an open-source ASR platform, WeNet111https://github.com/wenet-e2e/wenet [wenet-DBLP:journals/corr/abs-2102-01547]. We release code and pretrained models222https://github.com/Xianchao-Wu/wenet-deep-sparse-conformer. We select a Conformer baseline model consists of a 12-block Conformer encoder (=2048, =8, =512, CNN=31) and a 3-block bidirectional Transformer decoder (=2048, =8, =512) which encodes the textual sequences in left-to-right () and right-to-left () directions. The objective is to minimize , a linear combination of the CTC loss [ctc-10.1145/1143844.1143891] (=0.3) and attention losses (ATT) computed by point-wise KL-divergence [KL-10.1214/aoms/1177729694]:

(16)

Label smoothing with is applied to the attention objective so that the references are discounted by (1-).

During training, we select the Adam optimizer [Kingma2015AdamAM] with a maximum learning rate of 0.002. The Noam learning rate scheduler with 30K warm-up steps is used. The models are trained with static batching skill for 120 epochs. The top 30 best checkpoints ranked by validation set losses are averaged to be the final model. For decoding, we use CTC greedy search and Attention rescoring. All our experiments were performed under NVIDIA DGX-A100 with 8*A100-80GB GPUs.

4.2 Data

We evaluate deep sparse Conformer variants on the Japanese ‘‘Corpus of Spontaneous Japanese’’ (CSJ) dataset333https://ccd.ninjal.ac.jp/csj/en/, which consists of 500 hours of labeled speech. We use sentencepiece-bpe [kudo-richardson-2018-sentencepiece] to segment the text sequences and select a vocabulary size of 4,096. During data preparation, we generate 80-dimension FBank feature vectors with a 25ms window, a 10ms frame stride and dither=1.0. SpecAugment [spec-aug-2019] is adapted with 2 frequency masks (=10) and 2 time masks (=50). Global Cepstral Mean and Variance Normalization [cmvn-10.1016/S0167-6393(98)00033-8] technique is employed to normalize the 80-dimension FBank feature vectors.

4.3 Major Results on CSJ Tests

1.73h 1.82h 1.23h train. inf. size
models Test1 Test2 Test3 /ep. char/s (M)
Trans.[Li2019ImprovingTS] 7.6 6.1 6.3 - - 36
Espnet+LM 6.5 4.6 5.1 - - -
Citrinet[Majumdar2021CitrinetCT] 7.28 4.81 5.44 5m 210 22.7
Conformer[conformer_gulati20_interspeech] 6.97 4.65 5.29 10m 194 135.1
DSC-small (16) 7.64 5.35 6.15 6m 310 14.2
DSC-12en 5.52 4.03 4.50 8m 239 135.2
DSC-17en 6.00 4.30 5.17 13m 235 169.4
DSC-50en 6.20 4.31 5.49 42m 203 395.4
DSC-100en 6.27 4.36 5.56 132m 180 737.8
Ensemble+LM 4.16 2.84 3.20 - - -
Table 1: CERs (%) of 4 baselines and 5 deep sparse Conformer (DSC) variants trained with the CSJ-500h dataset.

Table 1 lists the CERs of five of our deep sparse Conformer (DSC) variants and four baselines. The first baseline is a Transformer with enhanced information from speakers and speech [Li2019ImprovingTS] (refer to Section 2). The second baseline is Espnet’s implementation of deep VGGBLSTM with CTC joint decoding and LM rescoring444https://github.com/espnet/espnet/blob/master/egs/csj/asr1/RESULTS.md. Note that only this baseline uses an external language model among all the nine models. The third baseline is Citrinet [Majumdar2021CitrinetCT] (channel size = 384), a recent pure CNN-based model with 1D time-channel separable convolutions combined with squeeze-and-excitation and has achieved comparable results compared with Conformer. The fourth baseline is Conformer-Large [conformer_gulati20_interspeech] with a bi-decoder.

Our first DSC variant is a Conformer-Small model with the same configurations of Conformer-S [conformer_gulati20_interspeech] with 16 layers except that we use a bidirectional decoder. The other four variants differ only at the encoder part of different layers: 12, 17, 50, and 100. These 5 variants use a bidirectional decoder in which both and decoders have 3 Transformer decoder layers.

We have the following observations. First, Conformer performs well among the baselines, with a relatively large model size. Second, considering that both Conformer and DSC-12en have 135M parameter sizes, we can compare their CERs and training/inferencing time directly. DSC-12en achieved an absolute CER improvement of 1.45%, 0.62% and 0.79% on the three test sets. Also, the training time is only 80% of Conformer’s and the inference speed is 1.23 times faster. These improvements of accuracy and training/inferencing speed reflect the effectiveness of the deep sparse Conformer blocks. Third, using DeepNorm strategy, we could successfully train 50 and 100 layers of Conformer. However, the training time increases significantly: the training time for DSC-17en, DSC-50en and DSC-100en are respectively 1.6, 5.25 and 16.5 times of DSC-12en’s. The accuracies slightly dropped when we enlarged the model parameter sizes. This observation aligns with that reported in [Pham2019VeryDS]. Following [Pham2019VeryDS], we also performed 6-gram LM enhanced ensembles of 30-best outputs from the 5 variants and achieved the best CERs for the 3 test sets: 4.16%, 2.84% and 3.20%.

4.4 Ablation Studies

4.4.1 Number of Deep Sparse Conformer Blocks

Test1 Test2 Test3
Attn CTC Attn CTC Attn CTC
small-1 7.64 7.82 5.35 5.53 6.15 6.40
12en-2 5.52 5.62 4.03 4.23 4.50 4.39
17en-3 6.00 6.16 4.30 4.51 5.17 5.02
1+2+3 4.83 4.94 3.36 3.51 3.74 3.70
+50en 4.38 4.45 3.00 3.16 3.40 3.29
++100en 4.16 4.21 2.84 2.92 3.20 3.09
Table 2: System ensemble CERs (%) with two types of decoding: attention rescoring (Attn) and CTC greedy searching.

Table 2 shows the detailed CER improvements when (1) ensembling DSC-small, DSC-12en and DSC-17en, (2) further appending DSC-50en and (3) finally adding DSC-100en. By ensembling the first three models, CER improved 0.70% averagely. Then, adding DSC-50en brings a gain of 0.40% on average. Finally, the DSC-100en can further contribute 0.21% improvements on average. These reflect that larger models are still helpful yet their contributions are marginally decreased.

4.4.2 Pre-LN vs. Post-LN in Deep Normalization

We investigated Pre-LN and Post-LN when performing DeepNorm. Different from that observed in NLP fields, Post-LN was less stable in DSCs and the loss could not converge after 30 epochs. We thus select a mixture solution in our five model variants by (1) keeping the LNs in Post-LN and (2) initially adding a Pre-LN layer.

5 Conclusions

In this paper, we introduced deep sparse Conformer, an architecture that integrates (1) sparse attentions guided by a query sparseness measure and (2) deep normalization which weight input tensors during residual connection into Conformer. We demonstrated that the usage of sparse attentions and deep normalization yielded faster training speed and stable training of much deeper Conformer encoder blocks. We built model variants with as much as 100 encoder layers and trained them using the Japanese CSJ-500h datasets. Future work includes using deep sparse Conformer blocks in self-supervised speech pretraining and fine-tuning.

References