class_docstr: A `Sampler` which redistributes the probability mass function for nodes among
  the top choices with a cumulative probability of at least `p`, then samples from that subset
  after re-normalizing the probabilities.
  
  Beams are sampled in the default, deterministic way.
  
  # Parameters
  
  p : `float`, optional (default = `0.9`)
      The cumulative probability cutoff threshold. A higher value of `p` will result in more possible
      examples to sample from. If `with_replacement` is `False` and the number of possible samples is
      insufficient to sample without replacement from when calling `sample_nodes`, then the top
      `per_node_beam_size` examples will be chosen.
  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 choices.
class_docstr_tok: ["A","`","Sampler","`","which","redistributes","the","probability","mass","function","for","nodes","among","the","top","choices","with","a","cumulative","probability","of","at","least","`","p","`",",","then","samples","from","that","subset","after","re-normalizing","the","probabilities",".","Beams","are","sampled","in","the","default",",","deterministic","way",".","#","Parameters","p",":","`","float","`",",","optional","(","default","=","`","0.9","`",")","The","cumulative","probability","cutoff","threshold",".","A","higher","value","of","`","p","`","will","result","in","more","possible","examples","to","sample","from",".","If","`","with_replacement","`","is","`","False","`","and","the","number","of","possible","samples","is","insufficient","to","sample","without","replacement","from","when","calling","`","sample_nodes","`",",","then","the","top","`","per_node_beam_size","`","examples","will","be","chosen",".","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","choices","."]
code: def __init__(
      self,
      p: float = 0.9,
      temperature: float = 1.0,
      with_replacement: bool = False,
  ):
      if p < 0.0 or p > 1.0:
          raise ValueError(
              "p must be a positive float no greater than 1.0"
          )
      self.p = p
      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 TopPSampler object from inherited base classes: Sampler with example: obj = TopPSampler(p, temperature, with_replacement)