OnlineIvectorFeature Class Reference

OnlineIvectorFeature is an online feature-extraction class that's responsible for extracting iVectors from raw features such as MFCC, PLP or filterbank. More...

#include <online-ivector-feature.h>

Inheritance diagram for OnlineIvectorFeature:
Collaboration diagram for OnlineIvectorFeature:

Public Member Functions

 OnlineIvectorFeature (const OnlineIvectorExtractionInfo &info, OnlineFeatureInterface *base_feature)
 Constructor. More...
 
virtual int32 Dim () const
 Dim() will return the iVector dimension. More...
 
virtual bool IsLastFrame (int32 frame) const
 Returns true if this is the last frame. More...
 
virtual int32 NumFramesReady () const
 returns the feature dimension. More...
 
virtual BaseFloat FrameShiftInSeconds () const
 
virtual void GetFrame (int32 frame, VectorBase< BaseFloat > *feat)
 Gets the feature vector for this frame. More...
 
void SetAdaptationState (const OnlineIvectorExtractorAdaptationState &adaptation_state)
 Set the adaptation state to a particular value, e.g. More...
 
void GetAdaptationState (OnlineIvectorExtractorAdaptationState *adaptation_state) const
 Get the adaptation state; you may want to call this before destroying this object, to get adaptation state that can be used to improve decoding of later utterances of this speaker. More...
 
virtual ~OnlineIvectorFeature ()
 
BaseFloat UbmLogLikePerFrame () const
 
BaseFloat ObjfImprPerFrame () const
 
BaseFloat NumFrames () const
 
void UpdateFrameWeights (const std::vector< std::pair< int32, BaseFloat > > &delta_weights)
 
- Public Member Functions inherited from OnlineFeatureInterface
virtual void GetFrames (const std::vector< int32 > &frames, MatrixBase< BaseFloat > *feats)
 This is like GetFrame() but for a collection of frames. More...
 
virtual ~OnlineFeatureInterface ()
 Virtual destructor. More...
 

Private Member Functions

void UpdateStatsForFrames (const std::vector< std::pair< int32, BaseFloat > > &frame_weights)
 
BaseFloat GetMinPost (BaseFloat weight) const
 
void UpdateStatsUntilFrame (int32 frame)
 
void UpdateStatsUntilFrameWeighted (int32 frame)
 
void PrintDiagnostics () const
 

Private Attributes

const OnlineIvectorExtractionInfoinfo_
 
OnlineFeatureInterfacebase_
 
OnlineFeatureInterfacelda_
 
OnlineCmvncmvn_
 
OnlineFeatureInterfacelda_normalized_
 
std::vector< OnlineFeatureInterface * > to_delete_
 
OnlineIvectorEstimationStats ivector_stats_
 the iVector estimation stats More...
 
int32 num_frames_stats_
 num_frames_stats_ is the number of frames of data we have already accumulated from this utterance and put in ivector_stats_. More...
 
std::priority_queue< std::pair< int32, BaseFloat >, std::vector< std::pair< int32, BaseFloat > >, std::greater< std::pair< int32, BaseFloat > > > delta_weights_
 delta_weights_ is written to by UpdateFrameWeights, in the case where the iVector estimation is silence-weighted using the decoder traceback. More...
 
std::vector< BaseFloatcurrent_frame_weight_debug_
 this is only used for validating that the frame-weighting code is not buggy. More...
 
bool delta_weights_provided_
 delta_weights_provided_ is set to true if UpdateFrameWeights was ever called; it's used to detect wrong usage of this class. More...
 
bool updated_with_no_delta_weights_
 The following is also used to detect wrong usage of this class; it's set to true if UpdateStatsUntilFrame() was ever called. More...
 
int32 most_recent_frame_with_weight_
 if delta_weights_ was ever called, this keeps track of the most recent frame that ever had a weight. More...
 
double tot_ubm_loglike_
 The following is only needed for diagnostics. More...
 
Vector< double > current_ivector_
 Most recently estimated iVector, will have been estimated at the greatest time t where t <= num_frames_stats_ and t % info_.ivector_period == 0. More...
 
std::vector< Vector< BaseFloat > *> ivectors_history_
 if info_.use_most_recent_ivector == false, we need to store the iVector we estimated each info_.ivector_period frames so that GetFrame() can return the iVector that was active on that frame. More...
 

Detailed Description

OnlineIvectorFeature is an online feature-extraction class that's responsible for extracting iVectors from raw features such as MFCC, PLP or filterbank.

Internally it processes the raw features using two different pipelines, one online-CMVN+splice+LDA, and one just splice+LDA. It gets GMM posteriors from the CMVN-normalized features, and with those and the unnormalized features it obtains iVectors.

