-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_tdnn_aug.sh
296 lines (259 loc) · 11 KB
/
run_tdnn_aug.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#!/bin/bash
# This recipe does multi-style training of TDNN model
# local/chain/compare_wer_general.sh --rt03 tdnn7q_sp tdnn1a_aug
# System tdnn7q_sp tdnn1a_aug
# WER on train_dev(tg) 11.91 12.06
# WER on train_dev(fg) 10.99 10.92
# WER on eval2000(tg) 14.3 14.4
# WER on eval2000(fg) 12.8 12.9
# WER on rt03(tg) 17.2 17.1
# WER on rt03(fg) 15.1 14.8
# Final train prob -0.062 -0.087
# Final valid prob -0.074 -0.105
# Final train prob (xent) -0.933 -1.164
# Final valid prob (xent) -0.9027 -1.2246
# Num-parameters 18693376 18483664
set -e
# configs for 'chain'
stage=0
train_stage=-10
get_egs_stage=-10
num_epochs=12
# Augmentation options
aug_list="noise" # Original train dir is referred to as `clean`
num_reverb_copies=1
use_ivectors=false
affix=1a
suffix="_aug"
if [ -e data/rt03 ]; then maybe_rt03=rt03; else maybe_rt03= ; fi
decode_iter=
decode_nj=50
# training options
frames_per_eg=150,110,100
remove_egs=false
common_egs_dir=
xent_regularize=0.1
dropout_schedule='0,0@0.20,0.5@0.50,0'
test_online_decoding=false # if true, it will run the last decoding stage.
# End configuration section.
echo "$0 $@" # Print the command line for logging
. ./cmd.sh
. ./path.sh
. ./utils/parse_options.sh
dir=exp/chain/tdnn${affix}${suffix}
if ! cuda-compiled; then
cat <<EOF && exit 1
This script is intended to be used with GPUs but you have not compiled Kaldi with CUDA
If you want to use GPUs (and have them), go to src/, and configure and make on a machine
where "nvcc" is installed.
EOF
fi
clean_set=train_nodup
clean_ali=tri4_ali_nodup
train_set=$clean_set$suffix # Will be prepared by the script local/nnet3/prepare_multistyle_data.sh
ali_dir=$clean_ali$suffix
treedir=exp/chain/tri5_7d_tree$suffix
lang=data/lang_chain_2y
#if [ $stage -le 0 ]; then
# steps/align_fmllr.sh --nj 30 --cmd "$train_cmd" \
# data/$clean_set data/lang exp/tri4 exp/$clean_ali
#fi
# First creates augmented data and then extracts features for it data
# The script also creates alignments for aug data by copying clean alignments
if [ $stage -le 0 ]; then
local/nnet3/multi_condition/run_aug_common.sh --stage $stage \
--aug-list "$aug_list" --num-reverb-copies $num_reverb_copies \
--use-ivectors "$use_ivectors" \
--train-set $clean_set --clean-ali $clean_ali || exit 1;
fi
if [ $stage -le 11 ]; then
# Get the alignments as lattices (gives the LF-MMI training more freedom).
# use the same num-jobs as the alignments
prefixes=""
include_original=false
for n in $aug_list; do
if [ "$n" == "reverb" ]; then
for i in `seq 1 $num_reverb_copies`; do
prefixes="$prefixes "reverb$i
done
elif [ "$n" != "clean" ]; then
prefixes="$prefixes "$n
else
# The original train directory will not have any prefix
# include_original flag will take care of copying the original lattices
include_original=true
fi
done
nj=$(cat exp/tri4_ali_nodup$suffix/num_jobs) || exit 1;
steps/align_fmllr_lats.sh --nj $nj --cmd "$train_cmd" data/${clean_set} \
data/lang exp/tri4 exp/tri4_lats_nodup${suffix}_clean
rm exp/tri4_lats_nodup${suffix}_clean/fsts.*.gz # save space
steps/copy_lat_dir.sh --nj $nj --cmd "$train_cmd" \
--include-original "$include_original" --prefixes "$prefixes" \
data/${train_set} exp/tri4_lats_nodup${suffix}_clean exp/tri4_lats_nodup${suffix} || exit 1;
if [[ $aug_list =~ "clean" ]]; then
ln -sf tri4_lats_nodup${suffix} exp/tri4_lats_nodup${suffix}_clean2
else
include_original=true
steps/copy_lat_dir.sh --nj $nj --cmd "$train_cmd" \
--include-original "$include_original" --prefixes "$prefixes" \
data/${train_set}_clean exp/tri4_lats_nodup${suffix}_clean exp/tri4_lats_nodup${suffix}_clean2 || exit 1;
fi
fi
if [ $stage -le 12 ]; then
# Create a version of the lang/ directory that has one state per phone in the
# topo file. [note, it really has two states.. the first one is only repeated
# once, the second one has zero or more repeats.]
rm -rf $lang
cp -r data/lang $lang
silphonelist=$(cat $lang/phones/silence.csl) || exit 1;
nonsilphonelist=$(cat $lang/phones/nonsilence.csl) || exit 1;
# Use our special topology... note that later on may have to tune this
# topology.
steps/nnet3/chain/gen_topo.py $nonsilphonelist $silphonelist >$lang/topo
fi
if [ $stage -le 13 ]; then
# Build a tree using our new topology. This is the critically different
# step compared with other recipes.
steps/nnet3/chain/build_tree.sh --frame-subsampling-factor 3 \
--context-opts "--context-width=2 --central-position=1" \
--cmd "$train_cmd" 7000 data/$train_set $lang exp/$ali_dir $treedir
fi
if [ $stage -le 14 ]; then
echo "$0: creating neural net configs using the xconfig parser";
num_targets=$(tree-info $treedir/tree |grep num-pdfs|awk '{print $2}')
learning_rate_factor=$(echo "print 0.5/$xent_regularize" | python)
affine_opts="l2-regularize=0.01 dropout-proportion=0.0 dropout-per-dim=true dropout-per-dim-continuous=true"
tdnnf_opts="l2-regularize=0.01 dropout-proportion=0.0 bypass-scale=0.66"
linear_opts="l2-regularize=0.01 orthonormal-constraint=-1.0"
prefinal_opts="l2-regularize=0.01"
output_opts="l2-regularize=0.002"
mkdir -p $dir/configs
cat <<EOF > $dir/configs/network.xconfig
input dim=40 name=input
# please note that it is important to have input layer with the name=input
# as the layer immediately preceding the fixed-affine-layer to enable
# the use of short notation for the descriptor
fixed-affine-layer name=lda input=Append(-1,0,1) affine-transform-file=$dir/configs/lda.mat
# the first splicing is moved before the lda layer, so no splicing here
relu-batchnorm-dropout-layer name=tdnn1 $affine_opts dim=1536
tdnnf-layer name=tdnnf2 $tdnnf_opts dim=1536 bottleneck-dim=160 time-stride=1
tdnnf-layer name=tdnnf3 $tdnnf_opts dim=1536 bottleneck-dim=160 time-stride=1
tdnnf-layer name=tdnnf4 $tdnnf_opts dim=1536 bottleneck-dim=160 time-stride=1
tdnnf-layer name=tdnnf5 $tdnnf_opts dim=1536 bottleneck-dim=160 time-stride=0
tdnnf-layer name=tdnnf6 $tdnnf_opts dim=1536 bottleneck-dim=160 time-stride=3
tdnnf-layer name=tdnnf7 $tdnnf_opts dim=1536 bottleneck-dim=160 time-stride=3
tdnnf-layer name=tdnnf8 $tdnnf_opts dim=1536 bottleneck-dim=160 time-stride=3
tdnnf-layer name=tdnnf9 $tdnnf_opts dim=1536 bottleneck-dim=160 time-stride=3
tdnnf-layer name=tdnnf10 $tdnnf_opts dim=1536 bottleneck-dim=160 time-stride=3
tdnnf-layer name=tdnnf11 $tdnnf_opts dim=1536 bottleneck-dim=160 time-stride=3
tdnnf-layer name=tdnnf12 $tdnnf_opts dim=1536 bottleneck-dim=160 time-stride=3
tdnnf-layer name=tdnnf13 $tdnnf_opts dim=1536 bottleneck-dim=160 time-stride=3
tdnnf-layer name=tdnnf14 $tdnnf_opts dim=1536 bottleneck-dim=160 time-stride=3
tdnnf-layer name=tdnnf15 $tdnnf_opts dim=1536 bottleneck-dim=160 time-stride=3
linear-component name=prefinal-l dim=256 $linear_opts
prefinal-layer name=prefinal-chain input=prefinal-l $prefinal_opts big-dim=1536 small-dim=256
output-layer name=output include-log-softmax=false dim=$num_targets $output_opts
prefinal-layer name=prefinal-xent input=prefinal-l $prefinal_opts big-dim=1536 small-dim=256
output-layer name=output-xent dim=$num_targets learning-rate-factor=$learning_rate_factor $output_opts
EOF
steps/nnet3/xconfig_to_configs.py --xconfig-file $dir/configs/network.xconfig --config-dir $dir/configs/
fi
if [ $stage -le 15 ]; then
if [[ $(hostname -f) == *.clsp.jhu.edu ]] && [ ! -d $dir/egs/storage ]; then
utils/create_split_dir.pl \
/export/b0{5,6,7,8}/$USER/kaldi-data/egs/swbd-$(date +'%m_%d_%H_%M')/s5c/$dir/egs/storage $dir/egs/storage
fi
steps/nnet3/chain/train.py --stage $train_stage \
--cmd "$train_cmd" \
--feat.cmvn-opts "--norm-means=false --norm-vars=false" \
--chain.xent-regularize $xent_regularize \
--chain.leaky-hmm-coefficient 0.1 \
--chain.l2-regularize 0.0 \
--chain.apply-deriv-weights false \
--chain.lm-opts="--num-extra-lm-states=2000" \
--trainer.dropout-schedule $dropout_schedule \
--trainer.add-option="--optimization.memory-compression-level=2" \
--egs.dir "$common_egs_dir" \
--egs.stage $get_egs_stage \
--egs.opts "--frames-overlap-per-eg 0 --constrained false" \
--egs.chunk-width $frames_per_eg \
--trainer.num-chunk-per-minibatch 64 \
--trainer.frames-per-iter 1500000 \
--trainer.num-epochs $num_epochs \
--trainer.optimization.num-jobs-initial 3 \
--trainer.optimization.num-jobs-final 16 \
--trainer.optimization.initial-effective-lrate 0.00025 \
--trainer.optimization.final-effective-lrate 0.000025 \
--trainer.max-param-change 2.0 \
--cleanup.remove-egs $remove_egs \
--feat-dir data/${train_set}_hires \
--tree-dir $treedir \
--lat-dir exp/tri4_lats_nodup$suffix \
--dir $dir || exit 1;
fi
if [ $stage -le 16 ]; then
utils/mkgraph.sh --self-loop-scale 1.0 data/lang_sw1_tg $dir $dir/graph_sw1_tg
fi
graph_dir=$dir/graph_sw1_tg
iter_opts=
if [ ! -z $decode_iter ]; then
iter_opts=" --iter $decode_iter "
fi
if [ $stage -le 17 ]; then
rm $dir/.error 2>/dev/null || true
for decode_set in train_dev eval2000; do
(
steps/nnet3/decode.sh --acwt 1.0 --post-decode-acwt 10.0 \
--nj $decode_nj --cmd "$decode_cmd" $iter_opts \
$graph_dir data/${decode_set}_hires \
$dir/decode_${decode_set}${decode_iter:+_$decode_iter}_sw1_tg || exit 1;
if $has_fisher; then
steps/lmrescore_const_arpa.sh --cmd "$decode_cmd" \
data/lang_sw1_{tg,fsh_fg} data/${decode_set}_hires \
$dir/decode_${decode_set}${decode_iter:+_$decode_iter}_sw1_{tg,fsh_fg} || exit 1;
fi
) || touch $dir/.error &
done
wait
if [ -f $dir/.error ]; then
echo "$0: something went wrong in decoding"
exit 1
fi
fi
if [ $stage -le 18 ]; then
rm $dir/.error 2>/dev/null || true
for x in eval2000; do
for n in noise reverb music babble; do
decode_set=${x}_${n}
dataset=$decode_set
steps/nnet3/decode.sh --acwt 1.0 --post-decode-acwt 10.0 \
--nj $decode_nj --cmd "$decode_cmd" $iter_opts \
$graph_dir data/${decode_set}_hires \
$dir/decode_${decode_set}${decode_iter:+_$decode_iter}_sw1_tg || exit 1;
#if $has_fisher; then
# steps/lmrescore_const_arpa.sh --cmd "$decode_cmd" \
# data/lang_sw1_{tg,fsh_fg} data/${decode_set}_hires \
# $dir/decode_${decode_set}${decode_iter:+_$decode_iter}_sw1_{tg,fsh_fg} || exit 1;
#fi
done
done
if [ -f $dir/.error ]; then
echo "$0: something went wrong in decoding"
exit 1
fi
fi
#if [ $stage -le 19 ]; then
# rm $dir/.error 2>/dev/null || true
# for decode_set in dev_aspire sdm1_eval ihm_eval; do
# steps/nnet3/decode.sh --acwt 1.0 --post-decode-acwt 10.0 \
# --nj 10 --cmd "$decode_cmd" $iter_opts \
# $graph_dir data/${decode_set}_hires \
# $dir/decode_${decode_set} || exit 1;
# done
# if [ -f $dir/.error ]; then
# echo "$0: something went wrong in decoding"
# exit 1
# fi
#fi
exit 0;