Skip to content

Commit e794480

Browse files
committed
#3: allow limiting number of iterations
1 parent 7f5e343 commit e794480

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

parser/lstm-parse.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ void InitCommandLine(int argc, char** argv, po::variables_map* conf) {
7676
("rel_dim", po::value<unsigned>()->default_value(10), "relation dimension")
7777
("lstm_input_dim", po::value<unsigned>()->default_value(60), "LSTM input dimension")
7878
("train,t", "Should training be run?")
79+
("maxit,M", po::value<unsigned>()->default_value(8000), "Maximum number of training iterations")
7980
("words,w", po::value<string>(), "Pretrained word embeddings")
8081
("use_spelling,S", "Use spelling model") //Miguel. Spelling model
8182
("help,h", "Help");
@@ -943,6 +944,8 @@ int main(int argc, char** argv) {
943944
}
944945
const double unk_prob = conf["unk_prob"].as<double>();
945946
assert(unk_prob >= 0.); assert(unk_prob <= 1.);
947+
const unsigned maxit = conf["maxit"].as<unsigned>();
948+
cerr << "Maximum number of iterations: " << maxit << "\n";
946949
ostringstream os;
947950
os << "parser_" << (USE_POS ? "pos" : "nopos")
948951
<< '_' << LAYERS
@@ -1031,9 +1034,8 @@ int main(int argc, char** argv) {
10311034
double right = 0;
10321035
double llh = 0;
10331036
bool first = true;
1034-
int iter = -1;
1035-
while(!requested_stop) {
1036-
++iter;
1037+
unsigned iter = 0;
1038+
while(!requested_stop && iter < maxit) {
10371039
for (unsigned sii = 0; sii < status_every_i_iterations; ++sii) {
10381040
if (si == corpus.nsentences) {
10391041
si = 0;
@@ -1120,6 +1122,10 @@ int main(int argc, char** argv) {
11201122
}
11211123
}
11221124
}
1125+
++iter;
1126+
}
1127+
if (iter >= maxit) {
1128+
cerr << "\nMaximum number of iterations reached (" << iter << "), terminating optimization...\n";
11231129
}
11241130
} // should do training?
11251131
if (true) { // do test evaluation

0 commit comments

Comments
 (0)