Definition at line 256 of file online-ivector-feature.h.

Constructor & Destructor Documentation

◆ OnlineIvectorFeature()

OnlineIvectorFeature ( const OnlineIvectorExtractionInfo info,
OnlineFeatureInterface base_feature 
)
explicit

Constructor.

base_feature is for example raw MFCC or PLP or filterbank features, whatever was used to train the iVector extractor. "info" contains all the configuration information as well as things like the iVector extractor that we won't be modifying. Caution: the class keeps a const reference to "info", so don't delete it while this class or others copied from it still exist.

Definition at line 399 of file online-ivector-feature.cc.

References OnlineIvectorExtractionInfo::Check(), OnlineIvectorFeature::cmvn_, OnlineIvectorExtractionInfo::cmvn_opts, OnlineIvectorFeature::current_ivector_, OnlineIvectorExtractionInfo::extractor, OnlineIvectorExtractionInfo::global_cmvn_stats, OnlineIvectorFeature::info_, IvectorExtractor::IvectorDim(), KALDI_ASSERT, OnlineIvectorFeature::lda_, OnlineIvectorExtractionInfo::lda_mat, OnlineIvectorFeature::lda_normalized_, IvectorExtractor::PriorOffset(), Vector< Real >::Resize(), OnlineIvectorExtractionInfo::splice_opts, and OnlineIvectorFeature::to_delete_.

401  :
402  info_(info),
403  base_(base_feature),
406  info_.max_count),
410  info.Check();
411  KALDI_ASSERT(base_feature != NULL);
412  OnlineFeatureInterface *splice_feature = new OnlineSpliceFrames(info_.splice_opts, base_feature);
413  to_delete_.push_back(splice_feature);
414  OnlineFeatureInterface *lda_feature = new OnlineTransform(info.lda_mat, splice_feature);
415  to_delete_.push_back(lda_feature);
416  OnlineFeatureInterface *lda_cache_feature = new OnlineCacheFeature(lda_feature);
417  lda_ = lda_cache_feature;
418  to_delete_.push_back(lda_cache_feature);
419 
420 
421  OnlineCmvnState naive_cmvn_state(info.global_cmvn_stats);
422  // Note: when you call this constructor the CMVN state knows nothing
423  // about the speaker. If you want to inform this class about more specific
424  // adaptation state, call this->SetAdaptationState(), most likely derived
425  // from a call to GetAdaptationState() from a previous object of this type.
426  cmvn_ = new OnlineCmvn(info.cmvn_opts, naive_cmvn_state, base_feature);
427  to_delete_.push_back(cmvn_);
428 
429  OnlineFeatureInterface *splice_normalized =
430  new OnlineSpliceFrames(info_.splice_opts, cmvn_),
431  *lda_normalized =
432  new OnlineTransform(info.lda_mat, splice_normalized),
433  *cache_normalized = new OnlineCacheFeature(lda_normalized);
434  lda_normalized_ = cache_normalized;
435 
436  to_delete_.push_back(splice_normalized);
437  to_delete_.push_back(lda_normalized);
438  to_delete_.push_back(cache_normalized);
439 
440  // Set the iVector to its default value, [ prior_offset, 0, 0, ... ].
443 }
double PriorOffset() const
The distribution over iVectors, in our formulation, is not centered at zero; its first dimension has ...
Vector< double > current_ivector_
Most recently estimated iVector, will have been estimated at the greatest time t where t <= num_frame...
OnlineFeatureInterface * base_
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
int32 num_frames_stats_
num_frames_stats_ is the number of frames of data we have already accumulated from this utterance and...
double tot_ubm_loglike_
The following is only needed for diagnostics.
OnlineFeatureInterface * lda_normalized_
OnlineIvectorEstimationStats ivector_stats_
the iVector estimation stats
bool updated_with_no_delta_weights_
The following is also used to detect wrong usage of this class; it&#39;s set to true if UpdateStatsUntilF...
int32 most_recent_frame_with_weight_
if delta_weights_ was ever called, this keeps track of the most recent frame that ever had a weight...
const OnlineIvectorExtractionInfo & info_
bool delta_weights_provided_
delta_weights_provided_ is set to true if UpdateFrameWeights was ever called; it&#39;s used to detect wro...
std::vector< OnlineFeatureInterface * > to_delete_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
OnlineFeatureInterface * lda_

◆ ~OnlineIvectorFeature()

~OnlineIvectorFeature ( )
virtual

Definition at line 377 of file online-ivector-feature.cc.

References rnnlm::i.

