Download tools/mosesdecoder/moses-cmd/MainVW.cpp from Quagmire1/wiki-cased: direct link, hf CLI and curl.
- Browser
- Download file 5.12 kB
-
https://huggingface.co/Quagmire1/wiki-cased/resolve/main/tools/mosesdecoder/moses-cmd/MainVW.cpp
- Command line
-
hf download hf://Quagmire1/wiki-cased/tools/mosesdecoder/moses-cmd/MainVW.cpp
-
curl -L -o MainVW.cpp https://huggingface.co/Quagmire1/wiki-cased/resolve/main/tools/mosesdecoder/moses-cmd/MainVW.cpp
5.12 kB
| // $Id: MainMT.cpp 3045 2010-04-05 13:07:29Z hieuhoang1972 $ | |
| /*********************************************************************** | |
| Moses - factored phrase-based language decoder | |
| Copyright (C) 2009 University of Edinburgh | |
| This library is free software; you can redistribute it and/or | |
| modify it under the terms of the GNU Lesser General Public | |
| License as published by the Free Software Foundation; either | |
| version 2.1 of the License, or (at your option) any later version. | |
| This library is distributed in the hope that it will be useful, | |
| but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| Lesser General Public License for more details. | |
| You should have received a copy of the GNU Lesser General Public | |
| License along with this library; if not, write to the Free Software | |
| Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| ***********************************************************************/ | |
| /** | |
| * Moses main, for single-threaded and multi-threaded. | |
| **/ | |
| // Include Visual Leak Detector | |
| //#include <vld.h> | |
| 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); | |
| } | |
| } //namespace | |
| /** main function of the command line version of the decoder **/ | |
| int main(int argc, char const** argv) | |
| { | |
| //setting in the Staticdata a link between the thread id of this process and a NULL tasksptr | |
| // StaticData::InstanceNonConst().SetTask(); // => moved into StaticData constructor | |
| try { | |
| GOOGLE_PROTOBUF_VERIFY_VERSION; | |
| // echo command line, if verbose | |
| IFVERBOSE(1) { | |
| TRACE_ERR("command: "); | |
| for(int i=0; i<argc; ++i) TRACE_ERR(argv[i]<<" "); | |
| TRACE_ERR(endl); | |
| } | |
| // set number of significant decimals in output | |
| FixPrecision(cout); | |
| FixPrecision(cerr); | |
| // load all the settings into the Parameter class | |
| // (stores them as strings, or array of strings) | |
| Parameter params; | |
| if (!params.LoadParam(argc,argv)) { | |
| exit(1); | |
| } | |
| // initialize all "global" variables, which are stored in StaticData | |
| // note: this also loads models such as the language model, etc. | |
| ResetUserTime(); | |
| if (!StaticData::LoadDataStatic(¶ms, argv[0])) { | |
| exit(1); | |
| } | |
| // setting "-show-weights" -> just dump out weights and exit | |
| if (params.isParamSpecified("show-weights")) { | |
| ShowWeights(); | |
| exit(0); | |
| } | |
| // shorthand for accessing information in StaticData | |
| const StaticData& staticData = StaticData::Instance(); | |
| //initialise random numbers | |
| util::rand_init(); | |
| // set up read/writing class | |
| 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); | |
| } | |
| // check on weights | |
| const ScoreComponentCollection& weights = staticData.GetAllWeights(); | |
| IFVERBOSE(2) { | |
| TRACE_ERR("The global weight vector looks like this: "); | |
| TRACE_ERR(weights); | |
| TRACE_ERR("\n"); | |
| } | |
| ThreadPool pool(staticData.ThreadCount()); | |
| // main loop over set of input sentences | |
| boost::shared_ptr<ContextScope> scope(new ContextScope); | |
| boost::shared_ptr<InputType> source; | |
| while ((source = ioWrapper->ReadInput()) != NULL) { | |
| IFVERBOSE(1) { | |
| ResetUserTime(); | |
| } | |
| // set up task of training one sentence | |
| boost::shared_ptr<TrainingTask> task; | |
| task = TrainingTask::create(source, ioWrapper, scope); | |
| // execute task | |
| pool.Submit(task); | |
| task->Run(); | |
| } | |
| // we are done, finishing up | |
| pool.Stop(true); //flush remaining jobs | |
| FeatureFunction::Destroy(); | |
| } catch (const std::exception &e) { | |
| std::cerr << "Exception: " << e.what() << std::endl; | |
| return EXIT_FAILURE; | |
| } | |
| IFVERBOSE(1) util::PrintUsage(std::cerr); | |
| //This avoids that destructors are called (it can take a long time) | |
| exit(EXIT_SUCCESS); | |
| return EXIT_SUCCESS; | |
| } | |