OpenNLP-981: Add training stream hash to AbstractEventTrainer. This closes #118.
Project: http://git-wip-us.apache.org/repos/asf/opennlp/repo Commit: http://git-wip-us.apache.org/repos/asf/opennlp/commit/cd23b58a Tree: http://git-wip-us.apache.org/repos/asf/opennlp/tree/cd23b58a Diff: http://git-wip-us.apache.org/repos/asf/opennlp/diff/cd23b58a Branch: refs/heads/parser_regression Commit: cd23b58a3c04053d8c6cafa761aa0fc533774304 Parents: daa9fca Author: Daniel Russ <dr...@mail.nih.gov> Authored: Thu Feb 9 09:56:12 2017 -0500 Committer: Jörn Kottmann <jo...@apache.org> Committed: Sun Apr 16 19:24:52 2017 +0200 ---------------------------------------------------------------------- .../opennlp/tools/ml/AbstractEventTrainer.java | 1 + .../ml/perceptron/PerceptronPrepAttachTest.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/opennlp/blob/cd23b58a/opennlp-tools/src/main/java/opennlp/tools/ml/AbstractEventTrainer.java ---------------------------------------------------------------------- diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/AbstractEventTrainer.java b/opennlp-tools/src/main/java/opennlp/tools/ml/AbstractEventTrainer.java index c465f88..bb11aaa 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/AbstractEventTrainer.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/AbstractEventTrainer.java @@ -88,6 +88,7 @@ public abstract class AbstractEventTrainer extends AbstractTrainer implements Ev HashSumEventStream hses = new HashSumEventStream(events); DataIndexer indexer = getDataIndexer(hses); + addToReport("Training-Eventhash", hses.calculateHashSum().toString(16)); return train(indexer); } } http://git-wip-us.apache.org/repos/asf/opennlp/blob/cd23b58a/opennlp-tools/src/test/java/opennlp/tools/ml/perceptron/PerceptronPrepAttachTest.java ---------------------------------------------------------------------- diff --git a/opennlp-tools/src/test/java/opennlp/tools/ml/perceptron/PerceptronPrepAttachTest.java b/opennlp-tools/src/test/java/opennlp/tools/ml/perceptron/PerceptronPrepAttachTest.java index d4d70ca..eda49f8 100644 --- a/opennlp-tools/src/test/java/opennlp/tools/ml/perceptron/PerceptronPrepAttachTest.java +++ b/opennlp-tools/src/test/java/opennlp/tools/ml/perceptron/PerceptronPrepAttachTest.java @@ -23,6 +23,7 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.util.HashMap; +import java.util.Map; import org.junit.Assert; import org.junit.Test; @@ -134,4 +135,20 @@ public class PerceptronPrepAttachTest { Assert.assertEquals(modelA, modelB); Assert.assertEquals(modelA.hashCode(), modelB.hashCode()); } + + @Test + public void verifyReportMap() throws IOException { + TrainingParameters trainParams = new TrainingParameters(); + trainParams.put(AbstractTrainer.ALGORITHM_PARAM, PerceptronTrainer.PERCEPTRON_VALUE); + trainParams.put(AbstractTrainer.CUTOFF_PARAM, Integer.toString(1)); + // Since we are verifying the report map, we don't need to have more than 1 iteration + trainParams.put(AbstractTrainer.ITERATIONS_PARAM, Integer.toString(1)); + trainParams.put("UseSkippedAveraging", Boolean.toString(true)); + + Map<String,String> reportMap = new HashMap<>(); + EventTrainer trainer = TrainerFactory.getEventTrainer(trainParams, reportMap); + trainer.train(PrepAttachDataUtil.createTrainingStream()); + Assert.assertTrue("Report Map does not contain the training event hash", + reportMap.containsKey("Training-Eventhash")); + } }