class_docstr: APIs to help create and train a BERT-based text classifier.
class_docstr_tok: ["APIs","to","help","create","and","train","a","BERT-based","text","classifier","."]
docstr: Creates metrics for training and evaluation.
  
  The default metrics are accuracy, precision, and recall.
  
  For binary classification tasks only (num_classes=2):
    Users can configure PrecisionAtRecall and RecallAtPrecision metrics using
    the desired_presisions and desired_recalls fields in BertHParams.
  
  Returns:
    A list of tf.keras.Metric subclasses which can be used with model.compile
code: def _create_metrics(self):
      """Creates metrics for training and evaluation.
  
      The default metrics are accuracy, precision, and recall.
  
      For binary classification tasks only (num_classes=2):
        Users can configure PrecisionAtRecall and RecallAtPrecision metrics using
        the desired_presisions and desired_recalls fields in BertHParams.
  
      Returns:
        A list of tf.keras.Metric subclasses which can be used with model.compile
      """
      metric_functions = [
          tf.keras.metrics.SparseCategoricalAccuracy(
              "accuracy", dtype=tf.float32
          ),
          metrics.SparsePrecision(name="precision", dtype=tf.float32),
          metrics.SparseRecall(name="recall", dtype=tf.float32),
          metrics.BinaryAUC(name="auc", num_thresholds=1000),
      ]
      if self._num_classes == 2:
          if self._hparams.desired_precisions:
              for desired_precision in self._hparams.desired_precisions:
                  metric_functions.append(
                      metrics.BinarySparseRecallAtPrecision(
                          desired_precision,
                          name=f"recall_at_precision_{desired_precision}",
                          num_thresholds=1000,
                      )
                  )
          if self._hparams.desired_recalls:
              for desired_recall in self._hparams.desired_recalls:
                  metric_functions.append(
                      metrics.BinarySparseRecallAtPrecision(
                          desired_recall,
                          name=f"precision_at_recall_{desired_recall}",
                          num_thresholds=1000,
                      )
                  )
      else:
          if (
              self._hparams.desired_precisions
              or self._hparams.desired_recalls
          ):
              raise ValueError(
                  "desired_recalls and desired_precisions parameters are binary"
                  " metrics and not supported for num_classes > 2. Found"
                  f" num_classes: {self._num_classes}"
              )
      return metric_functions
  
imports: import abc
  import os
  import tempfile
  from typing import Any, Optional, Sequence, Tuple
  import tensorflow
  from tensorflow_addons import optimizers
  import tensorflow_hub
  from mediapipe.model_maker.python.core.data import dataset
  from mediapipe.model_maker.python.core.tasks import classifier
  from mediapipe.model_maker.python.core.utils import hub_loader
  from mediapipe.model_maker.python.core.utils import loss_functions
  from mediapipe.model_maker.python.core.utils import metrics
  from mediapipe.model_maker.python.core.utils import model_util
  from mediapipe.model_maker.python.core.utils import quantization
  from mediapipe.model_maker.python.text.text_classifier import bert_tokenizer
  from mediapipe.model_maker.python.text.text_classifier import dataset
  from mediapipe.model_maker.python.text.text_classifier import hyperparameters
  from mediapipe.model_maker.python.text.text_classifier import model_options
  from mediapipe.model_maker.python.text.text_classifier import model_spec
  from mediapipe.model_maker.python.text.text_classifier import model_with_tokenizer
  from mediapipe.model_maker.python.text.text_classifier import preprocessor
  from mediapipe.model_maker.python.text.text_classifier import text_classifier_options
  from mediapipe.tasks.python.metadata.metadata_writers import metadata_writer
  from mediapipe.tasks.python.metadata.metadata_writers import text_classifier
label_desc: Use image node_id 5 for calling the _BertClassifier obj's underlying member method code with example usage: obj._create_metrics() and returns: metric_functions