-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add CTC recipe to AISHELL-1 #1576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
a05c989
add ctc recipe
BenoitWang 4a38c31
add readme
BenoitWang fd720bf
clean prepare
BenoitWang 5bd8def
update train_with_wav2vec.yaml
BenoitWang f8a5779
update train_with_wav2vec.yaml
BenoitWang b66436b
Merge remote-tracking branch 'upstream/develop' into aishell-ctc
BenoitWang b2ccd9b
pre-commit tests
BenoitWang 4aaf376
add to recipes.csv
BenoitWang 1062a06
consistency tests
BenoitWang dd93c85
minor fixes
BenoitWang 2a2309f
fix filenames for all aishell recipes and other fixes
BenoitWang 6d82dea
add new files names to recipes.csv
BenoitWang 436387c
Update train_with_wav2vec.yaml
BenoitWang 1cb1652
add num_buckets and fix Tokenizer readme
BenoitWang 8881bc3
Merge branch 'aishell-ctc' of https://github.com/BenoitWang/speechbra…
BenoitWang 04a116e
fix/add dynamic batching for all the recipes
BenoitWang 28ba0b9
add hf link
BenoitWang 72d5203
fix conflict
BenoitWang f0450cd
fix conflict
BenoitWang f15b8aa
add to recipes.csv
BenoitWang ccb88d3
fix names
BenoitWang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # AISHELL-1 ASR with CTC. | ||
| This folder contains a CTC-wav2vec2 recipe for speech recognition with [AISHELL-1](https://www.openslr.org/33/), a 150-hour Chinese ASR dataset. | ||
|
|
||
| ### How to run | ||
| 1- Tokenizer/Dataset | ||
| A pretrained tokenizer from [huggingface](https://huggingface.co/bert-base-chinese) is used and can be downloaded | ||
| automatically. | ||
|
|
||
| If not present in the specified data_folder, the dataset will be automatically downloaded there. | ||
| This step is not mandatory. We will use the official tokenizer downloaded from the web if you do not | ||
| specify a different tokenizer in the speech recognition recipe. | ||
|
|
||
| 2- Train the speech recognizer | ||
| ``` | ||
| python train_with_wav2vec.py hparams/train_with_wav2vec.yaml | ||
| ``` | ||
|
|
||
| Make sure to have "transformers" installed. | ||
|
|
||
| # Performance summary | ||
| Results are reported in terms of Character Error Rate (CER). | ||
|
|
||
| | hyperparams file | LM | Test CER | Dev CER | GPUs | | ||
| |:--------------------------:|:-----:| :-----:| :-----:| :-----: | | ||
| | train_with_wav2vec.yaml | No | 5.06 | 4.52 | 1xRTX 8000 Ti 48GB | | ||
|
|
||
| You can checkout our results (models, training logs, etc,) [here](https://drive.google.com/drive/folders/1GTB5IzQPl57j-0I1IpmvKg722Ti4ahLz?usp=sharing) | ||
|
|
||
| # Training Time | ||
| It takes about 2h on 1 RTX 8000 (48GB) | ||
|
|
||
| # PreTrained Model + Easy-Inference | ||
| You can find the pre-trained model with an easy-inference function on HuggingFace | ||
| - https://huggingface.co/speechbrain/asr-wav2vec2-ctc-aishell | ||
|
|
||
| # **About SpeechBrain** | ||
| - Website: https://speechbrain.github.io/ | ||
| - Code: https://github.com/speechbrain/speechbrain/ | ||
| - HuggingFace: https://huggingface.co/speechbrain/ | ||
|
|
||
|
|
||
| # **Citing SpeechBrain** | ||
| Please, cite SpeechBrain if you use it for your research or business. | ||
|
|
||
| ```bibtex | ||
| @misc{speechbrain, | ||
| title={{SpeechBrain}: A General-Purpose Speech Toolkit}, | ||
| 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}, | ||
| year={2021}, | ||
| eprint={2106.04624}, | ||
| archivePrefix={arXiv}, | ||
| primaryClass={eess.AS}, | ||
| note={arXiv:2106.04624} | ||
| } | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../aishell_prepare.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # For wav2vec2 recipe (HuggingFace) | ||
| transformers |
186 changes: 186 additions & 0 deletions
186
recipes/AISHELL-1/ASR/CTC/hparams/train_with_wav2vec.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,186 @@ | ||
| # ############################################################################ | ||
| # Model: CTC-wav2vec2 | ||
| # Encoder: wav2vec2 | ||
| # Decoder: - | ||
| # Tokens: Char | ||
| # losses: CTC | ||
| # Training: AISHELL-1 | ||
| # Authors: Yingzhi WANG 2022 | ||
| # ############################################################################ | ||
|
|
||
| seed: 2 | ||
| __set_seed: !apply:torch.manual_seed [!ref <seed>] | ||
| output_folder: !ref results/ctc_wav2vec/<seed> | ||
| cer_file: !ref <output_folder>/cer.txt | ||
| save_folder: !ref <output_folder>/save | ||
| train_log: !ref <output_folder>/train_log.txt | ||
|
|
||
| # Data files | ||
| data_folder: !PLACEHOLDER # e,g./path/to/aishell | ||
|
|
||
| skip_prep: False | ||
| ckpt_interval_minutes: 15 # save checkpoint every N min | ||
| train_data: !ref <output_folder>/train.csv | ||
| valid_data: !ref <output_folder>/dev.csv | ||
| test_data: !ref <output_folder>/test.csv | ||
|
|
||
| wav2vec2_hub: TencentGameMate/chinese-wav2vec2-large | ||
|
|
||
| # Training parameters | ||
| number_of_epochs: 80 | ||
| lr: 1.0 | ||
| lr_wav2vec: 0.0001 | ||
| sorting: ascending | ||
| auto_mix_prec: False | ||
| sample_rate: 16000 | ||
|
|
||
| # With data_parallel batch_size is split into N jobs | ||
| # With DDP batch_size is multiplied by N jobs | ||
| # Must be 8 per GPU to fit 32GB of VRAM | ||
| batch_size: 10 | ||
| test_batch_size: 4 | ||
|
|
||
| dynamic_batching: False | ||
| dynamic_batch_sampler: | ||
| feats_hop_size: 0.01 | ||
| max_batch_len: 15 # in terms of "duration" in annotations by default, second here | ||
| left_bucket_len: 200 # old implementation attributs | ||
| multiplier: 1.1 # old implementation attributs | ||
| shuffle_ex: False # if true re-creates batches at each epoch shuffling examples. | ||
| num_buckets: 10 # floor(log(max_batch_len/left_bucket_len, multiplier)) + 1 | ||
| batch_ordering: ascending | ||
|
|
||
| num_workers: 6 | ||
|
|
||
| # Dataloader options | ||
| train_dataloader_opts: | ||
| batch_size: !ref <batch_size> | ||
| num_workers: !ref <num_workers> | ||
| valid_dataloader_opts: | ||
| batch_size: !ref <test_batch_size> | ||
| num_workers: !ref <num_workers> | ||
| test_dataloader_opts: | ||
| batch_size: !ref <test_batch_size> | ||
| num_workers: !ref <num_workers> | ||
|
|
||
| wav2vec_output_dim: 1024 | ||
| dnn_neurons: 1024 | ||
| freeze_wav2vec: False | ||
| dropout: 0.15 | ||
|
|
||
| tokenizer: !apply:transformers.BertTokenizer.from_pretrained | ||
| pretrained_model_name_or_path: bert-base-chinese | ||
| # bert-base-chinese tokens length | ||
| output_neurons: 21128 | ||
|
|
||
| # Decoding parameters | ||
| # Be sure that the bos and eos index match with the BPEs ones | ||
| blank_index: 0 | ||
|
|
||
| # AISHELL-1 has spaces between words in the transcripts, | ||
| # which Chinese writing normally does not do. | ||
| # If remove_spaces, spaces are removed | ||
| # from the transcript before computing CER. | ||
| # (e.g., 祝 可爱 的 你 —> 祝可爱的你) | ||
| remove_spaces: True | ||
| split_tokens: !apply:operator.not_ [!ref <remove_spaces>] | ||
|
|
||
| epoch_counter: !new:speechbrain.utils.epoch_loop.EpochCounter | ||
| limit: !ref <number_of_epochs> | ||
|
|
||
| SpeedPerturb: !new:speechbrain.lobes.augment.TimeDomainSpecAugment | ||
| sample_rate: !ref <sample_rate> | ||
| speeds: [90, 100, 110] | ||
|
|
||
| SpecAugment: !new:speechbrain.lobes.augment.SpecAugment | ||
| time_warp: True | ||
| time_warp_window: 5 | ||
| time_warp_mode: bicubic | ||
| freq_mask: True | ||
| n_freq_mask: 2 | ||
| time_mask: True | ||
| n_time_mask: 2 | ||
| replace_with_zero: False | ||
| freq_mask_width: 30 | ||
| time_mask_width: 40 | ||
|
|
||
| enc: !new:speechbrain.nnet.containers.Sequential | ||
| input_shape: [null, null, !ref <wav2vec_output_dim>] | ||
| linear1: !name:speechbrain.nnet.linear.Linear | ||
| n_neurons: !ref <dnn_neurons> | ||
| bias: True | ||
| bn1: !name:speechbrain.nnet.normalization.BatchNorm1d | ||
| activation: !new:torch.nn.LeakyReLU | ||
| drop: !new:torch.nn.Dropout | ||
| p: !ref <dropout> | ||
| linear2: !name:speechbrain.nnet.linear.Linear | ||
| n_neurons: !ref <dnn_neurons> | ||
| bias: True | ||
| bn2: !name:speechbrain.nnet.normalization.BatchNorm1d | ||
| activation2: !new:torch.nn.LeakyReLU | ||
| drop2: !new:torch.nn.Dropout | ||
| p: !ref <dropout> | ||
| linear3: !name:speechbrain.nnet.linear.Linear | ||
| n_neurons: !ref <dnn_neurons> | ||
| bias: True | ||
| bn3: !name:speechbrain.nnet.normalization.BatchNorm1d | ||
| activation3: !new:torch.nn.LeakyReLU | ||
|
|
||
| wav2vec2: !new:speechbrain.lobes.models.huggingface_wav2vec.HuggingFaceWav2Vec2 | ||
| source: !ref <wav2vec2_hub> | ||
| output_norm: True | ||
| freeze: !ref <freeze_wav2vec> | ||
| save_path: !ref <save_folder>/wav2vec2_checkpoint | ||
|
|
||
| ctc_lin: !new:speechbrain.nnet.linear.Linear | ||
| input_size: !ref <dnn_neurons> | ||
| n_neurons: !ref <output_neurons> | ||
|
|
||
| log_softmax: !new:speechbrain.nnet.activations.Softmax | ||
| apply_log: True | ||
|
|
||
| ctc_cost: !name:speechbrain.nnet.losses.ctc_loss | ||
| blank_index: !ref <blank_index> | ||
|
|
||
| modules: | ||
| wav2vec2: !ref <wav2vec2> | ||
| enc: !ref <enc> | ||
| ctc_lin: !ref <ctc_lin> | ||
|
|
||
| model: !new:torch.nn.ModuleList | ||
| - [!ref <enc>, !ref <ctc_lin>] | ||
|
|
||
| model_opt_class: !name:torch.optim.Adadelta | ||
| lr: !ref <lr> | ||
| rho: 0.95 | ||
| eps: 1.e-8 | ||
|
|
||
| wav2vec_opt_class: !name:torch.optim.Adam | ||
| lr: !ref <lr_wav2vec> | ||
|
|
||
| lr_annealing_model: !new:speechbrain.nnet.schedulers.NewBobScheduler | ||
| initial_value: !ref <lr> | ||
| improvement_threshold: 0.0025 | ||
| annealing_factor: 0.8 | ||
| patient: 0 | ||
|
|
||
| lr_annealing_wav2vec: !new:speechbrain.nnet.schedulers.NewBobScheduler | ||
| initial_value: !ref <lr_wav2vec> | ||
| improvement_threshold: 0.0025 | ||
| annealing_factor: 0.9 | ||
| patient: 0 | ||
|
|
||
| checkpointer: !new:speechbrain.utils.checkpoints.Checkpointer | ||
| checkpoints_dir: !ref <save_folder> | ||
| recoverables: | ||
| wav2vec2: !ref <wav2vec2> | ||
| model: !ref <model> | ||
| scheduler_model: !ref <lr_annealing_model> | ||
| scheduler_wav2vec: !ref <lr_annealing_wav2vec> | ||
| counter: !ref <epoch_counter> | ||
|
|
||
| train_logger: !new:speechbrain.utils.train_logger.FileTrainLogger | ||
| save_file: !ref <train_log> | ||
|
|
||
| cer_computer: !name:speechbrain.utils.metric_stats.ErrorRateStats | ||
| split_tokens: !ref <split_tokens> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.