Commit a1d196b9 authored by Karel Vesely's avatar Karel Vesely
Browse files

trunk,nnet1: WARNING, change in the interface of : steps/nnet/train.sh

a) options --apply-cmvn --norm-vars are replaced by --cmvn-opts
b) option --delta-oder replaced by --delta-opts

- the files with setup of cmvn/deltas in exp/dnn.../ changed too, while keeping backward compatibility for nnet/decode.sh nnet/align.sh etc (please let me know if you have problems).



git-svn-id: https://svn.code.sf.net/p/kaldi/code/trunk@4815 5e6a8d80-dfce-4ca6-a32a-6e07a63d50c8
parent 15dfbb5d
#!/bin/bash
. path.sh
. cmd.sh
# Train,
dir=exp/autoencoder
data_fmllr=data-fmllr-tri3b
labels="ark:feat-to-post scp:$data_fmllr/train/feats.scp ark:- |"
$cuda_cmd $dir/log/train_nnet.log \
steps/nnet/train.sh --hid-layers 2 --hid-dim 200 --learn-rate 0.00001 \
--labels "$labels" --num-tgt 40 --train-tool "nnet-train-frmshuff --objective-function=mse" \
--proto-opts "--no-softmax --activation-type=<Tanh> --hid-bias-mean=0.0 --hid-bias-range=1.0 --param-stddev-factor=0.01" \
$data_fmllr/train_tr90 $data_fmllr/train_cv10 dummy-dir dummy-dir dummy-dir $dir || exit 1;
# Forward the data,
output_dir=data-autoencoded/test
steps/nnet/make_bn_feats.sh --nj 1 --cmd "$train_cmd" --remove-last-components 0 \
$output_dir $data_fmllr/test $dir $output_dir/{log,data} || exit 1
......@@ -20,12 +20,12 @@ stage=0
# Make the FBANK features
if [ $stage -le 0 ]; then
# Dev set
mkdir -p $dev && cp $dev_original/* $dev && rm $dev/{feats,cmvn}.scp
utils/copy_data_dir.sh $dev_original $dev || exit 1; rm $dev/{cmvn,feats}.scp
steps/make_fbank_pitch.sh --nj 10 --cmd "$train_cmd" \
$dev $dev/log $dev/data || exit 1;
steps/compute_cmvn_stats.sh $dev $dev/log $dev/data || exit 1;
# Training set
mkdir -p $train && cp $train_original/* $train && rm $train/{feats,cmvn}.scp
utils/copy_data_dir.sh $train_original $train || exit 1; rm $train/{cmvn,feats}.scp
steps/make_fbank_pitch.sh --nj 10 --cmd "$train_cmd" \
$train $train/log $train/data || exit 1;
steps/compute_cmvn_stats.sh $train $train/log $train/data || exit 1;
......@@ -40,9 +40,10 @@ if [ $stage -le 1 ]; then
# Train
$cuda_cmd $dir/log/train_nnet.log \
steps/nnet/train.sh \
--apply-cmvn true --norm-vars true --delta-order 2 --splice 5 \
--cmvn-opts "--norm-means=true --norm-vars=true" \
--delta-opts "--delta-order=2" --splice 5 \
--prepend-cnn-type cnn1d --cnn-proto-opts "--patch-dim1 8 --pitch-dim 3" \
--hid-layers 2 --learn-rate 0.008 --train-opts "--verbose 2" \
--hid-layers 2 --learn-rate 0.008 \
${train}_tr90 ${train}_cv10 data/lang $ali $ali $dir || exit 1;
# Decode
steps/nnet/decode.sh --nj 20 --cmd "$decode_cmd" --config conf/decode_dnn.config --acwt 0.2 \
......
......@@ -3,7 +3,7 @@
# Copyright 2012-2014 Brno University of Technology (Author: Karel Vesely)
# Apache 2.0
# This example script trains a DNN on top of fMLLR features.
# This example script trains a DNN on top of FBANK features.
# The training is done in 3 stages,
#
# 1) RBM pre-training:
......@@ -34,12 +34,12 @@ stage=0
# Make the FBANK features
if [ $stage -le 0 ]; then
# Dev set
mkdir -p $dev && cp $dev_original/* $dev
utils/copy_data_dir.sh $dev_original $dev || exit 1; rm $dev/{cmvn,feats}.scp
steps/make_fbank_pitch.sh --nj 10 --cmd "$train_cmd" \
$dev $dev/log $dev/data || exit 1;
steps/compute_cmvn_stats.sh $dev $dev/log $dev/data || exit 1;
# Training set
mkdir -p $train && cp $train_original/* $train
utils/copy_data_dir.sh $train_original $train || exit 1; rm $train/{cmvn,feats}.scp
steps/make_fbank_pitch.sh --nj 10 --cmd "$train_cmd -tc 10" \
$train $train/log $train/data || exit 1;
steps/compute_cmvn_stats.sh $train $train/log $train/data || exit 1;
......@@ -49,21 +49,20 @@ fi
if [ $stage -le 1 ]; then
# Pre-train DBN, i.e. a stack of RBMs (small database, smaller DNN)
dir=exp/dnn4c_pretrain-dbn
(tail --pid=$$ -F $dir/log/pretrain_dbn.log 2>/dev/null)& # forward log
dir=exp/dnn4d-fbank_pretrain-dbn
$cuda_cmd $dir/log/pretrain_dbn.log \
steps/nnet/pretrain_dbn.sh \
--apply-cmvn true --norm-vars true --delta-order 2 --splice 5 \
--cmvn-opts "--norm-means=true --norm-vars=true" \
--delta-opts "--delta-order=2" --splice 5 \
--hid-dim 1024 --rbm-iter 20 $train $dir || exit 1;
fi
if [ $stage -le 2 ]; then
# Train the DNN optimizing per-frame cross-entropy.
dir=exp/dnn4c_pretrain-dbn_dnn
dir=exp/dnn4d-fbank_pretrain-dbn_dnn
ali=${gmm}_ali
feature_transform=exp/dnn4c_pretrain-dbn/final.feature_transform
dbn=exp/dnn4c_pretrain-dbn/6.dbn
(tail --pid=$$ -F $dir/log/train_nnet.log 2>/dev/null)& # forward log
feature_transform=exp/dnn4d-fbank_pretrain-dbn/final.feature_transform
dbn=exp/dnn4d-fbank_pretrain-dbn/6.dbn
# Train
$cuda_cmd $dir/log/train_nnet.log \
steps/nnet/train.sh --feature-transform $feature_transform --dbn $dbn --hid-layers 0 --learn-rate 0.008 \
......@@ -78,8 +77,8 @@ fi
# Sequence training using sMBR criterion, we do Stochastic-GD
# with per-utterance updates. We use usually good acwt 0.1
dir=exp/dnn4c_pretrain-dbn_dnn_smbr
srcdir=exp/dnn4c_pretrain-dbn_dnn
dir=exp/dnn4d-fbank_pretrain-dbn_dnn_smbr
srcdir=exp/dnn4d-fbank_pretrain-dbn_dnn
acwt=0.1
if [ $stage -le 3 ]; then
......
#!/bin/bash
# Copyright 2012-2015 Brno University of Technology (Author: Karel Vesely)
# Apache 2.0
# This example script trains DNN with <MultiSoftmax> output on top of FBANK features.
# The network is trained on RM and WSJ84 simultaneously.
. ./cmd.sh ## You'll want to change cmd.sh to something that will work on your system.
## This relates to the queue.
. ./path.sh ## Source the tools/utils (import the queue.pl)
dev=data-fbank-multilingual/test
train=data-fbank-multilingual/train
wsj=data-fbank-multilingual/wsj
train_tr90_wsj=data-fbank-multilingual/train_tr90_wsj
dev_original=data/test
train_original=data/train
wsj_original=../../wsj/s5/data/train_si84
[ ! -e $wsj_original ] && echo "Missing $wsj_original" && exit 1
gmm=exp/tri3b
wsj_ali=../../wsj/s5/exp/tri4b_ali_si284
[ ! -e $wsj_ali ] && echo "Missing $wsj_ali" && exit 1
stage=0
. utils/parse_options.sh || exit 1;
# Make the FBANK features,
if [ $stage -le 0 ]; then
# Make datadir copies,
utils/copy_data_dir.sh $dev_original $dev || exit 1; rm $dev/{cmvn,feats}.scp 2>/dev/null
utils/copy_data_dir.sh $train_original $train || exit 1; rm $train/{cmvn,feats}.scp 2>/dev/null
utils/copy_data_dir.sh --utt-prefix wsj --spk-prefix wsj $wsj_original $wsj || exit 1; rm $wsj/{cmvn,feats}.scp 2>/dev/null
# Feature extraction,
# Dev set,
steps/make_fbank_pitch.sh --nj 10 --cmd "$train_cmd" \
$dev $dev/log $dev/data || exit 1;
steps/compute_cmvn_stats.sh $dev $dev/log $dev/data || exit 1;
# Training set,
steps/make_fbank_pitch.sh --nj 10 --cmd "$train_cmd -tc 10" \
$train $train/log $train/data || exit 1;
steps/compute_cmvn_stats.sh $train $train/log $train/data || exit 1;
# Wsj,
steps/make_fbank_pitch.sh --nj 10 --cmd "$train_cmd -tc 10" \
$wsj $wsj/log $wsj/data || exit 1;
steps/compute_cmvn_stats.sh $wsj $wsj/log $wsj/data || exit 1;
# Split the rm training set,
utils/subset_data_dir_tr_cv.sh --cv-spk-percent 10 $train ${train}_tr90 ${train}_cv10 || exit 1
# Merge-in the wsj set with train-set,
utils/combine_data.sh $train_tr90_wsj ${train}_tr90 $wsj || exit 1
fi
# Prepare the merged targets,
dir=exp/dnn4e-fbank_multisoftmax
ali1_dim=$(hmm-info ${gmm}_ali/final.mdl | grep pdfs | awk '{ print $NF }')
ali2_dim=$(hmm-info ${wsj_ali}/final.mdl | grep pdfs | awk '{ print $NF }')
#
output_dim=$((ali1_dim + ali2_dim))
#
ali1_pdf="ark:ali-to-pdf ${gmm}_ali/final.mdl 'ark:gzcat ${gmm}_ali/ali.*.gz |' ark:- |"
ali1_dir=${gmm}_ali
#
if [ $stage -le 1 ]; then
mkdir -p $dir/log
featlen="ark:feat-to-len 'scp:cat $train/feats.scp $wsj/feats.scp |' ark,t:- |"
ali1="ark:ali-to-pdf ${gmm}_ali/final.mdl 'ark:gzcat ${gmm}_ali/ali.*.gz |' ark:- | ali-to-post ark:- ark:- |"
ali2="ark:ali-to-pdf ${wsj_ali}/final.mdl 'ark:gzcat ${wsj_ali}/ali.*.gz |' ark:- | ali-to-post ark:- ark:- |"
paste-post "$featlen" $ali1_dim:$ali2_dim "$ali1" "$ali2" ark,scp:$dir/pasted_post.ark,$dir/pasted_post.scp 2>$dir/log/paste_post.log || exit 1
fi
# Train <MultiSoftmax> system,
if [ $stage -le 2 ]; then
$cuda_cmd $dir/log/train_nnet.log \
steps/nnet/train.sh \
--cmvn-opts "--norm-means=true --norm-vars=true" \
--delta-opts "--delta-order=2" --splice 5 \
--labels "scp:$dir/pasted_post.scp" --num-tgt $output_dim \
--proto-opts "--block-softmax-dims='$ali1_dim:$ali2_dim'" \
--learn-rate 0.008 \
${train_tr90_wsj} ${train}_cv10 lang-dummy ali-dummy ali-dummy $dir || exit 1;
# Create files used in decdoing, missing due to --labels use,
analyze-counts --binary=false "$ali1_pdf" $dir/ali_train_pdf.counts || exit 1
copy-transition-model --binary=false $ali1_dir/final.mdl $dir/final.mdl || exit 1
cp $ali1_dir/tree $dir/tree || exit 1
# Rebuild network, <MultiSoftmax> is removed, and neurons from 1st block are selected,
nnet-concat "nnet-copy --remove-last-components=1 $dir/final.nnet - |" \
"echo '<Copy> <InputDim> $output_dim <OutputDim> $ali1_dim <BuildVector> 1:$ali1_dim </BuildVector>' | nnet-initialize - - |" \
$dir/final.nnet.lang1 || exit 1
# Decode (reuse HCLG graph)
steps/nnet/decode.sh --nj 20 --cmd "$decode_cmd" --config conf/decode_dnn.config --acwt 0.1 \
--nnet $dir/final.nnet.lang1 \
$gmm/graph $dev $dir/decode || exit 1;
steps/nnet/decode.sh --nj 20 --cmd "$decode_cmd" --config conf/decode_dnn.config --acwt 0.1 \
--nnet $dir/final.nnet.lang1 \
$gmm/graph_ug $dev $dir/decode_ug || exit 1;
fi
# Train baseline system with <Softmax>,
if [ $stage -le 3 ]; then
dir=exp/dnn4e-fbank_baseline
$cuda_cmd $dir/log/train_nnet.log \
steps/nnet/train.sh \
--cmvn-opts "--norm-means=true --norm-vars=true" \
--delta-opts "--delta-order=2" --splice 5 \
--learn-rate 0.008 \
${train}_tr90 ${train}_cv10 data/lang ${gmm}_ali ${gmm}_ali $dir || exit 1;
# Decode (reuse HCLG graph)
steps/nnet/decode.sh --nj 20 --cmd "$decode_cmd" --config conf/decode_dnn.config --acwt 0.1 \
$gmm/graph $dev $dir/decode || exit 1;
steps/nnet/decode.sh --nj 20 --cmd "$decode_cmd" --config conf/decode_dnn.config --acwt 0.1 \
$gmm/graph_ug $dev $dir/decode_ug || exit 1;
fi
echo Success
exit 0
# Getting results [see RESULTS file]
# for x in exp/*/decode*; do [ -d $x ] && grep WER $x/wer_* | utils/best_wer.sh; done
......@@ -42,7 +42,6 @@ lang=$2
srcdir=$3
dir=$4
oov=`cat $lang/oov.int` || exit 1;
mkdir -p $dir/log
echo $nj > $dir/num_jobs
sdata=$data/split$nj
......@@ -63,30 +62,37 @@ done
# PREPARE FEATURE EXTRACTION PIPELINE
# Create the feature stream:
# import config,
cmvn_opts=
delta_opts=
D=$srcdir
[ -e $D/norm_vars ] && cmvn_opts="--norm-means=true --norm-vars=$(cat $D/norm_vars)" # Bwd-compatibility,
[ -e $D/cmvn_opts ] && cmvn_opts=$(cat $D/cmvn_opts)
[ -e $D/delta_order ] && delta_opts="--delta-order=$(cat $D/delta_order)" # Bwd-compatibility,
[ -e $D/delta_opts ] && delta_opts=$(cat $D/delta_opts)
#
# Create the feature stream,
feats="ark,s,cs:copy-feats scp:$sdata/JOB/feats.scp ark:- |"
# Optionally add cmvn
if [ -f $srcdir/norm_vars ]; then
norm_vars=$(cat $srcdir/norm_vars 2>/dev/null)
[ ! -f $sdata/1/cmvn.scp ] && echo "$0: cannot find cmvn stats $sdata/1/cmvn.scp" && exit 1
feats="$feats apply-cmvn --norm-vars=$norm_vars --utt2spk=ark:$sdata/JOB/utt2spk scp:$sdata/JOB/cmvn.scp ark:- ark:- |"
fi
# Optionally add deltas
if [ -f $srcdir/delta_order ]; then
delta_order=$(cat $srcdir/delta_order)
feats="$feats add-deltas --delta-order=$delta_order ark:- ark:- |"
fi
# Finally add feature_transform and the MLP
# apply-cmvn (optional),
[ ! -z "$cmvn_opts" -a ! -f $sdata/1/cmvn.scp ] && echo "$0: Missing $sdata/1/cmvn.scp" && exit 1
[ ! -z "$cmvn_opts" ] && feats="$feats apply-cmvn $cmvn_opts --utt2spk=ark:$sdata/JOB/utt2spk scp:$sdata/JOB/cmvn.scp ark:- ark:- |"
# add-deltas (optional),
[ ! -z "$delta_opts" ] && feats="$feats add-deltas $delta_opts ark:- ark:- |"
# nnet-forward,
feats="$feats nnet-forward $nnet_forward_opts --feature-transform=$feature_transform --class-frame-counts=$class_frame_counts --use-gpu=$use_gpu $nnet ark:- ark:- |"
#
echo "$0: aligning data '$data' using nnet/model '$srcdir', putting alignments in '$dir'"
# Map oovs in reference transcription
# Map oovs in reference transcription,
oov=`cat $lang/oov.int` || exit 1;
tra="ark:utils/sym2int.pl --map-oov $oov -f 2- $lang/words.txt $sdata/JOB/text|";
# We could just use align-mapped in the next line, but it's less efficient as it compiles the
# training graphs one by one.
if [ $stage -le 0 ]; then
train_graphs="ark:compile-train-graphs $dir/tree $dir/final.mdl $lang/L.fst '$tra' ark:- |"
$cmd JOB=1:$nj $dir/log/align.JOB.log \
compile-train-graphs $dir/tree $dir/final.mdl $lang/L.fst "$tra" ark:- \| \
compile-train-graphs $dir/tree $dir/final.mdl $lang/L.fst "$tra" ark:- \| \
align-compiled-mapped $scale_opts --beam=$beam --retry-beam=$retry_beam $dir/final.mdl ark:- \
"$feats" "ark,t:|gzip -c >$dir/ali.JOB.gz" || exit 1;
fi
......
......@@ -20,6 +20,7 @@ lattice_beam=8.0
min_active=200
max_active=7000 # limit of active tokens
max_mem=50000000 # approx. limit to memory consumption during minimization in bytes
nnet_forward_opts="--no-softmax=true --prior-scale=1.0"
skip_scoring=false
scoring_opts="--min-lmwt 4 --max-lmwt 15"
......@@ -88,24 +89,28 @@ thread_string=
# PREPARE FEATURE EXTRACTION PIPELINE
# Create the feature stream:
# import config,
cmvn_opts=
delta_opts=
D=$srcdir
[ -e $D/norm_vars ] && cmvn_opts="--norm-means=true --norm-vars=$(cat $D/norm_vars)" # Bwd-compatibility,
[ -e $D/cmvn_opts ] && cmvn_opts=$(cat $D/cmvn_opts)
[ -e $D/delta_order ] && delta_opts="--delta-order=$(cat $D/delta_order)" # Bwd-compatibility,
[ -e $D/delta_opts ] && delta_opts=$(cat $D/delta_opts)
#
# Create the feature stream,
feats="ark,s,cs:copy-feats scp:$sdata/JOB/feats.scp ark:- |"
# Optionally add cmvn
if [ -f $srcdir/norm_vars ]; then
norm_vars=$(cat $srcdir/norm_vars 2>/dev/null)
[ ! -f $sdata/1/cmvn.scp ] && echo "$0: cannot find cmvn stats $sdata/1/cmvn.scp" && exit 1
feats="$feats apply-cmvn --norm-vars=$norm_vars --utt2spk=ark:$sdata/JOB/utt2spk scp:$sdata/JOB/cmvn.scp ark:- ark:- |"
fi
# Optionally add deltas
if [ -f $srcdir/delta_order ]; then
delta_order=$(cat $srcdir/delta_order)
feats="$feats add-deltas --delta-order=$delta_order ark:- ark:- |"
fi
# Run the decoding in the queue
# apply-cmvn (optional),
[ ! -z "$cmvn_opts" -a ! -f $sdata/1/cmvn.scp ] && echo "$0: Missing $sdata/1/cmvn.scp" && exit 1
[ ! -z "$cmvn_opts" ] && feats="$feats apply-cmvn $cmvn_opts --utt2spk=ark:$sdata/JOB/utt2spk scp:$sdata/JOB/cmvn.scp ark:- ark:- |"
# add-deltas (optional),
[ ! -z "$delta_opts" ] && feats="$feats add-deltas $delta_opts ark:- ark:- |"
#
# Run the decoding in the queue,
if [ $stage -le 0 ]; then
$cmd $parallel_opts JOB=1:$nj $dir/log/decode.JOB.log \
nnet-forward --feature-transform=$feature_transform --no-softmax=true --class-frame-counts=$class_frame_counts --use-gpu=$use_gpu $nnet "$feats" ark:- \| \
nnet-forward $nnet_forward_opts --feature-transform=$feature_transform --class-frame-counts=$class_frame_counts --use-gpu=$use_gpu $nnet "$feats" ark:- \| \
latgen-faster-mapped$thread_string --min-active=$min_active --max-active=$max_active --max-mem=$max_mem --beam=$beam \
--lattice-beam=$lattice_beam --acoustic-scale=$acwt --allow-partial=true --word-symbol-table=$graphdir/words.txt \
$model $graphdir/HCLG.fst ark:- "ark:|gzip -c > $dir/lat.JOB.gz" || exit 1;
......
......@@ -9,6 +9,7 @@
nj=4
cmd=run.pl
remove_last_components=4 # remove N last components from the nnet
use_gpu=no
htk_save=false
# End configuration section.
......@@ -20,9 +21,10 @@ if [ -f path.sh ]; then . ./path.sh; fi
if [ $# != 5 ]; then
echo "usage: $0 [options] <tgt-data-dir> <src-data-dir> <nnet-dir> <log-dir> <abs-path-to-bn-feat-dir>";
echo "options: "
echo " --trim-transforms <N> # number of NNet Components to remove from the end"
echo " --nj <nj> # number of parallel jobs"
echo " --cmd (utils/run.pl|utils/queue.pl <queue opts>) # how to run jobs."
echo " --cmd 'queue.pl <queue opts>' # how to run jobs."
echo " --nj <nj> # number of parallel jobs"
echo " --remove-last-components <N> # number of NNet Components to remove from the end"
echo " --use-gpu (no|yes|optional) # forwarding on GPU"
exit 1;
fi
......@@ -37,24 +39,13 @@ bnfeadir=$5
######## CONFIGURATION
# copy the dataset metadata from srcdata.
mkdir -p $data || exit 1;
cp $srcdata/* $data 2>/dev/null; rm $data/feats.scp $data/cmvn.scp;
mkdir -p $data $logdir $bnfeadir || exit 1;
utils/copy_data_dir.sh $srcdata $data; rm $data/{feats,cmvn}.scp 2>/dev/null
# make $bnfeadir an absolute pathname.
bnfeadir=`perl -e '($dir,$pwd)= @ARGV; if($dir!~m:^/:) { $dir = "$pwd/$dir"; } print $dir; ' $bnfeadir ${PWD}`
[ '/' != ${bnfeadir:0:1} ] && bnfeadir=$PWD/$bnfeadir
# use "name" as part of name of the archive.
name=`basename $data`
mkdir -p $bnfeadir || exit 1;
mkdir -p $data || exit 1;
mkdir -p $logdir || exit 1;
srcscp=$srcdata/feats.scp
scp=$data/feats.scp
required="$srcscp $nndir/final.nnet $nndir/final.feature_transform"
required="$srcdata/feats.scp $nndir/final.nnet $nndir/final.feature_transform"
for f in $required; do
if [ ! -f $f ]; then
echo "$0: no such file $f"
......@@ -62,55 +53,54 @@ for f in $required; do
fi
done
if [ ! -d $srcdata/split$nj -o $srcdata/split$nj -ot $srcdata/feats.scp ]; then
utils/split_data.sh $srcdata $nj
fi
sdata=$srcdata/split$nj
[[ -d $sdata && $srcdata/feats.scp -ot $sdata ]] || split_data.sh $srcdata $nj || exit 1;
# Concat feature transform with trimmed MLP:
nnet=$bnfeadir/feature_extractor.nnet
nnet-concat $nndir/final.feature_transform "nnet-copy --remove-last-components=$remove_last_components $nndir/final.nnet - |" $nnet 2>$logdir/feature_extractor.log || exit 1
nnet-info $nnet >$data/feature_extractor.nnet-info
echo "Creating bn-feats into $data"
###
### Prepare feature pipeline
feats="ark,s,cs:copy-feats scp:$srcdata/split$nj/JOB/feats.scp ark:- |"
# Optionally add cmvn
if [ -f $nndir/norm_vars ]; then
norm_vars=$(cat $nndir/norm_vars 2>/dev/null)
feats="$feats apply-cmvn --norm-vars=$norm_vars --utt2spk=ark:$srcdata/utt2spk scp:$srcdata/cmvn.scp ark:- ark:- |"
fi
# Optionally add deltas
if [ -f $nndir/delta_order ]; then
delta_order=$(cat $nndir/delta_order)
feats="$feats add-deltas --delta-order=$delta_order ark:- ark:- |"
fi
###
###
# Run the forward pass
# PREPARE FEATURE EXTRACTION PIPELINE
# import config,
cmvn_opts=
delta_opts=
D=$nndir
[ -e $D/norm_vars ] && cmvn_opts="--norm-means=true --norm-vars=$(cat $D/norm_vars)" # Bwd-compatibility,
[ -e $D/cmvn_opts ] && cmvn_opts=$(cat $D/cmvn_opts)
[ -e $D/delta_order ] && delta_opts="--delta-order=$(cat $D/delta_order)" # Bwd-compatibility,
[ -e $D/delta_opts ] && delta_opts=$(cat $D/delta_opts)
#
# Create the feature stream,
feats="ark,s,cs:copy-feats scp:$sdata/JOB/feats.scp ark:- |"
# apply-cmvn (optional),
[ ! -z "$cmvn_opts" -a ! -f $sdata/1/cmvn.scp ] && echo "$0: Missing $sdata/1/cmvn.scp" && exit 1
[ ! -z "$cmvn_opts" ] && feats="$feats apply-cmvn $cmvn_opts --utt2spk=ark:$sdata/JOB/utt2spk scp:$sdata/JOB/cmvn.scp ark:- ark:- |"
# add-deltas (optional),
[ ! -z "$delta_opts" ] && feats="$feats add-deltas $delta_opts ark:- ark:- |"
#
# Run the forward pass,
$cmd JOB=1:$nj $logdir/make_bnfeats.JOB.log \
nnet-forward $nnet "$feats" \
nnet-forward --use-gpu=$use_gpu $nnet "$feats" \
ark,scp:$bnfeadir/raw_bnfea_$name.JOB.ark,$bnfeadir/raw_bnfea_$name.JOB.scp \
|| exit 1;
# check that the sentence counts match
N0=$(cat $srcdata/feats.scp | wc -l)
N1=$(cat $bnfeadir/raw_bnfea_$name.*.scp | wc -l)
if [[ "$N0" != "$N1" ]]; then
echo "Error producing features for $name:"
echo "Original sentences : $N0 Bottleneck sentences : $N1"
exit 1;
fi
# concatenate the .scp files
for ((n=1; n<=nj; n++)); do
cat $bnfeadir/raw_bnfea_$name.$n.scp >> $data/feats.scp
done
echo "Succeeded creating MLP-BN features for $name ($data)"
# check sentence counts,
N0=$(cat $srcdata/feats.scp | wc -l)
N1=$(cat $data/feats.scp | wc -l)
[[ "$N0" != "$N1" ]] && echo "$0: sentence-count mismatch, $srcdata $N0, $data $N1" && exit 1
echo "Succeeded creating MLP-BN features '$data'"
# optionally resave in as HTK features:
# optionally resave in as HTK features,
if [ $htk_save == true ]; then
echo -n "Resaving as HTK features into $bnfeadir/htk ... "
mkdir -p $bnfeadir/htk
......
......@@ -15,6 +15,7 @@ lattice_beam=7.0
acwt=0.1
max_active=5000
nnet=
nnet_forward_opts="--no-softmax=true --prior-scale=1.0"
max_mem=20000000 # This will stop the processes getting too large.
# This is in bytes, but not "real" bytes-- you have to multiply
# by something like 5 or 10 to get real bytes (not sure why so large)
......@@ -93,22 +94,25 @@ done
# PREPARE FEATURE EXTRACTION PIPELINE
# Create the feature stream:
# import config,
cmvn_opts=
delta_opts=
D=$srcdir
[ -e $D/norm_vars ] && cmvn_opts="--norm-means=true --norm-vars=$(cat $D/norm_vars)" # Bwd-compatibility,
[ -e $D/cmvn_opts ] && cmvn_opts=$(cat $D/cmvn_opts)
[ -e $D/delta_order ] && delta_opts="--delta-order=$(cat $D/delta_order)" # Bwd-compatibility,
[ -e $D/delta_opts ] && delta_opts=$(cat $D/delta_opts)
#
# Create the feature stream,
feats="ark,s,cs:copy-feats scp:$sdata/JOB/feats.scp ark:- |"
# Optionally add cmvn
if [ -f $srcdir/norm_vars ]; then
norm_vars=$(cat $srcdir/norm_vars 2>/dev/null)
[ ! -f $sdata/1/cmvn.scp ] && echo "$0: cannot find cmvn stats $sdata/1/cmvn.scp" && exit 1
feats="$feats apply-cmvn --norm-vars=$norm_vars --utt2spk=ark:$sdata/JOB/utt2spk scp:$sdata/JOB/cmvn.scp ark:- ark:- |"
fi
# Optionally add deltas
if [ -f $srcdir/delta_order ]; then
delta_order=$(cat $srcdir/delta_order)
feats="$feats add-deltas --delta-order=$delta_order ark:- ark:- |"
fi
# Finally add feature_transform and the MLP
feats="$feats nnet-forward --feature-transform=$feature_transform --no-softmax=true --class-frame-counts=$class_frame_counts --use-gpu=$use_gpu $nnet ark:- ark:- |"
# apply-cmvn (optional),
[ ! -z "$cmvn_opts" -a ! -f $sdata/1/cmvn.scp ] && echo "$0: Missing $sdata/1/cmvn.scp" && exit 1
[ ! -z "$cmvn_opts" ] && feats="$feats apply-cmvn $cmvn_opts --utt2spk=ark:$sdata/JOB/utt2spk scp:$sdata/JOB/cmvn.scp ark:- ark:- |"
# add-deltas (optional),
[ ! -z "$delta_opts" ] && feats="$feats add-deltas $delta_opts ark:- ark:- |"
# nnet-forward,
feats="$feats nnet-forward $nnet_forward_opts --feature-transform=$feature_transform --class-frame-counts=$class_frame_counts --use-gpu=$use_gpu $nnet ark:- ark:- |"
#
# if this job is interrupted by the user, we want any background jobs to be
# killed too.
......
......@@ -51,14 +51,12 @@ mkdir -p $data $logdir $feadir
# Check files exist,
for f in $sdata/1/feats.scp $sdata/1/cmvn.scp; do
[ ! -f $f ] && echo "$0: Missing file $f" && exit 1;
[ ! -f $f ] && echo "$0: Missing $f" && exit 1;
done
if [ ! -z "$transform_dir" ]; then
[ ! -f $transform_dir/trans.1 ] && "$0: Missing file $transform_dir/trans.1" && exit 1;
fi
if [ ! -z "$raw_transform_dir" ]; then
[ ! -f $raw_transform_dir/raw_trans.1 ] && "$0: Missing file $raw_transform_dir/raw_trans.1" && exit 1;
fi
[ ! -z "$transform_dir" -a ! -f $transform_dir/trans.1 ] && \
echo "$0: Missing $transform_dir/trans.1" && exit 1;
[ ! -z "$raw_transform_dir" -a ! -f $raw_transform_dir/raw_trans.1 ] && \
echo "$0: Missing $raw_transform_dir/raw_trans.1" && exit 1;
# Figure-out the feature-type,
feat_type=delta # Default
......@@ -81,9 +79,9 @@ case $feat_type in
esac
# Prepare the output dir,
cp $srcdata/* $data 2>/dev/null; rm $data/{feats,cmvn}.scp;
# Make $bnfeadir an absolute pathname,
feadir=`perl -e '($dir,$pwd)= @ARGV; if($dir!~m:^/:) { $dir = "$pwd/$dir"; } print $dir; ' $feadir ${PWD}`
utils/copy_data_dir.sh $srcdata $data; rm $data/{feats,cmvn}.scp 2>/dev/null
# Make $feadir an absolute pathname,
[ '/' != ${feadir:0:1} ] && feadir=$PWD/$feadir
# Store the output-features,
name=`basename $data`
......
......@@ -46,9 +46,8 @@ copy_feats=true # resave the features randomized consecutively to tmpdir
# feature config
feature_transform= # Optionally reuse feature processing front-end (override splice,etc.)
feature_transform_proto= # Optionally pass prototype of feature transform
delta_order= # Optionally use deltas on the input features
apply_cmvn=false # Optionally do CMVN of the input features
norm_vars=false # When apply_cmvn=true, this enables CVN
cmvn_opts= # Optionally do CMVN of the input features with options
delta_opts= # Optionally use deltas on the input features
splice=5 # Temporal splicing
splice_step=1 # Stepsize of the splicing (1 is consecutive splice,
# value 2 would do [ -10 -8 -6 -4 -2 0 2 4 6 8 10 ] splicing)
......@@ -127,10 +126,11 @@ head -n 10000 $dir/train.scp > $dir/train.scp.10k
###### OPTIONALLY IMPORT FEATURE SETTINGS ######
if [ ! -z $feature_transform ]; then
transf_dir=$(dirname $feature_transform)
D=$(dirname $feature_transform)
echo "Importing feature settings from: $transf_dir"
[ -e $transf_dir/norm_vars ] && apply_cmvn=true && norm_vars=$(cat $transf_dir/norm_vars)
[ -e $transf_dir/delta_order ] && delta_order=$(cat $transf_dir/delta_order)
[ -e $D/cmvn_opts ] && cmvn_opts=$(cat $D/cmvn_opts)
[ -e $D/delta_opts ] && delta_opts=$(cat $D/delta_opts)
echo "Imported config : cmvn_opts='$cmvn_opts' delta_opts='$delta_opts'"
fi
###### PREPARE FEATURE PIPELINE ######
......@@ -139,21 +139,21 @@ fi
feats="ark:copy-feats scp:$dir/train.scp ark:- |"