00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00025 #include <exception>
00026 #include <fstream>
00027 #include <sstream>
00028 #include <vector>
00029
00030 #include "util/usage.hh"
00031
00032 #ifdef WIN32
00033
00034
00035 #endif
00036
00037 #include "moses/IOWrapper.h"
00038 #include "moses/Hypothesis.h"
00039 #include "moses/Manager.h"
00040 #include "moses/StaticData.h"
00041 #include "moses/TypeDef.h"
00042 #include "moses/Util.h"
00043 #include "moses/Timer.h"
00044 #include "moses/TranslationModel/PhraseDictionary.h"
00045 #include "moses/FF/StatefulFeatureFunction.h"
00046 #include "moses/FF/StatelessFeatureFunction.h"
00047 #include "moses/TrainingTask.h"
00048 #include "util/random.hh"
00049
00050 #ifdef HAVE_PROTOBUF
00051 #include "hypergraph.pb.h"
00052 #endif
00053
00054 using namespace std;
00055 using namespace Moses;
00056
00057 namespace Moses
00058 {
00059
00060 void OutputFeatureWeightsForHypergraph(std::ostream &outputSearchGraphStream)
00061 {
00062 outputSearchGraphStream.setf(std::ios::fixed);
00063 outputSearchGraphStream.precision(6);
00064 StaticData::Instance().GetAllWeights().Save(outputSearchGraphStream);
00065 }
00066
00067
00068 }
00069
00071 int main(int argc, char const** argv)
00072 {
00073
00074
00075
00076 try {
00077
00078 #ifdef HAVE_PROTOBUF
00079 GOOGLE_PROTOBUF_VERIFY_VERSION;
00080 #endif
00081
00082
00083 IFVERBOSE(1) {
00084 TRACE_ERR("command: ");
00085 for(int i=0; i<argc; ++i) TRACE_ERR(argv[i]<<" ");
00086 TRACE_ERR(endl);
00087 }
00088
00089
00090 FixPrecision(cout);
00091 FixPrecision(cerr);
00092
00093
00094
00095 Parameter params;
00096 if (!params.LoadParam(argc,argv)) {
00097 exit(1);
00098 }
00099
00100
00101
00102
00103 ResetUserTime();
00104 if (!StaticData::LoadDataStatic(¶ms, argv[0])) {
00105 exit(1);
00106 }
00107
00108
00109 if (params.isParamSpecified("show-weights")) {
00110 ShowWeights();
00111 exit(0);
00112 }
00113
00114
00115 const StaticData& staticData = StaticData::Instance();
00116
00117
00118
00119 util::rand_init();
00120
00121
00122 IFVERBOSE(1) {
00123 PrintUserTime("Created input-output object");
00124 }
00125 AllOptions::ptr opts(new AllOptions(*StaticData::Instance().options()));
00126 boost::shared_ptr<IOWrapper> ioWrapper(new IOWrapper(*opts));
00127 if (ioWrapper == NULL) {
00128 cerr << "Error; Failed to create IO object" << endl;
00129 exit(1);
00130 }
00131
00132
00133 const ScoreComponentCollection& weights = staticData.GetAllWeights();
00134 IFVERBOSE(2) {
00135 TRACE_ERR("The global weight vector looks like this: ");
00136 TRACE_ERR(weights);
00137 TRACE_ERR("\n");
00138 }
00139
00140 #ifdef WITH_THREADS
00141 #pragma message ("Compiling with Threads.")
00142 ThreadPool pool(staticData.ThreadCount());
00143 #endif
00144
00145
00146
00147 boost::shared_ptr<ContextScope> scope(new ContextScope);
00148 boost::shared_ptr<InputType> source;
00149 while ((source = ioWrapper->ReadInput()) != NULL) {
00150 IFVERBOSE(1) {
00151 ResetUserTime();
00152 }
00153
00154
00155 boost::shared_ptr<TrainingTask> task;
00156 task = TrainingTask::create(source, ioWrapper, scope);
00157
00158
00159 #ifdef WITH_THREADS
00160 pool.Submit(task);
00161 #else
00162 task->Run();
00163 #endif
00164 }
00165
00166
00167 #ifdef WITH_THREADS
00168 pool.Stop(true);
00169 #endif
00170
00171 FeatureFunction::Destroy();
00172
00173 } catch (const std::exception &e) {
00174 std::cerr << "Exception: " << e.what() << std::endl;
00175 return EXIT_FAILURE;
00176 }
00177
00178 IFVERBOSE(1) util::PrintUsage(std::cerr);
00179
00180 #ifndef EXIT_RETURN
00181
00182 exit(EXIT_SUCCESS);
00183 #else
00184 return EXIT_SUCCESS;
00185 #endif
00186 }