mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
add inter-stack pruning
This commit is contained in:
parent
f7cf9a84ed
commit
fc4fa0f19c
@ -48,13 +48,17 @@ const HypothesisBase *HypothesisColl::GetBestHypo() const
|
||||
}
|
||||
|
||||
void HypothesisColl::Add(
|
||||
const System &system,
|
||||
const ManagerBase &mgr,
|
||||
HypothesisBase *hypo,
|
||||
Recycler<HypothesisBase*> &hypoRecycle,
|
||||
ArcLists &arcLists)
|
||||
{
|
||||
size_t maxStackSize = system.options.search.stack_size;
|
||||
//cerr << "stackSize=" << stackSize << endl;
|
||||
size_t maxStackSize = mgr.system.options.search.stack_size;
|
||||
//cerr << "maxStackSize=" << maxStackSize << endl;
|
||||
|
||||
if (GetSize() * 2 > maxStackSize) {
|
||||
PruneHypos(mgr, mgr.arcLists);
|
||||
}
|
||||
|
||||
SCORE futureScore = hypo->GetFutureScore();
|
||||
/*
|
||||
@ -96,7 +100,7 @@ void HypothesisColl::Add(
|
||||
|
||||
StackAdd added = Add(hypo);
|
||||
|
||||
size_t nbestSize = system.options.nbest.nbest_size;
|
||||
size_t nbestSize = mgr.system.options.nbest.nbest_size;
|
||||
if (nbestSize) {
|
||||
arcLists.AddArc(added.added, hypo, added.other);
|
||||
}
|
||||
@ -219,6 +223,60 @@ void HypothesisColl::SortAndPruneHypos(const ManagerBase &mgr,
|
||||
*/
|
||||
}
|
||||
|
||||
void HypothesisColl::PruneHypos(const ManagerBase &mgr, ArcLists &arcLists) const
|
||||
{
|
||||
size_t stackSize = mgr.system.options.search.stack_size;
|
||||
Recycler<HypothesisBase*> &recycler = mgr.GetHypoRecycle();
|
||||
|
||||
/*
|
||||
cerr << "UNSORTED hypos: ";
|
||||
BOOST_FOREACH(const HypothesisBase *hypo, m_coll) {
|
||||
cerr << hypo << "(" << hypo->GetFutureScore() << ")" << " ";
|
||||
}
|
||||
cerr << endl;
|
||||
*/
|
||||
vector<const HypothesisBase*> sortedHypos;
|
||||
size_t ind = 0;
|
||||
BOOST_FOREACH(const HypothesisBase *hypo, m_coll){
|
||||
sortedHypos[ind] = hypo;
|
||||
++ind;
|
||||
}
|
||||
|
||||
vector<const HypothesisBase*>::iterator iterMiddle;
|
||||
iterMiddle =
|
||||
(stackSize == 0 || sortedHypos.size() < stackSize) ?
|
||||
sortedHypos.end() : sortedHypos.begin() + stackSize;
|
||||
|
||||
std::partial_sort(sortedHypos.begin(), iterMiddle, sortedHypos.end(),
|
||||
HypothesisFutureScoreOrderer());
|
||||
|
||||
// prune
|
||||
if (stackSize && sortedHypos.size() > stackSize) {
|
||||
for (size_t i = stackSize; i < sortedHypos.size(); ++i) {
|
||||
HypothesisBase *hypo = const_cast<HypothesisBase*>((sortedHypos)[i]);
|
||||
recycler.Recycle(hypo);
|
||||
|
||||
// delete from arclist
|
||||
if (mgr.system.options.nbest.nbest_size) {
|
||||
arcLists.Delete(hypo);
|
||||
}
|
||||
|
||||
// delete from collection
|
||||
//Delete(hypo);
|
||||
}
|
||||
sortedHypos.resize(stackSize);
|
||||
}
|
||||
|
||||
/*
|
||||
cerr << "sorted hypos: ";
|
||||
for (size_t i = 0; i < sortedHypos.size(); ++i) {
|
||||
const HypothesisBase *hypo = sortedHypos[i];
|
||||
cerr << hypo << " ";
|
||||
}
|
||||
cerr << endl;
|
||||
*/
|
||||
}
|
||||
|
||||
void HypothesisColl::Clear()
|
||||
{
|
||||
m_sortedHypos = NULL;
|
||||
|
@ -25,7 +25,7 @@ class HypothesisColl
|
||||
public:
|
||||
HypothesisColl(const ManagerBase &mgr);
|
||||
|
||||
void Add(const System &system,
|
||||
void Add(const ManagerBase &mgr,
|
||||
HypothesisBase *hypo,
|
||||
Recycler<HypothesisBase*> &hypoRecycle,
|
||||
ArcLists &arcLists);
|
||||
@ -67,6 +67,8 @@ protected:
|
||||
StackAdd Add(const HypothesisBase *hypo);
|
||||
void SortAndPruneHypos(const ManagerBase &mgr, ArcLists &arcLists) const;
|
||||
|
||||
void PruneHypos(const ManagerBase &mgr, ArcLists &arcLists) const;
|
||||
|
||||
};
|
||||
|
||||
} /* namespace Moses2 */
|
||||
|
@ -47,7 +47,7 @@ void Stack::Add(Hypothesis *hypo, Recycler<HypothesisBase*> &hypoRecycle,
|
||||
{
|
||||
HypoCoverage key(&hypo->GetBitmap(), hypo->GetInputPath().range.GetEndPos());
|
||||
Moses2::HypothesisColl &coll = GetMiniStack(key);
|
||||
coll.Add(m_mgr.system, hypo, hypoRecycle, arcLists);
|
||||
coll.Add(m_mgr, hypo, hypoRecycle, arcLists);
|
||||
}
|
||||
|
||||
const Hypothesis *Stack::GetBestHypo() const
|
||||
|
@ -60,7 +60,7 @@ void Stacks::Add(Hypothesis *hypo, Recycler<HypothesisBase*> &hypoRecycle,
|
||||
size_t numWordsCovered = hypo->GetBitmap().GetNumWordsCovered();
|
||||
//cerr << "numWordsCovered=" << numWordsCovered << endl;
|
||||
Stack &stack = *m_stacks[numWordsCovered];
|
||||
stack.Add(m_mgr.system, hypo, hypoRecycle, arcLists);
|
||||
stack.Add(m_mgr, hypo, hypoRecycle, arcLists);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ void Stack::Add(SCFG::Hypothesis *hypo, Recycler<HypothesisBase*> &hypoRecycle,
|
||||
//cerr << "lhs=" << lhs << endl;
|
||||
|
||||
HypothesisColl &coll = GetColl(lhs);
|
||||
coll.Add(m_mgr.system, hypo, hypoRecycle, arcLists);
|
||||
coll.Add(m_mgr, hypo, hypoRecycle, arcLists);
|
||||
}
|
||||
|
||||
size_t Stack::GetSize() const
|
||||
|
Loading…
Reference in New Issue
Block a user