From f9211a7bbe1708988766b845284d5c4b266392f1 Mon Sep 17 00:00:00 2001 From: Martin Jansche Date: Wed, 13 Apr 2016 13:40:40 +0100 Subject: [PATCH] Fix bugs introduced in commit 3c9c06e: account for final weight in path weight; normalize path probabilities. --- festus/runtime/fst-util.h | 4 ++-- festus/runtime/g2p.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/festus/runtime/fst-util.h b/festus/runtime/fst-util.h index 7a606d8..85d57e3 100644 --- a/festus/runtime/fst-util.h +++ b/festus/runtime/fst-util.h @@ -298,8 +298,7 @@ void DeterminizeConvertWeight( // path in the FST. template std::vector> ShortestPathsToVector( - const F &paths_fst, - typename F::Arc::Weight total_weight = F::Arc::Weight::One()) { + const F &paths_fst) { typedef typename F::Arc Arc; typedef typename F::StateId StateId; typedef typename F::Weight Weight; @@ -329,6 +328,7 @@ std::vector> ShortestPathsToVector( CHECK((iter.Next(), iter.Done())); } CHECK(fst::ArcIterator>(paths_fst, state).Done()); + weight = Times(weight, paths_fst.Final(state)); paths.emplace_back(std::move(str), weight.Value()); } return paths; diff --git a/festus/runtime/g2p.h b/festus/runtime/g2p.h index 189d534..b041a41 100644 --- a/festus/runtime/g2p.h +++ b/festus/runtime/g2p.h @@ -255,9 +255,9 @@ bool G2P::Pronounce(const string &spelling, } VLOG(2) << "8. Convert shortest paths to pronunciations."; - result->pronunciations = ShortestPathsToVector(paths, total_weight.Value()); + result->pronunciations = ShortestPathsToVector(paths); for (auto &pron : result->pronunciations) { - pron.second = std::exp(-pron.second); + pron.second = std::exp(total_weight.Value() - pron.second); } result->error.clear(); return true;