Package nltk :: Package tag :: Module sequential :: Class NgramTagger
[hide private]
[frames] | no frames]

YAMLObjectMetaclass NgramTagger

source code

         object --+            
                  |            
        api.TaggerI --+        
                      |        
SequentialBackoffTagger --+    
                          |    
              ContextTagger --+
                              |
                 object --+   |
                          |   |
            yaml.YAMLObject --+
                              |
                             NgramTagger
Known Subclasses:

A tagger that chooses a token's tag based on its word string and on the preceeding 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.

Nested Classes [hide private]

Inherited from yaml.YAMLObject: yaml_dumper, yaml_loader

Instance Methods [hide private]
 
__init__(self, n, train=None, model=None, backoff=None, cutoff=0, verbose=False)
Train a new NgramTagger using the given training data or the supplied model.
source code
(hashable)
context(self, tokens, index, history)
Returns: the context that should be used to look up the tag for the specified token; or None if the specified token should not be handled by this tagger.
source code

Inherited from ContextTagger: __repr__, choose_tag, size

Inherited from ContextTagger (private): _train

Inherited from SequentialBackoffTagger: tag, tag_one

Inherited from SequentialBackoffTagger (private): _get_backoff

Inherited from api.TaggerI: batch_tag, evaluate

Inherited from api.TaggerI (private): _check_params

Class Methods [hide private]

Inherited from yaml.YAMLObject: from_yaml, to_yaml

Class Variables [hide private]
  yaml_tag = '!nltk.NgramTagger'

Inherited from yaml.YAMLObject: yaml_flow_style

Instance Variables [hide private]

Inherited from ContextTagger (private): _context_to_tag

Inherited from SequentialBackoffTagger (private): _taggers

Properties [hide private]

Inherited from SequentialBackoffTagger: backoff

Method Details [hide private]

__init__(self, n, train=None, model=None, backoff=None, cutoff=0, verbose=False)
(Constructor)

source code 

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.
Overrides: SequentialBackoffTagger.__init__

context(self, tokens, index, history)

source code 
Returns: (hashable)
the context that should be used to look up the tag for the specified token; or None if the specified token should not be handled by this tagger.
Overrides: ContextTagger.context
(inherited documentation)