class_docstr: Test loss functions.
class_docstr_tok: ["Test","loss","functions","."]
docstr: Test SparseSoftmaxCrossEntropy.
code: def test_sparse_softmax_cross_entropy_tf(self):
      """Test SparseSoftmaxCrossEntropy."""
      loss = losses.SparseSoftmaxCrossEntropy()
      y = np.array([[0.1, 0.8], [0.4, 0.6]])
      outputs = tf.constant(y)
      labels = tf.constant([1, 0])
      result = loss._compute_tf_loss(outputs, labels).numpy()
      softmax = np.exp(y) / np.expand_dims(np.sum(np.exp(y), axis=1), 1)
      expected = [-np.log(softmax[0, 1]), -np.log(softmax[1, 0])]
      assert np.allclose(expected, result)
  
      labels = tf.constant([[1], [0]])
      result = loss._compute_tf_loss(outputs, labels).numpy()
      softmax = np.exp(y) / np.expand_dims(np.sum(np.exp(y), axis=1), 1)
      expected = [-np.log(softmax[0, 1]), -np.log(softmax[1, 0])]
      assert np.allclose(expected, result)
  
imports: import unittest
  import numpy
  import pytest
  import deepchem
  import deepchem.models.losses
label_desc: Use image node_id 21 for calling the TestLosses obj's underlying member method code with example usage: obj.test_sparse_softmax_cross_entropy_tf() without return types