Skip to content

Commit

Permalink
clab#3: allow limiting number of iterations
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhers committed Jul 28, 2015
1 parent 7c5aec7 commit 55ba994
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions parser/lstm-parse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ void InitCommandLine(int argc, char** argv, po::variables_map* conf) {
("rel_dim", po::value<unsigned>()->default_value(10), "relation dimension")
("lstm_input_dim", po::value<unsigned>()->default_value(60), "LSTM input dimension")
("train,t", "Should training be run?")
("maxit,M", po::value<unsigned>()->default_value(8000), "Maximum number of training iterations")
("words,w", po::value<string>(), "Pretrained word embeddings")
("help,h", "Help");
po::options_description dcmdline_options;
Expand Down Expand Up @@ -522,6 +523,8 @@ int main(int argc, char** argv) {
}
const double unk_prob = conf["unk_prob"].as<double>();
assert(unk_prob >= 0.); assert(unk_prob <= 1.);
const unsigned maxit = conf["maxit"].as<unsigned>();
cerr << "Maximum number of iterations: " << maxit << "\n";
ostringstream os;
os << "parser_" << (USE_POS ? "pos" : "nopos")
<< '_' << LAYERS
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 55ba994

Please sign in to comment.