class_docstr: Computes VQA accuracy and F1 metrics.
  
  Since jax does not support strings, during the compute phase, which is done
  outside of pmap and other jax functions, converts the integer word/text
  predictions into words/strings which are used to compute the scores.
  
  Attributes:
    predictions: jnp.ndarray of integers representing word/text predictions.
    targets: jnp.ndarray of integers representing ground truth words/text.
class_docstr_tok: ["Computes","VQA","accuracy","and","F1","metrics",".","Since","jax","does","not","support","strings",",","during","the","compute","phase",",","which","is","done","outside","of","pmap","and","other","jax","functions",",","converts","the","integer","word\/text","predictions","into","words\/strings","which","are","used","to","compute","the","scores",".","Attributes",":","predictions",":","jnp.ndarray","of","integers","representing","word\/text","predictions",".","targets",":","jnp.ndarray","of","integers","representing","ground","truth","words\/text","."]
code: def compute(self) -> dict[str, Any]:
      values = super().compute()
      tokenizer = t5_tokenizer.build_dmvr_sp_model()
      tokenizer.initialize()
      # Moves all values into the batch dimension when run with pmap.
      predictions = jnp.reshape(
          values["predictions"], (-1, values["predictions"].shape[-1])
      )
      # Targets has multiple answers per-question, so we keep that structure when
      # reshaping.
      targets = values["targets"]
      targets = jnp.reshape(
          targets, (-1, targets.shape[-2], targets.shape[-1])
      )
      assert len(targets.shape) == 3
      assert len(predictions.shape) == 2
  
      # Convert the values into text.
      prediction_tokens = []
      for p in predictions.tolist():
          if data_utils.EOS_ID in p:
              p = p[: p.index(data_utils.EOS_ID)]
          prediction_tokens += [tokenizer.indices_to_string(p)]
      # Each question has multiple answers, so we need to decode a list-of-list.
  
      target_tokens = []
      for target_answers in targets.tolist():
          tokens = []
          for answer in target_answers:
              if data_utils.EOS_ID in answer:
                  answer = answer[: answer.index(data_utils.EOS_ID)]
              tokens += [tokenizer.indices_to_string(answer)]
          target_tokens += [tokens]
      # Normalize answers, which expects a string.
      predictions = [normalize_answer(p) for p in prediction_tokens]
      targets = [
          [normalize_answer(a) for a in t] for t in target_tokens
      ]
  
      if len(targets[0]) > 1:
          # VizWiz and VQA2.0 style metric with multiple GT answers.
          qa = qa_utils.vqa_metrics(targets, predictions)
      else:
          # SNLI-VE, GQA, NLVR single GT answer metric.
          qa = qa_utils.qa_metrics(targets, predictions)
      qa["acc"] = 100 * np.average(
          [p in ans for p, ans in zip(predictions, targets)]
      )
      return qa
  
file_path: scenic/scenic/projects/knowledge_visual_language/models/metrics_vqa.py
imports: import string
  from typing import Any
  from clu import metrics
  import clu.values
  import flax
  import jax.numpy
  import numpy
  from scenic.projects.knowledge_visual_language.data import data_utils
  from scenic.projects.t5 import tokenizer
  from scenic.projects.vit_vqa.models import qa_utils
label_desc: Use image node_id 1 for calling the VQAMetrics obj's underlying member method code with example usage: obj.compute() and returns: qa