def nce_loss(weights, biases, inputs, labels, num_sampled, num_classes, num_true=1, sampled_values=None, remove_accidental_hits=False, partition_strategy='mod', name='nce_loss'):
    'Computes and returns the noise-contrastive estimation training loss.\n\n  See [Noise-contrastive estimation: A new estimation principle for\n  unnormalized statistical models]\n  (http://www.jmlr.org/proceedings/papers/v9/gutmann10a/gutmann10a.pdf).\n  Also see our [Candidate Sampling Algorithms Reference]\n  (../../extras/candidate_sampling.pdf)\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  Note: It would be useful to allow a variable number of target classes per\n  example.  We hope to provide this functionality in a future release.\n  For now, if you have a variable number of target classes, you can pad them\n  out to a constant number by either repeating them or by padding\n  with an otherwise unused class.\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.\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    remove_accidental_hits:  A `bool`.  Whether to remove "accidental hits"\n        where a sampled class equals one of the target classes.  If set to\n        `True`, this is a "Sampled Logistic" loss instead of NCE, and we are\n        learning to generate log-odds instead of log probabilities.  See\n        our [Candidate Sampling Algorithms Reference]\n        (../../extras/candidate_sampling.pdf).\n        Default is 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\n  Returns:\n    A `batch_size` 1-D tensor of per-example NCE losses.\n  '
    (logits, labels) = _compute_sampled_logits(weights, biases, inputs, labels, num_sampled, num_classes, num_true=num_true, sampled_values=sampled_values, subtract_log_q=True, remove_accidental_hits=remove_accidental_hits, partition_strategy=partition_strategy, name=name)
    sampled_losses = sigmoid_cross_entropy_with_logits(logits, labels, name='sampled_losses')
    return _sum_rows(sampled_losses)
Computes and returns the noise-contrastive estimation training loss.

See [Noise-contrastive estimation: A new estimation principle for
unnormalized statistical models]
(http://www.jmlr.org/proceedings/papers/v9/gutmann10a/gutmann10a.pdf).
Also see our [Candidate Sampling Algorithms Reference]
(../../extras/candidate_sampling.pdf)

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.

Note: It would be useful to allow a variable number of target classes per
example.  We hope to provide this functionality in a future release.
For now, if you have a variable number of target classes, you can pad them
out to a constant number by either repeating them or by padding
with an otherwise unused class.

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.
  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`)
  remove_accidental_hits:  A `bool`.  Whether to remove "accidental hits"
      where a sampled class equals one of the target classes.  If set to
      `True`, this is a "Sampled Logistic" loss instead of NCE, and we are
      learning to generate log-odds instead of log probabilities.  See
      our [Candidate Sampling Algorithms Reference]
      (../../extras/candidate_sampling.pdf).
      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:
  A `batch_size` 1-D tensor of per-example NCE losses.
def nce_loss(weights, biases, inputs, labels, num_sampled, num_classes, num_true=1, sampled_values=None, remove_accidental_hits=False, partition_strategy='mod', name='nce_loss'):
    'Computes and returns the noise-contrastive estimation training loss.\n\n  See [Noise-contrastive estimation: A new estimation principle for\n  unnormalized statistical models]\n  (http://www.jmlr.org/proceedings/papers/v9/gutmann10a/gutmann10a.pdf).\n  Also see our [Candidate Sampling Algorithms Reference]\n  (../../extras/candidate_sampling.pdf)\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  Note: It would be useful to allow a variable number of target classes per\n  example.  We hope to provide this functionality in a future release.\n  For now, if you have a variable number of target classes, you can pad them\n  out to a constant number by either repeating them or by padding\n  with an otherwise unused class.\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.\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    remove_accidental_hits:  A `bool`.  Whether to remove "accidental hits"\n        where a sampled class equals one of the target classes.  If set to\n        `True`, this is a "Sampled Logistic" loss instead of NCE, and we are\n        learning to generate log-odds instead of log probabilities.  See\n        our [Candidate Sampling Algorithms Reference]\n        (../../extras/candidate_sampling.pdf).\n        Default is 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\n  Returns:\n    A `batch_size` 1-D tensor of per-example NCE losses.\n  '
    (logits, labels) = _compute_sampled_logits(weights, biases, inputs, labels, num_sampled, num_classes, num_true=num_true, sampled_values=sampled_values, subtract_log_q=True, remove_accidental_hits=remove_accidental_hits, partition_strategy=partition_strategy, name=name)
    sampled_losses = sigmoid_cross_entropy_with_logits(logits, labels, name='sampled_losses')
    return _sum_rows(sampled_losses)