Skip to content
DeepForgeby svx
All problems
MediumDeep Learningdl-204

Min-P Sampling

Problem

Filter logits with min-p sampling: compute a stable softmax, set the threshold to min_p times the largest probability, and keep every token whose probability is at least the threshold. Always keep the top token if nothing qualifies. Return the kept indices in ascending order.

The signature is min_p_filter(logits, min_p).

Hint

Min-p scales the cutoff with the model's own confidence, unlike fixed top-p.

Test cases

case 1
in: [[1,2,3],0.1]
expected: [0,1,2]
case 2
in: [[1,2,3],0.2]
expected: [1,2]
case 3
in: [[1,2,3],0.5]
expected: [2]
case 4
in: [[0,0,0],0.5]
expected: [0,1,2]
case 5
in: [[2,1,0],1]
expected: [0]
Starter codePython
import math
def min_p_filter(logits, min_p):
    # Your code here
    pass

5 test cases · run your code against them in the editor