class_docstr: An abstract class that can be used to sample candidates (either nodes or beams)
  within `BeamSearch`.
  
  A `Sampler` just has three methods, `init_state()`, `sample_nodes()` and `sample_beams()`.
  
  `init_state()` takes three arguments:
  
  - a tensor of starting log probs with shape `(batch_size,, num_classes)`,
  - the batch size, an int,
  - and the number of classes, also an int.
  
  It returns a state dictionary with any state tensors needed for subsequent
  calls to `sample_nodes()` and `sample_beams()`.
  
  By default this method just returns an empty dictionary.
  
  Both `sample_nodes()` and `sample_beams()` should take three arguments:
  
  - tensor of normalized log probabilities with shape `(batch_size, num_examples)`,
  - an integer representing the number of samples to take for each example in the batch,
  - and a state dictionary which could contain any tensors needed for the `Sampler` to keep
    track of state.
  
  For `sample_nodes()`, `num_examples = num_classes`, but for `sample_beams`,
  `num_examples = beam_size * per_node_beam_size`.
  
  The return value should be a tuple containing:
  
  - a tensor of log probabilities of the sampled examples with shape `(batch_size, num_samples)`,
  - a tensor of indices of the sampled examples with shape `(batch_size, num_samples)`,
  - and the updated state dictionary.
  
  A default implementation of `sample_beams` is provided, which just deterministically
  picks the `k` examples with highest log probability.
class_docstr_tok: ["An","abstract","class","that","can","be","used","to","sample","candidates","(","either","nodes","or","beams",")","within","`","BeamSearch","`",".","A","`","Sampler","`","just","has","three","methods",",","`","init_state","(",")","`",",","`","sample_nodes","(",")","`","and","`","sample_beams","(",")","`",".","`","init_state","(",")","`","takes","three","arguments",":","-","a","tensor","of","starting","log","probs","with","shape","`","(","batch_size",",",",","num_classes",")","`",",","-","the","batch","size",",","an","int",",","-","and","the","number","of","classes",",","also","an","int",".","It","returns","a","state","dictionary","with","any","state","tensors","needed","for","subsequent","calls","to","`","sample_nodes","(",")","`","and","`","sample_beams","(",")","`",".","By","default","this","method","just","returns","an","empty","dictionary",".","Both","`","sample_nodes","(",")","`","and","`","sample_beams","(",")","`","should","take","three","arguments",":","-","tensor","of","normalized","log","probabilities","with","shape","`","(","batch_size",",","num_examples",")","`",",","-","an","integer","representing","the","number","of","samples","to","take","for","each","example","in","the","batch",",","-","and","a","state","dictionary","which","could","contain","any","tensors","needed","for","the","`","Sampler","`","to","keep","track","of","state",".","For","`","sample_nodes","(",")","`",",","`","num_examples","=","num_classes","`",",","but","for","`","sample_beams","`",",","`","num_examples","=","beam_size","*","per_node_beam_size","`",".","The","return","value","should","be","a","tuple","containing",":","-","a","tensor","of","log","probabilities","of","the","sampled","examples","with","shape","`","(","batch_size",",","num_samples",")","`",",","-","a","tensor","of","indices","of","the","sampled","examples","with","shape","`","(","batch_size",",","num_samples",")","`",",","-","and","the","updated","state","dictionary",".","A","default","implementation","of","`","sample_beams","`","is","provided",",","which","just","deterministically","picks","the","`","k","`","examples","with","highest","log","probability","."]
code: def sample_nodes(
      self,
      log_probs: torch.Tensor,
      per_node_beam_size: int,
      state: StateType,
  ) -> Tuple[torch.Tensor, torch.Tensor, StateType]:
      raise NotImplementedError
  
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 2 for calling the Sampler obj's underlying member method code with example usage: obj.sample_nodes(log_probs, per_node_beam_size, state) without return types