class_docstr: | Bases :class:`~deeppavlov.core.trainers.FitTrainer`
  | Trainer class for training and evaluating pipelines containing
    :class:`Estimators <deeppavlov.core.models.estimator.Estimator>`
    and an :class:`~deeppavlov.core.models.nn_model.NNModel`
  
  Args:
      chainer_config: ``"chainer"`` block of a configuration file
      batch_size: batch_size to use for partial fitting (if available) and evaluation,
          the whole dataset is used if ``batch_size`` is negative or zero (default is ``1``)
      epochs: maximum epochs number to train the pipeline, ignored if negative or zero (default is ``-1``)
      start_epoch_num: starting epoch number for reports (default is ``0``)
      max_batches: maximum batches number to train the pipeline, ignored if negative or zero (default is ``-1``)
      metrics: iterable of metrics where each metric can be a registered metric name or a dict of ``name`` and
          ``inputs`` where ``name`` is a registered metric name and ``inputs`` is a collection of parameter names
          from chainer’s inner memory that will be passed to the metric function;
          default value for ``inputs`` parameter is a concatenation of chainer’s ``in_y`` and ``out`` fields;
          the first metric is used for early stopping (default is ``('accuracy',)``)
      train_metrics: metrics calculated for train logs (if omitted, ``metrics`` argument is used)
      metric_optimization: one of ``'maximize'`` or ``'minimize'`` — strategy for metric optimization used in early
          stopping (default is ``'maximize'``)
      evaluation_targets: data types on which to evaluate a trained pipeline (default is ``('valid', 'test')``)
      show_examples: a flag used to print inputs, expected outputs and predicted outputs for the last batch
          in evaluation logs (default is ``False``)
      tensorboard_log_dir: path to a directory where tensorboard logs can be stored, ignored if None
          (default is ``None``)
      validate_first: flag used to calculate metrics on the ``'valid'`` data type before starting training
          (default is ``True``)
      validation_patience: how many times in a row the validation metric has to not improve for early stopping,
          ignored if negative or zero (default is ``5``)
      val_every_n_epochs: how often (in epochs) to validate the pipeline, ignored if negative or zero
          (default is ``-1``)
      val_every_n_batches: how often (in batches) to validate the pipeline, ignored if negative or zero
          (default is ``-1``)
      log_every_n_epochs: how often (in epochs) to calculate metrics on train data, ignored if negative or zero
          (default is ``-1``)
      log_every_n_batches: how often (in batches) to calculate metrics on train data, ignored if negative or zero
          (default is ``-1``)
      log_on_k_batches: count of random train batches to calculate metrics in log (default is ``1``)
      max_test_batches: maximum batches count for pipeline testing and evaluation, overrides ``log_on_k_batches``,
          ignored if negative (default is ``-1``)
      **kwargs: additional parameters whose names will be logged but otherwise ignored
  
  
  Trainer saves the model if it sees progress in scores. The full rules look like following:
  
  - For the validation savepoint:
      * 0-th validation (optional). Don't save model, establish a baseline.
      * 1-th validation.
           + If we have a baseline, save the model if we see an improvement, don't save otherwise.
           + If we don't have a baseline, save the model.
      * 2nd and later validations. Save the model if we see an improvement
  - For the at-train-exit savepoint:
      * Save the model if it happened before 1st validation (to capture early training results), don't save otherwise.
code: def _send_event(
      self, event_name: str, data: Optional[dict] = None
  ) -> None:
      report = {
          "time_spent": str(
              datetime.timedelta(
                  seconds=round(time.time() - self.start_time + 0.5)
              )
          ),
          "epochs_done": self.epoch,
          "batches_seen": self.train_batches_seen,
          "train_examples_seen": self.examples,
      }
      if data is not None:
          report.update(data)
      self._chainer.process_event(event_name=event_name, data=report)
  
imports: import datetime
  import json
  import time
  from itertools import islice
  from logging import getLogger
  from pathlib import Path
  from typing import List, Tuple, Union, Optional, Iterable
  from tqdm import tqdm
  from deeppavlov.core.common.errors import ConfigError
  from deeppavlov.core.common.log_events import get_tb_writer
  from deeppavlov.core.common.registry import register
  from deeppavlov.core.data.data_learning_iterator import DataLearningIterator
  from deeppavlov.core.trainers.fit_trainer import FitTrainer
  from deeppavlov.core.trainers.utils import parse_metrics, NumpyArrayEncoder
label_desc: Use image node_id 7 for calling the NNTrainer obj's underlying member method code with example usage: obj._send_event(event_name, data) without return types