post_latgen_faster_mapped.h 2.8 KB
Newer Older
Y
Yibing Liu 已提交
1
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
Y
Yibing Liu 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

#include <string>
#include <vector>
17 18 19
#include "base/kaldi-common.h"
#include "base/timer.h"
#include "decoder/decodable-matrix.h"
Y
Yibing Liu 已提交
20 21
#include "decoder/decoder-wrappers.h"
#include "fstext/kaldi-fst-io.h"
22 23 24
#include "hmm/transition-model.h"
#include "tree/context-dep.h"
#include "util/common-utils.h"
Y
Yibing Liu 已提交
25

26 27
class Decoder {
public:
Y
Yibing Liu 已提交
28 29
  Decoder(std::string trans_model_in_filename,
          std::string word_syms_filename,
30
          std::string fst_in_filename,
Y
Yibing Liu 已提交
31
          std::string logprior_in_filename,
Y
Yibing Liu 已提交
32
          size_t beam_size,
33
          kaldi::BaseFloat acoustic_scale);
34 35
  ~Decoder();

36 37 38 39
  // Interface to accept the scores read from specifier and print
  // the decoding results directly
  void decode_from_file(std::string posterior_rspecifier,
                        size_t num_processes = 1);
40

Y
Yibing Liu 已提交
41
  // Accept the scores of one utterance and return the decoding result
Y
Yibing Liu 已提交
42 43 44
  std::string decode(
      std::string key,
      const std::vector<std::vector<kaldi::BaseFloat>> &log_probs);
45

46 47 48 49
  // Accept the scores of utterances in batch and return the decoding results
  std::vector<std::string> decode_batch(
      std::vector<std::string> key,
      const std::vector<std::vector<std::vector<kaldi::BaseFloat>>>
50 51
          &log_probs_batch,
      size_t num_processes = 1);
52

53
private:
Y
Yibing Liu 已提交
54
  // For decoding one utterance
55 56 57 58 59 60
  std::string decode_internal(kaldi::LatticeFasterDecoder *decoder,
                              std::string key,
                              kaldi::Matrix<kaldi::BaseFloat> &loglikes);

  std::string DecodeUtteranceLatticeFaster(kaldi::LatticeFasterDecoder *decoder,
                                           kaldi::DecodableInterface &decodable,
61 62
                                           std::string utt,
                                           double *like_ptr);
63

64
  fst::SymbolTable *word_syms;
Y
Yibing Liu 已提交
65
  fst::Fst<fst::StdArc> *decode_fst;
66
  std::vector<kaldi::LatticeFasterDecoder *> decoder_pool;
67
  kaldi::Vector<kaldi::BaseFloat> logprior;
Y
Yibing Liu 已提交
68
  kaldi::TransitionModel trans_model;
69
  kaldi::LatticeFasterDecoderConfig config;
Y
Yibing Liu 已提交
70 71 72 73 74

  kaldi::CompactLatticeWriter compact_lattice_writer;
  kaldi::LatticeWriter lattice_writer;
  kaldi::Int32VectorWriter *words_writer;
  kaldi::Int32VectorWriter *alignment_writer;
75 76

  bool binary;
Y
Yibing Liu 已提交
77
  bool determinize;
78 79 80
  kaldi::BaseFloat acoustic_scale;
  bool allow_partial;
};