create blank states

This commit is contained in:
Hieu Hoang 2015-11-05 15:34:24 +00:00
parent 31ae7d6f50
commit d9cd216ceb
12 changed files with 54 additions and 15 deletions

View File

@ -41,7 +41,12 @@ Distortion::~Distortion() {
// TODO Auto-generated destructor stub
}
const Moses::FFState* Distortion::EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const
Moses::FFState* Distortion::BlankState(const Manager &mgr, const PhraseImpl &input) const
{
}
Moses::FFState* Distortion::EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const
{
MemPool &pool = mgr.GetPool();

View File

@ -18,7 +18,8 @@ public:
Distortion(size_t startInd, const std::string &line);
virtual ~Distortion();
virtual const Moses::FFState* EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const;
virtual Moses::FFState* BlankState(const Manager &mgr, const PhraseImpl &input) const;
virtual Moses::FFState* EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const;
virtual void
EvaluateInIsolation(const System &system,

View File

@ -36,7 +36,12 @@ SkeletonStatefulFF::~SkeletonStatefulFF() {
// TODO Auto-generated destructor stub
}
const Moses::FFState* SkeletonStatefulFF::EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const
Moses::FFState* SkeletonStatefulFF::BlankState(const Manager &mgr, const PhraseImpl &input) const
{
}
Moses::FFState* SkeletonStatefulFF::EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const
{
return new SkeletonState(0);
}

View File

@ -16,7 +16,8 @@ public:
SkeletonStatefulFF(size_t startInd, const std::string &line);
virtual ~SkeletonStatefulFF();
virtual const Moses::FFState* EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const;
virtual Moses::FFState* BlankState(const Manager &mgr, const PhraseImpl &input) const;
virtual Moses::FFState* EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const;
virtual void
EvaluateInIsolation(const System &system,

View File

@ -24,8 +24,11 @@ public:
size_t GetStatefulInd() const
{ return m_statefulInd; }
//! return uninitialise state
virtual Moses::FFState* BlankState(const Manager &mgr, const PhraseImpl &input) const = 0;
//! return the state associated with the empty hypothesis for a given sentence
virtual const Moses::FFState* EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const = 0;
virtual Moses::FFState* EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const = 0;
virtual Moses::FFState* EvaluateWhenApplied(const Manager &mgr,
const Hypothesis &hypo,

View File

@ -99,8 +99,13 @@ void KENLM::SetParameter(const std::string& key, const std::string& value)
}
}
Moses::FFState* KENLM::BlankState(const Manager &mgr, const PhraseImpl &input) const
{
}
//! return the state associated with the empty hypothesis for a given sentence
const Moses::FFState* KENLM::EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const
Moses::FFState* KENLM::EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const
{
MemPool &pool = mgr.GetPool();
KenLMState *ret = new (pool.Allocate<KenLMState>()) KenLMState();

View File

@ -23,8 +23,10 @@ public:
virtual void Load(System &system);
virtual Moses::FFState* BlankState(const Manager &mgr, const PhraseImpl &input) const;
//! return the state associated with the empty hypothesis for a given sentence
virtual const Moses::FFState* EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const;
virtual Moses::FFState* EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const;
virtual void
EvaluateInIsolation(const System &system,

View File

@ -117,7 +117,12 @@ void LanguageModel::SetParameter(const std::string& key, const std::string& valu
}
}
const Moses::FFState* LanguageModel::EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const
Moses::FFState* LanguageModel::BlankState(const Manager &mgr, const PhraseImpl &input) const
{
}
Moses::FFState* LanguageModel::EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const
{
MemPool &pool = mgr.GetPool();
return new (pool.Allocate<LMState>()) LMState(pool, m_bos);

View File

@ -50,7 +50,8 @@ public:
virtual void SetParameter(const std::string& key, const std::string& value);
virtual const Moses::FFState* EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const;
virtual Moses::FFState* BlankState(const Manager &mgr, const PhraseImpl &input) const;
virtual Moses::FFState* EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const;
virtual void
EvaluateInIsolation(const System &system,

View File

@ -21,10 +21,18 @@ Hypothesis::Hypothesis(Manager &mgr)
{
MemPool &pool = m_mgr.GetPool();
size_t numStatefulFFs = m_mgr.GetSystem().featureFunctions.GetStatefulFeatureFunctions().size();
m_ffStates = (const Moses::FFState **) pool.Allocate(sizeof(Moses::FFState*) * numStatefulFFs);
m_scores = new (pool.Allocate<Scores>()) Scores(pool, m_mgr.GetSystem().featureFunctions.GetNumScores());
// FF states
const std::vector<const StatefulFeatureFunction*> &sfffs = m_mgr.GetSystem().featureFunctions.GetStatefulFeatureFunctions();
size_t numStatefulFFs = sfffs.size();
m_ffStates = (Moses::FFState **) pool.Allocate(sizeof(Moses::FFState*) * numStatefulFFs);
BOOST_FOREACH(const StatefulFeatureFunction *sfff, sfffs) {
size_t statefulInd = sfff->GetStatefulInd();
Moses::FFState *state = sfff->BlankState(mgr, mgr.GetInput());
m_ffStates[statefulInd] = state;
}
}
Hypothesis::~Hypothesis() {
@ -127,7 +135,7 @@ void Hypothesis::EmptyHypothesisState(const PhraseImpl &input)
const std::vector<const StatefulFeatureFunction*> &sfffs = m_mgr.GetSystem().featureFunctions.GetStatefulFeatureFunctions();
BOOST_FOREACH(const StatefulFeatureFunction *sfff, sfffs) {
size_t statefulInd = sfff->GetStatefulInd();
const Moses::FFState *state = sfff->EmptyHypothesisState(m_mgr, input);
Moses::FFState *state = sfff->EmptyHypothesisState(m_mgr, input);
m_ffStates[statefulInd] = state;
}
}
@ -139,7 +147,7 @@ void Hypothesis::EvaluateWhenApplied()
size_t statefulInd = sfff->GetStatefulInd();
const Moses::FFState *prevState = m_prevHypo->GetState(statefulInd);
assert(prevState);
const Moses::FFState *state = sfff->EvaluateWhenApplied(m_mgr, *this, *prevState, *m_scores);
Moses::FFState *state = sfff->EvaluateWhenApplied(m_mgr, *this, *prevState, *m_scores);
m_ffStates[statefulInd] = state;
}

View File

@ -84,7 +84,7 @@ protected:
const Moses::Range *m_range;
const Hypothesis *m_prevHypo;
const Moses::FFState **m_ffStates;
Moses::FFState **m_ffStates;
Scores *m_scores;
Moses::Range m_currTargetWordsRange;
};

View File

@ -35,6 +35,9 @@ public:
Moses::Bitmaps &GetBitmaps()
{ return *m_bitmaps; }
const PhraseImpl &GetInput() const
{ return *m_input; }
const InputPaths &GetInputPaths() const
{ return m_inputPaths; }