AI Logic

Architectures

QuartzNet

Updated:

Architecture of QuartzNet. Left: the overall flow of QuartzNet 15x5 (mel filterbank features β†’ C1 β†’ blocks B1 to B5, each repeated 3 times β†’ C2, C3, C4 β†’ CTC loss). Right: inside one block, where modules of 1D depthwise convolution, pointwise convolution, batch normalization, and ReLU are stacked Rβˆ’1 times; the block input, passed through a pointwise convolution and batch normalization as a residual, is added to the batch normalization output of the last module before ReLU

Background and overview

QuartzNet is an end-to-end speech recognition model trained with CTC that greatly reduces the number of parameters by replacing the 1D convolutions of Jasper with "time-channel separable convolutions", which split each convolution into a depthwise convolution that looks only along time within each channel and a pointwise convolution that mixes channels at each time step. It was introduced in 2019 by Kriman et al. at NVIDIA.

Around 2019, end-to-end speech recognition models were accurate, but many had more than 100 million parameters. Jasper DR 10x5 also has 333 million parameters. QuartzNet's goal was to make the model smaller while keeping accuracy nearly the same. Small models have the following advantages.

  • They train faster.
  • They are easier to deploy on devices with limited compute and memory.
  • They can process more audio at once during inference.

To this end, QuartzNet applies depthwise separable convolutions, used in lightweight image models such as MobileNet and Xception, to 1D convolutions over audio. The best model, QuartzNet 15x5, has 18.9 million parameters and reaches a word error rate on LibriSpeech test-clean of 3.90% with greedy decoding and no language model, and 2.69% when combined with an external Transformer-XL language model.

As an analogy, an ordinary convolution is like a single listener hearing everyone's (all channels') past and future remarks (time steps) all at once, so the effort grows with the number of listeners. A separable convolution splits this into two stages: first each person organizes only the flow of their own remarks (depthwise), and then the opinions of everyone at that moment are combined (pointwise), which takes far less effort.

Time-channel separable convolution

The core of QuartzNet is splitting a 1D convolution into two parts. Let cinc_{\text{in}} be the number of input channels, coutc_{\text{out}} the number of output channels, and KK the kernel length along time.

  1. Depthwise 1D convolution: Convolves KK time steps along time, separately for each channel. Channels are not mixed.
  2. Pointwise convolution: Mixes all channels, separately at each time step. It is a convolution with kernel length 1 (1Γ—11 \times 1).

The number of weights in an ordinary 1D convolution and in a time-channel separable convolution is as follows (Section 3.1 of the paper).

KΓ—cinΓ—cout⏟ordinaryΒ convolution⟢KΓ—cin⏟depthwise+cinΓ—cout⏟pointwise\underbrace{K \times c_{\text{in}} \times c_{\text{out}}}_{\text{ordinary convolution}} \quad \longrightarrow \quad \underbrace{K \times c_{\text{in}}}_{\text{depthwise}} + \underbrace{c_{\text{in}} \times c_{\text{out}}}_{\text{pointwise}}

For example, with K=33K = 33 and cin=cout=256c_{\text{in}} = c_{\text{out}} = 256, an ordinary convolution has 33Γ—256Γ—256β‰ˆ2.1633 \times 256 \times 256 \approx 2.16 million weights, whereas the separable version has 33Γ—256+256Γ—256β‰ˆ7433 \times 256 + 256 \times 256 \approx 74 thousand, about 1/29.

Because the depthwise convolution has very few weights, making the kernel longer barely increases the number of weights. So QuartzNet uses kernels about 3 times longer than wav2letter and Jasper (33 to 87), letting a single layer see a wide time range.

TDS (time-depth separable) convolutions, which used separable convolutions for speech recognition earlier, treat data in 3 dimensions, "time Γ— frequency width Γ— channels", with KΓ—c2+2Γ—(wβ‹…c)2K \times c^2 + 2 \times (w \cdot c)^2 weights (ww is the input width). QuartzNet treats data in 2 dimensions, "time Γ— channels", and fully separates time from channels, so it needs only KΓ—c+c2K \times c + c^2 weights.

Architecture

