All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
NnetLogprobTask Struct Reference
Collaboration diagram for NnetLogprobTask:

Public Member Functions

 NnetLogprobTask (const AmNnet &am_nnet, const CuVector< BaseFloat > &inv_priors, const std::string &key, const CuMatrix< BaseFloat > &feats, BaseFloatCuMatrixWriter *logprob_writer)
 
void operator() ()
 
 ~NnetLogprobTask ()
 
 NnetLogprobTask (const AmNnet &am_nnet, const CuVector< BaseFloat > &inv_priors, const std::string &key, const Matrix< BaseFloat > &feats, BaseFloatMatrixWriter *prob_writer_nodiv, BaseFloatMatrixWriter *logprob_writer_divided)
 
void operator() ()
 
 ~NnetLogprobTask ()
 

Private Attributes

const AmNnetam_nnet_
 
const CuVector< BaseFloat > & inv_priors_
 
std::string key_
 
CuMatrix< BaseFloatfeats_
 
CuMatrix< BaseFloatlog_probs_
 
BaseFloatCuMatrixWriterlogprob_writer_
 
BaseFloatMatrixWriterprob_writer_nodiv_
 
BaseFloatMatrixWriterlogprob_writer_divided_
 

Detailed Description

Definition at line 31 of file nnet-logprob-parallel.cc.

Constructor & Destructor Documentation

NnetLogprobTask ( const AmNnet am_nnet,
const CuVector< BaseFloat > &  inv_priors,
const std::string &  key,
const CuMatrix< BaseFloat > &  feats,
BaseFloatCuMatrixWriter logprob_writer 
)
inline

Definition at line 32 of file nnet-logprob-parallel.cc.

36  :
37  am_nnet_(am_nnet), inv_priors_(inv_priors), key_(key), feats_(feats),
38  logprob_writer_(logprob_writer) { }
BaseFloatCuMatrixWriter * logprob_writer_
const CuVector< BaseFloat > & inv_priors_
~NnetLogprobTask ( )
inline

Definition at line 46 of file nnet-logprob-parallel.cc.

References CuMatrixBase< Real >::ApplyFloor(), CuMatrixBase< Real >::ApplyLog(), rnnlm::i, NnetLogprobTask::inv_priors_, KALDI_WARN, NnetLogprobTask::key_, NnetLogprobTask::log_probs_, NnetLogprobTask::logprob_writer_, CuMatrixBase< Real >::MulColsVec(), CuMatrixBase< Real >::NumRows(), CuVectorBase< Real >::Scale(), CuVectorBase< Real >::Sum(), and TableWriter< Holder >::Write().

46  { // Produces output. Run sequentially.
47  // at this point they are probabilities, not log-probs, without prior division.
48 
49  log_probs_.MulColsVec(inv_priors_); // scales each column by the corresponding element
50  // of inv_priors.
51  for (int32 i = 0; i < log_probs_.NumRows(); i++) {
53  BaseFloat p = frame.Sum();
54  if (!(p > 0.0)) {
55  KALDI_WARN << "Bad sum of probabilities " << p;
56  } else {
57  frame.Scale(1.0 / p); // re-normalize to sum to one.
58  }
59  }
60  log_probs_.ApplyFloor(1.0e-20); // To avoid log of zero which leads to NaN.
63  }
void Write(const std::string &key, const T &value) const
void MulColsVec(const CuVectorBase< Real > &scale)
scale i'th column by scale[i]
Definition: cu-matrix.cc:750
void ApplyFloor(Real floor_val)
Definition: cu-matrix.cc:2365
float BaseFloat
Definition: kaldi-types.h:29
MatrixIndexT NumRows() const
Dimensions.
Definition: cu-matrix.h:195
BaseFloatCuMatrixWriter * logprob_writer_
#define KALDI_WARN
Definition: kaldi-error.h:130
const CuVector< BaseFloat > & inv_priors_
NnetLogprobTask ( const AmNnet am_nnet,
const CuVector< BaseFloat > &  inv_priors,
const std::string &  key,
const Matrix< BaseFloat > &  feats,
BaseFloatMatrixWriter prob_writer_nodiv,
BaseFloatMatrixWriter logprob_writer_divided 
)
inline

Definition at line 32 of file nnet-logprob2-parallel.cc.

37  :
38  am_nnet_(am_nnet), inv_priors_(inv_priors), key_(key), feats_(feats),
39  prob_writer_nodiv_(prob_writer_nodiv),
40  logprob_writer_divided_(logprob_writer_divided) { }
BaseFloatMatrixWriter * logprob_writer_divided_
BaseFloatMatrixWriter * prob_writer_nodiv_
const CuVector< BaseFloat > & inv_priors_
~NnetLogprobTask ( )
inline

Definition at line 48 of file nnet-logprob2-parallel.cc.

References CuMatrixBase< Real >::ApplyFloor(), CuMatrixBase< Real >::ApplyLog(), rnnlm::i, NnetLogprobTask::inv_priors_, KALDI_WARN, NnetLogprobTask::key_, NnetLogprobTask::log_probs_, NnetLogprobTask::logprob_writer_divided_, CuMatrixBase< Real >::MulColsVec(), CuMatrixBase< Real >::NumRows(), NnetLogprobTask::prob_writer_nodiv_, CuVectorBase< Real >::Scale(), CuVectorBase< Real >::Sum(), and TableWriter< Holder >::Write().

