Skip to content

Commit 5c98096

Browse files
vijayadityadanpovey
authored andcommitted
[egs] swbd/chain : added blstm script using fast-LSTM; added BLSTM+TDNN script. (#1497)
1 parent eba49a0 commit 5c98096

File tree

4 files changed

+484
-1
lines changed

4 files changed

+484
-1
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
tuning/run_blstm_6j.sh
1+
tuning/run_blstm_6k.sh
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tuning/run_tdnn_blstm_1a.sh
Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
#!/bin/bash
2+
3+
# 6k is same as 6j, but with the fast lstm layers
4+
5+
# local/chain/compare_wer_general.sh blstm_6j_sp blstm_6k_sp
6+
# System blstm_6j_sp blstm_6k_sp
7+
# WER on train_dev(tg) 13.80 13.25
8+
# WER on train_dev(fg) 12.64 12.27
9+
# WER on eval2000(tg) 15.6 15.7
10+
# WER on eval2000(fg) 14.2 14.5
11+
# Final train prob -0.055 -0.052
12+
# Final valid prob -0.077 -0.080
13+
# Final train prob (xent) -0.777 -0.743
14+
# Final valid prob (xent) -0.9126 -0.8816
15+
16+
set -e
17+
18+
# configs for 'chain'
19+
stage=12
20+
train_stage=-10
21+
get_egs_stage=-10
22+
speed_perturb=true
23+
dir=exp/chain/blstm_6k # Note: _sp will get added to this if $speed_perturb == true.
24+
decode_iter=
25+
decode_dir_affix=
26+
27+
# training options
28+
leftmost_questions_truncate=-1
29+
chunk_width=150
30+
chunk_left_context=40
31+
chunk_right_context=40
32+
xent_regularize=0.025
33+
self_repair_scale=0.00001
34+
label_delay=0
35+
36+
# decode options
37+
extra_left_context=50
38+
extra_right_context=50
39+
frames_per_chunk=
40+
41+
remove_egs=false
42+
common_egs_dir=
43+
44+
affix=
45+
# End configuration section.
46+
echo "$0 $@" # Print the command line for logging
47+
48+
. ./cmd.sh
49+
. ./path.sh
50+
. ./utils/parse_options.sh
51+
52+
if ! cuda-compiled; then
53+
cat <<EOF && exit 1
54+
This script is intended to be used with GPUs but you have not compiled Kaldi with CUDA
55+
If you want to use GPUs (and have them), go to src/, and configure and make on a machine
56+
where "nvcc" is installed.
57+
EOF
58+
fi
59+
60+
# The iVector-extraction and feature-dumping parts are the same as the standard
61+
# nnet3 setup, and you can skip them by setting "--stage 8" if you have already
62+
# run those things.
63+
64+
suffix=
65+
if [ "$speed_perturb" == "true" ]; then
66+
suffix=_sp
67+
fi
68+
69+
dir=$dir${affix:+_$affix}
70+
if [ $label_delay -gt 0 ]; then dir=${dir}_ld$label_delay; fi
71+
dir=${dir}$suffix
72+
train_set=train_nodup$suffix
73+
ali_dir=exp/tri4_ali_nodup$suffix
74+
treedir=exp/chain/tri5_7d_tree$suffix
75+
lang=data/lang_chain_2y
76+
77+
78+
# if we are using the speed-perturbed data we need to generate
79+
# alignments for it.
80+
local/nnet3/run_ivector_common.sh --stage $stage \
81+
--speed-perturb $speed_perturb \
82+
--generate-alignments $speed_perturb || exit 1;
83+
84+
85+
if [ $stage -le 9 ]; then
86+
# Get the alignments as lattices (gives the CTC training more freedom).
87+
# use the same num-jobs as the alignments
88+
nj=$(cat exp/tri4_ali_nodup$suffix/num_jobs) || exit 1;
89+
steps/align_fmllr_lats.sh --nj $nj --cmd "$train_cmd" data/$train_set \
90+
data/lang exp/tri4 exp/tri4_lats_nodup$suffix
91+
rm exp/tri4_lats_nodup$suffix/fsts.*.gz # save space
92+
fi
93+
94+
95+
if [ $stage -le 10 ]; then
96+
# Create a version of the lang/ directory that has one state per phone in the
97+
# topo file. [note, it really has two states.. the first one is only repeated
98+
# once, the second one has zero or more repeats.]
99+
rm -rf $lang
100+
cp -r data/lang $lang
101+
silphonelist=$(cat $lang/phones/silence.csl) || exit 1;
102+
nonsilphonelist=$(cat $lang/phones/nonsilence.csl) || exit 1;
103+
# Use our special topology... note that later on may have to tune this
104+
# topology.
105+
steps/nnet3/chain/gen_topo.py $nonsilphonelist $silphonelist >$lang/topo
106+
fi
107+
108+
if [ $stage -le 11 ]; then
109+
# Build a tree using our new topology.
110+
steps/nnet3/chain/build_tree.sh --frame-subsampling-factor 3 \
111+
--leftmost-questions-truncate $leftmost_questions_truncate \
112+
--context-opts "--context-width=2 --central-position=1" \
113+
--cmd "$train_cmd" 7000 data/$train_set $lang $ali_dir $treedir
114+
fi
115+
116+
if [ $stage -le 12 ]; then
117+
echo "$0: creating neural net configs using the xconfig parser";
118+
119+
num_targets=$(tree-info $treedir/tree |grep num-pdfs|awk '{print $2}')
120+
[ -z $num_targets ] && { echo "$0: error getting num-targets"; exit 1; }
121+
learning_rate_factor=$(echo "print 0.5/$xent_regularize" | python)
122+
123+
lstm_opts="decay-time=20"
124+
125+
mkdir -p $dir/configs
126+
cat <<EOF > $dir/configs/network.xconfig
127+
input dim=100 name=ivector
128+
input dim=40 name=input
129+
130+
# please note that it is important to have input layer with the name=input
131+
# as the layer immediately preceding the fixed-affine-layer to enable
132+
# the use of short notation for the descriptor
133+
fixed-affine-layer name=lda input=Append(-2,-1,0,1,2,ReplaceIndex(ivector, t, 0)) affine-transform-file=$dir/configs/lda.mat
134+
135+
# the first splicing is moved before the lda layer, so no splicing here
136+
137+
# check steps/libs/nnet3/xconfig/lstm.py for the other options and defaults
138+
fast-lstmp-layer name=blstm1-forward input=lda cell-dim=1024 recurrent-projection-dim=256 non-recurrent-projection-dim=256 delay=-3 $lstm_opts
139+
fast-lstmp-layer name=blstm1-backward input=lda cell-dim=1024 recurrent-projection-dim=256 non-recurrent-projection-dim=256 delay=3 $lstm_opts
140+
141+
fast-lstmp-layer name=blstm2-forward input=Append(blstm1-forward, blstm1-backward) cell-dim=1024 recurrent-projection-dim=256 non-recurrent-projection-dim=256 delay=-3 $lstm_opts
142+
fast-lstmp-layer name=blstm2-backward input=Append(blstm1-forward, blstm1-backward) cell-dim=1024 recurrent-projection-dim=256 non-recurrent-projection-dim=256 delay=3 $lstm_opts
143+
144+
fast-lstmp-layer name=blstm3-forward input=Append(blstm2-forward, blstm2-backward) cell-dim=1024 recurrent-projection-dim=256 non-recurrent-projection-dim=256 delay=-3 $lstm_opts
145+
fast-lstmp-layer name=blstm3-backward input=Append(blstm2-forward, blstm2-backward) cell-dim=1024 recurrent-projection-dim=256 non-recurrent-projection-dim=256 delay=3 $lstm_opts
146+
147+
## adding the layers for chain branch
148+
output-layer name=output input=Append(blstm3-forward, blstm3-backward) output-delay=$label_delay include-log-softmax=false dim=$num_targets max-change=1.5
149+
150+
# adding the layers for xent branch
151+
# This block prints the configs for a separate output that will be
152+
# trained with a cross-entropy objective in the 'chain' models... this
153+
# has the effect of regularizing the hidden parts of the model. we use
154+
# 0.5 / args.xent_regularize as the learning rate factor- the factor of
155+
# 0.5 / args.xent_regularize is suitable as it means the xent
156+
# final-layer learns at a rate independent of the regularization
157+
# constant; and the 0.5 was tuned so as to make the relative progress
158+
# similar in the xent and regular final layers.
159+
output-layer name=output-xent input=Append(blstm3-forward, blstm3-backward) output-delay=$label_delay dim=$num_targets learning-rate-factor=$learning_rate_factor max-change=1.5
160+
161+
EOF
162+
steps/nnet3/xconfig_to_configs.py --xconfig-file $dir/configs/network.xconfig --config-dir $dir/configs/
163+
fi
164+
165+
if [ $stage -le 13 ]; then
166+
if [[ $(hostname -f) == *.clsp.jhu.edu ]] && [ ! -d $dir/egs/storage ]; then
167+
utils/create_split_dir.pl \
168+
/export/b0{5,6,7,8}/$USER/kaldi-data/egs/swbd-$(date +'%m_%d_%H_%M')/s5c/$dir/egs/storage $dir/egs/storage
169+
fi
170+
171+
steps/nnet3/chain/train.py --stage $train_stage \
172+
--cmd "$decode_cmd" \
173+
--feat.online-ivector-dir exp/nnet3/ivectors_${train_set} \
174+
--feat.cmvn-opts "--norm-means=false --norm-vars=false" \
175+
--chain.xent-regularize $xent_regularize \
176+
--chain.leaky-hmm-coefficient 0.1 \
177+
--chain.l2-regularize 0.00005 \
178+
--chain.apply-deriv-weights false \
179+
--chain.lm-opts="--num-extra-lm-states=2000" \
180+
--trainer.num-chunk-per-minibatch 64 \
181+
--trainer.frames-per-iter 1200000 \
182+
--trainer.max-param-change 2.0 \
183+
--trainer.num-epochs 4 \
184+
--trainer.optimization.shrink-value 0.99 \
185+
--trainer.optimization.num-jobs-initial 3 \
186+
--trainer.optimization.num-jobs-final 16 \
187+
--trainer.optimization.initial-effective-lrate 0.001 \
188+
--trainer.optimization.final-effective-lrate 0.0001 \
189+
--trainer.optimization.momentum 0.0 \
190+
--trainer.deriv-truncate-margin 8 \
191+
--egs.stage $get_egs_stage \
192+
--egs.opts "--frames-overlap-per-eg 0" \
193+
--egs.chunk-width $chunk_width \
194+
--egs.chunk-left-context $chunk_left_context \
195+
--egs.chunk-right-context $chunk_right_context \
196+
--egs.dir "$common_egs_dir" \
197+
--cleanup.remove-egs $remove_egs \
198+
--feat-dir data/${train_set}_hires \
199+
--tree-dir $treedir \
200+
--lat-dir exp/tri4_lats_nodup$suffix \
201+
--dir $dir || exit 1;
202+
fi
203+
204+
if [ $stage -le 14 ]; then
205+
# Note: it might appear that this $lang directory is mismatched, and it is as
206+
# far as the 'topo' is concerned, but this script doesn't read the 'topo' from
207+
# the lang directory.
208+
utils/mkgraph.sh --self-loop-scale 1.0 data/lang_sw1_tg $dir $dir/graph_sw1_tg
209+
fi
210+
211+
decode_suff=sw1_tg
212+
graph_dir=$dir/graph_sw1_tg
213+
if [ $stage -le 15 ]; then
214+
[ -z $extra_left_context ] && extra_left_context=$chunk_left_context;
215+
[ -z $extra_right_context ] && extra_right_context=$chunk_right_context;
216+
[ -z $frames_per_chunk ] && frames_per_chunk=$chunk_width;
217+
iter_opts=
218+
if [ ! -z $decode_iter ]; then
219+
iter_opts=" --iter $decode_iter "
220+
fi
221+
for decode_set in train_dev eval2000; do
222+
(
223+
steps/nnet3/decode.sh --acwt 1.0 --post-decode-acwt 10.0 \
224+
--nj 50 --cmd "$decode_cmd" $iter_opts \
225+
--extra-left-context $extra_left_context \
226+
--extra-right-context $extra_right_context \
227+
--frames-per-chunk "$frames_per_chunk" \
228+
--online-ivector-dir exp/nnet3/ivectors_${decode_set} \
229+
$graph_dir data/${decode_set}_hires \
230+
$dir/decode_${decode_set}${decode_dir_affix:+_$decode_dir_affix}_${decode_suff} || exit 1;
231+
if $has_fisher; then
232+
steps/lmrescore_const_arpa.sh --cmd "$decode_cmd" \
233+
data/lang_sw1_{tg,fsh_fg} data/${decode_set}_hires \
234+
$dir/decode_${decode_set}${decode_dir_affix:+_$decode_dir_affix}_sw1_{tg,fsh_fg} || exit 1;
235+
fi
236+
) &
237+
done
238+
fi
239+
wait;
240+
exit 0;

0 commit comments

Comments
 (0)