377  {
379  // Delete objects owned here.
380  for (size_t i = 0; i < to_delete_.size(); i++)
381  delete to_delete_[i];
382  for (size_t i = 0; i < ivectors_history_.size(); i++)
383  delete ivectors_history_[i];
384 }
std::vector< Vector< BaseFloat > *> ivectors_history_
if info_.use_most_recent_ivector == false, we need to store the iVector we estimated each info_...
std::vector< OnlineFeatureInterface * > to_delete_

Member Function Documentation

◆ Dim()

int32 Dim ( ) const
virtual

Dim() will return the iVector dimension.

Implements OnlineFeatureInterface.

Definition at line 147 of file online-ivector-feature.cc.

Referenced by main().

147  {
148  return info_.extractor.IvectorDim();
149 }
const OnlineIvectorExtractionInfo & info_

◆ FrameShiftInSeconds()

BaseFloat FrameShiftInSeconds ( ) const
virtual

Implements OnlineFeatureInterface.

Definition at line 165 of file online-ivector-feature.cc.

165  {
166  return lda_->FrameShiftInSeconds();
167 }
virtual BaseFloat FrameShiftInSeconds() const =0
OnlineFeatureInterface * lda_

◆ GetAdaptationState()

void GetAdaptationState ( OnlineIvectorExtractorAdaptationState adaptation_state) const

Get the adaptation state; you may want to call this before destroying this object, to get adaptation state that can be used to improve decoding of later utterances of this speaker.

Definition at line 386 of file online-ivector-feature.cc.

References OnlineIvectorExtractorAdaptationState::cmvn_state, OnlineIvectorExtractorAdaptationState::ivector_stats, and OnlineIvectorExtractorAdaptationState::LimitFrames().

Referenced by OnlineNnet2FeaturePipeline::GetAdaptationState(), and main().

387  {
388  // Note: the following call will work even if cmvn_->NumFramesReady() == 0; in
389  // that case it will return the unmodified adaptation state that cmvn_ was
390  // initialized with.
392  &(adaptation_state->cmvn_state));
393  adaptation_state->ivector_stats = ivector_stats_;
394  adaptation_state->LimitFrames(info_.max_remembered_frames,
396 }
void GetState(int32 cur_frame, OnlineCmvnState *cmvn_state)
OnlineIvectorEstimationStats ivector_stats_
the iVector estimation stats
const OnlineIvectorExtractionInfo & info_
virtual int32 NumFramesReady() const
returns the feature dimension.

◆ GetFrame()

void GetFrame ( int32  frame,
VectorBase< BaseFloat > *  feat 
)
virtual

Gets the feature vector for this frame.

Before calling this for a given frame, it is assumed that you called NumFramesReady() and it returned a number greater than "frame". Otherwise this call will likely crash with an assert failure. This function is not declared const, in case there is some kind of caching going on, but most of the time it shouldn't modify the class.

Implements OnlineFeatureInterface.

Definition at line 327 of file online-ivector-feature.cc.

References VectorBase< Real >::CopyFromVec(), VectorBase< Real >::Dim(), rnnlm::i, KALDI_ASSERT, and KALDI_VLOG.

Referenced by main().

328  {
329  int32 frame_to_update_until = (info_.greedy_ivector_extractor ?
330  lda_->NumFramesReady() - 1 : frame);
331  if (!delta_weights_provided_) // No silence weighting.
332  UpdateStatsUntilFrame(frame_to_update_until);
333  else
334  UpdateStatsUntilFrameWeighted(frame_to_update_until);
335 
336  KALDI_ASSERT(feat->Dim() == this->Dim());
337 
339  KALDI_VLOG(5) << "due to --use-most-recent-ivector=true, using iVector "
340  << "from frame " << num_frames_stats_ << " for frame "
341  << frame;
342  // use the most recent iVector we have, even if 'frame' is significantly in
343  // the past.
344  feat->CopyFromVec(current_ivector_);
345  // Subtract the prior-mean from the first dimension of the output feature so
346  // it's approximately zero-mean.
347  (*feat)(0) -= info_.extractor.PriorOffset();
348  } else {
349  int32 i = frame / info_.ivector_period; // rounds down.
350  // if the following fails, UpdateStatsUntilFrame would have a bug.
351  KALDI_ASSERT(static_cast<size_t>(i) < ivectors_history_.size());
352  feat->CopyFromVec(*(ivectors_history_[i]));
353  (*feat)(0) -= info_.extractor.PriorOffset();
354  }
355 }
double PriorOffset() const
The distribution over iVectors, in our formulation, is not centered at zero; its first dimension has ...
Vector< double > current_ivector_
Most recently estimated iVector, will have been estimated at the greatest time t where t <= num_frame...
kaldi::int32 int32
virtual int32 Dim() const
Dim() will return the iVector dimension.
int32 num_frames_stats_
num_frames_stats_ is the number of frames of data we have already accumulated from this utterance and...
std::vector< Vector< BaseFloat > *> ivectors_history_
if info_.use_most_recent_ivector == false, we need to store the iVector we estimated each info_...
const OnlineIvectorExtractionInfo & info_
bool delta_weights_provided_
delta_weights_provided_ is set to true if UpdateFrameWeights was ever called; it&#39;s used to detect wro...
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156
void UpdateStatsUntilFrameWeighted(int32 frame)
virtual int32 NumFramesReady() const =0
returns the feature dimension.
OnlineFeatureInterface * lda_

