Add CTC HLG decoding using OpenFst (#349)
This commit is contained in:
@@ -5,6 +5,7 @@ pybind11_add_module(_sherpa_onnx
|
||||
display.cc
|
||||
endpoint.cc
|
||||
features.cc
|
||||
offline-ctc-fst-decoder-config.cc
|
||||
offline-lm-config.cc
|
||||
offline-model-config.cc
|
||||
offline-nemo-enc-dec-ctc-model-config.cc
|
||||
@@ -14,6 +15,7 @@ pybind11_add_module(_sherpa_onnx
|
||||
offline-tdnn-model-config.cc
|
||||
offline-transducer-model-config.cc
|
||||
offline-whisper-model-config.cc
|
||||
offline-zipformer-ctc-model-config.cc
|
||||
online-lm-config.cc
|
||||
online-model-config.cc
|
||||
online-paraformer-model-config.cc
|
||||
|
||||
23
sherpa-onnx/python/csrc/offline-ctc-fst-decoder-config.cc
Normal file
23
sherpa-onnx/python/csrc/offline-ctc-fst-decoder-config.cc
Normal file
@@ -0,0 +1,23 @@
|
||||
// sherpa-onnx/python/csrc/offline-ctc-fst-decoder-config.cc
|
||||
//
|
||||
// Copyright (c) 2023 Xiaomi Corporation
|
||||
|
||||
#include "sherpa-onnx/python/csrc/offline-ctc-fst-decoder-config.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "sherpa-onnx/csrc/offline-ctc-fst-decoder-config.h"
|
||||
|
||||
namespace sherpa_onnx {
|
||||
|
||||
void PybindOfflineCtcFstDecoderConfig(py::module *m) {
|
||||
using PyClass = OfflineCtcFstDecoderConfig;
|
||||
py::class_<PyClass>(*m, "OfflineCtcFstDecoderConfig")
|
||||
.def(py::init<const std::string &, int32_t>(), py::arg("graph") = "",
|
||||
py::arg("max_active") = 3000)
|
||||
.def_readwrite("graph", &PyClass::graph)
|
||||
.def_readwrite("max_active", &PyClass::max_active)
|
||||
.def("__str__", &PyClass::ToString);
|
||||
}
|
||||
|
||||
} // namespace sherpa_onnx
|
||||
16
sherpa-onnx/python/csrc/offline-ctc-fst-decoder-config.h
Normal file
16
sherpa-onnx/python/csrc/offline-ctc-fst-decoder-config.h
Normal file
@@ -0,0 +1,16 @@
|
||||
// sherpa-onnx/python/csrc/offline-ctc-fst-decoder-config.h
|
||||
//
|
||||
// Copyright (c) 2023 Xiaomi Corporation
|
||||
|
||||
#ifndef SHERPA_ONNX_PYTHON_CSRC_OFFLINE_CTC_FST_DECODER_CONFIG_H_
|
||||
#define SHERPA_ONNX_PYTHON_CSRC_OFFLINE_CTC_FST_DECODER_CONFIG_H_
|
||||
|
||||
#include "sherpa-onnx/python/csrc/sherpa-onnx.h"
|
||||
|
||||
namespace sherpa_onnx {
|
||||
|
||||
void PybindOfflineCtcFstDecoderConfig(py::module *m);
|
||||
|
||||
}
|
||||
|
||||
#endif // SHERPA_ONNX_PYTHON_CSRC_OFFLINE_CTC_FST_DECODER_CONFIG_H_
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "sherpa-onnx/python/csrc/offline-tdnn-model-config.h"
|
||||
#include "sherpa-onnx/python/csrc/offline-transducer-model-config.h"
|
||||
#include "sherpa-onnx/python/csrc/offline-whisper-model-config.h"
|
||||
#include "sherpa-onnx/python/csrc/offline-zipformer-ctc-model-config.h"
|
||||
|
||||
namespace sherpa_onnx {
|
||||
|
||||
@@ -22,6 +23,7 @@ void PybindOfflineModelConfig(py::module *m) {
|
||||
PybindOfflineNemoEncDecCtcModelConfig(m);
|
||||
PybindOfflineWhisperModelConfig(m);
|
||||
PybindOfflineTdnnModelConfig(m);
|
||||
PybindOfflineZipformerCtcModelConfig(m);
|
||||
|
||||
using PyClass = OfflineModelConfig;
|
||||
py::class_<PyClass>(*m, "OfflineModelConfig")
|
||||
@@ -29,20 +31,23 @@ void PybindOfflineModelConfig(py::module *m) {
|
||||
const OfflineParaformerModelConfig &,
|
||||
const OfflineNemoEncDecCtcModelConfig &,
|
||||
const OfflineWhisperModelConfig &,
|
||||
const OfflineTdnnModelConfig &, const std::string &,
|
||||
const OfflineTdnnModelConfig &,
|
||||
const OfflineZipformerCtcModelConfig &, const std::string &,
|
||||
int32_t, bool, const std::string &, const std::string &>(),
|
||||
py::arg("transducer") = OfflineTransducerModelConfig(),
|
||||
py::arg("paraformer") = OfflineParaformerModelConfig(),
|
||||
py::arg("nemo_ctc") = OfflineNemoEncDecCtcModelConfig(),
|
||||
py::arg("whisper") = OfflineWhisperModelConfig(),
|
||||
py::arg("tdnn") = OfflineTdnnModelConfig(), py::arg("tokens"),
|
||||
py::arg("num_threads"), py::arg("debug") = false,
|
||||
py::arg("tdnn") = OfflineTdnnModelConfig(),
|
||||
py::arg("zipformer_ctc") = OfflineZipformerCtcModelConfig(),
|
||||
py::arg("tokens"), py::arg("num_threads"), py::arg("debug") = false,
|
||||
py::arg("provider") = "cpu", py::arg("model_type") = "")
|
||||
.def_readwrite("transducer", &PyClass::transducer)
|
||||
.def_readwrite("paraformer", &PyClass::paraformer)
|
||||
.def_readwrite("nemo_ctc", &PyClass::nemo_ctc)
|
||||
.def_readwrite("whisper", &PyClass::whisper)
|
||||
.def_readwrite("tdnn", &PyClass::tdnn)
|
||||
.def_readwrite("zipformer_ctc", &PyClass::zipformer_ctc)
|
||||
.def_readwrite("tokens", &PyClass::tokens)
|
||||
.def_readwrite("num_threads", &PyClass::num_threads)
|
||||
.def_readwrite("debug", &PyClass::debug)
|
||||
|
||||
@@ -16,15 +16,18 @@ static void PybindOfflineRecognizerConfig(py::module *m) {
|
||||
py::class_<PyClass>(*m, "OfflineRecognizerConfig")
|
||||
.def(py::init<const OfflineFeatureExtractorConfig &,
|
||||
const OfflineModelConfig &, const OfflineLMConfig &,
|
||||
const std::string &, int32_t, const std::string &, float>(),
|
||||
const OfflineCtcFstDecoderConfig &, const std::string &,
|
||||
int32_t, const std::string &, float>(),
|
||||
py::arg("feat_config"), py::arg("model_config"),
|
||||
py::arg("lm_config") = OfflineLMConfig(),
|
||||
py::arg("ctc_fst_decoder_config") = OfflineCtcFstDecoderConfig(),
|
||||
py::arg("decoding_method") = "greedy_search",
|
||||
py::arg("max_active_paths") = 4, py::arg("hotwords_file") = "",
|
||||
py::arg("hotwords_score") = 1.5)
|
||||
.def_readwrite("feat_config", &PyClass::feat_config)
|
||||
.def_readwrite("model_config", &PyClass::model_config)
|
||||
.def_readwrite("lm_config", &PyClass::lm_config)
|
||||
.def_readwrite("ctc_fst_decoder_config", &PyClass::ctc_fst_decoder_config)
|
||||
.def_readwrite("decoding_method", &PyClass::decoding_method)
|
||||
.def_readwrite("max_active_paths", &PyClass::max_active_paths)
|
||||
.def_readwrite("hotwords_file", &PyClass::hotwords_file)
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// sherpa-onnx/python/csrc/offline-zipformer-ctc-model-config.cc
|
||||
//
|
||||
// Copyright (c) 2023 Xiaomi Corporation
|
||||
|
||||
#include "sherpa-onnx/python/csrc/offline-zipformer-ctc-model-config.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "sherpa-onnx/csrc/offline-zipformer-ctc-model-config.h"
|
||||
|
||||
namespace sherpa_onnx {
|
||||
|
||||
void PybindOfflineZipformerCtcModelConfig(py::module *m) {
|
||||
using PyClass = OfflineZipformerCtcModelConfig;
|
||||
py::class_<PyClass>(*m, "OfflineZipformerCtcModelConfig")
|
||||
.def(py::init<>())
|
||||
.def(py::init<const std::string &>(), py::arg("model"))
|
||||
.def_readwrite("model", &PyClass::model)
|
||||
.def("__str__", &PyClass::ToString);
|
||||
}
|
||||
|
||||
} // namespace sherpa_onnx
|
||||
16
sherpa-onnx/python/csrc/offline-zipformer-ctc-model-config.h
Normal file
16
sherpa-onnx/python/csrc/offline-zipformer-ctc-model-config.h
Normal file
@@ -0,0 +1,16 @@
|
||||
// sherpa-onnx/python/csrc/offline-zipformer-ctc-model-config.h
|
||||
//
|
||||
// Copyright (c) 2023 Xiaomi Corporation
|
||||
|
||||
#ifndef SHERPA_ONNX_PYTHON_CSRC_OFFLINE_ZIPFORMER_CTC_MODEL_CONFIG_H_
|
||||
#define SHERPA_ONNX_PYTHON_CSRC_OFFLINE_ZIPFORMER_CTC_MODEL_CONFIG_H_
|
||||
|
||||
#include "sherpa-onnx/python/csrc/sherpa-onnx.h"
|
||||
|
||||
namespace sherpa_onnx {
|
||||
|
||||
void PybindOfflineZipformerCtcModelConfig(py::module *m);
|
||||
|
||||
}
|
||||
|
||||
#endif // SHERPA_ONNX_PYTHON_CSRC_OFFLINE_ZIPFORMER_CTC_MODEL_CONFIG_H_
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "sherpa-onnx/python/csrc/display.h"
|
||||
#include "sherpa-onnx/python/csrc/endpoint.h"
|
||||
#include "sherpa-onnx/python/csrc/features.h"
|
||||
#include "sherpa-onnx/python/csrc/offline-ctc-fst-decoder-config.h"
|
||||
#include "sherpa-onnx/python/csrc/offline-lm-config.h"
|
||||
#include "sherpa-onnx/python/csrc/offline-model-config.h"
|
||||
#include "sherpa-onnx/python/csrc/offline-recognizer.h"
|
||||
@@ -37,6 +38,7 @@ PYBIND11_MODULE(_sherpa_onnx, m) {
|
||||
PybindOfflineStream(&m);
|
||||
PybindOfflineLMConfig(&m);
|
||||
PybindOfflineModelConfig(&m);
|
||||
PybindOfflineCtcFstDecoderConfig(&m);
|
||||
PybindOfflineRecognizer(&m);
|
||||
|
||||
PybindVadModelConfig(&m);
|
||||
|
||||
@@ -4,12 +4,14 @@ from pathlib import Path
|
||||
from typing import List, Optional
|
||||
|
||||
from _sherpa_onnx import (
|
||||
OfflineCtcFstDecoderConfig,
|
||||
OfflineFeatureExtractorConfig,
|
||||
OfflineModelConfig,
|
||||
OfflineNemoEncDecCtcModelConfig,
|
||||
OfflineParaformerModelConfig,
|
||||
OfflineTdnnModelConfig,
|
||||
OfflineWhisperModelConfig,
|
||||
OfflineZipformerCtcModelConfig,
|
||||
)
|
||||
from _sherpa_onnx import OfflineRecognizer as _Recognizer
|
||||
from _sherpa_onnx import (
|
||||
|
||||
Reference in New Issue
Block a user