class_docstr: Plugin that manages the loss.tsv file output.
class_docstr_tok: ["Plugin","that","manages","the","loss.tsv","file","output","."]
code: def __init__(
      self,
      base_path,
      epoch: int,
      metrics_to_collect: Optional[Dict[Union[Tuple, str], str]] = None,
  ) -> None:
      super().__init__()
  
      self.first_epoch = epoch + 1
      # prepare loss logging file and set up header
      self.loss_txt = init_output_file(base_path, "loss.tsv")
      self.base_path = base_path
  
      # set up all metrics to collect
      self.metrics_to_collect = metrics_to_collect
      if self.metrics_to_collect is not None:
          metrics_to_collect = self.metrics_to_collect
      else:
          metrics_to_collect = {
              "loss": "LOSS",
              ("micro avg", "precision"): "PRECISION",
              ("micro avg", "recall"): "RECALL",
              ("micro avg", "f1-score"): "F1",
              "accuracy": "ACCURACY",
          }
  
      # set up headers
      self.headers = {
          # name: HEADER
          MetricName("epoch"): "EPOCH",
          MetricName("timestamp"): "TIMESTAMP",
          MetricName("bad_epochs"): "BAD_EPOCHS",
          MetricName("learning_rate"): "LEARNING_RATE",
      }
  
      # Add all potentially relevant metrics. If a metric is not published
      # after the first epoch (when the header is written), the column is
      # removed at that point.
      for prefix in ["train", "train_sample", "dev", "test"]:
          for name, header in metrics_to_collect.items():
              metric_name = MetricName(name)
  
              if prefix == "train" and metric_name != "loss":
                  metric_name = "train_eval" + metric_name
              else:
                  metric_name = prefix + metric_name
  
              self.headers[metric_name] = f"{prefix.upper()}_{header}"
  
      # initialize the first log line
      self.current_row: Optional[Dict[MetricName, str]] = None
  
file_path: flair/flair/trainers/plugins/loggers/loss_file.py
imports: from datetime import datetime
  from typing import Any, Dict, Optional, Tuple, Union
  from flair.trainers.plugins.base import TrainerPlugin
  from flair.trainers.plugins.metric_records import MetricName
  from flair.training_utils import init_output_file
label_desc: Use image node_id 1 to create a new LossFilePlugin object from inherited base classes: TrainerPlugin with example: obj = LossFilePlugin(base_path, epoch, metrics_to_collect)