Practical Exercises
Exercise 1: Tokenization with NLTK
Task: Use the nltk library to tokenize the following text: "Natural Language Processing enables computers to understand human language."
Solution:
from nltk.tokenize import word_tokenize
text = "Natural Language Processing enables computers to understand human language."
tokens = word_tokenize(text)
Output:
['Natural', 'Language', 'Processing', 'enables', 'computers', 'to', 'understand', 'human', 'language', '.']
Exercise 2: Named Entity Recognition with SpaCy
Task: Use the spaCy library to extract named entities from the text: "Google was founded by Larry Page and Sergey Brin while they were Ph.D. students at Stanford University." ...