0
0
Prompt Engineering / GenAIml~10 mins

Hierarchical chunking in Prompt Engineering / GenAI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A5
B3
C10
D1
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.
2fill in blank
medium

Complete 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'
Achunk
Bchunks
Ctokens
Dflat_tokens
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.
3fill in blank
hard

Fix 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'
A2
B0
C-1
Dlen(chunk)
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.
4fill in blank
hard

Fill 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'
Achunk
Bchunks
Cchunk_size
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.
5fill in blank
hard

Fill 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'
Achunk
Dchunks
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.