class_docstr: Can be used to control early stopping with a Trainer class. Any object can be used instead which
  implements the method check_stopping and and provides the attribute save_dir
class_docstr_tok: ["Can","be","used","to","control","early","stopping","with","a","Trainer","class",".","Any","object","can","be","used","instead","which","implements","the","method","check_stopping","and","and","provides","the","attribute","save_dir"]
docstr: :param head: the prediction head referenced by the metric.
  :param save_dir: the directory where to save the final best model, if None, no saving.
  :param metric: name of dev set metric to monitor (default: loss) to get extracted from the 0th head or
                 a function that extracts a value from the trainer dev evaluation result.
                 NOTE: this is different from the metric to get specified for the processor which defines how
                 to calculate one or more evaluation matric values from prediction/target sets, while this
                 specifies the name of one particular such metric value or a method to calculate that value
                 from the result returned from a processor metric.
  :param mode: "min" or "max"
  :param patience: how many evaluations to wait after the best evaluation to stop
  :param min_delta: minimum difference to a previous best value to count as an improvement.
  :param min_evals: minimum number of evaluations to wait before using eval value
docstr_tok: [":","param","head",":","the","prediction","head","referenced","by","the","metric",".",":","param","save_dir",":","the","directory","where","to","save","the","final","best","model",",","if","None",",","no","saving",".",":","param","metric",":","name","of","dev","set","metric","to","monitor","(","default",":","loss",")","to","get","extracted","from","the","0th","head","or","a","function","that","extracts","a","value","from","the","trainer","dev","evaluation","result",".","NOTE",":","this","is","different","from","the","metric","to","get","specified","for","the","processor","which","defines","how","to","calculate","one","or","more","evaluation","matric","values","from","prediction\/target","sets",",","while","this","specifies","the","name","of","one","particular","such","metric","value","or","a","method","to","calculate","that","value","from","the","result","returned","from","a","processor","metric",".",":","param","mode",":","``","min","''","or","``","max","''",":","param","patience",":","how","many","evaluations","to","wait","after","the","best","evaluation","to","stop",":","param","min_delta",":","minimum","difference","to","a","previous","best","value","to","count","as","an","improvement",".",":","param","min_evals",":","minimum","number","of","evaluations","to","wait","before","using","eval","value"]
code: def __init__(
      self,
      head=0,
      metric="loss",
      save_dir=None,
      mode="min",
      patience=0,
      min_delta=0.001,
      min_evals=0,
  ):
      """
      :param head: the prediction head referenced by the metric.
      :param save_dir: the directory where to save the final best model, if None, no saving.
      :param metric: name of dev set metric to monitor (default: loss) to get extracted from the 0th head or
                     a function that extracts a value from the trainer dev evaluation result.
                     NOTE: this is different from the metric to get specified for the processor which defines how
                     to calculate one or more evaluation matric values from prediction/target sets, while this
                     specifies the name of one particular such metric value or a method to calculate that value
                     from the result returned from a processor metric.
      :param mode: "min" or "max"
      :param patience: how many evaluations to wait after the best evaluation to stop
      :param min_delta: minimum difference to a previous best value to count as an improvement.
      :param min_evals: minimum number of evaluations to wait before using eval value
      """
      self.head = head
      self.metric = metric
      self.save_dir = save_dir
      self.mode = mode
      self.patience = patience
      self.min_delta = min_delta
      self.min_evals = min_evals
      self.eval_values = []  # for more complex modes
      self.n_since_best = None
      if mode == "min":
          self.best_so_far = 1.0e99
      elif mode == "max":
          self.best_so_far = -1.0e99
      else:
          raise Exception("Mode must be 'min' or 'max'")
  
imports: import logging
  import sys
  import torch
  from pathlib import Path
  from tqdm import tqdm
  import numpy
  import shutil
  import dill
  from farm.utils import MLFlowLogger
  from farm.utils import GracefulKiller, set_all_seeds
  from farm.eval import Evaluator
  from farm.data_handler.data_silo import DataSilo
  from farm.visual.ascii.images import GROWING_TREE
  from farm.modeling.adaptive_model import AdaptiveModel
  from farm.modeling.biadaptive_model import BiAdaptiveModel
  from farm.modeling.optimization import get_scheduler
label_desc: Use image node_id 1 to create a new EarlyStopping object  with example: obj = EarlyStopping(head, metric, save_dir, mode, patience, min_delta, min_evals)