class_docstr: Class for BERT few-shot evaluation.
class_docstr_tok: ["Class","for","BERT","few-shot","evaluation","."]
docstr: Compute few-shot metrics on one dataset.
docstr_tok: ["Compute","few-shot","metrics","on","one","dataset","."]
code: def compute_fewshot_metrics(self, train_state, config):
      """Compute few-shot metrics on one dataset."""
      (
          train_ds,
          test_ds,
          num_train_samples,
          num_test_samples,
          num_classes,
      ) = self._get_dataset(config)
      task = config.dataset_configs.task
      logging.info("[fewshot][%s]: Precomputing train", task)
      repr_train, labels_train = self._get_repr(
          train_state, train_ds, num_train_samples
      )
      logging.info("[fewshot][%s]: Precomputing test", task)
      repr_test, labels_test = self._get_repr(
          train_state, test_ds, num_test_samples
      )
      logging.info("[fewshot][%s]: solving systems", task)
  
      # Collect where we have samples of which classes.
      class_indices = [
          np.where(labels_train == cls_i)[0]
          for cls_i in range(num_classes)
      ]
  
      results = {}
      for shots in self.shots:
          all_idx = [indices[:shots] for indices in class_indices]
          all_idx = np.concatenate(all_idx, axis=0)
          x = repr_train[all_idx]
          y = labels_train[all_idx]
  
          for l2_reg in self.l2_regs:
              acc = _fewshot_acc_fn(  # pylint: disable=protected-access
                  x, y, repr_test, labels_test, l2_reg, num_classes
              )
              results[shots, l2_reg] = np.array(acc)
      return results
  
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 4 for calling the BERTFewShotEvaluator obj's underlying member method code with example usage: obj.compute_fewshot_metrics(train_state, config) and returns: results