94 static void*
Run(
void *ptr_in) {
106 double *total_weight) {
120 if (examples->empty()) {
150 double *tot_weight_ptr,
151 double *tot_logprob_ptr) {
152 int64 num_egs_processed = 0;
153 double tot_weight = 0.0, tot_logprob = 0.0;
161 double tot_weight_this_phase = 0.0, tot_logprob_this_phase = 0.0;
165 std::vector<NnetExample> examples;
167 double minibatch_total_weight;
169 &minibatch_total_weight))
171 tot_logprob_this_phase +=
DoBackprop(*nnet, examples, &examples_formatted,
173 tot_weight_this_phase += minibatch_total_weight;
174 num_egs_processed += examples.size();
177 KALDI_LOG <<
"Training objective function (this phase) is " 178 << (tot_logprob_this_phase / tot_weight_this_phase) <<
" over " 179 << tot_weight_this_phase <<
" frames.";
181 tot_weight += tot_weight_this_phase;
182 tot_logprob += tot_logprob_this_phase;
189 if (tot_weight == 0.0) {
192 KALDI_LOG <<
"Did backprop on " << tot_weight
193 <<
" examples, average log-prob per frame is " 194 << (tot_logprob / tot_weight);
195 KALDI_LOG <<
"[this line is to be parsed by a script:] log-prob-per-frame=" 196 << (tot_logprob / tot_weight);
198 if (tot_weight_ptr) *tot_weight_ptr = tot_weight;
199 if (tot_logprob_ptr) *tot_logprob_ptr = tot_logprob;
200 return num_egs_processed;
bool GetNextMinibatch(std::vector< NnetExample > *examples, Matrix< BaseFloat > *formatted_examples, double *total_weight)
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
std::vector< NnetExample > examples_
Matrix< BaseFloat > formatted_examples_
static void * Run(void *ptr_in)
void Signal()
increase the counter
void Swap(Matrix< Real > *other)
Swaps the contents of *this and *other. Shallow swap.
double DoBackprop(const Nnet &nnet, const std::vector< NnetExample > &examples, Nnet *nnet_to_update, double *tot_accuracy)
This function computes the objective function and either updates the model or adds to parameter gradi...
~NnetExampleBackgroundReader()
void FormatNnetInput(const Nnet &nnet, const std::vector< NnetExample > &data, Matrix< BaseFloat > *input_mat)
Takes the input to the nnet for a minibatch of examples, and formats as a single matrix.
int64 TrainNnetSimple(const NnetSimpleTrainerConfig &config, Nnet *nnet, SequentialNnetExampleReader *reader, double *tot_weight_ptr, double *tot_logprob_ptr)
Train on all the examples it can read from the reader.
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Semaphore producer_semaphore_
SequentialNnetExampleReader * reader_
Semaphore consumer_semaphore_
BaseFloat TotalNnetTrainingWeight(const std::vector< NnetExample > &egs)
Returns the total weight summed over all the examples...
#define KALDI_ASSERT(cond)
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).
int32 minibatches_per_phase
void Wait()
decrease the counter
NnetExampleBackgroundReader(int32 minibatch_size, Nnet *nnet, SequentialNnetExampleReader *reader)