0
0
NLPml~10 mins

LSTM for text 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 LSTM layer from Keras.

NLP
from tensorflow.keras.layers import [1]
Drag options to blanks, or click blank then click option'
ADense
BLSTM
CConv2D
DDropout
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Dense or Conv2D instead of LSTM.
Forgetting to import LSTM from keras.layers.
2fill in blank
medium

Complete the code to add an LSTM layer with 50 units to the model.

NLP
model.add(LSTM([1]))
Drag options to blanks, or click blank then click option'
A10
B100
C50
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using too few units like 5 which may underfit.
Using too many units like 100 which may overfit or slow training.
3fill in blank
hard

Fix the error in the code to compile the model with categorical crossentropy loss.

NLP
model.compile(optimizer='adam', loss='[1]', metrics=['accuracy'])
Drag options to blanks, or click blank then click option'
Acategorical_crossentropy
Bbinary_crossentropy
Chinge
Dmean_squared_error
Attempts:
3 left
💡 Hint
Common Mistakes
Using binary_crossentropy for multi-class problems.
Using mean_squared_error which is for regression.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.

NLP
{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 the word itself as value instead of its length.
Using less than instead of greater than in the condition.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their counts if count is greater than 0.

NLP
{ [1]: [2] for [3], count in word_counts.items() if count > 0 }
Drag options to blanks, or click blank then click option'
Aword.upper()
Bcount
Cword
Dcount.upper()
Attempts:
3 left
💡 Hint
Common Mistakes
Using count.upper() which is invalid since count is a number.
Using word instead of word.upper() as key.