@@ -78,9 +78,13 @@ class OfflineRecognizerTransducerImpl : public OfflineRecognizerImpl {
78
78
config_(config),
79
79
symbol_table_(config_.model_config.tokens),
80
80
model_(std::make_unique<OfflineTransducerModel>(config_.model_config)) {
81
+ if (symbol_table_.Contains (" <unk>" )) {
82
+ unk_id_ = symbol_table_[" <unk>" ];
83
+ }
84
+
81
85
if (config_.decoding_method == " greedy_search" ) {
82
86
decoder_ = std::make_unique<OfflineTransducerGreedySearchDecoder>(
83
- model_.get (), config_.blank_penalty );
87
+ model_.get (), unk_id_, config_.blank_penalty );
84
88
} else if (config_.decoding_method == " modified_beam_search" ) {
85
89
if (!config_.lm_config .model .empty ()) {
86
90
lm_ = OfflineLM::Create (config.lm_config );
@@ -97,7 +101,7 @@ class OfflineRecognizerTransducerImpl : public OfflineRecognizerImpl {
97
101
98
102
decoder_ = std::make_unique<OfflineTransducerModifiedBeamSearchDecoder>(
99
103
model_.get (), lm_.get (), config_.max_active_paths ,
100
- config_.lm_config .scale , config_.blank_penalty );
104
+ config_.lm_config .scale , unk_id_, config_.blank_penalty );
101
105
} else {
102
106
SHERPA_ONNX_LOGE (" Unsupported decoding method: %s" ,
103
107
config_.decoding_method .c_str ());
@@ -113,9 +117,13 @@ class OfflineRecognizerTransducerImpl : public OfflineRecognizerImpl {
113
117
symbol_table_(mgr, config_.model_config.tokens),
114
118
model_(std::make_unique<OfflineTransducerModel>(mgr,
115
119
config_.model_config)) {
120
+ if (symbol_table_.Contains (" <unk>" )) {
121
+ unk_id_ = symbol_table_[" <unk>" ];
122
+ }
123
+
116
124
if (config_.decoding_method == " greedy_search" ) {
117
125
decoder_ = std::make_unique<OfflineTransducerGreedySearchDecoder>(
118
- model_.get (), config_.blank_penalty );
126
+ model_.get (), unk_id_, config_.blank_penalty );
119
127
} else if (config_.decoding_method == " modified_beam_search" ) {
120
128
if (!config_.lm_config .model .empty ()) {
121
129
lm_ = OfflineLM::Create (mgr, config.lm_config );
@@ -133,7 +141,7 @@ class OfflineRecognizerTransducerImpl : public OfflineRecognizerImpl {
133
141
134
142
decoder_ = std::make_unique<OfflineTransducerModifiedBeamSearchDecoder>(
135
143
model_.get (), lm_.get (), config_.max_active_paths ,
136
- config_.lm_config .scale , config_.blank_penalty );
144
+ config_.lm_config .scale , unk_id_, config_.blank_penalty );
137
145
} else {
138
146
SHERPA_ONNX_LOGE (" Unsupported decoding method: %s" ,
139
147
config_.decoding_method .c_str ());
@@ -293,6 +301,7 @@ class OfflineRecognizerTransducerImpl : public OfflineRecognizerImpl {
293
301
std::unique_ptr<OfflineTransducerModel> model_;
294
302
std::unique_ptr<OfflineTransducerDecoder> decoder_;
295
303
std::unique_ptr<OfflineLM> lm_;
304
+ int32_t unk_id_ = -1 ;
296
305
};
297
306
298
307
} // namespace sherpa_onnx
0 commit comments