Add Python API support for Offline LM rescoring (#1033)
This commit is contained in:
@@ -6,6 +6,7 @@ from typing import List, Optional
|
|||||||
from _sherpa_onnx import (
|
from _sherpa_onnx import (
|
||||||
FeatureExtractorConfig,
|
FeatureExtractorConfig,
|
||||||
OfflineCtcFstDecoderConfig,
|
OfflineCtcFstDecoderConfig,
|
||||||
|
OfflineLMConfig,
|
||||||
OfflineModelConfig,
|
OfflineModelConfig,
|
||||||
OfflineNemoEncDecCtcModelConfig,
|
OfflineNemoEncDecCtcModelConfig,
|
||||||
OfflineParaformerModelConfig,
|
OfflineParaformerModelConfig,
|
||||||
@@ -56,6 +57,8 @@ class OfflineRecognizer(object):
|
|||||||
model_type: str = "transducer",
|
model_type: str = "transducer",
|
||||||
rule_fsts: str = "",
|
rule_fsts: str = "",
|
||||||
rule_fars: str = "",
|
rule_fars: str = "",
|
||||||
|
lm: str = "",
|
||||||
|
lm_scale: float = 0.1,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Please refer to
|
Please refer to
|
||||||
@@ -143,9 +146,21 @@ class OfflineRecognizer(object):
|
|||||||
f"--hotwords-file. Currently given: {decoding_method}"
|
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 = OfflineLMConfig(
|
||||||
|
model=lm,
|
||||||
|
scale=lm_scale,
|
||||||
|
)
|
||||||
|
|
||||||
recognizer_config = OfflineRecognizerConfig(
|
recognizer_config = OfflineRecognizerConfig(
|
||||||
feat_config=feat_config,
|
feat_config=feat_config,
|
||||||
model_config=model_config,
|
model_config=model_config,
|
||||||
|
lm_config=lm_config,
|
||||||
decoding_method=decoding_method,
|
decoding_method=decoding_method,
|
||||||
max_active_paths=max_active_paths,
|
max_active_paths=max_active_paths,
|
||||||
hotwords_file=hotwords_file,
|
hotwords_file=hotwords_file,
|
||||||
|
|||||||
Reference in New Issue
Block a user