From 4bc9ea17ba9f85c899e35a9d657ee3f174ff2863 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Tue, 22 Mar 2011 11:35:45 -0400 Subject: check for infs --- decoder/decoder.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'decoder') diff --git a/decoder/decoder.cc b/decoder/decoder.cc index 8a03c5c9..a16a9b5a 100644 --- a/decoder/decoder.cc +++ b/decoder/decoder.cc @@ -810,8 +810,12 @@ bool DecoderImpl::Decode(const string& input, DecoderObserver* o) { const prob_t z = forest.ComputeEdgePosteriors(1.0, &posteriors); if (!SILENT) { cerr << " " << passtr << " adding summary feature " << FD::Convert(rp.fid_summary) << " log(Z)=" << log(z) << endl; } assert(forest.edges_.size() == posteriors.size()); - for (int i = 0; i < posteriors.size(); ++i) - forest.edges_[i].feature_values_.set_value(rp.fid_summary, log(posteriors[i] / z)); + if (!isfinite(log(z)) || isnan(log(z))) { + cerr << " " << passtr << " !!! Invalid partition detected, abandoning.\n"; + } else { + for (int i = 0; i < posteriors.size(); ++i) + forest.edges_[i].feature_values_.set_value(rp.fid_summary, log(posteriors[i] / z)); + } } string fullbp = "beam_prune" + StringSuffixForRescoringPass(pass); -- cgit v1.2.3