def _compute_sampled_logits(weights, biases, inputs, labels, num_sampled, num_classes, num_true=1, sampled_values=None, subtract_log_q=True, remove_accidental_hits=False, partition_strategy='mod', name=None):
    'Helper function for nce_loss and sampled_softmax_loss functions.\n\n  Computes sampled output training logits and labels suitable for implementing\n  e.g. noise-contrastive estimation (see nce_loss) or sampled softmax (see\n  sampled_softmax_loss).\n\n  Note: In the case where num_true > 1, we assign to each target class\n  the target probability 1 / num_true so that the target probabilities\n  sum to 1 per-example.\n\n  Args:\n    weights: A `Tensor` of shape `[num_classes, dim]`, or a list of `Tensor`\n        objects whose concatenation along dimension 0 has shape\n        `[num_classes, dim]`.  The (possibly-partitioned) class embeddings.\n    biases: A `Tensor` of shape `[num_classes]`.  The class biases.\n    inputs: A `Tensor` of shape `[batch_size, dim]`.  The forward\n        activations of the input network.\n    labels: A `Tensor` of type `int64` and shape `[batch_size,\n        num_true]`. The target classes.  Note that this format differs from\n        the `labels` argument of `nn.softmax_cross_entropy_with_logits`.\n    num_sampled: An `int`.  The number of classes to randomly sample per batch.\n    num_classes: An `int`. The number of possible classes.\n    num_true: An `int`.  The number of target classes per training example.\n    sampled_values: a tuple of (`sampled_candidates`, `true_expected_count`,\n        `sampled_expected_count`) returned by a `*_candidate_sampler` function.\n        (if None, we default to `log_uniform_candidate_sampler`)\n    subtract_log_q: A `bool`.  whether to subtract the log expected count of\n        the labels in the sample to get the logits of the true labels.\n        Default is True.  Turn off for Negative Sampling.\n    remove_accidental_hits:  A `bool`.  whether to remove "accidental hits"\n        where a sampled class equals one of the target classes.  Default is\n        False.\n    partition_strategy: A string specifying the partitioning strategy, relevant\n        if `len(weights) > 1`. Currently `"div"` and `"mod"` are supported.\n        Default is `"mod"`. See `tf.nn.embedding_lookup` for more details.\n    name: A name for the operation (optional).\n  Returns:\n    out_logits, out_labels: `Tensor` objects each with shape\n        `[batch_size, num_true + num_sampled]`, for passing to either\n        `nn.sigmoid_cross_entropy_with_logits` (NCE) or\n        `nn.softmax_cross_entropy_with_logits` (sampled softmax).\n  '
    if (not isinstance(weights, list)):
        weights = [weights]
    with ops.op_scope((weights + [biases, inputs, labels]), name, 'compute_sampled_logits'):
        if (labels.dtype != dtypes.int64):
            labels = math_ops.cast(labels, dtypes.int64)
        labels_flat = array_ops.reshape(labels, [(- 1)])
        if (sampled_values is None):
            sampled_values = candidate_sampling_ops.log_uniform_candidate_sampler(true_classes=labels, num_true=num_true, num_sampled=num_sampled, unique=True, range_max=num_classes)
        (sampled, true_expected_count, sampled_expected_count) = sampled_values
        all_ids = array_ops.concat(0, [labels_flat, sampled])
        all_w = embedding_ops.embedding_lookup(weights, all_ids, partition_strategy=partition_strategy)
        all_b = embedding_ops.embedding_lookup(biases, all_ids)
        true_w = array_ops.slice(all_w, [0, 0], array_ops.pack([array_ops.shape(labels_flat)[0], (- 1)]))
        true_b = array_ops.slice(all_b, [0], array_ops.shape(labels_flat))
        dim = array_ops.shape(true_w)[1:2]
        new_true_w_shape = array_ops.concat(0, [[(- 1), num_true], dim])
        row_wise_dots = math_ops.mul(array_ops.expand_dims(inputs, 1), array_ops.reshape(true_w, new_true_w_shape))
        dots_as_matrix = array_ops.reshape(row_wise_dots, array_ops.concat(0, [[(- 1)], dim]))
        true_logits = array_ops.reshape(_sum_rows(dots_as_matrix), [(- 1), num_true])
        true_b = array_ops.reshape(true_b, [(- 1), num_true])
        true_logits += true_b
        sampled_w = array_ops.slice(all_w, array_ops.pack([array_ops.shape(labels_flat)[0], 0]), [(- 1), (- 1)])
        sampled_b = array_ops.slice(all_b, array_ops.shape(labels_flat), [(- 1)])
        sampled_logits = (math_ops.matmul(inputs, sampled_w, transpose_b=True) + sampled_b)
        if remove_accidental_hits:
            acc_hits = candidate_sampling_ops.compute_accidental_hits(labels, sampled, num_true=num_true)
            (acc_indices, acc_ids, acc_weights) = acc_hits
            acc_indices_2d = array_ops.reshape(acc_indices, [(- 1), 1])
            acc_ids_2d_int32 = array_ops.reshape(math_ops.cast(acc_ids, dtypes.int32), [(- 1), 1])
            sparse_indices = array_ops.concat(1, [acc_indices_2d, acc_ids_2d_int32], 'sparse_indices')
            sampled_logits_shape = array_ops.concat(0, [array_ops.shape(labels)[:1], array_ops.expand_dims(num_sampled, 0)])
            if (sampled_logits.dtype != acc_weights.dtype):
                acc_weights = math_ops.cast(acc_weights, sampled_logits.dtype)
            sampled_logits += sparse_ops.sparse_to_dense(sparse_indices, sampled_logits_shape, acc_weights, default_value=0.0, validate_indices=False)
        if subtract_log_q:
            true_logits -= math_ops.log(true_expected_count)
            sampled_logits -= math_ops.log(sampled_expected_count)
        out_logits = array_ops.concat(1, [true_logits, sampled_logits])
        out_labels = array_ops.concat(1, [(array_ops.ones_like(true_logits) / num_true), array_ops.zeros_like(sampled_logits)])
    return (out_logits, out_labels)
