code: def dot_product(a: torch.Tensor, b: torch.Tensor, normalize=False):
      """Computes dot product for pairs of vectors.
  
      Args:
          a: the left tensor
          b: the right tensor
          normalize: Vectors are normalized (leads to cosine similarity)
  
      Returns: Matrix with res[i][j] = dot_product(a[i], b[j])
      """
      if len(a.shape) == 1:
          a = a.unsqueeze(0)
  
      if len(b.shape) == 1:
          b = b.unsqueeze(0)
  
      if normalize:
          a = torch.nn.functional.normalize(a, p=2, dim=1)
          b = torch.nn.functional.normalize(b, p=2, dim=1)
  
      return torch.mm(a, b.transpose(0, 1))
  
file_path: flair/flair/nn/distance/cosine.py
imports: import torch
label_desc: Use image node_id 1 for calling a global function with example usage: dot_product(a, b, normalize) and returns: torch