From 25acffeb79a3258d978b7a3168b076f959bfb1bb Mon Sep 17 00:00:00 2001 From: graehl Date: Tue, 27 Jul 2010 04:59:59 +0000 Subject: sample fsa ffs compile git-svn-id: https://ws10smt.googlecode.com/svn/trunk@432 ec762483-ff6d-05da-a07a-a48fb63a330f --- decoder/cdec.cc | 11 ++++++----- decoder/cdec_ff.cc | 5 ++--- decoder/ff_fsa.h | 40 ++++++++++++++++++++++++++++++---------- decoder/ff_lm_fsa.h | 6 +++--- decoder/ff_sample_fsa.h | 5 ++--- 5 files changed, 43 insertions(+), 24 deletions(-) (limited to 'decoder') diff --git a/decoder/cdec.cc b/decoder/cdec.cc index 76551cfa..460e9f15 100644 --- a/decoder/cdec.cc +++ b/decoder/cdec.cc @@ -388,6 +388,12 @@ int main(int argc, char** argv) { exit(1); } + const string input = str("input",conf); + cerr << "Reading input from " << ((input == "-") ? "STDIN" : input.c_str()) << endl; + ReadFile in_read(input); + istream *in = in_read.stream(); + assert(*in); + // load feature weights (and possibly freeze feature set) vector feature_weights,prelm_feature_weights; Weights w,prelm_w; @@ -503,11 +509,6 @@ int main(int argc, char** argv) { int combine_size = conf["combine_size"].as(); if (combine_size < 1) combine_size = 1; - const string input = str("input",conf); - cerr << "Reading input from " << ((input == "-") ? "STDIN" : input.c_str()) << endl; - ReadFile in_read(input); - istream *in = in_read.stream(); - assert(*in); SparseVector acc_vec; // accumulate gradient double acc_obj = 0; // accumulate objective diff --git a/decoder/cdec_ff.cc b/decoder/cdec_ff.cc index c8cd8a66..fc64e5c4 100644 --- a/decoder/cdec_ff.cc +++ b/decoder/cdec_ff.cc @@ -8,19 +8,18 @@ #include "ff_factory.h" #include "ff_ruleshape.h" #include "ff_bleu.h" -//#include "ff_sample_fsa.h" #include "ff_lm_fsa.h" +#include "ff_sample_fsa.h" + boost::shared_ptr global_ff_registry; void register_feature_functions() { global_ff_registry->Register(new FFFactory); global_ff_registry->Register(new FFFactory >); // same as LM but using fsa wrapper - /* // sample_fsa: global_ff_registry->Register(new FFFactory); // same as WordPenalty, but implemented using ff_fsa global_ff_registry->Register(new FFFactory >); global_ff_registry->Register(new FFFactory >); - */ //TODO: use for all features the new Register which requires usage(...) #ifdef HAVE_RANDLM diff --git a/decoder/ff_fsa.h b/decoder/ff_fsa.h index 85d184ee..45837f2c 100755 --- a/decoder/ff_fsa.h +++ b/decoder/ff_fsa.h @@ -201,7 +201,7 @@ public: template inline void ScanAccum(SentenceMetadata const& smeta,const Hypergraph::Edge& edge, WordID w,void const* state,void *next_state,Accum *a) const { - Add(d().Scan1Meta(smeta,edge,smeta,edge,w,state,next_state),a); + Add(d().Scan1Meta(smeta,edge,w,state,next_state),a); } // bounce back and forth between two state vars starting at cs, returning end state location. if we required src=dest addr safe state updating, this concept wouldn't need to exist. @@ -233,7 +233,7 @@ public: } - + // note you'll still have to override ScanAccum // override this (and SCAN_PHRASE_ACCUM_OVERRIDE ) if you want e.g. maximum possible order ngram scores with markov_order < n-1. in the future SparseFeatureAccumulator will probably be the only option for type-erased FSA ffs. you will be adding to accum, not setting template inline void ScanPhraseAccum(SentenceMetadata const& smeta,const Hypergraph::Edge& edge, @@ -284,10 +284,14 @@ public: } template - inline void Add(Featval v,Accum *a) const { // for single-feat only + inline void Add(Featval v,Accum *a) const { // for single-feat only. but will work for different accums + a->Add(fid_,v); + } + inline void Add(Featval v,SingleFeatureAccumulator *a) const { a->Add(v); } + inline void set_feat(FeatureVector *features,Featval v) const { features->set_value(fid_,v); } @@ -343,15 +347,31 @@ public: o<maybe_add(d().fid_,d().ScanT1(w,prev_st,new_st)); + + // override this + Featval ScanT1S(WordID w,St const& /* from */ ,St & /* to */) const { + return 0; + } + + // or this + Featval ScanT1(SentenceMetadata const& /* smeta */,const Hypergraph::Edge& /* edge */,WordID w,St const& from ,St & to) const { + return d().ScanT1S(w,from,to); } - inline void Scan(SentenceMetadata const& smeta,const Hypergraph::Edge& edge,WordID w,void const* st,void *next_state,FeatureVector *features) const { + + // or this (most general) + template + inline void ScanT(SentenceMetadata const& smeta,const Hypergraph::Edge& edge,WordID w,St const& prev_st,St &new_st,Accum *a) const { + Add(d().ScanT1(smeta,edge,w,prev_st,new_st),a); + } + + // note: you're on your own when it comes to Phrase overrides. see FsaFeatureFunctionBase. sorry. + + template + inline void ScanAccum(SentenceMetadata const& smeta,const Hypergraph::Edge& edge,WordID w,void const* st,void *next_state,Accum *a) const { Impl const& im=d(); - FSADBG(edge,"Scan "<"<"<