class_docstr: 用于 early stop 的 callback 。当监控的结果连续多少次没有变好便 raise 一个 :class:`EarlyStopException` 。
  
  :param monitor: 监控的 metric 值。
  
      * 为 ``None``
       将尝试使用 :class:`~fastNLP.core.controllers.Trainer` 中设置 `monitor` 值（如果有设置）。
      * 为 ``str``
       尝试直接使用该名称从 ``evaluation`` 结果中寻找，如果在 ``evaluation`` 结果中没有找到完全一致的名称，将
       使用 最长公共字符串算法 从 ``evaluation`` 结果中找到最匹配的那个作为 ``monitor`` 。
      * 为 :class:`Callable`
       接受参数为 ``evaluation`` 的结果(字典类型)，返回一个 ``float`` 值作为 ``monitor`` 的结果，如果当前结果中没有相关
       的 ``monitor`` 值请返回 ``None`` 。
  :param larger_better: monitor 的值是否是越大越好。
  :param patience: 多少次 evaluate 不没有提升就停止。
class_docstr_tok: ["\u7528\u4e8e","early","stop","\u7684","callback","\u3002\u5f53\u76d1\u63a7\u7684\u7ed3\u679c\u8fde\u7eed\u591a\u5c11\u6b21\u6ca1\u6709\u53d8\u597d\u4fbf","raise","\u4e00\u4e2a",":","class",":","`","EarlyStopException","`","\u3002",":","param","monitor",":","\u76d1\u63a7\u7684","metric","\u503c\u3002","*","\u4e3a","``","None","``","\u5c06\u5c1d\u8bd5\u4f7f\u7528",":","class",":","`","~fastNLP.core.controllers.Trainer","`","\u4e2d\u8bbe\u7f6e","`","monitor","`","\u503c\uff08\u5982\u679c\u6709\u8bbe\u7f6e\uff09\u3002","*","\u4e3a","``","str","``","\u5c1d\u8bd5\u76f4\u63a5\u4f7f\u7528\u8be5\u540d\u79f0\u4ece","``","evaluation","``","\u7ed3\u679c\u4e2d\u5bfb\u627e\uff0c\u5982\u679c\u5728","``","evaluation","``","\u7ed3\u679c\u4e2d\u6ca1\u6709\u627e\u5230\u5b8c\u5168\u4e00\u81f4\u7684\u540d\u79f0\uff0c\u5c06","\u4f7f\u7528","\u6700\u957f\u516c\u5171\u5b57\u7b26\u4e32\u7b97\u6cd5","\u4ece","``","evaluation","``","\u7ed3\u679c\u4e2d\u627e\u5230\u6700\u5339\u914d\u7684\u90a3\u4e2a\u4f5c\u4e3a","``","monitor","``","\u3002","*","\u4e3a",":","class",":","`","Callable","`","\u63a5\u53d7\u53c2\u6570\u4e3a","``","evaluation","``","\u7684\u7ed3\u679c","(","\u5b57\u5178\u7c7b\u578b",")","\uff0c\u8fd4\u56de\u4e00\u4e2a","``","float","``","\u503c\u4f5c\u4e3a","``","monitor","``","\u7684\u7ed3\u679c\uff0c\u5982\u679c\u5f53\u524d\u7ed3\u679c\u4e2d\u6ca1\u6709\u76f8\u5173","\u7684","``","monitor","``","\u503c\u8bf7\u8fd4\u56de","``","None","``","\u3002",":","param","larger_better",":","monitor","\u7684\u503c\u662f\u5426\u662f\u8d8a\u5927\u8d8a\u597d\u3002",":","param","patience",":","\u591a\u5c11\u6b21","evaluate","\u4e0d\u6ca1\u6709\u63d0\u5347\u5c31\u505c\u6b62\u3002"]
code: def on_evaluate_end(self, trainer, results):
      monitor_value = self.get_monitor_value(results)
      if monitor_value is None:
          return
      if self.is_better_monitor_value(
          monitor_value, keep_if_better=True
      ):
          self.wait = 0
      else:
          self.wait += 1
  
file_path: fastNLP/fastNLP/core/callbacks/early_stop_callback.py
imports: from typing import Dict, Union, Callable
  from .has_monitor_callback import HasMonitorCallback
  from fastNLP.core.utils.exceptions import EarlyStopException
label_desc: Use image node_id 2 for calling the EarlyStopCallback obj's underlying member method code with example usage: obj.on_evaluate_end(trainer, results) without return types