Skip to content

Commit

Permalink
[src] Fix issue kaldi-asr#3401 RE crash in silence-weighting ivector …
Browse files Browse the repository at this point in the history
…extraction with max-remembered-frames
  • Loading branch information
danpovey committed Jun 22, 2019
1 parent 777f8c1 commit dd07c69
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 65 deletions.
6 changes: 5 additions & 1 deletion src/feat/online-feature.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ OnlineGenericBaseFeature<C>::OnlineGenericBaseFeature(
const typename C::Options &opts):
computer_(opts), window_function_(computer_.GetFrameOptions()),
features_(opts.frame_opts.max_feature_vectors),
input_finished_(false), waveform_offset_(0) { }
input_finished_(false), waveform_offset_(0) {
// RE the following assert: search for ONLINE_IVECTOR_LIMIT in
// online-ivector-feature.cc.
KALDI_ASSERT(opts.frame_opts.max_feature_vectors > 210);
}


template <class C>
Expand Down
2 changes: 1 addition & 1 deletion src/ivector/ivector-extractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ struct IvectorExtractorEstimationOptions {
"update any associated parameters.");
opts->Register("diagonalize", &diagonalize,
"If true, diagonalize the quadratic term in the "
"objective function. This reorders the ivector dimensions"
"objective function. This reorders the ivector dimensions "
"from most to least important.");
}
};
Expand Down
63 changes: 7 additions & 56 deletions src/online2/online-ivector-feature.cc
Original file line number Diff line number Diff line change
Expand Up @@ -521,58 +521,6 @@ template
void OnlineSilenceWeighting::ComputeCurrentTraceback<fst::GrammarFst>(
const LatticeFasterOnlineDecoderTpl<fst::GrammarFst> &decoder);

int32 OnlineSilenceWeighting::GetBeginFrame() {
int32 max_duration = config_.max_state_duration;
if (max_duration <= 0 || num_frames_output_and_correct_ == 0)
return num_frames_output_and_correct_;

// t_last_untouched is the index of the last frame that is not newly touched
// by ComputeCurrentTraceback. We are interested in whether it is part of a
// run of length greater than max_duration, since this would force it
// to be treated as silence (note: typically a non-silence phone that's very
// long is really silence, for example this can happen with the word "mm").

int32 t_last_untouched = num_frames_output_and_correct_ - 1,
t_end = frame_info_.size();
int32 transition_id = frame_info_[t_last_untouched].transition_id;
// no point searching longer than max_duration; when the length of the run is
// at least that much, a longer length makes no difference.
int32 lower_search_bound = std::max(0, t_last_untouched - max_duration),
upper_search_bound = std::min(t_last_untouched + max_duration, t_end - 1),
t_lower, t_upper;

// t_lower will be the first index in the run of equal transition-ids.
for (t_lower = t_last_untouched;
t_lower > lower_search_bound &&
frame_info_[t_lower - 1].transition_id == transition_id; t_lower--);

// t_lower will be the last index in the run of equal transition-ids.
for (t_upper = t_last_untouched;
t_upper < upper_search_bound &&
frame_info_[t_upper + 1].transition_id == transition_id; t_upper++);

int32 run_length = t_upper - t_lower + 1;
if (run_length <= max_duration) {
// we wouldn't treat this run as being silence, as it's within
// the duration limit. So we return the default value
// num_frames_output_and_correct_ as our lower bound for processing.
return num_frames_output_and_correct_;
}
int32 old_run_length = t_last_untouched - t_lower + 1;
if (old_run_length > max_duration) {
// The run-length before we got this new data was already longer than the
// max-duration, so would already have been treated as silence. therefore
// we don't have to encompass it all- we just include a long enough length
// in the region we are going to process, that the run-length in that region
// is longer than max_duration.
int32 ans = t_upper - max_duration;
KALDI_ASSERT(ans >= t_lower);
return ans;
} else {
return t_lower;
}
}

void OnlineSilenceWeighting::GetDeltaWeights(
int32 num_frames_ready_in,
std::vector<std::pair<int32, BaseFloat> > *delta_weights) {
Expand All @@ -591,10 +539,13 @@ void OnlineSilenceWeighting::GetDeltaWeights(
if (frame_info_.size() < static_cast<size_t>(num_frames_ready))
frame_info_.resize(num_frames_ready);

// we may have to make begin_frame earlier than num_frames_output_and_correct_
// so that max_state_duration is properly enforced. GetBeginFrame() handles
// this logic.
int32 begin_frame = GetBeginFrame(),

// Don't go further backward into the past than 200 frames when modifying the
// traceback. C.f. the value 210 in template
// OnlineGenericBaseFeature<C>::OnlineGenericBaseFeature in online-feature.cc,
// which needs to be more than this value of 200 plus the amount of context
// that LDA might use. Search for ONLINE_IVECTOR_LIMIT in online-feature.cc
int32 begin_frame = std::max<int32>(0, num_frames_ready - 200),
frames_out = static_cast<int32>(frame_info_.size()) - begin_frame;
// frames_out is the number of frames we will output.
KALDI_ASSERT(frames_out >= 0);
Expand Down
8 changes: 1 addition & 7 deletions src/online2/online-ivector-feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ class OnlineSilenceWeighting {

OnlineSilenceWeighting(const TransitionModel &trans_model,
const OnlineSilenceWeightingConfig &config,
int32 frame_subsampling_factor = 1);
int32 frame_subsampling_factor = 1);

bool Active() const { return config_.Active(); }

Expand Down Expand Up @@ -510,12 +510,6 @@ class OnlineSilenceWeighting {
FrameInfo(): token(NULL), transition_id(-1), current_weight(0.0) {}
};

// gets the frame at which we need to begin our processing in
// GetDeltaWeights... normally this is equal to
// num_frames_output_and_correct_, but it may be earlier in case
// max_state_duration is relevant.
int32 GetBeginFrame();

// This contains information about any previously computed traceback;
// when the traceback changes we use this variable to compare it with the
// previous traceback.
Expand Down

0 comments on commit dd07c69

Please sign in to comment.