Skip to content

OPENNLP-124: Maxent/Perceptron training should report progess back via an API #758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

NishantShri4
Copy link
Contributor

@NishantShri4 NishantShri4 commented Mar 24, 2025

Thank you for contributing to Apache OpenNLP.

In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:

For all changes:

  • Is there a JIRA ticket associated with this PR? Is it referenced
    in the commit message?

  • Does your PR title start with OPENNLP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.

  • Has your PR been rebased against the latest commit within the target branch (typically main)?

  • Is your initial contribution a single, squashed commit?

For code changes:

  • Have you ensured that the full suite of tests is executed via mvn clean install at the root opennlp folder?
  • Have you written or updated unit tests to verify your changes?
  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
  • If applicable, have you updated the LICENSE file, including the main LICENSE file in opennlp folder?
  • If applicable, have you updated the NOTICE file, including the main NOTICE file found in opennlp folder?

For documentation related changes:

  • Have you ensured that format looks appropriate for the output in which it is rendered?

Note:

Please ensure that once the PR is submitted, you check GitHub Actions for build issues and submit an update to your PR as soon as possible.

@NishantShri4
Copy link
Contributor Author

Hello @mawiesne / @kottmann . Good day!

Is this item waiting to be picked up? https://issues.apache.org/jira/browse/OPENNLP-124.
Here is my draft PR.
This PR is just to explain my current understanding of the Jira .
This needs further improvements (refactoring, integration with other model trainers, unit tests etc.).
I am happy to be part of the discussion and pick it up for implementation if the team approves.
Pls. let me know your views.

Attached the output of a couple of existing Tests (Perceptron Trainer) based on the integration with Console based TrainingProgressMonitor.
PerceptroTrainerUnitTests-LogOutput.txt

@NishantShri4 NishantShri4 marked this pull request as draft March 24, 2025 07:28
@mawiesne
Copy link
Contributor

FYI: @jzonthemtn + @rzo1

Copy link
Contributor

@rzo1 rzo1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the draft. I added some thoughts / comments.

@NishantShri4
Copy link
Contributor Author

NishantShri4 commented Apr 13, 2025

hi @rzo1, @mawiesne,

Hope you are well. I have tried to fix the review comments. Would you pls. be able to review once more and direct towards the intended solution? Many thanks in advance.

Some queries and ToDos:

  1. The jira description gives following prototype of finishedTraining() method.
finishedTraining(int iterations, int numberCorrectEvents, int totalEvents, StopCriteria stopCriteria);
}

Please can you clarify, what is the use of numberCorrectEvents and totalEvents parameters? In my current implementation, I have not used them, instead I found stopCriteria is sufficient. Pls. take a look.

  1. ToDo : Update the documentation to include description of TPM and StopCriteria.

/**
* Stop-criteria for a {@link opennlp.tools.ml.model.AbstractModel} training .
*/
public interface StopCriteria extends Predicate<Double> {
Copy link
Contributor Author

@NishantShri4 NishantShri4 Apr 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be made as extends Predicate<Object>;
So that this common API is flexible to receive any object as input to verify testing Criteria? views pls.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NishantShri4

Or even nicer
public interface StopCriteria<T extends Number> extends Predicate<T> {

This way, several numerical stop criteria can be defined, either as integer/long or float/double precision.
Don't think that we need sth different than Number as base type for T, do we?

* used to store the training progress events. Callers of this method can invoke it periodically
* during training progress to avoid storing too much progress related data.
*/
void displayAndClear();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be made to accept a boolean input parameter which decides whether the underlying data structure is cleared or not?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If parameter clear is introduced, method should be renamed to void display(boolean clear)

@NishantShri4 NishantShri4 marked this pull request as ready for review April 16, 2025 08:30
@NishantShri4
Copy link
Contributor Author

Hi Reviewers - All checks are green now. This is available for review. If possible, pls. take a look.
One query - This PR has 10 commits. Before presenting it for review, Is it needed to club them into a single commit?

@mawiesne
Copy link
Contributor

Hi Reviewers - All checks are green now. This is available for review. If possible, pls. take a look.

One query - This PR has 10 commits. Before presenting it for review, Is it needed to club them into a single commit?

Thx @NishantShri4 for moving this topic forward! Could you squash those commits and force push the resulting single commit? Once available, we'll have a detailed look and provide feedback.

@mawiesne mawiesne changed the title OPENNLP-124 Maxent/Perceptron training should report progess back via an API OPENNLP-124: Maxent/Perceptron training should report progess back via an API Apr 16, 2025
@NishantShri4
Copy link
Contributor Author

Thanks @mawiesne. This is done (rebase, squash and force push).

Copy link
Contributor

@mawiesne mawiesne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx @NishantShri4 for providing this substantial contribution. I've left feedback by comments to further improve it. Once addressed, I'll re-check and potentially, @rzo1 can add his final thoughts/checks then.

@@ -72,6 +72,13 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NishantShri4 Can we avoid AssertJ as extra dependency? I wonder, why assertions of JUnit 5.x are not sufficient?

*
* @param trainParams The {@link TrainingParameters} to use.
* @param reportMap The {@link Map} instance used as report map.
* @param config The {@link TrainingConfiguration} to use.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The training configuration should not be null at runtime, I guess?

Pls therefore add:
"Must not be {@code null}." to the parameter JavaDoc.

Same applies for different scenarios, pls re-iterate JavaDoc with that idea in mind.

*
* @param trainParams The {@link TrainingParameters} to use.
* @param reportMap The {@link Map} instance used as report map.
* @param config The {@link TrainingConfiguration} to use.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment for Trainer interface.

@@ -108,4 +124,12 @@ protected void addToReport(String key, String value) {
reportMap.put(key, value);
}

/**
* Retrieves the {@link TrainingConfiguration} associated with a {@link AbstractTrainer}.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should read "with an...", extra "n"

* and a null {@link opennlp.tools.monitoring.StopCriteria}.
* If not provided, the actual {@link opennlp.tools.monitoring.StopCriteria}
* will be decided by the {@link EventTrainer} implementation.
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls add specific parameter JavaDoc.
Pls add specific return value JavaDoc.

import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
import org.assertj.core.api.Assertions;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to eliminate dependance on org.assertj.core... here and elsewhere.

}

@ParameterizedTest()
@CsvSource( {"0.01,false", "-0.01,false", "0.00001,true", "-0.00001,true"})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a nice approach! 👍

.00002)));
}

@ParameterizedTest()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra brackets here, not required when no arguments are specified.

new TrainingParameters(Map.of(LOG_LIKELIHOOD_THRESHOLD_PARAM,5.)));
}

@ParameterizedTest()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra brackets here, not required when no arguments are specified.

@@ -180,6 +180,7 @@
<!-- Dependency versions -->
<junit.version>5.12.1</junit.version>
<junit5-system-exit.version>2.0.2</junit5-system-exit.version>
<assertj-core.version>3.27.3</assertj-core.version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid it, see comment(s) above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants