Day18 - 语音辨识神级工具-Kaldi part3

今天我们进入kaldi训练神经网路模型的部分,程序的部分是在 local/chain/tuning/run_tdnn.sh 中。
程序主要分为以下几个部分:

  • iVector extract (local/nnet3/run_ivector_common.sh): 包含
    • 资料扩充: 将资料集中音档的语速调整为 0.9、1.1倍(可自行设定)来让资料集增加为原本的2倍,透过 utils/data/perturb_data_dir_speed_3way.sh 来达成
    • 加入音量扰动 volume-perturbation: 这边需要设定音量调整的最小、最大值(预设为0.125~2),会将每一笔音档的音量随机调整至此区间内,透过 utils/data/perturb_data_dir_volume.sh 来达成。经过此步骤後资料集总数不会改变
    • 语音特徵撷取: 扩充完资料集後需要重新撷取语音特徵,做法与Day16时提到的类似,不过这边在撷取时会把MFCC的维度由原本的13调整为40,config档则是 conf/mfcc_hires.conf
    • 取部分的训练资料计算 PCA transform
    • 取部分的训练资料训练 diagonal UBM
    • 训练 iVector (identity vector)
  • create neural network: 建立神经网路,以TDNN为范例
  • train (steps/nnet3/chain/train.py): 透过 steps/nnet3/chain/train.py 训练神经网路,训练完成後会在指定的目录下产生模型档 final.mdl
  • decode (steps/nnet3/decode.sh): 透过 steps/nnet3/decode.sh 进行解码

参考程序如下

#!/bin/bash

set -e

# configs for 'chain'
affix=1d
stage=0
train_stage=-10
get_egs_stage=-10
dir=exp/chain/tdnn  # Note: _sp will get added to this
decode_iter=

# training options
num_epochs=6
initial_effective_lrate=0.00025
final_effective_lrate=0.000025
max_param_change=2.0
final_layer_normalize_target=0.5
num_jobs_initial=3
num_jobs_final=16
minibatch_size=64
frames_per_eg=150,110,90
remove_egs=false
common_egs_dir=
xent_regularize=0.1
dropout_schedule='0,[email protected],[email protected],0'

# End configuration section.
echo "$0 $@"  # Print the command line for logging

. ./cmd.sh
. ./path.sh
. ./utils/parse_options.sh

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

# The iVector-extraction and feature-dumping parts are the same as the standard
# nnet3 setup, and you can skip them by setting "--stage 8" if you have already
# run those things.

dir=${dir}${affix:+_$affix}_sp
train_set=train_sp
ali_dir=exp/tri5a_sp_ali
treedir=exp/chain/tri6a_tree_sp
lang=data/lang_chain


# if we are using the speed-perturbed data we need to generate
# alignments for it.
local/nnet3/run_ivector_common.sh --stage $stage --train-set train --gmm tri5a ${nnet3_affix:+ --nnet3-affix $nnet3_affix}

if [ $stage -le 7 ]; then
 # Get the alignments as lattices (gives the LF-MMI training more freedom).
 # use the same num-jobs as the alignments
 nj=$(cat $ali_dir/num_jobs) || exit 1;
 steps/align_fmllr_lats.sh --nj $nj --cmd "$train_cmd" data/$train_set \
   data/lang exp/tri5a exp/tri5a_sp_lats
 rm exp/tri5a_sp_lats/fsts.*.gz # save space
fi

if [ $stage -le 8 ]; 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 9 ]; 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 $ali_dir $treedir
fi

if [ $stage -le 10 ]; 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=100 name=ivector
  input dim=43 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,ReplaceIndex(ivector, t, 0)) 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 11 ]; then
  steps/nnet3/chain/train.py --stage $train_stage \
    --cmd "$decode_cmd" \
    --feat.online-ivector-dir exp/nnet3$nnet3_affix/ivectors_${train_set} \
    --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 $minibatch_size \
    --trainer.frames-per-iter 1500000 \
    --trainer.num-epochs $num_epochs \
    --trainer.optimization.num-jobs-initial $num_jobs_initial \
    --trainer.optimization.num-jobs-final $num_jobs_final \
    --trainer.optimization.initial-effective-lrate $initial_effective_lrate \
    --trainer.optimization.final-effective-lrate $final_effective_lrate \
    --trainer.max-param-change $max_param_change \
    --cleanup.remove-egs $remove_egs \
    --feat-dir data/${train_set}_hires \
    --tree-dir $treedir \
    --lat-dir exp/tri5a_sp_lats \
    --use-gpu wait \
    --dir $dir  || exit 1;
fi

if [ $stage -le 12 ]; then
  # Note: it might appear that this $lang directory is mismatched, and it is as
  # far as the 'topo' is concerned, but this script doesn't read the 'topo' from
  # the lang directory.
  utils/mkgraph.sh --self-loop-scale 1.0 data/lang_test $dir $dir/graph
fi

graph_dir=$dir/graph
if [ $stage -le 13 ]; then
  for test_set in test ; do
    steps/nnet3/decode.sh --acwt 1.0 --post-decode-acwt 10.0 \
      --nj 10 --cmd "$decode_cmd" \
      --online-ivector-dir exp/nnet3${nnet3_affix:+_$nnet3_affix}/ivectors_$test_set \
      $graph_dir data/${test_set}_hires $dir/decode_${test_set} || exit 1;
  done
  wait;
fi

exit 0;

Kaldi 初步的介绍就到这边了,明天开始就要进入语音情绪辨识的范围了。

参考资料:

https://www.cs.cmu.edu/~elaw/papers/pca.pdf
https://www.danielpovey.com/files/jhu_lecture2.pdf
https://www.sciencedirect.com/science/article/pii/S1877050918314042


<<:  Day14【Web】网路攻击:域名劫持

>>:  [Day 18] 机器学习 boosting 神器 - CatBoost

网页颜色-30天学会HTML+CSS,制作精美网站

好的网站除了内容传达之外,颜色是进入网站的第一印象,可以针对文字大小、框线、背景色...等做变化,是...

[影片]第27天:英雄指南-5. 新增应用内导航(2)

GitHub:https://github.com/dannypc1628/Angular-Tou...

搞懂 P2P 技术 (2) - STUN x TURN x ICE

前言 上一篇介绍完中心化、去中心化、分布式网路以及 IPv4、NAT、NAT 类型,但我们依旧还有些...

Day13 - 使用Chip和ChipGroup显示搜寻项目

原本今天是想写解析文章列表的,不过思考了一下,为了让脉络顺一点,决定把今天的内容放到解析文章列表之前...

Day 29 Quantum Protocols and Quantum Algorithms

Understanding Quantum Teleportation 1.Creates an e...