Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bindings/python/flashlight/lib/text/_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ PYBIND11_MODULE(flashlight_lib_text_decoder, m) {
.def("decode_end", &LexiconDecoder::decodeEnd)
.def("decode", &LexiconDecoder_decode, "emissions"_a, "T"_a, "N"_a)
.def("prune", &LexiconDecoder::prune, "look_back"_a = 0)
.def("rewind", &LexiconDecoder::rewind, "num_frames"_a)
.def(
"get_best_hypothesis",
&LexiconDecoder::getBestHypothesis,
Expand Down
9 changes: 9 additions & 0 deletions flashlight/lib/text/decoder/LexiconDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,15 @@ void LexiconDecoder::prune(int lookBack) {

nPrunedFrames_ = nDecodedFrames_ - lookBack;
}

void LexiconDecoder::rewind(int numFrames) {
int startFrame = std::max(1, nDecodedFrames_ - numFrames);
for (int i = startFrame; i <= nDecodedFrames_; i++) {
hyp_.erase(i);
}

nDecodedFrames_ = std::max(0, nDecodedFrames_ - numFrames);
}
} // namespace text
} // namespace lib
} // namespace fl
2 changes: 2 additions & 0 deletions flashlight/lib/text/decoder/LexiconDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ class FL_TEXT_API LexiconDecoder : public Decoder {

void prune(int lookBack = 0) override;

void rewind(int numFrames);

int nDecodedFramesInBuffer() const override;

DecodeResult getBestHypothesis(int lookBack = 0) const override;
Expand Down