diff options
author | Chris Dyer <redpony@gmail.com> | 2014-02-09 20:50:41 -0500 |
---|---|---|
committer | Chris Dyer <redpony@gmail.com> | 2014-02-09 20:50:41 -0500 |
commit | 9b83a2e82aba73b5ff0e848182a8726481a10485 (patch) | |
tree | 81e7ade548bdffaa8534705c2d34beb8c752dc24 /training/utils/candidate_set.cc | |
parent | 702591b3296af472cc5c7c4720f1c21b2a6e34b1 (diff) |
adaptive hope-fear learner
Diffstat (limited to 'training/utils/candidate_set.cc')
-rw-r--r-- | training/utils/candidate_set.cc | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/training/utils/candidate_set.cc b/training/utils/candidate_set.cc index 33dae9a3..36f5b271 100644 --- a/training/utils/candidate_set.cc +++ b/training/utils/candidate_set.cc @@ -171,4 +171,19 @@ void CandidateSet::AddKBestCandidates(const Hypergraph& hg, size_t kbest_size, c Dedup(); } +void CandidateSet::AddUniqueKBestCandidates(const Hypergraph& hg, size_t kbest_size, const SegmentEvaluator* scorer) { + typedef KBest::KBestDerivations<vector<WordID>, ESentenceTraversal, KBest::FilterUnique> K; + K kbest(hg, kbest_size); + + for (unsigned i = 0; i < kbest_size; ++i) { + const K::Derivation* d = + kbest.LazyKthBest(hg.nodes_.size() - 1, i); + if (!d) break; + cs.push_back(Candidate(d->yield, d->feature_values)); + if (scorer) + scorer->Evaluate(d->yield, &cs.back().eval_feats); + } + Dedup(); +} + } |