◆ GetMinPost()

BaseFloat GetMinPost ( BaseFloat  weight) const
private

Definition at line 188 of file online-ivector-feature.cc.

188  {
189  BaseFloat min_post = info_.min_post;
190  BaseFloat abs_weight = fabs(weight);
191  // If we return 0.99, it will have the same effect as just picking the
192  // most probable Gaussian on that frame.
193  if (abs_weight == 0.0)
194  return 0.99; // I don't anticipate reaching here.
195  min_post /= abs_weight;
196  if (min_post > 0.99)
197  min_post = 0.99;
198  return min_post;
199 }
float BaseFloat
Definition: kaldi-types.h:29
const OnlineIvectorExtractionInfo & info_

◆ IsLastFrame()

bool IsLastFrame ( int32  frame) const
virtual

Returns true if this is the last frame.

Frame indices 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). This function may return false for some frame if we haven't yet decided to terminate decoding, but later true if we decide to terminate decoding. This function exists mainly to correctly handle end effects in feature extraction, and is not a mechanism to determine how many frames are in the decodable object (as it used to be, and for backward compatibility, still is, in the Decodable interface).

Implements OnlineFeatureInterface.

Definition at line 151 of file online-ivector-feature.cc.

151  {
152  // Note: it might be more logical to return, say, lda_->IsLastFrame()
153  // since this is the feature the iVector extractor directly consumes,
154  // but it will give the same answer as base_->IsLastFrame() anyway.
155  // [note: the splicing component pads at begin and end so it always
156  // returns the same number of frames as its input.]
157  return base_->IsLastFrame(frame);
158 }
OnlineFeatureInterface * base_
virtual bool IsLastFrame(int32 frame) const =0
Returns true if this is the last frame.

◆ NumFrames()

BaseFloat NumFrames ( ) const
inline

Definition at line 307 of file online-ivector-feature.h.

Referenced by OnlineIvectorFeature::UbmLogLikePerFrame().

307  {
309  }
OnlineIvectorEstimationStats ivector_stats_
the iVector estimation stats
const OnlineIvectorExtractionInfo & info_

◆ NumFramesReady()

int32 NumFramesReady ( ) const
virtual

returns the feature dimension.

Returns the total number of frames, since the start of the utterance, that are now available. In an online-decoding context, this will likely increase with time as more data becomes available.

Implements OnlineFeatureInterface.

Definition at line 160 of file online-ivector-feature.cc.

References KALDI_ASSERT.

Referenced by SingleUtteranceNnet2DecoderThreaded::RunNnetEvaluationInternal().

