diff options
author | Rico Sennrich <rico.sennrich@gmx.ch> | 2013-07-31 15:32:53 +0400 |
---|---|---|
committer | Rico Sennrich <rico.sennrich@gmx.ch> | 2013-07-31 16:18:18 +0400 |
commit | b32366ab8cf228d8789202aeb74da6737881b7b5 (patch) | |
tree | 05ef43b76aa97b42d03596b0adb7e073e5a95cfa /moses | |
parent | d0e2c43011e26483598fae00a4fb15020fdf21cf (diff) |
fix future and total cost in multimodel(counts). (was broken since merge of branch weight-new in May)
Diffstat (limited to 'moses')
-rw-r--r-- | moses/ScoreComponentCollection.cpp | 13 | ||||
-rw-r--r-- | moses/ScoreComponentCollection.h | 1 | ||||
-rw-r--r-- | moses/TranslationModel/PhraseDictionaryMultiModel.cpp | 23 | ||||
-rw-r--r-- | moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp | 19 |
4 files changed, 40 insertions, 16 deletions
diff --git a/moses/ScoreComponentCollection.cpp b/moses/ScoreComponentCollection.cpp index d6ddaec9f..97ae2684d 100644 --- a/moses/ScoreComponentCollection.cpp +++ b/moses/ScoreComponentCollection.cpp @@ -185,6 +185,19 @@ void ScoreComponentCollection::Assign(const FeatureFunction* sp, const string li } } +void ScoreComponentCollection::InvertDenseFeatures(const FeatureFunction* sp) +{ + + Scores old_scores = GetScoresForProducer(sp); + Scores new_scores(old_scores.size()); + + for (size_t i = 0; i != old_scores.size(); ++i) { + new_scores[i] = -old_scores[i]; + } + + Assign(sp, new_scores); +} + void ScoreComponentCollection::ZeroDenseFeatures(const FeatureFunction* sp) { size_t numScores = sp->GetNumScoreComponents(); diff --git a/moses/ScoreComponentCollection.h b/moses/ScoreComponentCollection.h index a35cfde71..a7c4eb2b7 100644 --- a/moses/ScoreComponentCollection.h +++ b/moses/ScoreComponentCollection.h @@ -335,6 +335,7 @@ public: float GetWeightedScore() const; void ZeroDenseFeatures(const FeatureFunction* sp); + void InvertDenseFeatures(const FeatureFunction* sp); void L1Normalise(); float GetL1Norm() const; float GetL2Norm() const; diff --git a/moses/TranslationModel/PhraseDictionaryMultiModel.cpp b/moses/TranslationModel/PhraseDictionaryMultiModel.cpp index d9c53d5f9..77b611335 100644 --- a/moses/TranslationModel/PhraseDictionaryMultiModel.cpp +++ b/moses/TranslationModel/PhraseDictionaryMultiModel.cpp @@ -136,19 +136,19 @@ void PhraseDictionaryMultiModel::CollectSufficientStatistics(const Phrase& src, multiModelStatistics * statistics = new multiModelStatistics; statistics->targetPhrase = new TargetPhrase(*targetPhrase); //make a copy so that we don't overwrite the original phrase table info - - // zero out scores from original phrase table - statistics->targetPhrase->GetScoreBreakdown().ZeroDenseFeatures(&pd); - - Scores scoreVector(m_numScoreComponents); statistics->p.resize(m_numScoreComponents); for(size_t j = 0; j < m_numScoreComponents; ++j) { statistics->p[j].resize(m_numModels); - scoreVector[j] = -raw_scores[j]; } - statistics->targetPhrase->GetScoreBreakdown().Assign(this, scoreVector); // set scores to 0 - statistics->targetPhrase->Evaluate(src, GetFeaturesToApply()); + //correct future cost estimates and total score + statistics->targetPhrase->GetScoreBreakdown().InvertDenseFeatures(&pd); + vector<FeatureFunction*> pd_feature; + pd_feature.push_back(m_pd[i]); + const vector<FeatureFunction*> pd_feature_const(pd_feature); + statistics->targetPhrase->Evaluate(src, pd_feature_const); + // zero out scores from original phrase table + statistics->targetPhrase->GetScoreBreakdown().ZeroDenseFeatures(&pd); (*allStats)[targetString] = statistics; @@ -183,7 +183,12 @@ TargetPhraseCollection* PhraseDictionaryMultiModel::CreateTargetPhraseCollection scoreVector[m_numScoreComponents-1] = 1.0; statistics->targetPhrase->GetScoreBreakdown().Assign(this, scoreVector); - statistics->targetPhrase->Evaluate(src, GetFeaturesToApply()); + + //correct future cost estimates and total score + vector<FeatureFunction*> pd_feature; + pd_feature.push_back(const_cast<PhraseDictionaryMultiModel*>(this)); + const vector<FeatureFunction*> pd_feature_const(pd_feature); + statistics->targetPhrase->Evaluate(src, pd_feature_const); ret->Add(new TargetPhrase(*statistics->targetPhrase)); } diff --git a/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp b/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp index 4af3060ea..7b9320827 100644 --- a/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp +++ b/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp @@ -183,17 +183,17 @@ void PhraseDictionaryMultiModelCounts::CollectSufficientStatistics(const Phrase& multiModelCountsStatistics * statistics = new multiModelCountsStatistics; statistics->targetPhrase = new TargetPhrase(*targetPhrase); //make a copy so that we don't overwrite the original phrase table info + //correct future cost estimates and total score + statistics->targetPhrase->GetScoreBreakdown().InvertDenseFeatures(&pd); + vector<FeatureFunction*> pd_feature; + pd_feature.push_back(m_pd[i]); + const vector<FeatureFunction*> pd_feature_const(pd_feature); + statistics->targetPhrase->Evaluate(src, pd_feature_const); // zero out scores from original phrase table statistics->targetPhrase->GetScoreBreakdown().ZeroDenseFeatures(&pd); statistics->fst.resize(m_numModels); statistics->ft.resize(m_numModels); - Scores scoreVector(5); - scoreVector[0] = -raw_scores[0]; - scoreVector[1] = -raw_scores[1]; - scoreVector[2] = -raw_scores[2]; - statistics->targetPhrase->GetScoreBreakdown().Assign(this, scoreVector); // set scores to 0 - statistics->targetPhrase->Evaluate(src, GetFeaturesToApply()); (*allStats)[targetString] = statistics; @@ -246,7 +246,12 @@ TargetPhraseCollection* PhraseDictionaryMultiModelCounts::CreateTargetPhraseColl scoreVector[4] = FloorScore(TransformScore(2.718)); statistics->targetPhrase->GetScoreBreakdown().Assign(this, scoreVector); - statistics->targetPhrase->Evaluate(src, GetFeaturesToApply()); + + //correct future cost estimates and total score + vector<FeatureFunction*> pd_feature; + pd_feature.push_back(const_cast<PhraseDictionaryMultiModelCounts*>(this)); + const vector<FeatureFunction*> pd_feature_const(pd_feature); + statistics->targetPhrase->Evaluate(src, pd_feature_const); } catch (AlignmentException& e) { continue; } |