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
## Modified: Rita Singh, 27 Nov 2000
38
## Author: Ricky Houghton
44
use File::Spec::Functions;
47
use lib catdir(dirname($0), updir(), 'lib');
48
use SphinxTrain::Config;
49
use SphinxTrain::Util;
51
#*******************************************************************
52
#*******************************************************************
53
$| = 1; # Turn on autoflushing
55
die "USAGE: $0 <iter> <n_parts>" if (@ARGV != 2);
57
my ($iter, $n_parts) = @ARGV;
59
my $processname="02.mllt_train";
61
my $logdir ="$ST::CFG_LOG_DIR/$processname";
63
my $log = "$logdir/${ST::CFG_EXPTNAME}.$iter.norm.log";
65
# Check the number and list of parts done. Compute avg likelihood per frame
66
my $num_done = 0; my $tot_lkhd = 0; my $tot_frms = 0;
68
for (my $i=1;$i<=$n_parts;$i++){
70
my $input_log = "${logdir}/${ST::CFG_EXPTNAME}.${iter}-${i}.bw.log";
71
next if (! -s $input_log);
74
if (/.*(Counts saved to).*/) {
78
if (/.*(overall>).*/){
79
my (undef, undef, $nfrms, undef, undef, $lkhd) = split(/ /);
80
$tot_lkhd = $tot_lkhd + $lkhd;
81
$tot_frms = $tot_frms + $nfrms;
87
if ($num_done != $n_parts) {
88
print OUTPUT "Only $num_done parts of $n_parts of Baum Welch were successfully completed\n";
89
my $errmsg = "Parts ";
90
for (my $i=1;$i<=$n_parts;$i++) {
91
$errmsg .= "$i " if ($done[$i] == 0);
93
$errmsg .= "failed to run!\n";
95
print OUTPUT "Only $num_done parts of $n_parts of Baum Welch were successfully completed\n";
98
LogError("Only $num_done parts of $n_parts of Baum Welch were successfully completed");
103
if ($tot_frms == 0) {
105
print OUTPUT "Baum welch ran successfully for only 0 frames! Aborting..\n";
110
my $lkhd_per_frame = $tot_lkhd/$tot_frms;
112
my $previter = $iter - 1;
113
my $prev_norm = "${logdir}/${ST::CFG_EXPTNAME}.${previter}.norm.log";
114
if (! -s $prev_norm) {
115
# Either iter == 1 or we are starting from an intermediate iter value
116
RunScript('norm.pl', $iter);
117
open OUTPUT, ">> $log";
118
print OUTPUT "Current Overall Likelihood Per Frame = $lkhd_per_frame\n";
120
Launch_BW($iter, $iter + 1);
124
# Find the likelihood from the previous iteration
125
open LOG, $prev_norm; my $prevlkhd = -99999999;
127
if (/.*(Current Overall Likelihood Per Frame).*/){
128
(undef,undef,undef,undef,undef,undef,$prevlkhd) = split(/ /);
133
if ($prevlkhd == -99999999) {
134
# Some error with previous norm.log. Continue Baum Welch
135
RunScript('norm.pl', $iter);
136
open OUTPUT, ">> $log";
137
print OUTPUT "Current Overall Likelihood Per Frame = $lkhd_per_frame\n";
139
Launch_BW($iter, $iter + 1);
144
if ($prevlkhd == 0) {
146
$convg_ratio = 1 if ($lkhd_per_frame > 0);
147
$convg_ratio = -1 if ($lkhd_per_frame < 0);
150
$convg_ratio = $lkhd_per_frame - $prevlkhd;
152
RunScript('norm.pl', $iter);
154
open OUTPUT, ">> $log";
155
print OUTPUT "Current Overall Likelihood Per Frame = $lkhd_per_frame\n";
156
if (defined($convg_ratio)) {
157
print OUTPUT "Convergence ratio = $convg_ratio\n";
160
if ($convg_ratio < 0) {
161
print OUTPUT "*WARNING*: NEGATIVE CONVERGENCE RATIO! CHECK YOUR DATA AND TRASNCRIPTS\n";
162
LogWarning("*WARNING*: NEGATIVE CONVERGENCE RATIO AT ITER ${iter}! CHECK BW AND NORM LOGFILES");
165
if ($convg_ratio > $ST::CFG_CONVERGENCE_RATIO && $iter >= $ST::CFG_MAX_ITERATIONS) {
166
open OUTPUT, ">> $log";
167
print OUTPUT "Maximum desired iterations $ST::CFG_MAX_ITERATIONS performed. Terminating training iteration\n";
168
my $date = localtime;
169
print OUTPUT "$date\n";
170
Log("Maximum desired iterations $ST::CFG_MAX_ITERATIONS performed. Terminating CI training for MLLT",
173
# Do the last iteration
174
Launch_BW($iter, 'N');
178
if ($convg_ratio > $ST::CFG_CONVERGENCE_RATIO or $iter < $ST::CFG_MIN_ITERATIONS) {
179
Launch_BW($iter, $iter + 1);
183
Log("Current Overall Likelihood Per Frame = $lkhd_per_frame", 'result');
184
open OUTPUT, ">> $log";
185
print OUTPUT "Likelihoods have converged! CI training for MLLT completed\!\n";
186
my $date = localtime;
187
print OUTPUT "$date\n";
189
# Do the last iteration
190
Launch_BW($iter, 'N');
195
my ($iter, $newiter) = @_;
196
Log("Current Overall Likelihood Per Frame = $lkhd_per_frame", 'result');
197
Log("Convergence Ratio = $convg_ratio", 'result') if defined $convg_ratio;
198
RunScript('slave_mllt.pl', $newiter, $n_parts);