Skip to content

Commit c21b6a2

Browse files
Add finetuning script for aishell (k2-fsa#974)
* add aishell finetune scripts * add an example bash script
1 parent 2a5a75c commit c21b6a2

File tree

4 files changed

+1680
-0
lines changed

4 files changed

+1680
-0
lines changed

egs/wenetspeech/ASR/finetune.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env bash
2+
3+
# fix segmentation fault reported in https://github.com/k2-fsa/icefall/issues/674
4+
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
5+
6+
set -eou pipefail
7+
8+
stage=-1
9+
stop_stage=100
10+
11+
# This is an example script for fine-tuning. Here, we fine-tune a model trained
12+
# on WenetSpeech on Aishell. The model used for fine-tuning is
13+
# pruned_transducer_stateless2 (zipformer). If you want to fine-tune model
14+
# from another recipe, you can adapt ./pruned_transducer_stateless2/finetune.py
15+
# for that recipe. If you have any problem, please open up an issue in https://github.com/k2-fsa/icefall/issues.
16+
17+
# We assume that you have already prepared the Aishell manfiest&features under ./data.
18+
# If you haven't done that, please see https://github.com/k2-fsa/icefall/blob/master/egs/aishell/ASR/prepare.sh.
19+
20+
. shared/parse_options.sh || exit 1
21+
22+
log() {
23+
# This function is from espnet
24+
local fname=${BASH_SOURCE[1]##*/}
25+
echo -e "$(date '+%Y-%m-%d %H:%M:%S') (${fname}:${BASH_LINENO[0]}:${FUNCNAME[1]}) $*"
26+
}
27+
28+
if [ $stage -le -1 ] && [ $stop_stage -ge -1 ]; then
29+
log "Stage -1: Download Pre-trained model"
30+
31+
# clone from huggingface
32+
git lfs install
33+
git clone https://huggingface.co/luomingshuang/icefall_asr_wenetspeech_pruned_transducer_stateless2
34+
35+
fi
36+
37+
if [ $stage -le 0 ] && [ $stop_stage -ge 0 ]; then
38+
log "Stage 0: Start fine-tuning"
39+
40+
# The following configuration of lr schedule should work well
41+
# You may also tune the following parameters to adjust learning rate schedule
42+
initial_lr=0.0001
43+
lr_epochs=100
44+
lr_batches=100000
45+
46+
# We recommend to start from an averaged model
47+
finetune_ckpt=icefall_asr_wenetspeech_pruned_transducer_stateless2/exp/pretrained_epoch_10_avg_2.pt
48+
lang_dir=icefall_asr_wenetspeech_pruned_transducer_stateless2/data/lang_char
49+
export CUDA_VISIBLE_DEVICES="0,1"
50+
51+
./pruned_transducer_stateless2/finetune.py \
52+
--world-size 2 \
53+
--master-port 18180 \
54+
--num-epochs 15 \
55+
--context-size 2 \
56+
--exp-dir pruned_transducer_stateless2/exp_aishell_finetune \
57+
--initial-lr $initial_lr \
58+
--lr-epochs $lr_epochs \
59+
--lr-batches $lr_batches \
60+
--lang-dir $lang_dir \
61+
--do-finetune True \
62+
--finetune-ckpt $finetune_ckpt \
63+
--max-duration 200
64+
fi
65+
66+
if [ $stage -le 1 ] && [ $stop_stage -ge 1 ]; then
67+
log "Stage 1: Decoding"
68+
69+
epoch=4
70+
avg=4
71+
72+
for m in greedy_search modified_beam_search; do
73+
python pruned_transducer_stateless2/decode_aishell.py \
74+
--epoch $epoch \
75+
--avg $avg \
76+
--context-size 2 \
77+
--beam-size 4 \
78+
--exp-dir pruned_transducer_stateless2/exp_aishell_finetune \
79+
--max-duration 400 \
80+
--decoding-method $m
81+
done
82+
fi
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../aishell/ASR/tdnn_lstm_ctc/asr_datamodule.py

0 commit comments

Comments
 (0)