code: def early_stopping(value, best, cur_step, max_step, bigger=True):
      r"""validation-based early stopping
  
      Args:
          value (float): current result
          best (float): best result
          cur_step (int): the number of consecutive steps that did not exceed the best result
          max_step (int): threshold steps for stopping
          bigger (bool, optional): whether the bigger the better
  
      Returns:
          tuple:
          - float,
            best result after this step
          - int,
            the number of consecutive steps that did not exceed the best result after this step
          - bool,
            whether to stop
          - bool,
            whether to update
      """
      stop_flag = False
      update_flag = False
      if bigger:
          if value >= best:
              cur_step = 0
              best = value
              update_flag = True
          else:
              cur_step += 1
              if cur_step > max_step:
                  stop_flag = True
      else:
          if value <= best:
              cur_step = 0
              best = value
              update_flag = True
          else:
              cur_step += 1
              if cur_step > max_step:
                  stop_flag = True
      return best, cur_step, stop_flag, update_flag
  
imports: import datetime
  import importlib
  import os
  import random
  import pandas
  import numpy
  import torch
  import torch.nn
  from torch.utils.tensorboard import SummaryWriter
  from texttable import Texttable
  from recbole.utils.enum_type import ModelType
label_desc: Use image node_id 5 for calling a global function with example usage: early_stopping(value, best, cur_step, max_step, bigger) and returns: best,  cur_step,  stop_flag,  update_flag