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: Implements call() for the layer.
docstr_tok: ["Implements","call","(",")","for","the","layer","."]
code: def call(self, inputs):
      """Implements call() for the layer."""
      unpacked_inputs = tf_utils.unpack_inputs(inputs)
      lm_output = unpacked_inputs[0]
      sentence_output = unpacked_inputs[1]
      lm_label_ids = unpacked_inputs[2]
      lm_label_weights = tf.keras.backend.cast(
          unpacked_inputs[3], tf.float32
      )
      sentence_labels = unpacked_inputs[4]
  
      mask_label_loss = (
          losses.weighted_sparse_categorical_crossentropy_loss(
              labels=lm_label_ids,
              predictions=lm_output,
              weights=lm_label_weights,
          )
      )
      sentence_loss = (
          losses.weighted_sparse_categorical_crossentropy_loss(
              labels=sentence_labels, predictions=sentence_output
          )
      )
      loss = mask_label_loss + sentence_loss
      batch_shape = tf.slice(
          tf.keras.backend.shape(sentence_labels), [0], [1]
      )
      # TODO(hongkuny): Avoids the hack and switches add_loss.
      final_loss = tf.fill(batch_shape, loss)
  
      self._add_metrics(
          lm_output,
          lm_label_ids,
          lm_label_weights,
          mask_label_loss,
          sentence_output,
          sentence_labels,
          sentence_loss,
      )
      return final_loss
  
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 4 for calling the BertPretrainLossAndMetricLayer obj's underlying member method code with example usage: obj.call(inputs) and returns: final_loss