NgramTagger has 3 subclasses
BigramTagger subclass uses previous tag as part of its context
TrigramTagger subclass uses the previous two tags as part of its context.
ngram – It is a subsequence of n items.
Idea of NgramTagger subclasses :
- By looking at the previous words and P-O-S tags, part-of-speech tag for the current word can be guessed.
- Each tagger maintains a context dictionary (ContextTagger parent class is used to implement it).
- This dictionary is used to guess that tag based on the context.
- The context is some number of previous tagged words in the case of NgramTagger subclasses.
Code #1 : Working of Bigram tagger
Code #2 : Working of Trigram tagger
Code #3 : Collectively using Unigram, Bigram and Trigram tagger.
How it works ?
- The backoff_tagger function creates an instance of each tagger class.
- It gives previous tagger and train_sents as a backoff.
- The order of tagger classes is important: In the code above the first class is UnigramTagger and hence, it will be trained first and given the initial backoff tagger (the DefaultTagger).
- This tagger then becomes the backoff tagger for the next tagger class.
- Final tagger returned will be an instance of the last tagger class – TrigramTagger.
Code #4 : Proof
True True True
- NLP | Backoff Tagging to combine taggers
- Python | Combining two sorted lists
- Python | Combining values from dictionary of list
- Combining IoT and Machine Learning makes our future smarter
- Combining multiple columns in Pandas groupby with dictionary
- Python | Combining tuples in list of tuples
- ML | BIRCH Clustering
- What is AI(Artificial Intelligence)?
- Python program to convert any base to decimal by using int() method
- Check whether count of odd and even factors of a number are equal
- What is Information Retrieval?
- What is IBM Watson and Its Services?
- wxPython - ClearFocusedItem() method in wx.TreeCtrl
- wxPython - Collapse() method wx.TreeCtrl
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : shubham_singh