AI Logic

Data Augmentation

MixSpeech

Updated:

MixSpeech diagram. The left shows one training step (pair up part of the mini-batch, sample λ, mix the acoustic features, speech recognition model, compute the losses against two transcripts, mix the losses with λ). The right shows an example with λ = 0.7: the input formed by adding two spectrograms, and the equation that mixes the losses for two transcripts of different lengths with weights 0.7 and 0.3

What is MixSpeech

MixSpeech is a data augmentation method for speech recognition that feeds the model a weighted sum of the acoustic features of two utterances and trains it to recognize both transcripts. The features can be mel spectrograms, MFCCs, and so on. It was proposed by Meng et al. in 2021 (ICASSP 2021).

It builds on Mixup, a method widely used in image classification. Mixup mixes inputs and labels in the same proportion, but in speech recognition the label is a "sequence of text," so it cannot be mixed as is.

  • The two transcripts usually differ in length, so they cannot be added together.
  • A transcript is a sequence of discrete symbols (tokens), which cannot be added.
  • Adding them in an embedding space would teach the model to output a "blended sentence" of the two, which departs from the actual goal of recognizing one sentence from one utterance.

MixSpeech therefore leaves the transcripts unmixed and instead mixes the losses computed against each of the two transcripts, using the same weight as for the input.

Xmix=λXi+(1−λ)XjX_{mix} = \lambda X_i + (1 - \lambda) X_j Lmix=λ L(Xmix,Yi)+(1−λ) L(Xmix,Yj),λ∼Beta(α,α)\mathcal{L}_{mix} = \lambda\, \mathcal{L}(X_{mix}, Y_i) + (1 - \lambda)\, \mathcal{L}(X_{mix}, Y_j), \qquad \lambda \sim \mathrm{Beta}(\alpha, \alpha)

Here, XiX_i and YiY_i are the acoustic features and transcript of the ii-th example, and L(⋅,⋅)\mathcal{L}(\cdot, \cdot) is the speech recognition loss. The features are added frame by frame (a frame is a short slice of time).

For example, with λ=0.7\lambda = 0.7 (right side of the figure at the top), the loss for producing the 5-token transcript YiY_i from the mixed audio gets a weight of 0.7, and the loss for producing the 3-token transcript YjY_j gets 0.3. Think of it as practice in listening to a recording of two people talking at once: catching mainly what the louder speaker says, while also picking up the quieter one.

Training procedure

One training step (one mini-batch) proceeds as follows (left side of the figure at the top).

  1. Load a mini-batch (acoustic features XX and transcripts YY).
  2. Select a fraction τ\tau of the examples in the mini-batch and pair them up. The remaining examples are trained normally (without mixing). The paper's default is τ=15%\tau = 15\%.
  3. Sample the mixing ratio λ\lambda from Beta(α,α)\mathrm{Beta}(\alpha, \alpha). The paper's default is α=0.5\alpha = 0.5.
  4. Add the features of each pair frame by frame in the ratio λ:(1−λ)\lambda : (1 - \lambda) to form XmixX_{mix}.
  5. Feed XmixX_{mix} to the speech recognition model and compute the loss Li\mathcal{L}_i with YiY_i as the target and the loss Lj\mathcal{L}_j with YjY_j as the target.
  6. Mix the losses as Lmix=λLi+(1−λ)Lj\mathcal{L}_{mix} = \lambda \mathcal{L}_i + (1 - \lambda) \mathcal{L}_j and update the weights with the gradient.

The models in the paper are trained with a combination of CTC Loss and the decoder's cross-entropy. The loss L\mathcal{L} in step 5 is therefore the following sum.

LMTL=β LCTC+(1−β) LCE\mathcal{L}_{MTL} = \beta\, \mathcal{L}_{CTC} + (1 - \beta)\, \mathcal{L}_{CE}

The paper uses β=0.3\beta = 0.3. Because MixSpeech does not depend on what the loss is, it applies in the same form to models trained with CTC alone or cross-entropy alone.

In practice, MixSpeech's only hyperparameter is the distribution of the mixing ratio (α\alpha). The paper cites easy tuning as an advantage over SpecAugment, which requires setting many values such as the time warp, mask widths, and number of masks.

Why it works

