Data Augmentation for Speech Recognition
Tags: datascience, speechrecognition, ai, nlp
Published: 2019-06-13 03:34:59

---
title: Data Augmentation for Speech Recognition
published: true
tags: data-science,speech-recognition,artificial-intellige,nlp
canonical_url: https://towardsdatascience.com/data-augmentation-for-speech-recognition-e7c607482e78
---

#### Automatic Speech Recognition (ASR)

![](https://cdn-images-1.medium.com/max/1024/0*iD9ioERFLy_BIX4f)<figcaption>Photo by <a href="https://unsplash.com/@makcedward?utm_source=medium&amp;utm_medium=referral">Edward Ma</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption>

The objective of Speech Recognition is converting audio to text. This technology is applied in our life widely. [Google Assistant](https://en.wikipedia.org/wiki/Google_Assistant) and [Amazon Alexa](https://en.wikipedia.org/wiki/Amazon_Alexa) are some of the examples which taking our voice as input and converting to text to understand our intention.

Same as other NLP problem, one of critical challenge is lack of adequate volume of training data. It leads overfit or hard to tackle unseen data. [Google Brain](https://ai.google/research/teams/brain/) team with AI Resident come to tackle this problem by introducing several data augmentation method for speech recognition. This story will discuss about [SpecAugment: A Simple Data Augmentation Method for Automatic Speech Recognition](https://arxiv.org/pdf/1904.08779.pdf) (Park et al., 2019) and the following are will be covered:

- Data
- Architecture
- Experiment

### Data

To process data, waveform audio converts to spectrogram and feeding to neural network to generate output. Traditional way to perform data augmentation is normally applied to waveform. Park et al. go for another approach which is manipulate spectrogram.

![](https://cdn-images-1.medium.com/max/640/0*DMFTlxD5-3rhmcks.png)<figcaption>Waveform audio to spectrogram (<a href="https://ai.googleblog.com/2019/04/specaugment-new-data-augmentation.html">Google Brain</a>)</figcaption>

Given a spectrogram, you can view it as an image where x axis is time while y axis is frequency.

![](https://cdn-images-1.medium.com/max/1000/0*d3wpu740AzHNtsof.png)<figcaption>Spectrogram representation (<a href="https://librosa.github.io/librosa/generated/librosa.feature.melspectrogram.html">librosa</a>)</figcaption>

Intuitively, it improves training speed because no data transformation between waveform data to spectrogram data but augmenting spectrogram data.

Park et al. introduced SpecAugment for data augmentation in speech recognition. There are 3 basic ways to augment data which are time warping, frequency masking and time masking. In their experiment, they combine these ways to together and introducing 4 different combinations which are LibriSpeech basic (LB), LibriSpeech double (LD), Switchboard mild (SM) and Switchboard strong (SS).

#### **_Time Warping_**

A random point will be selected and warping to either left or right with a distance w which chosen from a uniform distribution from 0 to the time warp parameter W along that line.

#### Frequency Masking

A frequency channels [f0, f0 + f) are masked. f is chosen from a uniform distribution from 0 to the frequency mask parameter F, and f0 is chosen from (0, ν − f) where ν is the number of frequency channels.

#### Time Masking

t consecutive time steps [t0, t0 + t) are masked. t is chosen from a uniform distribution from 0 to the time mask parameter T, and t0 is chosen from [0, τ − t).

![](https://cdn-images-1.medium.com/max/504/1*xq6oahbJzFI9HdwY1fdWJw.png)<figcaption>From top to bottom, the figures depict the log mel spectrogram of the base input with no augmentation, time warp, frequency masking and time masking applied. (Park et al., 2019)</figcaption>

#### Combination of basic augmentation policy

By combing the augmentation policy of Frequency Masking and Time Masking, 4 new augmentation policies are introduced. While the symbols denote:

- W: Time Warping Parameter
- F: Frequency Masking Parameter
- mF: Number of frequency masking applied
- T: Time Masking Parameter
- mT: Number of time masking applied

![](https://cdn-images-1.medium.com/max/521/1*xfOBzbams8Z27HLVvTRvFA.png)<figcaption>Configuration for LB, LD, SM and SS (Park et al., 2019)</figcaption>

![](https://cdn-images-1.medium.com/max/540/1*PFcBVKIa4zWtcnwBjvy2NA.png)<figcaption>From top to bottom, the figures depict the log mel spectrogram of the base input with policies None, LB and LD applied. (Park et al., 2019)</figcaption>

### Architecture

#### Listen, Attend and Spell (LAS) Network Architecture

Park et al. uses LAS network architecture to verify the performance with and without data augmentation. It includes 2 layers of Convolutional Neural Network (CNN), attention and stacked bi-directional LSTMs. As the objective of this paper is data augmentation and the model is leveraged to see the impact of models, you can deep dive into LAS from [here](https://arxiv.org/pdf/1508.01211.pdf).

#### Learning Rate Schedules

Learning rate schedule turn out to be come a critical factor to determine model performance. Similar to [Slanted triangular learning rates (STLR)](https://towardsdatascience.com/multi-task-learning-in-language-model-for-text-classification-c3acc1fedd89), a non-static learning rate is applied. Learning rate will be decay exponentially until it reaches 1/100 of its maximum value and keeping it as constant beyond this point. Some parameters are denoted:

- sr: Step of the ramp-up (from zero learning rate) is complete
- si: Step of the exponential decay starts
- sf: Step of the exponential decay stops.

Another learning rate schedule is uniform label smoothing. The correct class label is assigned the confidence 0.9, while the confidence of the other labels are increased accordingly. Parameter is denoted:

- snoise: Variational weight noise

In later experiment, three standard learning rate schedules are defined:

1. B(asic): (sr, snoise, si, sf ) = (0.5k, 10k, 20k, 80k)
2. D(ouble): (sr, snoise, si, sf ) = (1k, 20k, 40k, 160k)
3. L(ong): (sr, snoise, si, sf ) = (1k, 20k, 140k, 320k)

#### Langauge Models (LM)

LM is applied to further boost up the model performance. In general, LM is designed to predict next token given consequence of previous tokens. Once a new token is predicted, it will be treat as “previous token” when predicting next tokens. This approach is applied in lots of modern NLP model such as [BERT](https://towardsdatascience.com/how-bert-leverage-attention-mechanism-and-transformer-to-learn-word-contextual-relations-5bbee1b6dbdb) and [GPT-2](https://towardsdatascience.com/too-powerful-nlp-model-generative-pre-training-2-4cc6afb6655).

### Experiment

Model performance is measured by [Word Error Rate](https://en.wikipedia.org/wiki/Word_error_rate) (WER).

From the below figure, “Sch” denotes as learning rate schedule while “Pol” denotes as augmentation policy. We can see that LAS with 6 LSTM layer and 1280 embedding vector perform the best result.

![](https://cdn-images-1.medium.com/max/490/1*gAVZttVQlypTtT6Cbncqzw.png)<figcaption>Evaluation of LibriSpeech (Park et al., 2019)</figcaption>

By using LAS-6–1280 with SpecAugment perform the best result when comparing to other model and LAS without data augmentation.

![](https://cdn-images-1.medium.com/max/491/1*74sHvUtwGvuN04nCZ9tfRg.png)<figcaption>Comparing SpecAugment method in LibriSpeech 960h (Park et al., 2019)</figcaption>

In Switchboard 300h, LAS-4–1024 is applied to be benchmark. We can see that SpecAugment did help on further boost up model performance.

![](https://cdn-images-1.medium.com/max/485/1*TeKA8tmEsyNxBu-E0m9FbA.png)<figcaption>Comparing SpecAugment method in Switchboard 300h (Park et al., 2019)</figcaption>

### Take Away

- Time warping did not improve model performance a lot. If resource is limited, this approach will be discarded.
- Label smoothing leads instability to training.
- Data augmentation converts over-fit problem to under-fit problems. From below figures, you can notice that the model without augmentation (None) perform nearly perfect in training set while no similar result is performed in other dataset.

![](https://cdn-images-1.medium.com/max/445/1*210d_HNZ72-BAA0VUmCxyA.png)

- To facilitate data augmentation for speech recognition, [nlpaug](https://github.com/makcedward/nlpaug) supports SpecAugment methods now.

### About Me

I am Data Scientist in Bay Area. Focusing on state-of-the-art in Data Science, Artificial Intelligence , especially in NLP and platform related. Feel free to connect with [me](https://makcedward.github.io/) on [LinkedIn](https://www.linkedin.com/in/edwardma1026) or following me on [Medium](http://medium.com/@makcedward/) or [Github](https://github.com/makcedward).

### Extension Reading

- [Data Augmentation in NLP](https://towardsdatascience.com/data-augmentation-in-nlp-2801a34dfc28)
- [Data Augmentation for Text](https://towardsdatascience.com/data-augmentation-library-for-text-9661736b13ff)
- [Data Augmentation for Audio](https://towardsdatascience.com/data-augmentation-for-audio-76912b01fdf6)
- [Official release of SpecAugment from Google](https://ai.googleblog.com/2019/04/specaugment-new-data-augmentation.html)
- [Slanted triangular learning rates (STLR)](https://towardsdatascience.com/multi-task-learning-in-language-model-for-text-classification-c3acc1fedd89)
- [Bidirectional Encoder Representations from Transformers](https://towardsdatascience.com/how-bert-leverage-attention-mechanism-and-transformer-to-learn-word-contextual-relations-5bbee1b6dbdb)
- [Generative Pre-Training 2](https://towardsdatascience.com/too-powerful-nlp-model-generative-pre-training-2-4cc6afb6655)

### Reference

- D. S. Park, W. Chan, Y. Zhang, C. C. Chiu, B. Zoph, E. D. Cubuk and Q. V. Le. [SpecAugment: A Simple Data Augmentation Method for Automatic Speech Recognition](https://arxiv.org/pdf/1904.08779.pdf). 2019
- W. Chan, N. Jaitly, Q. V. Le and O. Vinyals. [Listen, Attend and Spell](https://arxiv.org/pdf/1508.01211.pdf). 2015

* * *