code: def compute_semantic_similarity(
      a: torch.Tensor,
      b: torch.Tensor,
      similarity_type: Optional[str] = "cosine",
  ):
      """
      Compute the semantic similarity of each vector in `a` with each vector in `b`.
  
      Parameters
      ----------
      a
          A tensor with shape (n, dim).
      b
          A tensor with shape (m, dim).
      similarity_type
          Use what function (cosine/dot_prod) to score the similarity (default: cosine).
  
      Returns
      -------
      A similarity matrix with shape (n, m).
      """
      if not isinstance(a, torch.Tensor):
          a = torch.as_tensor(a)
  
      if not isinstance(b, torch.Tensor):
          b = torch.as_tensor(b)
  
      if len(a.shape) == 1:
          a = a.unsqueeze(0)
  
      if len(b.shape) == 1:
          b = b.unsqueeze(0)
  
      if similarity_type == "cosine":
          a = torch.nn.functional.normalize(a, p=2, dim=1)
          b = torch.nn.functional.normalize(b, p=2, dim=1)
      elif similarity_type == "dot_prod":
          pass
      else:
          raise ValueError(
              f"Invalid similarity type: {similarity_type}. The supported types are `cosine` and `dot_prod`."
          )
  
      return torch.mm(a, b.transpose(0, 1))
  
imports: import copy
  import functools
  import heapq
  import logging
  from typing import Dict, List, Optional, Union
  import pandas
  import torch
  from omegaconf import DictConfig
  from torch import nn
  from torch.nn import functional
  from ..constants import FUSION, QUERY, RESPONSE
  from .data import data_to_df
  from .model import create_model
label_desc: Use image node_id 6 for calling a global function with example usage: compute_semantic_similarity(a, b, similarity_type) and returns: torch