code: def test_forward_works_with_higher_order_tensors(self):
      dot_product = DotProductSimilarity()
      a_vectors = numpy.random.rand(5, 4, 3, 6, 7)
      b_vectors = numpy.random.rand(5, 4, 3, 6, 7)
      desired_result = numpy.sum(a_vectors * b_vectors, axis=-1)
      result = dot_product(
          torch.from_numpy(a_vectors), torch.from_numpy(b_vectors)
      ).data.numpy()
      assert result.shape == (5, 4, 3, 6)
      # We're cutting this down here with a random partial index, so that if this test fails the
      # output isn't so huge and slow.
      assert_almost_equal(result[2, 3, 1], desired_result[2, 3, 1])
  
file_path: magnitude/pymagnitude/third_party/allennlp/tests/modules/similarity_functions/dot_product_test.py
imports: from __future__ import absolute_import
  import numpy
  from numpy.testing import assert_almost_equal
  import torch
  from allennlp.common import Params
  from allennlp.modules.similarity_functions import DotProductSimilarity
  from allennlp.common.testing import AllenNlpTestCase
label_desc: Use image node_id 2 for calling the TestDotProductSimilarityFunction obj's underlying member method code with example usage: obj.test_forward_works_with_higher_order_tensors() without return types