ctc_decoders.h 2.7 KB
Newer Older
Y
Yibing Liu 已提交
1 2 3 4 5
#ifndef CTC_BEAM_SEARCH_DECODER_H_
#define CTC_BEAM_SEARCH_DECODER_H_

#include <string>
#include <utility>
Y
Yibing Liu 已提交
6
#include <vector>
7

Y
Yibing Liu 已提交
8 9
#include "scorer.h"

10 11 12 13 14 15 16
/* CTC Best Path Decoder
 *
 * Parameters:
 *     probs_seq: 2-D vector that each element is a vector of probabilities
 *               over vocabulary of one time step.
 *     vocabulary: A vector of vocabulary.
 * Return:
Y
Yibing Liu 已提交
17
 *     The decoding result in string
18
 */
19
std::string ctc_greedy_decoder(
Y
Yibing Liu 已提交
20 21
    const std::vector<std::vector<double>> &probs_seq,
    const std::vector<std::string> &vocabulary);
22 23

/* CTC Beam Search Decoder
24 25 26 27 28 29

 * Parameters:
 *     probs_seq: 2-D vector that each element is a vector of probabilities
 *               over vocabulary of one time step.
 *     beam_size: The width of beam search.
 *     vocabulary: A vector of vocabulary.
30 31
 *     cutoff_prob: Cutoff probability for pruning.
 *     cutoff_top_n: Cutoff number for pruning.
Y
Yibing Liu 已提交
32 33 34
 *     ext_scorer: External scorer to evaluate a prefix, which consists of
 *                 n-gram language model scoring and word insertion term.
 *                 Default null, decoding the input sample without scorer.
35 36 37 38
 * Return:
 *     A vector that each element is a pair of score  and decoding result,
 *     in desending order.
*/
Y
Yibing Liu 已提交
39
std::vector<std::pair<double, std::string>> ctc_beam_search_decoder(
Y
Yibing Liu 已提交
40
    const std::vector<std::vector<double>> &probs_seq,
Y
Yibing Liu 已提交
41
    const size_t beam_size,
Y
Yibing Liu 已提交
42
    std::vector<std::string> vocabulary,
Y
Yibing Liu 已提交
43 44
    const double cutoff_prob = 1.0,
    const size_t cutoff_top_n = 40,
Y
Yibing Liu 已提交
45
    Scorer *ext_scorer = NULL);
46

47
/* CTC Beam Search Decoder for batch data
48

49
 * Parameters:
50 51 52 53
 *     probs_seq: 3-D vector that each element is a 2-D vector that can be used
 *                by ctc_beam_search_decoder().
 *      .
 *     beam_size: The width of beam search.
54
 *     vocabulary: A vector of vocabulary.
55
 *     num_processes: Number of threads for beam search.
56 57
 *     cutoff_prob: Cutoff probability for pruning.
 *     cutoff_top_n: Cutoff number for pruning.
Y
Yibing Liu 已提交
58 59 60
 *     ext_scorer: External scorer to evaluate a prefix, which consists of
 *                 n-gram language model scoring and word insertion term.
 *                 Default null, decoding the input sample without scorer.
61
 * Return:
Y
Yibing Liu 已提交
62 63
 *     A 2-D vector that each element is a vector of beam search decoding
 *     result for one audio sample.
64 65
*/
std::vector<std::vector<std::pair<double, std::string>>>
Y
Yibing Liu 已提交
66
ctc_beam_search_decoder_batch(
Y
Yibing Liu 已提交
67
    const std::vector<std::vector<std::vector<double>>> &probs_split,
Y
Yibing Liu 已提交
68
    const size_t beam_size,
Y
Yibing Liu 已提交
69
    const std::vector<std::string> &vocabulary,
Y
Yibing Liu 已提交
70
    const size_t num_processes,
Y
Yibing Liu 已提交
71
    double cutoff_prob = 1.0,
Y
Yibing Liu 已提交
72
    const size_t cutoff_top_n = 40,
Y
Yibing Liu 已提交
73
    Scorer *ext_scorer = NULL);
Y
Yibing Liu 已提交
74

Y
Yibing Liu 已提交
75
#endif  // CTC_BEAM_SEARCH_DECODER_H_