class_docstr: Trainer class for fitting and evaluating :class:`Estimators <deeppavlov.core.models.estimator.Estimator>`
  
  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``)
      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
          (default is ``('accuracy',)``)
      evaluation_targets: data types on which to evaluate 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``)
      max_test_batches: maximum batches count for pipeline testing and evaluation, ignored if negative
          (default is ``-1``)
      **kwargs: additional parameters whose names will be logged but otherwise ignored
docstr: Calculate metrics and return reports on provided data for currently stored
  :class:`~deeppavlov.core.common.chainer.Chainer`
  
  Args:
      data: iterable of batches of inputs and expected outputs
      metrics: collection of metrics namedtuples containing names for report, metric functions
          and their inputs names (if omitted, ``self.metrics`` is used)
      start_time: start time for test report
      show_examples: a flag used to return inputs, expected outputs and predicted outputs for the last batch
          in a result report (if omitted, ``self.show_examples`` is used)
  
  Returns:
      a report dict containing calculated metrics, spent time value, examples count in tested data
      and maybe examples
docstr_tok: ["Calculate","metrics","and","return","reports","on","provided","data","for","currently","stored",":","class",":","`","~deeppavlov.core.common.chainer.Chainer","`","Args",":","data",":","iterable","of","batches","of","inputs","and","expected","outputs","metrics",":","collection","of","metrics","namedtuples","containing","names","for","report",",","metric","functions","and","their","inputs","names","(","if","omitted",",","``","self.metrics","``","is","used",")","start_time",":","start","time","for","test","report","show_examples",":","a","flag","used","to","return","inputs",",","expected","outputs","and","predicted","outputs","for","the","last","batch","in","a","result","report","(","if","omitted",",","``","self.show_examples","``","is","used",")","Returns",":","a","report","dict","containing","calculated","metrics",",","spent","time","value",",","examples","count","in","tested","data","and","maybe","examples"]
code: def test(
      self,
      data: Iterable[Tuple[Collection[Any], Collection[Any]]],
      metrics: Optional[Collection[Metric]] = None,
      *,
      start_time: Optional[float] = None,
      show_examples: Optional[bool] = None,
  ) -> dict:
      """
      Calculate metrics and return reports on provided data for currently stored
      :class:`~deeppavlov.core.common.chainer.Chainer`
  
      Args:
          data: iterable of batches of inputs and expected outputs
          metrics: collection of metrics namedtuples containing names for report, metric functions
              and their inputs names (if omitted, ``self.metrics`` is used)
          start_time: start time for test report
          show_examples: a flag used to return inputs, expected outputs and predicted outputs for the last batch
              in a result report (if omitted, ``self.show_examples`` is used)
  
      Returns:
          a report dict containing calculated metrics, spent time value, examples count in tested data
          and maybe examples
      """
  
      if start_time is None:
          start_time = time.time()
      if show_examples is None:
          show_examples = self.show_examples
      if metrics is None:
          metrics = self.metrics
  
      expected_outputs = list(
          set().union(
              self._chainer.out_params, *[m.inputs for m in metrics]
          )
      )
  
      outputs = {out: [] for out in expected_outputs}
      examples = 0
  
      data = islice(data, self.max_test_batches)
  
      for x, y_true in tqdm(data):
          examples += len(x)
          y_predicted = list(
              self._chainer.compute(
                  list(x), list(y_true), targets=expected_outputs
              )
          )
          if len(expected_outputs) == 1:
              y_predicted = [y_predicted]
          for out, val in zip(outputs.values(), y_predicted):
              out += list(val)
      if examples == 0:
          log.warning("Got empty data iterable for scoring")
          return {
              "eval_examples_count": 0,
              "metrics": None,
              "time_spent": str(datetime.timedelta(seconds=0)),
          }
  
      # metrics_values = [(m.name, m.fn(*[outputs[i] for i in m.inputs])) for m in metrics]
      metrics_values = []
      for metric in metrics:
          calculate_metric = True
          for i in metric.inputs:
              outputs[i] = [k for k in outputs[i] if k is not None]
              if len(outputs[i]) == 0:
                  log.info(
                      f"Metric {metric.alias} is not calculated due to absense of true and predicted samples"
                  )
                  calculate_metric = False
                  value = -1
          if calculate_metric:
              value = metric.fn(*[outputs[i] for i in metric.inputs])
          metrics_values.append((metric.alias, value))
  
      report = {
          "eval_examples_count": examples,
          "metrics": prettify_metrics(metrics_values),
          "time_spent": str(
              datetime.timedelta(
                  seconds=round(time.time() - start_time + 0.5)
              )
          ),
      }
  
      if show_examples:
          y_predicted = zip(
              *[
                  y_predicted_group
                  for out_name, y_predicted_group in zip(
                      expected_outputs, y_predicted
                  )
                  if out_name in self._chainer.out_params
              ]
          )
          if len(self._chainer.out_params) == 1:
              y_predicted = [
                  y_predicted_item[0]
                  for y_predicted_item in y_predicted
              ]
          report["examples"] = [
              {
                  "x": x_item,
                  "y_predicted": y_predicted_item,
                  "y_true": y_true_item,
              }
              for x_item, y_predicted_item, y_true_item in zip(
                  x, y_predicted, y_true
              )
          ]
  
      return report
  
imports: import datetime
  import json
  import time
  from itertools import islice
  from logging import getLogger
  from typing import Tuple, Dict, Union, Optional, Iterable, Any, Collection
  from tqdm import tqdm
  from deeppavlov.core.commands.infer import build_model
  from deeppavlov.core.common.chainer import Chainer
  from deeppavlov.core.common.params import from_params
  from deeppavlov.core.common.registry import register
  from deeppavlov.core.data.data_fitting_iterator import DataFittingIterator
  from deeppavlov.core.data.data_learning_iterator import DataLearningIterator
  from deeppavlov.core.models.estimator import Estimator
  from deeppavlov.core.trainers.utils import Metric, parse_metrics, prettify_metrics, NumpyArrayEncoder
label_desc: Use image node_id 6 for calling the FitTrainer obj's underlying member method code with example usage: obj.test(data, metrics) and returns: report, dict