DecodableAmNnetSimpleParallel Class Reference

#include <nnet-am-decodable-simple.h>

Inheritance diagram for DecodableAmNnetSimpleParallel:
Collaboration diagram for DecodableAmNnetSimpleParallel:

Public Member Functions

 DecodableAmNnetSimpleParallel (const NnetSimpleComputationOptions &opts, const TransitionModel &trans_model, const AmNnetSimple &am_nnet, const MatrixBase< BaseFloat > &feats, const VectorBase< BaseFloat > *ivector=NULL, const MatrixBase< BaseFloat > *online_ivectors=NULL, int32 online_ivector_period=1)
 This decodable object is for use in multi-threaded decoding. More...
virtual BaseFloat LogLikelihood (int32 frame, int32 transition_id)
 Returns the log likelihood, which will be negated in the decoder. More...
virtual 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...
 ~DecodableAmNnetSimpleParallel ()
- Public Member Functions inherited from DecodableInterface
virtual ~DecodableInterface ()

Private Member Functions

 KALDI_DISALLOW_COPY_AND_ASSIGN (DecodableAmNnetSimpleParallel)
void DeletePointers ()

Private Attributes

CachingOptimizingCompiler compiler_
const TransitionModeltrans_model_
Matrix< BaseFloat > * feats_copy_
Vector< BaseFloat > * ivector_copy_
Matrix< BaseFloat > * online_ivectors_copy_

Detailed Description

Definition at line 351 of file nnet-am-decodable-simple.h.

Constructor & Destructor Documentation

◆ DecodableAmNnetSimpleParallel()

DecodableAmNnetSimpleParallel ( const NnetSimpleComputationOptions opts,
const TransitionModel trans_model,
const AmNnetSimple am_nnet,
const MatrixBase< BaseFloat > &  feats,
const VectorBase< BaseFloat > *  ivector = NULL,
const MatrixBase< BaseFloat > *  online_ivectors = NULL,
int32  online_ivector_period = 1 

This decodable object is for use in multi-threaded decoding.

It differs from DecodableAmNnetSimple in two respects: (1) It doesn't keep around pointers to the features and iVectors; instead, it creates copies of them (so the caller can delete the originals). (2) It doesn't support the user passing in a pointer to the CachingOptimizingCompiler– because making that thread safe would be quite complicated, and in any case multi-threaded decoding probably makes the most sense when using CPU, and in that case we don't expect the compilation phase to dominate.

This constructor takes features as input, and you can either supply a single iVector input, estimated in batch-mode ('ivector'), or 'online' iVectors ('online_ivectors' and 'online_ivector_period', or none at all. Note: it stores references to all arguments to the constructor, so don't delete them till this goes out of scope.

[in]optsThe options class. Warning: it includes an acoustic weight, whose default is 0.1; you may sometimes want to change this to 1.0.
[in]trans_modelThe transition model to use. This takes care of the mapping from transition-id (which is an arg to LogLikelihood()) to pdf-id (which is used internally).
[in]am_nnetThe neural net that we're going to do the computation with; it may provide priors to divide by.
[in]featsA pointer to the input feature matrix; must be non-NULL.
[in]ivectorIf you are using iVectors estimated in batch mode, a pointer to the iVector, else NULL.
[in]online_ivectorsIf you are using iVectors estimated 'online' a pointer to the iVectors, else NULL.
[in]online_ivector_periodIf you are using iVectors estimated 'online' (i.e. if online_ivectors != NULL) gives the periodicity (in frames) with which the iVectors are estimated.

Definition at line 313 of file

References DecodableAmNnetSimpleParallel::compiler_, DecodableAmNnetSimpleParallel::decodable_nnet_, DecodableAmNnetSimpleParallel::DeletePointers(), DecodableAmNnetSimpleParallel::feats_copy_, AmNnetSimple::GetNnet(), DecodableAmNnetSimpleParallel::ivector_copy_, KALDI_ERR, DecodableAmNnetSimpleParallel::online_ivectors_copy_, and AmNnetSimple::Priors().

320  :
321  compiler_(am_nnet.GetNnet(), opts.optimize_config, opts.compiler_config),
322  trans_model_(trans_model),
323  feats_copy_(NULL),
324  ivector_copy_(NULL),
325  online_ivectors_copy_(NULL),
326  decodable_nnet_(NULL) {
327  try {
328  feats_copy_ = new Matrix<BaseFloat>(feats);
329  if (ivector != NULL)
330  ivector_copy_ = new Vector<BaseFloat>(*ivector);
331  if (online_ivectors != NULL)
332  online_ivectors_copy_ = new Matrix<BaseFloat>(*online_ivectors);
333  decodable_nnet_ = new DecodableNnetSimple(opts, am_nnet.GetNnet(),
334  am_nnet.Priors(), *feats_copy_,
337  online_ivector_period);
339  } catch (...) {
340  DeletePointers();
341  KALDI_ERR << "Error occurred in constructor (see above)";
342  }
343 }
#define KALDI_ERR
Definition: kaldi-error.h:147

◆ ~DecodableAmNnetSimpleParallel()

Member Function Documentation

◆ DeletePointers()

void DeletePointers ( )

◆ IsLastFrame()

virtual bool IsLastFrame ( int32  frame) const

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 407 of file nnet-am-decodable-simple.h.

References KALDI_ASSERT.

407  {
408  KALDI_ASSERT(frame < NumFramesReady());
409  return (frame == NumFramesReady() - 1);
410  }
virtual 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 ( DecodableAmNnetSimpleParallel  )

◆ LogLikelihood()

BaseFloat LogLikelihood ( int32  frame,
int32  index 

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 358 of file

References DecodableAmNnetSimpleParallel::decodable_nnet_, DecodableNnetSimple::GetOutput(), DecodableAmNnetSimpleParallel::trans_model_, and TransitionModel::TransitionIdToPdfFast().

359  {
360  int32 pdf_id = trans_model_.TransitionIdToPdfFast(transition_id);
361  return decodable_nnet_->GetOutput(frame, pdf_id);
362 }
int32 TransitionIdToPdfFast(int32 trans_id) const
kaldi::int32 int32
BaseFloat GetOutput(int32 subsampled_frame, int32 pdf_id)

◆ NumFramesReady()

virtual int32 NumFramesReady ( ) const

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 401 of file nnet-am-decodable-simple.h.

◆ NumIndices()

virtual int32 NumIndices ( ) const

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 405 of file nnet-am-decodable-simple.h.

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

Member Data Documentation

◆ compiler_

◆ decodable_nnet_

◆ feats_copy_

◆ ivector_copy_

◆ online_ivectors_copy_

◆ trans_model_

const TransitionModel& trans_model_

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