code: def test_op_cross_entropy_with_soft_max(
      output_vector, target_vector, device_id, precision
  ):
      dt = PRECISION_TO_TYPE[precision]
  
      o = AA(output_vector, dtype=dt)
      t = AA(target_vector, dtype=dt)
  
      ox = o - o.max()  # subtract max to avoid overflow
      exp_x = np.exp(ox)
      s_max = exp_x / np.sum(exp_x)  # softmax function
  
      expected_forward = np.asarray(
          -np.sum(t * np.log(s_max, dtype=dt), dtype=dt)
      )
      expected_forward.shape = (1, 1, 1) + expected_forward.shape
  
      s = np.sum(t, dtype=dt)
      backward = np.subtract(s_max * s, t)
      backward.shape = (1,) + backward.shape
  
      expected_backward = {"left_arg": backward, "right_arg": [-1 * o]}
  
      from cntk.losses import cross_entropy_with_softmax
  
      _test_binary_op(
          precision,
          device_id,
          cross_entropy_with_softmax,
          output_vector,
          target_vector,
          expected_forward,
          expected_backward,
      )
  
file_path: CNTK/bindings/python/cntk/losses/tests/losses_test.py
imports: from __future__ import division
  import numpy
  import pytest
  import cntk
  from cntk.ops.tests.ops_test_utils import _test_binary_op, AA, precision, PRECISION_TO_TYPE, unittest_helper
label_desc: Use image node_id 1 for calling a global function with example usage: test_op_cross_entropy_with_soft_max(output_vector, target_vector, device_id, precision) without return types