From 9fe6d978313f742477863ff42b9158cf2f55414f Mon Sep 17 00:00:00 2001
From: Patrick Simianer
Date: Sun, 25 Sep 2011 21:43:57 +0200
Subject: kbest, ksampler refactoring
---
dtrain/kbestget.h | 55 ++++++++++++++++++++++++++-----------------------------
1 file changed, 26 insertions(+), 29 deletions(-)
(limited to 'dtrain/kbestget.h')
diff --git a/dtrain/kbestget.h b/dtrain/kbestget.h
index 79201182..403384de 100644
--- a/dtrain/kbestget.h
+++ b/dtrain/kbestget.h
@@ -7,28 +7,27 @@ namespace dtrain
{
-struct Samples
+struct ScoredHyp
{
- vector > feats;
- vector > sents;
- vector model_scores;
- vector scores;
- size_t GetSize() { return sents.size(); }
+ vector w;
+ SparseVector f;
+ score_t model;
+ score_t score;
};
-struct HypoSampler : public DecoderObserver
+struct HypSampler : public DecoderObserver
{
- virtual Samples* GetSamples() {}
+ virtual vector* GetSamples() {}
};
-struct KBestGetter : public HypoSampler
+struct KBestGetter : public HypSampler
{
const size_t k_;
- const string filter_type;
- Samples s;
+ const string filter_type_;
+ vector s_;
KBestGetter(const size_t k, const string filter_type) :
- k_(k), filter_type(filter_type) {}
+ k_(k), filter_type_(filter_type) {}
virtual void
NotifyTranslationForest(const SentenceMetadata& smeta, Hypergraph* hg)
@@ -36,14 +35,14 @@ struct KBestGetter : public HypoSampler
KBest(*hg);
}
- Samples* GetSamples() { return &s; }
+ vector* GetSamples() { return &s_; }
void
KBest(const Hypergraph& forest)
{
- if (filter_type == "unique") {
+ if (filter_type_ == "unique") {
KBestUnique(forest);
- } else if (filter_type == "no") {
+ } else if (filter_type_ == "no") {
KBestNoFilter(forest);
}
}
@@ -51,36 +50,34 @@ struct KBestGetter : public HypoSampler
void
KBestUnique(const Hypergraph& forest)
{
- s.sents.clear();
- s.feats.clear();
- s.model_scores.clear();
- s.scores.clear();
+ s_.clear();
KBest::KBestDerivations, ESentenceTraversal, KBest::FilterUnique, prob_t, EdgeProb> kbest(forest, k_);
for (size_t i = 0; i < k_; ++i) {
const KBest::KBestDerivations, ESentenceTraversal, KBest::FilterUnique, prob_t, EdgeProb>::Derivation* d =
kbest.LazyKthBest(forest.nodes_.size() - 1, i);
if (!d) break;
- s.sents.push_back(d->yield);
- s.feats.push_back(d->feature_values);
- s.model_scores.push_back(log(d->score));
+ ScoredHyp h;
+ h.w = d->yield;
+ h.f = d->feature_values;
+ h.model = log(d->score);
+ s_.push_back(h);
}
}
void
KBestNoFilter(const Hypergraph& forest)
{
- s.sents.clear();
- s.feats.clear();
- s.model_scores.clear();
- s.scores.clear();
+ s_.clear();
KBest::KBestDerivations, ESentenceTraversal> kbest(forest, k_);
for (size_t i = 0; i < k_; ++i) {
const KBest::KBestDerivations, ESentenceTraversal>::Derivation* d =
kbest.LazyKthBest(forest.nodes_.size() - 1, i);
if (!d) break;
- s.sents.push_back(d->yield);
- s.feats.push_back(d->feature_values);
- s.model_scores.push_back(log(d->score));
+ ScoredHyp h;
+ h.w = d->yield;
+ h.f = d->feature_values;
+ h.model = log(d->score);
+ s_.push_back(h);
}
}
};
--
cgit v1.2.3