Algorithm Search⌘K

Modelresearch

Conformer

Also called convolution-augmented transformer.

A speech encoder block that sandwiches self-attention and a convolution module between two half-step feedforward layers.

The Conformer is an encoder for speech recognition. Its block puts a multi-head self-attention module and a convolution module between two feedforward modules, each feedforward module with half weight on its residual path. Self-attention lets every frame look at every other frame, which captures long-range context; the depthwise convolution captures local patterns such as formant movements over a few frames. A stack of Conformer blocks on top of a convolutional front end replaces the LSTM or Transformer encoder in end-to-end recognizers such as the RNN transducer, CTC and attention models. In the original paper it was more accurate on LibriSpeech than the Transformer and convolutional encoders it was compared with.

The machine

Front end. The input is a sequence of 80 log mel filter bank features every 10 ms. A convolutional subsampling stage reduces the frame rate to one vector every 40 ms, a linear layer maps it to width dd, and dropout follows. Then come NN Conformer blocks.

The block (Gulati et al. 2020, Section 2). For an input sequence xx of vectors of width dd:

x~=x+12 FFN(x),x′=x~+MHSA(x~),x′′=x′+Conv(x′),y=LayerNorm(x′′+12 FFN(x′′)).\tilde x = x + \tfrac{1}{2}\,\mathrm{FFN}(x), \qquad x' = \tilde x + \mathrm{MHSA}(\tilde x), \qquad x'' = x' + \mathrm{Conv}(x'), \qquad y = \mathrm{LayerNorm}\big(x'' + \tfrac{1}{2}\,\mathrm{FFN}(x'')\big).

The two half-step feedforward modules around the middle follow the Macaron-Net design. Each module starts with its own layer normalization (pre-norm residual units) and ends with dropout.

Feedforward module. LayerNorm, a linear layer that expands the width 4 times, the Swish activation z⋅σ(z)z \cdot \sigma(z), dropout, a linear layer back to width dd, and dropout.

Self-attention module. LayerNorm, multi-head self-attention with the relative positional encoding of Transformer-XL, and dropout. The relative encoding depends only on the distance between two positions, which helps the module generalize to inputs of different lengths.

Convolution module. LayerNorm, a pointwise convolution that doubles the width, a gated linear unit (GLU) that halves it again, a 1-D depthwise convolution with kernel size 32, batch normalization, Swish, a second pointwise convolution, and dropout. The depthwise convolution filters each channel separately along time, so it costs kdk d per frame instead of kd2k d^2.

Sizes. The paper uses three encoders with a one-layer LSTM decoder in a transducer:

model parameters blocks width dd heads decoder width
Conformer (S) 10.3 M 16 144 4 320
Conformer (M) 30.7 M 16 256 4 640
Conformer (L) 118.8 M 17 512 8 640

Example. Ten seconds of audio are 1000 frames at 10 ms, and 250 vectors after the front end. In Conformer (S), each self-attention module compares all 2502=62 500250^2 = 62\,500 pairs of positions in each of 4 heads, while each depthwise convolution sees 32 positions, 1.28 s of audio. The feedforward modules work on each of the 250 positions separately.

What it counts

The encoder maps TT input frames to T/4T/4 vectors of width dd that the decoder of the recognizer reads; the loss and the decoding rule come from the recognizer (transducer, CTC or attention). For n=T/4n = T/4 positions, one block costs about Θ(nd2)\Theta(n d^2) for the feedforward modules, the attention projections and the pointwise convolutions, Θ(n2d)\Theta(n^2 d) for the attention scores and weighted sums, and Θ(nkd)\Theta(n k d) for the depthwise convolution. The n2n^2 term dominates for long utterances, which is why the front end reduces the frame rate. Memory for training is Θ(N(nd+hn2))\Theta(N (n d + h n^2)) with hh heads, for the activations and the attention matrices.

Relation to other models

  • Transformer encoder. The Conformer block is a Transformer block with a convolution module added after the attention, the feedforward layer split into two halves around them, Swish activations and relative positions. Without the convolution module it is close to a Transformer with a Macaron feedforward pair.
  • Convolutional encoders. Models built only from convolutions see a limited window unless they add global context by other means. The Conformer gets global context from attention and local detail from the convolution, in every block.
  • RNN transducer and listen, attend and spell. These are recognizers that need an encoder; the Conformer is a drop-in encoder for them, and for joint CTC-attention.
  • wav2vec 2.0. Its context network is a Transformer encoder over speech features, the place a Conformer stack can also take.
  • SpecAugment. A data augmentation that is used together with Conformer encoders in training; it changes the input, not the model.

Known results in the model

  • LibriSpeech. With a transducer and no language model, Gulati et al. (2020) measured word error rates of 2.1% on test-clean and 4.3% on test-other for Conformer (L), 2.3% and 5.0% for Conformer (M) and 2.7% and 6.3% for Conformer (S). With an external language model, Conformer (L) reached 1.9% and 3.9% (measurements).
  • The convolution module matters. In the ablation studies of the paper, removing the convolution module from the large model raised the word error rate on test-other from 4.3% to 4.9% (measurements).
  • Cost of attention. The self-attention module costs Θ(n2d)\Theta(n^2 d) per block for nn positions (a property of full self-attention), so long-form audio needs chunking or limited attention spans.

References

  1. Anmol Gulati, James Qin, Chung-Cheng Chiu, Niki Parmar, Yu Zhang, Jiahui Yu, Wei Han, Shibo Wang, Zhengdong Zhang, Yonghui Wu and Ruoming Pang, Conformer: convolution-augmented transformer for speech recognition, Interspeech 2020, pages 5036 to 5040, Section 2 (the Conformer block, the convolution module, the feedforward module and the block equations), Section 3 (the model sizes and the LibriSpeech results) and the ablation studies

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW3 standard
  • at least two sources