summaryrefslogtreecommitdiff
path: root/decoder
diff options
context:
space:
mode:
Diffstat (limited to 'decoder')
-rw-r--r--decoder/cdec.cc6
-rw-r--r--decoder/viterbi.cc11
-rw-r--r--decoder/viterbi.h4
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<double, double> res =
Inside<PRPair<double, double>,
@@ -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<FeatureVectorTraversal>(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<string>(logp)+"!="+boost::lexical_cast<string>(fv));
+ if (!close_enough(logp,fv,EPSILON)) {
+ complaint="ViterbiFeatures log prob disagrees with features.dot(weights)"+boost::lexical_cast<string>(logp)+"!="+boost::lexical_cast<string>(fv);
+ if (fatal_dotprod_disagreement)
+ throw std::runtime_error(complaint);
+ else
+ cerr<<complaint<<endl;
+
}
return r;
}
diff --git a/decoder/viterbi.h b/decoder/viterbi.h
index 7e1e2c0e..4697590b 100644
--- a/decoder/viterbi.h
+++ b/decoder/viterbi.h
@@ -204,7 +204,7 @@ std::string ViterbiFTree(const Hypergraph& hg);
int ViterbiELength(const Hypergraph& hg);
int ViterbiPathLength(const Hypergraph& hg);
-/// if weights supplied, assert viterbi prob = features.dot(*weights). return features (sum over all edges in viterbi derivation)
-FeatureVector ViterbiFeatures(Hypergraph const& hg,FeatureWeights const* weights=0);
+/// if weights supplied, assert viterbi prob = features.dot(*weights) (exception if fatal, cerr warn if not). return features (sum over all edges in viterbi derivation)
+FeatureVector ViterbiFeatures(Hypergraph const& hg,FeatureWeights const* weights=0,bool fatal_dotprod_disagreement=false);
#endif