code: def bucket_values(
      distances, num_identity_buckets=4, num_total_buckets=10
  ):
      """
      Places the given values (designed for distances) into ``num_total_buckets``semi-logscale
      buckets, with ``num_identity_buckets`` of these capturing single values.
  
      The default settings will bucket values into the following buckets:
      [0, 1, 2, 3, 4, 5-7, 8-15, 16-31, 32-63, 64+].
  
      Parameters
      ----------
      distances : ``torch.Tensor``, required.
          A Tensor of any size, to be bucketed.
      num_identity_buckets: int, optional (default = 4).
          The number of identity buckets (those only holding a single value).
      num_total_buckets : int, (default = 10)
          The total number of buckets to bucket values into.
  
      Returns
      -------
      A tensor of the same shape as the input, containing the indices of the buckets
      the values were placed in.
      """
      # Chunk the values into semi-logscale buckets using .floor().
      # This is a semi-logscale bucketing because we divide by log(2) after taking the log.
      # We do this to make the buckets more granular in the initial range, where we expect
      # most values to fall. We then add (num_identity_buckets - 1) because we want these indices
      # to start _after_ the fixed number of buckets which we specified would only hold single values.
      logspace_index = (
          distances.float().log() / math.log(2)
      ).floor().long() + (num_identity_buckets - 1)
      # create a mask for values which will go into single number buckets (i.e not a range).
      use_identity_mask = (distances <= num_identity_buckets).long()
      use_buckets_mask = 1 + (-1 * use_identity_mask)
      # Use the original values if they are less than num_identity_buckets, otherwise
      # use the logspace indices.
      combined_index = (
          use_identity_mask * distances
          + use_buckets_mask * logspace_index
      )
      # Clamp to put anything > num_total_buckets into the final bucket.
      return combined_index.clamp(0, num_total_buckets - 1)
  
imports: from __future__ import division
  from __future__ import absolute_import
  from collections import defaultdict
  import logging
  import math
  import torch
  from allennlp.common.checks import ConfigurationError
label_desc: Use image node_id 30 for calling a global function with example usage: bucket_values(distances, num_identity_buckets, num_total_buckets) and returns: combined_index