mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2025-01-06 19:49:41 +03:00
debug info
This commit is contained in:
parent
7e456724b8
commit
de5c3cc797
@ -5,6 +5,7 @@
|
||||
* Author: hieu
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "Hypothesis.h"
|
||||
#include "Manager.h"
|
||||
#include "System.h"
|
||||
@ -15,12 +16,12 @@ Hypothesis::Hypothesis(Manager &mgr,
|
||||
const Moses::Bitmap &bitmap)
|
||||
:m_mgr(mgr)
|
||||
,m_targetPhrase(tp)
|
||||
,m_bitmap(bitmap)
|
||||
,m_sourceCompleted(bitmap)
|
||||
,m_range(range)
|
||||
,m_prevHypo(NULL)
|
||||
{
|
||||
util::Pool &pool = mgr.GetPool();
|
||||
size_t numStatefulFFs = mgr.GetSystem().GetStatefulFeatureFunctions().size();
|
||||
util::Pool &pool = m_mgr.GetPool();
|
||||
size_t numStatefulFFs = m_mgr.GetSystem().GetStatefulFeatureFunctions().size();
|
||||
m_ffStates = (Moses::FFState **) pool.Allocate(sizeof(Moses::FFState*) * numStatefulFFs);
|
||||
}
|
||||
|
||||
@ -30,11 +31,13 @@ Hypothesis::Hypothesis(const Hypothesis &prevHypo,
|
||||
const Moses::Bitmap &bitmap)
|
||||
:m_mgr(prevHypo.m_mgr)
|
||||
,m_targetPhrase(tp)
|
||||
,m_bitmap(bitmap)
|
||||
,m_sourceCompleted(bitmap)
|
||||
,m_range(pathRange)
|
||||
,m_prevHypo(&prevHypo)
|
||||
{
|
||||
|
||||
util::Pool &pool = m_mgr.GetPool();
|
||||
size_t numStatefulFFs = m_mgr.GetSystem().GetStatefulFeatureFunctions().size();
|
||||
m_ffStates = (Moses::FFState **) pool.Allocate(sizeof(Moses::FFState*) * numStatefulFFs);
|
||||
}
|
||||
|
||||
Hypothesis::~Hypothesis() {
|
||||
@ -47,7 +50,8 @@ size_t Hypothesis::hash() const
|
||||
size_t seed;
|
||||
|
||||
// coverage
|
||||
//seed = m_sourceCompleted.hash();
|
||||
seed = m_sourceCompleted.hash();
|
||||
seed = rand();
|
||||
|
||||
// states
|
||||
for (size_t i = 0; i < numStatefulFFs; ++i) {
|
||||
@ -63,9 +67,9 @@ bool Hypothesis::operator==(const Hypothesis &other) const
|
||||
{
|
||||
size_t numStatefulFFs = m_mgr.GetSystem().GetStatefulFeatureFunctions().size();
|
||||
// coverage
|
||||
// if (m_sourceCompleted != other.m_sourceCompleted) {
|
||||
// return false;
|
||||
// }
|
||||
if (m_sourceCompleted != other.m_sourceCompleted) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// states
|
||||
for (size_t i = 0; i < numStatefulFFs; ++i) {
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
bool operator==(const Hypothesis &other) const;
|
||||
|
||||
const Moses::Bitmap &GetBitmap() const
|
||||
{ return m_bitmap; }
|
||||
{ return m_sourceCompleted; }
|
||||
|
||||
const Moses::Range &GetRange() const
|
||||
{ return m_range; }
|
||||
@ -40,7 +40,7 @@ public:
|
||||
protected:
|
||||
Manager &m_mgr;
|
||||
const TargetPhrase &m_targetPhrase;
|
||||
const Moses::Bitmap &m_bitmap;
|
||||
const Moses::Bitmap &m_sourceCompleted;
|
||||
const Moses::Range &m_range;
|
||||
const Hypothesis *m_prevHypo;
|
||||
|
||||
|
@ -29,7 +29,7 @@ Manager::Manager(System &system, const std::string &inputStr)
|
||||
pt.Lookups(m_inputPaths);
|
||||
}
|
||||
|
||||
m_stacks.resize(m_input->GetSize());
|
||||
m_stacks.resize(m_input->GetSize() + 1);
|
||||
m_bitmaps = new Moses::Bitmaps(m_input->GetSize(), vector<bool>(0));
|
||||
m_search = new SearchNormal(*this, m_stacks);
|
||||
}
|
||||
@ -37,7 +37,8 @@ Manager::Manager(System &system, const std::string &inputStr)
|
||||
void Manager::Decode()
|
||||
{
|
||||
const Moses::Bitmap &initBitmap = m_bitmaps->GetInitialBitmap();
|
||||
Hypothesis *iniHypo = new (GetPool().Allocate<Hypothesis>()) Hypothesis(*this, m_initPhrase, m_initRange, initBitmap);
|
||||
Hypothesis *initHypo = new (GetPool().Allocate<Hypothesis>()) Hypothesis(*this, m_initPhrase, m_initRange, initBitmap);
|
||||
m_stacks[0].Add(initHypo);
|
||||
|
||||
for (size_t i = 0; i < m_stacks.size(); ++i) {
|
||||
m_search->Decode(i);
|
||||
|
@ -13,6 +13,8 @@
|
||||
#include "TargetPhrases.h"
|
||||
#include "TargetPhrase.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
SearchNormal::SearchNormal(Manager &mgr, std::vector<Stack> &stacks)
|
||||
:m_mgr(mgr)
|
||||
,m_stacks(stacks)
|
||||
@ -27,11 +29,12 @@ SearchNormal::~SearchNormal() {
|
||||
|
||||
void SearchNormal::Decode(size_t stackInd)
|
||||
{
|
||||
Stack &stack = m_stacks[stackInd];
|
||||
Stack &stack = m_stacks[stackInd];
|
||||
|
||||
BOOST_FOREACH(const Hypothesis *hypo, stack) {
|
||||
Extend(*hypo);
|
||||
}
|
||||
DebugStacks();
|
||||
}
|
||||
|
||||
void SearchNormal::Extend(const Hypothesis &hypo)
|
||||
@ -85,4 +88,15 @@ void SearchNormal::Extend(const Hypothesis &hypo,
|
||||
const Moses::Bitmap &newBitmap)
|
||||
{
|
||||
Hypothesis *newHypo = new (m_mgr.GetPool().Allocate<Hypothesis>()) Hypothesis(hypo, tp, pathRange, newBitmap);
|
||||
|
||||
size_t numWordsCovered = newBitmap.GetNumWordsCovered();
|
||||
m_stacks[numWordsCovered].Add(newHypo);
|
||||
}
|
||||
|
||||
void SearchNormal::DebugStacks() const
|
||||
{
|
||||
BOOST_FOREACH(const Stack &stack, m_stacks) {
|
||||
cerr << stack.GetSize() << " ";
|
||||
}
|
||||
cerr << endl;
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ public:
|
||||
|
||||
void Decode(size_t stackInd);
|
||||
|
||||
|
||||
protected:
|
||||
Manager &m_mgr;
|
||||
std::vector<Stack> &m_stacks;
|
||||
@ -39,6 +40,8 @@ protected:
|
||||
const TargetPhrase &tp,
|
||||
const Moses::Range &pathRange,
|
||||
const Moses::Bitmap &newBitmap);
|
||||
|
||||
void DebugStacks() const;
|
||||
};
|
||||
|
||||
#endif /* SEARCHNORMAL_H_ */
|
||||
|
@ -29,6 +29,9 @@ public:
|
||||
Stack();
|
||||
virtual ~Stack();
|
||||
|
||||
size_t GetSize() const
|
||||
{ return m_hypos.size(); }
|
||||
|
||||
bool Add(Hypothesis *hypo);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user