code: def wer_cer_batch(samples):
      r"""
      The WER is defined as the edit/Levenshtein distance on word level divided by
      the amount of words in the original text.
      In case of the original having more words (N) than the result and both
      being totally different (all N words resulting in 1 edit operation each),
      the WER will always be 1 (N / N = 1).
      """
      wer = sum(s.word_distance for s in samples) / sum(
          s.word_length for s in samples
      )
      cer = sum(s.char_distance for s in samples) / sum(
          s.char_length for s in samples
      )
  
      wer = min(wer, 1.0)
      cer = min(cer, 1.0)
  
      return wer, cer
  
file_path: DeepSpeech/training/deepspeech_training/util/evaluate_tools.py
imports: from __future__ import absolute_import, division, print_function
  import json
  from multiprocessing.dummy import Pool
  import numpy
  from attrdict import AttrDict
  from .flags import FLAGS
  from .text import levenshtein
  from .io import open_remote
label_desc: Use image node_id 2 for calling a global function with example usage: wer_cer_batch(samples) and returns: wer,  cer