hypo hierarchy

This commit is contained in:
Hieu Hoang 2016-02-26 15:19:20 +00:00
parent f18a257069
commit 9a51c62fa1
17 changed files with 106 additions and 75 deletions

View File

@ -6,8 +6,8 @@
*/
#include <sstream>
#include "Distortion.h"
#include "../Search/Hypothesis.h"
#include "../Search/Manager.h"
#include "../PhraseBased/Hypothesis.h"
#include "../PhraseBased/Manager.h"
#include "../legacy/Range.h"
#include "../legacy/Bitmap.h"

View File

@ -10,8 +10,8 @@
#include "../TranslationModel/PhraseTable.h"
#include "../System.h"
#include "../PhraseImpl.h"
#include "../Search/Manager.h"
#include "../Search/Hypothesis.h"
#include "../PhraseBased/Manager.h"
#include "../PhraseBased/Hypothesis.h"
#include "../legacy/InputFileStream.h"
#include "../legacy/Util2.h"
#include "../legacy/CompactPT/LexicalReorderingTableCompact.h"

View File

@ -6,8 +6,8 @@
*/
#include <sstream>
#include "SkeletonStatefulFF.h"
#include "../Search/Manager.h"
#include "../Search/Hypothesis.h"
#include "../PhraseBased/Manager.h"
#include "../PhraseBased/Hypothesis.h"
using namespace std;

View File

