LLM Sampling: Temperature, Top-k, Top-p (Nucleus)

Task

Implement an LLM token sampler.

You are given a logits vector logits of length V and sampling parameters:

  • temperature (>0)
  • top_k (integer, 0 disables)
  • top_p (0..1, 1 disab...

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: