From 9e8c208be2e237ba7643024ddb129b25d6a6c313 Mon Sep 17 00:00:00 2001 From: Reuben Morais Date: Mon, 7 Jan 2019 08:49:37 -0200 Subject: [PATCH] Don't save/load trie for character based LMs --- native_client/ctcdecode/path_trie.cpp | 4 ++-- native_client/ctcdecode/scorer.cpp | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/native_client/ctcdecode/path_trie.cpp b/native_client/ctcdecode/path_trie.cpp index 3b081290..effe5437 100644 --- a/native_client/ctcdecode/path_trie.cpp +++ b/native_client/ctcdecode/path_trie.cpp @@ -78,10 +78,10 @@ PathTrie* PathTrie::get_path_trie(int new_char, int new_timestep, bool reset) { auto final_weight = dictionary_->Final(matcher_->Value().nextstate); bool is_final = (final_weight != FSTZERO); if (is_final && reset) { - // restart spell checker at the start state + // restart spell checker at the start state new_path->dictionary_state_ = dictionary_->Start(); } else { - // go to next state + // go to next state new_path->dictionary_state_ = matcher_->Value().nextstate; } diff --git a/native_client/ctcdecode/scorer.cpp b/native_client/ctcdecode/scorer.cpp index daba7d69..39b9caf4 100644 --- a/native_client/ctcdecode/scorer.cpp +++ b/native_client/ctcdecode/scorer.cpp @@ -121,8 +121,10 @@ void Scorer::setup(const std::string& lm_path, const std::string& trie_path) fin.read(reinterpret_cast(&is_character_based_), sizeof(is_character_based_)); - fst::FstReadOptions opt; - dictionary.reset(fst::StdVectorFst::Read(fin, opt)); + if (!is_character_based_) { + fst::FstReadOptions opt; + dictionary.reset(fst::StdVectorFst::Read(fin, opt)); + } } max_order_ = language_model_->Order(); @@ -134,8 +136,10 @@ void Scorer::save_dictionary(const std::string& path) fout.write(reinterpret_cast(&MAGIC), sizeof(MAGIC)); fout.write(reinterpret_cast(&FILE_VERSION), sizeof(FILE_VERSION)); fout.write(reinterpret_cast(&is_character_based_), sizeof(is_character_based_)); - fst::FstWriteOptions opt; - dictionary->Write(fout, opt); + if (!is_character_based_) { + fst::FstWriteOptions opt; + dictionary->Write(fout, opt); + } } double Scorer::get_log_cond_prob(const std::vector& words)