code: def _loss(self, inputs, targets, outputs) -> Dict[str, AnyTensor]:
      def to_2d_list(x):
          return K.expand_dims(K.flatten(x), axis=-1)
  
      # note: blank is last index
      losses = {
          "loss": K.ctc_batch_cost(
              targets["gt"] - 1,
              outputs["blank_last_softmax"],
              to_2d_list(outputs["out_len"]),
              to_2d_list(targets["gt_len"]),
          )
      }
  
      for i in range(self._params.ensemble):
          losses[f"loss_{i}"] = K.ctc_batch_cost(
              targets["gt"] - 1,
              outputs[f"blank_last_softmax_{i}"],
              to_2d_list(outputs[f"out_len_{i}"]),
              to_2d_list(targets["gt_len"]),
          )
  
      return losses
  
imports: from dataclasses import dataclass
  import tensorflow
  from typing import Dict, List, Tuple
  import bidi.algorithm
  import Levenshtein
  from paiargparse import pai_dataclass
  from tfaip import Sample
  from tfaip.model.modelbase import ModelBase
  from tfaip.util.tftyping import AnyTensor
  from calamari_ocr.ocr.model.params import ModelParams
  from tensorflow.python.ops import math_ops
  from calamari_ocr.ocr.model.ensemblegraph import EnsembleGraph
label_desc: Use image node_id 3 for calling the EnsembleModel obj's underlying member method code with example usage: obj._loss(inputs, targets, outputs) and returns: losses, K