Fix code style issues (#774)
This commit is contained in:
@@ -26,8 +26,7 @@ void FeatureExtractorConfig::Register(ParseOptions *po) {
|
||||
po->Register("feat-dim", &feature_dim,
|
||||
"Feature dimension. Must match the one expected by the model.");
|
||||
|
||||
po->Register("low-freq", &low_freq,
|
||||
"Low cutoff frequency for mel bins");
|
||||
po->Register("low-freq", &low_freq, "Low cutoff frequency for mel bins");
|
||||
|
||||
po->Register("high-freq", &high_freq,
|
||||
"High cutoff frequency for mel bins "
|
||||
|
||||
@@ -80,8 +80,7 @@ class OfflineRecognizerTransducerImpl : public OfflineRecognizerImpl {
|
||||
InitHotwords();
|
||||
}
|
||||
if (config_.decoding_method == "greedy_search") {
|
||||
decoder_ =
|
||||
std::make_unique<OfflineTransducerGreedySearchDecoder>(
|
||||
decoder_ = std::make_unique<OfflineTransducerGreedySearchDecoder>(
|
||||
model_.get(), config_.blank_penalty);
|
||||
} else if (config_.decoding_method == "modified_beam_search") {
|
||||
if (!config_.lm_config.model.empty()) {
|
||||
@@ -106,8 +105,7 @@ class OfflineRecognizerTransducerImpl : public OfflineRecognizerImpl {
|
||||
model_(std::make_unique<OfflineTransducerModel>(mgr,
|
||||
config_.model_config)) {
|
||||
if (config_.decoding_method == "greedy_search") {
|
||||
decoder_ =
|
||||
std::make_unique<OfflineTransducerGreedySearchDecoder>(
|
||||
decoder_ = std::make_unique<OfflineTransducerGreedySearchDecoder>(
|
||||
model_.get(), config_.blank_penalty);
|
||||
} else if (config_.decoding_method == "modified_beam_search") {
|
||||
if (!config_.lm_config.model.empty()) {
|
||||
|
||||
@@ -16,8 +16,7 @@ class OfflineTransducerGreedySearchDecoder : public OfflineTransducerDecoder {
|
||||
public:
|
||||
explicit OfflineTransducerGreedySearchDecoder(OfflineTransducerModel *model,
|
||||
float blank_penalty)
|
||||
: model_(model),
|
||||
blank_penalty_(blank_penalty) {}
|
||||
: model_(model), blank_penalty_(blank_penalty) {}
|
||||
|
||||
std::vector<OfflineTransducerDecoderResult> Decode(
|
||||
Ort::Value encoder_out, Ort::Value encoder_out_length,
|
||||
|
||||
@@ -102,9 +102,9 @@ void OfflineWebsocketDecoder::Decode() {
|
||||
asio::post(server_->GetConnectionContext(),
|
||||
[this, hdl, result = ss[i]->GetResult()]() {
|
||||
websocketpp::lib::error_code ec;
|
||||
server_->GetServer().send(
|
||||
hdl, result.AsJsonString(),
|
||||
websocketpp::frame::opcode::text, ec);
|
||||
server_->GetServer().send(hdl, result.AsJsonString(),
|
||||
websocketpp::frame::opcode::text,
|
||||
ec);
|
||||
if (ec) {
|
||||
server_->GetServer().get_alog().write(
|
||||
websocketpp::log::alevel::app, ec.message());
|
||||
|
||||
@@ -40,8 +40,7 @@ struct OnlineModelConfig {
|
||||
const OnlineWenetCtcModelConfig &wenet_ctc,
|
||||
const OnlineZipformer2CtcModelConfig &zipformer2_ctc,
|
||||
const std::string &tokens, int32_t num_threads,
|
||||
int32_t warm_up, bool debug,
|
||||
const std::string &provider,
|
||||
int32_t warm_up, bool debug, const std::string &provider,
|
||||
const std::string &model_type)
|
||||
: transducer(transducer),
|
||||
paraformer(paraformer),
|
||||
|
||||
@@ -30,9 +30,9 @@
|
||||
#include "sherpa-onnx/csrc/online-transducer-greedy-search-decoder.h"
|
||||
#include "sherpa-onnx/csrc/online-transducer-model.h"
|
||||
#include "sherpa-onnx/csrc/online-transducer-modified-beam-search-decoder.h"
|
||||
#include "sherpa-onnx/csrc/onnx-utils.h"
|
||||
#include "sherpa-onnx/csrc/symbol-table.h"
|
||||
#include "sherpa-onnx/csrc/utils.h"
|
||||
#include "sherpa-onnx/csrc/onnx-utils.h"
|
||||
|
||||
namespace sherpa_onnx {
|
||||
|
||||
@@ -185,7 +185,7 @@ class OnlineRecognizerTransducerImpl : public OnlineRecognizerImpl {
|
||||
}
|
||||
|
||||
// Warmping up engine with wp: warm_up count and max-batch-size
|
||||
void WarmpUpRecognizer(int32_t warmup, int32_t mbs) const {
|
||||
void WarmpUpRecognizer(int32_t warmup, int32_t mbs) const override {
|
||||
auto max_batch_size = mbs;
|
||||
if (warmup <= 0 || warmup > 100) {
|
||||
return;
|
||||
@@ -210,8 +210,8 @@ class OnlineRecognizerTransducerImpl : public OnlineRecognizerImpl {
|
||||
for (int32_t i = 0; i != warmup; ++i) {
|
||||
auto states = model_->StackStates(states_vec);
|
||||
Ort::Value x = Ort::Value::CreateTensor(memory_info, features_vec.data(),
|
||||
features_vec.size(), x_shape.data(),
|
||||
x_shape.size());
|
||||
features_vec.size(),
|
||||
x_shape.data(), x_shape.size());
|
||||
auto x_copy = Clone(model_->Allocator(), &x);
|
||||
auto pair = model_->RunEncoder(std::move(x), std::move(states),
|
||||
std::move(x_copy));
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
#include "onnxruntime_cxx_api.h" // NOLINT
|
||||
#include "sherpa-onnx/csrc/macros.h"
|
||||
#include "sherpa-onnx/csrc/onnx-utils.h"
|
||||
#include "sherpa-onnx/csrc/text-utils.h"
|
||||
#include "sherpa-onnx/csrc/session.h"
|
||||
#include "sherpa-onnx/csrc/text-utils.h"
|
||||
|
||||
namespace sherpa_onnx {
|
||||
|
||||
@@ -44,8 +44,7 @@ class OnlineRnnLM::Impl {
|
||||
Ort::Value x = Ort::Value::CreateTensor<int64_t>(allocator_, x_shape.data(),
|
||||
x_shape.size());
|
||||
*x.GetTensorMutableData<int64_t>() = hyp->ys.back();
|
||||
auto lm_out =
|
||||
ScoreToken(std::move(x), Convert(hyp->nn_lm_states));
|
||||
auto lm_out = ScoreToken(std::move(x), Convert(hyp->nn_lm_states));
|
||||
hyp->nn_lm_scores.value = std::move(lm_out.first);
|
||||
hyp->nn_lm_states = Convert(std::move(lm_out.second));
|
||||
}
|
||||
|
||||
@@ -71,11 +71,9 @@ void OnlineTransducerGreedySearchDecoder::StripLeadingBlanks(
|
||||
r->tokens = std::vector<int64_t>(start, end);
|
||||
}
|
||||
|
||||
|
||||
void OnlineTransducerGreedySearchDecoder::Decode(
|
||||
Ort::Value encoder_out,
|
||||
std::vector<OnlineTransducerDecoderResult> *result) {
|
||||
|
||||
std::vector<int64_t> encoder_out_shape =
|
||||
encoder_out.GetTensorTypeAndShapeInfo().GetShape();
|
||||
|
||||
@@ -106,7 +104,8 @@ void OnlineTransducerGreedySearchDecoder::Decode(
|
||||
r.decoder_out.GetTensorTypeAndShapeInfo().GetShape();
|
||||
decoder_out_shape[0] = batch_size;
|
||||
decoder_out = Ort::Value::CreateTensor<float>(model_->Allocator(),
|
||||
decoder_out_shape.data(), decoder_out_shape.size());
|
||||
decoder_out_shape.data(),
|
||||
decoder_out_shape.size());
|
||||
UseCachedDecoderOut(*result, &decoder_out);
|
||||
} else {
|
||||
Ort::Value decoder_input = model_->BuildDecoderInput(*result);
|
||||
@@ -116,8 +115,8 @@ void OnlineTransducerGreedySearchDecoder::Decode(
|
||||
for (int32_t t = 0; t != num_frames; ++t) {
|
||||
Ort::Value cur_encoder_out =
|
||||
GetEncoderOutFrame(model_->Allocator(), &encoder_out, t);
|
||||
Ort::Value logit = model_->RunJoiner(
|
||||
std::move(cur_encoder_out), View(&decoder_out));
|
||||
Ort::Value logit =
|
||||
model_->RunJoiner(std::move(cur_encoder_out), View(&decoder_out));
|
||||
|
||||
float *p_logit = logit.GetTensorMutableData<float>();
|
||||
|
||||
|
||||
@@ -15,8 +15,7 @@ namespace sherpa_onnx {
|
||||
class OnlineTransducerGreedySearchDecoder : public OnlineTransducerDecoder {
|
||||
public:
|
||||
OnlineTransducerGreedySearchDecoder(OnlineTransducerModel *model,
|
||||
int32_t unk_id,
|
||||
float blank_penalty)
|
||||
int32_t unk_id, float blank_penalty)
|
||||
: model_(model), unk_id_(unk_id), blank_penalty_(blank_penalty) {}
|
||||
|
||||
OnlineTransducerDecoderResult GetEmptyResult() const override;
|
||||
|
||||
@@ -51,11 +51,11 @@ TEST(Stack, Test2DTensorsDim0) {
|
||||
std::array<int64_t, 2> a_shape{2, 3};
|
||||
std::array<int64_t, 2> b_shape{2, 3};
|
||||
|
||||
Ort::Value a = Ort::Value::CreateTensor<float>(
|
||||
allocator, a_shape.data(), a_shape.size());
|
||||
Ort::Value a = Ort::Value::CreateTensor<float>(allocator, a_shape.data(),
|
||||
a_shape.size());
|
||||
|
||||
Ort::Value b = Ort::Value::CreateTensor<float>(
|
||||
allocator, b_shape.data(), b_shape.size());
|
||||
Ort::Value b = Ort::Value::CreateTensor<float>(allocator, b_shape.data(),
|
||||
b_shape.size());
|
||||
|
||||
float *pa = a.GetTensorMutableData<float>();
|
||||
float *pb = b.GetTensorMutableData<float>();
|
||||
|
||||
@@ -12,10 +12,8 @@ static void PybindFeatureExtractorConfig(py::module *m) {
|
||||
using PyClass = FeatureExtractorConfig;
|
||||
py::class_<PyClass>(*m, "FeatureExtractorConfig")
|
||||
.def(py::init<int32_t, int32_t, float, float, float>(),
|
||||
py::arg("sampling_rate") = 16000,
|
||||
py::arg("feature_dim") = 80,
|
||||
py::arg("low_freq") = 20.0f,
|
||||
py::arg("high_freq") = -400.0f,
|
||||
py::arg("sampling_rate") = 16000, py::arg("feature_dim") = 80,
|
||||
py::arg("low_freq") = 20.0f, py::arg("high_freq") = -400.0f,
|
||||
py::arg("dither") = 0.0f)
|
||||
.def_readwrite("sampling_rate", &PyClass::sampling_rate)
|
||||
.def_readwrite("feature_dim", &PyClass::feature_dim)
|
||||
|
||||
@@ -23,8 +23,7 @@ static void PybindOfflineRecognizerConfig(py::module *m) {
|
||||
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,
|
||||
py::arg("blank_penalty") = 0.0)
|
||||
py::arg("hotwords_score") = 1.5, py::arg("blank_penalty") = 0.0)
|
||||
.def_readwrite("feat_config", &PyClass::feat_config)
|
||||
.def_readwrite("model_config", &PyClass::model_config)
|
||||
.def_readwrite("lm_config", &PyClass::lm_config)
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#include "sherpa-onnx/python/csrc/offline-transducer-model-config.h"
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
@@ -27,9 +27,9 @@ void PybindOnlineModelConfig(py::module *m) {
|
||||
.def(py::init<const OnlineTransducerModelConfig &,
|
||||
const OnlineParaformerModelConfig &,
|
||||
const OnlineWenetCtcModelConfig &,
|
||||
const OnlineZipformer2CtcModelConfig &,
|
||||
const std::string &, int32_t, int32_t,
|
||||
bool, const std::string &, const std::string &>(),
|
||||
const OnlineZipformer2CtcModelConfig &, const std::string &,
|
||||
int32_t, int32_t, bool, const std::string &,
|
||||
const std::string &>(),
|
||||
py::arg("transducer") = OnlineTransducerModelConfig(),
|
||||
py::arg("paraformer") = OnlineParaformerModelConfig(),
|
||||
py::arg("wenet_ctc") = OnlineWenetCtcModelConfig(),
|
||||
|
||||
Reference in New Issue
Block a user