From 1d7bbbffb6a024a33859b48a7a656d0455dc0be1 Mon Sep 17 00:00:00 2001
From: zhifu gao <zhifu.gzf@alibaba-inc.com>
Date: 星期一, 16 十月 2023 11:47:59 +0800
Subject: [PATCH] Update README.md
---
funasr/runtime/onnxruntime/src/ct-transformer.cpp | 49 +++++++++++++++++++++++++++++++++++--------------
1 files changed, 35 insertions(+), 14 deletions(-)
diff --git a/funasr/runtime/onnxruntime/src/ct-transformer.cpp b/funasr/runtime/onnxruntime/src/ct-transformer.cpp
index 30a1810..71a8847 100644
--- a/funasr/runtime/onnxruntime/src/ct-transformer.cpp
+++ b/funasr/runtime/onnxruntime/src/ct-transformer.cpp
@@ -17,11 +17,12 @@
session_options.DisableCpuMemArena();
try{
- m_session = std::make_unique<Ort::Session>(env_, punc_model.c_str(), session_options);
+ m_session = std::make_unique<Ort::Session>(env_, ORTSTRING(punc_model).c_str(), session_options);
+ LOG(INFO) << "Successfully load model from " << punc_model;
}
catch (std::exception const &e) {
LOG(ERROR) << "Error when load punc onnx model: " << e.what();
- exit(0);
+ exit(-1);
}
// read inputnames outputnames
string strName;
@@ -45,7 +46,7 @@
{
}
-string CTTransformer::AddPunc(const char* sz_input)
+string CTTransformer::AddPunc(const char* sz_input, std::string language)
{
string strResult;
vector<string> strOut;
@@ -65,8 +66,8 @@
for (size_t i = 0; i < InputData.size(); i += TOKEN_LEN)
{
nDiff = (i + TOKEN_LEN) < InputData.size() ? (0) : (i + TOKEN_LEN - InputData.size());
- vector<int32_t> InputIDs(InputData.begin() + i, InputData.begin() + i + TOKEN_LEN - nDiff);
- vector<string> InputStr(strOut.begin() + i, strOut.begin() + i + TOKEN_LEN - nDiff);
+ vector<int32_t> InputIDs(InputData.begin() + i, InputData.begin() + i + (TOKEN_LEN - nDiff));
+ vector<string> InputStr(strOut.begin() + i, strOut.begin() + i + (TOKEN_LEN - nDiff));
InputIDs.insert(InputIDs.begin(), RemainIDs.begin(), RemainIDs.end()); // RemainIDs+InputIDs;
InputStr.insert(InputStr.begin(), RemainStr.begin(), RemainStr.end()); // RemainStr+InputStr;
@@ -93,19 +94,20 @@
nSentEnd = nLastCommaIndex;
Punction[nSentEnd] = PERIOD_INDEX;
}
- RemainStr.assign(InputStr.begin() + nSentEnd + 1, InputStr.end());
- RemainIDs.assign(InputIDs.begin() + nSentEnd + 1, InputIDs.end());
- InputStr.assign(InputStr.begin(), InputStr.begin() + nSentEnd + 1); // minit_sentence
- Punction.assign(Punction.begin(), Punction.begin() + nSentEnd + 1);
+ RemainStr.assign(InputStr.begin() + (nSentEnd + 1), InputStr.end());
+ RemainIDs.assign(InputIDs.begin() + (nSentEnd + 1), InputIDs.end());
+ InputStr.assign(InputStr.begin(), InputStr.begin() + (nSentEnd + 1)); // minit_sentence
+ Punction.assign(Punction.begin(), Punction.begin() + (nSentEnd + 1));
}
NewPunctuation.insert(NewPunctuation.end(), Punction.begin(), Punction.end());
vector<string> WordWithPunc;
for (int i = 0; i < InputStr.size(); i++)
{
- if (i > 0 && !(InputStr[i][0] & 0x80) && (i + 1) <InputStr.size() && !(InputStr[i+1][0] & 0x80))// 锟叫硷拷锟接拷模锟�
+ // if (i > 0 && !(InputStr[i][0] & 0x80) && (i + 1) <InputStr.size() && !(InputStr[i+1][0] & 0x80))// 锟叫硷拷锟接拷模锟�
+ if (i > 0 && !(InputStr[i-1][0] & 0x80) && !(InputStr[i][0] & 0x80))
{
- InputStr[i] = InputStr[i]+ " ";
+ InputStr[i] = " " + InputStr[i];
}
WordWithPunc.push_back(InputStr[i]);
@@ -137,8 +139,28 @@
}
}
}
- for (auto& item : NewSentenceOut)
+
+ for (auto& item : NewSentenceOut){
strResult += item;
+ }
+
+ if(language == "en-bpe"){
+ std::vector<std::string> chineseSymbols;
+ chineseSymbols.push_back("锛�");
+ chineseSymbols.push_back("銆�");
+ chineseSymbols.push_back("銆�");
+ chineseSymbols.push_back("锛�");
+
+ std::string englishSymbols = ",.,?";
+ for (size_t i = 0; i < chineseSymbols.size(); i++) {
+ size_t pos = 0;
+ while ((pos = strResult.find(chineseSymbols[i], pos)) != std::string::npos) {
+ strResult.replace(pos, 3, 1, englishSymbols[i]);
+ pos++;
+ }
+ }
+ }
+
return strResult;
}
@@ -182,9 +204,8 @@
catch (std::exception const &e)
{
LOG(ERROR) << "Error when run punc onnx forword: " << (e.what());
- exit(0);
}
return punction;
}
-} // namespace funasr
\ No newline at end of file
+} // namespace funasr
--
Gitblit v1.9.1