Skip to content

Commit 80cb59f

Browse files
committed
trunk: various minor fixes. Modifying the new VTLN scripts to use the 'cvmn_opts'; some minor changes in how 'cmvn_opts' are handled; some cosmetic fixes in trunk. Adding --norm-means option to apply-cmvn.
git-svn-id: https://svn.code.sf.net/p/kaldi/code/trunk@3966 5e6a8d80-dfce-4ca6-a32a-6e07a63d50c8
1 parent e293af3 commit 80cb59f

11 files changed

Lines changed: 69 additions & 45 deletions

File tree

‎egs/wsj/s5/steps/align_lvtln.sh‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ cp $srcdir/final.occs $dir;
6161

6262
splice_opts=`cat $srcdir/splice_opts 2>/dev/null` # frame-splicing options.
6363
cp $srcdir/splice_opts $dir 2>/dev/null # frame-splicing options.
64-
norm_vars=`cat $srcdir/norm_vars 2>/dev/null` || norm_vars=false # cmn/cmvn option, default false.
65-
cp $srcdir/norm_vars $dir 2>/dev/null # cmn/cmvn option.
64+
cmvn_opts=`cat $srcdir/cmvn_opts 2>/dev/null`
65+
cp $srcdir/cmvn_opts $dir 2>/dev/null # cmn/cmvn option.
6666

6767
## Set up the unadapted features "$sifeats"
6868
if [ -f $srcdir/final.mat ]; then feat_type=lda; else feat_type=delta; fi
6969
echo "$0: feature type is $feat_type";
7070
case $feat_type in
71-
delta) sifeats="ark,s,cs:apply-cmvn --norm-vars=$norm_vars --utt2spk=ark:$sdata/JOB/utt2spk scp:$sdata/JOB/cmvn.scp scp:$sdata/JOB/feats.scp ark:- | add-deltas ark:- ark:- |";;
72-
lda) sifeats="ark,s,cs:apply-cmvn --norm-vars=$norm_vars --utt2spk=ark:$sdata/JOB/utt2spk scp:$sdata/JOB/cmvn.scp scp:$sdata/JOB/feats.scp ark:- | splice-feats $splice_opts ark:- ark:- | transform-feats $srcdir/final.mat ark:- ark:- |"
71+
delta) sifeats="ark,s,cs:apply-cmvn $cmvn_opts --utt2spk=ark:$sdata/JOB/utt2spk scp:$sdata/JOB/cmvn.scp scp:$sdata/JOB/feats.scp ark:- | add-deltas ark:- ark:- |";;
72+
lda) sifeats="ark,s,cs:apply-cmvn $cmvn_opts --utt2spk=ark:$sdata/JOB/utt2spk scp:$sdata/JOB/cmvn.scp scp:$sdata/JOB/feats.scp ark:- | splice-feats $splice_opts ark:- ark:- | transform-feats $srcdir/final.mat ark:- ark:- |"
7373
cp $srcdir/final.mat $srcdir/full.mat $dir
7474
;;
7575
*) echo "Invalid feature type $feat_type" && exit 1;

‎egs/wsj/s5/steps/decode_lvtln.sh‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ mkdir -p $dir/log
6161
split_data.sh $data $nj || exit 1;
6262
echo $nj > $dir/num_jobs
6363
splice_opts=`cat $srcdir/splice_opts 2>/dev/null` # frame-splicing options.
64-
norm_vars=`cat $srcdir/norm_vars 2>/dev/null` || norm_vars=false # cmn/cmvn option, default false.
64+
cmvn_opts=`cat $srcdir/cmvn_opts 2>/dev/null`
6565

6666
silphonelist=`cat $graphdir/phones/silence.csl` || exit 1;
6767

