class_docstr: Based on the default log_uniform_candidate_sampler in tensorflow.
  
  !!! NOTE
      num_words DOES NOT include padding id.
  
  !!! NOTE
      In all cases except (tie_embeddings=True and use_character_inputs=False)
      the weights are dimensioned as num_words and do not include an entry for the padding (0) id.
      For the (tie_embeddings=True and use_character_inputs=False) case,
      then the embeddings DO include the extra 0 padding, to be consistent with the word embedding layer.
  
  # Parameters
  
  num_words, `int`, required
      The number of words in the vocabulary
  embedding_dim, `int`, required
      The dimension to softmax over
  num_samples, `int`, required
      During training take this many samples. Must be less than num_words.
  sparse, `bool`, optional (default = `False`)
      If this is true, we use a sparse embedding matrix.
  unk_id, `int`, optional (default = `None`)
      If provided, the id that represents unknown characters.
  use_character_inputs, `bool`, optional (default = `True`)
      Whether to use character inputs
  use_fast_sampler, `bool`, optional (default = `False`)
      Whether to use the fast cython sampler.
class_docstr_tok: ["Based","on","the","default","log_uniform_candidate_sampler","in","tensorflow",".","!","!","!","NOTE","num_words","DOES","NOT","include","padding","id",".","!","!","!","NOTE","In","all","cases","except","(","tie_embeddings=True","and","use_character_inputs=False",")","the","weights","are","dimensioned","as","num_words","and","do","not","include","an","entry","for","the","padding","(","0",")","id",".","For","the","(","tie_embeddings=True","and","use_character_inputs=False",")","case",",","then","the","embeddings","DO","include","the","extra","0","padding",",","to","be","consistent","with","the","word","embedding","layer",".","#","Parameters","num_words",",","`","int","`",",","required","The","number","of","words","in","the","vocabulary","embedding_dim",",","`","int","`",",","required","The","dimension","to","softmax","over","num_samples",",","`","int","`",",","required","During","training","take","this","many","samples",".","Must","be","less","than","num_words",".","sparse",",","`","bool","`",",","optional","(","default","=","`","False","`",")","If","this","is","true",",","we","use","a","sparse","embedding","matrix",".","unk_id",",","`","int","`",",","optional","(","default","=","`","None","`",")","If","provided",",","the","id","that","represents","unknown","characters",".","use_character_inputs",",","`","bool","`",",","optional","(","default","=","`","True","`",")","Whether","to","use","character","inputs","use_fast_sampler",",","`","bool","`",",","optional","(","default","=","`","False","`",")","Whether","to","use","the","fast","cython","sampler","."]
code: def log_uniform_candidate_sampler(self, targets, choice_func=_choice):
      # returns sampled, true_expected_count, sampled_expected_count
      # targets = (batch_size, )
      #
      #  samples = (n_samples, )
      #  true_expected_count = (batch_size, )
      #  sampled_expected_count = (n_samples, )
  
      # see: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/kernels/range_sampler.h
      # https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/kernels/range_sampler.cc
  
      # algorithm: keep track of number of tries when doing sampling,
      #   then expected count is
      #   -expm1(num_tries * log1p(-p))
      # = (1 - (1-p)^num_tries) where p is self._probs[id]
  
      np_sampled_ids, num_tries = choice_func(
          self._num_words, self._num_samples
      )
  
      sampled_ids = torch.from_numpy(np_sampled_ids).to(targets.device)
  
      # Compute expected count = (1 - (1-p)^num_tries) = -expm1(num_tries * log1p(-p))
      # P(class) = (log(class + 2) - log(class + 1)) / log(range_max + 1)
      target_probs = (
          torch.log((targets.float() + 2.0) / (targets.float() + 1.0))
          / self._log_num_words_p1
      )
      target_expected_count = -1.0 * (
          torch.exp(num_tries * torch.log1p(-target_probs)) - 1.0
      )
      sampled_probs = (
          torch.log(
              (sampled_ids.float() + 2.0) / (sampled_ids.float() + 1.0)
          )
          / self._log_num_words_p1
      )
      sampled_expected_count = -1.0 * (
          torch.exp(num_tries * torch.log1p(-sampled_probs)) - 1.0
      )
  
      sampled_ids.requires_grad_(False)
      target_expected_count.requires_grad_(False)
      sampled_expected_count.requires_grad_(False)
  
      return sampled_ids, target_expected_count, sampled_expected_count
  
file_path: allennlp/allennlp/modules/sampled_softmax_loss.py
imports: from typing import Set, Tuple
  import numpy
  import torch
  from allennlp.common.checks import ConfigurationError
  from allennlp.nn import util
label_desc: Use image node_id 6 for calling the SampledSoftmaxLoss obj's underlying member method code with example usage: obj.log_uniform_candidate_sampler(targets, choice_func) and returns: sampled_ids,  target_expected_count,  sampled_expected_count