ctc_beam_search_decoder.h 2.2 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
/* CTC Beam Search Decoder
11 12 13 14 15

 * 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.
16
 *     beam_size: The width of beam search.
17 18
 *     cutoff_prob: Cutoff probability for pruning.
 *     cutoff_top_n: Cutoff number for pruning.
Y
Yibing Liu 已提交
19 20 21
 *     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.
22 23 24 25
 * Return:
 *     A vector that each element is a pair of score  and decoding result,
 *     in desending order.
*/
Y
Yibing Liu 已提交
26
std::vector<std::pair<double, std::string>> ctc_beam_search_decoder(
Y
Yibing Liu 已提交
27
    const std::vector<std::vector<double>> &probs_seq,
28
    const std::vector<std::string> &vocabulary,
29 30 31 32
    size_t beam_size,
    double cutoff_prob = 1.0,
    size_t cutoff_top_n = 40,
    Scorer *ext_scorer = nullptr);
33

34
/* CTC Beam Search Decoder for batch data
35

36
 * Parameters:
37 38
 *     probs_seq: 3-D vector that each element is a 2-D vector that can be used
 *                by ctc_beam_search_decoder().
39
 *     vocabulary: A vector of vocabulary.
40
 *     beam_size: The width of beam search.
41
 *     num_processes: Number of threads for beam search.
42 43
 *     cutoff_prob: Cutoff probability for pruning.
 *     cutoff_top_n: Cutoff number for pruning.
Y
Yibing Liu 已提交
44 45 46
 *     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.
47
 * Return:
Y
Yibing Liu 已提交
48 49
 *     A 2-D vector that each element is a vector of beam search decoding
 *     result for one audio sample.
50 51
*/
std::vector<std::vector<std::pair<double, std::string>>>
Y
Yibing Liu 已提交
52
ctc_beam_search_decoder_batch(
Y
Yibing Liu 已提交
53 54
    const std::vector<std::vector<std::vector<double>>> &probs_split,
    const std::vector<std::string> &vocabulary,
55
    size_t beam_size,
56
    size_t num_processes,
Y
Yibing Liu 已提交
57
    double cutoff_prob = 1.0,
58 59
    size_t cutoff_top_n = 40,
    Scorer *ext_scorer = nullptr);
Y
Yibing Liu 已提交
60

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