@@ -76,8 +76,8 @@ done
7676
if [ -f $srcdir/final.mat ]; then feat_type=lda; else feat_type=delta; fi
7777
echo "$0: feature type is $feat_type";
7878
case $feat_type in
79-
delta) sifeats="ark,s,cs:apply-cmvn --norm-vars=$norm_vars --utt2spk=ark:$sdata/JOB/utt2spk scp:$sdata/JOB/cmvn.scp scp:$sdata/JOB/feats.scp ark:- | add-deltas ark:- ark:- |";;
80-
lda) sifeats="ark,s,cs:apply-cmvn --norm-vars=$norm_vars --utt2spk=ark:$sdata/JOB/utt2spk scp:$sdata/JOB/cmvn.scp scp:$sdata/JOB/feats.scp ark:- | splice-feats $splice_opts ark:- ark:- | transform-feats $srcdir/final.mat ark:- ark:- |";;
79+
delta) sifeats="ark,s,cs:apply-cmvn $cmvn_opts --utt2spk=ark:$sdata/JOB/utt2spk scp:$sdata/JOB/cmvn.scp scp:$sdata/JOB/feats.scp ark:- | add-deltas ark:- ark:- |";;
80+
lda) sifeats="ark,s,cs:apply-cmvn $cmvn_opts --utt2spk=ark:$sdata/JOB/utt2spk scp:$sdata/JOB/cmvn.scp scp:$sdata/JOB/feats.scp ark:- | splice-feats $splice_opts ark:- ark:- | transform-feats $srcdir/final.mat ark:- ark:- |";;
8181
*) echo "Invalid feature type $feat_type" && exit 1;
8282
esac
8383

‎egs/wsj/s5/steps/train_deltas.sh‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ retry_beam=40
1616
boost_silence=1.0 # Factor by which to boost silence likelihoods in alignment
1717
power=0.25 # Exponent for number of gaussians according to occurrence counts
1818
cluster_thresh=-1 # for build-tree control final bottom-up clustering of leaves
19-
norm_vars=false # false : cmn, true : cmvn. To turn off CMN completely,
20-
# supply the --fake option to compute_cmvn_stats.sh
19+
norm_vars=false # deprecated. Prefer --cmvn-opts "--norm-vars=true"
20+
# use the option --cmvn-opts "--norm-means=false"
2121
cmvn_opts=
2222
# End configuration.
2323

@@ -58,6 +58,9 @@ echo $nj > $dir/num_jobs
5858
sdata=$data/split$nj;
5959
split_data.sh $data $nj || exit 1;
6060

61+
62+
[ $(cat $alidir/cmvn_opts 2>/dev/null | wc -c) -gt 1 ] && [ -z "$cmvn_opts" ] && \
63+
echo "$0: warning: ignoring CMVN options from source directory $alidir"
6164
$norm_vars && cmvn_opts="--norm-vars=true $cmvn_opts"
6265
echo $cmvn_opts > $dir/cmvn_opts # keep track of options to CMVN.
6366

‎egs/wsj/s5/steps/train_lda_mllt.sh‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ randprune=4.0 # This is approximately the ratio by which we will speed up the
2121
# LDA and MLLT calculations via randomized pruning.
2222
splice_opts=
2323
cluster_thresh=-1 # for build-tree control final bottom-up clustering of leaves
24-
norm_vars=false # false : cmn, true : cmvn
25-
# To turn off CMN completely, supply the --fake option to
26-
# compute_cmvn.sh.
24+
norm_vars=false # deprecated. Prefer --cmvn-opts "--norm-vars=false"
25+
cmvn_opts=
2726
# End configuration.
2827
train_tree=true # if false, don't actually train the tree.
2928
use_lda_mat= # If supplied, use this LDA[+MLLT] matrix.
@@ -66,8 +65,11 @@ echo $nj >$dir/num_jobs
6665
echo "$splice_opts" >$dir/splice_opts # keep track of frame-splicing options
6766
# so that later stages of system building can know what they were.
6867

