Add lm decode for the Python API. (#353)
* Add lm decode for the Python API. * fix style. * Fix LogAdd, Shouldn't double lm_log_prob when merge same prefix path * sort the import alphabetically
This commit is contained in:
@@ -37,6 +37,7 @@ static void PybindOnlineRecognizerConfig(py::module *m) {
|
||||
py::arg("hotwords_score") = 0)
|
||||
.def_readwrite("feat_config", &PyClass::feat_config)
|
||||
.def_readwrite("model_config", &PyClass::model_config)
|
||||
.def_readwrite("lm_config", &PyClass::lm_config)
|
||||
.def_readwrite("endpoint_config", &PyClass::endpoint_config)
|
||||
.def_readwrite("enable_endpoint", &PyClass::enable_endpoint)
|
||||
.def_readwrite("decoding_method", &PyClass::decoding_method)
|
||||
|
||||
@@ -5,6 +5,7 @@ from typing import List, Optional
|
||||
from _sherpa_onnx import (
|
||||
EndpointConfig,
|
||||
FeatureExtractorConfig,
|
||||
OnlineLMConfig,
|
||||
OnlineModelConfig,
|
||||
OnlineParaformerModelConfig,
|
||||
OnlineRecognizer as _Recognizer,
|
||||
@@ -46,6 +47,8 @@ class OnlineRecognizer(object):
|
||||
hotwords_file: str = "",
|
||||
provider: str = "cpu",
|
||||
model_type: str = "",
|
||||
lm: str = "",
|
||||
lm_scale: float = 0.1,
|
||||
):
|
||||
"""
|
||||
Please refer to
|
||||
@@ -137,10 +140,22 @@ class OnlineRecognizer(object):
|
||||
"Please use --decoding-method=modified_beam_search when using "
|
||||
f"--hotwords-file. Currently given: {decoding_method}"
|
||||
)
|
||||
|
||||
if lm and decoding_method != "modified_beam_search":
|
||||
raise ValueError(
|
||||
"Please use --decoding-method=modified_beam_search when using "
|
||||
f"--lm. Currently given: {decoding_method}"
|
||||
)
|
||||
|
||||
lm_config = OnlineLMConfig(
|
||||
model=lm,
|
||||
scale=lm_scale,
|
||||
)
|
||||
|
||||
recognizer_config = OnlineRecognizerConfig(
|
||||
feat_config=feat_config,
|
||||
model_config=model_config,
|
||||
lm_config=lm_config,
|
||||
endpoint_config=endpoint_config,
|
||||
enable_endpoint=enable_endpoint_detection,
|
||||
decoding_method=decoding_method,
|
||||
|
||||
Reference in New Issue
Block a user