~ubuntu-branches/ubuntu/utopic/sphinxtrain/utopic

« back to all changes in this revision

Viewing changes to scripts/10.falign_ci_hmm/baum_welch.pl

  • Committer: Package Import Robot
  • Author(s): Samuel Thibault
  • Date: 2013-01-02 04:10:21 UTC
  • Revision ID: package-import@ubuntu.com-20130102041021-ynsizmz33fx02hea
Tags: upstream-1.0.8
ImportĀ upstreamĀ versionĀ 1.0.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
## ====================================================================
 
3
##
 
4
## Copyright (c) 1996-2000 Carnegie Mellon University.  All rights
 
5
## reserved.
 
6
##
 
7
## Redistribution and use in source and binary forms, with or without
 
8
## modification, are permitted provided that the following conditions
 
9
## are met:
 
10
##
 
11
## 1. Redistributions of source code must retain the above copyright
 
12
##    notice, this list of conditions and the following disclaimer.
 
13
##
 
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
 
17
##    distribution.
 
18
##
 
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.
 
22
##
 
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.
 
34
##
 
35
## ====================================================================
 
36
##
 
37
## Author: Ricky Houghton
 
38
## Author: David Huggins-Daines
 
39
##
 
40
 
 
41
use strict;
 
42
use File::Copy;
 
43
use File::Basename;
 
44
use File::Spec::Functions;
 
45
use File::Path;
 
46
 
 
47
use lib catdir(dirname($0), updir(), 'lib');
 
48
use SphinxTrain::Config;
 
49
use SphinxTrain::Util;
 
50
 
 
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
#************************************************************************
 
56
 
 
57
$| = 1; # Turn on autoflushing
 
58
 
 
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);
 
62
 
 
63
use vars qw($MLLT_FILE $MODEL_TYPE);
 
64
$MLLT_FILE = catfile($ST::CFG_MODEL_DIR, "${ST::CFG_EXPTNAME}.mllt");
 
65
$MODEL_TYPE = 'ci';
 
66
 
 
67
my $modelinitialname;
 
68
if ($n_gau == $ST::CFG_INITIAL_NUM_DENSITIES) {
 
69
    $modelinitialname = "${ST::CFG_EXPTNAME}.ci_${ST::CFG_DIRLABEL}_flatinitial";
 
70
}
 
71
else {
 
72
    $modelinitialname = "${ST::CFG_EXPTNAME}.falign_ci_${ST::CFG_DIRLABEL}_initial";
 
73
}
 
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";
 
77
 
 
78
my $output_buffer_dir = "$ST::CFG_BWACCUM_DIR/${ST::CFG_EXPTNAME}_buff_${part}";
 
79
mkdir ($output_buffer_dir,0777);
 
80
 
 
81
my ($hmm_dir, $var2pass);
 
82
if ($iter == 1) {
 
83
    $hmm_dir  = "$ST::CFG_BASE_DIR/model_parameters/$modelinitialname";
 
84
    $var2pass    = "no";
 
85
} else {
 
86
    $hmm_dir      = "$ST::CFG_BASE_DIR/model_parameters/$modelname";
 
87
    $var2pass     = "yes";
 
88
}
 
89
 
 
90
 
 
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";
 
94
my $mwfloor = 1e-8;
 
95
my $tmatfn  = "$hmm_dir/transition_matrices";
 
96
my $meanfn  = "$hmm_dir/means";
 
97
my $varfn   = "$hmm_dir/variances";
 
98
my $minvar  = 1e-4;
 
99
 
 
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;
 
105
 
 
106
my $topn = $n_gau;
 
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));
 
108
 
 
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);
 
112
 
 
113
my $ctl_counter = 0;
 
114
open INPUT,"<$listoffiles" or die "Failed to open $listoffiles: $!";
 
115
while (<INPUT>) {
 
116
    $ctl_counter++;
 
117
}
 
118
close INPUT;
 
119
$ctl_counter = int ($ctl_counter / $npart) if $npart;
 
120
$ctl_counter = 1 unless ($ctl_counter);
 
121
 
 
122
Log("Baum welch starting for $n_gau Gaussian(s), iteration: $iter ($part of $npart)",
 
123
    'result');
 
124
 
 
125
# If there is an MLLR transformation, use it
 
126
my @feat_args;
 
127
if (defined($ST::CFG_SVSPEC)) {
 
128
    push(@feat_args, -svspec =>$ST::CFG_SVSPEC);
 
129
}
 
130
if (-r $MLLT_FILE) {
 
131
    push(@feat_args,
 
132
         -lda => $MLLT_FILE,
 
133
         -ldadim => $ST::CFG_LDA_DIMENSION);
 
134
}
 
135
 
 
136
my $dictfn = "$ST::CFG_DICTIONARY";
 
137
if ($ST::CFG_G2P_MODEL eq "yes") {
 
138
    $dictfn = "$ST::CFG_DICTIONARY.full";
 
139
}
 
140
 
 
141
my $return_value = RunTool
 
142
    ('bw', $logfile, $ctl_counter,
 
143
     -moddeffn => $moddeffn,
 
144
     -ts2cbfn => $statepdeffn,
 
145
     -mixwfn => $mixwfn,
 
146
     -mwfloor => $mwfloor,
 
147
     -tmatfn => $tmatfn,
 
148
     -meanfn => $meanfn,
 
149
     -varfn => $varfn,
 
150
     -dictfn => $dictfn,
 
151
     -fdictfn => $ST::CFG_FILLERDICT,
 
152
     -ctlfn => $listoffiles,
 
153
     -part => $part,
 
154
     -npart => $npart,
 
155
     -cepdir => $ST::CFG_FEATFILES_DIR,
 
156
     -cepext => $ST::CFG_FEATFILE_EXTENSION,
 
157
     -lsnfn => $transcriptfile,
 
158
     -accumdir => $output_buffer_dir,
 
159
     -varfloor => $minvar,
 
160
     -topn => $topn,
 
161
     -abeam => 1e-90,
 
162
     -bbeam => 1e-10,
 
163
     -agc => $ST::CFG_AGC,
 
164
     -cmn => $ST::CFG_CMN,
 
165
     -varnorm => $ST::CFG_VARNORM,
 
166
     -meanreest => "yes",
 
167
     -varreest => "yes",
 
168
     '-2passvar' => $var2pass,
 
169
     -tmatreest => "yes",
 
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",
 
176
     @feat_args,
 
177
     -timing => "no");
 
178
 
 
179
 
 
180
if ($return_value) {
 
181
  LogError("Failed to start bw");
 
182
}
 
183
exit ($return_value);