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,
32
          kaldi::BaseFloat acoustic_scale);
33 34
  ~Decoder();

35 36 37 38
  // 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);
39

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

45 46 47 48
  // 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>>>
49 50
          &log_probs_batch,
      size_t num_processes = 1);
51

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

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

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

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

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