Skip to content
This repository has been archived by the owner on Aug 3, 2021. It is now read-only.

Commit

Permalink
Provide separate flags to reset offsets and words
Browse files Browse the repository at this point in the history
Separate reset flags are required in cases where we want to get
continuous time stamps across reset but don't want past words.

Signed-off-by: Viraj Karandikar <[email protected]>
  • Loading branch information
virajkarandikar committed Nov 19, 2019
1 parent a81babd commit 5ccc608
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions decoders/ctc_beam_search_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ BeamDecoder::~BeamDecoder()
}


void BeamDecoder::reset(bool partial /* default = false */)
void BeamDecoder::reset(bool keep_offset /*default = false*/, bool keep_words /*default = false*/)
{
// init prefixes' root
if (root != nullptr) {
Expand All @@ -279,15 +279,20 @@ void BeamDecoder::reset(bool partial /* default = false */)
root->set_matcher(matcher);
}

if (partial) {
if (keep_offset) {
prev_time_offset += last_decoded_timestep + time_offset;
} else {
prev_time_offset = 0;
}

if (keep_words) {
prev_wordlist.insert(
std::end(prev_wordlist), std::begin(wordlist),
std::end(wordlist));
prev_time_offset += last_decoded_timestep + time_offset;
} else {
prev_wordlist.clear();
prev_time_offset = 0;
}

wordlist.clear();
time_offset = 0;
last_decoded_timestep = 0;
Expand Down
2 changes: 1 addition & 1 deletion decoders/ctc_beam_search_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class BeamDecoder {
void set_start_offset(int offset) { time_offset = offset; }

// reset state
void reset(bool partial = false);
void reset(bool keep_offset = false, bool keep_words = false);

private:
Scorer *ext_scorer;
Expand Down

0 comments on commit 5ccc608

Please sign in to comment.