Implement Top-p (Nucleus) Sampling in NumPy
Given a language model’s next-token probability distribution, implement top-p (nucleus) sampling.
Task
Implement top_p_sample(probs, p, rng) to sample a token id from probs using the follo...
Example
Unlock to view complete problem details
and practice with sample input/output
Was this article helpful?
View Test Cases & Run Code requires membership
Standard Input
Execution Result:
