From 7ebf32cd42fb1ea3db33603a7585792189b06d4a Mon Sep 17 00:00:00 2001 From: redpony Date: Tue, 30 Nov 2010 23:21:07 +0000 Subject: add flag to disable viterbi git-svn-id: https://ws10smt.googlecode.com/svn/trunk@733 ec762483-ff6d-05da-a07a-a48fb63a330f --- training/model1.cc | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'training') diff --git a/training/model1.cc b/training/model1.cc index 83dacd63..eacf4b32 100644 --- a/training/model1.cc +++ b/training/model1.cc @@ -19,7 +19,8 @@ bool InitCommandLine(int argc, char** argv, po::variables_map* conf) { opts.add_options() ("iterations,i",po::value()->default_value(5),"Number of iterations of EM training") ("beam_threshold,t",po::value()->default_value(-4),"log_10 of beam threshold (-10000 to include everything, 0 max)") - ("no_null_word,N","Do not generate from the null token"); + ("no_null_word,N","Do not generate from the null token") + ("no_add_viterbi,V","Do not add Viterbi alignment points (may generate a grammar where some training sentence pairs are unreachable)"); po::options_description clo("Command line options"); clo.add_options() ("config", po::value(), "Configuration file") @@ -51,6 +52,7 @@ int main(int argc, char** argv) { const double BEAM_THRESHOLD = pow(10.0, conf["beam_threshold"].as()); const bool use_null = (conf.count("no_null_word") == 0); const WordID kNULL = TD::Convert(""); + const bool add_viterbi = (conf.count("no_add_viterbi") == 0); TTable tt; TTable::Word2Word2Double was_viterbi; @@ -95,19 +97,21 @@ int main(int argc, char** argv) { sum += probs[i]; } if (final_iteration) { - WordID max_i = 0; - double max_p = -1; - if (use_null) { - max_i = kNULL; - max_p = probs[0]; - } - for (int i = 1; i <= src.size(); ++i) { - if (probs[i] > max_p) { - max_p = probs[i]; - max_i = src[i-1][0].label; + if (add_viterbi) { + WordID max_i = 0; + double max_p = -1; + if (use_null) { + max_i = kNULL; + max_p = probs[0]; + } + for (int i = 1; i <= src.size(); ++i) { + if (probs[i] > max_p) { + max_p = probs[i]; + max_i = src[i-1][0].label; + } } + was_viterbi[max_i][f_j] = 1.0; } - was_viterbi[max_i][f_j] = 1.0; } else { if (use_null) tt.Increment(kNULL, f_j, probs[0] / sum); -- cgit v1.2.3