0
0
NLPml~10 mins

Why machines need numerical text representation in NLP - Test Your Understanding

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

Complete the code to convert text into a list of words.

NLP
text = "Hello world"
words = text.[1]()
Drag options to blanks, or click blank then click option'
Asplit
Bjoin
Creplace
Dstrip
Attempts:
3 left
💡 Hint
Common Mistakes
Using join() instead of split(), which combines words instead of separating them.
2fill in blank
medium

Complete the code to convert words into their numerical indices using a dictionary.

NLP
word_to_index = {'hello': 1, 'world': 2}
indices = [word_to_index[[1]] for word in ['hello', 'world']]
Drag options to blanks, or click blank then click option'
Aword
Bindex
Cword_to_index
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using the dictionary name instead of the loop variable.
3fill in blank
hard

Fix the error in the code to convert text to lowercase before tokenizing.

NLP
text = "Hello World"
tokens = text.[1]().split()
Drag options to blanks, or click blank then click option'
Atitle
Bupper
Ccapitalize
Dlower
Attempts:
3 left
💡 Hint
Common Mistakes
Using upper() which makes letters uppercase, not lowercase.
4fill in blank
hard

Fill both blanks to create a dictionary mapping words to their lengths for words longer than 3 letters.

NLP
words = ['apple', 'cat', 'banana', 'dog']
lengths = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' causing wrong filtering.
5fill in blank
hard

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

NLP
words = ['apple', 'cat', 'banana', 'dog']
result = { [1]: [2] for w in words if len(w) [3] 6 }
Drag options to blanks, or click blank then click option'
Aw.upper()
Blen(w)
C<
Dw
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'w' instead of 'w.upper()' for keys.