The paper explains why MixSpeech works as follows.

  • The other utterance acts as a "distracting signal": Because another utterance is overlaid on the input, the model learns to pick out the part of the audio that corresponds to the correct transcript without being misled. The paper argues that augmentations that only alter a single utterance, such as masking or changing speed or pitch, do not have this effect.
  • The labels stay unchanged: Since the transcripts are not mixed, the model is never trained to output a nonexistent "blended sentence." The loss weights tell it how much to emphasize each transcript.
  • A harder task generalizes better: Extracting two transcripts from a mixed input is harder than ordinary training. The paper carries over the idea that Mixup improves the generalization bound of empirical risk minimization.

Because the task becomes harder, the paper trains models that use MixSpeech for longer. It notes that extending the baseline's training time did not improve its results in preliminary experiments.

Results reported in the paper

The paper compares no augmentation (baseline), SpecAugment, and MixSpeech on three low-resource speech recognition datasets. The numbers are error rates (lower is better): phone error rate (PER) for TIMIT and word error rate (WER) for WSJ and HKUST.

ModelDatasetBaseline+ SpecAugment+ MixSpeech
Listen, Attend and Spell (LAS)TIMIT (PER)21.8%20.5%19.5%
TransformerTIMIT (PER)23.1%22.5%21.8%
TransformerWSJ (WER)5.9%5.4%4.7%
TransformerHKUST (WER, Chinese)23.9%23.5%22.9%
  • Datasets: TIMIT (English phone recognition), WSJ (read English newspaper text, about 81 hours), and HKUST (Chinese telephone conversations, about 168 hours for training).
  • Input features: Filter bank features computed from 16 kHz audio (23 dimensions for TIMIT, 80 for the others).
  • Models: LAS has a 4-layer bidirectional LSTM encoder (width 320) and a 1-layer LSTM decoder (width 300). The Transformer has a 12-layer encoder and a 6-layer decoder (width 256). Both are implemented in ESPnet and decode with beam search using a beam width of 20.

The paper's abstract states that MixSpeech "improves PER by a relative 10.6% over SpecAugment on TIMIT," but computing from the numbers in the main text and table (21.8% → 19.5% with LAS) shows that 10.6% is the improvement over the baseline. The relative improvement over SpecAugment (20.5%) is about 4.9%.

Choosing settings (ablations in the paper)

The paper runs comparisons with different settings on TIMIT with the Transformer (PER).

Fraction τ\tau of the mini-batch that MixSpeech is applied to

τ\tau0% (baseline)15%20%30%
PER23.1%21.8%21.9%22.0%

Every value of τ\tau beat the baseline, and the results depended little on τ\tau.

Comparison with other mixing schemes and noise

MethodPER
Baseline (no augmentation)23.1%
Mixing three utterances at 1/3 each (Tri-mixup)35.8%
Adding Gaussian noise (SNR 5 dB)22.0%
MixSpeech21.8%
  • Mix two utterances, not more: Mixing three utterances made the error rate much worse than the baseline. The paper attributes this to adding too much information beyond the original audio, which prevents the model from learning useful patterns.
  • More effective than adding noise: MixSpeech achieved a lower error rate than regularization by adding noise.

Weight β\beta between CTC and cross-entropy (baseline only)

β\beta0 (cross-entropy only)0.30.50.7
PER26.6%23.0%23.1%23.7%

Cross-entropy alone performed poorly; supplementing it with alignment information from the CTC loss was important. Based on this, both the baseline and MixSpeech use β=0.3\beta = 0.3.

Caveats

Mix the losses, not the transcripts: Trying to mix the labels (transcripts) as Mixup does either fails because the lengths do not match or trains the model on sentences that do not exist. Only the input acoustic features and the weights of the two losses are mixed.

  • Mix only part of the mini-batch: The paper applies MixSpeech to only 15% of each mini-batch and trains the rest normally. Mixing every example removes the chance to learn from unmixed audio.
  • Train longer: Extracting two transcripts from mixed audio is a hard task, and the paper trains models that use MixSpeech for longer.
  • Decide how to handle utterances of different lengths: The paper only says that features are added frame by frame and does not describe what happens when lengths differ. An implementation has to choose a method itself, such as padding the shorter one with silence (e.g., zeros) to match the lengths.
  • Evaluated on small datasets: The paper's experiments are at the scale of TIMIT, WSJ, and HKUST (a few hours to around 170 hours). The effect on large datasets of thousands of hours is not examined in the paper.
  • Not used at inference: MixSpeech is used only during training. At recognition time, a single utterance is fed in as is.

Comparison with similar data augmentation methods and how to choose

The table below lines up MixSpeech with similar data augmentation methods for speech recognition and image classification from the same angles.

