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/797c234a Tree: http://git-wip-us.apache.org/repos/asf/opennlp/tree/797c234a Diff: http://git-wip-us.apache.org/repos/asf/opennlp/diff/797c234a Branch: refs/heads/parser_regression Commit: 797c234af757d95f11d568a7ae7b34512526a4a0 Parents: 2cb6254 Author: Daniel Russ <[email protected]> Authored: Thu Feb 9 09:56:12 2017 -0500 Committer: Jörn Kottmann <[email protected]> Committed: Thu Apr 20 12:40:19 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/797c234a/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/797c234a/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")); + } }
