Attention & TransformersMedium
Temperature and Top-p Distribution
~15 mincode completion
Implement top_p_distribution(logits, temperature, p) returning the array q, the same length as logits.
Where this shows up
~15 min
••••••••••••••••
8 employers weight this skill
4 frontier labs, 3 AI product companies, 1 enterprise vendor. Top match scores 92.
Python
import numpy as np
def top_p_distribution(logits, temperature, p):
"""
Temperature-scaled, nucleus-filtered next-token distribution.
Args:
logits: array of raw scores, shape (V,)
temperature: T > 0
p: nucleus threshold in (0, 1]
Returns:
array of shape (V,): renormalized probabilities, 0 on dropped tokens
"""
# YOUR CODE HERE
pass