Class ChunkerME

Namespace
NOpenNLP.Tools.Chunker
Assembly
NOpenNLP.Tools.dll

The class represents a maximum-entropy-based chunker. Such a chunker can be used to find flat structures based on sequence inputs such as noun phrases or named entities.

public class ChunkerME : IChunker
Inheritance
ChunkerME
Implements
Inherited Members

Constructors

ChunkerME(ChunkerModel)

Initializes the current instance with the specified model. The default beam size is used.

public ChunkerME(ChunkerModel model)

Parameters

model ChunkerModel

Fields

DEFAULT_BEAM_SIZE

public const int DEFAULT_BEAM_SIZE = 10

Field Value

int

model

The model used to assign chunk tags to a sequence of tokens.

protected readonly ISequenceClassificationModel<TokenTag> model

Field Value

ISequenceClassificationModel<TokenTag>

Methods

Chunk(string[], string[])

Generates chunk tags for the given sequence returning the result in an array.

public virtual string[] Chunk(string[] toks, string[] tags)

Parameters

toks string[]

an array of the tokens or words of the sequence.

tags string[]

an array of the pos tags of the sequence.

Returns

string[]

an array of chunk tags for each token in the sequence.

ChunkAsSpans(string[], string[])

Generates tagged chunk spans for the given sequence returning the result in a span array.

public virtual Span[] ChunkAsSpans(string[] toks, string[] tags)

Parameters

toks string[]

an array of the tokens or words of the sequence.

tags string[]

an array of the pos tags of the sequence.

Returns

Span[]

an array of spans with chunk tags for each chunk in the sequence.

Probs()

Returns an array with the probabilities of the last decoded sequence. The sequence was determined based on the previous call to Chunk(string[], string[]).

public virtual double[] Probs()

Returns

double[]

An array with the same number of probabilities as tokens were sent to Chunk(string[], string[]) when it was last called.

Probs(double[])

Populates the specified array with the probabilities of the last decoded sequence. The sequence was determined based on the previous call to Chunk(string[], string[]). The specified array should be at least as large as the numbe of tokens in the previous call to Chunk(string[], string[]).

public virtual void Probs(double[] probs)

Parameters

probs double[]

An array used to hold the probabilities of the last decoded sequence.

TopKSequences(string[], string[])

Returns the top k chunk sequences for the specified sentence with the specified pos-tags

public virtual Sequence[] TopKSequences(string[] sentence, string[] tags)

Parameters

sentence string[]

The tokens of the sentence.

tags string[]

The pos-tags for the specified sentence.

Returns

Sequence[]

the top k chunk sequences for the specified sentence.

TopKSequences(string[], string[], double)

Returns the top k chunk sequences for the specified sentence with the specified pos-tags

public virtual Sequence[] TopKSequences(string[] sentence, string[] tags, double minSequenceScore)

Parameters

sentence string[]

The tokens of the sentence.

tags string[]

The pos-tags for the specified sentence.

minSequenceScore double

A lower bound on the score of a returned sequence.

Returns

Sequence[]

the top k chunk sequences for the specified sentence.

Train(string, IObjectStream<ChunkSample?>, TrainingParameters, ChunkerFactory)

Trains a model for the ChunkerME.

public static ChunkerModel Train(string lang, IObjectStream<ChunkSample?> @in, TrainingParameters mlParams, ChunkerFactory factory)

Parameters

lang string

the language code of the training data

in IObjectStream<ChunkSample>

the samples used for the training

mlParams TrainingParameters

the machine learning train parameters

factory ChunkerFactory

a ChunkerFactory to get resources from

Returns

ChunkerModel

the trained ChunkerModel

Exceptions

IOException

if reading from the IObjectStream<T> fails