Skip to content

Commit

Permalink
Print a more user-friendly error message when using --hotwords-file. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Sep 26, 2023
1 parent 9091917 commit 33a5765
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 5 deletions.
12 changes: 11 additions & 1 deletion sherpa-onnx/csrc/offline-recognizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,17 @@ bool OfflineRecognizerConfig::Validate() const {
max_active_paths);
return false;
}
if (!lm_config.Validate()) return false;
if (!lm_config.Validate()) {
return false;
}
}

if (!hotwords_file.empty() && decoding_method != "modified_beam_search") {
SHERPA_ONNX_LOGE(
"Please use --decoding-method=modified_beam_search if you"
" provide --hotwords-file. Given --decoding-method=%s",
decoding_method.c_str());
return false;
}

return model_config.Validate();
Expand Down
3 changes: 2 additions & 1 deletion sherpa-onnx/csrc/online-recognizer-transducer-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ class OnlineRecognizerTransducerImpl : public OnlineRecognizerImpl {
bool has_context_graph = false;

for (int32_t i = 0; i != n; ++i) {
if (!has_context_graph && ss[i]->GetContextGraph())
if (!has_context_graph && ss[i]->GetContextGraph()) {
has_context_graph = true;
}

const auto num_processed_frames = ss[i]->GetNumProcessedFrames();
std::vector<float> features =
Expand Down
14 changes: 13 additions & 1 deletion sherpa-onnx/csrc/online-recognizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,20 @@ bool OnlineRecognizerConfig::Validate() const {
max_active_paths);
return false;
}
if (!lm_config.Validate()) return false;

if (!lm_config.Validate()) {
return false;
}
}

if (!hotwords_file.empty() && decoding_method != "modified_beam_search") {
SHERPA_ONNX_LOGE(
"Please use --decoding-method=modified_beam_search if you"
" provide --hotwords-file. Given --decoding-method=%s",
decoding_method.c_str());
return false;
}

return model_config.Validate();
}

Expand Down
2 changes: 0 additions & 2 deletions sherpa-onnx/python/sherpa_onnx/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Dict, List, Optional

from _sherpa_onnx import (
CircularBuffer,
Display,
Expand Down
6 changes: 6 additions & 0 deletions sherpa-onnx/python/sherpa_onnx/offline_recognizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ def from_transducer(
feature_dim=feature_dim,
)

if len(hotwords_file) > 0 and decoding_method != "modified_beam_search":
raise ValueError(
"Please use --decoding-method=modified_beam_search when using "
f"--hotwords-file. Currently given: {decoding_method}"
)

recognizer_config = OfflineRecognizerConfig(
feat_config=feat_config,
model_config=model_config,
Expand Down
6 changes: 6 additions & 0 deletions sherpa-onnx/python/sherpa_onnx/online_recognizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ def from_transducer(
rule3_min_utterance_length=rule3_min_utterance_length,
)

if len(hotwords_file) > 0 and decoding_method != "modified_beam_search":
raise ValueError(
"Please use --decoding-method=modified_beam_search when using "
f"--hotwords-file. Currently given: {decoding_method}"
)

recognizer_config = OnlineRecognizerConfig(
feat_config=feat_config,
model_config=model_config,
Expand Down

0 comments on commit 33a5765

Please sign in to comment.