class_docstr: Class for creating and setting up fuzzy matchers.
class_docstr_tok: ["Class","for","creating","and","setting","up","fuzzy","matchers","."]
code: def _get_batch_matches(self, batch):
      logger.debug(f"Starting fuzzy matching on {len(batch)} examples")
      fuzzy_count = 0
      start = time.time()
      augmented = list()
  
      # We split the `batch` and perform fuzzy matching
      # in smaller chunks of 10.000 examples in order to
      # reduce memory usage.
      # Perfomance is not affected.
      chunk_size = 10000
      mini_batches = np.array_split(
          batch,
          len(batch) // chunk_size if len(batch) > chunk_size else 1,
      )
      for mini_batch in mini_batches:
          plist = list(mini_batch)
          if fuzzy_count >= len(batch) * self.corpus_ratio:
              augmented.extend(plist)
              continue
  
          results = process.cdist(
              plist,
              self.internal_tm[0],
              scorer=fuzz.ratio,
              dtype=np.uint8,
              score_cutoff=self.threshold,
              workers=-1,
          )
  
          matches = np.any(results, 1)
          argmax = np.argmax(results, axis=1)
          for idx, s in enumerate(plist):
              # Probably redundant but let's be safe
              # in case some examples are already fuzzied
              # (e.g. from another pipeline or workflow)
              if self.fuzzy_token in s:
                  continue
              # We don't want exact matches
              if matches[idx] and results[idx][argmax[idx]] < 100:
                  if fuzzy_count >= len(batch) * self.corpus_ratio:
                      break
                  plist[idx] = (
                      s
                      + self.fuzzy_token
                      + self.internal_tm[1][argmax[idx]]
                  )
                  fuzzy_count += 1
          augmented.extend(plist)
  
      end = time.time()
      logger.debug(
          f"FuzzyMatch Transform: Added {fuzzy_count} "
          f"fuzzies in {end-start} secs"
      )
  
      return augmented
  
imports: from onmt.utils.logging import logger
  from onmt.transforms import register_transform
  from .transform import Transform
  from rapidfuzz import fuzz, process
  import numpy
  import time
label_desc: Use image node_id 3 for calling the FuzzyMatcher obj's underlying member method code with example usage: obj._get_batch_matches(batch) and returns: augmented