mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-25 04:43:03 +03:00
figure out which feature function to apply at which decode step. Book-keeping
This commit is contained in:
parent
f83622b0b7
commit
117eb76b0a
@ -33,6 +33,19 @@ FactorMask::FactorMask(const vector<FactorType> &factors)
|
||||
}
|
||||
}
|
||||
|
||||
bool FactorMask::IsUseable(const FactorMask &other) const
|
||||
{
|
||||
for (size_t i = 0; i < other.size(); ++i) {
|
||||
if (other[i]) {
|
||||
if (!this->operator[](i) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
TO_STRING_BODY(FactorMask);
|
||||
|
||||
// friend
|
||||
|
@ -45,6 +45,7 @@ public:
|
||||
//! copy constructor
|
||||
FactorMask(const std::bitset<MAX_NUM_FACTORS>& rhs) : std::bitset<MAX_NUM_FACTORS>(rhs) { }
|
||||
|
||||
bool IsUseable(const FactorMask &other) const;
|
||||
|
||||
TO_STRING();
|
||||
};
|
||||
|
@ -276,7 +276,7 @@ public:
|
||||
targetPhrase.SetSourcePhrase(*srcPtr);
|
||||
|
||||
targetPhrase.GetScoreBreakdown().Assign(m_obj, scoreVector);
|
||||
targetPhrase.Evaluate(*srcPtr);
|
||||
targetPhrase.Evaluate(*srcPtr, m_obj->GetFeaturesToApply());
|
||||
}
|
||||
|
||||
TargetPhraseCollection* PruneTargetCandidates(std::vector<TargetPhrase> const & tCands,
|
||||
|
@ -53,6 +53,14 @@ PhraseDictionary::PhraseDictionary(const std::string &description, const std::st
|
||||
}
|
||||
} // for (size_t i = 0; i < toks.size(); ++i) {
|
||||
|
||||
// find out which feature function can be applied in this decode step
|
||||
const std::vector<FeatureFunction*> &allFeatures = FeatureFunction::GetFeatureFunctions();
|
||||
for (size_t i = 0; i < allFeatures.size(); ++i) {
|
||||
FeatureFunction *feature = allFeatures[i];
|
||||
if (feature->IsUseable(m_outputFactors)) {
|
||||
m_featuresToApply.push_back(feature);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -92,15 +92,19 @@ public:
|
||||
return m_filePath;
|
||||
}
|
||||
|
||||
const std::vector<FeatureFunction*> &GetFeaturesToApply() const
|
||||
{ return m_featuresToApply; }
|
||||
|
||||
protected:
|
||||
size_t m_tableLimit;
|
||||
|
||||
|
||||
unsigned m_numInputScores;
|
||||
std::string m_filePath;
|
||||
|
||||
std::string m_targetFile;
|
||||
std::string m_alignmentsFile;
|
||||
|
||||
std::vector<FeatureFunction*> m_featuresToApply;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ void PhraseDictionaryMultiModel::CollectSufficientStatistics(const Phrase& src,
|
||||
}
|
||||
|
||||
statistics->targetPhrase->GetScoreBreakdown().Assign(this, scoreVector); // set scores to 0
|
||||
statistics->targetPhrase->Evaluate(src);
|
||||
statistics->targetPhrase->Evaluate(src, GetFeaturesToApply());
|
||||
|
||||
(*allStats)[targetString] = statistics;
|
||||
|
||||
@ -210,7 +210,7 @@ TargetPhraseCollection* PhraseDictionaryMultiModel::CreateTargetPhraseCollection
|
||||
scoreVector[m_numScoreComponents-1] = 1.0;
|
||||
|
||||
statistics->targetPhrase->GetScoreBreakdown().Assign(this, scoreVector);
|
||||
statistics->targetPhrase->Evaluate(src);
|
||||
statistics->targetPhrase->Evaluate(src, GetFeaturesToApply());
|
||||
|
||||
ret->Add(new TargetPhrase(*statistics->targetPhrase));
|
||||
}
|
||||
|
@ -275,7 +275,7 @@ void PhraseDictionaryMultiModelCounts::CollectSufficientStatistics(const Phrase&
|
||||
scoreVector[1] = -raw_scores[1];
|
||||
scoreVector[2] = -raw_scores[2];
|
||||
statistics->targetPhrase->GetScoreBreakdown().Assign(this, scoreVector); // set scores to 0
|
||||
statistics->targetPhrase->Evaluate(src);
|
||||
statistics->targetPhrase->Evaluate(src, GetFeaturesToApply());
|
||||
|
||||
(*allStats)[targetString] = statistics;
|
||||
|
||||
@ -328,7 +328,7 @@ TargetPhraseCollection* PhraseDictionaryMultiModelCounts::CreateTargetPhraseColl
|
||||
scoreVector[4] = FloorScore(TransformScore(2.718));
|
||||
|
||||
statistics->targetPhrase->GetScoreBreakdown().Assign(this, scoreVector);
|
||||
statistics->targetPhrase->Evaluate(src);
|
||||
statistics->targetPhrase->Evaluate(src, GetFeaturesToApply());
|
||||
} catch (AlignmentException& e) {
|
||||
continue;
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ bool RuleTableLoaderCompact::LoadRuleSection(
|
||||
targetPhrase->SetTargetLHS(targetLhs);
|
||||
targetPhrase->SetSourcePhrase(sourcePhrase);
|
||||
|
||||
targetPhrase->Evaluate(sourcePhrase);
|
||||
targetPhrase->Evaluate(sourcePhrase, ruleTable.GetFeaturesToApply());
|
||||
|
||||
// Insert rule into table.
|
||||
TargetPhraseCollection &coll = GetOrCreateTargetPhraseCollection(
|
||||
|
@ -242,7 +242,7 @@ bool RuleTableLoaderStandard::Load(FormatType format
|
||||
}
|
||||
|
||||
targetPhrase->GetScoreBreakdown().Assign(&ruleTable, scoreVector);
|
||||
targetPhrase->Evaluate(sourcePhrase);
|
||||
targetPhrase->Evaluate(sourcePhrase, ruleTable.GetFeaturesToApply());
|
||||
|
||||
TargetPhraseCollection &phraseColl = GetOrCreateTargetPhraseCollection(ruleTable, sourcePhrase, *targetPhrase, sourceLHS);
|
||||
phraseColl.Add(targetPhrase);
|
||||
|
@ -236,7 +236,7 @@ void PhraseDictionaryFuzzyMatch::InitializeForInput(InputType const& inputSenten
|
||||
std::transform(scoreVector.begin(),scoreVector.end(),scoreVector.begin(),FloorScore);
|
||||
|
||||
targetPhrase->GetScoreBreakdown().Assign(this, scoreVector);
|
||||
targetPhrase->Evaluate(sourcePhrase);
|
||||
targetPhrase->Evaluate(sourcePhrase, GetFeaturesToApply());
|
||||
|
||||
TargetPhraseCollection &phraseColl = GetOrCreateTargetPhraseCollection(rootNode, sourcePhrase, *targetPhrase, sourceLHS);
|
||||
phraseColl.Add(targetPhrase);
|
||||
|
Loading…
Reference in New Issue
Block a user