48  { // Produces output. Run sequentially.
49  // at this point they are probabilities, not log-probs, without prior division.
51 
52  log_probs_.MulColsVec(inv_priors_); // scales each column by the corresponding element
53  // of inv_priors.
54  for (int32 i = 0; i < log_probs_.NumRows(); i++) {
56  BaseFloat p = frame.Sum();
57  if (!(p > 0.0)) {
58  KALDI_WARN << "Bad sum of probabilities " << p;
59  } else {
60  frame.Scale(1.0 / p); // re-normalize to sum to one.
61  }
62  }
63  log_probs_.ApplyFloor(1.0e-20); // To avoid log of zero which leads to NaN.
66  }
void Write(const std::string &key, const T &value) const
BaseFloatMatrixWriter * logprob_writer_divided_
void MulColsVec(const CuVectorBase< Real > &scale)
scale i'th column by scale[i]
Definition: cu-matrix.cc:750
BaseFloatMatrixWriter * prob_writer_nodiv_
void ApplyFloor(Real floor_val)
Definition: cu-matrix.cc:2365
float BaseFloat
Definition: kaldi-types.h:29
MatrixIndexT NumRows() const
Dimensions.
Definition: cu-matrix.h:195
#define KALDI_WARN
Definition: kaldi-error.h:130
const CuVector< BaseFloat > & inv_priors_

Member Function Documentation

void operator() ( )
inline

Definition at line 39 of file nnet-logprob-parallel.cc.

References NnetLogprobTask::am_nnet_, NnetLogprobTask::feats_, AmNnet::GetNnet(), NnetLogprobTask::log_probs_, kaldi::nnet2::NnetComputation(), AmNnet::NumPdfs(), CuMatrixBase< Real >::NumRows(), and CuMatrix< Real >::Resize().

39  {
41  bool pad_input = true;
42  NnetComputation(am_nnet_.GetNnet(), feats_, pad_input,
43  &log_probs_);
44  }
void Resize(MatrixIndexT rows, MatrixIndexT cols, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Allocate the memory.
Definition: cu-matrix.cc:47
MatrixIndexT NumRows() const
Dimensions.
Definition: cu-matrix.h:195
int32 NumPdfs() const
Definition: am-nnet.h:55
const Nnet & GetNnet() const
Definition: am-nnet.h:61
void NnetComputation(const Nnet &nnet, const CuMatrixBase< BaseFloat > &input, bool pad_input, CuMatrixBase< BaseFloat > *output)
Does the basic neural net computation, on a sequence of data (e.g.
void operator() ( )
inline

Definition at line 41 of file nnet-logprob2-parallel.cc.

References NnetLogprobTask::am_nnet_, NnetLogprobTask::feats_, AmNnet::GetNnet(), NnetLogprobTask::log_probs_, kaldi::nnet2::NnetComputation(), AmNnet::NumPdfs(), CuMatrixBase< Real >::NumRows(), and CuMatrix< Real >::Resize().

41  {
43  bool pad_input = true;
44  NnetComputation(am_nnet_.GetNnet(), feats_, pad_input,
45  &log_probs_);
46  }
void Resize(MatrixIndexT rows, MatrixIndexT cols, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Allocate the memory.
Definition: cu-matrix.cc:47
MatrixIndexT NumRows() const
Dimensions.
Definition: cu-matrix.h:195
int32 NumPdfs() const
Definition: am-nnet.h:55
const Nnet & GetNnet() const
Definition: am-nnet.h:61
void NnetComputation(const Nnet &nnet, const CuMatrixBase< BaseFloat > &input, bool pad_input, CuMatrixBase< BaseFloat > *output)
Does the basic neural net computation, on a sequence of data (e.g.

Member Data Documentation

const AmNnet & am_nnet_
private

Definition at line 66 of file nnet-logprob-parallel.cc.

Referenced by NnetLogprobTask::operator()().

CuMatrix< BaseFloat > feats_
private

Definition at line 69 of file nnet-logprob-parallel.cc.

Referenced by NnetLogprobTask::operator()().

const CuVector< BaseFloat > & inv_priors_
private

Definition at line 67 of file nnet-logprob-parallel.cc.

Referenced by NnetLogprobTask::~NnetLogprobTask().

std::string key_
private

Definition at line 68 of file nnet-logprob-parallel.cc.

Referenced by NnetLogprobTask::~NnetLogprobTask().

CuMatrix< BaseFloat > log_probs_
private
BaseFloatCuMatrixWriter* logprob_writer_
private

Definition at line 71 of file nnet-logprob-parallel.cc.

Referenced by NnetLogprobTask::~NnetLogprobTask().

BaseFloatMatrixWriter* logprob_writer_divided_
private

Definition at line 75 of file nnet-logprob2-parallel.cc.

Referenced by NnetLogprobTask::~NnetLogprobTask().

BaseFloatMatrixWriter* prob_writer_nodiv_
private

Definition at line 74 of file nnet-logprob2-parallel.cc.

Referenced by NnetLogprobTask::~NnetLogprobTask().


The documentation for this struct was generated from the following files: