Add transducer modified_beam_search for RKNN. (#1949)

This commit is contained in:
Fangjun Kuang
2025-03-03 13:15:25 +08:00
committed by GitHub
parent d5e7b51af5
commit c9d6859df7
10 changed files with 290 additions and 25 deletions

View File

@@ -7,39 +7,26 @@
#include <vector>
#include "sherpa-onnx/csrc/rknn/online-transducer-decoder-rknn.h"
#include "sherpa-onnx/csrc/rknn/online-transducer-greedy-search-decoder-rknn.h"
#include "sherpa-onnx/csrc/rknn/online-zipformer-transducer-model-rknn.h"
namespace sherpa_onnx {
struct OnlineTransducerDecoderResultRknn {
/// Number of frames after subsampling we have decoded so far
int32_t frame_offset = 0;
/// The decoded token IDs so far
std::vector<int64_t> tokens;
/// number of trailing blank frames decoded so far
int32_t num_trailing_blanks = 0;
/// timestamps[i] contains the output frame index where tokens[i] is decoded.
std::vector<int32_t> timestamps;
std::vector<float> previous_decoder_out;
};
class OnlineTransducerGreedySearchDecoderRknn {
class OnlineTransducerGreedySearchDecoderRknn
: public OnlineTransducerDecoderRknn {
public:
explicit OnlineTransducerGreedySearchDecoderRknn(
OnlineZipformerTransducerModelRknn *model, int32_t unk_id = 2,
float blank_penalty = 0.0)
: model_(model), unk_id_(unk_id), blank_penalty_(blank_penalty) {}
OnlineTransducerDecoderResultRknn GetEmptyResult() const;
OnlineTransducerDecoderResultRknn GetEmptyResult() const override;
void StripLeadingBlanks(OnlineTransducerDecoderResultRknn *r) const;
void StripLeadingBlanks(OnlineTransducerDecoderResultRknn *r) const override;
void Decode(std::vector<float> encoder_out,
OnlineTransducerDecoderResultRknn *result) const;
OnlineTransducerDecoderResultRknn *result) const override;
private:
OnlineZipformerTransducerModelRknn *model_; // Not owned