NLP: HMMs and Viterbi algorithm for POS tagging
You have learnt to build your own HMM-based POS tagger and implement the Viterbi algorithm using the Penn Treebank training corpus. The vanilla Viterbi algorithm we had written had resulted in ~87% accuracy. The approx. 13% loss of accuracy was majorly due to the fact that when the algorithm encountered an unknown word (i.e. not present in the training set, such as ‘Twitter’), it assigned an incorrect tag arbitrarily. This is because, for unknown words, the emission probabilities for all candidate tags are 0, so the algorithm arbitrarily chooses (the first) tag.
In this project, you need to modify the Viterbi algorithm to solve the problem of unknown words using at least two techniques. Though there could be multiple ways to solve this problem, you may use the following hints:
You have been given a ‘test’ file below containing some sample sentences with unknown words. Look at the sentences and try to observe rules which may be useful to tag unknown words. Your final model will be evaluated on a similar test file.
For this project, you’ll use the Treebank dataset of NLTK with the ‘universal’ tagset. The Universal tagset of NLTK comprises only 12 coarse tag classes as follows: Verb, Noun, Pronouns, Adjectives, Adverbs, Adpositions, Conjunctions, Determiners, Cardinal Numbers, Particles, Other/ Foreign words, Punctuations.
Note that using only 12 coarse classes (compared to the 46 fine classes such as NNP, VBD etc.) will make the Viterbi algorithm faster as well.
You can split the Treebank dataset into train and validation sets. Please use a sample size of 95:5 for training: validation sets, i.e. keep the validation size small, else the algorithm will need a very high amount of runtime.
You need to accomplish the following in this project:
You can download the Jupyter notebook from below. The dataset has been read and stored in the variable ‘nltk_data’. Use this notebook as your starter code.
Submission: You need to submit final Jupyter notebook with the required modifications for this project. Also, please show the two modification techniques separately (as two separate functions) to make it easier to evaluate.
If you are unable to view or load the jupyter IPython notebook via Github, please click on this link.
Thank you!