From e449df548ae69bcd210dbb8a527c815ed50a6de0 Mon Sep 17 00:00:00 2001 From: XapaJIaMnu Date: Fri, 12 Sep 2014 10:23:46 +0100 Subject: [PATCH] Fix a bunch of off by one and silly errors --- moses/LM/bilingual-lm/BilingualLM.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/moses/LM/bilingual-lm/BilingualLM.cpp b/moses/LM/bilingual-lm/BilingualLM.cpp index fb8ad0bea..814b16595 100644 --- a/moses/LM/bilingual-lm/BilingualLM.cpp +++ b/moses/LM/bilingual-lm/BilingualLM.cpp @@ -692,7 +692,7 @@ int BilingualLM::getSourceWordsChart(const TargetPhrase &targetPhrase if ((targetWordIdx + j) < targetPhrase.GetSize()){ last_word_al = alignments.GetAlignmentsForTarget(targetWordIdx + j); //If the current word is non terminal we get the alignment from the previous state. - if (targetPhrase.GetWord(targetWordIdx - j).IsNonTerminal()) { + if (targetPhrase.GetWord(targetWordIdx + j).IsNonTerminal()) { const ChartHypothesis * prev_hypo = curr_hypothesis.GetPrevHypo(next_nonterminal_index); const BilingualLMState * prev_state = static_cast(prev_hypo->GetFFState(featureID)); const std::vector& word_alignments = prev_state->GetWordAlignmentVector(); @@ -706,7 +706,7 @@ int BilingualLM::getSourceWordsChart(const TargetPhrase &targetPhrase } else if ((targetWordIdx - j) > 0) { //If the current word is non terminal we get the alignment from a different place if (targetPhrase.GetWord(targetWordIdx - j).IsNonTerminal()) { - const ChartHypothesis * prev_hypo = curr_hypothesis.GetPrevHypo(next_nonterminal_index); + const ChartHypothesis * prev_hypo = curr_hypothesis.GetPrevHypo(next_nonterminal_index -1); //We need to look at the nonterm on the left. const BilingualLMState * prev_state = static_cast(prev_hypo->GetFFState(featureID)); const std::vector& word_alignments = prev_state->GetWordAlignmentVector(); source_word_mid_idx = word_alignments[0]; //The first word on the right or left of our word @@ -811,7 +811,7 @@ FFState* BilingualLM::EvaluateWhenApplied( getTargetWordsChart(whole_phrase, i + additional_shift + j, all_words); value += m_neuralLM->lookup_ngram(all_words); //Get the score } - additional_shift += prev_whole_phrase.GetSize(); //Take into account the size of this non Terminal + additional_shift += prev_whole_phrase.GetSize() - 1; //Take into account the size of this non Terminal }