Begin to support CTC models (#119)
Please see https://k2-fsa.github.io/sherpa/onnx/pretrained_models/offline-ctc/nemo/index.html for a list of pre-trained CTC models from NeMo.
This commit is contained in:
42
sherpa-onnx/csrc/offline-ctc-decoder.h
Normal file
42
sherpa-onnx/csrc/offline-ctc-decoder.h
Normal file
@@ -0,0 +1,42 @@
|
||||
// sherpa-onnx/csrc/offline-ctc-decoder.h
|
||||
//
|
||||
// Copyright (c) 2023 Xiaomi Corporation
|
||||
|
||||
#ifndef SHERPA_ONNX_CSRC_OFFLINE_CTC_DECODER_H_
|
||||
#define SHERPA_ONNX_CSRC_OFFLINE_CTC_DECODER_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "onnxruntime_cxx_api.h" // NOLINT
|
||||
|
||||
namespace sherpa_onnx {
|
||||
|
||||
struct OfflineCtcDecoderResult {
|
||||
/// The decoded token IDs
|
||||
std::vector<int64_t> tokens;
|
||||
|
||||
/// timestamps[i] contains the output frame index where tokens[i] is decoded.
|
||||
/// Note: The index is after subsampling
|
||||
std::vector<int32_t> timestamps;
|
||||
};
|
||||
|
||||
class OfflineCtcDecoder {
|
||||
public:
|
||||
virtual ~OfflineCtcDecoder() = default;
|
||||
|
||||
/** Run CTC decoding given the output from the encoder model.
|
||||
*
|
||||
* @param log_probs A 3-D tensor of shape (N, T, vocab_size) containing
|
||||
* lob_probs.
|
||||
* @param log_probs_length A 1-D tensor of shape (N,) containing number
|
||||
* of valid frames in log_probs before padding.
|
||||
*
|
||||
* @return Return a vector of size `N` containing the decoded results.
|
||||
*/
|
||||
virtual std::vector<OfflineCtcDecoderResult> Decode(
|
||||
Ort::Value log_probs, Ort::Value log_probs_length) = 0;
|
||||
};
|
||||
|
||||
} // namespace sherpa_onnx
|
||||
|
||||
#endif // SHERPA_ONNX_CSRC_OFFLINE_CTC_DECODER_H_
|
||||
Reference in New Issue
Block a user