68+
69+
[ $(cat $alidir/cmvn_opts 2>/dev/null | wc -c) -gt 1 ] && [ -z "$cmvn_opts" ] && \
70+
echo "$0: warning: ignoring CMVN options from source directory $alidir"
6971
$norm_vars && cmvn_opts="--norm-vars=true $cmvn_opts"
70-
echo $cmvn_opts > $dir/cmvn_opts # keep track of options to CMVN.
72+
echo $cmvn_opts > $dir/cmvn_opts # keep track of options to CMVN.
7173

7274
sdata=$data/split$nj;
7375
split_data.sh $data $nj || exit 1;

‎egs/wsj/s5/steps/train_lvtln.sh‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ retry_beam=40
2626
boost_silence=1.0 # Factor by which to boost silence likelihoods in alignment
2727
power=0.25 # Exponent for number of gaussians according to occurrence counts
2828
cluster_thresh=-1 # for build-tree control final bottom-up clustering of leaves
29-
norm_vars=false # false : cmn, true : cmvn. To turn off CMN completely,
30-
# supply the --fake option to compute_cmvn_stats.sh
31-
29+
cmvn_opts= # you can supply e.g. --cmvn-opts "--norm-vars=true" to turn on variance
30+
# normalization, but only if base system is the delta type, not LDA.
3231
lvtln_iters="2 4 6 8 10 12 14 16 20"; # iters on which to recompute LVTLN transform"
3332
num_utt_lvtln_init=200; # number of utterances (subset) to initialize
3433
# LVTLN transform. Not too critical.
@@ -81,11 +80,17 @@ echo $nj > $dir/num_jobs
8180
sdata=$data/split$nj;
8281
split_data.sh $data $nj || exit 1;
8382

84-
echo $norm_vars > $dir/norm_vars # keep track of feature normalization type for decoding, alignment
83+
84+
cp $alidir/splice_opts $dir 2>/dev/null
85+
8586

8687
if [ ! -f $alidir/final.mat ]; then
88+
[ $(cat $alidir/cmvn_opts 2>/dev/null | wc -c) -gt 1 ] && [ -z "$cmvn_opts" ] && \
89+
echo "$0: warning: ignoring CMVN options from $alidir.";
90+
echo $cmvn_opts > $dir/cmvn_opts
91+
8792
echo "$0: Using delta+delta-delta features since $alidir/final.mat does not exist"
88-
sifeats="ark,s,cs:apply-cmvn --norm-vars=$norm_vars --utt2spk=ark:$sdata/JOB/utt2spk scp:$sdata/JOB/cmvn.scp scp:$sdata/JOB/feats.scp ark:- | add-deltas ark:- ark:- |"
93+
sifeats="ark,s,cs:apply-cmvn $cmvn_opts --utt2spk=ark:$sdata/JOB/utt2spk scp:$sdata/JOB/cmvn.scp scp:$sdata/JOB/feats.scp ark:- | add-deltas ark:- ark:- |"
8994
feats="$sifeats transform-feats --utt2spk=ark:$sdata/JOB/utt2spk ark:$dir/trans.JOB ark:- ark:- |"
9095
# for the subsets of features that we use to estimate the linear transforms, we don't
9196
# bother with CMVN. This will give us wrong offsets on the transforms, but it will end
@@ -95,8 +100,10 @@ if [ ! -f $alidir/final.mat ]; then
95100
featsub_unwarped="ark:add-deltas ark:$dir/feats.$default_class.ark ark:- |"
96101
else
97102
echo "$0: Using LDA features"
98-
cp $alidir/final.mat $alidir/full.mat $alidir/splice_opts $dir 2>/dev/null
99-
sifeats="ark,s,cs:apply-cmvn --norm-vars=$norm_vars --utt2spk=ark:$sdata/JOB/utt2spk scp:$sdata/JOB/cmvn.scp scp:$sdata/JOB/feats.scp ark:- | splice-feats $splice_opts ark:- ark:- | transform-feats $dir/final.mat ark:- ark:- |"
103+
[ ! -z "$cmvn_opts" ] && echo "$0: you cannot supply --cmvn-opts if base system is LDA."
104+
cp $alidir/final.mat $alidir/full.mat $alidir/splice_opts $alidir/cmvn_opts $dir 2>/dev/null
105+
cmvn_opts=`cat $dir/cmvn_opts 2>/dev/null`
106+
sifeats="ark,s,cs:apply-cmvn $cmvn_opts --utt2spk=ark:$sdata/JOB/utt2spk scp:$sdata/JOB/cmvn.scp scp:$sdata/JOB/feats.scp ark:- | splice-feats $splice_opts ark:- ark:- | transform-feats $dir/final.mat ark:- ark:- |"
100107
feats="$sifeats transform-feats --utt2spk=ark:$sdata/JOB/utt2spk ark:$dir/trans.JOB ark:- ark:- |"
101108
featsub_warped="ark:splice-feats $splice_opts ark:$dir/feats.CLASS.ark ark:- | transform-feats $dir/final.mat ark:- ark:- |" # you need to define CLASS when invoking $cmd.
102109
featsub_unwarped="ark:splice-feats $splice_opts ark:$dir/feats.$default_class.ark ark:- | transform-feats $dir/final.mat ark:- ark:- |"
@@ -112,7 +119,6 @@ fi
112119
cat $data/utt2spk | awk '{print $1}' | utils/shuffle_list.pl | \
113120
head -n $num_utt_lvtln_init > $dir/utt_subset
114121

