Temperature and Top-p Distribution

~15 mincode completion

Implement top_p_distribution(logits, temperature, p) returning the array , 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
Loading docs…

The AI Mentor needs an account

It reads your code and the failing tests and nudges you toward the fix without handing you the answer. Free accounts get it on every problem you're working on today.