nltk.NgramTagger
¶
-
class
nltk.
NgramTagger
(n, train=None, model=None, backoff=None, cutoff=0, verbose=False)[source]¶ A tagger that chooses a token’s tag based on its word string and on the preceding n word’s tags. In particular, a tuple (tags[i-n:i-1], words[i]) is looked up in a table, and the corresponding tag is returned. N-gram taggers are typically trained on a tagged corpus.
Train a new NgramTagger using the given training data or the supplied model. In particular, construct a new tagger whose table maps from each context (tag[i-n:i-1], word[i]) to the most frequent tag for that context. But exclude any contexts that are already tagged perfectly by the backoff tagger.
Parameters: - train – A tagged corpus consisting of a list of tagged sentences, where each sentence is a list of (word, tag) tuples.
- backoff – A backoff tagger, to be used by the new tagger if it encounters an unknown context.
- cutoff – If the most likely tag for a context occurs fewer than cutoff times, then exclude it from the context-to-tag table for the new tagger.
Methods¶
__init__ (n[, train, model, backoff, cutoff, ...]) |
|||
choose_tag (tokens, index, history) |
|||
context (tokens, index, history) |
|||
decode_json_obj (obj) |
|||
encode_json_obj () |
|||
evaluate (gold) |
Score the accuracy of the tagger against the gold standard. | ||
size () |
|
||
tag (tokens) |
|||
tag_one (tokens, index, history) |
Determine an appropriate tag for the specified token, and return that tag. | ||
tag_sents (sentences) |
Apply self.tag() to each element of sentences. |
||
unicode_repr () |