class_docstr: A callback that writes training statistics/metrics to TensorBoard.
class_docstr_tok: ["A","callback","that","writes","training","statistics\/metrics","to","TensorBoard","."]
code: def log_scalars(
      self,
      scalars: Dict[str, Union[int, float]],
      log_prefix: str = "",
      epoch: Optional[int] = None,
  ) -> None:
      assert self.trainer is not None
      timestep = (
          epoch
          if epoch is not None
          else self.trainer._total_batches_completed
      )
      log = (
          self._train_log
          if not log_prefix.startswith("validation")
          else self._validation_log
      )
      for key, value in scalars.items():
          name = f"{log_prefix}/{key}" if log_prefix else key
          log.add_scalar(name, value, timestep + 1)
  
file_path: allennlp/allennlp/training/callbacks/tensorboard.py
imports: import os
  from typing import Dict, Union, Optional
  from tensorboardX import SummaryWriter
  import torch
  from allennlp.training.callbacks.callback import TrainerCallback
  from allennlp.training.callbacks.log_writer import LogWriterCallback
label_desc: Use image node_id 2 for calling the TensorBoardCallback obj's underlying member method code with example usage: obj.log_scalars(scalars, log_prefix, epoch) without return types