diff options
author | Chris Dyer <cdyer@cs.cmu.edu> | 2011-03-02 19:11:23 -0500 |
---|---|---|
committer | Chris Dyer <cdyer@cs.cmu.edu> | 2011-03-02 19:11:23 -0500 |
commit | 5c1f2543319f52e8866647369db209e4e9320ab0 (patch) | |
tree | 2758cd0c5e564be9d74fa69bbd5d6e0c0ecb9bf7 | |
parent | cef04414dec9ee9e7bec53b94ab355c08b7cc38e (diff) |
final version of SOS EOS handling, i think
-rw-r--r-- | decoder/ff_klm.cc | 16 |
1 files changed, 11 insertions, 5 deletions
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 <s> (n-1 left words) and (n-1 right words) </s> double FinalTraversalCost(const void* state) { - if (add_sos_eos_) { + if (add_sos_eos_) { // rules do not produce <s> </s>, 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 <s> ... </s> + 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; } } |