Helper function for nce_loss and sampled_softmax_loss functions.

Computes sampled output training logits and labels suitable for implementing
e.g. noise-contrastive estimation (see nce_loss) or sampled softmax (see
sampled_softmax_loss).

Note: In the case where num_true > 1, we assign to each target class
the target probability 1 / num_true so that the target probabilities
sum to 1 per-example.

Args:
  weights: A `Tensor` of shape `[num_classes, dim]`, or a list of `Tensor`
      objects whose concatenation along dimension 0 has shape
      `[num_classes, dim]`.  The (possibly-partitioned) class embeddings.
  biases: A `Tensor` of shape `[num_classes]`.  The class biases.
  inputs: A `Tensor` of shape `[batch_size, dim]`.  The forward
      activations of the input network.
  labels: A `Tensor` of type `int64` and shape `[batch_size,
      num_true]`. The target classes.  Note that this format differs from
      the `labels` argument of `nn.softmax_cross_entropy_with_logits`.
  num_sampled: An `int`.  The number of classes to randomly sample per batch.
  num_classes: An `int`. The number of possible classes.
  num_true: An `int`.  The number of target classes per training example.
  sampled_values: a tuple of (`sampled_candidates`, `true_expected_count`,
      `sampled_expected_count`) returned by a `*_candidate_sampler` function.
      (if None, we default to `log_uniform_candidate_sampler`)
  subtract_log_q: A `bool`.  whether to subtract the log expected count of
      the labels in the sample to get the logits of the true labels.
      Default is True.  Turn off for Negative Sampling.
  remove_accidental_hits:  A `bool`.  whether to remove "accidental hits"
      where a sampled class equals one of the target classes.  Default is
      False.
  partition_strategy: A string specifying the partitioning strategy, relevant
      if `len(weights) > 1`. Currently `"div"` and `"mod"` are supported.
      Default is `"mod"`. See `tf.nn.embedding_lookup` for more details.
  name: A name for the operation (optional).
Returns:
  out_logits, out_labels: `Tensor` objects each with shape
      `[batch_size, num_true + num_sampled]`, for passing to either
      `nn.sigmoid_cross_entropy_with_logits` (NCE) or
      `nn.softmax_cross_entropy_with_logits` (sampled softmax).
