ctc_beam_search_decoder.h 2.3 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 16

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

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