add transformer model
Browse files- .gitattributes +4 -0
- README.md +119 -0
- asr.ckpt +3 -0
- config.json +3 -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,122 @@
|
|
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 |
+
- ser
|
18 |
---
|
19 |
+
|
20 |
+
<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>
|
21 |
+
<br/><br/>
|
22 |
+
|
23 |
+
# Transformer for Switchboard (with Transformer LM)
|
24 |
+
|
25 |
+
This repository provides all the necessary tools to perform automatic speech
|
26 |
+
recognition from an end-to-end system pretrained on Switchboard within
|
27 |
+
SpeechBrain. For a better experience, we encourage you to learn more about
|
28 |
+
[SpeechBrain](https://speechbrain.github.io).
|
29 |
+
The performance of the model is the following:
|
30 |
+
|
31 |
+
|
32 |
+
| Release | Swbd SER | Callhome SER | Eval2000 SER | Swbd WER | Callhome WER | Eval2000 WER | GPUs |
|
33 |
+
|:--------:|:--------:|:------------:|:------------:|:--------:|:------------:|:------------:|:-----------:|
|
34 |
+
| 17-09-22 | 49.30 | 56.89 | 54.20 | 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 and trained with
|
41 |
+
the train transcriptions of LibriSpeech.
|
42 |
+
- Neural language model (Transformer LM) trained on the Switchboard training set and the Fisher corpus.
|
43 |
+
- Acoustic model made of a transformer encoder and a joint decoder with CTC +
|
44 |
+
transformer. Hence, the decoding also incorporates the CTC probabilities.
|
45 |
+
|
46 |
+
The system is trained with recordings sampled at 16kHz (single channel).
|
47 |
+
The code will automatically normalize your audio (i.e., resampling + mono channel selection) when calling *transcribe_file* if needed.
|
48 |
+
|
49 |
+
## Install SpeechBrain
|
50 |
+
|
51 |
+
First of all, please install SpeechBrain with the following command:
|
52 |
+
|
53 |
+
```
|
54 |
+
pip install speechbrain
|
55 |
+
```
|
56 |
+
|
57 |
+
Please notice that we encourage you to read our tutorials and learn more about
|
58 |
+
[SpeechBrain](https://speechbrain.github.io).
|
59 |
+
|
60 |
+
### Transcribing your own audio files (in English)
|
61 |
+
|
62 |
+
```python
|
63 |
+
from speechbrain.pretrained import EncoderDecoderASR
|
64 |
+
asr_model = EncoderDecoderASR.from_hparams(source="speechbrain/asr-transformer-switchboard", savedir="pretrained_models/asr-transformer-switchboard")
|
65 |
+
asr_model.transcribe_file("path/to/your/audiofile")
|
66 |
+
```
|
67 |
+
### Inference on GPU
|
68 |
+
To perform inference on the GPU, add `run_opts={"device":"cuda"}` when calling the `from_hparams` method.
|
69 |
+
|
70 |
+
## Parallel Inference on a Batch
|
71 |
+
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.
|
72 |
+
|
73 |
+
### Training
|
74 |
+
The model was trained with SpeechBrain (Commit hash: '70904d0').
|
75 |
+
To train it from scratch follow these steps:
|
76 |
+
1. Clone SpeechBrain:
|
77 |
+
```bash
|
78 |
+
git clone https://github.com/speechbrain/speechbrain/
|
79 |
+
```
|
80 |
+
2. Install it:
|
81 |
+
```bash
|
82 |
+
cd speechbrain
|
83 |
+
pip install -r requirements.txt
|
84 |
+
pip install -e .
|
85 |
+
```
|
86 |
+
|
87 |
+
3. Run Training:
|
88 |
+
```bash
|
89 |
+
cd recipes/Switchboard/ASR/transformer
|
90 |
+
python train.py hparams/transformer.yaml --data_folder=your_data_folder
|
91 |
+
```
|
92 |
+
|
93 |
+
You can find our training results (models, logs, etc) [here](https://drive.google.com/drive/folders/1ZudxqMWb8VNCJKvY2Ws5oNY3WI1To0I7?usp=sharing).
|
94 |
+
|
95 |
+
### Limitations
|
96 |
+
The SpeechBrain team does not provide any warranty on the performance achieved by this model when used on other datasets.
|
97 |
+
|
98 |
+
# **About SpeechBrain**
|
99 |
+
- Website: https://speechbrain.github.io/
|
100 |
+
- Code: https://github.com/speechbrain/speechbrain/
|
101 |
+
- HuggingFace: https://huggingface.co/speechbrain/
|
102 |
+
|
103 |
+
|
104 |
+
# **Citing SpeechBrain**
|
105 |
+
Please, cite SpeechBrain if you use it for your research or business.
|
106 |
+
|
107 |
+
|
108 |
+
```bibtex
|
109 |
+
@misc{speechbrain,
|
110 |
+
title={{SpeechBrain}: A General-Purpose Speech Toolkit},
|
111 |
+
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},
|
112 |
+
year={2021},
|
113 |
+
eprint={2106.04624},
|
114 |
+
archivePrefix={arXiv},
|
115 |
+
primaryClass={eess.AS},
|
116 |
+
note={arXiv:2106.04624}
|
117 |
+
}
|
118 |
+
```
|
119 |
+
|
120 |
+
#### Credits
|
121 |
+
|
122 |
+
This model was trained with resources provided by the [KIZ](https://www.th-nuernberg.de/en/facilities/competence-centers/center-for-artificial-intelligence-kiz/) Cluster at TH Nürnberg.
|
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 |
+
}
|
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
|