def _compute_sampled_logits(weights, biases, inputs, labels, num_sampled, num_classes, num_true=1, sampled_values=None, subtract_log_q=True, remove_accidental_hits=False, partition_strategy='mod', name=None):
    'Helper function for nce_loss and sampled_softmax_loss functions.\n\n  Computes sampled output training logits and labels suitable for implementing\n  e.g. noise-contrastive estimation (see nce_loss) or sampled softmax (see\n  sampled_softmax_loss).\n\n  Note: In the case where num_true > 1, we assign to each target class\n  the target probability 1 / num_true so that the target probabilities\n  sum to 1 per-example.\n\n  Args:\n    weights: A `Tensor` of shape `[num_classes, dim]`, or a list of `Tensor`\n        objects whose concatenation along dimension 0 has shape\n        `[num_classes, dim]`.  The (possibly-partitioned) class embeddings.\n    biases: A `Tensor` of shape `[num_classes]`.  The class biases.\n    inputs: A `Tensor` of shape `[batch_size, dim]`.  The forward\n        activations of the input network.\n    labels: A `Tensor` of type `int64` and shape `[batch_size,\n        num_true]`. The target classes.  Note that this format differs from\n        the `labels` argument of `nn.softmax_cross_entropy_with_logits`.\n    num_sampled: An `int`.  The number of classes to randomly sample per batch.\n    num_classes: An `int`. The number of possible classes.\n    num_true: An `int`.  The number of target classes per training example.\n    sampled_values: a tuple of (`sampled_candidates`, `true_expected_count`,\n        `sampled_expected_count`) returned by a `*_candidate_sampler` function.\n        (if None, we default to `log_uniform_candidate_sampler`)\n    subtract_log_q: A `bool`.  whether to subtract the log expected count of\n        the labels in the sample to get the logits of the true labels.\n        Default is True.  Turn off for Negative Sampling.\n    remove_accidental_hits:  A `bool`.  whether to remove "accidental hits"\n        where a sampled class equals one of the target classes.  Default is\n        False.\n    partition_strategy: A string specifying the partitioning strategy, relevant\n        if `len(weights) > 1`. Currently `"div"` and `"mod"` are supported.\n        Default is `"mod"`. See `tf.nn.embedding_lookup` for more details.\n    name: A name for the operation (optional).\n  Returns:\n    out_logits, out_labels: `Tensor` objects each with shape\n        `[batch_size, num_true + num_sampled]`, for passing to either\n        `nn.sigmoid_cross_entropy_with_logits` (NCE) or\n        `nn.softmax_cross_entropy_with_logits` (sampled softmax).\n  '
    if (not isinstance(weights, list)):
        weights = [weights]
    with ops.op_scope((weights + [biases, inputs, labels]), name, 'compute_sampled_logits'):
        if (labels.dtype != dtypes.int64):
            labels = math_ops.cast(labels, dtypes.int64)
        labels_flat = array_ops.reshape(labels, [(- 1)])
        if (sampled_values is None):
            sampled_values = candidate_sampling_ops.log_uniform_candidate_sampler(true_classes=labels, num_true=num_true, num_sampled=num_sampled, unique=True, range_max=num_classes)
        (sampled, true_expected_count, sampled_expected_count) = sampled_values
        all_ids = array_ops.concat(0, [labels_flat, sampled])
        all_w = embedding_ops.embedding_lookup(weights, all_ids, partition_strategy=partition_strategy)
        all_b = embedding_ops.embedding_lookup(biases, all_ids)
        true_w = array_ops.slice(all_w, [0, 0], array_ops.pack([array_ops.shape(labels_flat)[0], (- 1)]))
        true_b = array_ops.slice(all_b, [0], array_ops.shape(labels_flat))
        dim = array_ops.shape(true_w)[1:2]
        new_true_w_shape = array_ops.concat(0, [[(- 1), num_true], dim])
        row_wise_dots = math_ops.mul(array_ops.expand_dims(inputs, 1), array_ops.reshape(true_w, new_true_w_shape))
        dots_as_matrix = array_ops.reshape(row_wise_dots, array_ops.concat(0, [[(- 1)], dim]))
        true_logits = array_ops.reshape(_sum_rows(dots_as_matrix), [(- 1), num_true])
        true_b = array_ops.reshape(true_b, [(- 1), num_true])
        true_logits += true_b
        sampled_w = array_ops.slice(all_w, array_ops.pack([array_ops.shape(labels_flat)[0], 0]), [(- 1), (- 1)])
        sampled_b = array_ops.slice(all_b, array_ops.shape(labels_flat), [(- 1)])
        sampled_logits = (math_ops.matmul(inputs, sampled_w, transpose_b=True) + sampled_b)
        if remove_accidental_hits:
            acc_hits = candidate_sampling_ops.compute_accidental_hits(labels, sampled, num_true=num_true)
            (acc_indices, acc_ids, acc_weights) = acc_hits
            acc_indices_2d = array_ops.reshape(acc_indices, [(- 1), 1])
            acc_ids_2d_int32 = array_ops.reshape(math_ops.cast(acc_ids, dtypes.int32), [(- 1), 1])
            sparse_indices = array_ops.concat(1, [acc_indices_2d, acc_ids_2d_int32], 'sparse_indices')
            sampled_logits_shape = array_ops.concat(0, [array_ops.shape(labels)[:1], array_ops.expand_dims(num_sampled, 0)])
            if (sampled_logits.dtype != acc_weights.dtype):
                acc_weights = math_ops.cast(acc_weights, sampled_logits.dtype)
            sampled_logits += sparse_ops.sparse_to_dense(sparse_indices, sampled_logits_shape, acc_weights, default_value=0.0, validate_indices=False)
        if subtract_log_q:
            true_logits -= math_ops.log(true_expected_count)
            sampled_logits -= math_ops.log(sampled_expected_count)
        out_logits = array_ops.concat(1, [true_logits, sampled_logits])
        out_labels = array_ops.concat(1, [(array_ops.ones_like(true_logits) / num_true), array_ops.zeros_like(sampled_logits)])
    return (out_logits, out_labels)