Skip to content

Commit

Permalink
port beam threshold from Moses
Browse files Browse the repository at this point in the history
  • Loading branch information
hieuhoang committed Dec 1, 2016
1 parent 288af6e commit 0f12557
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
19 changes: 19 additions & 0 deletions contrib/moses2/HypothesisColl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ HypothesisColl::HypothesisColl(const ManagerBase &mgr) :
m_coll(MemPoolAllocator<const HypothesisBase*>(mgr.GetPool())), m_sortedHypos(
NULL)
{
m_bestScore = -std::numeric_limits<float>::infinity();
m_worstScore = -std::numeric_limits<float>::infinity();
}

const HypothesisBase *HypothesisColl::GetBestHypo() const
Expand Down Expand Up @@ -50,6 +52,23 @@ void HypothesisColl::Add(
Recycler<HypothesisBase*> &hypoRecycle,
ArcLists &arcLists)
{
SCORE futureScore = hypo->GetFutureScore();
if (futureScore < m_worstScore) {
// beam threshold
hypoRecycle.Recycle(hypo);
return;
}

if (futureScore > m_bestScore) {
m_bestScore = hypo->GetFutureScore();

// this may also affect the worst score
SCORE beamWidth = system.options.search.beam_width;
if ( m_bestScore + beamWidth > m_worstScore ) {
m_worstScore = m_bestScore + beamWidth;
}
}

StackAdd added = Add(hypo);

size_t nbestSize = system.options.nbest.nbest_size;
Expand Down
3 changes: 3 additions & 0 deletions contrib/moses2/HypothesisColl.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class HypothesisColl
_HCType m_coll;
mutable Hypotheses *m_sortedHypos;

SCORE m_bestScore;
SCORE m_worstScore;

StackAdd Add(const HypothesisBase *hypo);
void SortAndPruneHypos(const ManagerBase &mgr, ArcLists &arcLists) const;

Expand Down
4 changes: 2 additions & 2 deletions contrib/moses2/legacy/Parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ Parameter::Parameter()
desc += "8=tree-to-string (SCFG-based)\n";
desc += "9=forest-to-string";
AddParam(search_opts, "search-algorithm", desc);
//AddParam(search_opts, "beam-threshold", "b",
// "threshold for threshold pruning");
AddParam(search_opts, "beam-threshold", "b",
"threshold for threshold pruning");
//AddParam(search_opts, "early-discarding-threshold", "edt",
// "threshold for constructing hypotheses based on estimate cost");
AddParam(search_opts, "stack", "s",
Expand Down

0 comments on commit 0f12557

Please sign in to comment.