Practice
1.
import torch
optimizer = torch.optim.SGD(model.parameters(), lr=0.1)
for epoch in range(10):
for data, target in dataloader:
optimizer.zero_grad()
output = model(data)
loss = loss_fn(output, target)
loss.backward()
optimizer.step()
print(optimizer.param_groups[0]['lr'])What will be printed after the loop?easy
Solution
Step 1: Understand the code.
The learning rate is set to 0.1 and not changed in the loop.Step 2: Check for learning rate updates.
SGD without a scheduler keeps the learning rate constant.Final Answer:
Option C -> Option CQuick Check:
SGD without scheduler keeps lr constant. [check]
Hint: SGD without scheduler keeps lr constant. [check]
Common Mistakes:
2. Given the following Python code snippet, what will be the output if the model is trained with biased data?
from sklearn.metrics import accuracy_score
y_true = [0, 1, 1, 0, 1]
y_pred = [0, 1, 1, 0, 0]
accuracy = accuracy_score(y_true, y_pred)
print(accuracy)easy
Solution
Step 1: Calculate the accuracy.
Accuracy is the ratio of correctly predicted instances to the total instances. Here, 3 out of 5 predictions are correct.Step 2: Compute the accuracy.
Correct predictions: [0, 1, 1] -> 0.6Final Answer:
0.6 -> 0.6Quick Check:
Count correct predictions, divide by total. [OK]
Hint: Count correct predictions, divide by total. [OK]
Common Mistakes:
3. When choosing between BPE and WordPiece for a language model, which scenario makes WordPiece a better choice?
medium
Solution
Step 1: Identify the strengths of WordPiece.
WordPiece is designed to handle rare words efficiently by breaking them into subwords.Step 2: Eliminate wrong options.
Minimizing vocabulary size (A) and handling inflection (B) are not specific strengths of WordPiece; text generation (D) is not a specific advantage.Final Answer:
Option C -> Option CQuick Check:
WordPiece excels with rare words. [OK]
Hint: WordPiece excels with rare words. [OK]
Common Mistakes:
4. In a real-time prediction system, how should you handle data splits to ensure both model performance and system efficiency?
hard
Solution
Step 1: Consider real-time constraints
Real-time systems need to adapt to new data while maintaining performance.Step 2: Evaluate options for adaptability and efficiency
Use a single train-test split to minimize latency. risks overfitting. Use a large test set to ensure model robustness. misallocates resources. Use a static validation set to simplify the system. lacks adaptability to new data.Final Answer:
Option D -> Option DQuick Check:
Rolling window adapts to new data efficiently. [OK]
Hint: Rolling window adapts to new data efficiently. [OK]
Common Mistakes:
5. You need to train a model with a learning rate that decreases over time. Which approach would best suit this requirement?
hard
Solution
Step 1: Identify the requirement.
The requirement is for a learning rate that decreases over time.Step 2: Match the requirement to the solution.
A learning rate scheduler with SGD allows for controlled decrease over time.Final Answer:
Option D -> Option DQuick Check:
Scheduler with SGD for decreasing lr. [check]
Hint: Scheduler with SGD for decreasing lr. [check]
Common Mistakes:
