Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Germann <ugermann@inf.ed.ac.uk>2015-03-21 19:12:52 +0300
committerUlrich Germann <ugermann@inf.ed.ac.uk>2015-03-21 19:12:52 +0300
commit8ca11d941d99df42664b32c101020283cc83054e (patch)
treeeac36b128d9bfe22ff598458635ae66cdecbf57b /moses-cmd
parent85d2567b57af592a3a902209c7b0f3675576aac7 (diff)
1. Lifetime of tasks in ThreadPool is now managed via shared pointers.
2. Code cleanup in IOWrapper and a bit elsewhere.
Diffstat (limited to 'moses-cmd')
-rw-r--r--moses-cmd/LatticeMBRGrid.cpp77
-rw-r--r--moses-cmd/MainVW.cpp35
2 files changed, 52 insertions, 60 deletions
diff --git a/moses-cmd/LatticeMBRGrid.cpp b/moses-cmd/LatticeMBRGrid.cpp
index 631c717f4..edb4176c7 100644
--- a/moses-cmd/LatticeMBRGrid.cpp
+++ b/moses-cmd/LatticeMBRGrid.cpp
@@ -52,6 +52,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "moses/StaticData.h"
#include "util/exception.hh"
+#include <boost/foreach.hpp>
using namespace std;
using namespace Moses;
@@ -156,59 +157,55 @@ int main(int argc, char* argv[])
exit(1);
}
- StaticData& staticData = const_cast<StaticData&>(StaticData::Instance());
- staticData.SetUseLatticeMBR(true);
+ StaticData& SD = const_cast<StaticData&>(StaticData::Instance());
+ SD.SetUseLatticeMBR(true);
- IOWrapper* ioWrapper = new IOWrapper();
+ boost::shared_ptr<IOWrapper> ioWrapper(new IOWrapper);
if (!ioWrapper) {
throw runtime_error("Failed to initialise IOWrapper");
}
- size_t nBestSize = staticData.GetMBRSize();
+ size_t nBestSize = SD.GetMBRSize();
if (nBestSize <= 0) {
throw new runtime_error("Non-positive size specified for n-best list");
}
- size_t lineCount = 0;
- InputType* source = NULL;
-
const vector<float>& pgrid = grid.getGrid(lmbr_p);
const vector<float>& rgrid = grid.getGrid(lmbr_r);
const vector<float>& prune_grid = grid.getGrid(lmbr_prune);
const vector<float>& scale_grid = grid.getGrid(lmbr_scale);
- while(ioWrapper->ReadInput(staticData.GetInputType(),source)) {
- ++lineCount;
- source->SetTranslationId(lineCount);
-
- Manager manager(*source);
- manager.Decode();
- TrellisPathList nBestList;
- manager.CalcNBest(nBestSize, nBestList,true);
- //grid search
- for (vector<float>::const_iterator pi = pgrid.begin(); pi != pgrid.end(); ++pi) {
- float p = *pi;
- staticData.SetLatticeMBRPrecision(p);
- for (vector<float>::const_iterator ri = rgrid.begin(); ri != rgrid.end(); ++ri) {
- float r = *ri;
- staticData.SetLatticeMBRPRatio(r);
- for (vector<float>::const_iterator prune_i = prune_grid.begin(); prune_i != prune_grid.end(); ++prune_i) {
- size_t prune = (size_t)(*prune_i);
- staticData.SetLatticeMBRPruningFactor(prune);
- for (vector<float>::const_iterator scale_i = scale_grid.begin(); scale_i != scale_grid.end(); ++scale_i) {
- float scale = *scale_i;
- staticData.SetMBRScale(scale);
- cout << lineCount << " ||| " << p << " " << r << " " << prune << " " << scale << " ||| ";
- vector<Word> mbrBestHypo = doLatticeMBR(manager,nBestList);
- manager.OutputBestHypo(mbrBestHypo, lineCount, staticData.GetReportSegmentation(),
- staticData.GetReportAllFactors(),cout);
- }
- }
-
- }
+ for (boost::shared_ptr<InputType> source = ioWrapper->ReadInput();
+ source != NULL; source = ioWrapper->ReadInput())
+ {
+ Manager manager(*source);
+ manager.Decode();
+ TrellisPathList nBestList;
+ manager.CalcNBest(nBestSize, nBestList,true);
+ //grid search
+ BOOST_FOREACH(float const& p, pgrid)
+ {
+ SD.SetLatticeMBRPrecision(p);
+ BOOST_FOREACH(float const& r, rgrid)
+ {
+ SD.SetLatticeMBRPRatio(r);
+ BOOST_FOREACH(size_t const prune_i, prune_grid)
+ {
+ SD.SetLatticeMBRPruningFactor(size_t(prune_i));
+ BOOST_FOREACH(float const& scale_i, scale_grid)
+ {
+ SD.SetMBRScale(scale_i);
+ size_t lineCount = source->GetTranslationId();
+ cout << lineCount << " ||| " << p << " "
+ << r << " " << size_t(prune_i) << " " << scale_i
+ << " ||| ";
+ vector<Word> mbrBestHypo = doLatticeMBR(manager,nBestList);
+ manager.OutputBestHypo(mbrBestHypo, lineCount,
+ SD.GetReportSegmentation(),
+ SD.GetReportAllFactors(),cout);
+ }
+ }
+ }
+ }
}
-
-
- }
-
}
diff --git a/moses-cmd/MainVW.cpp b/moses-cmd/MainVW.cpp
index a93ba8b18..00df3df80 100644
--- a/moses-cmd/MainVW.cpp
+++ b/moses-cmd/MainVW.cpp
@@ -124,7 +124,7 @@ int main(int argc, char** argv)
PrintUserTime("Created input-output object");
}
- IOWrapper* ioWrapper = new IOWrapper();
+ boost::shared_ptr<IOWrapper> ioWrapper(new IOWrapper());
if (ioWrapper == NULL) {
cerr << "Error; Failed to create IO object" << endl;
exit(1);
@@ -143,37 +143,32 @@ int main(int argc, char** argv)
#endif
// main loop over set of input sentences
- InputType* source = NULL;
- size_t lineCount = staticData.GetStartTranslationId();
- while(ioWrapper->ReadInput(staticData.GetInputType(),source)) {
- source->SetTranslationId(lineCount);
- IFVERBOSE(1) {
- ResetUserTime();
- }
+
+ boost::shared_ptr<InputType> source;
+ while ((source = ioWrapper->ReadInput()) != NULL)
+ {
+ IFVERBOSE(1) { ResetUserTime(); }
- FeatureFunction::CallChangeSource(source);
+ InputType* foo = source.get();
+ FeatureFunction::CallChangeSource(foo);
- // set up task of training one sentence
- TrainingTask* task = new TrainingTask(source, *ioWrapper);
+ // set up task of training one sentence
+ boost::shared_ptr<TrainingTask>
+ task(new TrainingTask(source.get(), *ioWrapper));
- // execute task
+ // execute task
#ifdef WITH_THREADS
- pool.Submit(task);
+ pool.Submit(task);
#else
- task->Run();
- delete task;
+ task->Run();
#endif
-
- source = NULL; //make sure it doesn't get deleted
- ++lineCount;
- }
+ }
// we are done, finishing up
#ifdef WITH_THREADS
pool.Stop(true); //flush remaining jobs
#endif
- delete ioWrapper;
FeatureFunction::Destroy();
} catch (const std::exception &e) {