0
0
NLPml~20 mins

RNN-based text generation in NLP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
RNN Text Generation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding RNN hidden state behavior
In an RNN used for text generation, what does the hidden state represent during training?
AIt contains the loss value used to update the model weights.
BIt holds the final output probabilities for the next character prediction.
CIt resets to zero after every character to avoid memory buildup.
DIt stores information about previous characters or words to influence future predictions.
Attempts:
2 left
💡 Hint
Think about how RNNs remember context from earlier inputs.
Predict Output
intermediate
2:00remaining
Output shape of RNN layer in text generation
What is the shape of the output tensor from an RNN layer when processing a batch of sequences with shape (batch_size=4, sequence_length=10, input_dim=8) and hidden size 16?
NLP
import torch
import torch.nn as nn
rnn = nn.RNN(input_size=8, hidden_size=16, batch_first=True)
inputs = torch.randn(4, 10, 8)
output, hidden = rnn(inputs)
print(output.shape)
Atorch.Size([10, 4, 16])
Btorch.Size([4, 10, 16])
Ctorch.Size([4, 16])
Dtorch.Size([4, 10, 8])
Attempts:
2 left
💡 Hint
Remember batch_first=True means batch is the first dimension.
Hyperparameter
advanced
2:00remaining
Choosing sequence length for training RNN text generation
Which sequence length is generally better for training an RNN text generator to capture long-term dependencies without causing too much memory use?
ASequence length does not affect RNN training or memory.
BVery long sequences (e.g., 1000 characters) to capture all context at once.
CModerate length sequences (e.g., 50-100 characters) balancing context and memory.
DVery short sequences (e.g., 5 characters) to speed up training.
Attempts:
2 left
💡 Hint
Think about the trade-off between context and computational resources.
Metrics
advanced
2:00remaining
Evaluating RNN text generation with perplexity
What does a lower perplexity score indicate when evaluating an RNN text generation model?
AThe model is more confident and accurate in predicting the next character or word.
BThe model is overfitting and memorizing the training data.
CThe model has a higher loss value during training.
DThe model is underfitting and not learning the data patterns.
Attempts:
2 left
💡 Hint
Perplexity measures how well the model predicts the next token.
🔧 Debug
expert
3:00remaining
Identifying cause of exploding gradients in RNN training
During training an RNN for text generation, the loss suddenly becomes NaN and the model weights explode. Which code snippet is the most likely cause?
NLP
optimizer = torch.optim.Adam(model.parameters(), lr=1.0)
for inputs, targets in dataloader:
    optimizer.zero_grad()
    outputs = model(inputs)
    loss = loss_fn(outputs, targets)
    loss.backward()
    optimizer.step()
AThe learning rate is too high (lr=1.0), causing unstable updates.
BThe optimizer.zero_grad() is missing before loss.backward().
CThe loss function is not differentiable, causing NaN gradients.
DThe model inputs are not normalized, causing exploding gradients.
Attempts:
2 left
💡 Hint
Check the learning rate value and its effect on training stability.