class_docstr: Evaluator used for BERT global metrics evaluation.
class_docstr_tok: ["Evaluator","used","for","BERT","global","metrics","evaluation","."]
docstr: Computes the relevant metrics for all added <target, output> pairs.
docstr_tok: ["Computes","the","relevant","metrics","for","all","added","<","target",",","output",">","pairs","."]
code: def compute_metrics(
      self, clear_annotations: Optional[bool] = True
  ) -> Dict[str, Any]:
      """Computes the relevant metrics for all added <target, output> pairs."""
      metrics = {}
      if "f1" in self.global_metrics:
          # Used for QQP and MRPC tasks.
          prediction = np.argmax(self.batches[1], axis=-1)
          metrics.update(
              f1_score_with_invalid(
                  target=self.batches[0], prediction=prediction
              )
          )
  
      if "matthews_corrcoef" in self.global_metrics:
          # Used for COLA task.
          prediction = np.argmax(self.batches[1], axis=-1)
          metrics.update(
              matthews_corrcoef(
                  target=self.batches[0], prediction=prediction
              )
          )
  
      if "pearson_corrcoef" in self.global_metrics:
          # Used for STS-B task (which is a regression task).
          metrics.update(
              pearson_corrcoef(
                  target=np.squeeze(self.batches[0]),
                  prediction=np.squeeze(self.batches[1]),
              )
          )
  
      if clear_annotations:
          self.clear()
      return metrics
  
imports: import functools
  from typing import Any, Dict, List, Mapping, Optional, Tuple, Union
  from absl import logging
  from clu import metric_writers
  import flax
  from flax import jax_utils
  import flax.linen
  import jax
  import jax.numpy
  import jax.profiler
  import ml_collections
  import numpy
  from scenic.common_lib import debug_utils
  from scenic.train_lib import optimizers
  from scenic.train_lib import train_utils
  import scipy
  import sklearn.metrics
label_desc: Use image node_id 3 for calling the BERTGlobalEvaluator obj's underlying member method code with example usage: obj.compute_metrics(clear_annotations) and returns: metrics