code: def _inverse_frequency_weighting(
      idx: torch.LongTensor,
  ) -> torch.FloatTensor:
      """Calculate inverse relative frequency weighting."""
      # Calculate in-degree, i.e. number of incoming edges
      inv, cnt = torch.unique(
          idx, return_counts=True, return_inverse=True
      )[1:]
      return cnt[inv].float().reciprocal()
  
imports: from abc import abstractmethod
  from typing import ClassVar, Optional, Union
  import torch
  from class_resolver import ClassResolver
  from torch import nn
  from ..utils import einsum
label_desc: Use image node_id 2 for calling a global function with example usage: _inverse_frequency_weighting(idx) and returns: cnt