160  {
161  KALDI_ASSERT(lda_ != NULL);
162  return lda_->NumFramesReady();
163 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
virtual int32 NumFramesReady() const =0
returns the feature dimension.
OnlineFeatureInterface * lda_

◆ ObjfImprPerFrame()

BaseFloat ObjfImprPerFrame ( ) const

Definition at line 460 of file online-ivector-feature.cc.

References OnlineIvectorFeature::current_ivector_, OnlineIvectorFeature::ivector_stats_, and OnlineIvectorEstimationStats::ObjfChange().

Referenced by main().

460  {
462 }
double ObjfChange(const VectorBase< double > &ivector) const
ObjfChange returns the change in objective function *per frame* from using the default value [ prior_...
Vector< double > current_ivector_
Most recently estimated iVector, will have been estimated at the greatest time t where t <= num_frame...
OnlineIvectorEstimationStats ivector_stats_
the iVector estimation stats

◆ PrintDiagnostics()

void PrintDiagnostics ( ) const
private

Definition at line 357 of file online-ivector-feature.cc.

References KALDI_VLOG, VectorBase< Real >::Norm(), and kaldi::NumFrames().

357  {
358  if (num_frames_stats_ == 0) {
359  KALDI_VLOG(3) << "Processed no data.";
360  } else {
361  KALDI_VLOG(3) << "UBM log-likelihood was "
362  << (tot_ubm_loglike_ / NumFrames())
363  << " per frame, over " << NumFrames()
364  << " frames.";
365 
366  Vector<BaseFloat> temp_ivector(current_ivector_);
367  temp_ivector(0) -= info_.extractor.PriorOffset();
368 
369  KALDI_VLOG(2) << "By the end of the utterance, objf change/frame "
370  << "from estimating iVector (vs. default) was "
372  << " and iVector length was "
373  << temp_ivector.Norm(2.0);
374  }
375 }
double ObjfChange(const VectorBase< double > &ivector) const
ObjfChange returns the change in objective function *per frame* from using the default value [ prior_...
double PriorOffset() const
The distribution over iVectors, in our formulation, is not centered at zero; its first dimension has ...
Vector< double > current_ivector_
Most recently estimated iVector, will have been estimated at the greatest time t where t <= num_frame...
int32 num_frames_stats_
num_frames_stats_ is the number of frames of data we have already accumulated from this utterance and...
double tot_ubm_loglike_
The following is only needed for diagnostics.
OnlineIvectorEstimationStats ivector_stats_
the iVector estimation stats
const OnlineIvectorExtractionInfo & info_
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156

◆ SetAdaptationState()

void SetAdaptationState ( const OnlineIvectorExtractorAdaptationState adaptation_state)

Set the adaptation state to a particular value, e.g.

reflecting previous utterances of the same speaker; this will generally be called after constructing a new instance of this class.

Definition at line 445 of file online-ivector-feature.cc.

References OnlineIvectorFeature::cmvn_, OnlineIvectorExtractorAdaptationState::cmvn_state, OnlineIvectorExtractorAdaptationState::ivector_stats, OnlineIvectorFeature::ivector_stats_, OnlineIvectorEstimationStats::IvectorDim(), KALDI_ASSERT, OnlineIvectorFeature::num_frames_stats_, and OnlineCmvn::SetState().

Referenced by main(), and OnlineNnet2FeaturePipeline::SetAdaptationState().

446  {
448  "SetAdaptationState called after frames were processed.");
450  adaptation_state.ivector_stats.IvectorDim());
451  ivector_stats_ = adaptation_state.ivector_stats;
452  cmvn_->SetState(adaptation_state.cmvn_state);
453 }
int32 num_frames_stats_
num_frames_stats_ is the number of frames of data we have already accumulated from this utterance and...
OnlineIvectorEstimationStats ivector_stats_
the iVector estimation stats
void SetState(const OnlineCmvnState &cmvn_state)
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ UbmLogLikePerFrame()

BaseFloat UbmLogLikePerFrame ( ) const

Definition at line 455 of file online-ivector-feature.cc.

References OnlineIvectorFeature::NumFrames(), and OnlineIvectorFeature::tot_ubm_loglike_.

Referenced by main().

455  {
456  if (NumFrames() == 0) return 0;
457  else return tot_ubm_loglike_ / NumFrames();
458 }
double tot_ubm_loglike_
The following is only needed for diagnostics.

◆ UpdateFrameWeights()

void UpdateFrameWeights ( const std::vector< std::pair< int32, BaseFloat > > &  delta_weights)

Definition at line 169 of file online-ivector-feature.cc.

References rnnlm::i, and KALDI_ASSERT.

Referenced by main(), SingleUtteranceNnet2DecoderThreaded::RunNnetEvaluationInternal(), and OnlineNnet2FeaturePipeline::UpdateFrameWeights().

170  {
171  // add the elements to delta_weights_, which is a priority queue. The top
172  // element of the priority queue is the lowest numbered frame (we ensured this
173  // by making the comparison object std::greater instead of std::less). Adding
174  // elements from top (lower-numbered frames) to bottom (higher-numbered
175  // frames) should be most efficient, assuming it's a heap internally. So we
176  // go forward not backward in delta_weights while adding.
177  for (size_t i = 0; i < delta_weights.size(); i++) {
178  delta_weights_.push(delta_weights[i]);
179  int32 frame = delta_weights[i].first;
180  KALDI_ASSERT(frame >= 0);
181  if (frame > most_recent_frame_with_weight_)
183  }
185 }
kaldi::int32 int32
int32 most_recent_frame_with_weight_
if delta_weights_ was ever called, this keeps track of the most recent frame that ever had a weight...
std::priority_queue< std::pair< int32, BaseFloat >, std::vector< std::pair< int32, BaseFloat > >, std::greater< std::pair< int32, BaseFloat > > > delta_weights_
delta_weights_ is written to by UpdateFrameWeights, in the case where the iVector estimation is silen...
bool delta_weights_provided_
delta_weights_provided_ is set to true if UpdateFrameWeights was ever called; it&#39;s used to detect wro...
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ UpdateStatsForFrames()

void UpdateStatsForFrames ( const std::vector< std::pair< int32, BaseFloat > > &  frame_weights)
private

Definition at line 201 of file online-ivector-feature.cc.

References rnnlm::i, rnnlm::j, kaldi::kUndefined, kaldi::MergePairVectorSumming(), MatrixBase< Real >::Row(), and kaldi::VectorToPosteriorEntry().

202  {
203 
204  std::vector<std::pair<int32, BaseFloat> > frame_weights(frame_weights_in);
205  // Remove duplicates of frames.
206  MergePairVectorSumming(&frame_weights);
207 
208  if (frame_weights.empty())
209  return;
210 
211  int32 num_frames = static_cast<int32>(frame_weights.size());
212  int32 feat_dim = lda_normalized_->Dim();
213  Matrix<BaseFloat> feats(num_frames, feat_dim, kUndefined),
214  log_likes;
215 
216  std::vector<int32> frames;
217  frames.reserve(frame_weights.size());
218  for (int32 i = 0; i < num_frames; i++)
219  frames.push_back(frame_weights[i].first);
220  lda_normalized_->GetFrames(frames, &feats);
221 
222  info_.diag_ubm.LogLikelihoods(feats, &log_likes);
223 
224  // "posteriors" stores, for each frame index in the range of frames, the
225  // pruned posteriors for the Gaussians in the UBM.
226  std::vector<std::vector<std::pair<int32, BaseFloat> > > posteriors(num_frames);
227  for (int32 i = 0; i < num_frames; i++) {
228  std::vector<std::pair<int32, BaseFloat> > &posterior = posteriors[i];
229  BaseFloat weight = frame_weights[i].second;
230  if (weight != 0.0) {
231  tot_ubm_loglike_ += weight *
232  VectorToPosteriorEntry(log_likes.Row(i), info_.num_gselect,
233  GetMinPost(weight), &posterior);
234  for (size_t j = 0; j < posterior.size(); j++)
235  posterior[j].second *= info_.posterior_scale * weight;
236  }
237  }
238 
240  lda_->GetFrames(frames, &feats); // default, get features without OnlineCmvn
241  } else {
242  lda_normalized_->GetFrames(frames, &feats); // get features with OnlineCmvn
243  }
244  ivector_stats_.AccStats(info_.extractor, feats, posteriors);
245 }
void AccStats(const IvectorExtractor &extractor, const VectorBase< BaseFloat > &feature, const std::vector< std::pair< int32, BaseFloat > > &gauss_post)
BaseFloat VectorToPosteriorEntry(const VectorBase< BaseFloat > &log_likes, int32 num_gselect, BaseFloat min_post, std::vector< std::pair< int32, BaseFloat > > *post_entry)
Given a vector of log-likelihoods (typically of Gaussians in a GMM but could be of pdf-ids)...
Definition: posterior.cc:440
kaldi::int32 int32
double tot_ubm_loglike_
The following is only needed for diagnostics.
OnlineFeatureInterface * lda_normalized_
float BaseFloat
Definition: kaldi-types.h:29
OnlineIvectorEstimationStats ivector_stats_
the iVector estimation stats
virtual void GetFrames(const std::vector< int32 > &frames, MatrixBase< BaseFloat > *feats)
This is like GetFrame() but for a collection of frames.
BaseFloat GetMinPost(BaseFloat weight) const
const OnlineIvectorExtractionInfo & info_
void LogLikelihoods(const VectorBase< BaseFloat > &data, Vector< BaseFloat > *loglikes) const
Outputs the per-component log-likelihoods.
Definition: diag-gmm.cc:528
void MergePairVectorSumming(std::vector< std::pair< I, F > > *vec)
For a vector of pair<I, F> where I is an integer and F a floating-point or integer type...
Definition: stl-utils.h:288
OnlineFeatureInterface * lda_
virtual int32 Dim() const =0

