code: def compute_matching_probability(
      logits: Optional[torch.Tensor] = None,
      embeddings1: Optional[torch.Tensor] = None,
      embeddings2: Optional[torch.Tensor] = None,
      reverse_prob: Optional[bool] = False,
  ):
      """
      Compute probabilities from logits or embedding pairs.
  
      Parameters
      ----------
      logits
          The output of a model's head layer.
      embeddings1
          Feature embeddings of one side in matching.
      embeddings2
          Feature embeddings 2 of the other side in matching.
      reverse_prob
          Whether to reverse the probability.
  
      Returns
      -------
      Probabilities.
      """
      if logits is not None:
          prob = F.softmax(logits.float(), dim=1)[:, 1]
      else:
          cosine_similarity = F.cosine_similarity(
              embeddings1, embeddings2
          )
          prob = 0.5 * (cosine_similarity + 1)
  
      if reverse_prob:
          prob = 1 - prob
  
      return prob
  
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 9 for calling a global function with example usage: compute_matching_probability(logits, embeddings1, embeddings2, reverse_prob) and returns: prob