class_docstr: Hierarchical softmax layer over binary tree.
  
  In natural language applications, vocabulary size is too large to use
  softmax loss.
  Instead, the hierarchical softmax uses product of sigmoid functions.
  It costs only :math:`O(\log(n))` time where :math:`n` is the vocabulary
  size in average.
  
  At first a user needs to prepare a binary tree whose each leaf is
  corresponding to a word in a vocabulary.
  When a word :math:`x` is given, exactly one path from the root of the tree
  to the leaf of the word exists.
  Let :math:`\mbox{path}(x) = ((e_1, b_1), \dots, (e_m, b_m))` be the path
  of :math:`x`, where :math:`e_i` is an index of :math:`i`-th internal node,
  and :math:`b_i \in \{-1, 1\}` indicates direction to move at
  :math:`i`-th internal node (-1 is left, and 1 is right).
  Then, the probability of :math:`x` is given as below:
  
  .. math::
  
     P(x) &= \prod_{(e_i, b_i) \in \mbox{path}(x)}P(b_i | e_i)  \\
          &= \prod_{(e_i, b_i) \in \mbox{path}(x)}\sigma(b_i x^\top
             w_{e_i}),
  
  where :math:`\sigma(\cdot)` is a sigmoid function, and :math:`w` is a
  weight matrix.
  
  This function costs :math:`O(\log(n))` time as an average length of paths
  is :math:`O(\log(n))`, and :math:`O(n)` memory as the number of internal
  nodes equals :math:`n - 1`.
  
  Args:
      in_size (int): Dimension of input vectors.
      tree: A binary tree made with tuples like `((1, 2), 3)`.
      dtype (numpy.dtype): Type to use in computing.
  
  Attributes:
      W (~chainer.Variable): Weight parameter matrix.
  
  See: Hierarchical Probabilistic Neural Network Language Model [Morin+,
  AISTAT2005].
docstr: Makes a Huffman tree from a dictionary containing word counts.
  
  This method creates a binary Huffman tree, that is required for
  :class:`BinaryHierarchicalSoftmax`.
  For example, ``{0: 8, 1: 5, 2: 6, 3: 4}`` is converted to
  ``((3, 1), (2, 0))``.
  
  Args:
      word_counts (dict of int key and int or float values):
          Dictionary representing counts of words.
  
  Returns:
      Binary Huffman tree with tuples and keys of ``word_coutns``.
docstr_tok: ["Makes","a","Huffman","tree","from","a","dictionary","containing","word","counts",".","This","method","creates","a","binary","Huffman","tree",",","that","is","required","for",":","class",":","`","BinaryHierarchicalSoftmax","`",".","For","example",",","``","{","0",":","8",",","1",":","5",",","2",":","6",",","3",":","4","}","``","is","converted","to","``","(","(","3",",","1",")",",","(","2",",","0",")",")","``",".","Args",":","word_counts","(","dict","of","int","key","and","int","or","float","values",")",":","Dictionary","representing","counts","of","words",".","Returns",":","Binary","Huffman","tree","with","tuples","and","keys","of","``","word_coutns","``","."]
code: def create_huffman_tree(word_counts):
      """Makes a Huffman tree from a dictionary containing word counts.
  
      This method creates a binary Huffman tree, that is required for
      :class:`BinaryHierarchicalSoftmax`.
      For example, ``{0: 8, 1: 5, 2: 6, 3: 4}`` is converted to
      ``((3, 1), (2, 0))``.
  
      Args:
          word_counts (dict of int key and int or float values):
              Dictionary representing counts of words.
  
      Returns:
          Binary Huffman tree with tuples and keys of ``word_coutns``.
  
      """
      if not word_counts:
          raise ValueError("Empty vocabulary")
  
      q = six.moves.queue.PriorityQueue()
      # Add unique id to each entry so that we can compare two entries with
      # same counts.
      # Note that iteritems randomly order the entries.
      for uid, (w, c) in enumerate(six.iteritems(word_counts)):
          q.put((c, uid, w))
  
      while q.qsize() >= 2:
          (count1, id1, word1) = q.get()
          (count2, id2, word2) = q.get()
          count = count1 + count2
          tree = (word1, word2)
          q.put((count, min(id1, id2), tree))
  
      return q.get()[2]
  
imports: import copy
  import numpy
  import six
  import chainer
  from chainer.backends import cuda
  from chainer import device_resident
  from chainer import function
  from chainer.initializers import uniform
  from chainer import link
  from chainer import utils
  from chainer.utils import type_check
  from chainer import variable
label_desc: Use image node_id 3 for calling the BinaryHierarchicalSoftmax obj's underlying member method code with example usage: obj.create_huffman_tree(word_counts) and returns: q