@ -11,7 +11,7 @@
#include <boost/foreach.hpp>
#include "StatefulFeatureFunction.h"
#include "../Search/Hypothesis.h"
#include "../PhraseBased/Hypothesis.h"
namespace Moses2
{

View File

@ -9,7 +9,7 @@
#include "PhraseImpl.h"
#include "System.h"
#include "legacy/Range.h"
#include "Search/Manager.h"
#include "PhraseBased/Manager.h"
using namespace std;

View File

@ -10,8 +10,8 @@
#include "../Phrase.h"
#include "../Scores.h"
#include "../System.h"
#include "../Search/Hypothesis.h"
#include "../Search/Manager.h"
#include "../PhraseBased/Hypothesis.h"
#include "../PhraseBased/Manager.h"
#include "lm/state.hh"
#include "lm/left.hh"
#include "../legacy/FactorCollection.h"

View File

@ -8,8 +8,8 @@
#include "LanguageModel.h"
#include "../Phrase.h"
#include "../System.h"
#include "../Search/Manager.h"
#include "../Search/Hypothesis.h"
#include "../PhraseBased/Manager.h"
#include "../PhraseBased/Hypothesis.h"
#include "../legacy/Util2.h"
#include "../legacy/InputFileStream.h"
#include "../legacy/PointerState.h"

View File

@ -5,7 +5,6 @@
#include "Phrase.h"
#include "TranslationTask.h"
#include "MemPool.h"
#include "Search/Manager.h"
#include "legacy/InputFileStream.h"
#include "legacy/Parameter.h"
#include "legacy/ThreadPool.h"

View File

@ -23,25 +23,7 @@ namespace Moses2
//size_t g_numHypos = 0;
Hypothesis *Hypothesis::Create(MemPool &pool, Manager &mgr)
{
// ++g_numHypos;
Hypothesis *ret;
Recycler<Hypothesis*> &recycler = mgr.GetHypoRecycle();
ret = recycler.Get();
if (ret) {
// got new hypo from recycler. Do nothing
}
else {
ret = new (pool.Allocate<Hypothesis>()) Hypothesis(pool, mgr.system);
recycler.Keep(ret);
}
return ret;
}
Hypothesis::Hypothesis(MemPool &pool, const System &system)
:m_currTargetWordsRange()
HypothesisBase::HypothesisBase(MemPool &pool, const System &system)
{
m_scores = new (pool.Allocate<Scores>()) Scores(system, pool, system.featureFunctions.GetNumScores());
@ -57,6 +39,61 @@ Hypothesis::Hypothesis(MemPool &pool, const System &system)
}
}
size_t HypothesisBase::hash(size_t seed) const
{
size_t numStatefulFFs = GetManager().system.featureFunctions.GetStatefulFeatureFunctions().size();
// states
for (size_t i = 0; i < numStatefulFFs; ++i) {
const FFState *state = m_ffStates[i];
size_t hash = state->hash();
boost::hash_combine(seed, hash);
}
return seed;
}
bool HypothesisBase::operator==(const HypothesisBase &other) const
{
size_t numStatefulFFs = GetManager().system.featureFunctions.GetStatefulFeatureFunctions().size();
// states
for (size_t i = 0; i < numStatefulFFs; ++i) {
const FFState &thisState = *m_ffStates[i];
const FFState &otherState = *other.m_ffStates[i];
if (thisState != otherState) {
return false;
}
}
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
Hypothesis *Hypothesis::Create(MemPool &pool, Manager &mgr)
{
// ++g_numHypos;
Hypothesis *ret;
Recycler<Hypothesis*> &recycler = mgr.GetHypoRecycle();
ret = recycler.Get();
if (ret) {
// got new hypo from recycler. Do nothing
}
else {
ret = new (pool.Allocate<Hypothesis>()) Hypothesis(pool, mgr.system);
//cerr << "Hypothesis=" << sizeof(Hypothesis) << " " << ret << endl;
recycler.Keep(ret);
}
return ret;
}
Hypothesis::Hypothesis(MemPool &pool, const System &system)
:HypothesisBase(pool, system)
,m_currTargetWordsRange()
{
}
Hypothesis::~Hypothesis() {
// TODO Auto-generated destructor stub
}
@ -100,40 +137,22 @@ void Hypothesis::Init(Manager &mgr, const Hypothesis &prevHypo,
size_t Hypothesis::hash() const
{
size_t numStatefulFFs = GetManager().system.featureFunctions.GetStatefulFeatureFunctions().size();
size_t seed;
// coverage
seed = (size_t) m_sourceCompleted;
size_t seed = (size_t) m_sourceCompleted;
// states
for (size_t i = 0; i < numStatefulFFs; ++i) {
const FFState *state = m_ffStates[i];
size_t hash = state->hash();
boost::hash_combine(seed, hash);
}
seed = HypothesisBase::hash(seed);
return seed;
}
bool Hypothesis::operator==(const Hypothesis &other) const
{
size_t numStatefulFFs = GetManager().system.featureFunctions.GetStatefulFeatureFunctions().size();
// coverage
if (m_sourceCompleted != other.m_sourceCompleted) {
return false;
}
// states
for (size_t i = 0; i < numStatefulFFs; ++i) {
const FFState &thisState = *m_ffStates[i];
const FFState &otherState = *other.m_ffStates[i];
if (thisState != otherState) {
return false;
}
}
return true;
bool ret = HypothesisBase::operator ==(other);
return ret;
}
void Hypothesis::OutputToStream(std::ostream &out) const

View File

@ -26,7 +26,33 @@ class StatefulFeatureFunction;
class InputType;
class InputPath;
class Hypothesis {
class HypothesisBase
{
public:
inline Manager &GetManager() const
{ return *m_mgr; }
const Scores &GetScores() const
{ return *m_scores; }
const FFState *GetState(size_t ind) const
{ return m_ffStates[ind]; }
size_t hash(size_t seed = 0) const;
bool operator==(const HypothesisBase &other) const;
protected:
Manager *m_mgr;
Scores *m_scores;
FFState **m_ffStates;
HypothesisBase(MemPool &pool, const System &system);
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
class Hypothesis : public HypothesisBase
{
friend std::ostream& operator<<(std::ostream &, const Hypothesis &);
Hypothesis(MemPool &pool, const System &system);
@ -48,9 +74,6 @@ public:
size_t hash() const;
bool operator==(const Hypothesis &other) const;
inline Manager &GetManager() const
{ return *m_mgr; }
inline const Bitmap &GetBitmap() const
{ return *m_sourceCompleted; }
@ -61,18 +84,12 @@ public:
return m_currTargetWordsRange;
}
const Scores &GetScores() const
{ return *m_scores; }
SCORE GetFutureScore() const
{ return GetScores().GetTotalScore() + m_estimatedScore; }
const TargetPhrase &GetTargetPhrase() const
{ return *m_targetPhrase; }
const FFState *GetState(size_t ind) const
{ return m_ffStates[ind]; }
void OutputToStream(std::ostream &out) const;
void EmptyHypothesisState(const InputType &input);
@ -96,14 +113,11 @@ public:
void Swap(Hypothesis &other);
protected:
Manager *m_mgr;
const TargetPhrase *m_targetPhrase;
const Bitmap *m_sourceCompleted;
const InputPath *m_path;
const Hypothesis *m_prevHypo;
FFState **m_ffStates;
Scores *m_scores;
SCORE m_estimatedScore;
Range m_currTargetWordsRange;
};

View File

@ -11,7 +11,7 @@
#include <cstddef>
#include <string>
#include <deque>
#include "../Search/Manager.h"
#include "../ManagerBase.h"
namespace Moses2
{

View File

@ -10,7 +10,7 @@
#include "../Scores.h"
#include "../System.h"
#include "../MemPool.h"
#include "../Search/Manager.h"
#include "../PhraseBased/Manager.h"
using namespace std;

View File

@ -10,7 +10,7 @@
#include "Scores.h"
#include "System.h"
#include "MemPool.h"
#include "Search/Manager.h"
#include "PhraseBased/Manager.h"
using namespace std;

View File

@ -10,7 +10,7 @@
#include "../InputPaths.h"
#include "../legacy/Util2.h"
#include "../TypeDef.h"
#include "../Search/Manager.h"
#include "../PhraseBased/Manager.h"
using namespace std;

View File

@ -14,7 +14,7 @@
#include "../legacy/InputFileStream.h"
#include "../legacy/ProbingPT/probing_hash_utils.hh"
#include "../FF/FeatureFunctions.h"
#include "../Search/Manager.h"
#include "../PhraseBased/Manager.h"
#include "../legacy/FactorCollection.h"
#include "../legacy/ProbingPT/quering.hh"
#include "../legacy/Util2.h"

View File

@ -9,7 +9,7 @@
#include "../System.h"
#include "../InputPath.h"
#include "../Scores.h"
#include "../Search/Manager.h"
#include "../PhraseBased/Manager.h"
#include "../TargetPhraseImpl.h"
namespace Moses2

View File

@ -1,7 +1,6 @@
#include "TranslationTask.h"
#include "System.h"
#include "Search/Manager.h"
#include "Search/Hypothesis.h"
#include "PhraseBased/Manager.h"
using namespace std;