Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing Dense which is a fully connected layer, not recurrent.
Choosing Conv2D or MaxPooling2D which are for images.
✗ Incorrect
The SimpleRNN layer is the basic recurrent neural network layer used for sequence data like text.
2fill in blank
mediumComplete 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'
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.
✗ Incorrect
input_dim is the size of the vocabulary, typically a larger number like 5000 for text.
3fill in blank
hardFix 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'
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.
✗ Incorrect
return_sequences=False makes the RNN output only the last output, suitable for classification.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using categorical_crossentropy for binary classification.
Using sgd optimizer which may be slower to converge.
✗ Incorrect
For binary classification, use 'binary_crossentropy' loss and 'adam' optimizer for good performance.
5fill in blank
hardFill 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'
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.
✗ Incorrect
The comprehension maps each word to its length if the word length is greater than 3.