Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a hierarchical chunk from a list of tokens.
Prompt Engineering / GenAI
chunks = [tokens[i:i+[1]] for i in range(0, len(tokens), [1])]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 creates chunks of single tokens, which is not hierarchical.
Using 10 might create too large chunks losing detail.
✗ Incorrect
Using 3 as the chunk size divides the tokens into smaller groups of 3, which is a common choice for hierarchical chunking.
2fill in blank
mediumComplete the code to flatten a list of hierarchical chunks back into tokens.
Prompt Engineering / GenAI
flat_tokens = [token for chunk in chunks for token in [1]]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'chunks' instead of 'chunk' causes an error because 'chunks' is the outer list.
Using 'tokens' is incorrect because it is the original list, not the chunk variable.
✗ Incorrect
We iterate over each chunk and then each token inside that chunk to flatten the list.
3fill in blank
hardFix the error in the code to create nested hierarchical chunks.
Prompt Engineering / GenAI
nested_chunks = [[chunk[i:i+[1]] for i in range(0, len(chunk), [1])] for chunk in chunks]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or negative numbers causes runtime errors.
Using len(chunk) creates sub-chunks equal to the whole chunk, no nesting.
✗ Incorrect
Using 2 as the inner chunk size creates smaller sub-chunks inside each chunk, enabling nested hierarchy.
4fill in blank
hardFill both blanks to create a dictionary mapping chunk indices to their sizes.
Prompt Engineering / GenAI
chunk_sizes = {i: len([1]) for i, [2] in enumerate(chunks)} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'chunks' inside len() causes an error because it's the whole list.
Using different variable names inconsistently causes confusion.
✗ Incorrect
We use 'chunk' to represent each chunk in the dictionary comprehension and in the enumeration.
5fill in blank
hardFill all three blanks to filter chunks with size greater than 2 and create a summary dictionary.
Prompt Engineering / GenAI
summary = {i: len([1]) for i, [2] in enumerate(chunks) if len([3]) > 2} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'chunks' inside len() causes errors because it's the whole list.
Using inconsistent variable names causes syntax errors.
✗ Incorrect
All blanks refer to the current chunk variable to measure its length and filter accordingly.