Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ BINFILES = align-equal align-equal-compiled acc-tree-stats \

OBJFILES =

ADDLIBS = ../cudamatrix/kaldi-cudamatrix.a ../nnet3/kaldi-nnet3.a ../rnnlm/kaldi-rnnlm.a ../decoder/kaldi-decoder.a ../lat/kaldi-lat.a ../lm/kaldi-lm.a \
ADDLIBS = ../decoder/kaldi-decoder.a ../lat/kaldi-lat.a ../lm/kaldi-lm.a \
../fstext/kaldi-fstext.a ../hmm/kaldi-hmm.a \
../transform/kaldi-transform.a ../gmm/kaldi-gmm.a \
../tree/kaldi-tree.a ../util/kaldi-util.a \
Expand Down
71 changes: 13 additions & 58 deletions src/bin/lat2gen-biglm-faster-mapped.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
#include "fstext/fstext-lib.h"
#include "decoder/decoder-wrappers.h"
#include "decoder/decodable-matrix.h"
#include "lm/const-arpa-lm.h"
#include "rnnlm/rnnlm-lattice-rescoring.h"
#include "base/timer.h"
#include "decoder/lattice2-biglm-faster-decoder.h"

Expand Down Expand Up @@ -162,26 +160,14 @@ int main(int argc, char *argv[]) {
bool allow_partial = false;
BaseFloat acoustic_scale = 0.1;
Lattice2BiglmFasterDecoderConfig config;
int32 max_ngram_order = 4;
rnnlm::RnnlmComputeStateComputationOptions rnn_opts;
bool use_carpa = false;

std::string word_syms_filename, word_embedding_rxfilename;
std::string word_syms_filename;
config.Register(&po);
rnn_opts.Register(&po);
po.Register("acoustic-scale", &acoustic_scale, "Scaling factor for acoustic likelihoods");

po.Register("word-symbol-table", &word_syms_filename, "Symbol table for words [for debug output]");
po.Register("allow-partial", &allow_partial, "If true, produce output even if end state was not reached.");
po.Register("use-const-arpa", &use_carpa, "If true, read the old-LM file "
"as a const-arpa file as opposed to an FST file");
po.Register("word-embedding-rxfilename", &word_embedding_rxfilename, "If set, use rnnlm");
po.Register("max-ngram-order", &max_ngram_order,
"If positive, allow RNNLM histories longer than this to be identified "
"with each other for rescoring purposes (an approximation that "
"saves time and reduces output lattice size).");



po.Read(argc, argv);

if (po.NumArgs() < 6 || po.NumArgs() > 8) {
Expand All @@ -201,39 +187,17 @@ int main(int argc, char *argv[]) {
TransitionModel trans_model;
ReadKaldiObject(model_in_filename, &trans_model);

VectorFst<StdArc> *old_lm_fst = fst::ReadAndPrepareLmFst(
old_lm_fst_rxfilename);
fst::BackoffDeterministicOnDemandFst<StdArc> old_lm_dfst(*old_lm_fst);
fst::ScaleDeterministicOnDemandFst old_lm_sdfst(-1,
&old_lm_dfst);

fst::DeterministicOnDemandFst<StdArc>* new_lm_dfst = NULL;
VectorFst<StdArc> *new_lm_fst = NULL;
ConstArpaLm* const_arpa = NULL;
CuMatrix<BaseFloat>* word_embedding_mat = NULL;
kaldi::nnet3::Nnet *rnnlm = NULL;
const rnnlm::RnnlmComputeStateInfo *info = NULL;

if (word_embedding_rxfilename!="") {
rnnlm = new kaldi::nnet3::Nnet();
word_embedding_mat = new CuMatrix<BaseFloat>();
ReadKaldiObject(word_embedding_rxfilename, word_embedding_mat);
ReadKaldiObject(new_lm_fst_rxfilename, rnnlm);
info = new rnnlm::RnnlmComputeStateInfo(rnn_opts, *rnnlm, *word_embedding_mat);
new_lm_dfst = new rnnlm::KaldiRnnlmDeterministicFst(max_ngram_order, *info);
} else if (use_carpa) {
const_arpa = new ConstArpaLm();
ReadKaldiObject(new_lm_fst_rxfilename, const_arpa);
new_lm_dfst = new ConstArpaLmDeterministicFst(*const_arpa);
} else {
new_lm_fst = fst::ReadAndPrepareLmFst(
new_lm_fst_rxfilename);
new_lm_dfst =
new fst::BackoffDeterministicOnDemandFst<StdArc>(*new_lm_fst);
}
VectorFst<StdArc> *old_lm_fst = fst::CastOrConvertToVectorFst(
fst::ReadFstKaldiGeneric(old_lm_fst_rxfilename));
ApplyProbabilityScale(-1.0, old_lm_fst); // Negate old LM probs...

VectorFst<StdArc> *new_lm_fst = fst::CastOrConvertToVectorFst(
fst::ReadFstKaldiGeneric(new_lm_fst_rxfilename));

fst::ComposeDeterministicOnDemandFst<StdArc> compose_dfst(&old_lm_sdfst,
new_lm_dfst);
fst::BackoffDeterministicOnDemandFst<StdArc> old_lm_dfst(*old_lm_fst);
fst::BackoffDeterministicOnDemandFst<StdArc> new_lm_dfst(*new_lm_fst);
fst::ComposeDeterministicOnDemandFst<StdArc> compose_dfst(&old_lm_dfst,
&new_lm_dfst);
fst::CacheDeterministicOnDemandFst<StdArc> cache_dfst(&compose_dfst, 1e7);

bool determinize = config.determinize_lattice;
Expand All @@ -257,7 +221,6 @@ int main(int argc, char *argv[]) {
double tot_like = 0.0;
kaldi::int64 frame_count = 0;
int num_success = 0, num_fail = 0;
double elapsed = 0;


if (ClassifyRspecifier(fst_in_str, NULL, NULL) == kNoRspecifier) {
Expand Down Expand Up @@ -292,13 +255,13 @@ int main(int argc, char *argv[]) {
num_success++;
} else num_fail++;
}
elapsed = timer.Elapsed();
}
delete decode_fst; // delete this only after decoder goes out of scope.
} else { // We have different FSTs for different utterances.
assert(0);
}

double elapsed = timer.Elapsed();
KALDI_LOG << "Time taken "<< elapsed
<< "s: real-time factor assuming 100 frames/sec is "
<< (elapsed*100.0/frame_count);
Expand All @@ -308,14 +271,6 @@ int main(int argc, char *argv[]) {
<< frame_count<<" frames.";

delete word_syms;

delete const_arpa;
delete new_lm_fst;
delete new_lm_dfst;
delete word_embedding_mat;
delete rnnlm;
delete info;

if (num_success != 0) return 0;
else return 1;
} catch(const std::exception &e) {
Expand Down
71 changes: 13 additions & 58 deletions src/bin/latgen-biglm-faster-mapped.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
#include "fstext/fstext-lib.h"
#include "decoder/decoder-wrappers.h"
#include "decoder/decodable-matrix.h"
#include "lm/const-arpa-lm.h"
#include "rnnlm/rnnlm-lattice-rescoring.h"
#include "base/timer.h"
#include "decoder/lattice-biglm-faster-decoder.h"

Expand Down Expand Up @@ -162,26 +160,14 @@ int main(int argc, char *argv[]) {
bool allow_partial = false;
BaseFloat acoustic_scale = 0.1;
LatticeBiglmFasterDecoderConfig config;
int32 max_ngram_order = 4;
rnnlm::RnnlmComputeStateComputationOptions rnn_opts;
bool use_carpa = false;

std::string word_syms_filename, word_embedding_rxfilename;
std::string word_syms_filename;
config.Register(&po);
rnn_opts.Register(&po);
po.Register("acoustic-scale", &acoustic_scale, "Scaling factor for acoustic likelihoods");

po.Register("word-symbol-table", &word_syms_filename, "Symbol table for words [for debug output]");
po.Register("allow-partial", &allow_partial, "If true, produce output even if end state was not reached.");
po.Register("use-const-arpa", &use_carpa, "If true, read the old-LM file "
"as a const-arpa file as opposed to an FST file");
po.Register("word-embedding-rxfilename", &word_embedding_rxfilename, "If set, use rnnlm");
po.Register("max-ngram-order", &max_ngram_order,
"If positive, allow RNNLM histories longer than this to be identified "
"with each other for rescoring purposes (an approximation that "
"saves time and reduces output lattice size).");



po.Read(argc, argv);

if (po.NumArgs() < 6 || po.NumArgs() > 8) {
Expand All @@ -201,39 +187,17 @@ int main(int argc, char *argv[]) {
TransitionModel trans_model;
ReadKaldiObject(model_in_filename, &trans_model);

VectorFst<StdArc> *old_lm_fst = fst::ReadAndPrepareLmFst(
old_lm_fst_rxfilename);
fst::BackoffDeterministicOnDemandFst<StdArc> old_lm_dfst(*old_lm_fst);
fst::ScaleDeterministicOnDemandFst old_lm_sdfst(-1,
&old_lm_dfst);

fst::DeterministicOnDemandFst<StdArc>* new_lm_dfst = NULL;
VectorFst<StdArc> *new_lm_fst = NULL;
ConstArpaLm* const_arpa = NULL;
CuMatrix<BaseFloat>* word_embedding_mat = NULL;
kaldi::nnet3::Nnet *rnnlm = NULL;
const rnnlm::RnnlmComputeStateInfo *info = NULL;

if (word_embedding_rxfilename!="") {
rnnlm = new kaldi::nnet3::Nnet();
word_embedding_mat = new CuMatrix<BaseFloat>();
ReadKaldiObject(word_embedding_rxfilename, word_embedding_mat);
ReadKaldiObject(new_lm_fst_rxfilename, rnnlm);
info = new rnnlm::RnnlmComputeStateInfo(rnn_opts, *rnnlm, *word_embedding_mat);
new_lm_dfst = new rnnlm::KaldiRnnlmDeterministicFst(max_ngram_order, *info);
} else if (use_carpa) {
const_arpa = new ConstArpaLm();
ReadKaldiObject(new_lm_fst_rxfilename, const_arpa);
new_lm_dfst = new ConstArpaLmDeterministicFst(*const_arpa);
} else {
new_lm_fst = fst::ReadAndPrepareLmFst(
new_lm_fst_rxfilename);
new_lm_dfst =
new fst::BackoffDeterministicOnDemandFst<StdArc>(*new_lm_fst);
}
VectorFst<StdArc> *old_lm_fst = fst::CastOrConvertToVectorFst(
fst::ReadFstKaldiGeneric(old_lm_fst_rxfilename));
ApplyProbabilityScale(-1.0, old_lm_fst); // Negate old LM probs...

VectorFst<StdArc> *new_lm_fst = fst::CastOrConvertToVectorFst(
fst::ReadFstKaldiGeneric(new_lm_fst_rxfilename));

fst::ComposeDeterministicOnDemandFst<StdArc> compose_dfst(&old_lm_sdfst,
new_lm_dfst);
fst::BackoffDeterministicOnDemandFst<StdArc> old_lm_dfst(*old_lm_fst);
fst::BackoffDeterministicOnDemandFst<StdArc> new_lm_dfst(*new_lm_fst);
fst::ComposeDeterministicOnDemandFst<StdArc> compose_dfst(&old_lm_dfst,
&new_lm_dfst);
fst::CacheDeterministicOnDemandFst<StdArc> cache_dfst(&compose_dfst, 1e7);

bool determinize = config.determinize_lattice;
Expand All @@ -257,7 +221,6 @@ int main(int argc, char *argv[]) {
double tot_like = 0.0;
kaldi::int64 frame_count = 0;
int num_success = 0, num_fail = 0;
double elapsed = 0;


if (ClassifyRspecifier(fst_in_str, NULL, NULL) == kNoRspecifier) {
Expand Down Expand Up @@ -292,13 +255,13 @@ int main(int argc, char *argv[]) {
num_success++;
} else num_fail++;
}
elapsed = timer.Elapsed();
}
delete decode_fst; // delete this only after decoder goes out of scope.
} else { // We have different FSTs for different utterances.
assert(0);
}

double elapsed = timer.Elapsed();
KALDI_LOG << "Time taken "<< elapsed
<< "s: real-time factor assuming 100 frames/sec is "
<< (elapsed*100.0/frame_count);
Expand All @@ -308,14 +271,6 @@ int main(int argc, char *argv[]) {
<< frame_count<<" frames.";

delete word_syms;

delete const_arpa;
delete new_lm_fst;
delete new_lm_dfst;
delete word_embedding_mat;
delete rnnlm;
delete info;

if (num_success != 0) return 0;
else return 1;
} catch(const std::exception &e) {
Expand Down
12 changes: 1 addition & 11 deletions src/decoder/lattice-biglm-faster-decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ class LatticeBiglmFasterDecoder {
active_toks_[0].toks = start_tok;
toks_.Insert(start_pair, start_tok);
num_toks_++;
propage_lm_num_=0;
ProcessNonemitting(0);

// We use 1-based indexing for frames in this decoder (if you view it in
Expand All @@ -119,7 +118,6 @@ class LatticeBiglmFasterDecoder {
else if (frame % config_.prune_interval == 0)
PruneActiveTokens(frame, config_.lattice_beam * 0.1); // use larger delta.
}
KALDI_VLOG(1) << "propage_lm_num_: " << propage_lm_num_;
// Returns true if we have any kind of traceback available (not necessarily
// to the end state; query ReachedFinal() for that).
return !final_costs_.empty();
Expand Down Expand Up @@ -570,12 +568,7 @@ class LatticeBiglmFasterDecoder {
}
}
}
int32 ToksNum(int32 f) {
int32 c=0;
for (Token *t=active_toks_[f].toks; t; t=t->next) c++;
return c;
}


// Go backwards through still-alive tokens, pruning them. note: cur_frame is
// where hash toks_ are (so we do not want to mess with it because these tokens
// don't yet have forward pointers), but we do all previous frames, unless we
Expand Down Expand Up @@ -607,7 +600,6 @@ class LatticeBiglmFasterDecoder {
}
KALDI_VLOG(3) << "PruneActiveTokens: pruned tokens from " << num_toks_begin
<< " to " << num_toks_;
KALDI_VLOG(2) << "expand fr num: " << cur_frame-config_.prune_interval << " " << ToksNum(cur_frame-config_.prune_interval);
}

// Version of PruneActiveTokens that we call on the final frame.
Expand Down Expand Up @@ -686,7 +678,6 @@ class LatticeBiglmFasterDecoder {
if (arc->olabel == 0) {
return lm_state; // no change in LM state if no word crossed.
} else { // Propagate in the LM-diff FST.
propage_lm_num_++;
Arc lm_arc;
bool ans = lm_diff_fst_->GetArc(lm_state, arc->olabel, &lm_arc);
if (!ans) { // this case is unexpected for statistical LMs.
Expand Down Expand Up @@ -908,7 +899,6 @@ class LatticeBiglmFasterDecoder {
active_toks_.clear();
KALDI_ASSERT(num_toks_ == 0);
}
uint64 propage_lm_num_;
};

} // end namespace kaldi.
Expand Down
Loading