Class BeamSearch<T>
Performs k-best search over sequence. This is based on the description in Ratnaparkhi (1998), PhD diss, Univ. of Pennsylvania.
public class BeamSearch<T> : BeamSearch, ISequenceClassificationModel<T>
Type Parameters
T
- Inheritance
-
BeamSearch<T>
- Implements
- Inherited Members
Remarks
Constructors
BeamSearch(int, IMaxentModel, int)
Creates new search object.
public BeamSearch(int size, IMaxentModel model, int cacheSize = 0)
Parameters
sizeintThe size of the beam (k).
modelIMaxentModelthe model for assigning probabilities to the sequence outcomes.
cacheSizeint
Fields
model
protected readonly IMaxentModel model
Field Value
size
protected readonly int size
Field Value
Properties
Outcomes
Returns all possible outcomes.
public virtual string[] Outcomes { get; }
Property Value
- string[]
Methods
BestSequence(T[], object[]?, IBeamSearchContextGenerator<T>, ISequenceValidator<T>)
Finds the sequence with the highest probability.
public virtual Sequence? BestSequence(T[] sequence, object[]? additionalContext, IBeamSearchContextGenerator<T> cg, ISequenceValidator<T> validator)
Parameters
sequenceT[]additionalContextobject[]cgIBeamSearchContextGenerator<T>validatorISequenceValidator<T>
Returns
BestSequences(int, T[], object[]?, IBeamSearchContextGenerator<T>, ISequenceValidator<T>)
Finds the n most probable sequences.
public virtual Sequence[] BestSequences(int numSequences, T[] sequence, object[]? additionalContext, IBeamSearchContextGenerator<T> cg, ISequenceValidator<T> validator)
Parameters
numSequencesintsequenceT[]additionalContextobject[]cgIBeamSearchContextGenerator<T>validatorISequenceValidator<T>
Returns
- Sequence[]
BestSequences(int, T[], object[]?, double, IBeamSearchContextGenerator<T>, ISequenceValidator<T>)
Returns the best sequence of outcomes based on model for this object.
public virtual Sequence[] BestSequences(int numSequences, T[] sequence, object[]? additionalContext, double minSequenceScore, IBeamSearchContextGenerator<T> cg, ISequenceValidator<T> validator)
Parameters
numSequencesintsequenceT[]The input sequence.
additionalContextobject[]An Object[] of additional context. This is passed to the context generator blindly with the assumption that the context are appropiate.
minSequenceScoredoublecgIBeamSearchContextGenerator<T>validatorISequenceValidator<T>
Returns
- Sequence[]
The top ranked sequence of outcomes or null if no sequence could be found