You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by dr...@apache.org on 2017/02/09 18:12:03 UTC

opennlp git commit: OpenNLP-981: Add training stream hash to AbstractEventTrainer. This closes #118.

Repository: opennlp
Updated Branches:
  refs/heads/master efb183135 -> 324e8b4d4


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/324e8b4d
Tree: http://git-wip-us.apache.org/repos/asf/opennlp/tree/324e8b4d
Diff: http://git-wip-us.apache.org/repos/asf/opennlp/diff/324e8b4d

Branch: refs/heads/master
Commit: 324e8b4d43f0260b4857dafef46e8c5f349f633c
Parents: efb1831
Author: Daniel Russ <dr...@mail.nih.gov>
Authored: Thu Feb 9 09:56:12 2017 -0500
Committer: Daniel Russ <dr...@mail.nih.gov>
Committed: Thu Feb 9 13:08:18 2017 -0500

----------------------------------------------------------------------
 .../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/324e8b4d/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/324e8b4d/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")); 
+  }
 }