Practice
1. Given the following Python code using BPE tokenization, what is the output?
from tokenizers import Tokenizer
from tokenizers.models import BPE
from tokenizers.pre_tokenizers import Whitespace
# Initialize a BPE tokenizer
bpe_tokenizer = Tokenizer(BPE())
bpe_tokenizer.pre_tokenizer = Whitespace()
# Train the tokenizer
bpe_tokenizer.train(["hello world", "hello there"], vocab_size=10)
# Encode a sentence
output = bpe_tokenizer.encode("hello world")
print(output.tokens)easy
Solution
Step 1: Understand BPE tokenization with whitespace pre-tokenization.
BPE with whitespace pre-tokenization will initially split on spaces.Step 2: Analyze the output of the encode method.
The sentence 'hello world' is tokenized as ['hello', 'world'] due to whitespace splitting.Final Answer:
Option D -> Option DQuick Check:
BPE with whitespace splits on spaces first. [OK]
Hint: BPE with whitespace splits on spaces first. [OK]
Common Mistakes:
2. In a scenario where computational resources are limited, which approach is more suitable for hyperparameter tuning and why?
medium
Solution
Step 1: Evaluate resource constraints
Cross-validation is computationally expensive but provides robust tuning.Step 2: Eliminate less suitable options
Use a single train-test split to save resources. risks overfitting. Use a train-validation split and skip the test set. skips the test set, risking unseen data performance. Use a larger test set to ensure model generalization. misallocates resources to testing rather than tuning.Final Answer:
Option C -> Option CQuick Check:
Cross-validation ensures robust tuning despite cost. [OK]
Hint: Cross-validation ensures robust tuning despite cost. [OK]
Common Mistakes:
3. When monitoring an ML model in production, which approach is better for detecting data drift and why?
medium
Solution
Step 1: Identify effective drift detection
Monitoring statistical properties helps detect subtle changes in input data.Step 2: Eliminate wrong options
Use a static threshold on model accuracy. is reactive, not proactive. Rely on user feedback to identify issues. is unreliable and subjective. Increase the frequency of model retraining. addresses performance decay, not drift detection.Final Answer:
Option A -> Option AQuick Check:
Monitor input stats for drift detection [OK]
Hint: Monitor input stats for drift detection [OK]
Common Mistakes:
4. In a dataset with highly correlated features, which regularization technique is preferable and why?
medium
Solution
Step 1: Identify the issue with correlated features.
Highly correlated features can cause instability in L1 Lasso.Step 2: Choose the technique that addresses this.
Elastic Net combines L1 and L2, providing stability and feature selection.Step 3: Eliminate wrong options.
L1 Lasso struggles with multicollinearity. L2 Ridge does not select features. No regularization ignores the problem.Final Answer:
Option A -> Option AQuick Check:
Elastic Net = L1 + L2 for correlation. [OK]
Hint: Elastic Net = L1 + L2 for correlation. [OK]
Common Mistakes:
5. You need to design a recurrent neural network for a real-time translation system. Which approach would best handle the vanishing gradient problem while maintaining low latency?
hard
Solution
Step 1: Consider latency and vanishing gradient.
GRUs are simpler and faster, reducing latency while handling vanishing gradients.Step 2: Evaluate other options.
Deep LSTM (A) increases latency, standard RNN (C) struggles with gradients, bidirectional LSTM (D) adds complexity and latency.Final Answer:
Option B -> Option BQuick Check:
GRU: fast, handles vanishing gradients. [check]
Hint: GRU: fast, handles vanishing gradients. [check]
Common Mistakes:
