code: def test_forward_does_a_cosine_similarity(self):
      cosine_similarity = CosineSimilarity()
      a_vectors = numpy.random.rand(1, 2, 3)
      b_vectors = numpy.random.rand(1, 2, 3)
      normed_a = a_vectors / numpy.expand_dims(
          numpy.linalg.norm(a_vectors, 2, -1), -1
      )
      normed_b = b_vectors / numpy.expand_dims(
          numpy.linalg.norm(b_vectors, 2, -1), -1
      )
      desired_result = numpy.sum(normed_a * normed_b, axis=-1)
      result = cosine_similarity(
          torch.from_numpy(a_vectors), torch.from_numpy(b_vectors)
      ).data.numpy()
      assert result.shape == (1, 2)
      assert desired_result.shape == (1, 2)
      assert_almost_equal(result, desired_result)
  
file_path: magnitude/pymagnitude/third_party/allennlp/tests/modules/similarity_functions/cosine_test.py
imports: from __future__ import division
  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 CosineSimilarity
  from allennlp.common.testing import AllenNlpTestCase
label_desc: Use image node_id 1 for calling the TestCosineSimilarityFunction obj's underlying member method code with example usage: obj.test_forward_does_a_cosine_similarity() without return types