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 Feb 8, 2017
1 parent 7f5e343 commit e794480
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 @@ -76,6 +76,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")
("use_spelling,S", "Use spelling model") //Miguel. Spelling model
("help,h", "Help");
Expand Down Expand Up @@ -943,6 +944,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 @@ -1031,9 +1034,8 @@ int main(int argc, char** argv) {
double right = 0;
double llh = 0;
bool first = true;
int iter = -1;
while(!requested_stop) {
++iter;
unsigned iter = 0;
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 @@ -1120,6 +1122,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 e794480

Please sign in to comment.