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