◆ UpdateStatsUntilFrame()

void UpdateStatsUntilFrame ( int32  frame)
private

Definition at line 248 of file online-ivector-feature.cc.

References KALDI_ASSERT.

248  {
249  KALDI_ASSERT(frame >= 0 && frame < this->NumFramesReady() &&
252 
253  int32 ivector_period = info_.ivector_period;
254  int32 num_cg_iters = info_.num_cg_iters;
255 
256  std::vector<std::pair<int32, BaseFloat> > frame_weights;
257 
258  for (; num_frames_stats_ <= frame; num_frames_stats_++) {
260  BaseFloat frame_weight = 1.0;
261  frame_weights.push_back(std::pair<int32, BaseFloat>(t, frame_weight));
262  if ((!info_.use_most_recent_ivector && t % ivector_period == 0) ||
263  (info_.use_most_recent_ivector && t == frame)) {
264  // The call below to UpdateStatsForFrames() is equivalent to doing, for
265  // all valid indexes i:
266  // UpdateStatsForFrame(cur_start_frame + i, frame_weights[i])
267  UpdateStatsForFrames(frame_weights);
268  frame_weights.clear();
270  if (!info_.use_most_recent_ivector) { // need to cache iVectors.
271  int32 ivec_index = t / ivector_period;
272  KALDI_ASSERT(ivec_index == static_cast<int32>(ivectors_history_.size()));
273  ivectors_history_.push_back(new Vector<BaseFloat>(current_ivector_));
274  }
275  }
276  }
277  if (!frame_weights.empty())
278  UpdateStatsForFrames(frame_weights);
279 }
Vector< double > current_ivector_
Most recently estimated iVector, will have been estimated at the greatest time t where t <= num_frame...
kaldi::int32 int32
void UpdateStatsForFrames(const std::vector< std::pair< int32, BaseFloat > > &frame_weights)
int32 num_frames_stats_
num_frames_stats_ is the number of frames of data we have already accumulated from this utterance and...
std::vector< Vector< BaseFloat > *> ivectors_history_
if info_.use_most_recent_ivector == false, we need to store the iVector we estimated each info_...
float BaseFloat
Definition: kaldi-types.h:29
OnlineIvectorEstimationStats ivector_stats_
the iVector estimation stats
bool updated_with_no_delta_weights_
The following is also used to detect wrong usage of this class; it&#39;s set to true if UpdateStatsUntilF...
void GetIvector(int32 num_cg_iters, VectorBase< double > *ivector) const
This function gets the current estimate of the iVector.
const OnlineIvectorExtractionInfo & info_
bool delta_weights_provided_
delta_weights_provided_ is set to true if UpdateFrameWeights was ever called; it&#39;s used to detect wro...
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
virtual int32 NumFramesReady() const
returns the feature dimension.

◆ UpdateStatsUntilFrameWeighted()

void UpdateStatsUntilFrameWeighted ( int32  frame)
private

Definition at line 281 of file online-ivector-feature.cc.

References KALDI_ASSERT.

281  {
282  KALDI_ASSERT(frame >= 0 && frame < this->NumFramesReady() &&
286  bool debug_weights = false;
287 
288  int32 ivector_period = info_.ivector_period;
289  int32 num_cg_iters = info_.num_cg_iters;
290 
291  std::vector<std::pair<int32, BaseFloat> > frame_weights;
292  frame_weights.reserve(delta_weights_.size());
293 
294  for (; num_frames_stats_ <= frame; num_frames_stats_++) {
296  // Instead of just updating frame t, we update all frames that need updating
297  // with index <= t, in case old frames were reclassified as silence/nonsilence.
298  while (!delta_weights_.empty() &&
299  delta_weights_.top().first <= t) {
300  int32 frame = delta_weights_.top().first;
301  BaseFloat weight = delta_weights_.top().second;
302  frame_weights.push_back(delta_weights_.top());
303  delta_weights_.pop();
304  if (debug_weights) {
305  if (current_frame_weight_debug_.size() <= frame)
306  current_frame_weight_debug_.resize(frame + 1, 0.0);
307  current_frame_weight_debug_[frame] += weight;
308  }
309  }
310  if ((!info_.use_most_recent_ivector && t % ivector_period == 0) ||
311  (info_.use_most_recent_ivector && t == frame)) {
312  UpdateStatsForFrames(frame_weights);
313  frame_weights.clear();
315  if (!info_.use_most_recent_ivector) { // need to cache iVectors.
316  int32 ivec_index = t / ivector_period;
317  KALDI_ASSERT(ivec_index == static_cast<int32>(ivectors_history_.size()));
318  ivectors_history_.push_back(new Vector<BaseFloat>(current_ivector_));
319  }
320  }
321  }
322  if (!frame_weights.empty())
323  UpdateStatsForFrames(frame_weights);
324 }
Vector< double > current_ivector_
Most recently estimated iVector, will have been estimated at the greatest time t where t <= num_frame...
kaldi::int32 int32
void UpdateStatsForFrames(const std::vector< std::pair< int32, BaseFloat > > &frame_weights)
int32 num_frames_stats_
num_frames_stats_ is the number of frames of data we have already accumulated from this utterance and...
std::vector< Vector< BaseFloat > *> ivectors_history_
if info_.use_most_recent_ivector == false, we need to store the iVector we estimated each info_...
float BaseFloat
Definition: kaldi-types.h:29
OnlineIvectorEstimationStats ivector_stats_
the iVector estimation stats
bool updated_with_no_delta_weights_
The following is also used to detect wrong usage of this class; it&#39;s set to true if UpdateStatsUntilF...
int32 most_recent_frame_with_weight_
if delta_weights_ was ever called, this keeps track of the most recent frame that ever had a weight...
void GetIvector(int32 num_cg_iters, VectorBase< double > *ivector) const
This function gets the current estimate of the iVector.
std::vector< BaseFloat > current_frame_weight_debug_
this is only used for validating that the frame-weighting code is not buggy.
const OnlineIvectorExtractionInfo & info_
std::priority_queue< std::pair< int32, BaseFloat >, std::vector< std::pair< int32, BaseFloat > >, std::greater< std::pair< int32, BaseFloat > > > delta_weights_
delta_weights_ is written to by UpdateFrameWeights, in the case where the iVector estimation is silen...
bool delta_weights_provided_
delta_weights_provided_ is set to true if UpdateFrameWeights was ever called; it&#39;s used to detect wro...
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
virtual int32 NumFramesReady() const
returns the feature dimension.

Member Data Documentation

◆ base_

OnlineFeatureInterface* base_
private

Definition at line 352 of file online-ivector-feature.h.

◆ cmvn_

◆ current_frame_weight_debug_

std::vector<BaseFloat> current_frame_weight_debug_
private

this is only used for validating that the frame-weighting code is not buggy.

Definition at line 385 of file online-ivector-feature.h.

◆ current_ivector_

Vector<double> current_ivector_
private

Most recently estimated iVector, will have been estimated at the greatest time t where t <= num_frames_stats_ and t % info_.ivector_period == 0.

Definition at line 404 of file online-ivector-feature.h.

Referenced by OnlineIvectorFeature::ObjfImprPerFrame(), and OnlineIvectorFeature::OnlineIvectorFeature().

◆ delta_weights_

std::priority_queue<std::pair<int32, BaseFloat>, std::vector<std::pair<int32, BaseFloat> >, std::greater<std::pair<int32, BaseFloat> > > delta_weights_
private

delta_weights_ is written to by UpdateFrameWeights, in the case where the iVector estimation is silence-weighted using the decoder traceback.

Its elements are consumed by UpdateStatsUntilFrameWeighted(). We provide std::greater<std::pair<int32, BaseFloat> > > as the comparison type (default is std::less) so that the lowest-numbered frame, not the highest-numbered one, will be returned by top().

Definition at line 382 of file online-ivector-feature.h.

◆ delta_weights_provided_

bool delta_weights_provided_
private

delta_weights_provided_ is set to true if UpdateFrameWeights was ever called; it's used to detect wrong usage of this class.

Definition at line 389 of file online-ivector-feature.h.

◆ info_

const OnlineIvectorExtractionInfo& info_
private

◆ ivector_stats_

OnlineIvectorEstimationStats ivector_stats_
private

the iVector estimation stats

Definition at line 364 of file online-ivector-feature.h.

Referenced by OnlineIvectorFeature::ObjfImprPerFrame(), and OnlineIvectorFeature::SetAdaptationState().

◆ ivectors_history_

std::vector<Vector<BaseFloat>* > ivectors_history_
private

if info_.use_most_recent_ivector == false, we need to store the iVector we estimated each info_.ivector_period frames so that GetFrame() can return the iVector that was active on that frame.

ivectors_history_[i] contains the iVector we estimated on frame t = i * info_.ivector_period.

Definition at line 411 of file online-ivector-feature.h.

◆ lda_

OnlineFeatureInterface* lda_
private

◆ lda_normalized_

OnlineFeatureInterface* lda_normalized_
private

◆ most_recent_frame_with_weight_

int32 most_recent_frame_with_weight_
private

if delta_weights_ was ever called, this keeps track of the most recent frame that ever had a weight.

It's mostly for detecting errors.

Definition at line 396 of file online-ivector-feature.h.

◆ num_frames_stats_

int32 num_frames_stats_
private

num_frames_stats_ is the number of frames of data we have already accumulated from this utterance and put in ivector_stats_.

Each frame t < num_frames_stats_ is in the stats. In case you are doing the silence-weighted iVector estimation, with UpdateFrameWeights() being called, this variable is still used but you may later have to revisit earlier frames to adjust their weights... see the code.

Definition at line 372 of file online-ivector-feature.h.

Referenced by OnlineIvectorFeature::SetAdaptationState().

◆ to_delete_

std::vector<OnlineFeatureInterface*> to_delete_
private

◆ tot_ubm_loglike_

double tot_ubm_loglike_
private

The following is only needed for diagnostics.

Definition at line 399 of file online-ivector-feature.h.

Referenced by OnlineIvectorFeature::UbmLogLikePerFrame().

◆ updated_with_no_delta_weights_

bool updated_with_no_delta_weights_
private

The following is also used to detect wrong usage of this class; it's set to true if UpdateStatsUntilFrame() was ever called.

Definition at line 392 of file online-ivector-feature.h.


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