parameters: (labels, num_classes, smoothing_constant=10)
return_statement: return math_ops.cast(init_prob_estimate, dtypes.float32)
docstring: Estimate data distribution as labels are seen.
docstring_summary: Estimate data distribution as labels are seen.
docstring_tokens: Estimate data distribution as labels are seen .
function: def _estimate_data_distribution(labels, num_classes, smoothing_constant=10):
    """Estimate data distribution as labels are seen."""
    # Variable to track running count of classes. Smooth by a nonzero value to
    # avoid division-by-zero. Higher values provide more stability at the cost of
    # slower convergence.
    if smoothing_constant <= 0:
      raise ValueError('smoothing_constant must be nonzero.')
    num_examples_per_class_seen = variable_scope.variable(
        initial_value=[smoothing_constant] * num_classes,
        trainable=False,
        name='class_count',
        dtype=dtypes.int64)
  
    # Update the class-count based on what labels are seen in batch.
    num_examples_per_class_seen = num_examples_per_class_seen.assign_add(
        math_ops.reduce_sum(
            array_ops.one_hot(
                labels, num_classes, dtype=dtypes.int64), 0))
  
    # Normalize count into a probability.
    # NOTE: Without the `+= 0` line below, the test
    # `testMultiThreadedEstimateDataDistribution` fails. The reason is that
    # before this line, `num_examples_per_class_seen` is a Tensor that shares a
    # buffer with an underlying `ref` object. When the `ref` is changed by another
    # thread, `num_examples_per_class_seen` changes as well. Since this can happen
    # in the middle of the normalization computation, we get probabilities that
    # are very far from summing to one. Adding `+= 0` copies the contents of the
    # tensor to a new buffer, which will be consistent from the start to the end
    # of the normalization computation.
    num_examples_per_class_seen += 0
    init_prob_estimate = math_ops.truediv(
        num_examples_per_class_seen,
        math_ops.reduce_sum(num_examples_per_class_seen))
  
    # Must return float32 (not float64) to agree with downstream `_verify_input`
    # checks.
    return math_ops.cast(init_prob_estimate, dtypes.float32)
function_tokens: def _estimate_data_distribution ( labels , num_classes , smoothing_constant = 10 ) : # Variable to track running count of classes. Smooth by a nonzero value to # avoid division-by-zero. Higher values provide more stability at the cost of # slower convergence. if smoothing_constant <= 0 : raise ValueError ( 'smoothing_constant must be nonzero.' ) num_examples_per_class_seen = variable_scope . variable ( initial_value = [ smoothing_constant ] * num_classes , trainable = False , name = 'class_count' , dtype = dtypes . int64 ) # Update the class-count based on what labels are seen in batch. num_examples_per_class_seen = num_examples_per_class_seen . assign_add ( math_ops . reduce_sum ( array_ops . one_hot ( labels , num_classes , dtype = dtypes . int64 ) , 0 ) ) # Normalize count into a probability. # NOTE: Without the `+= 0` line below, the test # `testMultiThreadedEstimateDataDistribution` fails. The reason is that # before this line, `num_examples_per_class_seen` is a Tensor that shares a # buffer with an underlying `ref` object. When the `ref` is changed by another # thread, `num_examples_per_class_seen` changes as well. Since this can happen # in the middle of the normalization computation, we get probabilities that # are very far from summing to one. Adding `+= 0` copies the contents of the # tensor to a new buffer, which will be consistent from the start to the end # of the normalization computation. num_examples_per_class_seen += 0 init_prob_estimate = math_ops . truediv ( num_examples_per_class_seen , math_ops . reduce_sum ( num_examples_per_class_seen ) ) # Must return float32 (not float64) to agree with downstream `_verify_input` # checks. return math_ops . cast ( init_prob_estimate , dtypes . float32 )