krickert commented on code in PR #1003:
URL: https://github.com/apache/opennlp/pull/1003#discussion_r3058685400
##########
opennlp-core/opennlp-ml/opennlp-ml-commons/src/main/java/opennlp/tools/ml/BeamSearch.java:
##########
@@ -63,92 +84,82 @@ public BeamSearch(int size, MaxentModel model) {
}
/**
- * Initializes a {@link BeamSearch} instance.
+ * Initializes a {@link BeamSearch} instance with an optional per-thread
contexts cache.
*
* @param size The size of the beam (k).
* @param model The {@link MaxentModel} for assigning probabilities to the
sequence outcomes.
- * @param cacheSize The capacity of the {@link Cache} to use.
+ * @param cacheSize The capacity of the per-thread contexts cache. Use
{@code 0} to disable caching.
*/
public BeamSearch(int size, MaxentModel model, int cacheSize) {
this.size = size;
this.model = model;
-
- if (cacheSize > 0) {
- contextsCache = new Cache<>(cacheSize);
- }
-
- this.probs = new double[model.getNumOutcomes()];
+ this.cacheSize = cacheSize;
+ this.threadState = ThreadLocal.withInitial(
+ () -> new CacheState(model.getNumOutcomes(), cacheSize));
}
- /**
- * Computes the best sequence of outcomes based on the {@link MaxentModel}.
- *
- * @param numSequences The number of sequences.
- * @param sequence The input {@link T} sequence.
- * @param additionalContext An {@link Object[]} of additional context.
- * This is passed to the context generator blindly with the
- * assumption that the context are appropriate.
- * @param minSequenceScore The minimum sequence score to use.
- * @param cg The {@link BeamSearchContextGenerator context generator} to use.
- * @param validator The {@link SequenceValidator} to validate sequences.
- *
- * @return The top ranked {@link Sequence} of outcomes or {@code null}
- * if no sequence could be found.
- */
@Override
- public <T> Sequence[] bestSequences(int numSequences, T[] sequence,
- Object[] additionalContext, double minSequenceScore,
- BeamSearchContextGenerator<T> cg, SequenceValidator<T> validator) {
+ public <T> Sequence[] bestSequences(final int numSequences, final T[]
sequence,
Review Comment:
Agreed. The 6-arg `bestSequences` override now uses `{@inheritDoc}` so it
pulls the contract from `SequenceClassificationModel` instead of duplicating
the full param list. The 5-arg overload was already using `{@inheritDoc}`.
Same commit; no behavior change.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]