From c54bbd4c2c8fefb951f63422357e86c68710e908 Mon Sep 17 00:00:00 2001 From: Daniel Hershcovich Date: Tue, 28 Jul 2015 14:46:59 +0300 Subject: [PATCH] clab/lstm-parser#3: allow limiting number of iterations --- parser/lstm-parse.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/parser/lstm-parse.cc b/parser/lstm-parse.cc index 27594bd..bf2cc21 100644 --- a/parser/lstm-parse.cc +++ b/parser/lstm-parse.cc @@ -70,6 +70,7 @@ void InitCommandLine(int argc, char** argv, po::variables_map* conf) { ("rel_dim", po::value()->default_value(10), "relation dimension") ("lstm_input_dim", po::value()->default_value(60), "LSTM input dimension") ("train,t", "Should training be run?") + ("maxit,M", po::value()->default_value(8000), "Maximum number of training iterations") ("words,w", po::value(), "Pretrained word embeddings") ("help,h", "Help"); po::options_description dcmdline_options; @@ -522,6 +523,8 @@ int main(int argc, char** argv) { } const double unk_prob = conf["unk_prob"].as(); assert(unk_prob >= 0.); assert(unk_prob <= 1.); + const unsigned maxit = conf["maxit"].as(); + cerr << "Maximum number of iterations: " << maxit << "\n"; ostringstream os; os << "parser_" << (USE_POS ? "pos" : "nopos") << '_' << LAYERS @@ -603,11 +606,10 @@ int main(int argc, char** argv) { double right = 0; double llh = 0; bool first = true; - int iter = -1; + unsigned iter = 0; time_t time_start = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); cerr << "TRAINING STARTED AT: " << put_time(localtime(&time_start), "%c %Z") << endl; - while(!requested_stop) { - ++iter; + while(!requested_stop && iter < maxit) { for (unsigned sii = 0; sii < status_every_i_iterations; ++sii) { if (si == corpus.nsentences) { si = 0; @@ -692,6 +694,10 @@ int main(int argc, char** argv) { } } } + ++iter; + } + if (iter >= maxit) { + cerr << "\nMaximum number of iterations reached (" << iter << "), terminating optimization...\n"; } } // should do training? if (true) { // do test evaluation