TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
←

180. Min-P Sampling Filter

Easy

Implement the min-p truncation filter for next-token sampling.

Signature: def min_p_filter(probs: np.ndarray, min_p: float) -> np.ndarray

  1. Compute threshold = min_p * probs.max()
  2. Zero out every probability strictly below the threshold
  3. Renormalize so the surviving probabilities sum to 1
  4. Return the new probability vector

Assume probs is already a valid distribution (non-negative, sums to 1).

Math

p^​i​=∑j​pj​⋅1[pj​≥m⋅pmax​]pi​⋅1[pi​≥m⋅pmax​]​

Asked at

NumPy

import numpy as np

 

def min_p_filter(...):

    pass

🔒

Premium problem

Free accounts include problems #1–20. Upgrade to unlock the editor, hidden test cases, and reference solutions for every problem.

Upgrade to PremiumBack to problems

Already premium?