0
0
NLPml~10 mins

Lowercasing and normalization 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 convert the text to lowercase.

NLP
text = "Hello World!"
lower_text = text.[1]()
Drag options to blanks, or click blank then click option'
Alower
Bupper
Ccapitalize
Dtitle
Attempts:
3 left
💡 Hint
Common Mistakes
Using upper() instead of lower()
Using capitalize() which only changes the first letter
2fill in blank
medium

Complete the code to remove leading and trailing spaces from the text.

NLP
text = "  Hello World!  "
clean_text = text.[1]()
Drag options to blanks, or click blank then click option'
Areplace
Bsplit
Cstrip
Djoin
Attempts:
3 left
💡 Hint
Common Mistakes
Using split() which splits the string into words
Using replace() which replaces characters inside the string
3fill in blank
hard

Fix the error in the code to normalize the text by removing punctuation.

NLP
import string
text = "Hello, World!"
normalized = text.translate(str.maketrans('', '', [1]))
Drag options to blanks, or click blank then click option'
Astring.punctuation
Bstring.whitespace
Cstring.ascii_letters
Dstring.digits
Attempts:
3 left
💡 Hint
Common Mistakes
Using string.whitespace which removes spaces instead
Using string.ascii_letters which removes letters
4fill in blank
hard

Fill both blanks to create a dictionary that maps words to their lowercase forms, filtering out words shorter than 4 letters.

NLP
words = ["Apple", "is", "Good", "for", "You"]
lower_map = {word[1]: word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
A.lower()
B>
C>=
D.upper()
Attempts:
3 left
💡 Hint
Common Mistakes
Using .upper() instead of .lower()
Using '>=' instead of '>' which changes the filter condition
5fill in blank
hard

Fill all three blanks to create a normalized frequency dictionary of lowercase words longer than 2 letters.

NLP
texts = ["Hello", "world", "HELLO", "test"]
freq = {}
for word in texts:
    w = word[1]
    if len(w) [2] 2:
        freq[w] = freq.get(w, 0) [3] 1
Drag options to blanks, or click blank then click option'
A.lower()
B>
C+
D-
E*
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' or '*' instead of '+' for counting
Using '>=' instead of '>' changing the filter