Class ChunkerME
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
modelChunkerModel
Fields
DEFAULT_BEAM_SIZE
public const int DEFAULT_BEAM_SIZE = 10
Field Value
model
The model used to assign chunk tags to a sequence of tokens.
protected readonly ISequenceClassificationModel<TokenTag> model
Field Value
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
toksstring[]an array of the tokens or words of the sequence.
tagsstring[]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
toksstring[]an array of the tokens or words of the sequence.
tagsstring[]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
probsdouble[]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
sentencestring[]The tokens of the sentence.
tagsstring[]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
sentencestring[]The tokens of the sentence.
tagsstring[]The pos-tags for the specified sentence.
minSequenceScoredoubleA 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
langstringthe language code of the training data
inIObjectStream<ChunkSample>the samples used for the training
mlParamsTrainingParametersthe machine learning train parameters
factoryChunkerFactorya ChunkerFactory to get resources from
Returns
- ChunkerModel
the trained ChunkerModel
Exceptions
- IOException
if reading from the IObjectStream<T> fails