From 934ed3602c4226b667a2ff6b66228e897e814ccc Mon Sep 17 00:00:00 2001 From: graehl Date: Thu, 8 Jul 2010 19:30:57 +0000 Subject: warning only on feat dotprod vs. viterbi prob mismatch git-svn-id: https://ws10smt.googlecode.com/svn/trunk@187 ec762483-ff6d-05da-a07a-a48fb63a330f --- decoder/cdec.cc | 6 +++--- decoder/viterbi.cc | 11 ++++++++--- decoder/viterbi.h | 4 ++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/decoder/cdec.cc b/decoder/cdec.cc index 140fe8e4..54e24792 100644 --- a/decoder/cdec.cc +++ b/decoder/cdec.cc @@ -491,7 +491,7 @@ int main(int argc, char** argv) { } const bool show_tree_structure=conf.count("show_tree_structure"); const bool show_features=conf.count("show_features"); - forest_stats(forest," -LM forest",show_tree_structure,show_features); + forest_stats(forest," -LM forest",show_tree_structure,show_features,&feature_weights); if (conf.count("show_expected_length")) { const PRPair res = Inside, @@ -519,7 +519,7 @@ int main(int argc, char** argv) { &prelm_forest); forest.swap(prelm_forest); forest.Reweight(prelm_feature_weights); - forest_stats(forest," prelm forest",show_tree_structure,show_features); + forest_stats(forest," prelm forest",show_tree_structure,show_features,&prelm_feature_weights); } maybe_prune(forest,conf,"prelm_beam_prune","prelm_density_prune","-LM",srclen); @@ -538,7 +538,7 @@ int main(int argc, char** argv) { &lm_forest); forest.swap(lm_forest); forest.Reweight(feature_weights); - forest_stats(forest," +LM forest",show_tree_structure,show_features); + forest_stats(forest," +LM forest",show_tree_structure,show_features,&feature_weights); } maybe_prune(forest,conf,"beam_prune","density_prune","+LM",srclen); diff --git a/decoder/viterbi.cc b/decoder/viterbi.cc index 6a7a970b..ea0cd95e 100644 --- a/decoder/viterbi.cc +++ b/decoder/viterbi.cc @@ -116,15 +116,20 @@ inline bool close_enough(double a,double b,double epsilon) return diff<=epsilon*fabs(a) || diff<=epsilon*fabs(b); } -FeatureVector ViterbiFeatures(Hypergraph const& hg,FeatureWeights const* weights) { +FeatureVector ViterbiFeatures(Hypergraph const& hg,FeatureWeights const* weights,bool fatal_dotprod_disagreement) { FeatureVector r; const prob_t p = Viterbi(hg, &r); if (weights) { double logp=log(p); double fv=r.dot(*weights); const double EPSILON=1e-5; - if (!close_enough(logp,fv,EPSILON)) - throw std::runtime_error("ViterbiFeatures log prob disagrees with features.dot(weights)"+boost::lexical_cast(logp)+"!="+boost::lexical_cast(fv)); + if (!close_enough(logp,fv,EPSILON)) { + complaint="ViterbiFeatures log prob disagrees with features.dot(weights)"+boost::lexical_cast(logp)+"!="+boost::lexical_cast(fv); + if (fatal_dotprod_disagreement) + throw std::runtime_error(complaint); + else + cerr<