From 471b69d38404452e5150d1955d4dc96744cbbeda Mon Sep 17 00:00:00 2001 From: graehl Date: Thu, 8 Jul 2010 23:27:05 +0000 Subject: feature functions support e.g. --usage=LanguageModel, report feature ids, warn about duplicate ids, 0-expand weight vector for no segfault, --warn_0_weight, and know their own names to simplify registration git-svn-id: https://ws10smt.googlecode.com/svn/trunk@192 ec762483-ff6d-05da-a07a-a48fb63a330f --- decoder/ff.cc | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) (limited to 'decoder/ff.cc') diff --git a/decoder/ff.cc b/decoder/ff.cc index 73dbbdc9..3f433dfb 100644 --- a/decoder/ff.cc +++ b/decoder/ff.cc @@ -29,6 +29,55 @@ string FeatureFunction::usage_helper(std::string const& name,std::string const& return r; } +FeatureFunction::Features FeatureFunction::single_feature(WordID feat) { + return Features(1,feat); +} + +FeatureFunction::Features ModelSet::all_features(std::ostream *warn) { + typedef FeatureFunction::Features FFS; + FFS ffs; +#define WARNFF(x) do { if (warn) { *warn << "WARNING: "<< x ; *warn< FFM; + FFM ff_from; + for (unsigned i=0;i= weights_.size()) + weights_.resize(fid+1); + pair i_new=ff_from.insert(FFM::value_type(fid,ffname)); + if (i_new.second) + ffs.push_back(fid); + else { + WARNFF(ffname<<" models["<second); + } + } + } + return ffs; +#undef WARNFF +} + +void ModelSet::show_features(std::ostream &out,std::ostream &warn,bool warn_zero_wt) +{ + typedef FeatureFunction::Features FFS; + FFS ffs=all_features(&warn); + out << "Weight Feature\n"; + for (unsigned i=0;i& ant_states, @@ -75,12 +133,16 @@ void SourceWordPenalty::TraversalFeaturesImpl(const SentenceMetadata& smeta, ArityPenalty::ArityPenalty(const std::string& /* param */) : value_(-1.0 / log(10)) { string fname = "Arity_X"; - for (int i = 0; i < 10; ++i) { + for (int i = 0; i < N_ARITIES; ++i) { fname[6]=i + '0'; fids_[i] = FD::Convert(fname); } } +FeatureFunction::Features ArityPenalty::features() const { + return Features(&fids_[0],&fids_[N_ARITIES]); +} + void ArityPenalty::TraversalFeaturesImpl(const SentenceMetadata& smeta, const Hypergraph::Edge& edge, const std::vector& ant_states, -- cgit v1.2.3