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, affix_length=3) >>> prefix_tagger.evaluate(test_sents) 0.23587308439456076
To learn on two-character suffixes, the code will look like this:
>>> suffix_tagger = AffixTagger(train_sents...