Package opennlp.tools.ml
Class BeamSearch<T>
- java.lang.Object
-
- opennlp.tools.ml.BeamSearch<T>
-
- All Implemented Interfaces:
SequenceClassificationModel<T>
public class BeamSearch<T> extends Object implements SequenceClassificationModel<T>
Performs k-best search over a sequence.This is based on the description in Ratnaparkhi (1998), PhD diss, Univ. of Pennsylvania.
- See Also:
Sequence,SequenceValidator,BeamSearchContextGenerator
-
-
Field Summary
Fields Modifier and Type Field Description static StringBEAM_SIZE_PARAMETER
-
Constructor Summary
Constructors Constructor Description BeamSearch(int size, MaxentModel model)Initializes aBeamSearchinstance.BeamSearch(int size, MaxentModel model, int cacheSize)Initializes aBeamSearchinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SequencebestSequence(T[] sequence, Object[] additionalContext, BeamSearchContextGenerator<T> cg, SequenceValidator<T> validator)Computes the best sequence of outcomes based on theMaxentModel.Sequence[]bestSequences(int numSequences, T[] sequence, Object[] additionalContext, double minSequenceScore, BeamSearchContextGenerator<T> cg, SequenceValidator<T> validator)Computes the best sequence of outcomes based on theMaxentModel.Sequence[]bestSequences(int numSequences, T[] sequence, Object[] additionalContext, BeamSearchContextGenerator<T> cg, SequenceValidator<T> validator)Computes the best sequence of outcomes based on theMaxentModel.String[]getOutcomes()
-
-
-
Field Detail
-
BEAM_SIZE_PARAMETER
public static final String BEAM_SIZE_PARAMETER
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BeamSearch
public BeamSearch(int size, MaxentModel model)Initializes aBeamSearchinstance.- Parameters:
size- The size of the beam (k).model- TheMaxentModelfor assigning probabilities to the sequence outcomes.
-
BeamSearch
public BeamSearch(int size, MaxentModel model, int cacheSize)Initializes aBeamSearchinstance.- Parameters:
size- The size of the beam (k).model- TheMaxentModelfor assigning probabilities to the sequence outcomes.cacheSize- The capacity of theCacheto use.
-
-
Method Detail
-
bestSequences
public Sequence[] bestSequences(int numSequences, T[] sequence, Object[] additionalContext, double minSequenceScore, BeamSearchContextGenerator<T> cg, SequenceValidator<T> validator)
Computes the best sequence of outcomes based on theMaxentModel.- Specified by:
bestSequencesin interfaceSequenceClassificationModel<T>- Parameters:
numSequences- The number of sequences.sequence- The inputBeamSearchsequence.additionalContext- AnObjectof additional context. This is passed to the context generator blindly with the assumption that the context are appropriate.minSequenceScore- The minimum sequence score to use.cg- Thecontext generatorto use.validator- TheSequenceValidatorto validate sequences.- Returns:
- The top ranked
Sequenceof outcomes ornullif no sequence could be found.
-
bestSequences
public Sequence[] bestSequences(int numSequences, T[] sequence, Object[] additionalContext, BeamSearchContextGenerator<T> cg, SequenceValidator<T> validator)
Computes the best sequence of outcomes based on theMaxentModel.- Specified by:
bestSequencesin interfaceSequenceClassificationModel<T>- Parameters:
numSequences- The number of sequences.sequence- The inputBeamSearchsequence.additionalContext- AnObjectof additional context. This is passed to the context generator blindly with the assumption that the context are appropriate.cg- Thecontext generatorto use.validator- TheSequenceValidatorto validate sequences.- Returns:
- The top ranked
Sequenceof outcomes ornullif no sequence could be found.
-
bestSequence
public Sequence bestSequence(T[] sequence, Object[] additionalContext, BeamSearchContextGenerator<T> cg, SequenceValidator<T> validator)
Computes the best sequence of outcomes based on theMaxentModel.- Specified by:
bestSequencein interfaceSequenceClassificationModel<T>- Parameters:
sequence- The inputBeamSearchsequence.additionalContext- AnObjectof additional context. This is passed to the context generator blindly with the assumption that the context are appropriate.cg- Thecontext generatorto use.validator- TheSequenceValidatorto validate sequences.- Returns:
- The top ranked
Sequenceof outcomes ornullif no sequence could be found.
-
getOutcomes
public String[] getOutcomes()
- Specified by:
getOutcomesin interfaceSequenceClassificationModel<T>- Returns:
- Retrieves all possible outcomes.
-
-