Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to split text into chunks of fixed size for context window processing.
NLP
def split_text(text, chunk_size): return [text[i:i+[1]] for i in range(0, len(text), chunk_size)]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the entire text length instead of chunk size.
Using the loop variable i as the slice size.
✗ Incorrect
The chunk size determines the length of each text segment for the context window.
2fill in blank
mediumComplete the code to create overlapping context windows with a given stride.
NLP
def sliding_windows(text, window_size, stride): return [text[i:i+window_size] for i in range(0, len(text) - window_size + 1, [1])]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using window size as the step, which causes no overlap.
Using the loop variable i as the step size.
✗ Incorrect
The stride controls how much the window moves forward each step, allowing overlap.
3fill in blank
hardFix the error in the code that tries to pad a context window to a fixed size.
NLP
def pad_window(window, fixed_size, pad_token): if len(window) < fixed_size: window += [1] * (fixed_size - len(window)) return window
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to add the window to itself instead of padding.
Using fixed_size or length as the padding token.
✗ Incorrect
Padding uses the pad_token repeated to fill the window to fixed size.
4fill in blank
hardFill both blanks to create a dictionary mapping each chunk to its start index in the text.
NLP
def chunk_indices(text, chunk_size): return {text[i:i+[1]]: i for i in range(0, len(text), [2])}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different values for slice length and step size causing errors.
Using half chunk size for step causing overlapping.
✗ Incorrect
Both blanks use chunk_size: slice length and step size for non-overlapping chunks.
5fill in blank
hardFill all three blanks to filter chunks longer than min_length and map them to their lengths.
NLP
def filter_chunks(chunks, min_length): return {chunk: len(chunk) for chunk in chunks if len(chunk) [1] [2] and chunk [3] ''}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using == instead of != to check for non-empty strings.
Using < instead of > for length comparison.
✗ Incorrect
Filter chunks longer than min_length and not empty strings.