add-transformer
#2
by
dwgnr
- opened
- .gitattributes +4 -0
- README.md +126 -0
- asr.ckpt +3 -0
- config.json +3 -0
- example.wav +0 -0
- hyperparams.yaml +156 -0
- lm.ckpt +3 -0
- normalizer.ckpt +3 -0
- tokenizer.ckpt +3 -0
.gitattributes
CHANGED
@@ -30,3 +30,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
30 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
31 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
32 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
30 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
31 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
32 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
33 |
+
normalizer.ckpt filter=lfs diff=lfs merge=lfs -text
|
34 |
+
tokenizer.ckpt filter=lfs diff=lfs merge=lfs -text
|
35 |
+
asr.ckpt filter=lfs diff=lfs merge=lfs -text
|
36 |
+
lm.ckpt filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
@@ -1,3 +1,129 @@
|
|
1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
language:
|
3 |
+
- en
|
4 |
+
thumbnail: null
|
5 |
+
tags:
|
6 |
+
- automatic-speech-recognition
|
7 |
+
- CTC
|
8 |
+
- Attention
|
9 |
+
- Transformer
|
10 |
+
- pytorch
|
11 |
+
- speechbrain
|
12 |
license: apache-2.0
|
13 |
+
datasets:
|
14 |
+
- switchboard
|
15 |
+
metrics:
|
16 |
+
- wer
|
17 |
+
- cer
|
18 |
+
|
19 |
---
|
20 |
+
|
21 |
+
<iframe src="https://ghbtns.com/github-btn.html?user=speechbrain&repo=speechbrain&type=star&count=true&size=large&v=2" frameborder="0" scrolling="0" width="170" height="30" title="GitHub"></iframe>
|
22 |
+
<br/><br/>
|
23 |
+
|
24 |
+
# Transformer for Switchboard (with Transformer LM)
|
25 |
+
|
26 |
+
This repository provides all the necessary tools to perform automatic speech
|
27 |
+
recognition from an end-to-end system pretrained on Switchboard (EN) within SpeechBrain.
|
28 |
+
For a better experience, we encourage you to learn more about [SpeechBrain](https://speechbrain.github.io).
|
29 |
+
|
30 |
+
The performance of the model is the following:
|
31 |
+
|
32 |
+
| Release | Swbd WER | Callhome WER | Eval2000 WER | GPUs |
|
33 |
+
|:--------:|:--------:|:------------:|:------------:|:-----------:|
|
34 |
+
| 17-09-22 | 9.80 | 17.89 | 13.94 | 1xA100 40GB |
|
35 |
+
|
36 |
+
|
37 |
+
## Pipeline Description
|
38 |
+
|
39 |
+
This ASR system is composed of 3 different but linked blocks:
|
40 |
+
- Tokenizer (unigram) that transforms words into subword units trained on the Switchboard training transcriptions and the Fisher corpus.
|
41 |
+
- Neural language model (Transformer LM) trained on the Switchboard training transcriptions and the Fisher corpus.
|
42 |
+
- Acoustic model made of a transformer encoder and a joint decoder with CTC +
|
43 |
+
transformer. Hence, the decoding also incorporates the CTC probabilities.
|
44 |
+
|
45 |
+
The system is trained with recordings sampled at 16kHz (single channel).
|
46 |
+
The code will automatically normalize your audio (i.e., resampling + mono channel selection) when calling `transcribe_file` if needed.
|
47 |
+
|
48 |
+
## Install SpeechBrain
|
49 |
+
|
50 |
+
First of all, please install SpeechBrain with the following command:
|
51 |
+
|
52 |
+
```
|
53 |
+
pip install speechbrain
|
54 |
+
```
|
55 |
+
|
56 |
+
Please notice that we encourage you to read our tutorials and learn more about
|
57 |
+
[SpeechBrain](https://speechbrain.github.io).
|
58 |
+
|
59 |
+
## Transcribing Your Own Audio Files
|
60 |
+
|
61 |
+
```python
|
62 |
+
from speechbrain.pretrained import EncoderDecoderASR
|
63 |
+
asr_model = EncoderDecoderASR.from_hparams(source="speechbrain/asr-transformer-switchboard", savedir="pretrained_models/asr-transformer-switchboard")
|
64 |
+
asr_model.transcribe_file("speechbrain/asr-transformer-switchboard/example.wav")
|
65 |
+
```
|
66 |
+
|
67 |
+
## Inference on GPU
|
68 |
+
|
69 |
+
To perform inference on the GPU, add `run_opts={"device":"cuda"}` when calling the `from_hparams` method.
|
70 |
+
|
71 |
+
## Parallel Inference on a Batch
|
72 |
+
|
73 |
+
Please, [see this Colab notebook](https://colab.research.google.com/drive/1hX5ZI9S4jHIjahFCZnhwwQmFoGAi3tmu?usp=sharing) to figure out how to transcribe in parallel a batch of input sentences using a pre-trained model.
|
74 |
+
|
75 |
+
## Training
|
76 |
+
|
77 |
+
The model was trained with SpeechBrain (commit hash: `70904d0`).
|
78 |
+
To train it from scratch follow these steps:
|
79 |
+
|
80 |
+
1. Clone SpeechBrain:
|
81 |
+
```bash
|
82 |
+
git clone https://github.com/speechbrain/speechbrain/
|
83 |
+
```
|
84 |
+
|
85 |
+
2. Install it:
|
86 |
+
```bash
|
87 |
+
cd speechbrain
|
88 |
+
pip install -r requirements.txt
|
89 |
+
pip install -e .
|
90 |
+
```
|
91 |
+
|
92 |
+
3. Run Training:
|
93 |
+
```bash
|
94 |
+
cd recipes/Switchboard/ASR/transformer
|
95 |
+
python train.py hparams/transformer.yaml --data_folder=your_data_folder
|
96 |
+
```
|
97 |
+
|
98 |
+
## Limitations
|
99 |
+
|
100 |
+
The SpeechBrain team does not provide any warranty on the performance achieved by this model when used on other datasets.
|
101 |
+
|
102 |
+
## Credits
|
103 |
+
|
104 |
+
This model was trained with resources provided by the [THN Center for AI](https://www.th-nuernberg.de/en/kiz).
|
105 |
+
|
106 |
+
# About SpeechBrain
|
107 |
+
|
108 |
+
SpeechBrain is an open-source and all-in-one speech toolkit. It is designed to be simple, extremely flexible, and user-friendly.
|
109 |
+
Competitive or state-of-the-art performance is obtained in various domains.
|
110 |
+
|
111 |
+
- Website: https://speechbrain.github.io/
|
112 |
+
- GitHub: https://github.com/speechbrain/speechbrain/
|
113 |
+
- HuggingFace: https://huggingface.co/speechbrain/
|
114 |
+
|
115 |
+
# Citing SpeechBrain
|
116 |
+
|
117 |
+
Please cite SpeechBrain if you use it for your research or business.
|
118 |
+
|
119 |
+
```bibtex
|
120 |
+
@misc{speechbrain,
|
121 |
+
title={{SpeechBrain}: A General-Purpose Speech Toolkit},
|
122 |
+
author={Mirco Ravanelli and Titouan Parcollet and Peter Plantinga and Aku Rouhe and Samuele Cornell and Loren Lugosch and Cem Subakan and Nauman Dawalatabad and Abdelwahab Heba and Jianyuan Zhong and Ju-Chieh Chou and Sung-Lin Yeh and Szu-Wei Fu and Chien-Feng Liao and Elena Rastorgueva and François Grondin and William Aris and Hwidong Na and Yan Gao and Renato De Mori and Yoshua Bengio},
|
123 |
+
year={2021},
|
124 |
+
eprint={2106.04624},
|
125 |
+
archivePrefix={arXiv},
|
126 |
+
primaryClass={eess.AS},
|
127 |
+
note={arXiv:2106.04624}
|
128 |
+
}
|
129 |
+
```
|
asr.ckpt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ac0c043fd86ac73bb59ae43450b1a9df4a172eb4ca5af398d3e6e32e95410f02
|
3 |
+
size 111661649
|
config.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"speechbrain_interface": "EncoderDecoderASR"
|
3 |
+
}
|
example.wav
ADDED
Binary file (925 kB). View file
|
|
hyperparams.yaml
ADDED
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ############################################################################
|
2 |
+
# Model: E2E ASR with Transformer
|
3 |
+
# Encoder: Transformer Encoder
|
4 |
+
# Decoder: Transformer Decoder + (CTC/ATT joint) beamsearch + TransformerLM
|
5 |
+
# Tokens: unigram
|
6 |
+
# losses: CTC + KLdiv (Label Smoothing loss)
|
7 |
+
# Training: Switchboard
|
8 |
+
# Authors: Jianyuan Zhong, Titouan Parcollet, Samuele Cornell, Dominik Wagner
|
9 |
+
# ############################################################################
|
10 |
+
|
11 |
+
# Feature parameters
|
12 |
+
sample_rate: 16000
|
13 |
+
n_fft: 400
|
14 |
+
n_mels: 80
|
15 |
+
|
16 |
+
####################### Model parameters ###########################
|
17 |
+
# Transformer
|
18 |
+
transformer_input_size: 1280
|
19 |
+
d_model: 256
|
20 |
+
nhead: 4
|
21 |
+
num_encoder_layers: 12
|
22 |
+
num_decoder_layers: 6
|
23 |
+
d_ffn: 2048
|
24 |
+
transformer_dropout: 0.1
|
25 |
+
activation: !name:torch.nn.GELU
|
26 |
+
output_neurons: 2000
|
27 |
+
|
28 |
+
# Outputs
|
29 |
+
blank_index: 0
|
30 |
+
label_smoothing: 0.1
|
31 |
+
pad_index: 0
|
32 |
+
bos_index: 1
|
33 |
+
eos_index: 2
|
34 |
+
# unk_index: 0
|
35 |
+
|
36 |
+
# Decoding parameters
|
37 |
+
min_decode_ratio: 0.0
|
38 |
+
max_decode_ratio: 1.0
|
39 |
+
valid_search_interval: 10
|
40 |
+
valid_beam_size: 10
|
41 |
+
lm_weight: 0.30
|
42 |
+
test_beam_size: 60
|
43 |
+
ctc_weight_decode: 0.30
|
44 |
+
temperature: 1.0
|
45 |
+
temperature_lm: 1.0
|
46 |
+
using_eos_threshold: False
|
47 |
+
eos_threshold: 1.5
|
48 |
+
length_normalization: True
|
49 |
+
using_max_attn_shift: False
|
50 |
+
max_attn_shift: 30
|
51 |
+
|
52 |
+
CNN: !new:speechbrain.lobes.models.convolution.ConvolutionFrontEnd
|
53 |
+
input_shape: (8, 10, 80)
|
54 |
+
num_blocks: 3
|
55 |
+
num_layers_per_block: 1
|
56 |
+
out_channels: (64, 64, 64)
|
57 |
+
kernel_sizes: (5, 5, 1)
|
58 |
+
strides: (2, 2, 1)
|
59 |
+
residuals: (False, False, True)
|
60 |
+
|
61 |
+
Transformer: !new:speechbrain.lobes.models.transformer.TransformerASR.TransformerASR # yamllint disable-line rule:line-length
|
62 |
+
input_size: !ref <transformer_input_size>
|
63 |
+
tgt_vocab: !ref <output_neurons>
|
64 |
+
d_model: !ref <d_model>
|
65 |
+
nhead: !ref <nhead>
|
66 |
+
num_encoder_layers: !ref <num_encoder_layers>
|
67 |
+
num_decoder_layers: !ref <num_decoder_layers>
|
68 |
+
d_ffn: !ref <d_ffn>
|
69 |
+
dropout: !ref <transformer_dropout>
|
70 |
+
activation: !ref <activation>
|
71 |
+
encoder_module: transformer
|
72 |
+
attention_type: regularMHA
|
73 |
+
normalize_before: True
|
74 |
+
causal: False
|
75 |
+
|
76 |
+
lm_model: !new:speechbrain.lobes.models.transformer.TransformerLM.TransformerLM # yamllint disable-line rule:line-length
|
77 |
+
vocab: !ref <output_neurons>
|
78 |
+
d_model: 264
|
79 |
+
d_embedding: 128
|
80 |
+
nhead: 12
|
81 |
+
num_encoder_layers: 12
|
82 |
+
num_decoder_layers: 0
|
83 |
+
d_ffn: 1024
|
84 |
+
dropout: 0.1
|
85 |
+
activation: !name:torch.nn.ReLU
|
86 |
+
normalize_before: False
|
87 |
+
|
88 |
+
tokenizer: !new:sentencepiece.SentencePieceProcessor
|
89 |
+
|
90 |
+
ctc_lin: !new:speechbrain.nnet.linear.Linear
|
91 |
+
input_size: !ref <d_model>
|
92 |
+
n_neurons: !ref <output_neurons>
|
93 |
+
|
94 |
+
seq_lin: !new:speechbrain.nnet.linear.Linear
|
95 |
+
input_size: !ref <d_model>
|
96 |
+
n_neurons: !ref <output_neurons>
|
97 |
+
|
98 |
+
asr_model: !new:torch.nn.ModuleList
|
99 |
+
- [!ref <CNN>, !ref <Transformer>, !ref <seq_lin>, !ref <ctc_lin>]
|
100 |
+
|
101 |
+
log_softmax: !new:torch.nn.LogSoftmax
|
102 |
+
dim: -1
|
103 |
+
|
104 |
+
normalizer: !new:speechbrain.processing.features.InputNormalization
|
105 |
+
norm_type: global
|
106 |
+
|
107 |
+
compute_features: !new:speechbrain.lobes.features.Fbank
|
108 |
+
sample_rate: !ref <sample_rate>
|
109 |
+
n_fft: !ref <n_fft>
|
110 |
+
n_mels: !ref <n_mels>
|
111 |
+
|
112 |
+
Tencoder: !new:speechbrain.lobes.models.transformer.TransformerASR.EncoderWrapper
|
113 |
+
transformer: !ref <Transformer>
|
114 |
+
|
115 |
+
encoder: !new:speechbrain.nnet.containers.LengthsCapableSequential
|
116 |
+
input_shape: [null, null, !ref <n_mels>]
|
117 |
+
compute_features: !ref <compute_features>
|
118 |
+
normalize: !ref <normalizer>
|
119 |
+
cnn: !ref <CNN>
|
120 |
+
transformer_encoder: !ref <Tencoder>
|
121 |
+
|
122 |
+
decoder: !new:speechbrain.decoders.S2STransformerBeamSearch
|
123 |
+
modules: [!ref <Transformer>, !ref <seq_lin>, !ref <ctc_lin>]
|
124 |
+
bos_index: !ref <bos_index>
|
125 |
+
eos_index: !ref <eos_index>
|
126 |
+
blank_index: !ref <blank_index>
|
127 |
+
min_decode_ratio: !ref <min_decode_ratio>
|
128 |
+
max_decode_ratio: !ref <max_decode_ratio>
|
129 |
+
beam_size: !ref <test_beam_size>
|
130 |
+
ctc_weight: !ref <ctc_weight_decode>
|
131 |
+
lm_weight: !ref <lm_weight>
|
132 |
+
lm_modules: !ref <lm_model>
|
133 |
+
temperature: !ref <temperature>
|
134 |
+
temperature_lm: !ref <temperature_lm>
|
135 |
+
using_eos_threshold: !ref <using_eos_threshold>
|
136 |
+
eos_threshold: !ref <eos_threshold>
|
137 |
+
length_normalization: !ref <length_normalization>
|
138 |
+
using_max_attn_shift: !ref <using_max_attn_shift>
|
139 |
+
max_attn_shift: !ref <max_attn_shift>
|
140 |
+
|
141 |
+
modules:
|
142 |
+
compute_features: !ref <compute_features>
|
143 |
+
normalizer: !ref <normalizer>
|
144 |
+
pre_transformer: !ref <CNN>
|
145 |
+
transformer: !ref <Transformer>
|
146 |
+
asr_model: !ref <asr_model>
|
147 |
+
lm_model: !ref <lm_model>
|
148 |
+
encoder: !ref <encoder>
|
149 |
+
decoder: !ref <decoder>
|
150 |
+
|
151 |
+
pretrainer: !new:speechbrain.utils.parameter_transfer.Pretrainer
|
152 |
+
loadables:
|
153 |
+
normalizer: !ref <normalizer>
|
154 |
+
asr: !ref <asr_model>
|
155 |
+
lm: !ref <lm_model>
|
156 |
+
tokenizer: !ref <tokenizer>
|
lm.ckpt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4e52dfb1d4d23ae2e861feffb04eadd94c8e34537c74633263966294becaa6ab
|
3 |
+
size 45759305
|
normalizer.ckpt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4537250f5851871c7eb0871bf72ef32a0096bae22d43f120ff6cf0a63c2443db
|
3 |
+
size 1703
|
tokenizer.ckpt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:25f80ce1b720439d9ebc46a6d3aa399bc2018eaf001084f6f63dc4b7e35f25d0
|
3 |
+
size 270824
|