Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the WordNetLemmatizer from nltk.
NLP
from nltk.stem import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing a stemmer class instead of a lemmatizer.
Misspelling the class name.
✗ Incorrect
The WordNetLemmatizer is the class used for lemmatization in nltk.
2fill in blank
mediumComplete the code to create a lemmatizer object.
NLP
lemmatizer = [1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to instantiate a class that does not exist.
Using stemmer classes instead.
✗ Incorrect
You create a lemmatizer by calling WordNetLemmatizer().
3fill in blank
hardFix the error in the code to lemmatize the word 'running'.
NLP
lemma = lemmatizer.[1]('running')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using stem() which is for stemming, not lemmatization.
Using tokenize() which splits text, not lemmatizes.
✗ Incorrect
The method to get the lemma of a word is lemmatize().
4fill in blank
hardFill both blanks to lemmatize the word 'better' as an adjective.
NLP
lemma = lemmatizer.[1]('better', pos=[2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not specifying the part of speech, so 'better' returns 'better' instead of 'good'.
Using pos='v' (verb) or pos='n' (noun) incorrectly.
✗ Incorrect
Use lemmatize() with pos='a' to lemmatize adjectives like 'better'.
5fill in blank
hardFill all three blanks to create a dictionary of words and their lemmas for nouns only.
NLP
words = ['cars', 'geese', 'mice'] lemmas = {word: lemmatizer.[1](word, pos=[2]) for word in words if word.endswith([3])}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not specifying pos='n' so lemmatization defaults to noun but may be ambiguous.
Filtering with wrong suffix like 'ing' which is for verbs.
✗ Incorrect
Use lemmatize() with pos='n' for nouns. The filter checks words ending with 's' to focus on plural nouns.