decodable-am-sgmm2.h
Go to the documentation of this file.
1 // sgmm2/decodable-am-sgmm2.h
2 
3 // Copyright 2009-2012 Saarland University Microsoft Corporation
4 // Lukas Burget Johns Hopkins University (author: Daniel Povey)
5 
6 // See ../../COPYING for clarification regarding multiple authors
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 //
12 // http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 // MERCHANTABLITY OR NON-INFRINGEMENT.
18 // See the Apache 2 License for the specific language governing permissions and
19 // limitations under the License.
20 
21 #ifndef KALDI_SGMM2_DECODABLE_AM_SGMM2_H_
22 #define KALDI_SGMM2_DECODABLE_AM_SGMM2_H_
23 
24 #include <vector>
25 
26 #include "base/kaldi-common.h"
27 #include "sgmm2/am-sgmm2.h"
28 #include "hmm/transition-model.h"
29 #include "itf/decodable-itf.h"
30 
31 namespace kaldi {
32 
34  public:
36  const TransitionModel &tm,
37  const Matrix<BaseFloat> &feats,
38  const std::vector<std::vector<int32> > &gselect,
39  BaseFloat log_prune,
41  sgmm_(sgmm), spk_(spk),
42  trans_model_(tm), feature_matrix_(&feats),
43  gselect_(&gselect), log_prune_(log_prune), cur_frame_(-1),
44  sgmm_cache_(sgmm.NumGroups(), sgmm.NumPdfs()), delete_vars_(false) {
45  KALDI_ASSERT(gselect.size() == static_cast<size_t>(feats.NumRows()));
46  }
47 
51  const TransitionModel &tm,
52  const Matrix<BaseFloat> *feats,
53  const std::vector<std::vector<int32> > *gselect,
55  BaseFloat log_prune):
56  sgmm_(sgmm), spk_(spk),
57  trans_model_(tm), feature_matrix_(feats),
58  gselect_(gselect), log_prune_(log_prune), cur_frame_(-1),
59  sgmm_cache_(sgmm.NumGroups(), sgmm.NumPdfs()), delete_vars_(true) {
60  KALDI_ASSERT(gselect->size() == static_cast<size_t>(feats->NumRows()));
61  }
62 
63  // Note, frames are numbered from zero, but transition indices are 1-based!
64  // This is for compatibility with OpenFST.
65  virtual BaseFloat LogLikelihood(int32 frame, int32 tid) {
67  }
69  virtual int32 NumIndices() const { return trans_model_.NumTransitionIds(); }
70 
71  virtual bool IsLastFrame(int32 frame) const {
72  KALDI_ASSERT(frame < NumFramesReady());
73  return (frame == NumFramesReady() - 1);
74  }
75 
76  virtual ~DecodableAmSgmm2();
77  protected:
78  virtual BaseFloat LogLikelihoodForPdf(int32 frame, int32 pdf_id);
79 
80  const AmSgmm2 &sgmm_;
84  const std::vector<std::vector<int32> > *gselect_;
85 
87 
91 
92  bool delete_vars_; // If true, we will delete feature_matrix_, gselect_, and
93  // spk_ in the destructor.
94 
95  private:
97 };
98 
100  public:
102  const TransitionModel &tm,
103  const Matrix<BaseFloat> &feats,
104  const std::vector<std::vector<int32> > &gselect,
105  BaseFloat log_prune,
106  BaseFloat scale,
108  : DecodableAmSgmm2(sgmm, tm, feats, gselect, log_prune, spk),
109  scale_(scale) {}
110 
115  const TransitionModel &tm,
116  const Matrix<BaseFloat> *feats,
117  const std::vector<std::vector<int32> > *gselect,
119  BaseFloat log_prune,
120  BaseFloat scale)
121  : DecodableAmSgmm2(sgmm, tm, feats, gselect, spk, log_prune),
122  scale_(scale) {}
123 
124 
125  // Note, frames are numbered from zero but transition-ids from one.
126  virtual BaseFloat LogLikelihood(int32 frame, int32 tid) {
128  * scale_;
129  }
130  private:
133 };
134 
135 
136 } // namespace kaldi
137 
138 #endif // KALDI_SGMM2_DECODABLE_AM_SGMM2_H_
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
Class for definition of the subspace Gmm acoustic model.
Definition: am-sgmm2.h:231
DecodableInterface provides a link between the (acoustic-modeling and feature-processing) code and th...
Definition: decodable-itf.h:82
int32 NumFramesReady() const
The call NumFramesReady() will return the number of frames currently available for this decodable obj...
int32 TransitionIdToPdfFast(int32 trans_id) const
kaldi::int32 int32
virtual int32 NumIndices() const
Returns the number of states in the acoustic model (they will be indexed one-based, i.e.
const std::vector< std::vector< int32 > > * gselect_
Sgmm2PerSpkDerivedVars * spk_
Sgmm2LikelihoodCache sgmm_cache_
const TransitionModel & trans_model_
for tid to pdf mapping
Sgmm2PerFrameDerivedVars per_frame_vars_
const Matrix< BaseFloat > * feature_matrix_
virtual BaseFloat LogLikelihoodForPdf(int32 frame, int32 pdf_id)
int32 NumTransitionIds() const
Returns the total number of transition-ids (note, these are one-based).
virtual bool IsLastFrame(int32 frame) const
Returns true if this is the last frame.
virtual BaseFloat LogLikelihood(int32 frame, int32 tid)
Returns the log likelihood, which will be negated in the decoder.
DecodableAmSgmm2(const AmSgmm2 &sgmm, const TransitionModel &tm, const Matrix< BaseFloat > *feats, const std::vector< std::vector< int32 > > *gselect, Sgmm2PerSpkDerivedVars *spk, BaseFloat log_prune)
This version of the constructor takes ownership of the pointers "feats", "gselect" and "spk"...
virtual BaseFloat LogLikelihood(int32 frame, int32 tid)
Returns the log likelihood, which will be negated in the decoder.
KALDI_DISALLOW_COPY_AND_ASSIGN(DecodableAmSgmm2)
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
Sgmm2LikelihoodCache caches SGMM likelihoods at two levels: the final pdf likelihoods, and the sub-state level likelihoods, which means that with the SCTM system we can avoid redundant computation.
Definition: am-sgmm2.h:199
DecodableAmSgmm2(const AmSgmm2 &sgmm, const TransitionModel &tm, const Matrix< BaseFloat > &feats, const std::vector< std::vector< int32 > > &gselect, BaseFloat log_prune, Sgmm2PerSpkDerivedVars *spk)
DecodableAmSgmm2Scaled(const AmSgmm2 &sgmm, const TransitionModel &tm, const Matrix< BaseFloat > &feats, const std::vector< std::vector< int32 > > &gselect, BaseFloat log_prune, BaseFloat scale, Sgmm2PerSpkDerivedVars *spk)
Holds the per-frame precomputed quantities x(t), x_{i}(t), z_{i}(t), and n_{i}(t) (cf...
Definition: am-sgmm2.h:142
DecodableAmSgmm2Scaled(const AmSgmm2 &sgmm, const TransitionModel &tm, const Matrix< BaseFloat > *feats, const std::vector< std::vector< int32 > > *gselect, Sgmm2PerSpkDerivedVars *spk, BaseFloat log_prune, BaseFloat scale)
This version of the constructor takes ownership of the pointers "feats", "gselect" and "spk"...