QuartzNet's overall design is the same as Jasper's, and models are named QuartzNet BxR after the number of blocks BB and the number of modules RR within each block. The left side of the figure at the top of the article shows QuartzNet 15x5, which, as in Table 1 of the paper, processes in the following order.

  1. Convolution C1: kernel 33, stride 2, 256 channels.
  2. Blocks B1 to B5: kernel lengths KK of 33, 39, 51, 63, 75 and channels CC of 256, 256, 512, 512, 512. In QuartzNet 15x5, each is repeated 3 times for 15 blocks (twice each for 10x5, once each for 5x5).
  3. Convolutions C2 to C4: C2 has kernel 87, dilation 2, and 512 channels; C3 has kernel 1 and 1,024 channels; C4 has kernel 1, with the number of output channels equal to the number of labels (characters).
  4. Loss: Outputs probabilities of characters and the blank at each time step and trains with the CTC loss.

A module within a block consists of four layers (right side of the figure at the top).

Within a block, the same module is repeated RR times, and residual connections are placed between blocks. In Figure 1 of the paper, the block input is passed through a pointwise convolution and batch normalization, added to the batch normalization output of the last module, and then passed through ReLU. The differences from Jasper's block are that the convolutions are separable and that the block in the figure has no dropout.

Model size changes with the number of repetitions (trained on LibriSpeech for 300 epochs, greedy decoding, Table 2 of the paper).

ModelParametersdev-cleandev-other
QuartzNet 5x56.7M5.39%15.69%
QuartzNet 10x512.8M4.14%12.33%
QuartzNet 15x518.9M3.98%11.58%

For normalization, the paper compares batch normalization, Layer Normalization, Instance Normalization, and Group Normalization; batch normalization gave the most stable training and the best word error rate.

Grouped pointwise convolutions: Most of the weights in a separable convolution are in the pointwise convolution (cinΓ—coutc_{\text{in}} \times c_{\text{out}}). The paper also tries making the pointwise convolutions grouped convolutions, mixing information between groups with the same channel shuffle as ShuffleNet (QuartzNet 15x5, Table 3 of the paper).

GroupsParametersdev-cleandev-other
118.9M3.98%11.58%
212.1M4.29%12.52%
48.7M4.51%13.48%

More groups reduce the parameters, but accuracy also drops.

Experimental results

The LibriSpeech results are as follows (word error rate, excerpt from Table 4 of the paper). QuartzNet 15x5 is trained with NovoGrad (the optimizer proposed in the Jasper paper) and cosine annealing, and uses 10% speed perturbation and Cutout that cuts small rectangles out of the spectrogram (SpecCutout) for data augmentation.

ModelLanguage modeltest-cleantest-otherParameters
wav2letter++Convolutional LM3.26%10.47%208M
LAS (SpecAugment)RNN2.5%5.8%360M
Jasper DR 10x5None4.32%11.82%333M
Jasper DR 10x5Transformer-XL2.84%7.84%333M
QuartzNet 15x5None3.90%11.28%18.9M
QuartzNet 15x56-gram2.96%8.07%18.9M
QuartzNet 15x5Transformer-XL2.69%7.25%18.9M

QuartzNet 15x5, with about 1/18 the parameters of Jasper DR 10x5, has a lower word error rate than Jasper DR 10x5 under every condition. The paper states that because separable-convolution models are smaller than ordinary-convolution models and less prone to overfitting, regularization was limited to data augmentation and Weight Decay.

Training time: Training QuartzNet 15x5 for 400 epochs took about 5 days on one DGX-1 server with 8 Tesla V100s. Using mixed precision training and scaling to 32 DGX-2 machines with a batch size of 16K, 1,500 epochs could be trained in about 4.3 hours, and the dev-other word error rate improved from 11.08% to 10.78%.

WSJ (a small dataset of about 80 hours): QuartzNet 5x3 (6.4M parameters) reaches a word error rate on nov92 of 5.8% with a 4-gram language model and 4.5% with Transformer-XL.

Transfer learning: Fine-tuning QuartzNet 15x5, trained on LibriSpeech and Common Voice, on WSJ gives nov92 word error rates of 6.37% without a language model, 3.51% with a 4-gram, and 2.99% with Transformer-XL, better than QuartzNet 5x3 trained on WSJ alone.

Caveats in practice