115-
116122
all_warps="";
117123
for c in $(seq 0 $[$num_classes-1]); do
118124
this_warp=$(perl -e "print ($min_warp + ($c*$warp_step));")

‎egs/wsj/s5/steps/train_mono.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ config= # name of config file.
2020
stage=-4
2121
power=0.25 # exponent to determine number of gaussians from occurrence counts
2222
feat_dim=-1 # This option is now ignored but retained for compatibility.
23-
norm_vars=false # false : cmn, true : cmvn
23+
norm_vars=false # deprecated, prefer --cmvn-opts "--norm-vars=false"
2424
cmvn_opts= # can be used to add extra options to cmvn.
2525
# End configuration section.
2626

‎src/feat/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ TESTFILES = feature-mfcc-test feature-plp-test feature-fbank-test \
99

1010
OBJFILES = feature-functions.o feature-mfcc.o feature-plp.o feature-fbank.o \
1111
feature-spectrogram.o mel-computations.o wave-reader.o \
12-
pitch-functions.o feature-sdc-test.o
12+
pitch-functions.o
1313

1414
LIBNAME = kaldi-feat
1515

‎src/featbin/apply-cmvn.cc‎

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// featbin/apply-cmvn.cc
22

33
// Copyright 2009-2011 Microsoft Corporation
4+
// 2014 Johns Hopkins University
45

