kaldi-rnnlm.h
Go to the documentation of this file.
1 // lm/kaldi-rnnlm.h
2 
3 // Copyright 2015 Guoguo Chen
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 #ifndef KALDI_LM_KALDI_RNNLM_H_
21 #define KALDI_LM_KALDI_RNNLM_H_
22 
23 #include <string>
24 #include <vector>
25 
26 #include "base/kaldi-common.h"
28 #include "lm/mikolov-rnnlm-lib.h"
29 #include "util/common-utils.h"
30 
31 namespace kaldi {
32 
34  std::string unk_symbol;
35  std::string eos_symbol;
36 
37  KaldiRnnlmWrapperOpts() : unk_symbol("<RNN_UNK>"), eos_symbol("</s>") {}
38 
39  void Register(OptionsItf *opts) {
40  opts->Register("unk-symbol", &unk_symbol, "Symbol for out-of-vocabulary "
41  "words in rnnlm.");
42  opts->Register("eos-symbol", &eos_symbol, "End of sentence symbol in "
43  "rnnlm.");
44  }
45 };
46 
48  public:
50  const std::string &unk_prob_rspecifier,
51  const std::string &word_symbol_table_rxfilename,
52  const std::string &rnnlm_rxfilename);
53 
54  int32 GetHiddenLayerSize() const { return rnnlm_.getHiddenLayerSize(); }
55 
56  int32 GetEos() const { return eos_; }
57 
58  BaseFloat GetLogProb(int32 word, const std::vector<int32> &wseq,
59  const std::vector<float> &context_in,
60  std::vector<float> *context_out);
61 
62  private:
64  std::vector<std::string> label_to_word_;
66 
68 };
69 
71  : public fst::DeterministicOnDemandFst<fst::StdArc> {
72  public:
76 
77  // Does not take ownership.
79 
80  // We cannot use "const" because the pure virtual function in the interface is
81  // not const.
82  virtual StateId Start() { return start_state_; }
83 
84  // We cannot use "const" because the pure virtual function in the interface is
85  // not const.
86  virtual Weight Final(StateId s);
87 
88  virtual bool GetArc(StateId s, Label ilabel, fst::StdArc* oarc);
89 
90  private:
91  typedef unordered_map<std::vector<Label>,
93  StateId start_state_;
94  MapType wseq_to_state_;
95  std::vector<std::vector<Label> > state_to_wseq_;
96 
99  std::vector<std::vector<float> > state_to_context_;
100 };
101 
102 } // namespace kaldi
103 
104 #endif // KALDI_LM_KALDI_RNNLM_H_
fst::StdArc::StateId StateId
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
fst::StdArc::StateId StateId
Definition: kaldi-rnnlm.h:74
A hashing function-object for vectors.
Definition: stl-utils.h:216
rnnlm::CRnnLM rnnlm_
Definition: kaldi-rnnlm.h:63
Lattice::StateId StateId
fst::StdArc StdArc
int32 GetHiddenLayerSize() const
Definition: kaldi-rnnlm.h:54
kaldi::int32 int32
#define KALDI_DISALLOW_COPY_AND_ASSIGN(type)
Definition: kaldi-utils.h:121
std::vector< std::vector< float > > state_to_context_
Definition: kaldi-rnnlm.h:99
std::vector< std::vector< Label > > state_to_wseq_
Definition: kaldi-rnnlm.h:95
fst::StdArc::Label Label
Definition: kaldi-rnnlm.h:75
virtual void Register(const std::string &name, bool *ptr, const std::string &doc)=0
std::vector< std::string > label_to_word_
Definition: kaldi-rnnlm.h:64
class DeterministicOnDemandFst is an "FST-like" base-class.
fst::StdArc::Weight Weight
Definition: kaldi-rnnlm.h:73
fst::StdArc::Label Label
fst::StdArc::Weight Weight
virtual StateId Start()
Definition: kaldi-rnnlm.h:82
unordered_map< std::vector< Label >, StateId, VectorHasher< Label > > MapType
Definition: kaldi-rnnlm.h:92
int32 GetEos() const
Definition: kaldi-rnnlm.h:56
void Register(OptionsItf *opts)
Definition: kaldi-rnnlm.h:39
KaldiRnnlmWrapper * rnnlm_
Definition: kaldi-rnnlm.h:97