ctc_decoders.h 2.4 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 30

 * 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.
 *     blank_id: ID of blank.
31 32
 *     cutoff_prob: Cutoff probability for pruning.
 *     cutoff_top_n: Cutoff number for pruning.
33 34 35 36 37
 *     ext_scorer: External scorer to evaluate a prefix.
 * Return:
 *     A vector that each element is a pair of score  and decoding result,
 *     in desending order.
*/
Y
Yibing Liu 已提交
38
std::vector<std::pair<double, std::string>> ctc_beam_search_decoder(
Y
Yibing Liu 已提交
39
    const std::vector<std::vector<double>> &probs_seq,
Y
Yibing Liu 已提交
40 41 42 43 44 45
    int beam_size,
    std::vector<std::string> vocabulary,
    int blank_id,
    double cutoff_prob = 1.0,
    int cutoff_top_n = 40,
    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 56
 *     blank_id: ID of blank.
 *     num_processes: Number of threads for beam search.
57 58
 *     cutoff_prob: Cutoff probability for pruning.
 *     cutoff_top_n: Cutoff number for pruning.
59
 *     ext_scorer: External scorer to evaluate a prefix.
60
 * Return:
Y
Yibing Liu 已提交
61 62
 *     A 2-D vector that each element is a vector of beam search decoding
 *     result for one audio sample.
63 64
*/
std::vector<std::vector<std::pair<double, std::string>>>
Y
Yibing Liu 已提交
65
ctc_beam_search_decoder_batch(
Y
Yibing Liu 已提交
66
    const std::vector<std::vector<std::vector<double>>> &probs_split,
Y
Yibing Liu 已提交
67
    int beam_size,
Y
Yibing Liu 已提交
68
    const std::vector<std::string> &vocabulary,
Y
Yibing Liu 已提交
69 70 71 72 73
    int blank_id,
    int num_processes,
    double cutoff_prob = 1.0,
    int cutoff_top_n = 40,
    Scorer *ext_scorer = NULL);
Y
Yibing Liu 已提交
74

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