| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| #include <exception> |
| #include <fstream> |
| #include <sstream> |
| #include <vector> |
|
|
| #include "util/usage.hh" |
|
|
| #ifdef WIN32 |
| |
| |
| #endif |
|
|
| #include "moses/IOWrapper.h" |
| #include "moses/Hypothesis.h" |
| #include "moses/Manager.h" |
| #include "moses/StaticData.h" |
| #include "moses/TypeDef.h" |
| #include "moses/Util.h" |
| #include "moses/Timer.h" |
| #include "moses/TranslationModel/PhraseDictionary.h" |
| #include "moses/FF/StatefulFeatureFunction.h" |
| #include "moses/FF/StatelessFeatureFunction.h" |
| #include "moses/TrainingTask.h" |
| #include "util/random.hh" |
|
|
| #ifdef HAVE_PROTOBUF |
| #include "hypergraph.pb.h" |
| #endif |
|
|
| using namespace std; |
| using namespace Moses; |
|
|
| namespace Moses |
| { |
|
|
| void OutputFeatureWeightsForHypergraph(std::ostream &outputSearchGraphStream) |
| { |
| outputSearchGraphStream.setf(std::ios::fixed); |
| outputSearchGraphStream.precision(6); |
| StaticData::Instance().GetAllWeights().Save(outputSearchGraphStream); |
| } |
|
|
|
|
| } |
|
|
| |
| int main(int argc, char const** argv) |
| { |
| |
| |
|
|
| try { |
|
|
| #ifdef HAVE_PROTOBUF |
| GOOGLE_PROTOBUF_VERIFY_VERSION; |
| #endif |
|
|
| |
| IFVERBOSE(1) { |
| TRACE_ERR("command: "); |
| for(int i=0; i<argc; ++i) TRACE_ERR(argv[i]<<" "); |
| TRACE_ERR(endl); |
| } |
|
|
| |
| FixPrecision(cout); |
| FixPrecision(cerr); |
|
|
| |
| |
| Parameter params; |
| if (!params.LoadParam(argc,argv)) { |
| exit(1); |
| } |
|
|
|
|
| |
| |
| ResetUserTime(); |
| if (!StaticData::LoadDataStatic(¶ms, argv[0])) { |
| exit(1); |
| } |
|
|
| |
| if (params.isParamSpecified("show-weights")) { |
| ShowWeights(); |
| exit(0); |
| } |
|
|
| |
| const StaticData& staticData = StaticData::Instance(); |
|
|
|
|
| |
| util::rand_init(); |
|
|
| |
| IFVERBOSE(1) { |
| PrintUserTime("Created input-output object"); |
| } |
| AllOptions::ptr opts(new AllOptions(*StaticData::Instance().options())); |
| boost::shared_ptr<IOWrapper> ioWrapper(new IOWrapper(*opts)); |
| if (ioWrapper == NULL) { |
| cerr << "Error; Failed to create IO object" << endl; |
| exit(1); |
| } |
|
|
| |
| const ScoreComponentCollection& weights = staticData.GetAllWeights(); |
| IFVERBOSE(2) { |
| TRACE_ERR("The global weight vector looks like this: "); |
| TRACE_ERR(weights); |
| TRACE_ERR("\n"); |
| } |
|
|
| #ifdef WITH_THREADS |
| #pragma message ("Compiling with Threads.") |
| ThreadPool pool(staticData.ThreadCount()); |
| #endif |
|
|
| |
|
|
| boost::shared_ptr<ContextScope> scope(new ContextScope); |
| boost::shared_ptr<InputType> source; |
| while ((source = ioWrapper->ReadInput()) != NULL) { |
| IFVERBOSE(1) { |
| ResetUserTime(); |
| } |
|
|
| |
| boost::shared_ptr<TrainingTask> task; |
| task = TrainingTask::create(source, ioWrapper, scope); |
|
|
| |
| #ifdef WITH_THREADS |
| pool.Submit(task); |
| #else |
| task->Run(); |
| #endif |
| } |
|
|
| |
| #ifdef WITH_THREADS |
| pool.Stop(true); |
| #endif |
|
|
| FeatureFunction::Destroy(); |
|
|
| } catch (const std::exception &e) { |
| std::cerr << "Exception: " << e.what() << std::endl; |
| return EXIT_FAILURE; |
| } |
|
|
| IFVERBOSE(1) util::PrintUsage(std::cerr); |
|
|
| #ifndef EXIT_RETURN |
| |
| exit(EXIT_SUCCESS); |
| #else |
| return EXIT_SUCCESS; |
| #endif |
| } |
|
|