0
0
NLPml~10 mins

RNN-based text generation 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 TensorFlow Keras.

NLP
from tensorflow.keras.layers import [1]
Drag options to blanks, or click blank then click option'
ASimpleRNN
BDense
CConv2D
DMaxPooling2D
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Dense instead of SimpleRNN
Confusing convolutional layers with RNN layers
2fill in blank
medium

Complete the code to define an RNN model with an embedding layer and a SimpleRNN layer.

NLP
model = Sequential([
    Embedding(input_dim=1000, output_dim=64),
    [1](128),
    Dense(1000, activation='softmax')
])
Drag options to blanks, or click blank then click option'
AConv1D
BDropout
CLSTM
DSimpleRNN
Attempts:
3 left
💡 Hint
Common Mistakes
Using Conv1D instead of a recurrent layer
Using Dropout where a recurrent layer is needed
3fill in blank
hard

Fix the error in the code to compile the RNN model for text generation.

NLP
model.compile(optimizer='adam', loss=[1], metrics=['accuracy'])
Drag options to blanks, or click blank then click option'
A'categorical_crossentropy'
B'hinge'
C'binary_crossentropy'
D'mse'
Attempts:
3 left
💡 Hint
Common Mistakes
Using binary_crossentropy for multi-class output
Using mse which is for regression tasks
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_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 the word itself as the 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 only if count is greater than 0.

NLP
result = { [1]: [2] for word, count in word_counts.items() if count [3] 0 }
Drag options to blanks, or click blank then click option'
Aword.upper()
Bcount
C>
Dword.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using word.lower() instead of word.upper()
Using less than instead of greater than in the condition