All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DecodableAmNnetParallel Class Reference

This version of DecodableAmNnet is intended for a version of the decoder that processes different utterances with multiple threads. More...

#include <decodable-am-nnet.h>

Inheritance diagram for DecodableAmNnetParallel:
Collaboration diagram for DecodableAmNnetParallel:

Public Member Functions

 DecodableAmNnetParallel (const TransitionModel &trans_model, const AmNnet &am_nnet, const CuMatrix< BaseFloat > *feats, bool pad_input=true, BaseFloat prob_scale=1.0)
 
void Compute ()
 
virtual BaseFloat LogLikelihood (int32 frame, int32 transition_id)
 Returns the log likelihood, which will be negated in the decoder. More...
 
int32 NumFramesReady () const
 The call NumFramesReady() will return the number of frames currently available for this decodable object. More...
 
virtual int32 NumIndices () const
 Returns the number of states in the acoustic model (they will be indexed one-based, i.e. More...
 
virtual bool IsLastFrame (int32 frame) const
 Returns true if this is the last frame. More...
 
 ~DecodableAmNnetParallel ()
 
- Public Member Functions inherited from DecodableInterface
virtual ~DecodableInterface ()
 

Protected Member Functions

 KALDI_DISALLOW_COPY_AND_ASSIGN (DecodableAmNnetParallel)
 

Protected Attributes

const TransitionModeltrans_model_
 
const AmNnetam_nnet_
 
CuMatrix< BaseFloatlog_probs_
 
const CuMatrix< BaseFloat > * feats_
 
bool pad_input_
 
BaseFloat prob_scale_
 

Detailed Description

This version of DecodableAmNnet is intended for a version of the decoder that processes different utterances with multiple threads.

It needs to do the computation in a different place than the initializer, since the initializer gets called in the main thread of the program.

Definition at line 105 of file decodable-am-nnet.h.

Constructor & Destructor Documentation

DecodableAmNnetParallel ( const TransitionModel trans_model,
const AmNnet am_nnet,
const CuMatrix< BaseFloat > *  feats,
bool  pad_input = true,
BaseFloat  prob_scale = 1.0 
)
inline

Definition at line 107 of file decodable-am-nnet.h.

References DecodableAmNnetParallel::feats_, and KALDI_ASSERT.

112  :
113  trans_model_(trans_model), am_nnet_(am_nnet), feats_(feats),
114  pad_input_(pad_input), prob_scale_(prob_scale) {
115  KALDI_ASSERT(feats_ != NULL);
116  }
const CuMatrix< BaseFloat > * feats_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169

Definition at line 166 of file decodable-am-nnet.h.

References DecodableAmNnetParallel::feats_.

166  {
167  delete feats_;
168  }
const CuMatrix< BaseFloat > * feats_

Member Function Documentation

void Compute ( )
inline

Definition at line 118 of file decodable-am-nnet.h.

References CuMatrixBase< Real >::AddVecToRows(), DecodableAmNnetParallel::am_nnet_, CuMatrixBase< Real >::ApplyFloor(), CuMatrixBase< Real >::ApplyLog(), DecodableAmNnetParallel::feats_, AmNnet::GetNnet(), KALDI_ASSERT, DecodableAmNnetParallel::log_probs_, kaldi::nnet2::NnetComputation(), TransitionModel::NumPdfs(), CuMatrixBase< Real >::NumRows(), DecodableAmNnetParallel::pad_input_, AmNnet::Priors(), DecodableAmNnetParallel::prob_scale_, CuMatrix< Real >::Resize(), CuMatrixBase< Real >::Scale(), and DecodableAmNnetParallel::trans_model_.

Referenced by DecodableAmNnetParallel::LogLikelihood().

118  {
120  // the following function is declared in nnet-compute.h
123  log_probs_.ApplyFloor(1.0e-20); // Avoid log of zero which leads to NaN.
125  CuVector<BaseFloat> priors(am_nnet_.Priors());
126  KALDI_ASSERT(priors.Dim() == trans_model_.NumPdfs() &&
127  "Priors in neural network not set up.");
128  priors.ApplyLog();
129  // subtract log-prior (divide by prior)
130  log_probs_.AddVecToRows(-1.0, priors);
131  // apply probability scale.
133  delete feats_;
134  feats_ = NULL;
135  }
void AddVecToRows(Real alpha, const CuVectorBase< Real > &row, Real beta=1.0)
(for each row r of *this), r = alpha * row + beta * r
Definition: cu-matrix.cc:1111
void Scale(Real value)
Definition: cu-matrix.cc:608
const CuMatrix< BaseFloat > * feats_
void ApplyFloor(Real floor_val)
Definition: cu-matrix.cc:2365
const VectorBase< BaseFloat > & Priors() const
Definition: am-nnet.h:67
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
const Nnet & GetNnet() const
Definition: am-nnet.h:61
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
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.
virtual bool IsLastFrame ( int32  frame) const
inlinevirtual

Returns true if this is the last frame.

Frames are zero-based, so the first frame is zero. IsLastFrame(-1) will return false, unless the file is empty (which is a case that I'm not sure all the code will handle, so be careful). Caution: the behavior of this function in an online setting is being changed somewhat. In future it may return false in cases where we haven't yet decided to terminate decoding, but later true if we decide to terminate decoding. The plan in future is to rely more on NumFramesReady(), and in future, IsLastFrame() would always return false in an online-decoding setting, and would only return true in a decoding-from-matrix setting where we want to allow the last delta or LDA features to be flushed out for compatibility with the baseline setup.

Implements DecodableInterface.

Definition at line 162 of file decodable-am-nnet.h.

References KALDI_ASSERT, and DecodableAmNnetParallel::NumFramesReady().

162  {
163  KALDI_ASSERT(frame < NumFramesReady());
164  return (frame == NumFramesReady() - 1);
165  }
int32 NumFramesReady() const
The call NumFramesReady() will return the number of frames currently available for this decodable obj...
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
KALDI_DISALLOW_COPY_AND_ASSIGN ( DecodableAmNnetParallel  )
protected
virtual BaseFloat LogLikelihood ( int32  frame,
int32  index 
)
inlinevirtual

Returns the log likelihood, which will be negated in the decoder.

The "frame" starts from zero. You should verify that IsLastFrame(frame-1) returns false before calling this.

Implements DecodableInterface.

Definition at line 139 of file decodable-am-nnet.h.

References DecodableAmNnetParallel::Compute(), DecodableAmNnetParallel::feats_, DecodableAmNnetParallel::log_probs_, DecodableAmNnetParallel::trans_model_, and TransitionModel::TransitionIdToPdf().

139  {
140  if (feats_) Compute(); // this function sets feats_ to NULL.
141  return log_probs_(frame,
142  trans_model_.TransitionIdToPdf(transition_id));
143  }
int32 TransitionIdToPdf(int32 trans_id) const
const CuMatrix< BaseFloat > * feats_
int32 NumFramesReady ( ) const
inlinevirtual

The call NumFramesReady() will return the number of frames currently available for this decodable object.

This is for use in setups where you don't want the decoder to block while waiting for input. This is newly added as of Jan 2014, and I hope, going forward, to rely on this mechanism more than IsLastFrame to know when to stop decoding.

Reimplemented from DecodableInterface.

Definition at line 145 of file decodable-am-nnet.h.

References DecodableAmNnetParallel::am_nnet_, DecodableAmNnetParallel::feats_, AmNnet::GetNnet(), Nnet::LeftContext(), DecodableAmNnetParallel::log_probs_, CuMatrixBase< Real >::NumRows(), DecodableAmNnetParallel::pad_input_, and Nnet::RightContext().

Referenced by DecodableAmNnetParallel::IsLastFrame().

145  {
146  if (feats_) {
147  if (pad_input_) return feats_->NumRows();
148  else {
149  int32 ans = feats_->NumRows() - am_nnet_.GetNnet().LeftContext() -
151  if (ans < 0) ans = 0;
152  return ans;
153  }
154  } else {
155  return log_probs_.NumRows();
156  }
157  }
const CuMatrix< BaseFloat > * feats_
int32 LeftContext() const
Returns the left-context summed over all the Components...
Definition: nnet-nnet.cc:42
MatrixIndexT NumRows() const
Dimensions.
Definition: cu-matrix.h:195
const Nnet & GetNnet() const
Definition: am-nnet.h:61
int32 RightContext() const
Returns the right-context summed over all the Components...
Definition: nnet-nnet.cc:56
virtual int32 NumIndices ( ) const
inlinevirtual

Returns the number of states in the acoustic model (they will be indexed one-based, i.e.

from 1 to NumIndices(); this is for compatibility with OpenFst).

Implements DecodableInterface.

Definition at line 160 of file decodable-am-nnet.h.

References TransitionModel::NumTransitionIds(), and DecodableAmNnetParallel::trans_model_.

160 { return trans_model_.NumTransitionIds(); }
int32 NumTransitionIds() const
Returns the total number of transition-ids (note, these are one-based).

Member Data Documentation

const AmNnet& am_nnet_
protected
bool pad_input_
protected
BaseFloat prob_scale_
protected

Definition at line 176 of file decodable-am-nnet.h.

Referenced by DecodableAmNnetParallel::Compute().


The documentation for this class was generated from the following file: