From 7dfee211a81fdb42f250ba793a469ed8a2dcc3bf Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Mon, 7 Feb 2011 15:03:39 -0500 Subject: more span-level features --- decoder/ff_spans.cc | 29 +++++++++++++++++++++++++++-- decoder/ff_spans.h | 1 + 2 files changed, 28 insertions(+), 2 deletions(-) (limited to 'decoder') diff --git a/decoder/ff_spans.cc b/decoder/ff_spans.cc index 6fa49d45..b454c9fd 100644 --- a/decoder/ff_spans.cc +++ b/decoder/ff_spans.cc @@ -25,7 +25,10 @@ void SpanFeatures::TraversalFeaturesImpl(const SentenceMetadata& smeta, assert(edge.j_ < end_span_ids_.size()); assert(edge.j_ >= 0); features->set_value(end_span_ids_[edge.j_], 1); - + assert(edge.i_ < beg_span_ids_.size()); + assert(edge.i_ >= 0); + features->set_value(beg_span_ids_[edge.i_], 1); + features->set_value(span_feats_(edge.i_,edge.j_), 1); if (edge.Arity() == 2) { const TRule& rule = *edge.rule_; if (rule.f_[0] == kS && rule.f_[1] == kX) { @@ -36,15 +39,37 @@ void SpanFeatures::TraversalFeaturesImpl(const SentenceMetadata& smeta, void SpanFeatures::PrepareForInput(const SentenceMetadata& smeta) { const Lattice& lattice = smeta.GetSourceLattice(); - WordID eos = TD::Convert(""); + const WordID eos = TD::Convert(""); + const WordID bos = TD::Convert(""); + beg_span_ids_.resize(lattice.size() + 1); end_span_ids_.resize(lattice.size() + 1); for (int i = 0; i <= lattice.size(); ++i) { WordID word = eos; + WordID bword = bos; + if (i > 0) + bword = lattice[i-1][0].label; if (i < lattice.size()) word = lattice[i][0].label; // rather arbitrary for lattices ostringstream sfid; sfid << "ES:" << TD::Convert(word); end_span_ids_[i] = FD::Convert(sfid.str()); + ostringstream bfid; + bfid << "BS:" << TD::Convert(bword); + beg_span_ids_[i] = FD::Convert(bfid.str()); } + span_feats_.resize(lattice.size() + 1, lattice.size() + 1); + for (int i = 0; i <= lattice.size(); ++i) { + WordID bword = bos; + if (i > 0) + bword = lattice[i-1][0].label; + for (int j = 0; j <= lattice.size(); ++j) { + WordID word = eos; + if (j < lattice.size()) + word = lattice[j][0].label; + ostringstream pf; + pf << "SS:" << TD::Convert(bword) << "_" << TD::Convert(word); + span_feats_(i,j) = FD::Convert(pf.str()); + } + } } diff --git a/decoder/ff_spans.h b/decoder/ff_spans.h index 588956c9..0446d062 100644 --- a/decoder/ff_spans.h +++ b/decoder/ff_spans.h @@ -21,6 +21,7 @@ class SpanFeatures : public FeatureFunction { const int kX; Array2D span_feats_; std::vector end_span_ids_; + std::vector beg_span_ids_; }; #endif -- cgit v1.2.3