class_docstr: Returns layer that computes custom loss and metrics for pretraining.
class_docstr_tok: ["Returns","layer","that","computes","custom","loss","and","metrics","for","pretraining","."]
docstr: Adds metrics.
docstr_tok: ["Adds","metrics","."]
code: def _add_metrics(
      self,
      lm_output,
      lm_labels,
      lm_label_weights,
      lm_example_loss,
      sentence_output,
      sentence_labels,
      next_sentence_loss,
  ):
      """Adds metrics."""
      masked_lm_accuracy = tf.keras.metrics.sparse_categorical_accuracy(
          lm_labels, lm_output
      )
      numerator = tf.reduce_sum(masked_lm_accuracy * lm_label_weights)
      denominator = tf.reduce_sum(lm_label_weights) + 1e-5
      masked_lm_accuracy = numerator / denominator
      self.add_metric(
          masked_lm_accuracy,
          name="masked_lm_accuracy",
          aggregation="mean",
      )
  
      self.add_metric(
          lm_example_loss, name="lm_example_loss", aggregation="mean"
      )
  
      next_sentence_accuracy = (
          tf.keras.metrics.sparse_categorical_accuracy(
              sentence_labels, sentence_output
          )
      )
      self.add_metric(
          next_sentence_accuracy,
          name="next_sentence_accuracy",
          aggregation="mean",
      )
  
      self.add_metric(
          next_sentence_loss,
          name="next_sentence_loss",
          aggregation="mean",
      )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import tensorflow
  import tensorflow_hub
  from utils import tf_utils
  from utils.modeling import losses
  from utils.modeling import networks
  from utils.modeling.networks import bert_classifier
  from utils.modeling.networks import bert_pretrainer
  from utils.modeling.networks import bert_span_labeler
label_desc: Use image node_id 3 for calling the BertPretrainLossAndMetricLayer obj's underlying member method code with example usage: obj._add_metrics(lm_output, lm_labels, lm_label_weights, lm_example_loss, sentence_output, sentence_labels, next_sentence_loss) without return types