|
| 1 | +#!/bin/bash |
| 2 | +# Apache 2.0 |
| 3 | + |
| 4 | +# This is based on TDNN_OPGRU_1A, but using the FastNormOPGRU to replace the NormPGRU. |
| 5 | +# Different from the vanilla OPGRU, Norm-OPGRU adds batchnorm in its output (forward direction) |
| 6 | +# and renorm in its recurrence. Experiments show that the TDNN-NormOPGRU could achieve similar |
| 7 | +# results than TDNN-LSTMP and BLSTMP in both large or small data sets (80 ~ 2300 Hrs). |
| 8 | + |
| 9 | +# ./local/chain/compare_wer_general.sh --looped tdnn_opgru_1a_sp tdnn_opgru_1b_sp |
| 10 | +# System tdnn_opgru_1a_sp tdnn_opgru_1b_sp |
| 11 | +# WER on train_dev(tg) 12.31 12.41 |
| 12 | +# [looped:] 12.26 12.38 |
| 13 | +# WER on train_dev(fg) 11.49 11.60 |
| 14 | +# [looped:] 11.43 11.65 |
| 15 | +# WER on eval2000(tg) 14.9 15.1 |
| 16 | +# [looped:] 15.0 15.1 |
| 17 | +# WER on eval2000(fg) 13.5 13.7 |
| 18 | +# [looped:] 13.5 13.7 |
| 19 | +# Final train prob -0.068 -0.070 |
| 20 | +# Final valid prob -0.091 -0.092 |
| 21 | +# Final train prob (xent) -0.879 -0.889 |
| 22 | +# Final valid prob (xent) -0.9667 -0.9723 |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +set -e |
| 27 | + |
| 28 | +# configs for 'chain' |
| 29 | +stage=0 |
| 30 | +train_stage=-10 |
| 31 | +get_egs_stage=-10 |
| 32 | +speed_perturb=true |
| 33 | +dir=exp/chain/tdnn_opgru_1b # Note: _sp will get added to this if $speed_perturb == true. |
| 34 | +decode_iter= |
| 35 | +decode_dir_affix= |
| 36 | + |
| 37 | +# training options |
| 38 | +leftmost_questions_truncate=-1 |
| 39 | +chunk_width=150 |
| 40 | +chunk_left_context=40 |
| 41 | +chunk_right_context=0 |
| 42 | +xent_regularize=0.025 |
| 43 | +self_repair_scale=0.00001 |
| 44 | +label_delay=5 |
| 45 | +dropout_schedule='0,0@0.20,0.2@0.50,0' |
| 46 | +# decode options |
| 47 | +extra_left_context=50 |
| 48 | +extra_right_context=0 |
| 49 | +frames_per_chunk= |
| 50 | +test_online_decoding= |
| 51 | + |
| 52 | +remove_egs=false |
| 53 | +common_egs_dir= |
| 54 | + |
| 55 | +affix= |
| 56 | +# End configuration section. |
| 57 | +echo "$0 $@" # Print the command line for logging |
| 58 | + |
| 59 | +. ./cmd.sh |
| 60 | +. ./path.sh |
| 61 | +. ./utils/parse_options.sh |
| 62 | + |
| 63 | +if ! cuda-compiled; then |
| 64 | + cat <<EOF && exit 1 |
| 65 | +This script is intended to be used with GPUs but you have not compiled Kaldi with CUDA |
| 66 | +If you want to use GPUs (and have them), go to src/, and configure and make on a machine |
| 67 | +where "nvcc" is installed. |
| 68 | +EOF |
| 69 | +fi |
| 70 | + |
| 71 | +# The iVector-extraction and feature-dumping parts are the same as the standard |
| 72 | +# nnet3 setup, and you can skip them by setting "--stage 8" if you have already |
| 73 | +# run those things. |
| 74 | + |
| 75 | +suffix= |
| 76 | +if [ "$speed_perturb" == "true" ]; then |
| 77 | + suffix=_sp |
| 78 | +fi |
| 79 | + |
| 80 | +dir=$dir${affix:+_$affix} |
| 81 | +dir=${dir}$suffix |
| 82 | +train_set=train_nodup$suffix |
| 83 | +ali_dir=exp/tri4_ali_nodup$suffix |
| 84 | +treedir=exp/chain/tri5_7d_tree$suffix |
| 85 | +lang=data/lang_chain_2y |
| 86 | + |
| 87 | + |
| 88 | +# if we are using the speed-perturbed data we need to generate |
| 89 | +# alignments for it. |
| 90 | +local/nnet3/run_ivector_common.sh --stage $stage \ |
| 91 | + --speed-perturb $speed_perturb \ |
| 92 | + --generate-alignments $speed_perturb || exit 1; |
| 93 | + |
| 94 | + |
| 95 | +if [ $stage -le 9 ]; then |
| 96 | + # Get the alignments as lattices (gives the CTC training more freedom). |
| 97 | + # use the same num-jobs as the alignments |
| 98 | + nj=$(cat exp/tri4_ali_nodup$suffix/num_jobs) || exit 1; |
| 99 | + steps/align_fmllr_lats.sh --nj $nj --cmd "$train_cmd" data/$train_set \ |
| 100 | + data/lang exp/tri4 exp/tri4_lats_nodup$suffix |
| 101 | + rm exp/tri4_lats_nodup$suffix/fsts.*.gz # save space |
| 102 | +fi |
| 103 | + |
| 104 | + |
| 105 | +if [ $stage -le 10 ]; then |
| 106 | + # Create a version of the lang/ directory that has one state per phone in the |
| 107 | + # topo file. [note, it really has two states.. the first one is only repeated |
| 108 | + # once, the second one has zero or more repeats.] |
| 109 | + rm -rf $lang |
| 110 | + cp -r data/lang $lang |
| 111 | + silphonelist=$(cat $lang/phones/silence.csl) || exit 1; |
| 112 | + nonsilphonelist=$(cat $lang/phones/nonsilence.csl) || exit 1; |
| 113 | + # Use our special topology... note that later on may have to tune this |
| 114 | + # topology. |
| 115 | + steps/nnet3/chain/gen_topo.py $nonsilphonelist $silphonelist >$lang/topo |
| 116 | +fi |
| 117 | + |
| 118 | +if [ $stage -le 11 ]; then |
| 119 | + # Build a tree using our new topology. |
| 120 | + steps/nnet3/chain/build_tree.sh --frame-subsampling-factor 3 \ |
| 121 | + --leftmost-questions-truncate $leftmost_questions_truncate \ |
| 122 | + --context-opts "--context-width=2 --central-position=1" \ |
| 123 | + --cmd "$train_cmd" 7000 data/$train_set $lang $ali_dir $treedir |
| 124 | +fi |
| 125 | + |
| 126 | +if [ $stage -le 12 ]; then |
| 127 | + echo "$0: creating neural net configs using the xconfig parser"; |
| 128 | + |
| 129 | + num_targets=$(tree-info $treedir/tree |grep num-pdfs|awk '{print $2}') |
| 130 | + learning_rate_factor=$(echo "print 0.5/$xent_regularize" | python) |
| 131 | + gru_opts="dropout-per-frame=true dropout-proportion=0.0 gru-nonlinearity-options=\"max-change=0.75\"" |
| 132 | + |
| 133 | + mkdir -p $dir/configs |
| 134 | + cat <<EOF > $dir/configs/network.xconfig |
| 135 | + input dim=100 name=ivector |
| 136 | + input dim=40 name=input |
| 137 | +
|
| 138 | + # please note that it is important to have input layer with the name=input |
| 139 | + # as the layer immediately preceding the fixed-affine-layer to enable |
| 140 | + # the use of short notation for the descriptor |
| 141 | + fixed-affine-layer name=lda input=Append(-2,-1,0,1,2,ReplaceIndex(ivector, t, 0)) affine-transform-file=$dir/configs/lda.mat |
| 142 | +
|
| 143 | + # the first splicing is moved before the lda layer, so no splicing here |
| 144 | + relu-batchnorm-layer name=tdnn1 dim=1024 |
| 145 | + relu-batchnorm-layer name=tdnn2 input=Append(-1,0,1) dim=1024 |
| 146 | + relu-batchnorm-layer name=tdnn3 input=Append(-1,0,1) dim=1024 |
| 147 | +
|
| 148 | + # check steps/libs/nnet3/xconfig/gru.py for the other options and defaults |
| 149 | + fast-norm-opgru-layer name=opgru1 cell-dim=1024 recurrent-projection-dim=256 non-recurrent-projection-dim=256 delay=-3 $gru_opts |
| 150 | + relu-batchnorm-layer name=tdnn4 input=Append(-3,0,3) dim=1024 |
| 151 | + relu-batchnorm-layer name=tdnn5 input=Append(-3,0,3) dim=1024 |
| 152 | + fast-norm-opgru-layer name=opgru2 cell-dim=1024 recurrent-projection-dim=256 non-recurrent-projection-dim=256 delay=-3 $gru_opts |
| 153 | + relu-batchnorm-layer name=tdnn6 input=Append(-3,0,3) dim=1024 |
| 154 | + relu-batchnorm-layer name=tdnn7 input=Append(-3,0,3) dim=1024 |
| 155 | + fast-norm-opgru-layer name=opgru3 cell-dim=1024 recurrent-projection-dim=256 non-recurrent-projection-dim=256 delay=-3 $gru_opts |
| 156 | +
|
| 157 | + ## adding the layers for chain branch |
| 158 | + output-layer name=output input=opgru3 output-delay=$label_delay include-log-softmax=false dim=$num_targets max-change=1.5 |
| 159 | +
|
| 160 | + # adding the layers for xent branch |
| 161 | + # This block prints the configs for a separate output that will be |
| 162 | + # trained with a cross-entropy objective in the 'chain' models... this |
| 163 | + # has the effect of regularizing the hidden parts of the model. we use |
| 164 | + # 0.5 / args.xent_regularize as the learning rate factor- the factor of |
| 165 | + # 0.5 / args.xent_regularize is suitable as it means the xent |
| 166 | + # final-layer learns at a rate independent of the regularization |
| 167 | + # constant; and the 0.5 was tuned so as to make the relative progress |
| 168 | + # similar in the xent and regular final layers. |
| 169 | + output-layer name=output-xent input=opgru3 output-delay=$label_delay dim=$num_targets learning-rate-factor=$learning_rate_factor max-change=1.5 |
| 170 | +
|
| 171 | +EOF |
| 172 | + steps/nnet3/xconfig_to_configs.py --xconfig-file $dir/configs/network.xconfig --config-dir $dir/configs/ |
| 173 | +fi |
| 174 | + |
| 175 | +if [ $stage -le 13 ]; then |
| 176 | + if [[ $(hostname -f) == *.clsp.jhu.edu ]] && [ ! -d $dir/egs/storage ]; then |
| 177 | + utils/create_split_dir.pl \ |
| 178 | + /export/b0{5,6,7,8}/$USER/kaldi-data/egs/swbd-$(date +'%m_%d_%H_%M')/s5c/$dir/egs/storage $dir/egs/storage |
| 179 | + fi |
| 180 | + |
| 181 | + steps/nnet3/chain/train.py --stage $train_stage \ |
| 182 | + --cmd "$decode_cmd" \ |
| 183 | + --feat.online-ivector-dir exp/nnet3/ivectors_${train_set} \ |
| 184 | + --feat.cmvn-opts "--norm-means=false --norm-vars=false" \ |
| 185 | + --chain.xent-regularize $xent_regularize \ |
| 186 | + --chain.leaky-hmm-coefficient 0.1 \ |
| 187 | + --chain.l2-regularize 0.00005 \ |
| 188 | + --chain.apply-deriv-weights false \ |
| 189 | + --chain.lm-opts="--num-extra-lm-states=2000" \ |
| 190 | + --trainer.num-chunk-per-minibatch 64 \ |
| 191 | + --trainer.frames-per-iter 1200000 \ |
| 192 | + --trainer.max-param-change 2.0 \ |
| 193 | + --trainer.num-epochs 4 \ |
| 194 | + --trainer.optimization.shrink-value 0.99 \ |
| 195 | + --trainer.optimization.num-jobs-initial 3 \ |
| 196 | + --trainer.optimization.num-jobs-final 16 \ |
| 197 | + --trainer.optimization.initial-effective-lrate 0.001 \ |
| 198 | + --trainer.optimization.final-effective-lrate 0.0001 \ |
| 199 | + --trainer.optimization.momentum 0.0 \ |
| 200 | + --trainer.deriv-truncate-margin 8 \ |
| 201 | + --egs.stage $get_egs_stage \ |
| 202 | + --egs.opts "--frames-overlap-per-eg 0" \ |
| 203 | + --egs.chunk-width $chunk_width \ |
| 204 | + --egs.chunk-left-context $chunk_left_context \ |
| 205 | + --egs.chunk-right-context $chunk_right_context \ |
| 206 | + --trainer.dropout-schedule $dropout_schedule \ |
| 207 | + --egs.chunk-left-context-initial 0 \ |
| 208 | + --egs.chunk-right-context-final 0 \ |
| 209 | + --egs.dir "$common_egs_dir" \ |
| 210 | + --cleanup.remove-egs $remove_egs \ |
| 211 | + --feat-dir data/${train_set}_hires \ |
| 212 | + --tree-dir $treedir \ |
| 213 | + --lat-dir exp/tri4_lats_nodup$suffix \ |
| 214 | + --dir $dir || exit 1; |
| 215 | +fi |
| 216 | + |
| 217 | +if [ $stage -le 14 ]; then |
| 218 | + # Note: it might appear that this $lang directory is mismatched, and it is as |
| 219 | + # far as the 'topo' is concerned, but this script doesn't read the 'topo' from |
| 220 | + # the lang directory. |
| 221 | + utils/mkgraph.sh --self-loop-scale 1.0 data/lang_sw1_tg $dir $dir/graph_sw1_tg |
| 222 | +fi |
| 223 | + |
| 224 | +decode_suff=sw1_tg |
| 225 | +graph_dir=$dir/graph_sw1_tg |
| 226 | +if [ $stage -le 15 ]; then |
| 227 | + [ -z $extra_left_context ] && extra_left_context=$chunk_left_context; |
| 228 | + [ -z $extra_right_context ] && extra_right_context=$chunk_right_context; |
| 229 | + [ -z $frames_per_chunk ] && frames_per_chunk=$chunk_width; |
| 230 | + iter_opts= |
| 231 | + if [ ! -z $decode_iter ]; then |
| 232 | + iter_opts=" --iter $decode_iter " |
| 233 | + fi |
| 234 | + for decode_set in train_dev eval2000; do |
| 235 | + ( |
| 236 | + steps/nnet3/decode.sh --acwt 1.0 --post-decode-acwt 10.0 \ |
| 237 | + --nj 50 --cmd "$decode_cmd" $iter_opts \ |
| 238 | + --extra-left-context $extra_left_context \ |
| 239 | + --extra-right-context $extra_right_context \ |
| 240 | + --extra-left-context-initial 0 \ |
| 241 | + --extra-right-context-final 0 \ |
| 242 | + --frames-per-chunk "$frames_per_chunk" \ |
| 243 | + --online-ivector-dir exp/nnet3/ivectors_${decode_set} \ |
| 244 | + $graph_dir data/${decode_set}_hires \ |
| 245 | + $dir/decode_${decode_set}${decode_dir_affix:+_$decode_dir_affix}_${decode_suff} || exit 1; |
| 246 | + if $has_fisher; then |
| 247 | + steps/lmrescore_const_arpa.sh --cmd "$decode_cmd" \ |
| 248 | + data/lang_sw1_{tg,fsh_fg} data/${decode_set}_hires \ |
| 249 | + $dir/decode_${decode_set}${decode_dir_affix:+_$decode_dir_affix}_sw1_{tg,fsh_fg} || exit 1; |
| 250 | + fi |
| 251 | + ) & |
| 252 | + done |
| 253 | +fi |
| 254 | + |
| 255 | +if $test_online_decoding && [ $stage -le 16 ]; then |
| 256 | + # note: if the features change (e.g. you add pitch features), you will have to |
| 257 | + # change the options of the following command line. |
| 258 | + steps/online/nnet3/prepare_online_decoding.sh \ |
| 259 | + --mfcc-config conf/mfcc_hires.conf \ |
| 260 | + $lang exp/nnet3/extractor $dir ${dir}_online |
| 261 | + |
| 262 | + rm $dir/.error 2>/dev/null || true |
| 263 | + for decode_set in train_dev eval2000; do |
| 264 | + ( |
| 265 | + # note: we just give it "$decode_set" as it only uses the wav.scp, the |
| 266 | + # feature type does not matter. |
| 267 | + steps/online/nnet3/decode.sh --nj 50 --cmd "$decode_cmd" $iter_opts \ |
| 268 | + --acwt 1.0 --post-decode-acwt 10.0 \ |
| 269 | + $graph_dir data/${decode_set}_hires \ |
| 270 | + ${dir}_online/decode_${decode_set}${decode_iter:+_$decode_iter}_sw1_tg || exit 1; |
| 271 | + if $has_fisher; then |
| 272 | + steps/lmrescore_const_arpa.sh --cmd "$decode_cmd" \ |
| 273 | + data/lang_sw1_{tg,fsh_fg} data/${decode_set}_hires \ |
| 274 | + ${dir}_online/decode_${decode_set}${decode_iter:+_$decode_iter}_sw1_{tg,fsh_fg} || exit 1; |
| 275 | + fi |
| 276 | + ) || touch $dir/.error & |
| 277 | + done |
| 278 | + wait |
| 279 | + if [ -f $dir/.error ]; then |
| 280 | + echo "$0: something went wrong in online decoding" |
| 281 | + exit 1 |
| 282 | + fi |
| 283 | +fi |
| 284 | + |
| 285 | +if [ $stage -le 17 ]; then |
| 286 | + rm $dir/.error 2>/dev/null || true |
| 287 | + for decode_set in train_dev eval2000; do |
| 288 | + ( |
| 289 | + steps/nnet3/decode_looped.sh \ |
| 290 | + --acwt 1.0 --post-decode-acwt 10.0 \ |
| 291 | + --nj 50 --cmd "$decode_cmd" $iter_opts \ |
| 292 | + --online-ivector-dir exp/nnet3/ivectors_${decode_set} \ |
| 293 | + $graph_dir data/${decode_set}_hires \ |
| 294 | + $dir/decode_${decode_set}${decode_iter:+_$decode_iter}_sw1_tg_looped || exit 1; |
| 295 | + if $has_fisher; then |
| 296 | + steps/lmrescore_const_arpa.sh --cmd "$decode_cmd" \ |
| 297 | + data/lang_sw1_{tg,fsh_fg} data/${decode_set}_hires \ |
| 298 | + $dir/decode_${decode_set}${decode_iter:+_$decode_iter}_sw1_{tg,fsh_fg}_looped || exit 1; |
| 299 | + fi |
| 300 | + ) & |
| 301 | + done |
| 302 | + wait |
| 303 | + if [ -f $dir/.error ]; then |
| 304 | + echo "$0: something went wrong in looped decoding" |
| 305 | + exit 1 |
| 306 | + fi |
| 307 | +fi |
| 308 | + |
| 309 | +wait; |
| 310 | +exit 0; |
0 commit comments