class nltk.ContextTagger(context_to_tag, backoff=None)[source]

An abstract base class for sequential backoff taggers that choose a tag for a token based on the value of its “context”. Different subclasses are used to define different contexts.

A ContextTagger chooses the tag for a token by calculating the token’s context, and looking up the corresponding tag in a table. This table can be constructed manually; or it can be automatically constructed based on a training corpus, using the _train() factory method.

Variables:_context_to_tag – Dictionary mapping contexts to tags.


__init__(context_to_tag[, backoff])
param context_to_tag:
 A dictionary mapping contexts to tags.
choose_tag(tokens, index, history)
context(tokens, index, history)
return:the context that should be used to look up the tag
evaluate(gold) Score the accuracy of the tagger against the gold standard.
return:The number of entries in the table used by this
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.


backoff The backoff tagger for this tagger.