summaryrefslogtreecommitdiff
path: root/training
diff options
context:
space:
mode:
authorredpony <redpony@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-11-30 23:21:07 +0000
committerredpony <redpony@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-11-30 23:21:07 +0000
commit988461b40d14162dd93490c3e34de1f6c04cb540 (patch)
tree7dd88f3cdc837dd66587a532c34386de3f35dd8f /training
parentf06e7fa27c4e485dccaee356b3b5f46238f561a2 (diff)
add flag to disable viterbi
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@733 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'training')
-rw-r--r--training/model1.cc28
1 files changed, 16 insertions, 12 deletions
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<unsigned>()->default_value(5),"Number of iterations of EM training")
("beam_threshold,t",po::value<double>()->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<string>(), "Configuration file")
@@ -51,6 +52,7 @@ int main(int argc, char** argv) {
const double BEAM_THRESHOLD = pow(10.0, conf["beam_threshold"].as<double>());
const bool use_null = (conf.count("no_null_word") == 0);
const WordID kNULL = TD::Convert("<eps>");
+ 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);