mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2025-01-06 19:49:41 +03:00
debug
This commit is contained in:
parent
3d8231bbe6
commit
dc5201ee6e
@ -6,13 +6,17 @@
|
||||
*/
|
||||
#include <boost/functional/hash_fwd.hpp>
|
||||
#include "BidirectionalReorderingState.h"
|
||||
#include "../../legacy/Util2.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Moses2 {
|
||||
|
||||
BidirectionalReorderingState::BidirectionalReorderingState(
|
||||
const LRModel &config,
|
||||
const LRState *bw,
|
||||
const LRState *fw, size_t offset)
|
||||
LRState *bw,
|
||||
LRState *fw,
|
||||
size_t offset)
|
||||
: LRState(config,
|
||||
LRModel::Bidirectional,
|
||||
offset)
|
||||
@ -24,10 +28,31 @@ BidirectionalReorderingState::~BidirectionalReorderingState() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
||||
void BidirectionalReorderingState::Init(const LRState *prev,
|
||||
const TargetPhrase &topt,
|
||||
const InputPathBase &path,
|
||||
bool first)
|
||||
{
|
||||
if (m_backward) {
|
||||
m_backward->Init(prev, topt, path, first);
|
||||
}
|
||||
}
|
||||
|
||||
std::string BidirectionalReorderingState::ToString() const
|
||||
{ return "BidirectionalReorderingState "
|
||||
+ SPrint(this) + " "
|
||||
+ SPrint(m_backward) + " "
|
||||
+ SPrint(m_forward);
|
||||
}
|
||||
|
||||
size_t BidirectionalReorderingState::hash() const
|
||||
{
|
||||
cerr << "hashing " << *this << endl;
|
||||
cerr << "BEFORE hash " << m_backward->ToString() << endl;
|
||||
size_t ret = m_backward->hash();
|
||||
cerr << "HH1" << endl;
|
||||
boost::hash_combine(ret, m_forward->hash());
|
||||
cerr << "ret=" << ret << endl;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -49,7 +74,7 @@ void BidirectionalReorderingState::Expand(const System &system,
|
||||
Scores &scores,
|
||||
FFState &state) const
|
||||
{
|
||||
|
||||
cerr << "BidirectionalReorderingState::Expand" << endl;
|
||||
}
|
||||
|
||||
} /* namespace Moses2 */
|
||||
|
@ -5,24 +5,30 @@
|
||||
* Author: hieu
|
||||
*/
|
||||
#pragma once
|
||||
#include "PhraseBasedReorderingState.h"
|
||||
#include "LRState.h"
|
||||
|
||||
namespace Moses2 {
|
||||
|
||||
class BidirectionalReorderingState: public LRState
|
||||
{
|
||||
public:
|
||||
BidirectionalReorderingState(const LRModel &config,
|
||||
const LRState *bw,
|
||||
const LRState *fw, size_t offset);
|
||||
BidirectionalReorderingState(
|
||||
const LRModel &config,
|
||||
LRState *bw,
|
||||
LRState *fw,
|
||||
size_t offset);
|
||||
|
||||
virtual ~BidirectionalReorderingState();
|
||||
|
||||
void Init(const LRState *prev,
|
||||
const TargetPhrase &topt,
|
||||
const InputPathBase &path,
|
||||
bool first);
|
||||
|
||||
size_t hash() const;
|
||||
virtual bool operator==(const FFState& other) const;
|
||||
|
||||
virtual std::string ToString() const
|
||||
{ return ""; }
|
||||
virtual std::string ToString() const;
|
||||
|
||||
void Expand(const System &system,
|
||||
const LexicalReordering &ff,
|
||||
@ -32,8 +38,8 @@ public:
|
||||
FFState &state) const;
|
||||
|
||||
protected:
|
||||
const LRState *m_backward;
|
||||
const LRState *m_forward;
|
||||
LRState *m_backward;
|
||||
LRState *m_forward;
|
||||
|
||||
};
|
||||
|
||||
|
@ -12,6 +12,8 @@
|
||||
#include "PhraseBasedReorderingState.h"
|
||||
#include "BidirectionalReorderingState.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Moses2 {
|
||||
|
||||
LRModel::LRModel(const std::string &modelType, LexicalReordering &ff)
|
||||
@ -132,6 +134,7 @@ CreateLRState() const
|
||||
case Bidirectional:
|
||||
if (m_phraseBased) {
|
||||
bwd = new PhraseBasedReorderingState(*this, Backward, offset);
|
||||
cerr << "bwd=" << bwd << bwd->ToString() << endl;
|
||||
}
|
||||
else {
|
||||
//bwd = new HReorderingBackwardState(*this, offset);
|
||||
@ -141,6 +144,7 @@ CreateLRState() const
|
||||
case Forward:
|
||||
if (m_phraseBased) {
|
||||
fwd = new PhraseBasedReorderingState(*this, Forward, offset);
|
||||
cerr << "fwd=" << fwd << fwd->ToString() << endl;
|
||||
}
|
||||
else {
|
||||
//fwd = new HReorderingForwardState(*this, input.GetSize(), offset);
|
||||
@ -148,8 +152,10 @@ CreateLRState() const
|
||||
offset += m_collapseScores ? 1 : GetNumberOfTypes();
|
||||
if (m_direction == Forward) return fwd;
|
||||
}
|
||||
return new BidirectionalReorderingState(*this, bwd, fwd, 0);
|
||||
|
||||
BidirectionalReorderingState *ret = new BidirectionalReorderingState(*this, bwd, fwd, 0);
|
||||
cerr << "ret=" << ret->ToString() << endl;
|
||||
return ret;
|
||||
}
|
||||
|
||||
} /* namespace Moses2 */
|
||||
|
@ -10,6 +10,7 @@ class System;
|
||||
class Scores;
|
||||
class TargetPhrase;
|
||||
class InputType;
|
||||
class InputPathBase;
|
||||
|
||||
class LRState : public FFState
|
||||
{
|
||||
@ -21,6 +22,11 @@ public:
|
||||
LRModel::Direction dir,
|
||||
size_t offset);
|
||||
|
||||
virtual void Init(const LRState *prev,
|
||||
const TargetPhrase &topt,
|
||||
const InputPathBase &path,
|
||||
bool first) = 0;
|
||||
|
||||
virtual void Expand(const System &system,
|
||||
const LexicalReordering &ff,
|
||||
const Hypothesis &hypo,
|
||||
|
@ -117,7 +117,9 @@ void LexicalReordering::SetParameter(const std::string& key, const std::string&
|
||||
|
||||
FFState* LexicalReordering::BlankState(MemPool &pool) const
|
||||
{
|
||||
cerr << "BEFORE CreateLRState" << endl;
|
||||
FFState *ret = m_configuration->CreateLRState();
|
||||
cerr << "AFTER CreateLRState" << endl;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -126,13 +128,16 @@ void LexicalReordering::EmptyHypothesisState(FFState &state,
|
||||
const InputType &input,
|
||||
const Hypothesis &hypo) const
|
||||
{
|
||||
cerr << "START EmptyHypothesisState" << endl;
|
||||
if (m_configuration->IsPhraseBased()) {
|
||||
PhraseBasedReorderingState &stateCast = static_cast<PhraseBasedReorderingState&>(state);
|
||||
BidirectionalReorderingState &stateCast = static_cast<BidirectionalReorderingState&>(state);
|
||||
cerr << "BEFORE Init" << endl;
|
||||
stateCast.Init(NULL, hypo.GetTargetPhrase(), hypo.GetInputPath(), true);
|
||||
cerr << "AFTER Init" << endl;
|
||||
}
|
||||
else {
|
||||
cerr << "BEFORE BidirectionalReorderingState" << endl;
|
||||
BidirectionalReorderingState &stateCast = static_cast<BidirectionalReorderingState&>(state);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,7 +207,9 @@ void LexicalReordering::EvaluateWhenApplied(const ManagerBase &mgr,
|
||||
FFState &state) const
|
||||
{
|
||||
const LRState &prevStateCast = static_cast<const LRState&>(prevState);
|
||||
cerr << "BEFORE Expand" << endl;
|
||||
prevStateCast.Expand(mgr.system, *this, hypo, m_PhraseTableInd, scores, state);
|
||||
cerr << "AFTER Expand" << endl;
|
||||
}
|
||||
|
||||
const LexicalReordering::Values *LexicalReordering::GetValues(const Phrase &source, const Phrase &target) const
|
||||
|
@ -9,6 +9,8 @@
|
||||
#include "LexicalReordering.h"
|
||||
#include "../../PhraseBased/Hypothesis.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Moses2 {
|
||||
|
||||
PhraseBasedReorderingState::PhraseBasedReorderingState(
|
||||
@ -22,7 +24,7 @@ PhraseBasedReorderingState::PhraseBasedReorderingState(
|
||||
|
||||
|
||||
void PhraseBasedReorderingState::Init(
|
||||
const PhraseBasedReorderingState *prev,
|
||||
const LRState *prev,
|
||||
const TargetPhrase &topt,
|
||||
const InputPathBase &path,
|
||||
bool first)
|
||||
@ -33,11 +35,12 @@ void PhraseBasedReorderingState::Init(
|
||||
}
|
||||
|
||||
size_t PhraseBasedReorderingState::hash() const {
|
||||
size_t ret;
|
||||
ret = hash_value(prevPath->range);
|
||||
boost::hash_combine(ret, m_direction);
|
||||
cerr << "prevPath=" << prevPath << endl;
|
||||
size_t ret;
|
||||
ret = hash_value(prevPath->range);
|
||||
boost::hash_combine(ret, m_direction);
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool PhraseBasedReorderingState::operator==(const FFState& o) const {
|
||||
|
@ -21,7 +21,7 @@ public:
|
||||
LRModel::Direction dir,
|
||||
size_t offset);
|
||||
|
||||
void Init(const PhraseBasedReorderingState *prev,
|
||||
void Init(const LRState *prev,
|
||||
const TargetPhrase &topt,
|
||||
const InputPathBase &path,
|
||||
bool first);
|
||||
@ -31,7 +31,7 @@ public:
|
||||
|
||||
virtual std::string ToString() const
|
||||
{
|
||||
return "";
|
||||
return "PhraseBasedReorderingState";
|
||||
}
|
||||
|
||||
void Expand(const System &system,
|
||||
|
@ -58,8 +58,11 @@ void Search::Decode()
|
||||
Hypothesis *initHypo = Hypothesis::Create(mgr.GetSystemPool(), mgr);
|
||||
initHypo->Init(mgr, mgr.GetInputPaths().GetBlank(), mgr.GetInitPhrase(), initBitmap);
|
||||
initHypo->EmptyHypothesisState(mgr.GetInput());
|
||||
cerr << "initHypo=" << *initHypo << endl;
|
||||
|
||||
cerr << "BEFORE Add" << endl;
|
||||
m_stack.Add(initHypo, mgr.GetHypoRecycle(), mgr.arcLists);
|
||||
cerr << "AFTER Add" << endl;
|
||||
PostDecode(0);
|
||||
|
||||
for (size_t stackInd = 1; stackInd < mgr.GetInput().GetSize() + 1; ++stackInd) {
|
||||
|
Loading…
Reference in New Issue
Block a user