0
0
Prompt Engineering / GenAIml~10 mins

Top-p and top-k sampling 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 set the top-k value for sampling.

Prompt Engineering / GenAI
top_k = [1]
Drag options to blanks, or click blank then click option'
A0.9
B50
C1000
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using a float value like 0.9 for top-k instead of an integer.
Setting top-k to None disables it, not sets a value.
2fill in blank
medium

Complete the code to set the top-p value for nucleus sampling.

Prompt Engineering / GenAI
top_p = [1]
Drag options to blanks, or click blank then click option'
A50
B100
C0.9
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using an integer like 50 for top-p instead of a float.
Setting top-p to None disables it, not sets a value.
3fill in blank
hard

Fix the error in the code to apply top-k sampling correctly.

Prompt Engineering / GenAI
output = model.generate(input_ids, do_sample=True, top_k=[1])
Drag options to blanks, or click blank then click option'
ATrue
BNone
C0.9
D50
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a float like 0.9 causes an error.
Passing None disables top-k but does not apply sampling.
4fill in blank
hard

Fill both blanks to apply top-p and top-k sampling together.

Prompt Engineering / GenAI
output = model.generate(input_ids, do_sample=True, top_k=[1], top_p=[2])
Drag options to blanks, or click blank then click option'
A50
B0.9
C0.8
D100
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping top-k and top-p values.
Using floats for top-k or integers for top-p.
5fill in blank
hard

Fill all three blanks to create a dictionary of sampling parameters with top-k, top-p, and temperature.

Prompt Engineering / GenAI
sampling_params = {'top_k': [1], 'top_p': [2], 'temperature': [3]
Drag options to blanks, or click blank then click option'
A40
B0.85
C1.0
D0.7
Attempts:
3 left
💡 Hint
Common Mistakes
Using temperature as an integer.
Mixing up top-p and temperature values.