0
0
NLPml~20 mins

Context window handling in NLP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Context Window Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding context window size impact

In natural language processing, what is the main effect of increasing the context window size when training a language model?

AThe model can consider more words at once, improving understanding of long-range dependencies.
BThe model trains faster because it processes fewer tokens per batch.
CThe model reduces memory usage by limiting the number of tokens it stores.
DThe model ignores earlier words and focuses only on the last few tokens.
Attempts:
2 left
💡 Hint

Think about how much text the model can see at once.

Predict Output
intermediate
2:00remaining
Output of sliding window tokenization

What is the output of the following Python code that simulates a sliding context window over tokens?

NLP
tokens = ['I', 'love', 'machine', 'learning', 'and', 'AI']
window_size = 3
windows = [tokens[i:i+window_size] for i in range(len(tokens) - window_size + 1)]
print(windows)
A[['I', 'love', 'machine', 'learning'], ['love', 'machine', 'learning', 'and'], ['machine', 'learning', 'and', 'AI']]
B[['I', 'love', 'machine'], ['machine', 'learning', 'and'], ['love', 'machine', 'learning'], ['learning', 'and', 'AI']]
C[['I', 'love'], ['love', 'machine'], ['machine', 'learning'], ['learning', 'and'], ['and', 'AI']]
D[['I', 'love', 'machine'], ['love', 'machine', 'learning'], ['machine', 'learning', 'and'], ['learning', 'and', 'AI']]
Attempts:
2 left
💡 Hint

Look at how the list comprehension slices the tokens with a fixed window size.

Model Choice
advanced
2:00remaining
Choosing model type for long context handling

You want to build a model that can understand very long documents (thousands of words). Which model architecture is best suited to handle such long context windows efficiently?

ATransformer with sparse attention or memory-augmented mechanisms
BRecurrent Neural Network (RNN) with truncated backpropagation
CStandard Transformer with fixed 512-token context window
DFeedforward neural network without sequence modeling
Attempts:
2 left
💡 Hint

Consider models designed to reduce computation for long sequences.

Hyperparameter
advanced
2:00remaining
Effect of context window size on training time

How does increasing the context window size affect the training time of a Transformer-based language model?

ATraining time decreases because the model sees more tokens at once.
BTraining time increases roughly quadratically with context window size.
CTraining time remains constant regardless of context window size.
DTraining time increases linearly with context window size.
Attempts:
2 left
💡 Hint

Think about how attention computation scales with sequence length.

🔧 Debug
expert
2:00remaining
Identifying error in context window implementation

What error does the following code raise when trying to create context windows, and why?

tokens = ['a', 'b', 'c']
window_size = 4
windows = [tokens[i:i+window_size] for i in range(len(tokens) - window_size + 1)]
print(windows)
AIndexError because slicing goes beyond the list length.
BValueError because window_size must be less than tokens length.
CEmpty list because the range is negative, so no windows are created.
DTypeError because window_size is larger than tokens length.
Attempts:
2 left
💡 Hint

Check what happens when the range argument is negative.