Merge pull request #1820 from mozilla/issue1756

Don't save/load trie for character based LMs (Fixes #1756)
This commit is contained in:
Reuben Morais 2019-01-07 12:00:28 +00:00 committed by GitHub
commit b1c1ee7cbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -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;
}

View File

@ -121,8 +121,10 @@ void Scorer::setup(const std::string& lm_path, const std::string& trie_path)
fin.read(reinterpret_cast<char*>(&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<const char*>(&MAGIC), sizeof(MAGIC));
fout.write(reinterpret_cast<const char*>(&FILE_VERSION), sizeof(FILE_VERSION));
fout.write(reinterpret_cast<const char*>(&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<std::string>& words)