def categorical_crossentropy(y_pred, y_true):
 with tf.name_scope('Crossentropy'):
  y_pred /= tf.reduce_sum(y_pred, reduction_indices=(len(y_pred.get_shape()) - 1), keep_dims=True)
  y_pred = tf.clip_by_value(y_pred, tf.cast(_EPSILON, dtype=_FLOATX), tf.cast((1.0 - _EPSILON), dtype=_FLOATX))
  cross_entropy = (- tf.reduce_sum((y_true * tf.log(y_pred)), reduction_indices=(len(y_pred.get_shape()) - 1)))
  return tf.reduce_mean(cross_entropy)

def categorical_crossentropy ( y_pred , y_true ) : with tf . name_scope ( 'Crossentropy' ) : y_pred /= tf . reduce_sum ( y_pred , reduction_indices = ( len ( y_pred . get_shape ( ) ) - 1 ) , keep_dims = True ) y_pred = tf . clip_by_value ( y_pred , tf . cast ( _EPSILON , dtype = _FLOATX ) , tf . cast ( ( 1.0 - _EPSILON ) , dtype = _FLOATX ) ) cross_entropy = ( - tf . reduce_sum ( ( y_true * tf . log ( y_pred ) ) , reduction_indices = ( len ( y_pred . get_shape ( ) ) - 1 ) ) ) return tf . reduce_mean ( cross_entropy )
return the cross-entropy between an approximating distribution and a true distribution .