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()

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 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:185

◆ ~DecodableAmNnetParallel()

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

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

Member Function Documentation

◆ Compute()

void Compute ( )
inline

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

References MatrixBase< Real >::AddVecToRows(), MatrixBase< Real >::ApplyFloor(), MatrixBase< Real >::ApplyLog(), KALDI_ASSERT, DecodableAmNnet::log_probs_, kaldi::nnet2::NnetComputation(), TransitionModel::NumPdfs(), Matrix< Real >::Resize(), MatrixBase< Real >::Scale(), and DecodableAmNnet::trans_model_.

118  {
119  log_probs_.Resize(feats_->NumRows(), trans_model_.NumPdfs());
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.
124  log_probs_.ApplyLog();
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.
132  log_probs_.Scale(prob_scale_);
133  delete feats_;
134  feats_ = NULL;
135  }
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.
const CuMatrix< BaseFloat > * feats_
const VectorBase< BaseFloat > & Priors() const
Definition: am-nnet.h:67
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
const Nnet & GetNnet() const
Definition: am-nnet.h:61

◆ IsLastFrame()

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 DecodableAmNnet::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:185

◆ KALDI_DISALLOW_COPY_AND_ASSIGN()

KALDI_DISALLOW_COPY_AND_ASSIGN ( DecodableAmNnetParallel  )
protected

◆ LogLikelihood()

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 NumFramesReady() > frame before calling this.

Implements DecodableInterface.

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

References DecodableAmNnet::log_probs_, DecodableAmNnet::trans_model_, and TransitionModel::TransitionIdToPdfFast().

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

◆ NumFramesReady()

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 DecodableAmNnet::log_probs_, and MatrixBase< Real >::NumRows().

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  }
int32 LeftContext() const
Returns the left-context summed over all the Components...
Definition: nnet-nnet.cc:42
kaldi::int32 int32
const CuMatrix< BaseFloat > * feats_
int32 RightContext() const
Returns the right-context summed over all the Components...
Definition: nnet-nnet.cc:56
const Nnet & GetNnet() const
Definition: am-nnet.h:61

◆ NumIndices()

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 DecodableAmNnet::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

◆ am_nnet_

const AmNnet& am_nnet_
protected

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

◆ feats_

const CuMatrix<BaseFloat>* feats_
protected

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

◆ log_probs_

CuMatrix<BaseFloat> log_probs_
protected

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

◆ pad_input_

bool pad_input_
protected

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

◆ prob_scale_

BaseFloat prob_scale_
protected

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

◆ trans_model_

const TransitionModel& trans_model_
protected

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


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