2
## ====================================================================
4
## Copyright (c) 1996-2000 Carnegie Mellon University. All rights
7
## Redistribution and use in source and binary forms, with or without
8
## modification, are permitted provided that the following conditions
11
## 1. Redistributions of source code must retain the above copyright
12
## notice, this list of conditions and the following disclaimer.
14
## 2. Redistributions in binary form must reproduce the above copyright
15
## notice, this list of conditions and the following disclaimer in
16
## the documentation and/or other materials provided with the
19
## This work was supported in part by funding from the Defense Advanced
20
## Research Projects Agency and the National Science Foundation of the
21
## United States of America, and the CMU Sphinx Speech Consortium.
23
## THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
24
## ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25
## THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26
## PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
27
## NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28
## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30
## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31
## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32
## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
## ====================================================================
37
## Author: Ricky Houghton
38
## Author: David Huggins-Daines
44
use File::Spec::Functions;
47
use lib catdir(dirname($0), updir(), 'lib');
48
use SphinxTrain::Config;
49
use SphinxTrain::Util;
51
#************************************************************************
52
# this script performs baum-welch training using
53
# it needs as inputs an initial set of models in s3 format
54
# a mdef file and cepstra with transcription files.
55
#************************************************************************
57
$| = 1; # Turn on autoflushing
59
die "USAGE: $0 <iter> <part> <npart> [<ngau>]" if @ARGV < 3;
60
my ($iter, $part, $npart, $n_gau) = @ARGV;
61
$n_gau = $ST::CFG_INITIAL_NUM_DENSITIES unless defined($n_gau);
63
use vars qw($MLLT_FILE $MODEL_TYPE);
64
$MLLT_FILE = catfile($ST::CFG_MODEL_DIR, "${ST::CFG_EXPTNAME}.mllt");
68
if ($n_gau == $ST::CFG_INITIAL_NUM_DENSITIES) {
69
$modelinitialname = "${ST::CFG_EXPTNAME}.ci_${ST::CFG_DIRLABEL}_flatinitial";
72
$modelinitialname = "${ST::CFG_EXPTNAME}.falign_ci_${ST::CFG_DIRLABEL}_initial";
74
my $modelname="${ST::CFG_EXPTNAME}.falign_ci_${ST::CFG_DIRLABEL}";
75
my $mdefname="${ST::CFG_EXPTNAME}.falign_ci.mdef";
76
my $processname ="10.falign_ci_hmm";
78
my $output_buffer_dir = "$ST::CFG_BWACCUM_DIR/${ST::CFG_EXPTNAME}_buff_${part}";
79
mkdir ($output_buffer_dir,0777);
81
my ($hmm_dir, $var2pass);
83
$hmm_dir = "$ST::CFG_BASE_DIR/model_parameters/$modelinitialname";
86
$hmm_dir = "$ST::CFG_BASE_DIR/model_parameters/$modelname";
91
my $moddeffn = "$ST::CFG_BASE_DIR/model_architecture/$mdefname";
92
my $statepdeffn = $ST::CFG_HMM_TYPE; # indicates the type of HMMs
93
my $mixwfn = "$hmm_dir/mixture_weights";
95
my $tmatfn = "$hmm_dir/transition_matrices";
96
my $meanfn = "$hmm_dir/means";
97
my $varfn = "$hmm_dir/variances";
100
# These models are created in preparation for forced alignment, so use
101
# the non-forced aligned ones, necessarily
102
my ($listoffiles, $transcriptfile);
103
$listoffiles = $ST::CFG_LISTOFFILES;
104
$transcriptfile = $ST::CFG_TRANSCRIPTFILE;
107
$topn = $ST::CFG_CI_TOPN if (defined($ST::CFG_CI_TOPN) and ($ST::CFG_FULLVAR eq 'no') and ($ST::CFG_CI_TOPN < $n_gau));
109
my $logdir = "$ST::CFG_LOG_DIR/$processname";
110
my $logfile = "$logdir/${ST::CFG_EXPTNAME}.${n_gau}.$iter-$part.bw.log";
111
mkdir ($logdir,0777);
114
open INPUT,"<$listoffiles" or die "Failed to open $listoffiles: $!";
119
$ctl_counter = int ($ctl_counter / $npart) if $npart;
120
$ctl_counter = 1 unless ($ctl_counter);
122
Log("Baum welch starting for $n_gau Gaussian(s), iteration: $iter ($part of $npart)",
125
# If there is an MLLR transformation, use it
127
if (defined($ST::CFG_SVSPEC)) {
128
push(@feat_args, -svspec =>$ST::CFG_SVSPEC);
133
-ldadim => $ST::CFG_LDA_DIMENSION);
136
my $dictfn = "$ST::CFG_DICTIONARY";
137
if ($ST::CFG_G2P_MODEL eq "yes") {
138
$dictfn = "$ST::CFG_DICTIONARY.full";
141
my $return_value = RunTool
142
('bw', $logfile, $ctl_counter,
143
-moddeffn => $moddeffn,
144
-ts2cbfn => $statepdeffn,
146
-mwfloor => $mwfloor,
151
-fdictfn => $ST::CFG_FILLERDICT,
152
-ctlfn => $listoffiles,
155
-cepdir => $ST::CFG_FEATFILES_DIR,
156
-cepext => $ST::CFG_FEATFILE_EXTENSION,
157
-lsnfn => $transcriptfile,
158
-accumdir => $output_buffer_dir,
159
-varfloor => $minvar,
163
-agc => $ST::CFG_AGC,
164
-cmn => $ST::CFG_CMN,
165
-varnorm => $ST::CFG_VARNORM,
168
'-2passvar' => $var2pass,
170
-fullvar => $ST::CFG_FULLVAR,
171
-diagfull => $ST::CFG_DIAGFULL,
172
-feat => $ST::CFG_FEATURE,
173
-ceplen => $ST::CFG_VECTOR_LENGTH,
174
-outputfullpath => "yes",
175
-fullsuffixmatch => "yes",
181
LogError("Failed to start bw");
183
exit ($return_value);