Class BeamSearch<T>

Namespace
NOpenNLP.Tools.Ml
Assembly
NOpenNLP.Tools.dll

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

size int

The size of the beam (k).

model IMaxentModel

the model for assigning probabilities to the sequence outcomes.

cacheSize int

Fields

model

protected readonly IMaxentModel model

Field Value

IMaxentModel

size

protected readonly int size

Field Value

int

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

sequence T[]
additionalContext object[]
cg IBeamSearchContextGenerator<T>
validator ISequenceValidator<T>

Returns

Sequence

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

numSequences int
sequence T[]
additionalContext object[]
cg IBeamSearchContextGenerator<T>
validator ISequenceValidator<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

numSequences int
sequence T[]

The input sequence.

additionalContext object[]

An Object[] of additional context. This is passed to the context generator blindly with the assumption that the context are appropiate.

minSequenceScore double
cg IBeamSearchContextGenerator<T>
validator ISequenceValidator<T>

Returns

Sequence[]

The top ranked sequence of outcomes or null if no sequence could be found