0
0
NLPml~10 mins

Part-of-speech tagging in NLP - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the NLTK library for part-of-speech tagging.

NLP
import nltk

text = "I love learning AI"
tokens = nltk.word_tokenize(text)
pos_tags = nltk.[1](tokens)
print(pos_tags)
Drag options to blanks, or click blank then click option'
AposTag
Btag_pos
Ctagger
Dpos_tag
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong function name like tag_pos or posTag.
Forgetting to tokenize the text before tagging.
2fill in blank
medium

Complete the code to tokenize the sentence before tagging.

NLP
sentence = "She enjoys reading books"
tokens = [1](sentence)
print(tokens)
Drag options to blanks, or click blank then click option'
Asentence.split
Bsentence.tokenize
Cnltk.word_tokenize
Dnltk.tokenize_words
Attempts:
3 left
💡 Hint
Common Mistakes
Using sentence.split which does not handle punctuation well.
Using a non-existent function like sentence.tokenize.
3fill in blank
hard

Fix the error in the code to correctly tag the tokens.

NLP
tokens = ['They', 'are', 'playing', 'football']
pos_tags = nltk.pos_tag([1])
print(pos_tags)
Drag options to blanks, or click blank then click option'
Atokens()
Btokens
Ctokens[]
Dtoken
Attempts:
3 left
💡 Hint
Common Mistakes
Calling tokens as a function with parentheses.
Using incorrect syntax like tokens[].
4fill in blank
hard

Fill both blanks to create a dictionary of words and their POS tags.

NLP
tokens = ['He', 'runs', 'fast']
pos_tags = nltk.pos_tag(tokens)
pos_dict = [1](pos_tags)
print(pos_dict)

# Access the POS tag of 'runs'
print(pos_dict[[2]])
Drag options to blanks, or click blank then click option'
Adict
B'runs'
C'fast'
Dlist
Attempts:
3 left
💡 Hint
Common Mistakes
Using list() instead of dict() to convert.
Accessing dictionary with wrong key like 'fast'.
5fill in blank
hard

Fill the blanks to filter and print only nouns from the tagged tokens.

NLP
tokens = nltk.word_tokenize("Dogs bark loudly at night")
pos_tags = nltk.pos_tag(tokens)
nouns = [word for word, tag in pos_tags if tag [1] [2]]
print(nouns)

# Expected output: ['Dogs', 'night']
Drag options to blanks, or click blank then click option'
A==
Bin
CNN
D['NN', 'NNS']
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' to compare tag with a list (causes error).
Using wrong tag names or not filtering nouns.