MethodWhat it does to the inputHow labels are handledMain settings to tuneSuited tasks
MixupAdds two inputs togetherMixes the labels in the same ratioα\alphaClassification (one label)
MixSpeechAdds the acoustic features of two utterancesDoes not mix them; mixes the two losses in the same ratioα\alpha (and τ\tau)Sequence generation such as speech recognition
SpecAugmentWarps the spectrogram in time and masks time and frequency bandsUnchangedWarp size, mask widths and counts, etc.Speech recognition
Speed perturbationChanges the speed of the audioUnchangedSpeed factorsSpeech recognition

Rough guidelines for choosing:

  • Speech recognition with little training data, and less tuning effort is wanted: Try MixSpeech. In the paper, it achieved lower error rates than SpecAugment on all of TIMIT, WSJ, and HKUST.
  • SpecAugment is already in use: MixSpeech only changes how inputs are built and how losses are mixed, so the two can be combined. However, the paper does not report results for the combination, so verify it on validation data.
  • Classification tasks (such as identifying the type of sound): There is only one label, so ordinary Mixup is enough.

PyTorch example

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


def mixspeech_loss(model, feats, feat_lens, texts, text_lens, alpha=0.5, tau=0.15):
    """MixSpeech loss (Meng et al., 2021).

    feats:     (B, T, D) acoustic features (filter banks, etc.). Short utterances are zero-padded
    feat_lens: (B,) number of frames in each utterance
    texts:     (B, U) target token sequences. text_lens: (B,) length of each transcript
    model(feats, feat_lens, texts, text_lens) is assumed to return a per-example loss (B,)
    (in the paper, β·CTC + (1 − β)·cross-entropy, β = 0.3).
    """
    B = feats.size(0)
    n_mix = int(B * tau) // 2 * 2           # pair up a fraction τ of the examples
    if n_mix == 0:
        return model(feats, feat_lens, texts, text_lens).mean()
    perm = torch.randperm(B, device=feats.device)
    idx_i, idx_j = perm[: n_mix // 2], perm[n_mix // 2 : n_mix]
    rest = perm[n_mix:]

    # 1) train the remaining examples normally
    loss_plain = model(feats[rest], feat_lens[rest], texts[rest], text_lens[rest])

    # 2) sample λ ~ Beta(α, α) and add the features frame by frame
    lam = torch.distributions.Beta(alpha, alpha).sample().item()
    x_mix = lam * feats[idx_i] + (1 - lam) * feats[idx_j]
    # The paper does not say how to handle different lengths. Here, use the longer one (the zero padding of the shorter one gets added)
    mix_lens = torch.maximum(feat_lens[idx_i], feat_lens[idx_j])

    # 3) do not mix the transcripts; mix the losses against each target with λ
    loss_i = model(x_mix, mix_lens, texts[idx_i], text_lens[idx_i])
    loss_j = model(x_mix, mix_lens, texts[idx_j], text_lens[idx_j])
    loss_mix = lam * loss_i + (1 - lam) * loss_j

    # average weighted by the number of examples
    return torch.cat([loss_plain, loss_mix]).mean()


# Use only during training. At inference (model.eval()), feed a single utterance as is
# model.train()
# loss = mixspeech_loss(model, feats, feat_lens, texts, text_lens)
# loss.backward()

FAQ

Q. How does it differ from Mixup?
A.

The inputs are added together in the same way. The difference is how labels are handled: Mixup also mixes the labels with λ\lambda, whereas MixSpeech leaves the transcripts unmixed and mixes, with λ\lambda, the losses computed against each of the two transcripts. This is because transcripts differ in length and cannot be added.

Q. Is audio also mixed at inference time?
A.

No. MixSpeech is a data augmentation used only during training; at recognition time, the acoustic features of a single utterance are fed to the model as is.

Q. Can it be used together with SpecAugment?
A.

In principle, yes. MixSpeech only changes how inputs and losses are mixed, while SpecAugment only masks or warps the spectrogram, so they do not conflict. However, the paper does not report results for combining the two, so the effect needs to be checked on validation data.

References

  1. Meng, L., Xu, J., Tan, X., Wang, J., Qin, T., & Xu, B. (2021). MixSpeech: Data Augmentation for Low-resource Automatic Speech Recognition. ICASSP 2021.
  2. Zhang, H., Cisse, M., Dauphin, Y. N., & Lopez-Paz, D. (2018). mixup: Beyond Empirical Risk Minimization. ICLR 2018.