Skip to content

Commit 9f8621e

Browse files
committed
OPENNLP-124 : Fixed some comments and general refactoring.
1 parent b134684 commit 9f8621e

File tree

7 files changed

+8
-9
lines changed

7 files changed

+8
-9
lines changed

Diff for: opennlp-tools/src/main/java/opennlp/tools/commons/Trainer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public interface Trainer {
3737
void init(TrainingParameters trainParams, Map<String, String> reportMap);
3838

3939
/**
40-
* Conducts the initialization of an {@link Trainer} via
40+
* Conducts the initialization of a {@link Trainer} via
4141
* {@link TrainingParameters}, {@link Map report map} and {@link TrainingConfiguration}
4242
*
4343
* @param trainParams The {@link TrainingParameters} to use.

Diff for: opennlp-tools/src/main/java/opennlp/tools/ml/maxent/GISTrainer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ private void findParameters(int iterations, double correctionConstant) {
504504
double prevLL = 0.0;
505505
double currLL;
506506

507-
//Get the Training Progress Monitor to log training progress.
507+
//Get the Training Progress Monitor and the StopCriteria.
508508
TrainingProgressMonitor progressMonitor = getTrainingProgressMonitor(trainingConfiguration);
509509
StopCriteria stopCriteria = getStopCriteria(trainingConfiguration);
510510

Diff for: opennlp-tools/src/main/java/opennlp/tools/ml/perceptron/PerceptronTrainer.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ public AbstractModel trainModel(int iterations, DataIndexer di, int cutoff, bool
263263

264264
logger.info("Computing model parameters...");
265265

266-
267266
MutableContext[] finalParameters = findParameters(iterations, useAverage);
268267

269268
logger.info("...done.");
@@ -300,6 +299,7 @@ private MutableContext[] findParameters(int iterations, boolean useAverage) {
300299
}
301300
}
302301

302+
//Get the Training Progress Monitor and the StopCriteria.
303303
TrainingProgressMonitor progressMonitor = getTrainingProgressMonitor(trainingConfiguration);
304304
StopCriteria stopCriteria = getStopCriteria(trainingConfiguration);
305305

@@ -382,8 +382,6 @@ private MutableContext[] findParameters(int iterations, boolean useAverage) {
382382
// If the tolerance is greater than the difference between the
383383
// current training accuracy and all of the previous three
384384
// training accuracies, stop training.
385-
386-
387385
if (stopCriteria.test(prevAccuracy1 - trainingAccuracy)
388386
&& stopCriteria.test(prevAccuracy2 - trainingAccuracy)
389387
&& stopCriteria.test(prevAccuracy3 - trainingAccuracy)) {

Diff for: opennlp-tools/src/main/java/opennlp/tools/monitoring/DefaultTrainingProgressMonitor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public DefaultTrainingProgressMonitor() {
5454
*/
5555
@Override
5656
public synchronized void finishedIteration(int iteration, int numberCorrectEvents, int totalEvents,
57-
TrainingMeasure measure, double measureValue) {
57+
TrainingMeasure measure, double measureValue) {
5858
progress.add(String.format("%s: (%s/%s) %s : %s", iteration, numberCorrectEvents, totalEvents,
5959
measure.getMeasureName(), measureValue));
6060
}

Diff for: opennlp-tools/src/main/java/opennlp/tools/monitoring/IterDeltaAccuracyUnderTolerance.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import opennlp.tools.util.TrainingParameters;
2222

2323
/**
24-
* A {@link StopCriteria} implementation to identify whether the
24+
* A {@link StopCriteria} implementation to identify whether the absolute
2525
* difference between the training accuracy of current and previous iteration is under the defined tolerance.
2626
*/
2727
public class IterDeltaAccuracyUnderTolerance implements StopCriteria {

Diff for: opennlp-tools/src/test/java/opennlp/tools/ml/MockEventTrainer.java

-1
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,4 @@ public void init(TrainingParameters trainParams, Map<String, String> reportMap,
4646
TrainingConfiguration config) {
4747
}
4848

49-
5049
}

Diff for: opennlp-tools/src/test/java/opennlp/tools/monitoring/DefaultTrainingProgressMonitorTest.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class DefaultTrainingProgressMonitorTest {
4242
private TrainingProgressMonitor progressMonitor;
4343
private final ListAppender<ILoggingEvent> appender = new ListAppender<>();
4444
private static final Logger logger = (Logger) LoggerFactory.getLogger(LOGGER_NAME);
45-
private static final Level originalLogLevel = logger.getLevel();
45+
private static final Level originalLogLevel = logger != null ? logger.getLevel() : Level.OFF;
4646

4747
@BeforeAll
4848
static void beforeAll() {
@@ -78,6 +78,7 @@ void testTrainingEndWithStopCriteria() {
7878
progressMonitor.finishedTraining(150, stopCriteria);
7979
progressMonitor.displayAndClear();
8080

81+
//Assert that the logs captured the training completion message with StopCriteria satisfied.
8182
Assertions.assertThat(appender.list.stream().map(ILoggingEvent::getMessage).
8283
collect(Collectors.toList())).
8384
isEqualTo(List.of("Stopping: change in training set accuracy less than {2.0E-5}"));
@@ -88,6 +89,7 @@ void testTrainingEndWithoutHittingStopCriteria() {
8889
progressMonitor.finishedTraining(150, null);
8990
progressMonitor.displayAndClear();
9091

92+
//Assert that the logs captured the training completion message when all iterations are exhausted.
9193
Assertions.assertThat(appender.list.stream().map(ILoggingEvent::getMessage).
9294
collect(Collectors.toList())).
9395
isEqualTo(List.of("Training Finished after completing 150 Iterations successfully."));

0 commit comments

Comments
 (0)