Class BeamSearch

java.lang.Object
opennlp.tools.ml.BeamSearch
All Implemented Interfaces:
AutoCloseable, SequenceClassificationModel

@ThreadSafe public class BeamSearch extends Object implements SequenceClassificationModel, AutoCloseable
Performs k-best search over a sequence.

This is based on the description in Ratnaparkhi (1998), PhD diss, Univ. of Pennsylvania.

This implementation is thread-safe. The contexts cache and probability buffer are maintained per-thread via ThreadLocal.

Note: In container environments with classloader isolation (e.g. Jakarta EE), ThreadLocal state may pin the classloader. Ensure instances do not outlive the application's lifecycle, or call ThreadLocal.remove() on pooled threads.

See Also:
  • Field Details

  • Constructor Details

    • BeamSearch

      public BeamSearch(int size, MaxentModel model)
      Initializes a BeamSearch instance.
      Parameters:
      size - The size of the beam (k).
      model - The MaxentModel for assigning probabilities to the sequence outcomes.
    • BeamSearch

      public BeamSearch(int size, MaxentModel model, int cacheSize)
      Initializes a BeamSearch instance with an optional per-thread contexts cache.
      Parameters:
      size - The size of the beam (k).
      model - The MaxentModel for assigning probabilities to the sequence outcomes.
      cacheSize - The capacity of the per-thread contexts cache. Use 0 to disable only that cache; per-thread score buffers are still allocated so evaluation stays thread-safe (see BeamSearch.CacheState).
  • Method Details