FF registration is now in FeatureFactory::DefaultSetup, ...

... not in the FF constructor any more.

This is related to a bug fix in Base.cpp, related to moving the
LM OOV feature specification from the global space into the setup
of individual LMs (to eliminate the dependence on StaticData in the
LM constructors).
This commit is contained in:
Ulrich Germann 2015-11-24 18:28:38 +00:00
parent 060a5f1b47
commit bcb0212b5b
8 changed files with 23 additions and 12 deletions

View File

@ -153,6 +153,8 @@ void
FeatureFactory
::DefaultSetup(F *feature)
{
FeatureFunction::Register(feature);
StaticData &static_data = StaticData::InstanceNonConst();
const std::string &featureName = feature->GetScoreProducerDescription();
std::vector<float> weights = static_data.GetParameter()->GetWeights(featureName);

View File

@ -54,7 +54,8 @@ FeatureFunction(const std::string& line, bool registerNow)
{
m_numTuneableComponents = m_numScoreComponents;
ParseLine(line);
if (registerNow) Register();
// if (registerNow) Register(); // now done in FeatureFactory::DefaultSetup()
// TO DO: eliminate the registerNow parameter
}
FeatureFunction::FeatureFunction(size_t numScoreComponents, const std::string& line, bool registerNow)
@ -66,15 +67,16 @@ FeatureFunction::FeatureFunction(size_t numScoreComponents, const std::string& l
{
m_numTuneableComponents = m_numScoreComponents;
ParseLine(line);
if (registerNow) Register();
// if (registerNow) Register(); // now done in FeatureFactory::DefaultSetup()
// TO DO: eliminate the registerNow parameter
}
void
FeatureFunction::
Register()
Register(FeatureFunction* ff)
{
ScoreComponentCollection::RegisterScoreProducer(this);
s_staticColl.push_back(this);
ScoreComponentCollection::RegisterScoreProducer(ff);
s_staticColl.push_back(ff);
}
FeatureFunction::~FeatureFunction() {}

View File

@ -49,7 +49,8 @@ protected:
//In case there's multiple producers with the same description
static std::multiset<std::string> description_counts;
void Register();
public:
static void Register(FeatureFunction* ff);
private:
// void Initialize(const std::string &line);
void ParseLine(const std::string &line);

View File

@ -75,7 +75,7 @@ LexicalReordering(const std::string &line)
<< m_configuration->GetNumScoreComponents() << ")");
m_configuration->ConfigureSparse(sparseArgs, this);
this->Register();
// this->Register();
}
LexicalReordering::

View File

@ -38,10 +38,10 @@ LanguageModel::LanguageModel(const std::string &line) :
m_enableOOVFeature(false)
{
// load m_enableOOVFeature via SetParameter() first
ReadParameters();
// ReadParameters();
this->m_numScoreComponents = this->m_numTuneableComponents = m_enableOOVFeature ? 2 : 1;
// register with the correct m_numScoreComponents
Register();
// Register();
}
@ -112,6 +112,7 @@ void LanguageModel::SetParameter(const std::string& key, const std::string& valu
{
if(key == "oov-feature") {
m_enableOOVFeature = Scan<bool>(value);
this->m_numScoreComponents = this->m_numTuneableComponents = m_enableOOVFeature ? 2 : 1;
} else {
StatefulFeatureFunction::SetParameter(key, value);
}

View File

@ -47,7 +47,7 @@ protected:
public:
virtual ~LanguageModelSingleFactor();
bool IsUseable(const FactorMask &mask) const;
void SetParameter(const std::string& key, const std::string& value);
virtual void SetParameter(const std::string& key, const std::string& value);
const Factor *GetSentenceStart() const {
return m_sentenceStart;

View File

@ -89,7 +89,12 @@ public:
struct MockProducers {
MockProducers() {}
MockProducers()
{
FeatureFunction::Register(&single);
FeatureFunction::Register(&multi);
FeatureFunction::Register(&sparse);
}
MockSingleFeature single;
MockMultiFeature multi;

View File

@ -82,7 +82,7 @@ namespace Moses
// * Don't use features that depend on generation steps that won't be run
// yet at extract time
SetFeaturesToApply();
Register();
// Register();
}
void