Practical Exercises
Exercise 1: Parts of Speech (POS) Tagging
Task: Perform POS tagging on the following sentence: "The quick brown fox jumps over the lazy dog."
Solution:
from nltk import word_tokenize, pos_tag
nltk.download('averaged_perceptron_tagger')
text = "The quick brown fox jumps over the lazy dog."
# Tokenize the text into words
tokens = word_tokenize(text)
pos_tags = pos_tag(tokens)
Output:
[('The', 'DT'), ('quick', 'JJ'), ('brown', 'JJ'), ('fox', 'NN'), ('jumps', 'VBZ'), ('over', 'IN'), ('the', 'DT'), ('lazy', 'JJ'), ('dog', 'NN'), ('.', '.')]
Exercise 2: Named Entity Recognition (NER)