0
0
ML Pythonml~10 mins

Why NLP processes human language in ML Python - Test Your Understanding

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

Complete the code to print a simple greeting using NLP.

ML Python
text = "Hello, world!"
print([1])
Drag options to blanks, or click blank then click option'
Aprint(text)
BText
Ctext
Dhello
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Text' instead of 'text' causes a NameError.
Putting print(text) inside print() prints the greeting followed by 'None'.
2fill in blank
medium

Complete the code to split a sentence into words using NLP.

ML Python
sentence = "I love learning NLP"
words = sentence.[1](' ')
print(words)
Drag options to blanks, or click blank then click option'
Afind
Bjoin
Creplace
Dsplit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'join' causes a TypeError because it expects an iterable.
Using 'replace' causes a TypeError because it requires two arguments.
3fill in blank
hard

Fix the error in the code to count word frequency.

ML Python
from collections import Counter
text = "NLP helps computers understand language"
words = text.split()
word_counts = Counter([1])
print(word_counts)
Drag options to blanks, or click blank then click option'
Awords
Btext
CCounter
Dsplit
Attempts:
3 left
💡 Hint
Common Mistakes
Passing 'text' counts characters, not words.
Passing 'Counter' or 'split' counts characters, not words.
4fill in blank
hard

Fill both blanks to create a dictionary of word lengths for words longer than 3 letters.

ML Python
words = ['chat', 'ai', 'language', 'data']
lengths = {word: [1] for word in words if len(word) [2] 3}
print(lengths)
Drag options to blanks, or click blank then click option'
Alen(word)
B<
C>
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' filters shorter words, not longer.
Using 'word' instead of len(word) gives wrong values.
5fill in blank
hard

Fill all three blanks to create a dictionary of uppercase words and their lengths for words shorter than 6 letters.

ML Python
words = ['hello', 'world', 'python', 'ai']
result = { [1]: [2] for w in words if len(w) [3] 6 }
print(result)
Drag options to blanks, or click blank then click option'
Aw.upper()
Blen(w)
C<
Dw
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' filters longer words, not shorter.
Using 'w' as key does not convert to uppercase.