class_docstr: Learner for Sequence Taggers.
class_docstr_tok: ["Learner","for","Sequence","Taggers","."]
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
  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","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
      Returns:
          list of n tuples where first element is either
          filepath or id of validation example and second element
          is loss.
  
      """
      val = self._check_val(val_data)
      if type(n) == type(42):
          n = (0, n)
  
      # get predicictions and ground truth
      y_pred = self.predict(val_data=val)
      y_true = self.ground_truth(val_data=val)
  
      # compute losses and sort
      losses = []
      for idx, y_t in enumerate(y_true):
          y_p = y_pred[idx]
          # err = 1- sum(1 for x,y in zip(y_t,y_p) if x == y) / len(y_t)
          err = sum(1 for x, y in zip(y_t, y_p) if x != y)
          losses.append(err)
      tups = [
          (i, x, y_true[i], y_pred[i])
          for i, x in enumerate(losses)
          if x > 0
      ]
      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
  
file_path: ktrain/ktrain/text/ner/learner.py
imports: from ...None import utils
  from ...core import GenLearner
  from ...imports import *
  from .None import metrics
label_desc: Use image node_id 3 for calling the NERLearner obj's underlying member method code with example usage: obj.top_losses(n, val_data, preproc) and returns: tups