mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-25 12:52:29 +03:00
fix future and total cost in multimodel(counts). (was broken since merge of branch weight-new in May)
This commit is contained in:
parent
d0e2c43011
commit
b32366ab8c
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user