post_latgen_faster_mapped.h 2.5 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();

Y
Yibing Liu 已提交
35 36
  // Interface to accept the scores read from specifier and return
  // the batch decoding results
37 38
  std::vector<std::string> decode(std::string posterior_rspecifier);

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

44 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>>>
          &log_probs_batch);

50
private:
Y
Yibing Liu 已提交
51
  // For decoding one utterance
52 53
  std::string decode(std::string key,
                     kaldi::Matrix<kaldi::BaseFloat> &loglikes);
54 55 56
  std::string DecodeUtteranceLatticeFaster(kaldi::DecodableInterface &decodable,
                                           std::string utt,
                                           double *like_ptr);
57

58
  fst::SymbolTable *word_syms;
Y
Yibing Liu 已提交
59 60
  fst::Fst<fst::StdArc> *decode_fst;
  kaldi::LatticeFasterDecoder *decoder;
61
  kaldi::Vector<kaldi::BaseFloat> logprior;
Y
Yibing Liu 已提交
62 63 64 65 66 67
  kaldi::TransitionModel trans_model;

  kaldi::CompactLatticeWriter compact_lattice_writer;
  kaldi::LatticeWriter lattice_writer;
  kaldi::Int32VectorWriter *words_writer;
  kaldi::Int32VectorWriter *alignment_writer;
68 69

  bool binary;
Y
Yibing Liu 已提交
70
  bool determinize;
71 72 73
  kaldi::BaseFloat acoustic_scale;
  bool allow_partial;
};