Top-p chooses a fixed probability mass, which can keep many junk tokens when the distribution is flat and cut good options when it is peaked at high temperature. Min-p instead sets a threshold relative to the best token: keep every token whose probability is at least min_p times the probability of the most likely token. If the top token has probability 0.8 and min_p = 0.1, the cutoff is 0.08. If the model is unsure and the top token has 0.2, the cutoff drops to 0.02. The candidate set therefore scales with the model's confidence, and the rule stays sensible when the temperature is raised for creativity.
Implement min_p_filter.
probs is a 1-D probability vector and 0 <= min_p <= 1.min_p * probs.max(). Keep every token with probs >= threshold (so the top token is always kept).probs.A boolean mask probs >= min_p * probs.max() does the work.
With min_p = 0 nothing is removed, with min_p = 1 only the maximum (and exact ties) remains.
No results yet
Run your code to check it against the examples, or submit to run every test.