Skip to content

Instantly share code, notes, and snippets.

@risenW
Created July 16, 2018 19:00
Show Gist options
  • Save risenW/a7086a6af81e0d949f998016630e3b6e to your computer and use it in GitHub Desktop.
Save risenW/a7086a6af81e0d949f998016630e3b6e to your computer and use it in GitHub Desktop.
Code for Sparse softmax cross entropy
y_pred = tf.constant([[1., -3., 10.]])
sparse_target_dist = tf.constant([2]) #true value is in the second position of the sparse tensor
sparse_x_entropy = tf.nn.sparse_softmax_cross_entropy_with_logits(labels= sparse_target_dist, logits=y_pred)
print(sess.run(sparse_x_entropy))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment