# Top-k

> Top-k: Sampling only among the k most likely tokens, after renormalising their probabilities.

Canonical: https://llmdojo.dev/glossary/top-k

Sampling only among the k most likely tokens, after renormalising their probabilities.

Learn it in the lesson: [Top-k and top-p](https://llmdojo.dev/learn/model-foundations/sampling/top-k-and-top-p) (Model Foundations · Next-Token Prediction and Sampling).

## Interview questions about Top-k

- [Explain temperature, top-k and top-p. Why would you usually reach for top-p rather than a fixed k?](https://llmdojo.dev/interview/q/explain-temperature-top-k-and-top-p-why-would-you-usually-reach)
- [Given logits from a toy language model, implement greedy, top-k and top-p decoding in NumPy.](https://llmdojo.dev/interview/q/given-logits-from-a-toy-language-model-implement-greedy-top-k-and)
- [Your LM head is too big for one device. How do you shard it by vocabulary or by hidden width, combine the logits, and compute an exact top-k across shards?](https://llmdojo.dev/interview/q/your-lm-head-is-too-big-for-one-device-how-do-you)
- [Design a real-time system that shows the top-K points of interest in a user's map viewport as they pan and zoom, within a 150 ms p95 budget.](https://llmdojo.dev/interview/q/design-a-real-time-system-that-shows-the-top-k-points-of)
- [Your assistant's semantic search over user content is slow and expensive. How do you optimise it: embedding choice, ANN indexing and sharding?](https://llmdojo.dev/interview/q/your-assistant-s-semantic-search-over-user-content-is-slow-and-expensive)
- [Your integration tests call a hosted model at temperature 0 and compare the output with an exact string. They fail now and then. What's going on, and what do you change?](https://llmdojo.dev/interview/q/your-integration-tests-call-a-hosted-model-at-temperature-0-and-compare)

## Related
- [Logit](https://llmdojo.dev/glossary/logit)
- [LM head](https://llmdojo.dev/glossary/lm-head)
- [Autoregressive generation](https://llmdojo.dev/glossary/autoregressive)
- [Greedy decoding](https://llmdojo.dev/glossary/greedy-decoding)
- [Temperature](https://llmdojo.dev/glossary/temperature)
- [Top-p (nucleus sampling)](https://llmdojo.dev/glossary/top-p)
- [Seed](https://llmdojo.dev/glossary/seed)
- [Logprob](https://llmdojo.dev/glossary/logprob)
- [Glossary of every term](https://llmdojo.dev/glossary)
