Download tools/mosesdecoder/moses2/Main.cpp from Quagmire1/wiki-cased: direct link, hf CLI and curl.
- Browser
- Download file 3.09 kB
-
https://huggingface.co/Quagmire1/wiki-cased/resolve/main/tools/mosesdecoder/moses2/Main.cpp
- Command line
-
hf download hf://Quagmire1/wiki-cased/tools/mosesdecoder/moses2/Main.cpp
-
curl -L -o Main.cpp https://huggingface.co/Quagmire1/wiki-cased/resolve/main/tools/mosesdecoder/moses2/Main.cpp
3.09 kB
| //#include <vld.h> | |
| using namespace std; | |
| //extern size_t g_numHypos; | |
| int main(int argc, char** argv) | |
| { | |
| cerr << "Starting..." << endl; | |
| Moses2::Timer timer; | |
| timer.start(); | |
| //Temp(); | |
| Moses2::Parameter params; | |
| if (!params.LoadParam(argc, argv)) { | |
| return EXIT_FAILURE; | |
| } | |
| Moses2::System system(params); | |
| timer.check("Loaded"); | |
| if (params.GetParam("show-weights")) { | |
| return EXIT_SUCCESS; | |
| } | |
| //cerr << "system.numThreads=" << system.options.server.numThreads << endl; | |
| Moses2::ThreadPool pool(system.options.server.numThreads, system.cpuAffinityOffset, system.cpuAffinityOffsetIncr); | |
| //cerr << "CREATED POOL" << endl; | |
| if (params.GetParam("server")) { | |
| std::cerr << "RUN SERVER" << std::endl; | |
| run_as_server(system); | |
| } | |
| else { | |
| std::cerr << "RUN BATCH" << std::endl; | |
| batch_run(params, system, pool); | |
| } | |
| cerr << "Decoding took " << timer.get_elapsed_time() << endl; | |
| // cerr << "g_numHypos=" << g_numHypos << endl; | |
| cerr << "Finished" << endl; | |
| return EXIT_SUCCESS; | |
| } | |
| //////////////////////////////////////////////////////////////////////////////////////////////// | |
| void run_as_server(Moses2::System& system) | |
| { | |
| Moses2::Server server(system.options.server, system); | |
| server.run(system); // actually: don't return. see Server::run() | |
| UTIL_THROW2("Moses2 was compiled without xmlrpc-c. " | |
| << "No server functionality available."); | |
| } | |
| //////////////////////////////////////////////////////////////////////////////////////////////// | |
| istream &GetInputStream(Moses2::Parameter ¶ms) | |
| { | |
| const Moses2::PARAM_VEC *vec = params.GetParam("input-file"); | |
| if (vec && vec->size()) { | |
| Moses2::InputFileStream *stream = new Moses2::InputFileStream(vec->at(0)); | |
| return *stream; | |
| } else { | |
| return cin; | |
| } | |
| } | |
| //////////////////////////////////////////////////////////////////////////////////////////////// | |
| void batch_run(Moses2::Parameter& params, Moses2::System& system, Moses2::ThreadPool& pool) | |
| { | |
| istream& inStream = GetInputStream(params); | |
| long translationId = 0; | |
| string line; | |
| while (getline(inStream, line)) { | |
| //cerr << "line=" << line << endl; | |
| boost::shared_ptr<Moses2::TranslationTask> task(new Moses2::TranslationTask(system, line, translationId)); | |
| //cerr << "START pool.Submit()" << endl; | |
| pool.Submit(task); | |
| //task->Run(); | |
| ++translationId; | |
| } | |
| pool.Stop(true); | |
| if (&inStream != &cin) { | |
| delete& inStream; | |
| } | |
| //util::PrintUsage(std::cerr); | |
| } | |
| //////////////////////////////////////////////////////////////////////////////////////////////// | |