Allow more online models to load tokens file from the memory (#1352)
Co-authored-by: xiao <shawl336@6163.com>
This commit is contained in:
@@ -66,15 +66,25 @@ class KeywordSpotterTransducerImpl : public KeywordSpotterImpl {
|
||||
public:
|
||||
explicit KeywordSpotterTransducerImpl(const KeywordSpotterConfig &config)
|
||||
: config_(config),
|
||||
model_(OnlineTransducerModel::Create(config.model_config)),
|
||||
sym_(config.model_config.tokens) {
|
||||
model_(OnlineTransducerModel::Create(config.model_config)) {
|
||||
if (!config.model_config.tokens_buf.empty()) {
|
||||
sym_ = SymbolTable(config.model_config.tokens_buf, false);
|
||||
} else {
|
||||
/// assuming tokens_buf and tokens are guaranteed not being both empty
|
||||
sym_ = SymbolTable(config.model_config.tokens, true);
|
||||
}
|
||||
|
||||
if (sym_.Contains("<unk>")) {
|
||||
unk_id_ = sym_["<unk>"];
|
||||
}
|
||||
|
||||
model_->SetFeatureDim(config.feat_config.feature_dim);
|
||||
|
||||
InitKeywords();
|
||||
if (config.keywords_buf.empty()) {
|
||||
InitKeywords();
|
||||
} else {
|
||||
InitKeywordsFromBufStr();
|
||||
}
|
||||
|
||||
decoder_ = std::make_unique<TransducerKeywordDecoder>(
|
||||
model_.get(), config_.max_active_paths, config_.num_trailing_blanks,
|
||||
@@ -305,6 +315,12 @@ class KeywordSpotterTransducerImpl : public KeywordSpotterImpl {
|
||||
}
|
||||
#endif
|
||||
|
||||
void InitKeywordsFromBufStr() {
|
||||
// keywords_buf's content is supposed to be same as the keywords_file's
|
||||
std::istringstream is(config_.keywords_buf);
|
||||
InitKeywords(is);
|
||||
}
|
||||
|
||||
void InitOnlineStream(OnlineStream *stream) const {
|
||||
auto r = decoder_->GetEmptyResult();
|
||||
SHERPA_ONNX_CHECK_EQ(r.hyps.Size(), 1);
|
||||
|
||||
Reference in New Issue
Block a user