diff options
author | ccorbett <ccorbett@1f5c12ca-751b-0410-a591-d2e778427230> | 2006-08-16 20:22:53 +0400 |
---|---|---|
committer | ccorbett <ccorbett@1f5c12ca-751b-0410-a591-d2e778427230> | 2006-08-16 20:22:53 +0400 |
commit | 69babe34bfe433584c138a2bace503b5d262baa3 (patch) | |
tree | 430871a99439dad647aea76da4ac35f385a7cdf3 /moses | |
parent | 8eb7e08d8c3f473d29324abe4982a9814655001b (diff) |
bug fix for lexical reordering involving edge case
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@770 1f5c12ca-751b-0410-a591-d2e778427230
Diffstat (limited to 'moses')
-rwxr-xr-x | moses/src/DistortionOrientation.cpp | 24 | ||||
-rwxr-xr-x | moses/src/LexicalReordering.cpp | 19 | ||||
-rwxr-xr-x | moses/src/StaticData.cpp | 15 |
3 files changed, 19 insertions, 39 deletions
diff --git a/moses/src/DistortionOrientation.cpp b/moses/src/DistortionOrientation.cpp index 9ff2ac425..ab98fd87b 100755 --- a/moses/src/DistortionOrientation.cpp +++ b/moses/src/DistortionOrientation.cpp @@ -17,25 +17,19 @@ using namespace std; */ int DistortionOrientation::GetOrientation(const Hypothesis *curr_hypothesis, int direction, int type) { - size_t numSourceWords = curr_hypothesis->GetWordsBitmap().GetSize(); + const Hypothesis *prevHypo = curr_hypothesis->GetPrevHypo(); + if(prevHypo==NULL){ + //if there's no previous source we judge the first hypothesis as monotone. + return DistortionOrientationType::MONO; + } const WordsRange &currTargetRange = curr_hypothesis->GetCurrTargetWordsRange() , &currSourceRange = curr_hypothesis->GetCurrSourceWordsRange(); - const Hypothesis *prevHypo = curr_hypothesis->GetPrevHypo(); size_t curr_source_start = currSourceRange.GetStartPos(); size_t curr_source_end = currSourceRange.GetEndPos(); - size_t curr_target_end = currTargetRange.GetEndPos(); - size_t prev_source_start = 0; - size_t prev_source_end = 0; - if(prevHypo!=NULL){ - //don't look for attributes of the previous hypothesis if there is no previous hypothesis. - const WordsRange &prevSourceRange = prevHypo->GetCurrSourceWordsRange(); - prev_source_start = prevSourceRange.GetStartPos(); - prev_source_end = prevSourceRange.GetEndPos(); - } - else{ - return DistortionOrientationType::MONO; - } - if((curr_target_end==numSourceWords && type==LexReorderType::Forward) || prev_source_end==curr_source_start-1) + const WordsRange &prevSourceRange = prevHypo->GetCurrSourceWordsRange(); + size_t prev_source_start = prevSourceRange.GetStartPos(); + size_t prev_source_end = prevSourceRange.GetEndPos(); + if(prev_source_end==curr_source_start-1) { return DistortionOrientationType::MONO; } diff --git a/moses/src/LexicalReordering.cpp b/moses/src/LexicalReordering.cpp index 887be9cc5..4023d7b86 100755 --- a/moses/src/LexicalReordering.cpp +++ b/moses/src/LexicalReordering.cpp @@ -63,8 +63,6 @@ void LexicalReordering::LoadFile() // to make a single token key = f + "|||" + e; probs = Scan<float>(Tokenize(tokens[FE_PROBS])); - std::vector<float> scv(probs.size()); - std::transform(probs.begin(),probs.end(),probs.begin(),TransformScore); } else { @@ -72,8 +70,7 @@ void LexicalReordering::LoadFile() f = tokens[F_FOREIGN]; key = f; probs = Scan<float>(Tokenize(tokens[F_PROBS])); - std::vector<float> scv(probs.size()); - std::transform(probs.begin(),probs.end(),probs.begin(),TransformScore); + } if (m_orientation == DistortionOrientationType::Monotone) { @@ -83,6 +80,8 @@ void LexicalReordering::LoadFile() { assert(probs.size() == MSD_NUM_PROBS); // 3 backward, 3 forward } + std::vector<float> scv(probs.size()); + std::transform(probs.begin(),probs.end(),probs.begin(),TransformScore); m_orientation_table[key] = probs; } inFile.Close(); @@ -124,10 +123,6 @@ std::vector<float> LexicalReordering::CalcScore(Hypothesis *hypothesis) if(m_condition==LexReorderType::Fe) { //this key string is F+'|||'+E from the hypothesis - //TODO: following traces are for debugging, remove. -// TRACE_ERR("full source: " << hypothesis->GetSourcePhraseStringRep() << endl); -// TRACE_ERR("source: " << hypothesis->GetSourcePhraseStringRep(m_sourceFactors) << endl); -// TRACE_ERR("target: " << hypothesis->GetTargetPhraseStringRep(m_targetFactors) << endl); val=m_orientation_table[hypothesis->GetSourcePhraseStringRep(m_sourceFactors) +"||| " +hypothesis->GetTargetPhraseStringRep(m_targetFactors)]; @@ -240,14 +235,6 @@ std::vector<float> LexicalReordering::CalcScore(Hypothesis *hypothesis) } } - //TODO: for loop for debugging, remove. -// for(int i=0; i < score.size(); i++) -// { -// if(score[i]!=0) -// { -// TRACE_ERR("dist_score: " << score[i] << endl); -// } -// } return score; } diff --git a/moses/src/StaticData.cpp b/moses/src/StaticData.cpp index 8465a5896..e2e51bc1f 100755 --- a/moses/src/StaticData.cpp +++ b/moses/src/StaticData.cpp @@ -190,7 +190,6 @@ bool StaticData::LoadParameters(int argc, char* argv[]) { vector<string> token = Tokenize(lrFileVector[i]); //characteristics of the phrase table - //TODO: need to change in the case that the phrase table not dependent on the source, don't need to configure the input format in that case. vector<string> inputfactors = Tokenize(token[0],"-"); vector<FactorType> input,output; if(inputfactors.size() > 1) @@ -269,21 +268,21 @@ bool StaticData::LoadParameters(int argc, char* argv[]) boost::algorithm::to_lower(val); //orientation if(val == "monotone") - {orientation = DistortionOrientationType::Monotone; TRACE_ERR("monotone\n");} + orientation = DistortionOrientationType::Monotone; else if(val == "msd") - {orientation = DistortionOrientationType::Msd; TRACE_ERR("msd\n");} + orientation = DistortionOrientationType::Msd; //direction else if(val == "forward") - {direction = LexReorderType::Forward; TRACE_ERR("forward\n");} + direction = LexReorderType::Forward; else if(val == "backward") - {direction = LexReorderType::Backward; TRACE_ERR("backward\n");} + direction = LexReorderType::Backward; else if(val == "bidirectional") - {direction = LexReorderType::Bidirectional; TRACE_ERR("bidirectional\n");} + direction = LexReorderType::Bidirectional; //condition else if(val == "f") - {condition = LexReorderType::F; TRACE_ERR("f\n");} + condition = LexReorderType::F; else if(val == "fe") - {condition = LexReorderType::Fe; TRACE_ERR("fe\n");} + condition = LexReorderType::Fe; } timer.check("Starting to load lexical reorder table..."); TRACE_ERR(filePath << "..."); |