KaldiRnnlmWrapper Class Reference

#include <kaldi-rnnlm.h>

Collaboration diagram for KaldiRnnlmWrapper:

Public Member Functions

 KaldiRnnlmWrapper (const KaldiRnnlmWrapperOpts &opts, const std::string &unk_prob_rspecifier, const std::string &word_symbol_table_rxfilename, const std::string &rnnlm_rxfilename)
 
int32 GetHiddenLayerSize () const
 
int32 GetEos () const
 
BaseFloat GetLogProb (int32 word, const std::vector< int32 > &wseq, const std::vector< float > &context_in, std::vector< float > *context_out)
 

Private Member Functions

 KALDI_DISALLOW_COPY_AND_ASSIGN (KaldiRnnlmWrapper)
 

Private Attributes

rnnlm::CRnnLM rnnlm_
 
std::vector< std::string > label_to_word_
 
int32 eos_
 

Detailed Description

Definition at line 47 of file kaldi-rnnlm.h.

Constructor & Destructor Documentation

◆ KaldiRnnlmWrapper()

KaldiRnnlmWrapper ( const KaldiRnnlmWrapperOpts opts,
const std::string &  unk_prob_rspecifier,
const std::string &  word_symbol_table_rxfilename,
const std::string &  rnnlm_rxfilename 
)

Definition at line 28 of file kaldi-rnnlm.cc.

References KaldiRnnlmWrapper::eos_, KaldiRnnlmWrapperOpts::eos_symbol, rnnlm::i, KALDI_ERR, KaldiRnnlmWrapper::label_to_word_, CRnnLM::restoreNet(), KaldiRnnlmWrapper::rnnlm_, CRnnLM::setRandSeed(), CRnnLM::setRnnLMFile(), CRnnLM::setUnkPenalty(), CRnnLM::setUnkSym(), and KaldiRnnlmWrapperOpts::unk_symbol.

32  {
33  rnnlm_.setRnnLMFile(rnnlm_rxfilename);
35  rnnlm_.setUnkSym(opts.unk_symbol);
36  rnnlm_.setUnkPenalty(unk_prob_rspecifier);
38 
39  // Reads symbol table.
40  fst::SymbolTable *word_symbols = NULL;
41  if (!(word_symbols =
42  fst::SymbolTable::ReadText(word_symbol_table_rxfilename))) {
43  KALDI_ERR << "Could not read symbol table from file "
44  << word_symbol_table_rxfilename;
45  }
46  label_to_word_.resize(word_symbols->NumSymbols() + 1);
47  for (int32 i = 0; i < label_to_word_.size() - 1; ++i) {
48  label_to_word_[i] = word_symbols->Find(i);
49  if (label_to_word_[i] == "") {
50  KALDI_ERR << "Could not find word for integer " << i << "in the word "
51  << "symbol table, mismatched symbol table or you have discontinuous "
52  << "integers in your symbol table?";
53  }
54  }
55  label_to_word_[label_to_word_.size() - 1] = opts.eos_symbol;
56  eos_ = label_to_word_.size() - 1;
57 }
rnnlm::CRnnLM rnnlm_
Definition: kaldi-rnnlm.h:63
void setUnkSym(const std::string &unk)
kaldi::int32 int32
std::vector< std::string > label_to_word_
Definition: kaldi-rnnlm.h:64
#define KALDI_ERR
Definition: kaldi-error.h:147
void setRnnLMFile(const std::string &str)
void setRandSeed(int newSeed)
void setUnkPenalty(const std::string &filename)

Member Function Documentation

◆ GetEos()

int32 GetEos ( ) const
inline

Definition at line 56 of file kaldi-rnnlm.h.

56 { return eos_; }

◆ GetHiddenLayerSize()

int32 GetHiddenLayerSize ( ) const
inline

Definition at line 54 of file kaldi-rnnlm.h.

Referenced by RnnlmDeterministicFst::RnnlmDeterministicFst().

54 { return rnnlm_.getHiddenLayerSize(); }
rnnlm::CRnnLM rnnlm_
Definition: kaldi-rnnlm.h:63
int getHiddenLayerSize() const

◆ GetLogProb()

BaseFloat GetLogProb ( int32  word,
const std::vector< int32 > &  wseq,
const std::vector< float > &  context_in,
std::vector< float > *  context_out 
)

Definition at line 59 of file kaldi-rnnlm.cc.

References CRnnLM::computeConditionalLogprob(), rnnlm::i, KALDI_ASSERT, KaldiRnnlmWrapper::label_to_word_, and KaldiRnnlmWrapper::rnnlm_.

62  {
63 
64  std::vector<std::string> wseq_symbols(wseq.size());
65  for (int32 i = 0; i < wseq_symbols.size(); ++i) {
66  KALDI_ASSERT(wseq[i] < label_to_word_.size());
67  wseq_symbols[i] = label_to_word_[wseq[i]];
68  }
69 
70  return rnnlm_.computeConditionalLogprob(label_to_word_[word], wseq_symbols,
71  context_in, context_out);
72 }
rnnlm::CRnnLM rnnlm_
Definition: kaldi-rnnlm.h:63
kaldi::int32 int32
float computeConditionalLogprob(std::string current_word, const std::vector< std::string > &history_words, const std::vector< float > &context_in, std::vector< float > *context_out)
std::vector< std::string > label_to_word_
Definition: kaldi-rnnlm.h:64
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ KALDI_DISALLOW_COPY_AND_ASSIGN()

KALDI_DISALLOW_COPY_AND_ASSIGN ( KaldiRnnlmWrapper  )
private

Member Data Documentation

◆ eos_

int32 eos_
private

Definition at line 65 of file kaldi-rnnlm.h.

Referenced by KaldiRnnlmWrapper::KaldiRnnlmWrapper().

◆ label_to_word_

std::vector<std::string> label_to_word_
private

◆ rnnlm_


The documentation for this class was generated from the following files: