docstr: Updates metrics with the given targets and predictions.
  
  If decoded_targets and decoded_predictions are provided, as through LLM model types, then additional
  response-based metrics like BLEU and ROUGE are also computed.
  
  Args:
      targets: Tensor with target values for this output feature.
      predictions: Dict of tensors returned by predictions().
docstr_tok: ["Updates","metrics","with","the","given","targets","and","predictions",".","If","decoded_targets","and","decoded_predictions","are","provided",",","as","through","LLM","model","types",",","then","additional","response-based","metrics","like","BLEU","and","ROUGE","are","also","computed",".","Args",":","targets",":","Tensor","with","target","values","for","this","output","feature",".","predictions",":","Dict","of","tensors","returned","by","predictions","(",")","."]
code: def update_metrics(
      self,
      targets: Tensor,
      predictions: Dict[str, Tensor],
      tokenizer: Optional[PreTrainedTokenizer] = None,
  ) -> None:
      """Updates metrics with the given targets and predictions.
  
      If decoded_targets and decoded_predictions are provided, as through LLM model types, then additional
      response-based metrics like BLEU and ROUGE are also computed.
  
      Args:
          targets: Tensor with target values for this output feature.
          predictions: Dict of tensors returned by predictions().
      """
      if tokenizer is not None:
          # Decode the targets and predictions to compute response-based metrics using the initialized tokenizer.
          (
              decoded_targets,
              decoded_predictions,
          ) = get_decoded_targets_and_predictions(
              targets, predictions, tokenizer
          )
  
      for metric_name, metric_fn in self._metric_functions.items():
          prediction_key = get_metric_tensor_input(metric_name)
          try:
              if prediction_key == RESPONSE:
                  if tokenizer is not None:
                      # RESPONSE metrics cannot be computed if decoded texts are not provided.
                      # Decoded texts are only provided using the LLM model type.
                      if (
                          decoded_targets is not None
                          and decoded_predictions is not None
                      ):
                          # Move metric function to the device of the predictions.
                          # For CUDA, it can be computed on any of the GPUs since it uses allgather to collect
                          # the results from all GPUs and compute the final metric.
                          # We use 'predictions' as the key since it is always present in the predictions dict.
                          device = (
                              "cuda"
                              if predictions["predictions"].is_cuda
                              else "cpu"
                          )
                          metric_fn = metric_fn.to(device)
                          if metric_name == "bleu":
                              # BLEU takes in targets as a list.
                              metric_fn.update(
                                  decoded_predictions, [decoded_targets]
                              )
                          else:
                              metric_fn.update(
                                  decoded_predictions, decoded_targets
                              )
              else:
                  metric_fn = metric_fn.to(
                      predictions[prediction_key].device
                  )
                  metric_fn.update(
                      predictions[prediction_key].detach(), targets
                  )
          except Exception as e:
              logger.info(
                  f"Ran into error when calculating metric {metric_name}. Skipping. The error is: {e}"
              )
  
imports: import logging
  from functools import partial
  from typing import Dict, List, Optional, Tuple, Union
  import numpy
  import torch
  from torch import Tensor
  from transformers import PreTrainedTokenizer
  from ludwig.constants import COLUMN, IGNORE_INDEX_TOKEN_ID, LAST_PREDICTIONS, LENGTHS, NAME, PREDICTIONS, PREPROCESSING, PROBABILITIES, PROBABILITY, PROC_COLUMN, RESPONSE, TEXT
  from ludwig.features.base_feature import BaseFeatureMixin, OutputFeature
  from ludwig.features.feature_utils import compute_sequence_probability, compute_token_probabilities
  from ludwig.features.sequence_feature import _SequencePostprocessing, _SequencePreprocessing, SequenceInputFeature, SequenceOutputFeature
  from ludwig.modules.metric_registry import get_metric_tensor_input
  from ludwig.schema.features.text_feature import TextInputFeatureConfig, TextOutputFeatureConfig
  from ludwig.types import FeatureMetadataDict, ModelConfigDict, PreprocessingConfigDict, TrainingSetMetadataDict
  from ludwig.utils.math_utils import softmax
  from ludwig.utils.strings_utils import build_sequence_matrix, create_vocabulary, get_tokenizer, SpecialSymbol, UNKNOWN_SYMBOL, Vocabulary
label_desc: Use image node_id 4 for calling the TextOutputFeature obj's underlying member method code with example usage: obj.update_metrics(targets, predictions, tokenizer) without return types