port beam threshold from Moses

This commit is contained in:
Hieu Hoang 2016-12-01 12:55:20 +00:00
parent 288af6e425
commit 0f12557e19
3 changed files with 24 additions and 2 deletions

View File

@ -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
@ -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;

View File

@ -60,6 +60,9 @@ protected:
_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;

View File

@ -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",