From 5c1f2543319f52e8866647369db209e4e9320ab0 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Wed, 2 Mar 2011 19:11:23 -0500 Subject: final version of SOS EOS handling, i think --- decoder/ff_klm.cc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'decoder') diff --git a/decoder/ff_klm.cc b/decoder/ff_klm.cc index a12d4a2d..7c37ddb7 100644 --- a/decoder/ff_klm.cc +++ b/decoder/ff_klm.cc @@ -175,18 +175,24 @@ class KLanguageModelImpl { return sum; } - //FIXME: this assumes no target words on final unary -> goal rule. is that ok? + // this assumes no target words on final unary -> goal rule. is that ok? // for (n-1 left words) and (n-1 right words) double FinalTraversalCost(const void* state) { - if (add_sos_eos_) { + if (add_sos_eos_) { // rules do not produce , so do it here SetRemnantLMState(ngram_->BeginSentenceState(), dummy_state_); SetHasFullContext(1, dummy_state_); SetUnscoredSize(0, dummy_state_); dummy_ants_[1] = state; return LookupWords(*dummy_rule_, dummy_ants_, NULL, NULL); - } else { - // TODO, figure out whether spans are correct - return 0; + } else { // rules DO produce ... + double p = 0; + if (!GetFlag(state, HAS_EOS_ON_RIGHT)) { p -= 100; } + if (UnscoredSize(state) > 0) { // are there unscored words + if (kSOS_ != IthUnscoredWord(0, state)) { + p -= 100 * UnscoredSize(state); + } + } + return p; } } -- cgit v1.2.3