class_docstr: ```
  Abstract class used to tune and train Keras models. The fit method is
  an abstract method and must be implemented by subclasses.
  ```
class_docstr_tok: ["``","`","Abstract","class","used","to","tune","and","train","Keras","models",".","The","fit","method","is","an","abstract","method","and","must","be","implemented","by","subclasses",".","``","`"]
docstr: ```
  Computes losses on validation set sorted by examples with top losses
  Args:
    n(int or tuple): a range to select in form of int or tuple
                    e.g., n=8 is treated as n=(0,8)
    val_data:  optional val_data to use instead of self.val_data
    preproc (Preprocessor): A TextPreprocessor or ImagePreprocessor.
                            For some data like text data, a preprocessor
                            is required to undo the pre-processing
                             to correctly view raw data.
  Returns:
      list of n tuples where first element is either
      filepath or id of validation example and second element
      is loss.
  ```
docstr_tok: ["``","`","Computes","losses","on","validation","set","sorted","by","examples","with","top","losses","Args",":","n","(","int","or","tuple",")",":","a","range","to","select","in","form","of","int","or","tuple","e.g.",",","n=8","is","treated","as","n=","(","0,8",")","val_data",":","optional","val_data","to","use","instead","of","self.val_data","preproc","(","Preprocessor",")",":","A","TextPreprocessor","or","ImagePreprocessor",".","For","some","data","like","text","data",",","a","preprocessor","is","required","to","undo","the","pre-processing","to","correctly","view","raw","data",".","Returns",":","list","of","n","tuples","where","first","element","is","either","filepath","or","id","of","validation","example","and","second","element","is","loss",".","``","`"]
code: def top_losses(self, n=4, val_data=None, preproc=None):
      """
      ```
      Computes losses on validation set sorted by examples with top losses
      Args:
        n(int or tuple): a range to select in form of int or tuple
                        e.g., n=8 is treated as n=(0,8)
        val_data:  optional val_data to use instead of self.val_data
        preproc (Preprocessor): A TextPreprocessor or ImagePreprocessor.
                                For some data like text data, a preprocessor
                                is required to undo the pre-processing
                                 to correctly view raw data.
      Returns:
          list of n tuples where first element is either
          filepath or id of validation example and second element
          is loss.
      ```
      """
  
      # check validation data and arguments
      if val_data is not None:
          val = val_data
      else:
          val = self.val_data
      if val is None:
          raise Exception(
              "val_data must be supplied to get_learner or top_losses"
          )
      if type(n) == type(42):
          n = (0, n)
  
      # multilabel = True if U.is_multilabel(val) else False
      classification, multilabel = U.is_classifier(self.model)
  
      # get predicictions and ground truth
      y_pred = self.predict(val_data=val)
      y_true = self.ground_truth(val_data=val)
      y_true = y_true.astype("float32")
  
      # adjust y_true for regression problems
      if (
          not classification
          and len(y_true.shape) == 1
          and (len(y_pred.shape) == 2 and y_pred.shape[1] == 1)
      ):
          y_true = np.expand_dims(y_true, -1)
  
      # compute loss
      # this doesn't work in tf.keras 1.14
      # losses = self.model.loss_functions[0](tf.convert_to_tensor(y_true), tf.convert_to_tensor(y_pred))
      # if U.is_tf_keras():
      # L = self.model.loss_functions[0].fn
      # else:
      # L = self.model.loss_functions[0]
      L = U.loss_fn_from_model(self.model)
      losses = L(
          tf.convert_to_tensor(y_true), tf.convert_to_tensor(y_pred)
      )
      if DISABLE_V2_BEHAVIOR:
          losses = tf.Session().run(losses)
      else:
          losses = losses.numpy()
  
      class_names = [] if preproc is None else preproc.get_classes()
      if preproc is None:
          class_fcn = lambda x: "%s" % (x)
      else:
          class_fcn = lambda x: class_names[x]
  
      # regression output modifications
      if not classification:
          if len(y_pred.shape) == 2 and y_pred.shape[1] == 1:
              y_pred = np.squeeze(y_pred)
              y_pred = np.around(y_pred, 2)
          if len(y_true.shape) == 2 and y_true.shape[1] == 1:
              y_true = np.squeeze(y_true)
              y_true = np.around(y_true, 2)
  
      # sort by loss and prune correct classifications, if necessary
      if classification and not multilabel:
          y_pred = np.squeeze(y_pred)
          y_true = np.squeeze(y_true)
          if len(y_pred.shape) == 1:
              y_p = np.where(y_pred > 0.5, 1, 0)
              y_t = np.where(y_true > 0.5, 1, 0)
          else:
              y_p = np.argmax(y_pred, axis=1)
              y_t = np.argmax(y_true, axis=1)
          tups = [
              (i, x, class_fcn(y_t[i]), class_fcn(y_p[i]))
              for i, x in enumerate(losses)
              if y_p[i] != y_t[i]
          ]
      else:
          tups = [
              (i, x, y_true[i], np.around(y_pred[i], 2))
              for i, x in enumerate(losses)
          ]
      tups.sort(key=operator.itemgetter(1), reverse=True)
  
      # prune by given range
      tups = tups[n[0] : n[1]] if n is not None else tups
      return tups
  
imports: from .None import utils
  from .graph.predictor import LinkPredictor, NodePredictor
  from .graph.preprocessor import LinkPreprocessor, NodePreprocessor
  from .imports import *
  from .lroptimize.lrfinder import *
  from .tabular.predictor import TabularPredictor
  from .tabular.preprocessor import TabularPreprocessor
  from .text.ner.predictor import NERPredictor
  from .text.ner.preprocessor import NERPreprocessor
  from .text.predictor import TextPredictor
  from .text.preprocessor import BERTPreprocessor, TextPreprocessor, TransformersPreprocessor
  from .vision.predictor import ImagePredictor
  from .vision.preprocessor import ImagePreprocessor
label_desc: Use image node_id 8 for calling the Learner obj's underlying member method code with example usage: obj.top_losses(n, val_data, preproc) and returns: tups