online-punctuation-model-config.cc
1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// sherpa-onnx/csrc/online-punctuation-model-config.cc
//
// Copyright (c) 2024 Jian You (jianyou@cisco.com, Cisco Systems)
#include "sherpa-onnx/csrc/online-punctuation-model-config.h"
#include "sherpa-onnx/csrc/file-utils.h"
#include "sherpa-onnx/csrc/macros.h"
namespace sherpa_onnx {
void OnlinePunctuationModelConfig::Register(ParseOptions *po) {
po->Register("cnn-bilstm", &cnn_bilstm,
"Path to the light-weight CNN-BiLSTM model");
po->Register("bpe-vocab", &bpe_vocab, "Path to the bpe vocab file");
po->Register("num-threads", &num_threads,
"Number of threads to run the neural network");
po->Register("debug", &debug,
"true to print model information while loading it.");
po->Register("provider", &provider,
"Specify a provider to use: cpu, cuda, coreml");
}
bool OnlinePunctuationModelConfig::Validate() const {
if (cnn_bilstm.empty()) {
SHERPA_ONNX_LOGE("Please provide --cnn-bilstm");
return false;
}
if (!FileExists(cnn_bilstm)) {
SHERPA_ONNX_LOGE("--cnn-bilstm '%s' does not exist", cnn_bilstm.c_str());
return false;
}
if (bpe_vocab.empty()) {
SHERPA_ONNX_LOGE("Please provide --bpe-vocab");
return false;
}
if (!FileExists(bpe_vocab)) {
SHERPA_ONNX_LOGE("--bpe-vocab '%s' does not exist", bpe_vocab.c_str());
return false;
}
return true;
}
std::string OnlinePunctuationModelConfig::ToString() const {
std::ostringstream os;
os << "OnlinePunctuationModelConfig(";
os << "cnn_bilstm=\"" << cnn_bilstm << "\", ";
os << "bpe_vocab=\"" << bpe_vocab << "\", ";
os << "num_threads=" << num_threads << ", ";
os << "debug=" << (debug ? "True" : "False") << ", ";
os << "provider=\"" << provider << "\")";
return os.str();
}
} // namespace sherpa_onnx