56
// See ../../COPYING for clarification regarding multiple authors
67
//
@@ -35,18 +36,24 @@ int main(int argc, char *argv[]) {
3536
ParseOptions po(usage);
3637
std::string utt2spk_rspecifier;
3738
bool norm_vars = false;
39+
bool norm_means = true;
3840
po.Register("utt2spk", &utt2spk_rspecifier, "rspecifier for utterance to speaker map");
3941
po.Register("norm-vars", &norm_vars, "If true, normalize variances. Note: "
4042
"to turn off mean normalization also, it's generally easiest to "
4143
"compute 'fake' CMVN stats with zero/one mean/variance."
4244
"See the --fake option to compute_cmvn_stats.sh");
45+
po.Register("norm-means", &norm_means, "You can set this to false to turn off mean "
46+
"normalization, or to compute 'fake' CMVN stats; "
47+
"see the --fake option to compute_cmvn_stats.sh");
4348

4449
po.Read(argc, argv);
4550

4651
if (po.NumArgs() != 3) {
4752
po.PrintUsage();
4853
exit(1);
4954
}
55+
if (norm_vars && !norm_means)
56+
KALDI_ERR << "You cannot normalize the variance but not the mean.";
5057

5158
kaldi::int32 num_done = 0, num_err = 0;
5259

@@ -63,28 +70,31 @@ int main(int argc, char *argv[]) {
6370

6471
RandomAccessDoubleMatrixReaderMapped cmvn_reader(cmvn_rspecifier,
6572
utt2spk_rspecifier);
66-
67-
for (;!feat_reader.Done(); feat_reader.Next()) {
73+
74+
for (; !feat_reader.Done(); feat_reader.Next()) {
6875
std::string utt = feat_reader.Key();
6976
Matrix<BaseFloat> feat(feat_reader.Value());
70-
71-
if (!cmvn_reader.HasKey(utt)) {
72-
KALDI_WARN << "No normalization statistics available for key "
73-
<< utt << ", producing no output for this utterance";
74-
num_err++;
75-
continue;
77+
if (norm_means) {
78+
if (!cmvn_reader.HasKey(utt)) {
79+
KALDI_WARN << "No normalization statistics available for key "
80+
<< utt << ", producing no output for this utterance";
81+
num_err++;
82+
continue;
83+
}
84+
const Matrix<double> &cmvn_stats = cmvn_reader.Value(utt);
85+
86+
ApplyCmvn(cmvn_stats, norm_vars, &feat);
87+
88+
feat_writer.Write(utt, feat);
89+
} else {
90+
feat_writer.Write(utt, feat);
7691
}
77-
const Matrix<double> &cmvn_stats = cmvn_reader.Value(utt);
78-
79-
ApplyCmvn(cmvn_stats, norm_vars, &feat);
80-
81-
feat_writer.Write(utt, feat);
8292
num_done++;
8393
}
8494
} else {
8595
if (utt2spk_rspecifier != "")
8696
KALDI_ERR << "--utt2spk option not compatible with rxfilename as input "
87-
<< "(did you forget ark:?)";
97+
<< "(did you forget ark:?)";
8898
std::string cmvn_rxfilename = cmvn_rspecifier_or_rxfilename;
8999
bool binary;
90100
Input ki(cmvn_rxfilename, &binary);
@@ -94,7 +104,8 @@ int main(int argc, char *argv[]) {
94104
for (;!feat_reader.Done(); feat_reader.Next()) {
95105
std::string utt = feat_reader.Key();
96106
Matrix<BaseFloat> feat(feat_reader.Value());
97-
ApplyCmvn(cmvn_stats, norm_vars, &feat);
107+
if (norm_means)
108+
ApplyCmvn(cmvn_stats, norm_vars, &feat);
98109
feat_writer.Write(utt, feat);
99110
num_done++;
100111
}

‎src/latbin/lattice-copy.cc‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ int main(int argc, char *argv[]) {
3737
"Copy lattices (e.g. useful for changing to text mode or changing\n"
3838
"format to standard from compact lattice.)\n"
3939
"Usage: lattice-copy [options] lattice-rspecifier lattice-wspecifier\n"
40-
" e.g.: lattice-copy --write-compact=false ark:1.lats ark,t:text.lats\n";
41-
40+
" e.g.: lattice-copy --write-compact=false ark:1.lats ark,t:text.lats\n"
41+
"See also: lattice-to-fst, and the script egs/wsj/s5/utils/convert_slf.pl\n";
42+
4243
ParseOptions po(usage);
4344
bool write_compact = true;
4445
po.Register("write-compact", &write_compact, "If true, write in normal (compact) form.");

‎src/matrix/kaldi-matrix.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#ifndef KALDI_MATRIX_KALDI_MATRIX_H_
2323
#define KALDI_MATRIX_KALDI_MATRIX_H_ 1
2424

25-
#include "matrix-common.h"
25+
#include "matrix/matrix-common.h"
2626

2727
namespace kaldi {
2828

0 commit comments

Comments
 (0)