code: def cal_cos_similarity(
      self, x, y
  ):  # the 2nd dimension of x and y are the same
      xy = x.mm(torch.t(y))
      x_norm = torch.sqrt(torch.sum(x * x, dim=1)).reshape(-1, 1)
      y_norm = torch.sqrt(torch.sum(y * y, dim=1)).reshape(-1, 1)
      cos_similarity = xy / (x_norm.mm(torch.t(y_norm)) + 1e-6)
      return cos_similarity
  
imports: from __future__ import division
  from __future__ import print_function
  import numpy
  import pandas
  from typing import Text, Union
  import copy
  from ...utils import get_or_create_path
  from ...log import get_module_logger
  import torch
  import torch.nn
  import torch.optim
  from .pytorch_utils import count_parameters
  from ...model.base import Model
  from ...data.dataset import DatasetH
  from ...data.dataset.handler import DataHandlerLP
  from ...contrib.model.pytorch_lstm import LSTMModel
  from ...contrib.model.pytorch_gru import GRUModel
label_desc: Use image node_id 2 for calling the IGMTFModel obj's underlying member method code with example usage: obj.cal_cos_similarity(x, y) and returns: cos_similarity