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
## 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 |
| 3 | Test the final model performance |
| 4 | Get ctc alignment of test data using the final model |
| 4 | Get ctc alignment of test data using the final model |
| 5 | Infer the single audio file |
| 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:
For example, if you want to execute the code in stage 2 and stage 3, you can run this script:
```bash
```bash
bash run.sh --stage 2 --stop_stage 3
bash run.sh --stage 2 --stop_stage 3
```
```
Or you can set ```stage``` equal to ```stop-stage``` to only run one stage.
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:
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 environment variables
The path.sh contains the environment variable.
The path.sh contains the environment variable.
```bash
```bash
source path.sh
source path.sh
```
```
This script needs to be run firstly.
This script needs to be run firstly.
And another script is also needed:
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
## The local variables
Some local variables are set in the ```run.sh```.
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.
```stop stage```denotes the number of stage you want to end at in the expriments.
```conf_path``` denotes the config path of the model.
```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.
```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
```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.:
For example, you can set the ```gpus``` and ``avg_num`` when you use the command line.:
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
```bash
if [ ${stage} -le 2 ] && [ ${stop_stage} -ge 2 ]; then
if [ ${stage} -le 2 ] && [ ${stop_stage} -ge 2 ]; then
# avg n best model
# avg n best model
avg.sh best exp/${ckpt}/checkpoints ${avg_num}
avg.sh best exp/${ckpt}/checkpoints ${avg_num}
fi
fi
```
```
The ```avg.sh``` is in the ```../../../utils/``` which is define in the ```path.sh```.
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
bash run.sh --stage 0 --stop_stage 2
bash run.sh --stage 0 --stop_stage 2
```
```
or you can run these scripts in the command line (only use CPU).
or you can run these scripts in the command line (only use CPU).
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.
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.
## 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
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: