class_docstr: Joint model Enhancement and Speech to Text.
class_docstr_tok: ["Joint","model","Enhancement","and","Speech","to","Text","."]
docstr: The basic permutation loss function.
  
  Args:
      ref (List[torch.Tensor]): [(batch, ...), ...] x n_spk
      inf (List[torch.Tensor]): [(batch, ...), ...]
      criterion (function): Loss function
      perm: (batch)
  Returns:
      loss: torch.Tensor: (batch)
      perm: list[(num_spk)]
docstr_tok: ["The","basic","permutation","loss","function",".","Args",":","ref","(","List","[","torch.Tensor","]",")",":","[","(","batch",",","...",")",",","...","]","x","n_spk","inf","(","List","[","torch.Tensor","]",")",":","[","(","batch",",","...",")",",","...","]","criterion","(","function",")",":","Loss","function","perm",":","(","batch",")","Returns",":","loss",":","torch.Tensor",":","(","batch",")","perm",":","list","[","(","num_spk",")","]"]
code: def _permutation_loss(self, ref, inf, criterion, perm=None):
      """The basic permutation loss function.
  
      Args:
          ref (List[torch.Tensor]): [(batch, ...), ...] x n_spk
          inf (List[torch.Tensor]): [(batch, ...), ...]
          criterion (function): Loss function
          perm: (batch)
      Returns:
          loss: torch.Tensor: (batch)
          perm: list[(num_spk)]
      """
      num_spk = len(ref)
  
      losses = torch.stack(
          [
              torch.stack(
                  [criterion(ref[r], inf[h]) for r in range(num_spk)],
                  dim=1,
              )
              for h in range(num_spk)
          ],
          dim=2,
      )  # (B, n_ref, n_hyp)
      perm_detail, min_loss = self.permutation_invariant_training(
          losses
      )
  
      return min_loss.mean(), perm_detail
  
imports: import logging
  import random
  from contextlib import contextmanager
  from typing import Dict, List, Tuple, Union
  import numpy
  import torch
  import torch.nn.functional
  from packaging.version import parse
  from scipy.optimize import linear_sum_assignment
  from typeguard import check_argument_types
  from espnet2.asr.espnet_model import ESPnetASRModel
  from espnet2.diar.espnet_model import ESPnetDiarizationModel
  from espnet2.enh.espnet_model import ESPnetEnhancementModel
  from espnet2.st.espnet_model import ESPnetSTModel
  from espnet2.torch_utils.device_funcs import force_gatherable
  from espnet2.train.abs_espnet_model import AbsESPnetModel
label_desc: Use image node_id 8 for calling the ESPnetEnhS2TModel obj's underlying member method code with example usage: obj._permutation_loss(ref, inf, criterion, perm) and returns: min_loss,  perm_detail