code: def infer_metrics(
      problem_type: Optional[str] = None,
      eval_metric: Optional[Union[str, Scorer]] = None,
      validation_metric_name: Optional[str] = None,
      is_matching: Optional[bool] = False,
  ):
      """
      Infer the validation metric and the evaluation metric if not provided.
      Validation metric is for early-stopping and selecting the best model checkpoints.
      Evaluation metric is to report performance to users.
  
      Parameters
      ----------
      problem_type
          Type of problem.
      eval_metric_name
          Name of evaluation metric provided by users.
      validation_metric_name
          The provided validation metric name
      is_matching
          Whether is matching.
  
      Returns
      -------
      validation_metric_name
          Name of validation metric.
      eval_metric_name
          Name of evaluation metric.
      """
      is_customized = False
      if eval_metric is None:
          eval_metric_name = None
      elif isinstance(eval_metric, str):
          eval_metric_name = eval_metric
      elif isinstance(eval_metric, Scorer):
          eval_metric_name = eval_metric.name
          is_customized = True
      else:
          raise TypeError(
              f"eval_metric can be a str, a Scorer, or None, but is type: {type(eval_metric)}"
          )
  
      if problem_type is not None:
          problem_property = PROBLEM_TYPES_REG.get(problem_type)
  
      if is_matching:
          if eval_metric_name is not None:
              # if eval_metric_name is a valid metric
              if eval_metric_name.lower() in METRIC_MODE_MAP.keys():
                  validation_metric_name = eval_metric_name
                  return validation_metric_name, eval_metric_name
              elif eval_metric_name.lower() in RETRIEVAL_METRICS:
                  # Currently only support recall as validation metric in retrieval tasks.
                  validation_metric_name = RECALL
                  return validation_metric_name, eval_metric_name
  
          # When eval_metric_name is either None or not supported:
          # Fallback based on problem type unless it's a customized metric
          if problem_type is None:
              (
                  validation_metric_name,
                  fallback_evaluation_metric,
              ) = MATCHING_METRICS_WITHOUT_PROBLEM_TYPE
          elif problem_type in MATCHING_METRICS:
              (
                  validation_metric_name,
                  fallback_evaluation_metric,
              ) = MATCHING_METRICS[problem_type]
          else:
              raise NotImplementedError(
                  f"Problem type: {problem_type} is not yet supported for matching!"
              )
          if not is_customized:
              if eval_metric_name is not None:
                  warnings.warn(
                      f"Metric {eval_metric_name} is not supported as the evaluation metric for {problem_type} in matching tasks."
                      f"The evaluation metric is changed to {fallback_evaluation_metric} by default."
                  )
              eval_metric_name = fallback_evaluation_metric
          return validation_metric_name, eval_metric_name
  
      if eval_metric_name is not None:
          # Infer evaluation metric
          if (
              eval_metric_name.lower()
              not in problem_property.supported_evaluation_metrics
              and not is_customized
          ):
              warnings.warn(
                  f"Metric {eval_metric_name} is not supported as the evaluation metric for {problem_type}. "
                  f"The evaluation metric is changed to {problem_property.fallback_evaluation_metric} by default."
              )
              if (
                  problem_property.fallback_evaluation_metric
                  is not None
              ):
                  eval_metric_name = (
                      problem_property.fallback_evaluation_metric
                  )
              else:
                  # Problem types like extract_embedding does not need a eval/val metric
                  return None, None
  
          # Infer validation metric
          if (
              eval_metric_name.lower()
              in problem_property.supported_validation_metrics
          ):
              validation_metric_name = eval_metric_name
          else:
              if (
                  problem_property.fallback_validation_metric
                  is not None
              ):
                  validation_metric_name = (
                      problem_property.fallback_validation_metric
                  )
      else:
          eval_metric_name = problem_property.fallback_evaluation_metric
          validation_metric_name = (
              problem_property.fallback_validation_metric
          )
  
      return validation_metric_name, eval_metric_name
  
imports: import logging
  import math
  import operator
  import warnings
  from typing import Dict, List, Optional, Tuple, Union
  import evaluate
  import numpy
  from sklearn.metrics import f1_score
  from autogluon.core.metrics import Scorer, get_metric
  from ..constants import ACCURACY, AVERAGE_PRECISION, BINARY, DIRECT_LOSS, F1, FEW_SHOT_CLASSIFICATION, IOU, MAP, MATCHING_METRICS, MATCHING_METRICS_WITHOUT_PROBLEM_TYPE, MAX, METRIC_MODE_MAP, MIN, MULTICLASS, NDCG, NER, NER_TOKEN_F1, NUMERICAL, OBJECT_DETECTION, OPEN_VOCABULARY_OBJECT_DETECTION, OVERALL_ACCURACY, OVERALL_F1, PRECISION, RECALL, REGRESSION, RETRIEVAL_METRICS, RMSE, ROC_AUC, SEMANTIC_SEGMENTATION, SPEARMANR, Y_PRED, Y_PRED_PROB, Y_TRUE
  from ..problem_types import PROBLEM_TYPES_REG
label_desc: Use image node_id 1 for calling a global function with example usage: infer_metrics(problem_type, eval_metric, validation_metric_name, is_matching) and returns: validation_metric_name,  eval_metric_name, validation_metric_name,  eval_metric_name, validation_metric_name,  eval_metric_name, None,  None, validation_metric_name,  eval_metric_name