docstr: uses patience and the validation metric to determine if training should stop early
docstr_tok: ["uses","patience","and","the","validation","metric","to","determine","if","training","should","stop","early"]
code: def _should_stop_early(self, metric_history):
      """
      uses patience and the validation metric to determine if training should stop early
      """
      if self._patience and self._patience < len(metric_history):
          # Pylint can't figure out that in this branch `self._patience` is an int.
          # pylint: disable=invalid-unary-operand-type
  
          # Is the best score in the past N epochs worse than or equal the best score overall?
          if self._validation_metric_decreases:
              return min(metric_history[-self._patience :]) >= min(
                  metric_history[: -self._patience]
              )
          else:
              return max(metric_history[-self._patience :]) <= max(
                  metric_history[: -self._patience]
              )
  
      return False
  
imports: from __future__ import with_statement
  from __future__ import division
  from __future__ import absolute_import
  import logging
  import os
  import shutil
  import time
  import re
  import datetime
  import traceback
  import torch
  import torch.optim.lr_scheduler
  from torch.nn.parallel import replicate, parallel_apply
  from torch.nn.parallel.scatter_gather import scatter_kwargs, gather
  from allennlp.common import Params
  from allennlp.common.checks import ConfigurationError
  from allennlp.common.util import peak_memory_mb, gpu_memory_mb
  from allennlp.common.tqdm import Tqdm
  from allennlp.data.instance import Instance
  from allennlp.data.iterators.data_iterator import DataIterator
  from allennlp.models.model import Model
  from allennlp.nn import util
  from allennlp.training.learning_rate_schedulers import LearningRateScheduler
  from allennlp.training.optimizers import Optimizer
label_desc: Use image node_id 9 for calling the Trainer obj's underlying member method code with example usage: obj._should_stop_early(metric_history) and returns: False, unknown, unknown