QuartzNet's temporal context is determined by the kernel lengths and depth of its convolutions. Long kernels (33 to 87) and dilated convolutions cover a wide range, but unlike attention, the model does not look at the entire utterance directly. Also, CTC treats the output at each time step as independent, so spelling and word-order errors tend to remain; in the paper, combining an external language model greatly lowered the word error rate (3.90% β†’ 2.69% on test-clean).

  • Grouping trades parameters for accuracy: Grouping the pointwise convolutions reduces the parameters to 8.7M with 4 groups, but the dev-other word error rate rises from 11.58% to 13.48%.
  • Handling the learning rate: The paper states that adding warmup at the start of training stabilized it. For WSJ training, it uses NovoGrad (Ξ²1=0.95\beta_1 = 0.95, Ξ²2=0.5\beta_2 = 0.5), learning rate 0.05, 1,000 warmup steps, and weight decay 0.001.
  • Use model.eval() for inference: Batch normalization uses the mean and variance collected during training.
  • Implementing depthwise convolutions: In PyTorch, passing the number of input channels to groups of nn.Conv1d gives a depthwise convolution. A pointwise convolution is an nn.Conv1d with kernel length 1.

Comparison with other models

Comparing QuartzNet with a CTC model of the same lineage gives the following (parameters and word error rates for the best LibriSpeech models, with a Transformer-XL language model).

ModelConvolutionKernel length (blocks)Parameterstest-cleantest-other
Jasper DR 10x5Ordinary 1D convolution11–25333M2.84%7.84%
QuartzNet 15x5Time-channel separable convolution33–7518.9M2.69%7.25%

The figures are from Table 4 of the QuartzNet paper. The data augmentation differs: Jasper DR 10x5 uses SpecAugment-like masking and speed perturbation, while QuartzNet 15x5 uses SpecCutout and speed perturbation.

The differences from models of other lineages are as follows.

  • Deep Speech 2: A CTC model that stacks deep bidirectional RNNs on top of convolutions. RNNs can see the whole sequence, but they compute time steps in order, which makes them hard to parallelize on GPUs.
  • Conformer: A model that captures the whole sequence with attention and local patterns with convolutions. In its paper it is trained with an RNN-Transducer.
  • wav2vec 2.0: A model pretrained on untranscribed audio and fine-tuned with CTC. It suits cases with little transcribed data.

Rough guidelines for choosing a model:

  • When you want reasonably high accuracy from a small model, or want to run on-device: QuartzNet is suitable. You can choose down to the 6.7M-parameter 5x5.
  • When you want a simple design with ordinary convolutions: Jasper's design is an easy-to-understand starting point, but it has many more parameters.
  • When accuracy is the top priority: Configurations that incorporate attention, such as Conformer, became the mainstream afterward. Evaluation is generally compared by word error rate (WER).

PyTorch example

Show code
python
import torch
import torch.nn as nn
import torch.nn.functional as F


