Titouan Parcollet commited on
Commit
73d0f9f
1 Parent(s): 5c5ecbb

new conformer

Browse files
Files changed (8) hide show
  1. README.md +151 -0
  2. asr.ckpt +3 -0
  3. config.json +3 -0
  4. example.wav +0 -0
  5. hyperparams.yaml +154 -0
  6. lm.ckpt +3 -0
  7. normalizer.ckpt +0 -0
  8. tokenizer.ckpt +0 -0
README.md ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ thumbnail: null
5
+ tags:
6
+ - automatic-speech-recognition
7
+ - CTC
8
+ - Attention
9
+ - Transformer
10
+ - Conformer
11
+ - pytorch
12
+ - speechbrain
13
+ - hf-asr-leaderboard
14
+ license: apache-2.0
15
+ datasets:
16
+ - librispeech
17
+ metrics:
18
+ - wer
19
+ - cer
20
+ model-index:
21
+ - name: Transformer+TransformerLM by SpeechBrain
22
+ results:
23
+ - task:
24
+ name: Automatic Speech Recognition
25
+ type: automatic-speech-recognition
26
+ dataset:
27
+ name: LibriSpeech (clean)
28
+ type: librispeech_asr
29
+ config: clean
30
+ split: test
31
+ args:
32
+ language: en
33
+ metrics:
34
+ - name: Test WER
35
+ type: wer
36
+ value: 2.0
37
+ - task:
38
+ name: Automatic Speech Recognition
39
+ type: automatic-speech-recognition
40
+ dataset:
41
+ name: LibriSpeech (other)
42
+ type: librispeech_asr
43
+ config: other
44
+ split: test
45
+ args:
46
+ language: en
47
+ metrics:
48
+ - name: Test WER
49
+ type: wer
50
+ value: 4.5
51
+ ---
52
+
53
+ <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>
54
+ <br/><br/>
55
+
56
+ # Transformer for LibriSpeech (with Transformer LM)
57
+
58
+ This repository provides all the necessary tools to perform automatic speech
59
+ recognition from an end-to-end system pretrained on LibriSpeech (EN) within
60
+ SpeechBrain. For a better experience, we encourage you to learn more about
61
+ [SpeechBrain](https://speechbrain.github.io).
62
+ The performance of the model is the following:
63
+
64
+ | Release | Test clean WER | Test other WER | GPUs |
65
+ |:-------------:|:--------------:|:--------------:|:--------:|
66
+ | 21-06-23 | 2.01 | 4.52 | 4xA100 80GB |
67
+
68
+ ## Pipeline description
69
+
70
+ This ASR system is composed of 3 different but linked blocks:
71
+ - Tokenizer (unigram) that transforms words into subword units and trained with
72
+ the train transcriptions of LibriSpeech.
73
+ - Neural language model (Transformer LM) trained on the full 10M words dataset.
74
+ - Acoustic model made of a conformer encoder and a joint decoder with CTC +
75
+ transformer. Hence, the decoding also incorporates the CTC probabilities.
76
+
77
+ The system is trained with recordings sampled at 16kHz (single channel).
78
+ The code will automatically normalize your audio (i.e., resampling + mono channel selection) when calling *transcribe_file* if needed.
79
+
80
+ ## Install SpeechBrain
81
+
82
+ First of all, please install SpeechBrain with the following command:
83
+
84
+ ```
85
+ pip install speechbrain
86
+ ```
87
+
88
+ Please notice that we encourage you to read our tutorials and learn more about
89
+ [SpeechBrain](https://speechbrain.github.io).
90
+
91
+ ### Transcribing your own audio files (in English)
92
+
93
+ ```python
94
+ from speechbrain.pretrained import EncoderDecoderASR
95
+
96
+ asr_model = EncoderDecoderASR.from_hparams(source="speechbrain/asr-conformer-transformerlm-librispeech", savedir="pretrained_models/asr-transformer-transformerlm-librispeech")
97
+ asr_model.transcribe_file("speechbrain/asr-conformer-transformerlm-librispeech/example.wav")
98
+
99
+ ```
100
+ ### Inference on GPU
101
+ To perform inference on the GPU, add `run_opts={"device":"cuda"}` when calling the `from_hparams` method.
102
+
103
+ ## Parallel Inference on a Batch
104
+ 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.
105
+
106
+ ### Training
107
+ The model was trained with SpeechBrain (Commit hash: 'f73fcc35').
108
+ To train it from scratch follow these steps:
109
+ 1. Clone SpeechBrain:
110
+ ```bash
111
+ git clone https://github.com/speechbrain/speechbrain/
112
+ ```
113
+ 2. Install it:
114
+ ```bash
115
+ cd speechbrain
116
+ pip install -r requirements.txt
117
+ pip install -e .
118
+ ```
119
+
120
+ 3. Run Training:
121
+ ```bash
122
+ cd recipes/LibriSpeech/ASR/transformer
123
+ python train.py hparams/transformer.yaml --data_folder=your_data_folder
124
+ ```
125
+
126
+ You can find our training results (models, logs, etc) [here](https://drive.google.com/drive/folders/1Nv1OLbHLqVeShyZ8LY9gjhYGE1DBFzFf?usp=sharing).
127
+
128
+ ### Limitations
129
+ The SpeechBrain team does not provide any warranty on the performance achieved by this model when used on other datasets.
130
+
131
+ # **About SpeechBrain**
132
+ - Website: https://speechbrain.github.io/
133
+ - Code: https://github.com/speechbrain/speechbrain/
134
+ - HuggingFace: https://huggingface.co/speechbrain/
135
+
136
+
137
+ # **Citing SpeechBrain**
138
+ Please, cite SpeechBrain if you use it for your research or business.
139
+
140
+
141
+ ```bibtex
142
+ @misc{speechbrain,
143
+ title={{SpeechBrain}: A General-Purpose Speech Toolkit},
144
+ 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},
145
+ year={2021},
146
+ eprint={2106.04624},
147
+ archivePrefix={arXiv},
148
+ primaryClass={eess.AS},
149
+ note={arXiv:2106.04624}
150
+ }
151
+ ```
asr.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a738d0f06f29e248ee05331faa7db7e54564f65deb3c0d3e36d854334126b10a
3
+ size 441842873
config.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "speechbrain_interface": "EncoderDecoderASR"
3
+ }
example.wav ADDED
Binary file (104 kB). View file
 
hyperparams.yaml ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: Librispeech 960h
8
+ # Authors: Jianyuan Zhong, Titouan Parcollet 2021
9
+ # ############################################################################
10
+
11
+ # Feature parameters
12
+ sample_rate: 16000
13
+ n_fft: 400
14
+ n_mels: 80
15
+
16
+ ####################### Model parameters ###########################
17
+ # Transformer
18
+ d_model: 512
19
+ nhead: 4
20
+ num_encoder_layers: 12
21
+ num_decoder_layers: 6
22
+ d_ffn: 2048
23
+ transformer_dropout: 0.1
24
+ activation: !name:torch.nn.GELU
25
+ output_neurons: 5000
26
+ vocab_size: 5000
27
+
28
+ # Outputs
29
+ blank_index: 0
30
+ label_smoothing: 0.0
31
+ pad_index: 0
32
+ bos_index: 1
33
+ eos_index: 2
34
+
35
+ # Decoding parameters
36
+ min_decode_ratio: 0.0
37
+ max_decode_ratio: 1.0
38
+ valid_search_interval: 10
39
+ valid_beam_size: 10
40
+ test_beam_size: 66
41
+ lm_weight: 0.60
42
+ ctc_weight_decode: 0.40
43
+
44
+ ############################## models ################################
45
+
46
+ CNN: !new:speechbrain.lobes.models.convolution.ConvolutionFrontEnd
47
+ input_shape: (8, 10, 80)
48
+ num_blocks: 3
49
+ num_layers_per_block: 1
50
+ out_channels: (64, 64, 64)
51
+ kernel_sizes: (5, 5, 1)
52
+ strides: (2, 2, 1)
53
+ residuals: (False, False, True)
54
+ norm: !name:speechbrain.nnet.normalization.LayerNorm
55
+
56
+ Transformer: !new:speechbrain.lobes.models.transformer.TransformerASR.TransformerASR
57
+ input_size: 1280
58
+ tgt_vocab: !ref <output_neurons>
59
+ d_model: !ref <d_model>
60
+ nhead: !ref <nhead>
61
+ num_encoder_layers: !ref <num_encoder_layers>
62
+ num_decoder_layers: !ref <num_decoder_layers>
63
+ d_ffn: !ref <d_ffn>
64
+ dropout: !ref <transformer_dropout>
65
+ activation: !ref <activation>
66
+ encoder_module: transformer
67
+ attention_type: regularMHA
68
+ normalize_before: True
69
+ causal: False
70
+
71
+ ctc_lin: !new:speechbrain.nnet.linear.Linear
72
+ input_size: !ref <d_model>
73
+ n_neurons: !ref <output_neurons>
74
+
75
+ seq_lin: !new:speechbrain.nnet.linear.Linear
76
+ input_size: !ref <d_model>
77
+ n_neurons: !ref <output_neurons>
78
+
79
+ decoder: !new:speechbrain.decoders.S2STransformerBeamSearch
80
+ modules: [!ref <Transformer>, !ref <seq_lin>, !ref <ctc_lin>]
81
+ bos_index: !ref <bos_index>
82
+ eos_index: !ref <eos_index>
83
+ blank_index: !ref <blank_index>
84
+ min_decode_ratio: !ref <min_decode_ratio>
85
+ max_decode_ratio: !ref <max_decode_ratio>
86
+ beam_size: !ref <test_beam_size>
87
+ ctc_weight: !ref <ctc_weight_decode>
88
+ lm_weight: !ref <lm_weight>
89
+ lm_modules: !ref <lm_model>
90
+ temperature: 1.15
91
+ temperature_lm: 1.15
92
+ using_eos_threshold: False
93
+ length_normalization: True
94
+
95
+ log_softmax: !new:torch.nn.LogSoftmax
96
+ dim: -1
97
+
98
+ normalizer: !new:speechbrain.processing.features.InputNormalization
99
+ norm_type: global
100
+
101
+ compute_features: !new:speechbrain.lobes.features.Fbank
102
+ sample_rate: !ref <sample_rate>
103
+ n_fft: !ref <n_fft>
104
+ n_mels: !ref <n_mels>
105
+
106
+ # This is the Transformer LM that is used according to the Huggingface repository
107
+ # Visit the HuggingFace model corresponding to the pretrained_lm_tokenizer_path
108
+ # For more details about the model!
109
+ # NB: It has to match the pre-trained TransformerLM!!
110
+ lm_model: !new:speechbrain.lobes.models.transformer.TransformerLM.TransformerLM
111
+ vocab: 5000
112
+ d_model: 768
113
+ nhead: 12
114
+ num_encoder_layers: 12
115
+ num_decoder_layers: 0
116
+ d_ffn: 3072
117
+ dropout: 0.0
118
+ activation: !name:torch.nn.GELU
119
+ normalize_before: False
120
+
121
+ tokenizer: !new:sentencepiece.SentencePieceProcessor
122
+
123
+ Tencoder: !new:speechbrain.lobes.models.transformer.TransformerASR.EncoderWrapper
124
+ transformer: !ref <Transformer>
125
+
126
+ encoder: !new:speechbrain.nnet.containers.LengthsCapableSequential
127
+ input_shape: [null, null, !ref <n_mels>]
128
+ compute_features: !ref <compute_features>
129
+ normalize: !ref <normalizer>
130
+ cnn: !ref <CNN>
131
+ transformer_encoder: !ref <Tencoder>
132
+
133
+ # Models
134
+ asr_model: !new:torch.nn.ModuleList
135
+ - [!ref <CNN>, !ref <Transformer>, !ref <seq_lin>, !ref <ctc_lin>]
136
+
137
+ modules:
138
+ compute_features: !ref <compute_features>
139
+ normalizer: !ref <normalizer>
140
+ pre_transformer: !ref <CNN>
141
+ transformer: !ref <Transformer>
142
+ asr_model: !ref <asr_model>
143
+ lm_model: !ref <lm_model>
144
+ encoder: !ref <encoder>
145
+ decoder: !ref <decoder>
146
+
147
+ # The pretrainer allows a mapping between pretrained files and instances that
148
+ # are declared in the yaml.
149
+ pretrainer: !new:speechbrain.utils.parameter_transfer.Pretrainer
150
+ loadables:
151
+ normalizer: !ref <normalizer>
152
+ asr: !ref <asr_model>
153
+ lm: !ref <lm_model>
154
+ tokenizer: !ref <tokenizer>
lm.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:87f1398c0ed833631e487aedfbda32be4c9618565482f6fad78ca4e8dda03e5b
3
+ size 381074869
normalizer.ckpt ADDED
Binary file (1.7 kB). View file
 
tokenizer.ckpt ADDED
Binary file (324 kB). View file