Principle:LaurentMazare Tch rs Top K Prediction
| Knowledge Sources | |
|---|---|
| Domains | Computer_Vision, Model_Inference |
| Last Updated | 2026-02-08 14:00 GMT |
Overview
Post-processing technique that extracts the K most probable class predictions from a model's softmax output along with their human-readable class names.
Description
After a model produces probability scores over all possible classes, Top-K prediction selects the K classes with the highest probabilities. This is essential for image classification where reporting only the single most likely class may miss near-ties. The technique uses the topk operation to efficiently find the K largest values and their indices, then maps indices to class names using a lookup table.
Usage
Use after applying softmax to model logits for image classification. Standard practice is K=5 (top-5 accuracy is a common benchmark metric).
Theoretical Basis
Top-K Algorithm:
1. Given probability vector p of shape [num_classes]
2. Find indices of K largest values: topk(p, K, descending=true)
3. Map each index to class name: CLASSES[index]
4. Return list of (probability, class_name) pairs