|
| 1 | +# ################################ |
| 2 | +# Model: wav2vec2 + DNN + CTC + LM (k2) |
| 3 | +# Augmentation: SpecAugment |
| 4 | +# |
| 5 | +# This recipe trains a wav2vec2 model with a DNN and DWFST-based CTC loss. |
| 6 | +# To use this recipe you need to have the following: |
| 7 | +# - A folder with the LibriSpeech dataset (see `datafolder`) |
| 8 | +# - A folder with a small, and (optionally) a big LM (see `lm_dir`) |
| 9 | +# These can be downloaded in ARPA format from: http://www.openslr.org/resources/11/. |
| 10 | +# - A working installation of k2 (and kaldilm if you want to use ARPA LMs). |
| 11 | +# |
| 12 | +# Authors: Zeyu Zhao 2023 |
| 13 | +# Georgios Karakasidis 2023 |
| 14 | +# Pierre Champion 2023 |
| 15 | +# ################################ |
| 16 | + |
| 17 | +# Seed needs to be set at top of yaml, before objects with parameters are made |
| 18 | +seed: 1111 |
| 19 | +__set_seed: !apply:torch.manual_seed [!ref <seed>] |
| 20 | +output_folder: !ref results/train_wav2vec2_char_k2/<seed> |
| 21 | +output_wer_folder: !ref <output_folder>/ |
| 22 | +save_folder: !ref <output_folder>/save |
| 23 | +train_log: !ref <output_folder>/train_log.txt |
| 24 | + |
| 25 | +# URL for the biggest Fairseq english wav2vec2 model. |
| 26 | +wav2vec2_hub: facebook/wav2vec2-large-960h-lv60-self |
| 27 | +wav2vec2_folder: !ref <save_folder>/wav2vec2_checkpoint |
| 28 | + |
| 29 | +# Data files |
| 30 | +data_folder: !PLACEHOLDER # e,g./path/to/LibriSpeech |
| 31 | +# noise/ris dataset will automatically be downloaded |
| 32 | +# data_folder_rirs: !ref <data_folder> |
| 33 | +train_splits: ["train-clean-100", "train-clean-360", "train-other-500"] |
| 34 | +dev_splits: ["dev-clean", "dev-other"] |
| 35 | +test_splits: ["test-clean", "test-other"] |
| 36 | +skip_prep: False |
| 37 | +ckpt_interval_minutes: 25 # save checkpoint every N min |
| 38 | +train_csv: !ref <output_folder>/train.csv |
| 39 | +valid_csv: !ref <output_folder>/dev-clean.csv |
| 40 | +test_csv: |
| 41 | + - !ref <output_folder>/test-clean.csv |
| 42 | + - !ref <output_folder>/test-other.csv |
| 43 | + - !ref <output_folder>/dev-clean.csv |
| 44 | + - !ref <output_folder>/dev-other.csv |
| 45 | + |
| 46 | +# For k2 CTC training |
| 47 | +lang_dir: !ref <output_folder>/lang |
| 48 | +vocab_file: !ref <data_folder>/librispeech-vocab.txt |
| 49 | +sil_prob: 0. |
| 50 | +add_word_boundary: True |
| 51 | +# For k2 decoding |
| 52 | +test_search_beam: 32 |
| 53 | +# Beam size (for decoding) |
| 54 | +test_output_beam: 8 |
| 55 | +test_min_active_state: 300 |
| 56 | +test_max_active_state: 3000 |
| 57 | +# Acoustic scale (mutliplied by the log probs) |
| 58 | +ac_scale: 1.5 |
| 59 | +compose_HL_with_G: False |
| 60 | +# 1best or whole-lattice-rescoring |
| 61 | +# decoding_method: whole-lattice-rescoring |
| 62 | +decoding_method: 1best |
| 63 | +# LM scale to be used for rescoring. Only used if rescoring |
| 64 | +rescoring_lm_scale: 0.4 |
| 65 | +# This is where the 3gram and (optionally) 4gram LM are stored |
| 66 | +# They can be in either ARPA or FST format. If the former, then |
| 67 | +# the FST equivalent will be created in the same directory by |
| 68 | +# using kaldilm. |
| 69 | +lm_dir: !ref <output_folder>/lm |
| 70 | +# The ARPA LM files are located under the lm_dir. |
| 71 | +# - Use (recommended): |
| 72 | +# - 3-gram_sb.arpa |
| 73 | +# - 4-gram_sb.arpa |
| 74 | +# To downloads speechbrain pretrained models (trained on train-960+librispeech-lm-norm.txt, 214k words) |
| 75 | +# - Use: |
| 76 | +# - 3-gram.arpa |
| 77 | +# - 3-gram.pruned.1e-7.arpa |
| 78 | +# - 3-gram.pruned.3e-7.arpa |
| 79 | +# - 4-gram.arpa |
| 80 | +# To downloads http://www.openslr.org/resources/11/ pretrained models (trained on librispeech-lm-norm.txt, 200k words) |
| 81 | +# - Use another name for a model you trained yourself. |
| 82 | +# If the arpa does not exist in the lm_dir, you'll need to train it yourself. |
| 83 | +# Please see LibriSpeech/LM/README.md for instructions. |
| 84 | +# Using one of the above name will automatically download the corresponding model. |
| 85 | +# You can speciy a different name, but you'll need to make sure the file exists in the lm_dir. |
| 86 | +# Make sure to use enough RAM and CPUs as the conversion to FST can be quite demanding. |
| 87 | +G_arpa: 3-gram_sb.arpa |
| 88 | +G_rescoring_arpa: 4-gram_sb.arpa |
| 89 | +# caching: False |
| 90 | + |
| 91 | +# Training parameters |
| 92 | +number_of_epochs: 1 |
| 93 | +lr: 0.9 |
| 94 | +lr_wav2vec: 0.0001 |
| 95 | +sorting: ascending # only ascending and descending are supported currently |
| 96 | +precision: fp32 |
| 97 | +sample_rate: 16000 |
| 98 | + |
| 99 | +# With data_parallel batch_size is split into N jobs |
| 100 | +# With DDP batch_size is multiplied by N jobs |
| 101 | +# Must be 3 per GPU to fit 32GB of VRAM |
| 102 | +batch_size: 6 |
| 103 | +test_batch_size: 1 |
| 104 | +num_workers: 10 |
| 105 | + |
| 106 | +# Dataloader options |
| 107 | +train_dataloader_opts: |
| 108 | + batch_size: !ref <batch_size> |
| 109 | + num_workers: !ref <num_workers> |
| 110 | + |
| 111 | +valid_dataloader_opts: |
| 112 | + batch_size: !ref <batch_size> |
| 113 | + num_workers: !ref <num_workers> |
| 114 | + |
| 115 | +test_dataloader_opts: |
| 116 | + batch_size: !ref <test_batch_size> |
| 117 | + num_workers: !ref <num_workers> |
| 118 | + |
| 119 | +# Model parameters |
| 120 | +activation: !name:torch.nn.LeakyReLU |
| 121 | +dnn_layers: 2 |
| 122 | +dnn_neurons: 1024 |
| 123 | +freeze_wav2vec: True |
| 124 | + |
| 125 | +# Outputs |
| 126 | +output_neurons: 30 # BPE size, index(blank/eos/bos) = 0 |
| 127 | + |
| 128 | +# |
| 129 | +# Functions and classes |
| 130 | +# |
| 131 | +epoch_counter: !new:speechbrain.utils.epoch_loop.EpochCounter |
| 132 | + limit: !ref <number_of_epochs> |
| 133 | + |
| 134 | +speed_perturb: !new:speechbrain.augment.time_domain.SpeedPerturb |
| 135 | + orig_freq: !ref <sample_rate> |
| 136 | + speeds: [95, 100, 105] |
| 137 | + |
| 138 | +# Frequency drop: randomly drops a number of frequency bands to zero. |
| 139 | +drop_freq_low: 0 # Min frequency band dropout probability |
| 140 | +drop_freq_high: 1 # Max frequency band dropout probability |
| 141 | +drop_freq_count_low: 1 # Min number of frequency bands to drop |
| 142 | +drop_freq_count_high: 3 # Max number of frequency bands to drop |
| 143 | +drop_freq_width: 0.05 # Width of frequency bands to drop |
| 144 | + |
| 145 | +drop_freq: !new:speechbrain.augment.time_domain.DropFreq |
| 146 | + drop_freq_low: !ref <drop_freq_low> |
| 147 | + drop_freq_high: !ref <drop_freq_high> |
| 148 | + drop_freq_count_low: !ref <drop_freq_count_low> |
| 149 | + drop_freq_count_high: !ref <drop_freq_count_high> |
| 150 | + drop_freq_width: !ref <drop_freq_width> |
| 151 | + |
| 152 | +# Time drop: randomly drops a number of temporal chunks. |
| 153 | +drop_chunk_count_low: 1 # Min number of audio chunks to drop |
| 154 | +drop_chunk_count_high: 5 # Max number of audio chunks to drop |
| 155 | +drop_chunk_length_low: 1000 # Min length of audio chunks to drop |
| 156 | +drop_chunk_length_high: 2000 # Max length of audio chunks to drop |
| 157 | + |
| 158 | +drop_chunk: !new:speechbrain.augment.time_domain.DropChunk |
| 159 | + drop_length_low: !ref <drop_chunk_length_low> |
| 160 | + drop_length_high: !ref <drop_chunk_length_high> |
| 161 | + drop_count_low: !ref <drop_chunk_count_low> |
| 162 | + drop_count_high: !ref <drop_chunk_count_high> |
| 163 | + |
| 164 | +# Augmenter: Combines previously defined augmentations to perform data augmentation |
| 165 | +wav_augment: !new:speechbrain.augment.augmenter.Augmenter |
| 166 | + parallel_augment: False |
| 167 | + repeat_augment: 1 |
| 168 | + shuffle_augmentations: False |
| 169 | + min_augmentations: 4 |
| 170 | + max_augmentations: 4 |
| 171 | + augment_prob: 1.0 |
| 172 | + augmentations: [ |
| 173 | + !ref <speed_perturb>, |
| 174 | + !ref <drop_freq>, |
| 175 | + !ref <drop_chunk>] |
| 176 | + |
| 177 | +enc: !new:speechbrain.lobes.models.VanillaNN.VanillaNN |
| 178 | + input_shape: [null, null, 1024] |
| 179 | + activation: !ref <activation> |
| 180 | + dnn_blocks: !ref <dnn_layers> |
| 181 | + dnn_neurons: !ref <dnn_neurons> |
| 182 | + |
| 183 | +wav2vec2: !new:speechbrain.lobes.models.huggingface_transformers.Wav2Vec2 |
| 184 | + source: !ref <wav2vec2_hub> |
| 185 | + output_norm: True |
| 186 | + freeze: !ref <freeze_wav2vec> |
| 187 | + save_path: !ref <wav2vec2_folder> |
| 188 | + |
| 189 | +##### |
| 190 | +# Uncomment this block if you prefer to use a Fairseq pretrained model instead |
| 191 | +# of a HuggingFace one. Here, we provide an URL that is obtained from the |
| 192 | +# Fairseq github for the multilingual XLSR. |
| 193 | +# |
| 194 | +#wav2vec2_url: https://dl.fbaipublicfiles.com/fairseq/wav2vec/wav2vec_vox_960h_pl.pt |
| 195 | +#wav2vec2: !new:speechbrain.lobes.models.fairseq_wav2vec.FairseqWav2Vec2 |
| 196 | +# pretrained_path: !ref <wav2vec2_url> |
| 197 | +# output_norm: True |
| 198 | +# freeze: False |
| 199 | +# save_path: !ref <save_folder>/wav2vec2_checkpoint/model.pt |
| 200 | + |
| 201 | +ctc_lin: !new:speechbrain.nnet.linear.Linear |
| 202 | + input_size: !ref <dnn_neurons> |
| 203 | + n_neurons: !ref <output_neurons> |
| 204 | + |
| 205 | +log_softmax: !new:speechbrain.nnet.activations.Softmax |
| 206 | + apply_log: True |
| 207 | + |
| 208 | +ctc_cost: !name:speechbrain.k2_integration.losses.ctc_k2 |
| 209 | + reduction: mean |
| 210 | + beam_size: 10 |
| 211 | + |
| 212 | +modules: |
| 213 | + wav2vec2: !ref <wav2vec2> |
| 214 | + enc: !ref <enc> |
| 215 | + ctc_lin: !ref <ctc_lin> |
| 216 | + |
| 217 | +model: !new:torch.nn.ModuleList |
| 218 | + - [!ref <enc>, !ref <ctc_lin>] |
| 219 | + |
| 220 | +model_opt_class: !name:torch.optim.Adadelta |
| 221 | + lr: !ref <lr> |
| 222 | + rho: 0.95 |
| 223 | + eps: 1.e-8 |
| 224 | + |
| 225 | +wav2vec_opt_class: !name:torch.optim.Adam |
| 226 | + lr: !ref <lr_wav2vec> |
| 227 | + |
| 228 | +lr_annealing_model: !new:speechbrain.nnet.schedulers.NewBobScheduler |
| 229 | + initial_value: !ref <lr> |
| 230 | + improvement_threshold: 0.0025 |
| 231 | + annealing_factor: 0.8 |
| 232 | + patient: 0 |
| 233 | + |
| 234 | +lr_annealing_wav2vec: !new:speechbrain.nnet.schedulers.NewBobScheduler |
| 235 | + initial_value: !ref <lr_wav2vec> |
| 236 | + improvement_threshold: 0.0025 |
| 237 | + annealing_factor: 0.9 |
| 238 | + patient: 0 |
| 239 | + |
| 240 | +checkpointer: !new:speechbrain.utils.checkpoints.Checkpointer |
| 241 | + checkpoints_dir: !ref <save_folder> |
| 242 | + recoverables: |
| 243 | + wav2vec2: !ref <wav2vec2> |
| 244 | + model: !ref <model> |
| 245 | + scheduler_model: !ref <lr_annealing_model> |
| 246 | + scheduler_wav2vec: !ref <lr_annealing_wav2vec> |
| 247 | + counter: !ref <epoch_counter> |
| 248 | + |
| 249 | +train_logger: !new:speechbrain.utils.train_logger.FileTrainLogger |
| 250 | + save_file: !ref <train_log> |
| 251 | + |
| 252 | +error_rate_computer: !name:speechbrain.utils.metric_stats.ErrorRateStats |
| 253 | + |
| 254 | +cer_computer: !name:speechbrain.utils.metric_stats.ErrorRateStats |
| 255 | + split_tokens: True |
0 commit comments