August 2014
Beginner to intermediate
304 pages
7h 10m
English
The AffixTagger class is another ContextTagger subclass, but this time the context is either the prefix or the suffix of a word. This means the AffixTagger class is able to learn tags based on fixed-length substrings of the beginning or ending of a word.
The default arguments for an AffixTagger class specify three-character suffixes, and that words must be at least five characters long. If a word is less than five characters, then None is returned as the tag.
>>> from nltk.tag import AffixTagger >>> tagger = AffixTagger(train_sents) >>> tagger.evaluate(test_sents) 0.27558817181092166
So, it does ok by itself with the default arguments. Let's try it by specifying three-character prefixes.
>>> prefix_tagger = AffixTagger(train_sents, ...
Read now
Unlock full access