Backoff tagging is one of the core features of SequentialBackoffTagger
. It allows you to chain taggers together so that if one tagger doesn't know how to tag a word, it can pass the word on to the next backoff tagger. If that one can't do it, it can pass the word on to the next backoff tagger, and so on until there are no backoff taggers left to check.
Every subclass of SequentialBackoffTagger
can take a backoff keyword argument whose value is another instance of a SequentialBackoffTagger
. So, we'll use the DefaultTagger
class from the Default tagging recipe in this chapter as the backoff to the UnigramTagger
class covered in the previous recipe, Training a unigram part-of-speech tagger. Refer to both the recipes for details on train_sents
and test_sents
.
>>> tagger1 = DefaultTagger('NN') >>> tagger2 = UnigramTagger(train_sents, backoff=tagger1) >>> tagger2.evaluate(test_sents) 0.8758471832505935
By using a default...