From 5a5b00f2ad1ef2cb50e9c58bcb77246f3ed99057 Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Thu, 13 Oct 2011 23:50:28 +0200 Subject: fixed approx bleu --- dtrain/kbestget.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'dtrain/kbestget.h') diff --git a/dtrain/kbestget.h b/dtrain/kbestget.h index c0fd3f47..d141da60 100644 --- a/dtrain/kbestget.h +++ b/dtrain/kbestget.h @@ -14,7 +14,7 @@ namespace dtrain { -typedef double score_t; // float +typedef double score_t; struct ScoredHyp { @@ -31,9 +31,11 @@ struct LocalScorer vector w_; virtual score_t - Score(vector& hyp, vector& ref)=0; + Score(vector& hyp, vector& ref, const unsigned rank)=0; - void + void Reset() {} // only for approx bleu + + inline void Init(unsigned N, vector weights) { assert(N > 0); @@ -42,7 +44,7 @@ struct LocalScorer else w_ = weights; } - score_t + inline score_t brevity_penaly(const unsigned hyp_len, const unsigned ref_len) { if (hyp_len > ref_len) return 1; @@ -55,11 +57,10 @@ struct HypSampler : public DecoderObserver LocalScorer* scorer_; vector* ref_; virtual vector* GetSamples()=0; - void SetScorer(LocalScorer* scorer) { scorer_ = scorer; } - void SetRef(vector& ref) { ref_ = &ref; } + inline void SetScorer(LocalScorer* scorer) { scorer_ = scorer; } + inline void SetRef(vector& ref) { ref_ = &ref; } }; -///////////////////////////////////////////////////////////////////// -// wtf +/////////////////////////////////////////////////////////////////////////////// @@ -107,7 +108,7 @@ struct KBestGetter : public HypSampler h.f = d->feature_values; h.model = log(d->score); h.rank = i; - h.score = scorer_->Score(h.w, *ref_); + h.score = scorer_->Score(h.w, *ref_, i); s_.push_back(h); } } @@ -126,7 +127,7 @@ struct KBestGetter : public HypSampler h.f = d->feature_values; h.model = log(d->score); h.rank = i; - h.score = scorer_->Score(h.w, *ref_); + h.score = scorer_->Score(h.w, *ref_, i); s_.push_back(h); } } -- cgit v1.2.3