This is an automated email from the ASF dual-hosted git repository.

rzo1 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opennlp.git


The following commit(s) were added to refs/heads/main by this push:
     new cf83a1375 OPENNLP-1742: Use the MaxEnt training default for 
NameFinderME (#1171)
cf83a1375 is described below

commit cf83a1375c564691acfd22fb6f64be3d67e5861d
Author: jerry317395616 <[email protected]>
AuthorDate: Thu Jul 16 16:28:39 2026 +0800

    OPENNLP-1742: Use the MaxEnt training default for NameFinderME (#1171)
    
    * OPENNLP-1742: Use the MaxEnt training default for NameFinderME
    
    * OPENNLP-1742: Stabilize the CLI output test
---
 .../opennlp/tools/cmdline/TokenNameFinderToolTest.java |  3 +++
 .../main/java/opennlp/tools/namefind/NameFinderME.java |  4 +---
 .../java/opennlp/tools/namefind/NameFinderMETest.java  |  3 +++
 .../tools/namefind/NameFinderMEWithDatesTest.java      | 18 ++++++++++++++++--
 4 files changed, 23 insertions(+), 5 deletions(-)

diff --git 
a/opennlp-core/opennlp-cli/src/test/java/opennlp/tools/cmdline/TokenNameFinderToolTest.java
 
b/opennlp-core/opennlp-cli/src/test/java/opennlp/tools/cmdline/TokenNameFinderToolTest.java
index da3d9e1fa..4806cf8fa 100644
--- 
a/opennlp-core/opennlp-cli/src/test/java/opennlp/tools/cmdline/TokenNameFinderToolTest.java
+++ 
b/opennlp-core/opennlp-cli/src/test/java/opennlp/tools/cmdline/TokenNameFinderToolTest.java
@@ -37,6 +37,7 @@ import org.junit.jupiter.api.Test;
 import org.slf4j.LoggerFactory;
 
 import opennlp.tools.cmdline.namefind.TokenNameFinderTool;
+import opennlp.tools.ml.AlgorithmType;
 import opennlp.tools.namefind.NameFinderME;
 import opennlp.tools.namefind.NameSample;
 import opennlp.tools.namefind.NameSampleDataStream;
@@ -128,6 +129,8 @@ public class TokenNameFinderToolTest {
             StandardCharsets.ISO_8859_1);
 
     TrainingParameters params = new TrainingParameters();
+    // This test verifies CLI output, so keep its fixture independent of the 
default trainer.
+    params.put(Parameters.ALGORITHM_PARAM, 
AlgorithmType.PERCEPTRON.getAlgorithmType());
     params.put(Parameters.ITERATIONS_PARAM, 70);
     params.put(Parameters.CUTOFF_PARAM, 1);
 
diff --git 
a/opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/namefind/NameFinderME.java
 
b/opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/namefind/NameFinderME.java
index f02feace5..f1dec349c 100644
--- 
a/opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/namefind/NameFinderME.java
+++ 
b/opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/namefind/NameFinderME.java
@@ -28,7 +28,6 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import opennlp.tools.commons.ThreadSafe;
-import opennlp.tools.ml.AlgorithmType;
 import opennlp.tools.ml.BeamSearch;
 import opennlp.tools.ml.EventModelSequenceTrainer;
 import opennlp.tools.ml.EventTrainer;
@@ -273,8 +272,7 @@ public class NameFinderME implements TokenNameFinder, 
Probabilistic {
                                            ObjectStream<NameSample> samples, 
TrainingParameters params,
                                            TokenNameFinderFactory factory) 
throws IOException {
 
-    //FIXME OPENNLP-1742
-    params.putIfAbsent(Parameters.ALGORITHM_PARAM, 
AlgorithmType.PERCEPTRON.getAlgorithmType());
+    params.putIfAbsent(Parameters.ALGORITHM_PARAM, 
Parameters.ALGORITHM_DEFAULT_VALUE);
     params.putIfAbsent(Parameters.CUTOFF_PARAM, 0);
     params.putIfAbsent(Parameters.ITERATIONS_PARAM, 300);
 
diff --git 
a/opennlp-core/opennlp-runtime/src/test/java/opennlp/tools/namefind/NameFinderMETest.java
 
b/opennlp-core/opennlp-runtime/src/test/java/opennlp/tools/namefind/NameFinderMETest.java
index b014e06c6..3c8c8e6bc 100644
--- 
a/opennlp-core/opennlp-runtime/src/test/java/opennlp/tools/namefind/NameFinderMETest.java
+++ 
b/opennlp-core/opennlp-runtime/src/test/java/opennlp/tools/namefind/NameFinderMETest.java
@@ -76,6 +76,9 @@ public class NameFinderMETest extends AbstractNameFinderTest {
     TokenNameFinderModel nameFinderModel = NameFinderME.train("eng", null, 
sampleStream,
         params, TokenNameFinderFactory.create(null, null, 
Collections.emptyMap(), new BioCodec()));
 
+    assertEquals(Parameters.ALGORITHM_DEFAULT_VALUE,
+        params.getStringParameter(Parameters.ALGORITHM_PARAM, null));
+
     TokenNameFinder nameFinder = new NameFinderME(nameFinderModel);
 
     // now test if it can detect the sample sentences
diff --git 
a/opennlp-core/opennlp-runtime/src/test/java/opennlp/tools/namefind/NameFinderMEWithDatesTest.java
 
b/opennlp-core/opennlp-runtime/src/test/java/opennlp/tools/namefind/NameFinderMEWithDatesTest.java
index e6abb6a53..9e3cb1720 100644
--- 
a/opennlp-core/opennlp-runtime/src/test/java/opennlp/tools/namefind/NameFinderMEWithDatesTest.java
+++ 
b/opennlp-core/opennlp-runtime/src/test/java/opennlp/tools/namefind/NameFinderMEWithDatesTest.java
@@ -28,7 +28,10 @@ import org.junit.jupiter.params.provider.Arguments;
 import org.junit.jupiter.params.provider.MethodSource;
 import org.junit.jupiter.params.provider.ValueSource;
 
+import opennlp.tools.ml.AlgorithmType;
+import opennlp.tools.util.Parameters;
 import opennlp.tools.util.Span;
+import opennlp.tools.util.TrainingParameters;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -69,11 +72,11 @@ public class NameFinderMEWithDatesTest extends 
AbstractNameFinderTest {
       downloadVersion15Model("en-ner-date.bin");
       v15ModelEN = new TokenNameFinderModel(Files.newInputStream(
               OPENNLP_DIR.resolve("en-ner-date.bin")));
-      TokenNameFinderModel trainedModelEN = trainModel("eng",
+      TokenNameFinderModel trainedModelEN = trainDateModel("eng",
               "opennlp/tools/namefind/RandomNewsWithGeneratedDates_EN.train");
       assertNotNull(trainedModelEN);
       assertTrue(hasOtherAsOutcome(trainedModelEN));
-      TokenNameFinderModel trainedModelDE = trainModel("deu",
+      TokenNameFinderModel trainedModelDE = trainDateModel("deu",
               "opennlp/tools/namefind/RandomNewsWithGeneratedDates_DE.train");
       assertNotNull(trainedModelDE);
       assertTrue(hasOtherAsOutcome(trainedModelDE));
@@ -84,6 +87,17 @@ public class NameFinderMEWithDatesTest extends 
AbstractNameFinderTest {
     }
   }
 
+  private static TokenNameFinderModel trainDateModel(String languageCode,
+                                                      String trainingFile) 
throws IOException {
+    TrainingParameters params = new TrainingParameters();
+    // This suite verifies date spans, so keep its established trainer 
independent of the default.
+    params.put(Parameters.ALGORITHM_PARAM, 
AlgorithmType.PERCEPTRON.getAlgorithmType());
+    params.put(Parameters.ITERATIONS_PARAM, 150);
+    params.put(Parameters.THREADS_PARAM, 4);
+    params.put(Parameters.CUTOFF_PARAM, 3);
+    return trainModel(languageCode, trainingFile, params);
+  }
+
   /**
    * Uses the English SourceForge V1.5 model with "date" nameType and verifies 
with sample text.
    */

Reply via email to