code: def cluster(
      dupes: Scores, threshold: float = 0.5, max_components: int = 30000
  ) -> Clusters:
      """
      Takes in a list of duplicate pairs and clusters them in to a
      list records that all refer to the same entity based on a given
      threshold
  
      Keyword arguments:
      threshold -- number between 0 and 1 (default is .5). lowering the
                   number will increase precision, raising it will increase
                   recall
      """
      distance_threshold = 1 - threshold
      dupe_sub_graphs = connected_components(dupes, max_components)
  
      for sub_graph in dupe_sub_graphs:
          if len(sub_graph) > 1:
              i_to_id, condensed_distances, N = condensedDistance(
                  sub_graph
              )
  
              linkage = scipy.cluster.hierarchy.linkage(
                  condensed_distances, method="centroid"
              )
  
              partition = scipy.cluster.hierarchy.fcluster(
                  linkage, distance_threshold, criterion="distance"
              )
  
              clusters: dict[int, list[int]] = defaultdict(list)
  
              for i, cluster_id in enumerate(partition):
                  clusters[cluster_id].append(i)
  
              squared_distances = condensed_distances**2
              for cluster in clusters.values():
                  if len(cluster) > 1:
                      scores = confidences(
                          cluster, squared_distances, N
                      )
                      yield tuple(i_to_id[i] for i in cluster), scores  # type: ignore[misc]
  
          else:
              ((ids, score),) = sub_graph
              if score > threshold:
                  yield tuple(ids), (score,) * 2
  
imports: from __future__ import annotations
  import array
  import itertools
  import logging
  import tempfile
  from collections import defaultdict
  from typing import Generator, Iterable, Sequence, cast
  import numpy
  import numpy.typing
  import scipy.cluster.hierarchy
  from dedupe._typing import ArrayLinks, Clusters, RecordID, Scores, TupleLinks
label_desc: Use image node_id 5 for calling a global function with example usage: cluster(dupes, threshold, max_components) without return types