code: def test_gumbel_sampler(self):
      sampler = GumbelSampler()
      num_classes = len(log_probabilities[0])
      sampler_state = sampler.init_state(
          log_probabilities, batch_size=2, num_classes=num_classes
      )
  
      log_probs, indices, state = sampler.sample_beams(
          log_probabilities, 3, sampler_state
      )
  
      assert log_probs.size() == indices.size()
      assert indices.size() == (2, 3)
  
      # Make sure the probabilities are sorted.
      _, sorted_indices = log_probs.sort(dim=-1, descending=True)
      assert (sorted_indices == torch.arange(3).unsqueeze(0)).all()
  
      assert all([x >= 0 and x < 4 for x in indices[0]])
      assert all([x > 1 and x <= 5 for x in indices[1]])
  
imports: from typing import Dict, Tuple, Union
  import numpy
  import pytest
  import torch
  from allennlp.common.checks import ConfigurationError
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.nn.beam_search import MultinomialSampler, BeamSearch, TopKSampler, TopPSampler, GumbelSampler, LengthNormalizedSequenceLogProbabilityScorer, RepeatedNGramBlockingConstraint, StepFunctionTypeWithTimestep, StepFunctionTypeNoTimestep
  from allennlp.common.params import Params
  from allennlp.nn.util import min_value_of_dtype
label_desc: Use image node_id 27 for calling the BeamSearchTest obj's underlying member method code with example usage: obj.test_gumbel_sampler() without return types