class TCSConv(nn.Module):
  """Time-channel separable convolution: depthwise 1D conv (per channel) -> pointwise conv (1Γ—1)"""
  def __init__(self, c_in, c_out, k, stride=1, dilation=1):
    super().__init__()
    pad = dilation * (k // 2)
    self.depthwise = nn.Conv1d(c_in, c_in, k, stride=stride, padding=pad, dilation=dilation,
                               groups=c_in, bias=False)            # K Γ— c_in weights
    self.pointwise = nn.Conv1d(c_in, c_out, 1, bias=False)        # c_in Γ— c_out weights

  def forward(self, x):
    return self.pointwise(self.depthwise(x))


class QuartzBlock(nn.Module):
  """R modules (TCSConv -> BN -> ReLU). In the last module, the residual (pointwise conv -> BN) is added to the BN output before ReLU"""
  def __init__(self, c_in, c_out, k, R):
    super().__init__()
    mods = []
    for i in range(R - 1):
      mods += [TCSConv(c_in if i == 0 else c_out, c_out, k), nn.BatchNorm1d(c_out), nn.ReLU()]
    self.mods = nn.Sequential(*mods)
    self.last = TCSConv(c_out if R > 1 else c_in, c_out, k)
    self.last_bn = nn.BatchNorm1d(c_out)
    self.res = nn.Sequential(nn.Conv1d(c_in, c_out, 1, bias=False), nn.BatchNorm1d(c_out))

  def forward(self, x):
    h = self.last_bn(self.last(self.mods(x)))
    return F.relu(h + self.res(x))


def conv_bn_relu(c_in, c_out, k, stride=1, dilation=1):
  # Making C1 and C2 separable too makes the 15x5 parameter total nearly match the 18.9M in Table 1 of the paper
  return nn.Sequential(TCSConv(c_in, c_out, k, stride, dilation), nn.BatchNorm1d(c_out), nn.ReLU())


class QuartzNet(nn.Module):
  """QuartzNet BxR (Table 1 of the paper. repeat=3 gives 15x5, 2 gives 10x5, 1 gives 5x5)"""
  def __init__(self, n_feats=64, n_labels=29, R=5, repeat=3):
    super().__init__()
    cfg = [(33, 256), (39, 256), (51, 512), (63, 512), (75, 512)]  # (kernel K, channels C)
    self.c1 = conv_bn_relu(n_feats, 256, 33, stride=2)
    blocks, c = [], 256
    for k, ch in cfg:
      for _ in range(repeat):
        blocks.append(QuartzBlock(c, ch, k, R))
        c = ch
    self.blocks = nn.Sequential(*blocks)
    self.c2 = conv_bn_relu(c, 512, 87, dilation=2)
    self.c3 = nn.Sequential(nn.Conv1d(512, 1024, 1, bias=False), nn.BatchNorm1d(1024), nn.ReLU())
    self.c4 = nn.Conv1d(1024, n_labels, 1)                         # characters + CTC blank

  def forward(self, feats):
    # feats: (batch, feature dim, time)
    return self.c4(self.c3(self.c2(self.blocks(self.c1(feats)))))


# Compare the number of weights of an ordinary and a separable convolution (K=33, 256->256)
normal = nn.Conv1d(256, 256, 33, bias=False)
separable = TCSConv(256, 256, 33)
print(sum(p.numel() for p in normal.parameters()), sum(p.numel() for p in separable.parameters()))  # 2162688 and 73984

model = QuartzNet()  # 15x5
ctc = nn.CTCLoss(blank=0, zero_infinity=True)
feats = torch.randn(2, 64, 400)
targets = torch.randint(1, 29, (2, 50))
model.train()
log_probs = model(feats).permute(2, 0, 1).log_softmax(-1)          # (time, batch, number of labels)
input_lengths = torch.full((2,), log_probs.size(0), dtype=torch.long)
target_lengths = torch.full((2,), 50, dtype=torch.long)
ctc(log_probs, targets, input_lengths, target_lengths).backward()

model.eval()  # batch norm uses statistics from training
with torch.no_grad():
  best = model(feats).argmax(dim=1)  # greedy decoding; then remove repeated symbols and blanks

FAQ

Q. Why does QuartzNet keep its accuracy despite being much smaller than Jasper?
A.

Because it splits an ordinary 1D convolution (weights KΓ—cinΓ—coutK \times c_{\text{in}} \times c_{\text{out}}) into a depthwise convolution (KΓ—cinK \times c_{\text{in}}) and a pointwise convolution (cinΓ—coutc_{\text{in}} \times c_{\text{out}}). Since the number of weights drops sharply, the kernels can be made about 3 times longer and the number of blocks increased to 15. The paper also cites the fact that small models are less prone to overfitting as an advantage. As a result, with about 1/18 the parameters of Jasper DR 10x5, its word error rate on LibriSpeech is the same or slightly lower.

Q. What does "15x5" in QuartzNet mean?
A.

The number of blocks B=15B = 15 and the number of modules within each block R=5R = 5. The five kinds of blocks, B1 to B5, are each repeated 3 times for 15 blocks. 10x5 repeats each twice and 5x5 once, with 12.8M and 6.7M parameters respectively.

Q. How are QuartzNet and Jasper related?
A.

QuartzNet is based on Jasper and was built by the same NVIDIA group. The overall design of stacked blocks, the placement of one convolution layer before the blocks and three after, the residual connections of the blocks, and the CTC loss are the same as Jasper. The main differences are that the convolutions are time-channel separable and that the kernels are made longer accordingly.

References

  1. Kriman, S., Beliaev, S., Ginsburg, B., Huang, J., Kuchaiev, O., Lavrukhin, V., Leary, R., Li, J., & Zhang, Y. (2019). QuartzNet: Deep Automatic Speech Recognition with 1D Time-Channel Separable Convolutions. arXiv:1910.10261.
  2. Li, J., Lavrukhin, V., Ginsburg, B., Leary, R., Kuchaiev, O., Cohen, J. M., Nguyen, H., & Gadde, R. T. (2019). Jasper: An End-to-End Convolutional Neural Acoustic Model. INTERSPEECH 2019. arXiv:1904.03288.
  3. NVIDIA. NeMo (QuartzNet source code and pretrained models). GitHub.