DecodableMatrixMapped Class Reference

This is like DecodableMatrixScaledMapped, but it doesn't support an acoustic scale, and it does support a frame offset, whereby you can state that the first row of 'likes' is actually the n'th row of the matrix of available log-likelihoods. More...

#include <decodable-matrix.h>

Inheritance diagram for DecodableMatrixMapped:
Collaboration diagram for DecodableMatrixMapped:

Public Member Functions

 DecodableMatrixMapped (const TransitionModel &tm, const MatrixBase< BaseFloat > &likes, int32 frame_offset=0)
 
 DecodableMatrixMapped (const TransitionModel &tm, const Matrix< BaseFloat > *likes, int32 frame_offset=0)
 
virtual int32 NumFramesReady () const
 The call NumFramesReady() will return the number of frames currently available for this decodable object. More...
 
virtual bool IsLastFrame (int32 frame) const
 Returns true if this is the last frame. More...
 
virtual BaseFloat LogLikelihood (int32 frame, int32 tid)
 Returns the log likelihood, which will be negated in the decoder. More...
 
virtual int32 NumIndices () const
 Returns the number of states in the acoustic model (they will be indexed one-based, i.e. More...
 
virtual ~DecodableMatrixMapped ()
 
- Public Member Functions inherited from DecodableInterface
virtual ~DecodableInterface ()
 

Private Member Functions

 KALDI_DISALLOW_COPY_AND_ASSIGN (DecodableMatrixMapped)
 

Private Attributes

const TransitionModeltrans_model_
 
const MatrixBase< BaseFloat > * likes_
 
const Matrix< BaseFloat > * likes_to_delete_
 
int32 frame_offset_
 
const BaseFloatraw_data_
 
int32 stride_
 

Detailed Description

This is like DecodableMatrixScaledMapped, but it doesn't support an acoustic scale, and it does support a frame offset, whereby you can state that the first row of 'likes' is actually the n'th row of the matrix of available log-likelihoods.

It's useful if the neural net output comes in chunks for different frame ranges.

Note: DecodableMatrixMappedOffset solves the same problem in a slightly different way, where you use the same decodable object. This one, unlike DecodableMatrixMappedOffset, is compatible with when the loglikes are in a SubMatrix.

Definition at line 98 of file decodable-matrix.h.

Constructor & Destructor Documentation

◆ DecodableMatrixMapped() [1/2]

DecodableMatrixMapped ( const TransitionModel tm,
const MatrixBase< BaseFloat > &  likes,
int32  frame_offset = 0 
)

Definition at line 24 of file decodable-matrix.cc.

References MatrixBase< Real >::Data(), KALDI_ERR, MatrixBase< Real >::NumCols(), TransitionModel::NumPdfs(), DecodableMatrixMapped::raw_data_, MatrixBase< Real >::Stride(), and DecodableMatrixMapped::stride_.

27  :
28  trans_model_(tm), likes_(&likes), likes_to_delete_(NULL),
29  frame_offset_(frame_offset) {
30  stride_ = likes.Stride();
31  raw_data_ = likes.Data() - (stride_ * frame_offset);
32 
33  if (likes.NumCols() != tm.NumPdfs())
34  KALDI_ERR << "Mismatch, matrix has "
35  << likes.NumCols() << " cols but transition-model has "
36  << tm.NumPdfs() << " pdf-ids.";
37 }
const TransitionModel & trans_model_
const Matrix< BaseFloat > * likes_to_delete_
#define KALDI_ERR
Definition: kaldi-error.h:147
const MatrixBase< BaseFloat > * likes_

◆ DecodableMatrixMapped() [2/2]

DecodableMatrixMapped ( const TransitionModel tm,
const Matrix< BaseFloat > *  likes,
int32  frame_offset = 0 
)

Definition at line 39 of file decodable-matrix.cc.

References MatrixBase< Real >::Data(), DecodableMatrixMapped::frame_offset_, KALDI_ERR, MatrixBase< Real >::NumCols(), TransitionModel::NumPdfs(), DecodableMatrixMapped::raw_data_, MatrixBase< Real >::Stride(), and DecodableMatrixMapped::stride_.

41  :
42  trans_model_(tm), likes_(likes), likes_to_delete_(likes),
43  frame_offset_(frame_offset) {
44  stride_ = likes->Stride();
45  raw_data_ = likes->Data() - (stride_ * frame_offset_);
46  if (likes->NumCols() != tm.NumPdfs())
47  KALDI_ERR << "Mismatch, matrix has "
48  << likes->NumCols() << " cols but transition-model has "
49  << tm.NumPdfs() << " pdf-ids.";
50 }
const TransitionModel & trans_model_
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
const Real * Data() const
Gives pointer to raw data (const).
Definition: kaldi-matrix.h:79
const Matrix< BaseFloat > * likes_to_delete_
MatrixIndexT Stride() const
Stride (distance in memory between each row). Will be >= NumCols.
Definition: kaldi-matrix.h:70
#define KALDI_ERR
Definition: kaldi-error.h:147
const MatrixBase< BaseFloat > * likes_

◆ ~DecodableMatrixMapped()

~DecodableMatrixMapped ( )
virtual

Definition at line 76 of file decodable-matrix.cc.

References DecodableMatrixMapped::likes_to_delete_.

76  {
77  delete likes_to_delete_;
78 }
const Matrix< BaseFloat > * likes_to_delete_

Member Function Documentation

◆ IsLastFrame()

bool IsLastFrame ( int32  frame) const
virtual

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 66 of file decodable-matrix.cc.

References KALDI_ASSERT, and DecodableMatrixMapped::NumFramesReady().

66  {
67  KALDI_ASSERT(frame < NumFramesReady());
68  return (frame == NumFramesReady() - 1);
69 }
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()

KALDI_DISALLOW_COPY_AND_ASSIGN ( DecodableMatrixMapped  )
private

◆ LogLikelihood()

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

Implements DecodableInterface.

Definition at line 53 of file decodable-matrix.cc.

References DecodableMatrixMapped::frame_offset_, DecodableMatrixMapped::likes_, DecodableMatrixMapped::raw_data_, DecodableMatrixMapped::stride_, DecodableMatrixMapped::trans_model_, and TransitionModel::TransitionIdToPdfFast().

53  {
55 #ifdef KALDI_PARANOID
56  return (*likes_)(frame - frame_offset_, pdf_id);
57 #else
58  return raw_data_[frame * stride_ + pdf_id];
59 #endif
60 }
const TransitionModel & trans_model_
int32 TransitionIdToPdfFast(int32 trans_id) const
kaldi::int32 int32
const MatrixBase< BaseFloat > * likes_

◆ NumFramesReady()

int32 NumFramesReady ( ) const
virtual

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 62 of file decodable-matrix.cc.

References DecodableMatrixMapped::frame_offset_, and DecodableMatrixMapped::likes_.

Referenced by DecodableMatrixMapped::IsLastFrame().

62  {
63  return frame_offset_ + likes_->NumRows();
64 }
const MatrixBase< BaseFloat > * likes_

◆ NumIndices()

int32 NumIndices ( ) const
virtual

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 72 of file decodable-matrix.cc.

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

72  {
74 }
const TransitionModel & trans_model_
int32 NumTransitionIds() const
Returns the total number of transition-ids (note, these are one-based).

Member Data Documentation

◆ frame_offset_

◆ likes_

const MatrixBase<BaseFloat>* likes_
private

◆ likes_to_delete_

const Matrix<BaseFloat>* likes_to_delete_
private

Definition at line 127 of file decodable-matrix.h.

Referenced by DecodableMatrixMapped::~DecodableMatrixMapped().

◆ raw_data_

◆ stride_

◆ trans_model_


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