port Options framework

This commit is contained in:
Hieu Hoang 2016-04-07 17:51:43 +04:00
parent 75bdad21ba
commit 6bc6403b9d
11 changed files with 17 additions and 33 deletions

View File

@ -72,7 +72,7 @@ Hypotheses &HypothesisColl::GetSortedAndPruneHypos(const ManagerBase &mgr,
void HypothesisColl::SortAndPruneHypos(const ManagerBase &mgr,
ArcLists &arcLists) const
{
size_t stackSize = mgr.system.stackSize;
size_t stackSize = mgr.system.options.search.stack_size;
Recycler<HypothesisBase*> &recycler = mgr.GetHypoRecycle();
/*

View File

@ -77,7 +77,7 @@ void QueueItem::CreateHypothesis(Manager &mgr)
hypo->Init(mgr, *prevHypo, edge->path, tp, edge->newBitmap,
edge->estimatedScore);
if (!mgr.system.cubePruningLazyScoring) {
if (!mgr.system.options.cube.lazy_scoring) {
hypo->EvaluateWhenApplied();
}
}

View File

@ -118,7 +118,7 @@ void Search::Decode(size_t stackInd)
*/
size_t pops = 0;
while (!m_queue.empty() && pops < mgr.system.popLimit) {
while (!m_queue.empty() && pops < mgr.system.options.cube.pop_limit) {
// get best hypo from queue, add to stack
//cerr << "queue=" << queue.size() << endl;
QueueItem *item = m_queue.top();
@ -129,7 +129,7 @@ void Search::Decode(size_t stackInd)
// add hypo to stack
Hypothesis *hypo = item->hypo;
if (mgr.system.cubePruningLazyScoring) {
if (mgr.system.options.cube.lazy_scoring) {
hypo->EvaluateWhenApplied();
}
@ -142,7 +142,7 @@ void Search::Decode(size_t stackInd)
}
// create hypo from every edge. Increase diversity
if (mgr.system.cubePruningDiversity) {
if (mgr.system.options.cube.diversity) {
while (!m_queue.empty()) {
QueueItem *item = m_queue.top();
m_queue.pop();

View File

@ -21,7 +21,7 @@ void InputPaths::Init(const Sentence &input, const ManagerBase &mgr)
MemPool &pool = mgr.GetPool();
size_t numPt = mgr.system.mappings.size();
size_t size = input.GetSize();
size_t maxLength = min(size, mgr.system.maxPhraseLength);
size_t maxLength = min(size, mgr.system.options.search.max_phrase_length);
m_matrix = new (pool.Allocate<Matrix<InputPath*> >()) Matrix<InputPath*>(pool,
size, maxLength);

View File

@ -70,7 +70,7 @@ void Manager::Init()
m_bitmaps->Init(m_input->GetSize(), vector<bool>(0));
switch (system.searchAlgorithm) {
switch (system.options.search.algo) {
case Normal:
m_search = new SearchNormal(*this);
break;

View File

@ -39,11 +39,11 @@ bool Search::CanExtend(const Bitmap &hypoBitmap, size_t hypoRangeEndPos,
return false;
}
if (mgr.system.maxDistortion >= 0) {
if (mgr.system.options.reordering.max_distortion >= 0) {
// distortion limit
int distortion = ComputeDistortionDistance(hypoRangeEndPos,
pathRange.GetStartPos());
if (distortion > mgr.system.maxDistortion) {
if (distortion > mgr.system.options.reordering.max_distortion) {
//cerr << " NO" << endl;
return false;
}
@ -97,7 +97,7 @@ bool Search::CanExtend(const Bitmap &hypoBitmap, size_t hypoRangeEndPos,
Range bestNextExtension(hypoFirstGapPos, hypoFirstGapPos);
if (ComputeDistortionDistance(pathRange.GetEndPos(),
bestNextExtension.GetStartPos()) > mgr.system.maxDistortion) {
bestNextExtension.GetStartPos()) > mgr.system.options.reordering.max_distortion) {
//cerr << " NO" << endl;
return false;
}

View File

@ -23,7 +23,7 @@ void InputPaths::Init(const Sentence &input, const ManagerBase &mgr)
MemPool &pool = mgr.GetPool();
size_t numPt = mgr.system.mappings.size();
size_t size = input.GetSize();
size_t maxLength = min(size, mgr.system.maxPhraseLength);
size_t maxLength = min(size, mgr.system.options.search.max_phrase_length);
m_matrix = new (pool.Allocate<Matrix<InputPath*> >()) Matrix<InputPath*>(pool,
size, maxLength);

View File

@ -23,21 +23,11 @@ namespace Moses2
System::System(const Parameter &paramsArg) :
params(paramsArg), featureFunctions(*this)
{
options.init(paramsArg);
bestCollector.reset(new OutputCollector());
ini_performance_options();
params.SetParameter(stackSize, "stack", DEFAULT_MAX_HYPOSTACK_SIZE);
params.SetParameter(maxDistortion, "distortion-limit", -1);
params.SetParameter(maxPhraseLength, "max-phrase-length",
DEFAULT_MAX_PHRASE_LENGTH);
params.SetParameter(searchAlgorithm, "search-algorithm", Normal);
params.SetParameter(popLimit, "cube-pruning-pop-limit",
DEFAULT_CUBE_PRUNING_POP_LIMIT);
params.SetParameter(cubePruningDiversity, "cube-pruning-diversity",
(size_t) 0);
params.SetParameter(cubePruningLazyScoring, "cube-pruning-lazy-scoring",
false);
params.SetParameter(cpuAffinityOffset, "cpu-affinity-offset", 0);
params.SetParameter(cpuAffinityOffsetIncr, "cpu-affinity-increment", 1);

View File

@ -20,6 +20,7 @@
#include "TypeDef.h"
#include "legacy/Bitmaps.h"
#include "legacy/OutputCollector.h"
#include "parameters/AllOptions.h"
namespace Moses2
{
@ -37,6 +38,7 @@ class System
{
public:
const Parameter &params;
AllOptions options;
FeatureFunctions featureFunctions;
Weights weights;
std::vector<const PhraseTable*> mappings;
@ -44,16 +46,8 @@ public:
mutable boost::shared_ptr<OutputCollector> bestCollector, nbestCollector;
// moses.ini params
size_t stackSize;
int maxDistortion;
size_t maxPhraseLength;
int numThreads;
SearchAlgorithm searchAlgorithm;
size_t popLimit;
size_t cubePruningDiversity;
bool cubePruningLazyScoring;
size_t nbestSize;
bool distinctNBest;

View File

@ -140,7 +140,7 @@ void PhraseTableMemory::Load(System &system)
Phrase *source;
TargetPhrase *target;
switch (system.searchAlgorithm) {
switch (system.options.search.algo) {
case Normal:
case CubePruning:
case CubePruningPerMiniStack:

View File

@ -11,7 +11,7 @@ namespace Moses2
TranslationTask::TranslationTask(System &system, const std::string &line,
long translationId)
{
if (system.searchAlgorithm == CYKPlus) {
if (system.options.search.algo == CYKPlus) {
m_mgr = new SCFG::Manager(system, *this, line, translationId);
}
else {