summaryrefslogtreecommitdiff
path: root/gi/posterior-regularisation/prjava/src/phrase/Trainer.java
diff options
context:
space:
mode:
authortrevor.cohn <trevor.cohn@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-12 19:48:54 +0000
committertrevor.cohn <trevor.cohn@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-12 19:48:54 +0000
commit77c25d9f30f95ccb7843f9dce71a4f4e018cc727 (patch)
tree41ed18b1fe81fd4288a4e81e5f4e6efae392643b /gi/posterior-regularisation/prjava/src/phrase/Trainer.java
parent2f90f9e203da01583ee0b82d4769f25b198835dd (diff)
Updated launcher to include agreement model.
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@226 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'gi/posterior-regularisation/prjava/src/phrase/Trainer.java')
-rw-r--r--gi/posterior-regularisation/prjava/src/phrase/Trainer.java56
1 files changed, 36 insertions, 20 deletions
diff --git a/gi/posterior-regularisation/prjava/src/phrase/Trainer.java b/gi/posterior-regularisation/prjava/src/phrase/Trainer.java
index 439fb337..240c4d64 100644
--- a/gi/posterior-regularisation/prjava/src/phrase/Trainer.java
+++ b/gi/posterior-regularisation/prjava/src/phrase/Trainer.java
@@ -30,6 +30,7 @@ public class Trainer
parser.accepts("variational-bayes");
parser.accepts("alpha-emit").withRequiredArg().ofType(Double.class).defaultsTo(0.1);
parser.accepts("alpha-pi").withRequiredArg().ofType(Double.class).defaultsTo(0.01);
+ parser.accepts("agree");
OptionSet options = parser.parse(args);
if (options.has("help") || !options.has("in"))
@@ -37,7 +38,7 @@ public class Trainer
try {
parser.printHelpOn(System.err);
} catch (IOException e) {
- System.err.println("This should never happen. Really.");
+ System.err.println("This should never happen.");
e.printStackTrace();
}
System.exit(1);
@@ -75,34 +76,46 @@ public class Trainer
System.exit(1);
}
- System.out.println("Running with " + tags + " tags " +
- "for " + em_iterations + " EM and " + pr_iterations + " PR iterations " +
- "with scale " + scale_phrase + " phrase and " + scale_context + " context " +
- "and " + threads + " threads");
- System.out.println();
+ if (!options.has("agree"))
+ System.out.println("Running with " + tags + " tags " +
+ "for " + em_iterations + " EM and " + pr_iterations + " PR iterations " +
+ "with scale " + scale_phrase + " phrase and " + scale_context + " context " +
+ "and " + threads + " threads");
+ else
+ System.out.println("Running agreement model with " + tags + " tags " +
+ "for " + em_iterations);
+
+ System.out.println();
- PhraseCluster cluster = new PhraseCluster(tags, corpus, scale_phrase, scale_context, threads, alphaEmit, alphaPi);
+ PhraseCluster cluster = null;
+ Agree agree = null;
+ if (options.has("agree"))
+ agree = new Agree(tags, corpus);
+ else
+ {
+ cluster = new PhraseCluster(tags, corpus);
+ if (threads > 0) cluster.useThreadPool(threads);
+ if (vb) cluster.initialiseVB(alphaEmit, alphaPi);
+ }
double last = 0;
for (int i=0; i<em_iterations+pr_iterations; i++)
{
double o;
- if (i < em_iterations)
- {
- if (!vb)
- o = cluster.EM();
- else
- o = cluster.VBEM();
- }
- else if (scale_context == 0)
+ if (agree != null)
+ o = agree.EM();
+ else
{
- if (threads >= 1)
- o = cluster.PREM_phrase_constraints_parallel();
+ if (i < em_iterations)
+ {
+ if (!vb)
+ o = cluster.EM();
+ else
+ o = cluster.VBEM(alphaEmit, alphaPi);
+ }
else
- o = cluster.PREM_phrase_constraints();
+ o = cluster.PREM(scale_phrase, scale_context);
}
- else
- o = cluster.PREM_phrase_context_constraints();
System.out.println("ITER: "+i+" objective: " + o);
@@ -120,6 +133,9 @@ public class Trainer
last = o;
}
+ if (cluster == null)
+ cluster = agree.model1;
+
double pl1lmax = cluster.phrase_l1lmax();
double cl1lmax = cluster.context_l1lmax();
System.out.println("\nFinal posterior phrase l1lmax " + pl1lmax + " context l1lmax " + cl1lmax);