From 3e6605c395fa9798f4bd0b7ce2227cd5a5391a25 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