code: def compute_diar_errors(
      name, hyp_segs, ref_segs, uem_boundaries=None, collar=0.5
  ):
      # computing all diarization errors for each session here.
      # find optimal mapping too, which will then be used to find the WER.
      if uem_boundaries is not None:
          uem = Timeline(
              [Segment(start=uem_boundaries[0], end=uem_boundaries[-1])]
          )
      else:
          uem = None
  
      def to_annotation(segs, name):
          out = Annotation(uri=name)
          for s in segs:
              speaker = s["speaker"]
              start = float(s["start_time"])
              end = float(s["end_time"])
              out[Segment(start, end)] = speaker
          return out
  
      hyp_annotation = to_annotation(hyp_segs, name)
      ref_annotation = to_annotation(ref_segs, name)
  
      der_computer = DERComputer(collar=collar, skip_overlap=False)
      reference, hypothesis, uem = der_computer.get_uemified(
          ref_annotation, hyp_annotation, uem=uem
      )
      mapped, mapping = der_computer.get_optimal_mapping(
          reference, hypothesis
      )
      der_score = der_computer.compute_der(reference, mapped, uem=uem)
      # avoid uemify again with custom class
      jer_compute = JERComputer(
          collar=collar, skip_overlap=False
      )  # not optimal computationally
      jer_score = jer_compute.compute_jer(
          reference, hypothesis, {v: k for k, v in mapping.items()}
      )
      if DEBUG:
          from pyannote.metrics.diarization import (  # isort: skip
              DiarizationErrorRate,
              JaccardErrorRate,
          )
  
          orig_jer = JaccardErrorRate(collar=collar, skip_overlap=False)
          orig_der = DiarizationErrorRate(
              collar=collar, skip_overlap=False
          )
          jer_test = orig_jer(ref_annotation, hyp_annotation, uem=uem)
          der_test = orig_der(ref_annotation, hyp_annotation, uem=uem)
          assert abs(jer_score["Jaccard error rate"] - jer_test) < 1e-4
          assert (
              abs(der_test - der_score["diarization error rate"]) < 1e-4
          )
  
      # error analysis here
      error_compute = IdentificationErrorAnalysis(
          collar=collar, skip_overlap=False
      )
      reference, hypothesis, errors = error_compute.difference(
          ref_annotation, hyp_annotation, uem=uem, uemified=True
      )
  
      return (
          mapping,
          der_score,
          jer_score,
          reference,
          hypothesis,
          errors,
      )
  
imports: import argparse
  import glob
  import json
  import os
  import pickle
  import warnings
  from collections import OrderedDict
  from copy import deepcopy
  from pathlib import Path
  from typing import Dict, Optional
  import jiwer
  import pandas
  from pyannote.core.utils.types import Label
  from pyannote.metrics.diarization import DiarizationErrorRate
  from pyannote.metrics.errors.identification import IdentificationErrorAnalysis
  from pyannote.metrics.identification import IdentificationErrorRate
  from pyannote.metrics.matcher import HungarianMapper
  from pyannote.metrics.segmentation import Annotation, Segment, Timeline
  from pyannote.metrics.types import MetricComponents
  from tabulate import tabulate
  from tqdm import tqdm
label_desc: Use image node_id 4 for calling a global function with example usage: compute_diar_errors(name, hyp_segs, ref_segs, uem_boundaries, collar) and returns: mapping,  der_score,  jer_score,  reference,  hypothesis,  errors, out