code: def _create_mask_label(
      mix_spec, ref_spec, noise_spec=None, mask_type="IAM"
  ):
      """Create mask label.
  
      Args:
          mix_spec: ComplexTensor(B, T, [C,] F)
          ref_spec: List[ComplexTensor(B, T, [C,] F), ...]
          noise_spec: ComplexTensor(B, T, [C,] F)
              only used for IBM and IRM
          mask_type: str
      Returns:
          labels: List[Tensor(B, T, [C,] F), ...] or List[ComplexTensor(B, T, F), ...]
      """
  
      # Must be upper case
      mask_type = mask_type.upper()
      assert mask_type in [
          "IBM",
          "IRM",
          "IAM",
          "PSM",
          "NPSM",
          "PSM^2",
          "CIRM",
      ], f"mask type {mask_type} not supported"
      mask_label = []
      if ref_spec[0].ndim < mix_spec.ndim:
          # (B, T, F) -> (B, T, 1, F)
          ref_spec = [
              r.unsqueeze(2).expand_as(mix_spec.real) for r in ref_spec
          ]
      if noise_spec is not None and noise_spec.ndim < mix_spec.ndim:
          # (B, T, F) -> (B, T, 1, F)
          noise_spec = noise_spec.unsqueeze(2).expand_as(mix_spec.real)
      for idx, r in enumerate(ref_spec):
          mask = None
          if mask_type == "IBM":
              if noise_spec is None:
                  flags = [abs(r) >= abs(n) for n in ref_spec]
              else:
                  flags = [
                      abs(r) >= abs(n) for n in ref_spec + [noise_spec]
                  ]
              mask = reduce(lambda x, y: x * y, flags)
              mask = mask.int()
          elif mask_type == "IRM":
              beta = 0.5
              res_spec = sum(
                  n for i, n in enumerate(ref_spec) if i != idx
              )
              if noise_spec is not None:
                  res_spec += noise_spec
              mask = (abs(r).pow(2) / (abs(res_spec).pow(2) + EPS)).pow(
                  beta
              )
          elif mask_type == "IAM":
              mask = abs(r) / (abs(mix_spec) + EPS)
              mask = mask.clamp(min=0, max=1)
          elif mask_type == "PSM" or mask_type == "NPSM":
              phase_r = r / (abs(r) + EPS)
              phase_mix = mix_spec / (abs(mix_spec) + EPS)
              # cos(a - b) = cos(a)*cos(b) + sin(a)*sin(b)
              cos_theta = (
                  phase_r.real * phase_mix.real
                  + phase_r.imag * phase_mix.imag
              )
              mask = (abs(r) / (abs(mix_spec) + EPS)) * cos_theta
              mask = (
                  mask.clamp(min=0, max=1)
                  if mask_type == "NPSM"
                  else mask.clamp(min=-1, max=1)
              )
          elif mask_type == "PSM^2":
              # This is for training beamforming masks
              phase_r = r / (abs(r) + EPS)
              phase_mix = mix_spec / (abs(mix_spec) + EPS)
              # cos(a - b) = cos(a)*cos(b) + sin(a)*sin(b)
              cos_theta = (
                  phase_r.real * phase_mix.real
                  + phase_r.imag * phase_mix.imag
              )
              mask = (
                  abs(r).pow(2) / (abs(mix_spec).pow(2) + EPS)
              ) * cos_theta
              mask = mask.clamp(min=-1, max=1)
          elif mask_type == "CIRM":
              # Ref: Complex Ratio Masking for Monaural Speech Separation
              denominator = (
                  mix_spec.real.pow(2) + mix_spec.imag.pow(2) + EPS
              )
              mask_real = (
                  mix_spec.real * r.real + mix_spec.imag * r.imag
              ) / denominator
              mask_imag = (
                  mix_spec.real * r.imag - mix_spec.imag * r.real
              ) / denominator
              mask = new_complex_like(mix_spec, [mask_real, mask_imag])
          assert (
              mask is not None
          ), f"mask type {mask_type} not supported"
          mask_label.append(mask)
      return mask_label
  
imports: import math
  from abc import ABC, abstractmethod
  from functools import reduce
  import torch
  import torch.nn.functional
  from packaging.version import parse
  from espnet2.enh.layers.complex_utils import complex_norm, is_complex, new_complex_like
  from espnet2.enh.loss.criterions.abs_loss import AbsEnhLoss
label_desc: Use image node_id 1 for calling a global function with example usage: _create_mask_label(mix_spec, ref_spec, noise_spec, mask_type) and returns: mask_label