code: def append_metrics(
      model: BaseModel,
      dataset_name: Literal["train", "validation", "test"],
      results: Dict[str, Dict[str, float]],
      metrics_log: Dict[str, Dict[str, List[TrainerMetric]]],
      progress_tracker: ProgressTracker,
  ) -> Dict[str, Dict[str, List[TrainerMetric]]]:
      epoch = progress_tracker.epoch
      steps = progress_tracker.steps
      for output_feature in model.output_features:
          scores = [dataset_name]
  
          # collect metric names based on output features metrics to
          # ensure consistent order of reporting metrics
          metric_names = sorted(results[output_feature].keys())
  
          for metric in metric_names:
              if metric in results[output_feature]:
                  # Some metrics may have been excepted and excluded from results.
                  score = results[output_feature][metric]
                  metrics_log[output_feature][metric].append(
                      TrainerMetric(
                          epoch=epoch, step=steps, value=score
                      )
                  )
                  scores.append(score)
  
      metrics_log[COMBINED][LOSS].append(
          TrainerMetric(
              epoch=epoch, step=steps, value=results[COMBINED][LOSS]
          )
      )
      return metrics_log
  
imports: import logging
  from collections import defaultdict
  from typing import Dict, List, Tuple, TYPE_CHECKING
  from ludwig.api_annotations import DeveloperAPI
  from ludwig.constants import AUTO, COMBINED, LOSS
  from ludwig.models.base import BaseModel
  from ludwig.modules.metric_modules import get_best_function
  from ludwig.utils.data_utils import save_json
  from ludwig.utils.metric_utils import TrainerMetric
label_desc: Use image node_id 4 for calling a global function with example usage: append_metrics(model, dataset_name, results, metrics_log, progress_tracker) and returns: metrics_log