From f7651711119b6f881f5d5fc77bf9ca80fbcdb50b Mon Sep 17 00:00:00 2001 From: huangyuxin Date: Tue, 23 Nov 2021 07:52:17 +0000 Subject: [PATCH 1/3] add the readme for the run.sh in aishsll asr1 --- examples/aishell/asr1/READEME.md | 301 ++++++++++++++++++ .../asr1/{README.md => model_performance.md} | 0 examples/aishell/asr1/run.sh | 16 +- 3 files changed, 309 insertions(+), 8 deletions(-) create mode 100644 examples/aishell/asr1/READEME.md rename examples/aishell/asr1/{README.md => model_performance.md} (100%) diff --git a/examples/aishell/asr1/READEME.md b/examples/aishell/asr1/READEME.md new file mode 100644 index 000000000..3afd19546 --- /dev/null +++ b/examples/aishell/asr1/READEME.md @@ -0,0 +1,301 @@ +# Conformer ASR with Aishell + +This example contains code used to train a [Conformer](http://arxiv.org/abs/2008.03802) model with [Aishell dataset](http://www.openslr.org/resources/33) + +## Overview + +All the scirpt you need is in the ```run.sh```. There are several stages in the ```run.sh```, and each stage has it's function. + +| Stage | Function | +| :---- | :----------------------------------------------------------- | +| 0 | Process data. It includes:
(1) Download the dataset
(2) Caculate the CMVN of the train dataset
(3) Get the vocabulary file
(4) Get the manifest files of the train, development and test dataset | +| 1 | Train the model | +| 2 | Get the final model by average the top-k model , set k = 1 means choose the best model | +| 3 | Test the final model performance | +| 4 | Get ctc alignment of test data using the final model | +| 5 | Infer the single audio file | +| 51 | (Not supported at now) Transform the dynamic graph model to static graph model | +| 101 | (Need further installation) Train language model and Build TLG | + +You can choose to run a range of stages by set the ```stage``` and ```stop_stage ``` . + +For example , if you want to execute the code in stage 2 and stage 3, you can run this script: + +```bash +bash run.sh --stage 2 --stop_stage 3 +``` +Or you can set ```stage``` equal to ```stop-stage``` to only run one stage. +For example, if you only want to run ```stage 0```, you can use the script below: + +```bash +bash run.sh --stage 0 --stop_stage 0 +``` + + + +The document below will decribe the scripts in the ```run.sh``` in detail. + +## The environment variables + +The path.sh contains the environment variable. +```bash +source path.sh +``` +This script needs to be run firstly. + +And another script is also needed: + +```bash +source ${MAIN_ROOT}/utils/parse_options.sh +``` + +It will support the way of using```--varibale value``` in the shell scripts. + + + +## The local variables + +Some local variables are set in the ```run.sh```. +```gpus``` denotes the GPU number you want to use. If you set ```gpus=```, it means you only use CPU. + +```stage``` denotes the number of stage you want to start from in the expriments. +```stop stage```denotes the number of stage you want to end at in the expriments. + +```conf_path``` denotes the config path of the model. + +```avg_num``` denotes the number K of top-K model you want to average to get the final model. + +```ckpt``` denotes the checkpoint prefix of the model, e.g. "conformer" + +```audio file``` denotes the file path of the single file you want to infer in stage 6 + +You can set the local variables when you use the ```run.sh``` + +For example, you can set the ```gpus``` and ``avg_num`` when you use the command line.: + +```bash +bash run.sh --gpus 0,1 --avg_num 20 +``` + + + +## Stage 0: Data processing + +To use this example, you need to process data firstly and you can use the stage 0 in the ```run.sh``` to do this. The code is shown below: +```bash + if [ ${stage} -le 0 ] && [ ${stop_stage} -ge 0 ]; then + # prepare data + bash ./local/data.sh || exit -1 + fi +``` + +The stage 0 is for processing the data. + +If you only want to process the data. You can run + +```bash +bash run.sh --stage 0 --stop_stage 0 +``` + +You can also just run these scripts in your command line. + +```bash +source path.sh +source ${MAIN_ROOT}/utils/parse_options.sh +bash ./local/data.sh +``` + +Aftre processing the data, the ``data`` directory will be look like this: + +```bash +data/ +├── dev.meta +├── manifest.dev.raw +├── manifest.test.raw +├── manifest.train.raw +├── mean_std.json +├── test.meta +├── train.meta +└── vocab.txt +``` + + + +## Stage 1: Model training + +If you want to train the model. you can use the stage 1 in the ```run.sh```. The code is shown below. +```bash +if [ ${stage} -le 1 ] && [ ${stop_stage} -ge 1 ]; then + # train model, all `ckpt` under `exp` dir + CUDA_VISIBLE_DEVICES=${gpus} ./local/train.sh ${conf_path} ${ckpt} + fi +``` + +If you want to train the model, you can use the script below to execute the stage 0 and stage 1: +```bash +bash run.sh --stage 0 --stop_stage 1 +``` +or you can run these scripts in command line (only use CPU). +```bash +source path.sh +source ${MAIN_ROOT}/utils/parse_options.sh +bash ./local/data.sh +CUDA_VISIBLE_DEVICES= ./local/train.sh conf/conformer.yaml conformer +``` + + + +## Stage 2: Top-k model averaging + +After training the model, we need to get the final model for test and infer. In every epoch, the model checkpoint is saved , so we can choose the best model from them based on the validation loss or we can sort them and average the top-k model parameters to get the final model. We can use the stage 2 to do this, and the code is shown below: +```bash + if [ ${stage} -le 2 ] && [ ${stop_stage} -ge 2 ]; then + # avg n best model + avg.sh best exp/${ckpt}/checkpoints ${avg_num} + fi +``` +The ```avg.sh``` is in the ```../../../utils/``` which is define in the ```path.sh```. +If you want to get the final model, you can use the script below to execute the stage 0, stage 1, and stage 2: + +```bash +bash run.sh --stage 0 --stop_stage 2 +``` + +or you can run these scripts in command line (only use CPU). +```bash +source path.sh +source ${MAIN_ROOT}/utils/parse_options.sh +bash ./local/data.sh +CUDA_VISIBLE_DEVICES= ./local/train.sh conf/conformer.yaml conformer +avg.sh best exp/conformer/checkpoints 20 +``` + + + +## Stage 3: Model Testing + +To know the preformence of the model, test stage is needed. The code of test stage is shown below: + +```bash + if [ ${stage} -le 3 ] && [ ${stop_stage} -ge 3 ]; then + # test ckpt avg_n + CUDA_VISIBLE_DEVICES=0 ./local/test.sh ${conf_path} exp/${ckpt}/checkpoints/${avg_ckpt} || exit -1 + fi +``` + +If you want to train a model and test it, you can use the script below to execute the stage 0, stage 1, stage 2, and stage 3 : + +```bash +bash run.sh --stage 0 --stop_stage 3 +``` + +or you can run these scripts in command line (only use CPU). + +```bash +source path.sh +source ${MAIN_ROOT}/utils/parse_options.sh +bash ./local/data.sh +CUDA_VISIBLE_DEVICES= ./local/train.sh conf/conformer.yaml conformer +avg.sh best exp/conformer/checkpoints 20 +CUDA_VISIBLE_DEVICES= ./local/test.sh conf/conformer.yaml exp/conformer/checkpoints/avg_20 +``` + + + +## Stage 4: CTC alignment + +If you want to get the alignment between the audio and the text, you can use the ctc alignment. The code of this stage is shown below: + +```bash + if [ ${stage} -le 4 ] && [ ${stop_stage} -ge 4 ]; then + # ctc alignment of test data + CUDA_VISIBLE_DEVICES=0 ./local/align.sh ${conf_path} exp/${ckpt}/checkpoints/${avg_ckpt} || exit -1 + fi +``` + +If you want to train the model, test it and do the alignment, you can use the script below to execute the stage 0, stage 1, stage 2, and stage 3 : + +```bash +bash run.sh --stage 0 --stop_stage 4 +``` + +or if you only need to train a model and do the alignment, you can use these scripts to escape the stage 3(test stage): + +```bash +bash run.sh --stage 0 --stop_stage 2 +bash run.sh --stage 4 --stop_stage 4 +``` + +or you can also use these scripts in command line (only use CPU). + +```bash +source path.sh +source ${MAIN_ROOT}/utils/parse_options.sh +bash ./local/data.sh +CUDA_VISIBLE_DEVICES= ./local/train.sh conf/conformer.yaml conformer +avg.sh best exp/conformer/checkpoints 20 +# test stage is optional +CUDA_VISIBLE_DEVICES= ./local/test.sh conf/conformer.yaml exp/conformer/checkpoints/avg_20 +CUDA_VISIBLE_DEVICES= ./local/align.sh conf/conformer.yaml exp/conformer/checkpoints/avg_20 +``` + + + +## Stage 5: Single audio file inference + +In some situation, you want to use the trained model to do the inference for the single audio file. You can use the stage 5. The code is shown below + +```bash + if [ ${stage} -le 5 ] && [ ${stop_stage} -ge 5 ]; then + # test a single .wav file + CUDA_VISIBLE_DEVICES=0 ./local/test_hub.sh ${conf_path} exp/${ckpt}/checkpoints/${avg_ckpt} ${audio_file} || exit -1 + fi +``` + +you can train the model by yourself using ```bash run.sh --stage 0 --stop_stage 3```, or you can download the pretrained model by the script below: + +``` +wget https://deepspeech.bj.bcebos.com/release2.1/aishell/s1/aishell.release.tar.gz +tar aishell.release.tar.gz +``` + +You need to prepare an audio file, please confirme the sample rate of the audio is 16K. Assume the path of the audio file is ```data/test_audio.wav```, you can get the result by runing the script below. + +```bash +CUDA_VISIBLE_DEVICES= ./local/test_hub.sh conf/conformer.yaml exp/conformer/checkpoints/avg_20 data/test_audio.wav +``` + + + +## Stage 51: Static model transforming(not supported at now) + +To transform the dynamic model to static model,stage 51 can be used. The code of this stage is shown below: + +```bash + if [ ${stage} -le 5 ] && [ ${stop_stage} -ge 5 ]; then + # export ckpt avg_n + CUDA_VISIBLE_DEVICES=0 ./local/export.sh ${conf_path} exp/${ckpt}/checkpoints/${avg_ckpt} exp/${ckpt}/checkpoints/${avg_ckpt}.jit + fi +``` + +It is not supported at now, so we set a large stage number for this stage. + + + +## Stage: 101 Language model training and TLG building (Need further installation! ) + +You need to install the kaldi and srilm to use the stage 101, it is used for train language model and build TLG. To do further installation, you need to do these: + +```bash +# go to the root of the repo +cd ../../../ +# Do the further installation +pip install -e . +cd tools +bash extras/install_openblas.sh +bash extras/install_kaldi.sh +``` + +You need to be patient, since installing the kaldi takes some time. + + diff --git a/examples/aishell/asr1/README.md b/examples/aishell/asr1/model_performance.md similarity index 100% rename from examples/aishell/asr1/README.md rename to examples/aishell/asr1/model_performance.md diff --git a/examples/aishell/asr1/run.sh b/examples/aishell/asr1/run.sh index 0b40e0649..c687e966e 100644 --- a/examples/aishell/asr1/run.sh +++ b/examples/aishell/asr1/run.sh @@ -4,7 +4,7 @@ set -e gpus=0,1,2,3 stage=0 -stop_stage=100 +stop_stage=50 conf_path=conf/conformer.yaml avg_num=20 @@ -41,18 +41,18 @@ if [ ${stage} -le 4 ] && [ ${stop_stage} -ge 4 ]; then CUDA_VISIBLE_DEVICES=0 ./local/align.sh ${conf_path} exp/${ckpt}/checkpoints/${avg_ckpt} || exit -1 fi -# if [ ${stage} -le 5 ] && [ ${stop_stage} -ge 5 ]; then -# # export ckpt avg_n -# CUDA_VISIBLE_DEVICES=0 ./local/export.sh ${conf_path} exp/${ckpt}/checkpoints/${avg_ckpt} exp/${ckpt}/checkpoints/${avg_ckpt}.jit -# fi - # Optionally, you can add LM and test it with runtime. -if [ ${stage} -le 6 ] && [ ${stop_stage} -ge 6 ]; then +if [ ${stage} -le 5 ] && [ ${stop_stage} -ge 5 ]; then # test a single .wav file CUDA_VISIBLE_DEVICES=0 ./local/test_hub.sh ${conf_path} exp/${ckpt}/checkpoints/${avg_ckpt} ${audio_file} || exit -1 fi -if [ ${stage} -le 7 ] && [ ${stop_stage} -ge 7 ]; then +# if [ ${stage} -le 51 ] && [ ${stop_stage} -ge 51 ]; then +# # export ckpt avg_n +# CUDA_VISIBLE_DEVICES=0 ./local/export.sh ${conf_path} exp/${ckpt}/checkpoints/${avg_ckpt} exp/${ckpt}/checkpoints/${avg_ckpt}.jit +# fi + +if [ ${stage} -le 101 ] && [ ${stop_stage} -ge 101 ]; then echo "warning: deps on kaldi and srilm, please make sure installed." # train lm and build TLG ./local/tlg.sh --corpus aishell --lmtype srilm From 649fcc4c165c5bdf604c26bd23523db13df895e6 Mon Sep 17 00:00:00 2001 From: huangyuxin Date: Wed, 24 Nov 2021 05:29:19 +0000 Subject: [PATCH 2/3] revise some programming mistakes --- examples/aishell/asr1/READEME.md | 82 +++++++++++++++++--------------- 1 file changed, 43 insertions(+), 39 deletions(-) diff --git a/examples/aishell/asr1/READEME.md b/examples/aishell/asr1/READEME.md index 3afd19546..fe9688709 100644 --- a/examples/aishell/asr1/READEME.md +++ b/examples/aishell/asr1/READEME.md @@ -4,22 +4,22 @@ This example contains code used to train a [Conformer](http://arxiv.org/abs/2008 ## Overview -All the scirpt you need is in the ```run.sh```. There are several stages in the ```run.sh```, and each stage has it's function. +All the scirpts you need are in the ```run.sh```. There are several stages in the ```run.sh```, and each stage has its function. | Stage | Function | | :---- | :----------------------------------------------------------- | | 0 | Process data. It includes:
(1) Download the dataset
(2) Caculate the CMVN of the train dataset
(3) Get the vocabulary file
(4) Get the manifest files of the train, development and test dataset | | 1 | Train the model | -| 2 | Get the final model by average the top-k model , set k = 1 means choose the best model | +| 2 | Get the final model by averaging the top-k models, set k = 1 means choose the best model | | 3 | Test the final model performance | | 4 | Get ctc alignment of test data using the final model | | 5 | Infer the single audio file | | 51 | (Not supported at now) Transform the dynamic graph model to static graph model | | 101 | (Need further installation) Train language model and Build TLG | -You can choose to run a range of stages by set the ```stage``` and ```stop_stage ``` . +You can choose to run a range of stages by setting the ```stage``` and ```stop_stage ``` . -For example , if you want to execute the code in stage 2 and stage 3, you can run this script: +For example, if you want to execute the code in stage 2 and stage 3, you can run this script: ```bash bash run.sh --stage 2 --stop_stage 3 @@ -33,7 +33,7 @@ bash run.sh --stage 0 --stop_stage 0 -The document below will decribe the scripts in the ```run.sh``` in detail. +The document below will describe the scripts in the ```run.sh``` in detail. ## The environment variables @@ -41,7 +41,7 @@ The path.sh contains the environment variable. ```bash source path.sh ``` -This script needs to be run firstly. +This script needs to be run firstly. And another script is also needed: @@ -56,14 +56,14 @@ It will support the way of using```--varibale value``` in the shell scripts. ## The local variables Some local variables are set in the ```run.sh```. -```gpus``` denotes the GPU number you want to use. If you set ```gpus=```, it means you only use CPU. +```gpus``` denotes the GPU number you want to use. If you set ```gpus=```, it means you only use CPU. -```stage``` denotes the number of stage you want to start from in the expriments. +```stage``` denotes the number of stage you want to start from in the expriments. ```stop stage```denotes the number of stage you want to end at in the expriments. ```conf_path``` denotes the config path of the model. -```avg_num``` denotes the number K of top-K model you want to average to get the final model. +```avg_num``` denotes the number K of top-K models you want to average to get the final model. ```ckpt``` denotes the checkpoint prefix of the model, e.g. "conformer" @@ -81,7 +81,7 @@ bash run.sh --gpus 0,1 --avg_num 20 ## Stage 0: Data processing -To use this example, you need to process data firstly and you can use the stage 0 in the ```run.sh``` to do this. The code is shown below: +To use this example, you need to process data firstly and you can use stage 0 in the ```run.sh``` to do this. The code is shown below: ```bash if [ ${stage} -le 0 ] && [ ${stop_stage} -ge 0 ]; then # prepare data @@ -89,7 +89,7 @@ To use this example, you need to process data firstly and you can use the stage fi ``` -The stage 0 is for processing the data. +Stage 0 is for processing the data. If you only want to process the data. You can run @@ -105,49 +105,53 @@ source ${MAIN_ROOT}/utils/parse_options.sh bash ./local/data.sh ``` -Aftre processing the data, the ``data`` directory will be look like this: +After processing the data, the ``data`` directory will look like this: ```bash data/ -├── dev.meta -├── manifest.dev.raw -├── manifest.test.raw -├── manifest.train.raw -├── mean_std.json -├── test.meta -├── train.meta -└── vocab.txt +|-- dev.meta +|-- lang_char +| `-- vocab.txt +|-- manifest.dev +|-- manifest.dev.raw +|-- manifest.test +|-- manifest.test.raw +|-- manifest.train +|-- manifest.train.raw +|-- mean_std.json +|-- test.meta +`-- train.meta ``` ## Stage 1: Model training -If you want to train the model. you can use the stage 1 in the ```run.sh```. The code is shown below. +If you want to train the model. you can use stage 1 in the ```run.sh```. The code is shown below. ```bash if [ ${stage} -le 1 ] && [ ${stop_stage} -ge 1 ]; then # train model, all `ckpt` under `exp` dir - CUDA_VISIBLE_DEVICES=${gpus} ./local/train.sh ${conf_path} ${ckpt} + CUDA_VISIBLE_DEVICES=${gpus} ./local/train.sh ${conf_path} ${ckpt} fi ``` -If you want to train the model, you can use the script below to execute the stage 0 and stage 1: +If you want to train the model, you can use the script below to execute stage 0 and stage 1: ```bash bash run.sh --stage 0 --stop_stage 1 ``` -or you can run these scripts in command line (only use CPU). +or you can run these scripts in the command line (only use CPU). ```bash source path.sh source ${MAIN_ROOT}/utils/parse_options.sh bash ./local/data.sh -CUDA_VISIBLE_DEVICES= ./local/train.sh conf/conformer.yaml conformer +CUDA_VISIBLE_DEVICES= ./local/train.sh conf/conformer.yaml conformer ``` -## Stage 2: Top-k model averaging +## Stage 2: Top-k models averaging -After training the model, we need to get the final model for test and infer. In every epoch, the model checkpoint is saved , so we can choose the best model from them based on the validation loss or we can sort them and average the top-k model parameters to get the final model. We can use the stage 2 to do this, and the code is shown below: +After training the model, we need to get the final model for testing and inference. In every epoch, the model checkpoint is saved, so we can choose the best model from them based on the validation loss or we can sort them and average the parameters of the top-k models to get the final model. We can use stage 2 to do this, and the code is shown below: ```bash if [ ${stage} -le 2 ] && [ ${stop_stage} -ge 2 ]; then # avg n best model @@ -155,13 +159,13 @@ After training the model, we need to get the final model for test and infer. In fi ``` The ```avg.sh``` is in the ```../../../utils/``` which is define in the ```path.sh```. -If you want to get the final model, you can use the script below to execute the stage 0, stage 1, and stage 2: +If you want to get the final model, you can use the script below to execute stage 0, stage 1, and stage 2: ```bash bash run.sh --stage 0 --stop_stage 2 ``` -or you can run these scripts in command line (only use CPU). +or you can run these scripts in the command line (only use CPU). ```bash source path.sh source ${MAIN_ROOT}/utils/parse_options.sh @@ -174,7 +178,7 @@ avg.sh best exp/conformer/checkpoints 20 ## Stage 3: Model Testing -To know the preformence of the model, test stage is needed. The code of test stage is shown below: +The test stage is to evaluate the model performance.. The code of test stage is shown below: ```bash if [ ${stage} -le 3 ] && [ ${stop_stage} -ge 3 ]; then @@ -183,13 +187,13 @@ To know the preformence of the model, test stage is needed. The code of test sta fi ``` -If you want to train a model and test it, you can use the script below to execute the stage 0, stage 1, stage 2, and stage 3 : +If you want to train a model and test it, you can use the script below to execute stage 0, stage 1, stage 2, and stage 3: ```bash bash run.sh --stage 0 --stop_stage 3 ``` -or you can run these scripts in command line (only use CPU). +or you can run these scripts in the command line (only use CPU). ```bash source path.sh @@ -213,20 +217,20 @@ If you want to get the alignment between the audio and the text, you can use the fi ``` -If you want to train the model, test it and do the alignment, you can use the script below to execute the stage 0, stage 1, stage 2, and stage 3 : +If you want to train the model, test it and do the alignment, you can use the script below to execute stage 0, stage 1, stage 2, and stage 3 : ```bash bash run.sh --stage 0 --stop_stage 4 ``` -or if you only need to train a model and do the alignment, you can use these scripts to escape the stage 3(test stage): +or if you only need to train a model and do the alignment, you can use these scripts to escape stage 3(test stage): ```bash bash run.sh --stage 0 --stop_stage 2 bash run.sh --stage 4 --stop_stage 4 ``` -or you can also use these scripts in command line (only use CPU). +or you can also use these scripts in the command line (only use CPU). ```bash source path.sh @@ -243,7 +247,7 @@ CUDA_VISIBLE_DEVICES= ./local/align.sh conf/conformer.yaml exp/conformer/checkpo ## Stage 5: Single audio file inference -In some situation, you want to use the trained model to do the inference for the single audio file. You can use the stage 5. The code is shown below +In some situations, you want to use the trained model to do the inference for the single audio file. You can use stage 5. The code is shown below ```bash if [ ${stage} -le 5 ] && [ ${stop_stage} -ge 5 ]; then @@ -252,14 +256,14 @@ In some situation, you want to use the trained model to do the inference for the fi ``` -you can train the model by yourself using ```bash run.sh --stage 0 --stop_stage 3```, or you can download the pretrained model by the script below: +you can train the model by yourself using ```bash run.sh --stage 0 --stop_stage 3```, or you can download the pretrained model by the script below: ``` wget https://deepspeech.bj.bcebos.com/release2.1/aishell/s1/aishell.release.tar.gz tar aishell.release.tar.gz ``` -You need to prepare an audio file, please confirme the sample rate of the audio is 16K. Assume the path of the audio file is ```data/test_audio.wav```, you can get the result by runing the script below. +You need to prepare an audio file, please confirm the sample rate of the audio is 16K. Assume the path of the audio file is ```data/test_audio.wav```, you can get the result by running the script below. ```bash CUDA_VISIBLE_DEVICES= ./local/test_hub.sh conf/conformer.yaml exp/conformer/checkpoints/avg_20 data/test_audio.wav @@ -284,7 +288,7 @@ It is not supported at now, so we set a large stage number for this stage. ## Stage: 101 Language model training and TLG building (Need further installation! ) -You need to install the kaldi and srilm to use the stage 101, it is used for train language model and build TLG. To do further installation, you need to do these: +You need to install the kaldi and srilm to use stage 101, it is used for training language model and building TLG. To do further installation, you need to do these: ```bash # go to the root of the repo From 45ac9e0520377cab92b3c0e96f75c0ec5fce6532 Mon Sep 17 00:00:00 2001 From: huangyuxin Date: Thu, 25 Nov 2021 09:46:47 +0000 Subject: [PATCH 3/3] delete the unsupport --- examples/aishell/asr1/READEME.md | 169 +++++++++++++++++++------------ examples/aishell/asr1/run.sh | 14 +-- 2 files changed, 113 insertions(+), 70 deletions(-) diff --git a/examples/aishell/asr1/READEME.md b/examples/aishell/asr1/READEME.md index fe9688709..a873a2dcd 100644 --- a/examples/aishell/asr1/READEME.md +++ b/examples/aishell/asr1/READEME.md @@ -1,6 +1,6 @@ -# Conformer ASR with Aishell +# Transformer/Conformer ASR with Aishell -This example contains code used to train a [Conformer](http://arxiv.org/abs/2008.03802) model with [Aishell dataset](http://www.openslr.org/resources/33) +This example contains code used to train a Transformer or [Conformer](http://arxiv.org/abs/2008.03802) model with [Aishell dataset](http://www.openslr.org/resources/33) ## Overview @@ -14,16 +14,16 @@ All the scirpts you need are in the ```run.sh```. There are several stages in th | 3 | Test the final model performance | | 4 | Get ctc alignment of test data using the final model | | 5 | Infer the single audio file | -| 51 | (Not supported at now) Transform the dynamic graph model to static graph model | -| 101 | (Need further installation) Train language model and Build TLG | -You can choose to run a range of stages by setting the ```stage``` and ```stop_stage ``` . + +You can choose to run a range of stages by setting the ```stage``` and ```stop_stage ``` . For example, if you want to execute the code in stage 2 and stage 3, you can run this script: ```bash bash run.sh --stage 2 --stop_stage 3 ``` + Or you can set ```stage``` equal to ```stop-stage``` to only run one stage. For example, if you only want to run ```stage 0```, you can use the script below: @@ -38,10 +38,12 @@ The document below will describe the scripts in the ```run.sh``` in detail. ## The environment variables The path.sh contains the environment variable. + ```bash source path.sh ``` -This script needs to be run firstly. + +This script needs to be run firstly. And another script is also needed: @@ -56,20 +58,20 @@ It will support the way of using```--varibale value``` in the shell scripts. ## The local variables Some local variables are set in the ```run.sh```. -```gpus``` denotes the GPU number you want to use. If you set ```gpus=```, it means you only use CPU. +```gpus``` denotes the GPU number you want to use. If you set ```gpus=```, it means you only use CPU. -```stage``` denotes the number of stage you want to start from in the expriments. +```stage``` denotes the number of stage you want to start from in the expriments. ```stop stage```denotes the number of stage you want to end at in the expriments. ```conf_path``` denotes the config path of the model. ```avg_num``` denotes the number K of top-K models you want to average to get the final model. -```ckpt``` denotes the checkpoint prefix of the model, e.g. "conformer" - ```audio file``` denotes the file path of the single file you want to infer in stage 6 -You can set the local variables when you use the ```run.sh``` +```ckpt``` denotes the checkpoint prefix of the model, e.g. "conformer" + +You can set the local variables (except ```ckpt```) when you use the ```run.sh``` For example, you can set the ```gpus``` and ``avg_num`` when you use the command line.: @@ -81,7 +83,8 @@ bash run.sh --gpus 0,1 --avg_num 20 ## Stage 0: Data processing -To use this example, you need to process data firstly and you can use stage 0 in the ```run.sh``` to do this. The code is shown below: +To use this example, you need to process data firstly and you can use stage 0 in the ```run.sh``` to do this. The code is shown below: + ```bash if [ ${stage} -le 0 ] && [ ${stop_stage} -ge 0 ]; then # prepare data @@ -101,7 +104,6 @@ You can also just run these scripts in your command line. ```bash source path.sh -source ${MAIN_ROOT}/utils/parse_options.sh bash ./local/data.sh ``` @@ -128,47 +130,52 @@ data/ ## Stage 1: Model training If you want to train the model. you can use stage 1 in the ```run.sh```. The code is shown below. + ```bash if [ ${stage} -le 1 ] && [ ${stop_stage} -ge 1 ]; then # train model, all `ckpt` under `exp` dir - CUDA_VISIBLE_DEVICES=${gpus} ./local/train.sh ${conf_path} ${ckpt} + CUDA_VISIBLE_DEVICES=${gpus} ./local/train.sh ${conf_path} ${ckpt} fi ``` If you want to train the model, you can use the script below to execute stage 0 and stage 1: + ```bash bash run.sh --stage 0 --stop_stage 1 ``` + or you can run these scripts in the command line (only use CPU). + ```bash source path.sh -source ${MAIN_ROOT}/utils/parse_options.sh bash ./local/data.sh -CUDA_VISIBLE_DEVICES= ./local/train.sh conf/conformer.yaml conformer +CUDA_VISIBLE_DEVICES= ./local/train.sh conf/conformer.yaml conformer ``` -## Stage 2: Top-k models averaging +## Stage 2: Top-k Models Averaging + +After training the model, we need to get the final model for testing and inference. In every epoch, the model checkpoint is saved, so we can choose the best model from them based on the validation loss or we can sort them and average the parameters of the top-k models to get the final model. We can use stage 2 to do this, and the code is shown below: -After training the model, we need to get the final model for testing and inference. In every epoch, the model checkpoint is saved, so we can choose the best model from them based on the validation loss or we can sort them and average the parameters of the top-k models to get the final model. We can use stage 2 to do this, and the code is shown below: ```bash if [ ${stage} -le 2 ] && [ ${stop_stage} -ge 2 ]; then # avg n best model avg.sh best exp/${ckpt}/checkpoints ${avg_num} fi ``` + The ```avg.sh``` is in the ```../../../utils/``` which is define in the ```path.sh```. -If you want to get the final model, you can use the script below to execute stage 0, stage 1, and stage 2: +If you want to get the final model, you can use the script below to execute stage 0, stage 1, and stage 2: ```bash bash run.sh --stage 0 --stop_stage 2 ``` or you can run these scripts in the command line (only use CPU). + ```bash source path.sh -source ${MAIN_ROOT}/utils/parse_options.sh bash ./local/data.sh CUDA_VISIBLE_DEVICES= ./local/train.sh conf/conformer.yaml conformer avg.sh best exp/conformer/checkpoints 20 @@ -187,7 +194,7 @@ The test stage is to evaluate the model performance.. The code of test stage is fi ``` -If you want to train a model and test it, you can use the script below to execute stage 0, stage 1, stage 2, and stage 3: +If you want to train a model and test it, you can use the script below to execute stage 0, stage 1, stage 2, and stage 3 : ```bash bash run.sh --stage 0 --stop_stage 3 @@ -197,7 +204,6 @@ or you can run these scripts in the command line (only use CPU). ```bash source path.sh -source ${MAIN_ROOT}/utils/parse_options.sh bash ./local/data.sh CUDA_VISIBLE_DEVICES= ./local/train.sh conf/conformer.yaml conformer avg.sh best exp/conformer/checkpoints 20 @@ -206,7 +212,75 @@ CUDA_VISIBLE_DEVICES= ./local/test.sh conf/conformer.yaml exp/conformer/checkpoi -## Stage 4: CTC alignment +## Pretrained Model + +You can get the pretrained transfomer or conformer using the scripts below: + +```bash +Conformer: +wget https://deepspeech.bj.bcebos.com/release2.1/aishell/s1/aishell.release.tar.gz + +Chunk Conformer: +wget https://deepspeech.bj.bcebos.com/release2.1/aishell/s1/aishell.chunk.release.tar.gz + +Transfomer: +wget https://paddlespeech.bj.bcebos.com/s2t/aishell/asr1/transformer.model.tar.gz + +``` + +using the ```tar``` scripts to unpack the model and then you can use the script to test the modle. + +For example: + +``` +wget https://paddlespeech.bj.bcebos.com/s2t/aishell/asr1/transformer.model.tar.gz +tar xzvf transformer.model.tar.gz +source path.sh +# If you have process the data and get the manifest file, you can skip the following 2 steps +bash local/data.sh --stage -1 --stop_stage -1 +bash local/data.sh --stage 2 --stop_stage 2 + +CUDA_VISIBLE_DEVICES= ./local/test.sh conf/transformer.yaml exp/transformer/checkpoints/avg_20 +``` + + + +The performance of the released models are shown below: + +### Conformer + +| Model | Params | Config | Augmentation | Test set | Decode method | Loss | CER | +| --------- | ------ | ------------------- | ---------------- | -------- | ---------------------- | ---- | -------- | +| conformer | 47.07M | conf/conformer.yaml | spec_aug + shift | test | attention | - | 0.059858 | +| conformer | 47.07M | conf/conformer.yaml | spec_aug + shift | test | ctc_greedy_search | - | 0.062311 | +| conformer | 47.07M | conf/conformer.yaml | spec_aug + shift | test | ctc_prefix_beam_search | - | 0.062196 | +| conformer | 47.07M | conf/conformer.yaml | spec_aug + shift | test | attention_rescoring | - | 0.054694 | + + +### Chunk Conformer + +Need set `decoding.decoding_chunk_size=16` when decoding. + +| Model | Params | Config | Augmentation | Test set | Decode method | Chunk Size & Left Chunks | Loss | CER | +| --------- | ------ | ------------------------- | ---------------- | -------- | ---------------------- | ------------------------ | ---- | -------- | +| conformer | 47.06M | conf/chunk_conformer.yaml | spec_aug + shift | test | attention | 16, -1 | - | 0.061939 | +| conformer | 47.06M | conf/chunk_conformer.yaml | spec_aug + shift | test | ctc_greedy_search | 16, -1 | - | 0.070806 | +| conformer | 47.06M | conf/chunk_conformer.yaml | spec_aug + shift | test | ctc_prefix_beam_search | 16, -1 | - | 0.070739 | +| conformer | 47.06M | conf/chunk_conformer.yaml | spec_aug + shift | test | attention_rescoring | 16, -1 | - | 0.059400 | + + +### Transformer + +| Model | Params | Config | Augmentation | Test set | Decode method | Loss | CER | +| ----------- | ------ | --------------------- | ------------ | -------- | ---------------------- | ----------------- | -------- | +| transformer | 31.95M | conf/transformer.yaml | spec_aug | test | attention | 3.858648955821991 | 0.057293 | +| transformer | 31.95M | conf/transformer.yaml | spec_aug | test | ctc_greedy_search | 3.858648955821991 | 0.061837 | +| transformer | 31.95M | conf/transformer.yaml | spec_aug | test | ctc_prefix_beam_search | 3.858648955821991 | 0.061685 | +| transformer | 31.95M | conf/transformer.yaml | spec_aug | test | attention_rescoring | 3.858648955821991 | 0.053844 | + + + +## Stage 4: CTC Alignment If you want to get the alignment between the audio and the text, you can use the ctc alignment. The code of this stage is shown below: @@ -217,7 +291,7 @@ If you want to get the alignment between the audio and the text, you can use the fi ``` -If you want to train the model, test it and do the alignment, you can use the script below to execute stage 0, stage 1, stage 2, and stage 3 : +If you want to train the model, test it and do the alignment, you can use the script below to execute stage 0, stage 1, stage 2, and stage 3 : ```bash bash run.sh --stage 0 --stop_stage 4 @@ -234,7 +308,6 @@ or you can also use these scripts in the command line (only use CPU). ```bash source path.sh -source ${MAIN_ROOT}/utils/parse_options.sh bash ./local/data.sh CUDA_VISIBLE_DEVICES= ./local/train.sh conf/conformer.yaml conformer avg.sh best exp/conformer/checkpoints 20 @@ -245,61 +318,29 @@ CUDA_VISIBLE_DEVICES= ./local/align.sh conf/conformer.yaml exp/conformer/checkpo -## Stage 5: Single audio file inference +## Stage 5: Single Audio File Inference -In some situations, you want to use the trained model to do the inference for the single audio file. You can use stage 5. The code is shown below +In some situations, you want to use the trained model to do the inference for the single audio file. You can use stage 5. The code is shown below ```bash if [ ${stage} -le 5 ] && [ ${stop_stage} -ge 5 ]; then # test a single .wav file - CUDA_VISIBLE_DEVICES=0 ./local/test_hub.sh ${conf_path} exp/${ckpt}/checkpoints/${avg_ckpt} ${audio_file} || exit -1 + CUDA_VISIBLE_DEVICES=0 ./local/test_wav.sh ${conf_path} exp/${ckpt}/checkpoints/${avg_ckpt} ${audio_file} || exit -1 fi ``` you can train the model by yourself using ```bash run.sh --stage 0 --stop_stage 3```, or you can download the pretrained model by the script below: -``` -wget https://deepspeech.bj.bcebos.com/release2.1/aishell/s1/aishell.release.tar.gz -tar aishell.release.tar.gz -``` - -You need to prepare an audio file, please confirm the sample rate of the audio is 16K. Assume the path of the audio file is ```data/test_audio.wav```, you can get the result by running the script below. - ```bash -CUDA_VISIBLE_DEVICES= ./local/test_hub.sh conf/conformer.yaml exp/conformer/checkpoints/avg_20 data/test_audio.wav +wget https://paddlespeech.bj.bcebos.com/s2t/aishell/asr1/transformer.model.tar.gz +tar xzvf transformer.model.tar.gz ``` - - -## Stage 51: Static model transforming(not supported at now) - -To transform the dynamic model to static model,stage 51 can be used. The code of this stage is shown below: - -```bash - if [ ${stage} -le 5 ] && [ ${stop_stage} -ge 5 ]; then - # export ckpt avg_n - CUDA_VISIBLE_DEVICES=0 ./local/export.sh ${conf_path} exp/${ckpt}/checkpoints/${avg_ckpt} exp/${ckpt}/checkpoints/${avg_ckpt}.jit - fi -``` - -It is not supported at now, so we set a large stage number for this stage. - - - -## Stage: 101 Language model training and TLG building (Need further installation! ) - -You need to install the kaldi and srilm to use stage 101, it is used for training language model and building TLG. To do further installation, you need to do these: +You need to prepare an audio file, please confirm the sample rate of the audio is 16K. Assume the path of the audio file is ```data/test_audio.wav```, you can get the result by running the script below. ```bash -# go to the root of the repo -cd ../../../ -# Do the further installation -pip install -e . -cd tools -bash extras/install_openblas.sh -bash extras/install_kaldi.sh +CUDA_VISIBLE_DEVICES= ./local/test_wav.sh conf/transformer.yaml exp/transformer/checkpoints/avg_20 data/test_audio.wav ``` -You need to be patient, since installing the kaldi takes some time. diff --git a/examples/aishell/asr1/run.sh b/examples/aishell/asr1/run.sh index c687e966e..41af24453 100644 --- a/examples/aishell/asr1/run.sh +++ b/examples/aishell/asr1/run.sh @@ -14,7 +14,7 @@ avg_ckpt=avg_${avg_num} ckpt=$(basename ${conf_path} | awk -F'.' '{print $1}') echo "checkpoint name ${ckpt}" -audio_file="data/tmp.wav" +audio_file="data/test_single_audio.wav" if [ ${stage} -le 0 ] && [ ${stop_stage} -ge 0 ]; then # prepare data @@ -44,14 +44,16 @@ fi # Optionally, you can add LM and test it with runtime. if [ ${stage} -le 5 ] && [ ${stop_stage} -ge 5 ]; then # test a single .wav file - CUDA_VISIBLE_DEVICES=0 ./local/test_hub.sh ${conf_path} exp/${ckpt}/checkpoints/${avg_ckpt} ${audio_file} || exit -1 + CUDA_VISIBLE_DEVICES=0 ./local/test_wav.sh ${conf_path} exp/${ckpt}/checkpoints/${avg_ckpt} ${audio_file} || exit -1 fi -# if [ ${stage} -le 51 ] && [ ${stop_stage} -ge 51 ]; then -# # export ckpt avg_n -# CUDA_VISIBLE_DEVICES=0 ./local/export.sh ${conf_path} exp/${ckpt}/checkpoints/${avg_ckpt} exp/${ckpt}/checkpoints/${avg_ckpt}.jit -# fi +# Not supported at now!!! +if [ ${stage} -le 51 ] && [ ${stop_stage} -ge 51 ]; then + # export ckpt avg_n + CUDA_VISIBLE_DEVICES=0 ./local/export.sh ${conf_path} exp/${ckpt}/checkpoints/${avg_ckpt} exp/${ckpt}/checkpoints/${avg_ckpt}.jit +fi +# Need further installation! Read the install.md to complete further installation if [ ${stage} -le 101 ] && [ ${stop_stage} -ge 101 ]; then echo "warning: deps on kaldi and srilm, please make sure installed." # train lm and build TLG