Practical Exercises
Exercise 1: N-grams
Task: Generate trigrams (3-grams) from the following text: "Natural Language Processing with Python."
Solution:
text = "Natural Language Processing with Python"
# Tokenize the text into words
tokens = nltk.word_tokenize(text)
trigrams = ngrams(tokens, 3)
('Natural', 'Language', 'Processing')
('Language', 'Processing', 'with')
('Processing', 'with', 'Python')
Exercise 2: Bigram Language Model
Task: Train a bigram language model on the following text corpus and calculate the probability of the bigram ("Language", ...