class_docstr: ## Top-k Sampler
class_docstr_tok: ["#","#","Top-k","Sampler"]
docstr: :param k: is the number of tokens to pick
  :param sampler: is the sampler to use for the top-k tokens
  
  `sampler` can be any sampler that takes a logits tensor as input and returns a token tensor;
   e.g. [`TemperatureSampler'](temperature.html).
docstr_tok: [":","param","k",":","is","the","number","of","tokens","to","pick",":","param","sampler",":","is","the","sampler","to","use","for","the","top-k","tokens","`","sampler","`","can","be","any","sampler","that","takes","a","logits","tensor","as","input","and","returns","a","token","tensor",";","e.g",".","[","`","TemperatureSampler","'","]","(","temperature.html",")","."]
code: def __init__(self, k: int, sampler: Sampler):
      """
      :param k: is the number of tokens to pick
      :param sampler: is the sampler to use for the top-k tokens
  
      `sampler` can be any sampler that takes a logits tensor as input and returns a token tensor;
       e.g. [`TemperatureSampler'](temperature.html).
      """
      self.k = k
      self.sampler = sampler
  
imports: import torch
  from labml_nn.sampling import Sampler
label_desc: Use image node_id 1 to create a new TopKSampler object from inherited base classes: Sampler with example: obj = TopKSampler(k, sampler)