code: def compute_permutation(old_dic, num_spkrs=2):
      """Compute the permutation per utterance."""
      all_scores, all_keys = [], list(old_dic.keys())
      for (
          scores
      ) in old_dic.values():  # compute error rate for each utt_id
          all_scores.append(convert_score(scores, num_spkrs))
      all_scores = np.array(all_scores)  # (B, n_ref, n_hyp, 4)
  
      all_error_rates = np.sum(
          all_scores[:, :, :, 1:4], axis=-1, dtype=float
      ) / np.sum(
          all_scores[:, :, :, 0:3], axis=-1, dtype=float
      )  # (s+d+i) / (c+s+d), (B, n_ref, n_hyp)
  
      min_scores, hyp_perms = [], []
      for idx, error_rate in enumerate(all_error_rates):
          row_idx, col_idx = linear_sum_assignment(error_rate)
  
          hyp_perms.append(col_idx)
          min_scores.append(
              np.sum(all_scores[idx, row_idx, col_idx], axis=0)
          )
  
      min_scores = np.stack(min_scores)
  
      return hyp_perms, all_keys
  
file_path: espnet/egs2/how2_2000h/sum1/pyscripts/utils/eval_perm_free_error.py
imports: import argparse
  import codecs
  import re
  import sys
  from collections import OrderedDict
  from pathlib import Path
  from typing import List
  import numpy
  from scipy.optimize import linear_sum_assignment
label_desc: Use image node_id 3 for calling a global function with example usage: compute_permutation(old_dic, num_spkrs) and returns: hyp_perms,  all_keys