This repository has been archived on 2025-08-26. You can view files and clone it, but cannot push or open issues or pull requests.
Files
enginex_bi_series-sherpa-onnx/sherpa-onnx/csrc/utils.h
Yunus Emre Özköse 1e75e0958d First working version.
2022-09-23 08:46:25 +03:00

40 lines
1.1 KiB
C++

#include <iostream>
#include <fstream>
void vector2file(std::vector<float> vector, std::string saveFileName){
std::ofstream f(saveFileName);
for(std::vector<float>::const_iterator i = vector.begin(); i != vector.end(); ++i) {
f << *i << '\n';
}
}
std::vector<std::string> hyps2result(std::map<int, std::string> token_map, std::vector<std::vector<int32_t>> hyps, int context_size = 2){
std::vector<std::string> results;
for (int k=0; k < hyps.size(); k++){
std::string result = token_map[hyps[k][context_size]];
for (int i=context_size+1; i < hyps[k].size(); i++){
std::string token = token_map[hyps[k][i]];
// TODO: recognising '_' is not working
if (token.at(0) == '_')
result += " " + token;
else
result += token;
}
results.push_back(result);
}
return results;
}
void print_hyps(std::vector<std::vector<int32_t>> hyps, int context_size = 2){
std::cout << "Hyps:" << std::endl;
for (int i=context_size; i<hyps[0].size(); i++)
std::cout << hyps[0][i] << "-";
std::cout << "|" << std::endl;
}