class_docstr: A `Sampler` which redistributes the probability mass function for nodes among the
  top `k` choices, then samples from that subset after re-normalizing the probabilities.
  
  Beams are sampled in the default, deterministic way.
  
  # Parameters
  
  k : `int`, optional (default = `1`)
      The number of top choices to be selected from.
  temperature : `float`, optional (default = `1.0`)
      A `temperature` below 1.0 produces a sharper probability distribution and a `temperature`
      above 1.0 produces a flatter probability distribution.
  with_replacement: `bool`, optional, (default = `False`)
      If set to `True`, samples will be selected with replacement from the top k choices.
class_docstr_tok: ["A","`","Sampler","`","which","redistributes","the","probability","mass","function","for","nodes","among","the","top","`","k","`","choices",",","then","samples","from","that","subset","after","re-normalizing","the","probabilities",".","Beams","are","sampled","in","the","default",",","deterministic","way",".","#","Parameters","k",":","`","int","`",",","optional","(","default","=","`","1","`",")","The","number","of","top","choices","to","be","selected","from",".","temperature",":","`","float","`",",","optional","(","default","=","`","1.0","`",")","A","`","temperature","`","below","1.0","produces","a","sharper","probability","distribution","and","a","`","temperature","`","above","1.0","produces","a","flatter","probability","distribution",".","with_replacement",":","`","bool","`",",","optional",",","(","default","=","`","False","`",")","If","set","to","`","True","`",",","samples","will","be","selected","with","replacement","from","the","top","k","choices","."]
code: def __init__(
      self,
      k: int = 1,
      temperature: float = 1.0,
      with_replacement: bool = False,
  ):
      self.k = k
      self.temperature = temperature or 1.0
      self.with_replacement = with_replacement
  
imports: from inspect import signature
  from typing import Any, List, Callable, Tuple, Dict, cast, TypeVar, Optional
  import copy
  import warnings
  import torch
  from allennlp.common import Lazy, Registrable
  from allennlp.common.checks import ConfigurationError
  from allennlp.data import Vocabulary
  from allennlp.nn.util import min_value_of_dtype
label_desc: Use image node_id 1 to create a new TopKSampler object from inherited base classes: Sampler with example: obj = TopKSampler(k, temperature, with_replacement)