()
return base.Fn('_CrossEntropy', f)
Returns a layer that computes prediction-target cross entropies.
Returns a layer that computes prediction-target cross entropies.
Returns a layer that computes prediction - target cross entropies .
def _CrossEntropy():
  """Returns a layer that computes prediction-target cross entropies."""
  def f(model_output, target_category):  # pylint: disable=invalid-name
    # TODO(pkozakowski): This assertion breaks some tests. Fix and uncomment.
    # shapes.assert_shape_equals(target_category, model_output.shape[:-1])
    target_distribution = core.one_hot(target_category, model_output.shape[-1])
    return -1.0 * jnp.sum(model_output * target_distribution, axis=-1)
  return base.Fn('_CrossEntropy', f)
def _CrossEntropy ( ) : def f ( model_output , target_category ) : # pylint: disable=invalid-name # TODO(pkozakowski): This assertion breaks some tests. Fix and uncomment. # shapes.assert_shape_equals(target_category, model_output.shape[:-1]) target_distribution = core . one_hot ( target_category , model_output . shape [ - 1 ] ) return - 1.0 * jnp . sum ( model_output * target_distribution , axis = - 1 ) return base . Fn ( '_CrossEntropy' , f )