courses/machine_learning/deepdive/09_sequence/word2vec/word2vec.py
def nce_loss(self, true_logits, sampled_logits):
    """Build the graph for the NCE loss."""

    # cross-entropy(logits, labels)
    opts = self._options
    true_xent = tf.nn.sigmoid_cross_entropy_with_logits(
        labels=tf.ones_like(true_logits), logits=true_logits)
    sampled_xent = tf.nn.sigmoid_cross_entropy_with_logits(
        labels=tf.zeros_like(sampled_logits), logits=sampled_logits)

    # NCE-loss is the sum of the true and noise (sampled words)
    # contributions, averaged over the batch.
    nce_loss_tensor = (tf.reduce_sum(true_xent) +
                       tf.reduce_sum(sampled_xent)) / opts.batch_size
    return nce_loss_tensor
Build the graph for the NCE loss.
Build the graph for the NCE loss.
Build the graph for the NCE loss .
def nce_loss(self, true_logits, sampled_logits):
    opts = self._options
    true_xent = tf.nn.sigmoid_cross_entropy_with_logits(
        labels=tf.ones_like(true_logits), logits=true_logits)
    sampled_xent = tf.nn.sigmoid_cross_entropy_with_logits(
        labels=tf.zeros_like(sampled_logits), logits=sampled_logits)
    nce_loss_tensor = (tf.reduce_sum(true_xent) +
                       tf.reduce_sum(sampled_xent)) / opts.batch_size
    return nce_loss_tensor
def nce_loss ( self , true_logits , sampled_logits ) : opts = self . _options true_xent = tf . nn . sigmoid_cross_entropy_with_logits ( labels = tf . ones_like ( true_logits ) , logits = true_logits ) sampled_xent = tf . nn . sigmoid_cross_entropy_with_logits ( labels = tf . zeros_like ( sampled_logits ) , logits = sampled_logits ) nce_loss_tensor = ( tf . reduce_sum ( true_xent ) + tf . reduce_sum ( sampled_xent ) ) / opts . batch_size return nce_loss_tensor
Build the graph for the NCE loss.
Build the graph for the NCE loss .
"""Build the graph for the NCE loss.""" # cross-entropy(logits, labels) # NCE-loss is the sum of the true and noise (sampled words) # contributions, averaged over the batch.
self
true_logits
sampled_logits