0
0
NLPml~10 mins

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

NLP
from tensorflow.keras.layers import [1]
Drag options to blanks, or click blank then click option'
ADense
BSimpleRNN
CConv2D
DMaxPooling2D
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing Dense which is a fully connected layer, not recurrent.
Choosing Conv2D or MaxPooling2D which are for images.
2fill in blank
medium

Complete the code to add an embedding layer for text input.

NLP
model.add(Embedding(input_dim=[1], output_dim=64, input_length=100))
Drag options to blanks, or click blank then click option'
A100
B64
C10
D5000
Attempts:
3 left
💡 Hint
Common Mistakes
Using input_dim equal to output_dim or input_length.
Choosing a very small number like 10 which is too small for vocab size.
3fill in blank
hard

Fix the error in the RNN layer definition to return the last output only.

NLP
model.add(SimpleRNN(32, return_sequences=[1]))
Drag options to blanks, or click blank then click option'
AFalse
BTrue
CNone
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Setting return_sequences=True which outputs the full sequence.
Using None or 0 which are invalid values for this parameter.
4fill in blank
hard

Fill both blanks to compile the model with appropriate loss and optimizer for binary classification.

NLP
model.compile(loss=[1], optimizer=[2], metrics=['accuracy'])
Drag options to blanks, or click blank then click option'
A'binary_crossentropy'
B'categorical_crossentropy'
C'adam'
D'sgd'
Attempts:
3 left
💡 Hint
Common Mistakes
Using categorical_crossentropy for binary classification.
Using sgd optimizer which may be slower to converge.
5fill in blank
hard

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

NLP
word_lengths = { [1] : [2] for [3] in words if len([3]) > 3 }
Drag options to blanks, or click blank then click option'
Aword
Blen(word)
Dlen(words)
Attempts:
3 left
💡 Hint
Common Mistakes
Using len(words) which is the length of the list, not each word.
Using inconsistent variable names in the comprehension.