Support decoding with byte-level BPE (bbpe) models. (#1633)
This commit is contained in:
@@ -38,13 +38,14 @@ OnlineRecognizerResult Convert(const OnlineTransducerDecoderResult &src,
|
||||
r.tokens.reserve(src.tokens.size());
|
||||
r.timestamps.reserve(src.tokens.size());
|
||||
|
||||
std::string text;
|
||||
for (auto i : src.tokens) {
|
||||
auto sym = sym_table[i];
|
||||
|
||||
r.text.append(sym);
|
||||
text.append(sym);
|
||||
|
||||
if (sym.size() == 1 && (sym[0] < 0x20 || sym[0] > 0x7e)) {
|
||||
// for byte bpe models
|
||||
// for bpe models with byte_fallback
|
||||
// (but don't rewrite printable characters 0x20..0x7e,
|
||||
// which collide with standard BPE units)
|
||||
std::ostringstream os;
|
||||
@@ -56,6 +57,12 @@ OnlineRecognizerResult Convert(const OnlineTransducerDecoderResult &src,
|
||||
r.tokens.push_back(std::move(sym));
|
||||
}
|
||||
|
||||
if (sym_table.IsByteBpe()) {
|
||||
text = sym_table.DecodeByteBpe(text);
|
||||
}
|
||||
|
||||
r.text = std::move(text);
|
||||
|
||||
float frame_shift_s = frame_shift_ms / 1000. * subsampling_factor;
|
||||
for (auto t : src.timestamps) {
|
||||
float time = frame_shift_s * t;
|
||||
|
||||
Reference in New Issue
Block a user