2828#include " fst/arcsort.h"
2929#include " fst/symbol-table.h"
3030#include " fst/vector-fst.h"
31- #include " ngram /ngram-count.h"
32- #include " ngram/ngram-model .h"
31+ #include " third_party/opengrm/sfst /ngram-count.h"
32+ #include " third_party/opengrm/sfst/sfst .h"
3333#include " nisaba/port/status_macros.h"
3434
3535namespace mozolm {
@@ -230,7 +230,7 @@ int IncrementBackoffArcReturnBackoffState(StdVectorFst* fst,
230230 if (arc.ilabel == 0 ) {
231231 backoff_state = arc.nextstate ;
232232 if (increment_count) {
233- arc.weight = StdArc::Weight (ngram ::NegLogSum (arc.weight .Value (), 0.0 ));
233+ arc.weight = StdArc::Weight (sfst ::NegLogSum (arc.weight .Value (), 0.0 ));
234234 arc_iterator.SetValue (arc);
235235 }
236236 }
@@ -248,7 +248,7 @@ double GetTotalStateCount(const StdVectorFst& fst, StdArc::StateId s) {
248248 state_count = arc.weight .Value ();
249249 return state_count;
250250 }
251- state_count = ngram ::NegLogSum (state_count, arc.weight .Value ());
251+ state_count = sfst ::NegLogSum (state_count, arc.weight .Value ());
252252 }
253253 return state_count;
254254}
@@ -271,8 +271,8 @@ absl::StatusOr<double> UpdateIndexProb(double count, double neg_log_beta,
271271 if (count >= neg_log_beta) {
272272 return absl::InternalError (" Found a count less than \b eta." );
273273 }
274- sym_prob = ngram ::NegLogSum (
275- lower_order_prob, ngram ::NegLogDiff (count, neg_log_beta) - denominator);
274+ sym_prob = sfst ::NegLogSum (
275+ lower_order_prob, sfst ::NegLogDiff (count, neg_log_beta) - denominator);
276276 }
277277 return sym_prob;
278278}
@@ -356,10 +356,10 @@ absl::Status PpmAsFstModel::AddPriorCounts() {
356356 StdArc arc = arc_iterator.Value ();
357357 has_unigram.insert (arc.ilabel );
358358 arc.weight = StdArc::Weight (
359- ngram ::NegLogSum (arc.weight .Value (), 0.0 )); // Adds 1 count.
359+ sfst ::NegLogSum (arc.weight .Value (), 0.0 )); // Adds 1 count.
360360 arc_iterator.SetValue (arc);
361361 }
362- fst_->SetFinal (unigram_state, StdArc::Weight (ngram ::NegLogSum (
362+ fst_->SetFinal (unigram_state, StdArc::Weight (sfst ::NegLogSum (
363363 fst_->Final (unigram_state).Value (), 0.0 )));
364364 bool syms_added = false ;
365365 for (SymbolTableIterator syms_iter (*syms_); !syms_iter.Done ();
@@ -474,7 +474,7 @@ absl::Status PpmAsFstModel::Read(const ModelStorage& storage) {
474474 syms_->AddSymbol (" <epsilon>" );
475475 fst_->SetInputSymbols (syms_.get ());
476476 fst_->SetOutputSymbols (syms_.get ());
477- ngram_counter_ = std::make_unique<ngram ::NGramCounter<Log64Weight>>(
477+ ngram_counter_ = std::make_unique<sfst ::NGramCounter<Log64Weight>>(
478478 /* order=*/ max_order_);
479479 if (!storage.model_file ().empty ()) {
480480 GOOGLE_LOG (INFO ) << " Initializing from training data ..." ;
@@ -598,7 +598,7 @@ std::vector<double> PpmAsFstModel::InitCacheProbs(
598598 --num_continuations;
599599 }
600600 const double gamma =
601- ngram ::NegLogSum (-std::log (num_continuations) - std::log (beta_),
601+ sfst ::NegLogSum (-std::log (num_continuations) - std::log (beta_),
602602 -std::log (alpha_)) - denominator;
603603 for (size_t i = 0 ; i < cache_probs.size (); ++i) {
604604 // Adds in gamma factor to backoff probabilities.
@@ -657,7 +657,7 @@ absl::Status PpmAsFstModel::UpdateCacheAtNonEmptyState(
657657 std::vector<int > destination_states =
658658 InitCacheStates (s, backoff_state, backoff_cache, /* arc_origin=*/ false );
659659 const double denominator =
660- ngram ::NegLogSum (impl::GetTotalStateCount (*fst_, s), -std::log (alpha_));
660+ sfst ::NegLogSum (impl::GetTotalStateCount (*fst_, s), -std::log (alpha_));
661661 std::vector<double > neg_log_probabilities =
662662 InitCacheProbs (s, backoff_state, backoff_cache, denominator);
663663 update_status = UpdateCacheStatesAndProbs (
@@ -831,7 +831,7 @@ absl::Status PpmAsFstModel::UpdateHighestFoundState(StdArc::StateId curr_state,
831831 int sym_index) {
832832 if (sym_index == 0 ) {
833833 // Adds one to final cost and sets destination state to start state.
834- fst_->SetFinal (curr_state, StdArc::Weight (ngram ::NegLogSum (
834+ fst_->SetFinal (curr_state, StdArc::Weight (sfst ::NegLogSum (
835835 fst_->Final (curr_state).Value (), 0.0 )));
836836 } else {
837837 // Arc with sym_index found at current state.
@@ -853,7 +853,7 @@ absl::Status PpmAsFstModel::UpdateHighestFoundState(StdArc::StateId curr_state,
853853 new_next_state = state_orders_.size ();
854854 arc.nextstate = new_next_state;
855855 }
856- arc.weight = StdArc::Weight (ngram ::NegLogSum (arc.weight .Value (), 0.0 ));
856+ arc.weight = StdArc::Weight (sfst ::NegLogSum (arc.weight .Value (), 0.0 ));
857857 arc_iterator.SetValue (arc);
858858 break ;
859859 }
0 commit comments