class_docstr: Calculate CER and WER for E2E_ASR and CTC models during training.
  
  :param y_hats: numpy array with predicted text
  :param y_pads: numpy array with true (target) text
  :param char_list:
  :param sym_space:
  :param sym_blank:
  :return:
docstr: Calculate sentence-level CER score for CTC.
  
  :param torch.Tensor ys_hat: prediction (batch, seqlen)
  :param torch.Tensor ys_pad: reference (batch, seqlen)
  :return: average sentence-level CER score
  :rtype float
docstr_tok: ["Calculate","sentence-level","CER","score","for","CTC",".",":","param","torch.Tensor","ys_hat",":","prediction","(","batch",",","seqlen",")",":","param","torch.Tensor","ys_pad",":","reference","(","batch",",","seqlen",")",":","return",":","average","sentence-level","CER","score",":","rtype","float"]
code: def calculate_cer_ctc(self, ys_hat, ys_pad):
      """Calculate sentence-level CER score for CTC.
  
      :param torch.Tensor ys_hat: prediction (batch, seqlen)
      :param torch.Tensor ys_pad: reference (batch, seqlen)
      :return: average sentence-level CER score
      :rtype float
      """
      import editdistance
  
      cers, char_ref_lens = [], []
      for i, y in enumerate(ys_hat):
          y_hat = [x[0] for x in groupby(y)]
          y_true = ys_pad[i]
          seq_hat, seq_true = [], []
          for idx in y_hat:
              idx = int(idx)
              if (
                  idx != -1
                  and idx != self.idx_blank
                  and idx != self.idx_space
              ):
                  seq_hat.append(self.char_list[int(idx)])
  
          for idx in y_true:
              idx = int(idx)
              if (
                  idx != -1
                  and idx != self.idx_blank
                  and idx != self.idx_space
              ):
                  seq_true.append(self.char_list[int(idx)])
  
          hyp_chars = "".join(seq_hat)
          ref_chars = "".join(seq_true)
          if len(ref_chars) > 0:
              cers.append(editdistance.eval(hyp_chars, ref_chars))
              char_ref_lens.append(len(ref_chars))
  
      cer_ctc = float(sum(cers)) / sum(char_ref_lens) if cers else None
      return cer_ctc
  
file_path: espnet/espnet/nets/e2e_asr_common.py
imports: import json
  import logging
  import sys
  from itertools import groupby
  import numpy
label_desc: Use image node_id 3 for calling the ErrorCalculator obj's underlying member method code with example usage: obj.calculate_cer_ctc(ys_hat, ys_pad) and returns: cer_ctc