From b2ad842245f1645e4e9f3c60a80a07e13151a560 Mon Sep 17 00:00:00 2001 From: graehl Date: Mon, 26 Jul 2010 01:07:36 +0000 Subject: stateful ff_from_fsa works - fixed bug that never moved right state from rightmost variable up to result git-svn-id: https://ws10smt.googlecode.com/svn/trunk@413 ec762483-ff6d-05da-a07a-a48fb63a330f --- decoder/ff_from_fsa.h | 21 +++++++++++---------- decoder/ff_fsa.h | 35 ++++++++++++++++++++--------------- decoder/ff_sample_fsa.h | 20 +++++++++++++++----- decoder/hg.h | 4 ++-- 4 files changed, 48 insertions(+), 32 deletions(-) (limited to 'decoder') diff --git a/decoder/ff_from_fsa.h b/decoder/ff_from_fsa.h index d32e90df..237e5d0d 100755 --- a/decoder/ff_from_fsa.h +++ b/decoder/ff_from_fsa.h @@ -3,8 +3,8 @@ #include "ff_fsa.h" -#define FSA_FF_DEBUG -#ifdef FSA_FF_DEBUG +#define FSA_FF_DEBUG 0 +#if FSA_FF_DEBUG # define FSAFFDBG(e,x) FSADBGif(debug,e,x) # define FSAFFDBGnl(e) FSADBGif_nl(debug,e) #else @@ -49,7 +49,6 @@ public: FeatureVector* estimated_features, void* out_state) const { - FSAFFDBG(edge,"(FromFsa) "<M) // child had full state already (had a "gap"); if nw==M then we already reached the same state via left word heuristic scan above + if (nw==M) // child had full state already fsa.reset(fsa_state(a)); + assert(nw<=M); } else { // single word WordID ew=e[j]; FSAFFDBG(edge,' '< "<{"<") - FSAFFDBG(edge," right: "< "<{"<R if we only scan 1 word at a time, that's fine -//#define FSA_DEBUG +#define FSA_DEBUG 0 -#ifdef USE_INFO_EDGE +#if USE_INFO_EDGE #define FSA_DEBUG_CERR 0 #else #define FSA_DEBUG_CERR 1 @@ -24,7 +26,7 @@ #define FSA_DEBUG_DEBUG 0 # define FSADBGif(i,e,x) do { if (i) { if (FSA_DEBUG_CERR){std::cerr< # define FSADBG(e,x) FSADBGif(d().debug(),e,x) # define FSADBGnl(e) FSADBGif_nl(d().debug(),e,x) @@ -93,6 +95,11 @@ protected: } public: + // can override to different return type, e.g. just return feats: + Featval describe_features(FeatureVector const& feats) const { + return feats.get(fid_); + } + bool debug() const { return true; } int fid() const { return fid_; } // return the one most important feature (for debugging) std::string name() const { @@ -240,6 +247,8 @@ protected: Base::start.resize(sizeof(State)); Base::h_start.resize(sizeof(State)); } + assert(Base::start.size()==sizeof(State)); + assert(Base::h_start.size()==sizeof(State)); state(Base::start.begin())=s; state(Base::h_start.begin())=heuristic_s; } @@ -254,28 +263,24 @@ public: o<maybe_add(d().fid_,d().ScanT1(w,prevlen,len)); + Featval ScanT1(WordID w,St const&,St &) const { return 0; } + inline void ScanT(SentenceMetadata const& smeta,const Hypergraph::Edge& edge,WordID w,St const& prev_st,St &new_st,FeatureVector *features) const { + features->maybe_add(d().fid_,d().ScanT1(w,prev_st,new_st)); } - inline void Scan(SentenceMetadata const& smeta,const Hypergraph::Edge& edge,WordID w,void const* st,void *next_state,FeatureVector *features) const { Impl const& im=d(); - FSADBG(edge,"Scan "<"<"<