code: def test_masked_softmax_no_mask(self):
      # Testing the general unmasked 1D case.
      vector_1d = torch.FloatTensor([[1.0, 2.0, 3.0]])
      vector_1d_softmaxed = util.masked_softmax(
          vector_1d, None
      ).data.numpy()
      assert_array_almost_equal(
          vector_1d_softmaxed,
          numpy.array([[0.090031, 0.244728, 0.665241]]),
      )
      assert_almost_equal(
          1.0, numpy.sum(vector_1d_softmaxed), decimal=6
      )
  
      vector_1d = torch.FloatTensor([[1.0, 2.0, 5.0]])
      vector_1d_softmaxed = util.masked_softmax(
          vector_1d, None
      ).data.numpy()
      assert_array_almost_equal(
          vector_1d_softmaxed,
          numpy.array([[0.017148, 0.046613, 0.93624]]),
      )
  
      # Testing the unmasked 1D case where the input is all 0s.
      vector_zero = torch.FloatTensor([[0.0, 0.0, 0.0]])
      vector_zero_softmaxed = util.masked_softmax(
          vector_zero, None
      ).data.numpy()
      assert_array_almost_equal(
          vector_zero_softmaxed,
          numpy.array([[0.33333334, 0.33333334, 0.33333334]]),
      )
  
      # Testing the general unmasked batched case.
      matrix = torch.FloatTensor([[1.0, 2.0, 5.0], [1.0, 2.0, 3.0]])
      masked_matrix_softmaxed = util.masked_softmax(
          matrix, None
      ).data.numpy()
      assert_array_almost_equal(
          masked_matrix_softmaxed,
          numpy.array(
              [
                  [0.01714783, 0.04661262, 0.93623955],
                  [0.09003057, 0.24472847, 0.66524096],
              ]
          ),
      )
  
      # Testing the unmasked batched case where one of the inputs are all 0s.
      matrix = torch.FloatTensor([[1.0, 2.0, 5.0], [0.0, 0.0, 0.0]])
      masked_matrix_softmaxed = util.masked_softmax(
          matrix, None
      ).data.numpy()
      assert_array_almost_equal(
          masked_matrix_softmaxed,
          numpy.array(
              [
                  [0.01714783, 0.04661262, 0.93623955],
                  [0.33333334, 0.33333334, 0.33333334],
              ]
          ),
      )
  
imports: from __future__ import with_statement
  from __future__ import division
  from __future__ import absolute_import
  import numpy
  from numpy.testing import assert_array_almost_equal, assert_almost_equal
  import torch
  import pytest
  from allennlp.common.checks import ConfigurationError
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.nn import util
label_desc: Use image node_id 6 for calling the TestNnUtil obj's underlying member method code with example usage: obj.test_masked_softmax_no_mask() without return types