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-mr_series-sherpa-onnx/sherpa-onnx/csrc/offline-paraformer-greedy-search-decoder.cc

35 lines
936 B
C++
Raw Normal View History

2023-03-28 17:59:54 +08:00
// sherpa-onnx/csrc/offline-paraformer-greedy-search-decoder.cc
//
// Copyright (c) 2023 Xiaomi Corporation
#include "sherpa-onnx/csrc/offline-paraformer-greedy-search-decoder.h"
#include <vector>
namespace sherpa_onnx {
std::vector<OfflineParaformerDecoderResult>
OfflineParaformerGreedySearchDecoder::Decode(Ort::Value /*log_probs*/,
Ort::Value token_num) {
std::vector<int64_t> shape = token_num.GetTensorTypeAndShapeInfo().GetShape();
int32_t batch_size = shape[0];
int32_t num_tokens = shape[1];
std::vector<OfflineParaformerDecoderResult> results(batch_size);
const int64_t *p = token_num.GetTensorData<int64_t>();
for (int32_t i = 0; i != batch_size; ++i) {
for (int32_t k = 0; k != num_tokens; ++k) {
if (p[k] == eos_id_) break;
results[i].tokens.push_back(p[k]);
}
p += num_tokens;
}
return results;
}
} // namespace sherpa_onnx