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

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

Inheritance diagram for DecodableAmNnetSimple:
Collaboration diagram for DecodableAmNnetSimple:

Public Member Functions

 DecodableAmNnetSimple (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, CachingOptimizingCompiler *compiler=NULL)
 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. 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...
 
- Public Member Functions inherited from DecodableInterface
virtual ~DecodableInterface ()
 

Private Member Functions

 KALDI_DISALLOW_COPY_AND_ASSIGN (DecodableAmNnetSimple)
 

Private Attributes

CachingOptimizingCompiler compiler_
 
DecodableNnetSimple decodable_nnet_
 
const TransitionModeltrans_model_
 

Detailed Description

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

Constructor & Destructor Documentation

DecodableAmNnetSimple ( 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,
CachingOptimizingCompiler compiler = NULL 
)

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.

Parameters
[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; we also get the priors to divide by, if applicable, from here.
[in]featsA pointer to the input feature matrix; must be non-NULL. We
[in]ivectorIf you are using iVectors estimated in batch mode, a pointer to the iVector, else 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.
[in,out]compilerA pointer to a compiler [optional]– the user can declare one in the calling code and repeatedly supply pointers to it, which allows for caching of computations across consecutive decodes. You'd want to have initialized the compiler object with as compiler(am_nnet.GetNnet(), opts.optimize_config).

Definition at line 58 of file nnet-am-decodable-simple.cc.

66  :
67  compiler_(am_nnet.GetNnet(), opts.optimize_config, opts.compiler_config),
68  decodable_nnet_(opts, am_nnet.GetNnet(), am_nnet.Priors(),
69  feats, compiler != NULL ? compiler : &compiler_,
70  ivector, online_ivectors,
71  online_ivector_period),
72  trans_model_(trans_model) {
73  // note: we only use compiler_ if the passed-in 'compiler' is NULL.
74 }

Member Function Documentation

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

References KALDI_ASSERT, and DecodableAmNnetSimple::NumFramesReady().

302  {
303  KALDI_ASSERT(frame < NumFramesReady());
304  return (frame == NumFramesReady() - 1);
305  }
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:169
KALDI_DISALLOW_COPY_AND_ASSIGN ( DecodableAmNnetSimple  )
private
BaseFloat LogLikelihood ( int32  frame,
int32  index 
)
virtual

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 78 of file nnet-am-decodable-simple.cc.

References DecodableAmNnetSimple::decodable_nnet_, DecodableNnetSimple::GetOutput(), DecodableAmNnetSimple::trans_model_, and TransitionModel::TransitionIdToPdf().

79  {
80  int32 pdf_id = trans_model_.TransitionIdToPdf(transition_id);
81  return decodable_nnet_.GetOutput(frame, pdf_id);
82 }
int32 TransitionIdToPdf(int32 trans_id) const
BaseFloat GetOutput(int32 subsampled_frame, int32 pdf_id)
virtual 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 296 of file nnet-am-decodable-simple.h.

References DecodableAmNnetSimple::decodable_nnet_, and DecodableNnetSimple::NumFrames().

Referenced by DecodableAmNnetSimple::IsLastFrame(), and main().

296  {
297  return decodable_nnet_.NumFrames();
298  }
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 300 of file nnet-am-decodable-simple.h.

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

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

Member Data Documentation

CachingOptimizingCompiler compiler_
private

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

const TransitionModel& trans_model_
private

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