Skip to content

Instantly share code, notes, and snippets.

@risenW
Created July 16, 2018 18:56
Show Gist options
  • Save risenW/14792330680ed01a4f2b4ee520a78989 to your computer and use it in GitHub Desktop.
Save risenW/14792330680ed01a4f2b4ee520a78989 to your computer and use it in GitHub Desktop.
Code for cross entropy loss
#Redefining our data
Y_pred = tf.linspace(-4., 6., 500)
Y_label = tf.constant(1.)
Y_labels = tf.fill([500,], 1.)
#applying sigmoid
x_entropy_vals = - tf.multiply(Y_label, tf.log(Y_pred)) - tf.multiply((1. - Y_label), tf.log(1. - Y_pred))
x_entropy_loss = sess.run(x_entropy_vals)
#ploting the predicted values against the cross entropy loss
Y_array = sess.run(Y_pred)
plt.plot(Y_array, x_entropy_loss, 'r-' )
plt.title('Cross entropy loss')
plt.xlabel('$Y_{pred}$', fontsize=15)
plt.ylabel('$Y_{label}$', fontsize=15)
plt.ylim(-2, 5)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment